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"); +}