Skip to content

Commit 5015a16

Browse files
authored
Merge pull request #211 from Chia-Network/windows-test
Run tests on multiple platforms and fix windows MPIR issue
2 parents 56e2f89 + 93166a0 commit 5015a16

File tree

2 files changed

+125
-20
lines changed

2 files changed

+125
-20
lines changed

.github/workflows/rust.yml

+85-8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ on:
1010
branches:
1111
- "**"
1212

13+
concurrency:
14+
group: ${{ github.event_name == 'pull_request' && format('{0}-{1}', github.workflow_ref, github.event.pull_request.number) || github.run_id }}
15+
cancel-in-progress: true
16+
1317
permissions:
1418
id-token: write
1519
contents: read
@@ -32,16 +36,11 @@ jobs:
3236
cd rust_bindings
3337
cargo fuzz list | xargs -I "%" sh -c "cargo +nightly fuzz run % -- -max_total_time=600 || exit 255"
3438
35-
build_crate:
36-
name: Build crate
39+
lint:
40+
name: Lint
3741
runs-on: ubuntu-latest
38-
strategy:
39-
fail-fast: false
40-
4142
steps:
4243
- uses: actions/checkout@v4
43-
with:
44-
fetch-depth: 0
4544

4645
- name: Set up Rust
4746
uses: dtolnay/rust-toolchain@stable
@@ -54,14 +53,92 @@ jobs:
5453
- name: Clippy
5554
run: cargo clippy
5655

56+
test:
57+
name: Test (${{ matrix.os.name }} ${{ matrix.arch.name }})
58+
runs-on: ${{ matrix.os.runs-on[matrix.arch.matrix] }}
59+
60+
strategy:
61+
fail-fast: false
62+
matrix:
63+
os:
64+
- name: macOS
65+
matrix: macos
66+
runs-on:
67+
arm: [macos-13-arm64]
68+
intel: [macos-13]
69+
cibw-archs-macos:
70+
arm: arm64
71+
intel: x86_64
72+
- name: Ubuntu
73+
matrix: ubuntu
74+
runs-on:
75+
arm: [Linux, ARM64]
76+
intel: [ubuntu-latest]
77+
- name: Windows
78+
matrix: windows
79+
runs-on:
80+
intel: [windows-latest]
81+
82+
arch:
83+
- name: ARM
84+
matrix: arm
85+
- name: Intel
86+
matrix: intel
87+
88+
exclude:
89+
- os:
90+
name: Windows
91+
matrix: windows
92+
runs-on:
93+
intel: [windows-latest]
94+
arch:
95+
name: ARM
96+
matrix: arm
97+
98+
steps:
99+
- uses: actions/checkout@v4
100+
101+
- name: Setup library path on MacOS
102+
if: matrix.os.name == 'macOS'
103+
run: echo "LIBRARY_PATH=/opt/homebrew/lib:$LIBRARY_PATH" >> $GITHUB_ENV
104+
105+
- name: Install MPIR on Windows
106+
if: matrix.os.name == 'Windows'
107+
run: |
108+
git clone https://github.com/Chia-Network/mpir_gc_x64.git
109+
"$(Get-Location)/mpir_gc_x64" | Out-File -Append -FilePath $env:GITHUB_PATH
110+
111+
- name: Install libclang-dev on Linux
112+
if: matrix.os.name == 'Ubuntu'
113+
run: sudo apt-get install libclang-dev -y
114+
115+
- name: Set up Rust
116+
uses: dtolnay/rust-toolchain@stable
117+
57118
- name: Tests
58119
run: cargo test && cargo test --release
59120

121+
build_crate:
122+
name: Build crate
123+
needs: [lint, test]
124+
runs-on: ubuntu-latest
125+
strategy:
126+
fail-fast: false
127+
128+
steps:
129+
- uses: actions/checkout@v4
130+
131+
- name: Set up Rust
132+
uses: dtolnay/rust-toolchain@stable
133+
60134
- name: Build
61135
run: cargo build --release
62136

63137
- name: Prepare for publish
64-
run: cp -r src rust_bindings/cpp
138+
run: |
139+
cd rust_bindings
140+
cp -r ../src cpp
141+
git clone https://github.com/Chia-Network/mpir_gc_x64.git
65142
66143
- name: Publish to crates.io (dry run)
67144
# We use `--allow-dirty` because the `cpp` folder is copied into the working directory.

rust_bindings/build.rs

+40-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::env;
22
use std::path::PathBuf;
3-
use std::str::FromStr;
43

54
use cmake::Config;
65

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

30-
println!(
31-
"cargo:rustc-link-search=native={}",
32-
PathBuf::from_str(dst.display().to_string().as_str())
33-
.unwrap()
34-
.join("build")
35-
.join("lib")
36-
.join("static")
37-
.to_str()
38-
.unwrap()
39-
);
4029
println!("cargo:rustc-link-lib=static=chiavdfc");
41-
println!("cargo:rustc-link-lib=gmp");
30+
31+
if cfg!(target_os = "windows") {
32+
let build_type = if cfg!(debug_assertions) {
33+
"Debug"
34+
} else {
35+
"Release"
36+
};
37+
38+
println!(
39+
"cargo:rustc-link-search=native={}",
40+
dst.join("build")
41+
.join("lib")
42+
.join("static")
43+
.join(build_type)
44+
.to_str()
45+
.unwrap()
46+
);
47+
48+
println!("cargo:rustc-link-lib=static=mpir");
49+
println!(
50+
"cargo:rustc-link-search=native={}",
51+
src_dir
52+
.parent()
53+
.unwrap()
54+
.join("mpir_gc_x64")
55+
.to_str()
56+
.unwrap()
57+
);
58+
} else {
59+
println!(
60+
"cargo:rustc-link-search=native={}",
61+
dst.join("build")
62+
.join("lib")
63+
.join("static")
64+
.to_str()
65+
.unwrap()
66+
);
67+
68+
println!("cargo:rustc-link-lib=gmp");
69+
}
4270

4371
let bindings = bindgen::Builder::default()
4472
.header(manifest_dir.join("wrapper.h").to_str().unwrap())

0 commit comments

Comments
 (0)