| 1 |
use std::env; |
| 2 |
use std::path::PathBuf; |
| 3 |
|
| 4 |
fn main() { |
| 5 |
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or(String::new()); |
| 6 |
let target_family = env::var("CARGO_CFG_TARGET_FAMILY").unwrap_or(String::new()); |
| 7 |
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap()); |
| 8 |
|
| 9 |
if target_family != "wasm" { |
| 10 |
return; |
| 11 |
} |
| 12 |
|
| 13 |
if target_arch != "wasm32" { |
| 14 |
panic!("only wasm32 supports cabi-realloc right now"); |
| 15 |
} |
| 16 |
|
| 17 |
let mut src = env::current_dir().unwrap(); |
| 18 |
src.push("src"); |
| 19 |
src.push("rt"); |
| 20 |
src.push("libwit_bindgen_cabi.a"); |
| 21 |
|
| 22 |
let dst_name = format!( |
| 23 |
"wit_bindgen_cabi{}", |
| 24 |
env!("CARGO_PKG_VERSION").replace(".", "_") |
| 25 |
); |
| 26 |
let dst = out_dir.join(format!("lib{dst_name}.a")); |
| 27 |
|
| 28 |
std::fs::copy(&src, &dst).unwrap(); |
| 29 |
|
| 30 |
println!("cargo:rustc-link-lib=static={dst_name}"); |
| 31 |
println!("cargo:rustc-link-search=native={}", out_dir.display()); |
| 32 |
} |