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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
83 changes: 75 additions & 8 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,14 +49,86 @@ 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: MacOS - GMP library path
if: matrix.os.name == 'macOS'
run: echo "LIBRARY_PATH=/opt/homebrew/lib:$LIBRARY_PATH" >> $GITHUB_ENV

- name: Windows - Download MPIR
if: matrix.os.name == 'Windows'
run: git clone https://github.com/Chia-Network/mpir_gc_x64.git

- 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
53 changes: 41 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,48 @@ 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-search=native={}",
src_dir
.parent()
.unwrap()
.join("mpir_gc_x64")
.to_str()
.unwrap()
);

println!("cargo:rustc-link-lib=static=mpir");
} 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