From d43d386e699bb06895cf72b7f7d55542185576da Mon Sep 17 00:00:00 2001 From: "Ya-wen, Jeng" Date: Thu, 14 Aug 2025 10:18:56 +0800 Subject: [PATCH 1/6] chore: update Rust toolchain to version 1.89.0 in README and CI configuration --- .github/workflows/build-and-test.yml | 10 +++++----- README.md | 2 +- crates/README.md | 2 +- rust-toolchain.toml | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index c2e83a2..bf24dee 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -45,7 +45,7 @@ jobs: - name: Install Rust uses: dtolnay/rust-toolchain@stable with: - toolchain: "1.81.0" + toolchain: "1.89.0" targets: ${{ matrix.target }} - name: Build run: cargo build --target ${{ matrix.target }} @@ -63,7 +63,7 @@ jobs: - name: Install Rust uses: dtolnay/rust-toolchain@stable with: - toolchain: "1.81.0" + toolchain: "1.89.0" targets: ${{ matrix.target }} - name: Install Android NDK run: cargo install cargo-ndk @@ -77,7 +77,7 @@ jobs: - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: - toolchain: "1.81.0" + toolchain: "1.89.0" override: true - name: Run tests run: cargo test @@ -89,7 +89,7 @@ jobs: - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: - toolchain: "1.81.0" + toolchain: "1.89.0" override: true - name: Run tests run: cargo test @@ -101,7 +101,7 @@ jobs: - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: - toolchain: "1.81.0" + toolchain: "1.89.0" override: true - name: Run tests run: cargo test diff --git a/README.md b/README.md index 5066102..cc07a2e 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This project provides a Rust adapter for compiling and linking [Rapidsnark](http ### Rust toolchain ``` -cargo 1.81.0 (2dbb1af80 2024-08-20) +cargo 1.89.0 (c24e10642 2025-06-23) ``` ## Usage diff --git a/crates/README.md b/crates/README.md index 5066102..cc07a2e 100644 --- a/crates/README.md +++ b/crates/README.md @@ -9,7 +9,7 @@ This project provides a Rust adapter for compiling and linking [Rapidsnark](http ### Rust toolchain ``` -cargo 1.81.0 (2dbb1af80 2024-08-20) +cargo 1.89.0 (c24e10642 2025-06-23) ``` ## Usage diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 1de01fa..b67e7d5 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.81.0" +channel = "1.89.0" From 55b04c95fac8d02a5fca0d21181a08ddabb6104d Mon Sep 17 00:00:00 2001 From: "Ya-wen, Jeng" Date: Thu, 14 Aug 2025 10:22:06 +0800 Subject: [PATCH 2/6] chore: remove rust-toolchain.toml and update CI configuration to use actions/checkout@v5 --- .github/workflows/build-and-test.yml | 198 +++++++++++++-------------- rust-toolchain.toml | 2 - 2 files changed, 99 insertions(+), 101 deletions(-) delete mode 100644 rust-toolchain.toml diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index bf24dee..76c14b8 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -1,107 +1,107 @@ name: Build and Test on: - push: - pull_request: - types: - - opened - - synchronize - - reopened - - ready_for_review + push: + pull_request: + types: + - opened + - synchronize + - reopened + - ready_for_review env: - CARGO_TERM_COLOR: always + CARGO_TERM_COLOR: always jobs: - clippy_check: - runs-on: ubuntu-latest - if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name - env: - RUSTFLAGS: "-Dwarnings" # Make sure CI fails on all warnings, including Clippy lints - steps: - - uses: actions/checkout@v4 - - name: Run Clippy - run: cargo clippy --all-targets --all-features - lint: - runs-on: ubuntu-latest - if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name - steps: - - uses: actions/checkout@v4 + clippy_check: + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + env: + RUSTFLAGS: "-Dwarnings" # Make sure CI fails on all warnings, including Clippy lints + steps: + - uses: actions/checkout@v5 + - name: Run Clippy + run: cargo clippy --all-targets --all-features + lint: + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + steps: + - uses: actions/checkout@v5 - - name: Check formatting - run: cargo fmt --all -- --check - build-ios: - runs-on: macos-latest - if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name - strategy: - matrix: - target: - - aarch64-apple-ios - - aarch64-apple-ios-sim - - x86_64-apple-ios - steps: - - name: Checkout Repository - uses: actions/checkout@v4 - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - with: - toolchain: "1.89.0" - targets: ${{ matrix.target }} - - name: Build - run: cargo build --target ${{ matrix.target }} - build-android: - runs-on: ubuntu-latest - if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name - strategy: - matrix: - target: - - x86_64-linux-android - - aarch64-linux-android - steps: - - name: Checkout Repository - uses: actions/checkout@v4 - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - with: - toolchain: "1.89.0" - targets: ${{ matrix.target }} - - name: Install Android NDK - run: cargo install cargo-ndk - - name: Build - run: cargo ndk -t ${{ matrix.target }} build - test-linux: - runs-on: ubuntu-latest - if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name - steps: - - uses: actions/checkout@v4 - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: "1.89.0" - override: true - - name: Run tests - run: cargo test - test-macOS: - runs-on: macos-latest - if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name - steps: - - uses: actions/checkout@v4 - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: "1.89.0" - override: true - - name: Run tests - run: cargo test - test-macOS-x86_64: - runs-on: macos-13 - if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name - steps: - - uses: actions/checkout@v4 - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: "1.89.0" - override: true - - name: Run tests - run: cargo test + - name: Check formatting + run: cargo fmt --all -- --check + build-ios: + runs-on: macos-latest + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + strategy: + matrix: + target: + - aarch64-apple-ios + - aarch64-apple-ios-sim + - x86_64-apple-ios + steps: + - name: Checkout Repository + uses: actions/checkout@v5 + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: "1.89.0" + targets: ${{ matrix.target }} + - name: Build + run: cargo build --target ${{ matrix.target }} + build-android: + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + strategy: + matrix: + target: + - x86_64-linux-android + - aarch64-linux-android + steps: + - name: Checkout Repository + uses: actions/checkout@v5 + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: "1.89.0" + targets: ${{ matrix.target }} + - name: Install Android NDK + run: cargo install cargo-ndk + - name: Build + run: cargo ndk -t ${{ matrix.target }} build + test-linux: + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + steps: + - uses: actions/checkout@v5 + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: "1.89.0" + override: true + - name: Run tests + run: cargo test + test-macOS: + runs-on: macos-latest + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + steps: + - uses: actions/checkout@v5 + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: "1.89.0" + override: true + - name: Run tests + run: cargo test + test-macOS-x86_64: + runs-on: macos-13 + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + steps: + - uses: actions/checkout@v5 + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: "1.89.0" + override: true + - name: Run tests + run: cargo test diff --git a/rust-toolchain.toml b/rust-toolchain.toml deleted file mode 100644 index b67e7d5..0000000 --- a/rust-toolchain.toml +++ /dev/null @@ -1,2 +0,0 @@ -[toolchain] -channel = "1.89.0" From 50d71afbd02846563aae13cefd8358ed1f8e1ef9 Mon Sep 17 00:00:00 2001 From: "Ya-wen, Jeng" Date: Thu, 14 Aug 2025 10:54:36 +0800 Subject: [PATCH 3/6] fix: improve error messages and formatting in build script --- crates/build.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/build.rs b/crates/build.rs index 0aef23c..58fc58e 100644 --- a/crates/build.rs +++ b/crates/build.rs @@ -22,11 +22,11 @@ fn main() { .arg(rapidsnark_script_path.to_str().unwrap()) .spawn(); if let Err(e) = child_process { - panic!("Failed to spawn rapidsnark download: {}", e); + panic!("Failed to spawn rapidsnark download: {e}"); } let status = child_process.unwrap().wait(); if let Err(e) = status { - panic!("Failed to wait for rapidsnark download: {}", e); + panic!("Failed to wait for rapidsnark download: {e}"); } else if !status.unwrap().success() { panic!("Failed to wait for rapidsnark download"); } @@ -49,7 +49,7 @@ fn main() { ); println!("cargo:rustc-link-lib=static=rapidsnark"); - println!("cargo:rustc-link-lib={}", cpp_stdlib); + println!("cargo:rustc-link-lib={cpp_stdlib}"); if target.contains("android") { // pthread is included in libc in android println!("cargo:rustc-link-lib=c"); @@ -83,11 +83,10 @@ fn android() { let lib_path = sysroot_libs_path.join("libc++_shared.so"); assert!( lib_path.exists(), - "Error: Source file {:?} does not exist", - lib_path + "Error: Source file {lib_path:?} does not exist" ); let dest_dir = Path::new(&output_path).join(env::var("CARGO_NDK_ANDROID_TARGET").unwrap()); - println!("cargo:rerun-if-changed={}", dest_dir.display()); + println!("cargo:rerun-if-changed={dest_dir:?}"); if !dest_dir.exists() { fs::create_dir_all(&dest_dir).unwrap(); } From 8231d16df103de6812168fcefb3f9e985912cf55 Mon Sep 17 00:00:00 2001 From: "Ya-wen, Jeng" Date: Thu, 14 Aug 2025 14:17:13 +0800 Subject: [PATCH 4/6] feat: add iOS stub source file generation in build script --- crates/build.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/crates/build.rs b/crates/build.rs index 58fc58e..80dde3f 100644 --- a/crates/build.rs +++ b/crates/build.rs @@ -11,6 +11,11 @@ fn main() { let out_dir = env::var("OUT_DIR").expect("OUT_DIR not set"); let arch = target.split('-').next().unwrap(); + // Create the stub source file + if target.contains("apple-ios") { + stub_for_ios(&out_dir); + } + // Try to list contents of the target directory let rapidsnark_path = Path::new(&out_dir).join(Path::new("rapidsnark")); // If the rapidsnark repo is not downloaded, download it @@ -93,3 +98,23 @@ fn android() { fs::copy(lib_path, Path::new(&dest_dir).join("libc++_shared.so")).unwrap(); } } + +fn stub_for_ios(out_dir: &str) { + let stub_path = Path::new(&out_dir).join("chkstk_stub.c"); + fs::write( + &stub_path, + r#" + void __chkstk_darwin(void) {} + "#, + ) + .unwrap(); + + // Compile the stub into a static lib + cc::Build::new() + .file(&stub_path) + .out_dir(&out_dir) + .compile("chkstk_stub"); + + println!("cargo:rustc-link-search=native={out_dir}"); + println!("cargo:rustc-link-lib=static=chkstk_stub"); +} From 33e7c86ff58fbd486b8ffee0282c7b9c79ac705c Mon Sep 17 00:00:00 2001 From: "Ya-wen, Jeng" Date: Thu, 14 Aug 2025 14:35:56 +0800 Subject: [PATCH 5/6] fix: correct out_dir parameter usage in iOS stub compilation --- crates/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/build.rs b/crates/build.rs index 80dde3f..4af36d9 100644 --- a/crates/build.rs +++ b/crates/build.rs @@ -112,7 +112,7 @@ fn stub_for_ios(out_dir: &str) { // Compile the stub into a static lib cc::Build::new() .file(&stub_path) - .out_dir(&out_dir) + .out_dir(out_dir) .compile("chkstk_stub"); println!("cargo:rustc-link-search=native={out_dir}"); From 9b3c80eaccf9343ccfb61a4e430e7b52f434c061 Mon Sep 17 00:00:00 2001 From: "Ya-wen, Jeng" Date: Thu, 14 Aug 2025 21:19:56 +0800 Subject: [PATCH 6/6] feat: integrate chkstk_stub crate and simplify iOS stub handling in build script --- Cargo.lock | 10 ++++++++++ crates/Cargo.toml | 1 + crates/build.rs | 26 ++------------------------ 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 656be4d..b9f1428 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,6 +25,15 @@ dependencies = [ "shlex", ] +[[package]] +name = "chkstk_stub" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "047f6ab2f3b9bcaf23b593d1580898e4244d27eadf1a1fae99212ee5735d3d1c" +dependencies = [ + "cc", +] + [[package]] name = "fnv" version = "1.0.7" @@ -86,6 +95,7 @@ version = "0.1.1" dependencies = [ "anyhow", "cc", + "chkstk_stub", "num-bigint", "num-traits", ] diff --git a/crates/Cargo.toml b/crates/Cargo.toml index 5494ef3..26dc4f2 100644 --- a/crates/Cargo.toml +++ b/crates/Cargo.toml @@ -17,3 +17,4 @@ num-traits = "0.2.19" [build-dependencies] cc = "1.0" +chkstk_stub = "0.1" diff --git a/crates/build.rs b/crates/build.rs index 4af36d9..80a5ca9 100644 --- a/crates/build.rs +++ b/crates/build.rs @@ -11,10 +11,8 @@ fn main() { let out_dir = env::var("OUT_DIR").expect("OUT_DIR not set"); let arch = target.split('-').next().unwrap(); - // Create the stub source file - if target.contains("apple-ios") { - stub_for_ios(&out_dir); - } + // See: https://github.com/zkmopro/chkstk_stub + chkstk_stub::build(); // Try to list contents of the target directory let rapidsnark_path = Path::new(&out_dir).join(Path::new("rapidsnark")); @@ -98,23 +96,3 @@ fn android() { fs::copy(lib_path, Path::new(&dest_dir).join("libc++_shared.so")).unwrap(); } } - -fn stub_for_ios(out_dir: &str) { - let stub_path = Path::new(&out_dir).join("chkstk_stub.c"); - fs::write( - &stub_path, - r#" - void __chkstk_darwin(void) {} - "#, - ) - .unwrap(); - - // Compile the stub into a static lib - cc::Build::new() - .file(&stub_path) - .out_dir(out_dir) - .compile("chkstk_stub"); - - println!("cargo:rustc-link-search=native={out_dir}"); - println!("cargo:rustc-link-lib=static=chkstk_stub"); -}