From 9b3c80eaccf9343ccfb61a4e430e7b52f434c061 Mon Sep 17 00:00:00 2001 From: "Ya-wen, Jeng" Date: Thu, 14 Aug 2025 21:19:56 +0800 Subject: [PATCH] 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"); -}