Skip to content

Commit

Permalink
Build and Test the rust bindings on all platforms (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
emlowe authored Nov 1, 2024
2 parents 582ad09 + 315489d commit 82367da
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 9 deletions.
67 changes: 60 additions & 7 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,11 @@ jobs:
cd rust-bindings
cargo fuzz list | xargs -I "%" sh -c "cargo +nightly fuzz run % -- -max_total_time=600 || exit 255"
build_crate:
name: Build crate
lint:
name: Lint
runs-on: ubuntu-latest
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
Expand All @@ -54,9 +49,67 @@ jobs:
- name: Clippy
run: cargo clippy

test:
name: Test (${{ matrix.os.name }} ${{ matrix.arch.name }})
runs-on: ${{ matrix.os.runs-on[matrix.arch.matrix] }}

strategy:
fail-fast: false
matrix:
os:
- name: macOS
matrix: macos
runs-on:
arm: [macos-13-arm64]
intel: [macos-13]
cibw-archs-macos:
arm: arm64
intel: x86_64
- name: Ubuntu
matrix: ubuntu
runs-on:
arm: [Linux, ARM64]
intel: [ubuntu-latest]
- name: Windows
matrix: windows
runs-on:
intel: [windows-latest]

arch:
- name: ARM
matrix: arm
- name: Intel
matrix: intel

exclude:
- os:
name: Windows
matrix: windows
runs-on:
intel: [windows-latest]
arch:
name: ARM
matrix: arm

steps:
- uses: actions/checkout@v4

- name: Set up Rust
uses: dtolnay/rust-toolchain@stable

- name: Tests
run: cargo test && cargo test --release

build_crate:
name: Build crate
runs-on: ubuntu-latest
needs: [lint, test]
steps:
- uses: actions/checkout@v4

- name: Set up Rust
uses: dtolnay/rust-toolchain@stable

- name: Build
run: cargo build --release

Expand Down
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ option(BUILD_STATIC_CHIAPOS_LIBRARY "Build chiapos static library (verify-only)"
IF (BUILD_STATIC_CHIAPOS_LIBRARY)
message("Build chiapos static library (verify-only)")
add_library(chiapos_static STATIC src/chacha8.c c-bindings/wrapper.cpp)
target_link_libraries(chiapos_static PUBLIC blake3)
target_include_directories(chiapos_static PUBLIC lib/include)
target_link_libraries(chiapos_static PRIVATE blake3 $<$<CXX_COMPILER_ID:MSVC>:uint128>)
target_include_directories(chiapos_static PUBLIC lib/include uint128_t)
set_target_properties(chiapos_static PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib$<0:>")
ENDIF()

Expand Down Expand Up @@ -190,6 +190,7 @@ find_package(Threads REQUIRED)

add_library(uint128 STATIC uint128_t/uint128_t.cpp)
target_include_directories(uint128 PUBLIC uint128_t)
set_target_properties(uint128 PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib$<0:>")

target_compile_features(fse PUBLIC cxx_std_17)
target_compile_features(chiapos PUBLIC cxx_std_17)
Expand All @@ -213,6 +214,7 @@ target_link_libraries(RunTests PRIVATE fse Threads::Threads Catch2::Catch2WithMa
$<$<NOT:$<PLATFORM_ID:Darwin,OpenBSD,FreeBSD,Windows>>:stdc++fs>
)


if (${CP_LINK_BLADEBIT_HARVESTER})

set(bb_defs
Expand Down
4 changes: 4 additions & 0 deletions rust-bindings/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ fn main() {
println!("cargo:rustc-link-lib=static=chiapos_static");
println!("cargo:rustc-link-lib=static=blake3");

if cfg!(target_os = "windows") {
println!("cargo:rustc-link-lib=static=uint128");
}

let bindings = bindgen::Builder::default()
.header(
cpp_dir
Expand Down

0 comments on commit 82367da

Please sign in to comment.