Skip to content

Commit

Permalink
Improve support for wasm32.
Browse files Browse the repository at this point in the history
Make emscripten visible to wasm32-unknown-unknown if emscripten is installed.
  • Loading branch information
TheVeryDarkness committed Oct 13, 2023
1 parent 163f80c commit 0df54a2
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions z3-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,26 @@ fn generate_binding(header: &str) {
"symbol_kind",
] {
let mut enum_bindings = bindgen::Builder::default()
.header(&header)
.header(header)
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate_comments(false)
.rustified_enum(format!("Z3_{}", x))
.allowlist_type(format!("Z3_{}", x));
if env::var("TARGET").unwrap() == "wasm32-unknown-emscripten" {
enum_bindings = enum_bindings.clang_arg(format!(
"--sysroot={}/upstream/emscripten/cache/sysroot",
env::var("EMSDK").expect("$EMSDK env var missing. Is emscripten installed?")
));
let target = env::var("TARGET").unwrap();
let wasm32 = target.starts_with("wasm32-unknown");
let wasm32_emscripten = target == "wasm32-unknown-emscripten";
if wasm32 {
let sysroot = env::var("EMSDK")
.map(|emsdk| format!("{}/upstream/emscripten/cache/sysroot", emsdk))
.or_else(|_err| {
env::var("EMSCRIPTEN_ROOT")
.map(|emscripten_root| format!("{}/cache/sysroot", emscripten_root))
});
if let Ok(sysroot) = sysroot {
enum_bindings = enum_bindings.clang_arg(format!("--sysroot={}", sysroot));
} else if wasm32_emscripten {
panic!("$EMSDK and $EMSCRIPTEN_ROOT env var missing. Is emscripten installed?");
}
}
enum_bindings
.generate()
Expand Down

0 comments on commit 0df54a2

Please sign in to comment.