xref: /wasmtime-44.0.1/crates/fiber/build.rs (revision 3e9eca8b)
1 use std::env;
2 use wasmtime_versioned_export_macros::versioned_suffix;
3 
main()4 fn main() {
5     let mut build = cc::Build::new();
6     let arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
7     let os = env::var("CARGO_CFG_TARGET_OS").unwrap();
8 
9     // NB: Technically `cfg(sanitize = "address")` is not stable and requires a
10     // `#![feature]` but sort of abuse the fact that cfgs are "leaked" through
11     // into Cargo ungated via `--print cfg`. Translate that to `cfg(asan)` for
12     // us to write down in the code.
13     println!("cargo:rustc-check-cfg=cfg(asan)");
14     match env::var("CARGO_CFG_SANITIZE") {
15         Ok(s) if s == "address" => {
16             println!("cargo:rustc-cfg=asan");
17         }
18         _ => {}
19     }
20 
21     if os == "windows" {
22         println!("cargo:rerun-if-changed=src/windows.c");
23         build.file("src/windows.c");
24         build.define("VERSIONED_SUFFIX", Some(versioned_suffix!()));
25     } else {
26         // assume that this is included via inline assembly in the crate itself,
27         // and the crate will otherwise have a `compile_error!` for unsupported
28         // platforms.
29         println!("cargo:rerun-if-changed=build.rs");
30         return;
31     }
32     build.define(&format!("CFG_TARGET_OS_{os}"), None);
33     build.define(&format!("CFG_TARGET_ARCH_{arch}"), None);
34     build.compile("wasmtime-fiber");
35 }
36