forked from gear-tech/gear
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
34 lines (25 loc) · 937 Bytes
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::{env, error::Error, path::PathBuf};
#[cfg(not(feature = "compile-alloca"))]
fn main() -> Result<(), Box<dyn Error>> {
let alloca_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?).join("alloca");
if env::var("TARGET")? == "wasm32-unknown-unknown" {
println!("cargo:rustc-link-lib=static=calloca");
println!("cargo:rustc-link-search=native={}", alloca_dir.display());
}
Ok(())
}
#[cfg(feature = "compile-alloca")]
fn main() -> Result<(), Box<dyn Error>> {
let alloca_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?).join("alloca");
let mut builder = cc::Build::new();
#[cfg(feature = "stack-clash-protection")]
builder.flag_if_supported("-fstack-clash-protection");
if option_env!("CC") == Some("clang") {
builder.flag("-flto");
}
builder
.file(alloca_dir.join("alloca.c"))
.opt_level(2)
.compile("calloca");
Ok(())
}