Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests on multiple platforms and fix windows MPIR issue #211

Merged
merged 31 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 85 additions & 8 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ on:
branches:
- "**"

concurrency:
group: ${{ github.event_name == 'pull_request' && format('{0}-{1}', github.workflow_ref, github.event.pull_request.number) || github.run_id }}
cancel-in-progress: true

permissions:
id-token: write
contents: read
Expand All @@ -32,16 +36,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,14 +53,92 @@ 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: Setup library path on MacOS
if: matrix.os.name == 'macOS'
run: echo "LIBRARY_PATH=/opt/homebrew/lib:$LIBRARY_PATH" >> $GITHUB_ENV

- name: Install MPIR on Windows
if: matrix.os.name == 'Windows'
run: |
git clone https://github.com/Chia-Network/mpir_gc_x64.git
"$(Get-Location)/mpir_gc_x64" | Out-File -Append -FilePath $env:GITHUB_PATH

- name: Install libclang-dev on Linux
if: matrix.os.name == 'Ubuntu'
run: sudo apt-get install libclang-dev -y

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

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

build_crate:
name: Build crate
needs: [lint, test]
runs-on: ubuntu-latest
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v4

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

- name: Build
run: cargo build --release

- name: Prepare for publish
run: cp -r src rust_bindings/cpp
run: |
cd rust_bindings
cp -r ../src cpp
git clone https://github.com/Chia-Network/mpir_gc_x64.git

- name: Publish to crates.io (dry run)
# We use `--allow-dirty` because the `cpp` folder is copied into the working directory.
Expand Down
52 changes: 40 additions & 12 deletions rust_bindings/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::env;
use std::path::PathBuf;
use std::str::FromStr;

use cmake::Config;

Expand All @@ -27,18 +26,47 @@ fn main() {
.define("BUILD_PYTHON", "OFF")
.build();

println!(
"cargo:rustc-link-search=native={}",
PathBuf::from_str(dst.display().to_string().as_str())
.unwrap()
.join("build")
.join("lib")
.join("static")
.to_str()
.unwrap()
);
println!("cargo:rustc-link-lib=static=chiavdfc");
println!("cargo:rustc-link-lib=gmp");

if cfg!(target_os = "windows") {
let build_type = if cfg!(debug_assertions) {
"Debug"
} else {
"Release"
};

println!(
"cargo:rustc-link-search=native={}",
dst.join("build")
.join("lib")
.join("static")
.join(build_type)
.to_str()
.unwrap()
);

println!("cargo:rustc-link-lib=static=mpir");
println!(
"cargo:rustc-link-search=native={}",
src_dir
.parent()
.unwrap()
.join("mpir_gc_x64")
.to_str()
.unwrap()
);
} else {
println!(
"cargo:rustc-link-search=native={}",
dst.join("build")
.join("lib")
.join("static")
.to_str()
.unwrap()
);

println!("cargo:rustc-link-lib=gmp");
}

let bindings = bindgen::Builder::default()
.header(manifest_dir.join("wrapper.h").to_str().unwrap())
Expand Down
Loading