diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7d4c8f0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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/action-conventional-commits@v1.3.0 + \ No newline at end of file diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index 4f2a4a6..0000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Rust tests - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -env: - CARGO_TERM_COLOR: always - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Build - run: cargo build --verbose - - name: Run tests [std] - run: cargo test --verbose - - name: Run clippy - run: cargo clippy diff --git a/gitoid/Makefile b/gitoid/Makefile deleted file mode 100644 index a23a3ac..0000000 --- a/gitoid/Makefile +++ /dev/null @@ -1,42 +0,0 @@ -# Makefile for testing the C FFI interface for the `gitoid` crate. -# -# This purposefully uses few features of Make and is written in a linear style. -# It is intended to be easy for newcomers to the project to understand. - -# 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" - -.PHONY: c_test -c_test: - @echo "--------------------------------------------------" - @echo "BUILDING LIBRARY" - @cargo build --release - - @echo "--------------------------------------------------" - @echo "GENERATING C HEADER FILE" - @mkdir -p "${INCLUDE_DIR}" - @cbindgen -c "${CBINDGEN_CONFIG}" -o "${INCLUDE_DIR}/${HEADER_NAME}" - - @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}" diff --git a/gitoid/cbindgen.toml b/gitoid/cbindgen.toml index 92fc5b9..381aa6c 100644 --- a/gitoid/cbindgen.toml +++ b/gitoid/cbindgen.toml @@ -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" @@ -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. diff --git a/gitoid/ctest.sh b/gitoid/ctest.sh new file mode 100755 index 0000000..a818a74 --- /dev/null +++ b/gitoid/ctest.sh @@ -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}" + diff --git a/gitoid/src/ffi/gitoid.rs b/gitoid/src/ffi/gitoid.rs index 2f1fcce..d270048 100644 --- a/gitoid/src/ffi/gitoid.rs +++ b/gitoid/src/ffi/gitoid.rs @@ -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(); }; } diff --git a/gitoid/src/gitoid.rs b/gitoid/src/gitoid.rs index edc173c..e0dde39 100644 --- a/gitoid/src/gitoid.rs +++ b/gitoid/src/gitoid.rs @@ -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; @@ -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; @@ -49,6 +45,7 @@ where value: GenericArray, } +/// cbindgen:ignore const GITOID_URL_SCHEME: &str = "gitoid"; impl GitOid @@ -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 { @@ -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))?; diff --git a/gitoid/src/hash_algorithm.rs b/gitoid/src/hash_algorithm.rs index ea9baab..12c8fb3 100644 --- a/gitoid/src/hash_algorithm.rs +++ b/gitoid/src/hash_algorithm.rs @@ -29,6 +29,7 @@ macro_rules! impl_hash_algorithm { impl Sealed for $type {} impl HashAlgorithm for $type { + /// cbindgen:ignore const NAME: &'static str = $name; } }; diff --git a/gitoid/src/object_type.rs b/gitoid/src/object_type.rs index 6f6bcd9..7557163 100644 --- a/gitoid/src/object_type.rs +++ b/gitoid/src/object_type.rs @@ -60,6 +60,7 @@ macro_rules! define_object_type { impl Sealed for $name {} impl ObjectType for $name { + /// cbindgen:ignore const NAME: &'static str = $s; } }; diff --git a/omnibor/Cargo.toml b/omnibor/Cargo.toml index 26e30b6..0150605 100644 --- a/omnibor/Cargo.toml +++ b/omnibor/Cargo.toml @@ -11,4 +11,4 @@ repository = "https://github.com/omnibor/omnibor-rs" version = "0.1.7" [dependencies] -gitoid = "0.3.0" +gitoid = "0.4.0"