Skip to content

Commit

Permalink
feat: Windows test, FFI test, and commit msg CI (#106)
Browse files Browse the repository at this point in the history
* feat: Windows test, FFI test, and commit msg CI

This commit improves the CI configuration by:

- Adding testing for Windows
- Adding testing for CCI code on Ubuntu and Windows
- Adding checking for conventional commit format in commit messages
- Upgrading from checkout v2 to v4 across the board.

Signed-off-by: Andrew Lilley Brinker <[email protected]>

* fix: resolved transient cbindgen issue

This commit fixes a transient issue where cbindgen would sometimes pick
up and try to build gitoid:0.3.0 instead of the current version
gitoid:0.4.0. This was happening because the omnibor crate imported
gitoid:0.3.0, and the two names would both appear in the output of
`cargo metadata`. cbindgen would use the first one that appeared, which
was sometimes gitoid:0.4.0 and sometimes gitoid:0.3.0. If it was the
older version, then everything would break.

This isn't really a long term fix, so there's a need to do more in the
future to stop this from happening again. For now this is enough.

Signed-off-by: Andrew Lilley Brinker <[email protected]>

* fix: Update CI jobs from make to shell script.

Haha forgot to do this when I made the replacement. We weren't really
using the features of Make so I thought it would be better to just
use a shell script. This commit updates CI to use that script.

Signed-off-by: Andrew Lilley Brinker <[email protected]>

---------

Signed-off-by: Andrew Lilley Brinker <[email protected]>
  • Loading branch information
alilleybrinker authored Feb 15, 2024
1 parent 1e21f10 commit 45fee33
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 98 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

permissions:
contents: read

env:
RUSTFLAGS: -Dwarnings
CARGO_TERM_COLOR: always

jobs:
test-linux:
name: Test (Ubuntu)
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Building
run: cargo build --verbose
- name: Testing (Rust)
run: cargo test --verbose
- name: Linting
run: cargo clippy --verbose

ffi-test-linux:
name: FFI Test (Ubuntu)
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- name: FFI Test
run: cd gitoid && ./ctest.sh

ffi-test-windows:
name: FFI Test (Windows)
runs-on: windows-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- name: FFI Test
run: cd gitoid && ./ctest.sh

conventional-commits:
name: Conventional Commits
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: webiny/[email protected]

24 changes: 0 additions & 24 deletions .github/workflows/rust.yml

This file was deleted.

42 changes: 0 additions & 42 deletions gitoid/Makefile

This file was deleted.

19 changes: 3 additions & 16 deletions gitoid/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include_guard = "gitoid_h"
include_version = true

# Wrap generated file in C++ compatibility code.
cpp_compat = false
cpp_compat = true

# Generate documentation in Doxygen style.
documentation_style = "doxy"
Expand All @@ -28,24 +28,11 @@ header = """
autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */"

[defines]

# Map Windows-specific and Unix-specific cfg's to define guards in the C code.
"target_family = unix" = "DEFINE_UNIX"
"target_family = windows" = "DEFINE_WINDOWS"


#==============================================================================
# Enum Rules
#------------------------------------------------------------------------------

[enum]

# Prefix enum variants with the name of the overall type.
prefix_with_name = true


#==============================================================================
# Parsing Rules
#------------------------------------------------------------------------------

[parse.expand]

# Make sure to do macro expansion when generating C bindings.
Expand Down
38 changes: 38 additions & 0 deletions gitoid/ctest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

# Variables for cbindgen.
CBINDGEN_CONFIG="./cbindgen.toml"

# Variables for the header file.
INCLUDE_DIR="./include"
HEADER_NAME="gitoid.h"

# Variables for the DLL/archive file.
LIB_DIR="../target/release"
LIB_NAME="gitoid"

# Variables for the test files.
TEST_SRC_FILE="./test/c/test.c"
TEST_EXE_FILE="./test/c_test"

echo "--------------------------------------------------"
echo "BUILDING LIBRARY"
cargo build -p "gitoid:0.4.0" --release --verbose

echo "--------------------------------------------------"
echo "GENERATING C HEADER FILE"
mkdir -p "${INCLUDE_DIR}"
cbindgen -v --clean -c "${CBINDGEN_CONFIG}" -o "${INCLUDE_DIR}/${HEADER_NAME}" --crate "gitoid"

echo "--------------------------------------------------"
echo "BUILDING C TEST FILE"
gcc --std=c99 -I"${INCLUDE_DIR}" -L"${LIB_DIR}" -o"${TEST_EXE_FILE}" "${TEST_SRC_FILE}" -l"${LIB_NAME}"

echo "--------------------------------------------------"
echo "RUNNING C TEST FILE"
PATH="${LIB_DIR}:${PATH}" LD_LIBRARY_PATH="${LIB_DIR}" "${TEST_EXE_FILE}"

echo "--------------------------------------------------"
echo "DELETING C TEST FILE"
rm "${TEST_EXE_FILE}"

1 change: 1 addition & 0 deletions gitoid/src/ffi/gitoid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub unsafe extern "C" fn gitoid_get_error_message(buffer: *mut c_char, length: c
/// Embed a C string into the binary.
macro_rules! embed_cstr {
($name:ident, $arr:expr) => {
/// cbindgen:ignore
const $name: *const c_char = $arr.as_ptr();
};
}
Expand Down
17 changes: 2 additions & 15 deletions gitoid/src/gitoid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use core::marker::PhantomData;
use core::ops::Not as _;
use digest::OutputSizeUser;
use format_bytes::format_bytes;
use format_bytes::write_bytes;
use format_bytes::DisplayBytes;
use generic_array::sequence::GenericSequence;
use generic_array::ArrayLength;
use generic_array::GenericArray;
Expand All @@ -23,10 +21,8 @@ use std::hash::Hasher;
use std::io::BufRead;
use std::io::BufReader;
use std::io::Read;
use std::io::Result as IoResult;
use std::io::Seek;
use std::io::SeekFrom;
use std::io::Write;
use std::str::FromStr;
use std::str::Split;
use url::Url;
Expand All @@ -49,6 +45,7 @@ where
value: GenericArray<u8, H::OutputSize>,
}

/// cbindgen:ignore
const GITOID_URL_SCHEME: &str = "gitoid";

impl<H, O> GitOid<H, O>
Expand Down Expand Up @@ -454,16 +451,6 @@ where
Ok(GitOid::from_hash(hash))
}

// Helper struct for using `format_bytes` during prefix construction for hashing.
struct Str<'s>(&'s str);

impl<'s> DisplayBytes for Str<'s> {
fn display_bytes(&self, output: &mut dyn Write) -> IoResult<()> {
write_bytes!(output, b"{}", self.0.as_bytes())?;
Ok(())
}
}

// Helper extension trait to give a convenient way to iterate over
// chunks sized to the size of the internal buffer of the reader.
trait ForEachChunk: BufRead {
Expand Down Expand Up @@ -512,7 +499,7 @@ where
{
digester.update(format_bytes!(
b"{} {}\0",
Str(O::NAME),
O::NAME.as_bytes(),
expected_read_length
));
let amount_read = BufReader::new(reader).for_each_chunk(|b| digester.update(b))?;
Expand Down
1 change: 1 addition & 0 deletions gitoid/src/hash_algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ macro_rules! impl_hash_algorithm {
impl Sealed for $type {}

impl HashAlgorithm for $type {
/// cbindgen:ignore
const NAME: &'static str = $name;
}
};
Expand Down
1 change: 1 addition & 0 deletions gitoid/src/object_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ macro_rules! define_object_type {
impl Sealed for $name {}

impl ObjectType for $name {
/// cbindgen:ignore
const NAME: &'static str = $s;
}
};
Expand Down
2 changes: 1 addition & 1 deletion omnibor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ repository = "https://github.com/omnibor/omnibor-rs"
version = "0.1.7"

[dependencies]
gitoid = "0.3.0"
gitoid = "0.4.0"

0 comments on commit 45fee33

Please sign in to comment.