use std::path::Path;
use std::{env, fs};
use cargo_metadata::{MetadataCommand, Package};
fn main() {
if env::var_os("CARGO_CFG_HYPERLIGHT").is_none() {
return;
}
println!("cargo:rerun-if-changed=.");
let mut cfg = cc::Build::new();
let metadata = MetadataCommand::new().exec().unwrap();
let wasmtime_package: Option<&Package> =
metadata.packages.iter().find(|p| *p.name == "wasmtime");
let version_number = match wasmtime_package {
Some(pkg) => pkg.version.clone(),
None => panic!("wasmtime dependency not found"),
};
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("metadata.rs");
let version_number_string = format!("{:\0<32}", version_number.to_string());
let file_contents = format!(
r#"
// The section name beginning with .note is important, otherwise the linker will not include it in the binary.
#[used]
#[link_section = ".note_hyperlight_metadata"]
static WASMTIME_VERSION_NUMBER: [u8; 32] = *b"{}";
"#,
version_number_string
);
fs::write(dest_path, file_contents).unwrap();
cfg.include("src/include");
cfg.file("src/platform.c");
if cfg!(windows) {
env::set_var("AR_x86_64_unknown_none", "llvm-ar");
}
cfg.compile("wasmtime-hyperlight-platform");
println!("cargo::rerun-if-env-changed=WIT_WORLD");
println!("cargo::rerun-if-env-changed=WIT_WORLD_NAME");
println!("cargo::rustc-check-cfg=cfg(component)");
if env::var_os("WIT_WORLD").is_some() {
println!("cargo::rustc-cfg=component");
}
cfg_aliases::cfg_aliases! {
gdb: { all(feature = "gdb", debug_assertions) },
pulley: { feature = "pulley" },
}
}