use anyhow::Result;
#[cfg(feature = "build-metadata")]
use built::write_built_file;
fn main() -> Result<()> {
println!("cargo:rerun-if-changed=build.rs");
#[cfg(target_os = "windows")]
{
println!("cargo:rerun-if-changed=src/hyperlight_surrogate/src/main.rs");
let out_dir = std::env::var("OUT_DIR")?;
std::fs::create_dir_all(format!("{out_dir}/hyperlight_surrogate/src"))?;
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR")?;
std::fs::copy(
format!("{manifest_dir}/src/hyperlight_surrogate/src/main.rs"),
format!("{out_dir}/hyperlight_surrogate/src/main.rs"),
)?;
std::fs::copy(
format!("{manifest_dir}/src/hyperlight_surrogate/Cargo.toml_temp_name"),
format!("{out_dir}/hyperlight_surrogate/Cargo.toml"),
)?;
let target_manifest_path = format!("{out_dir}/hyperlight_surrogate/Cargo.toml");
let target_dir = std::path::PathBuf::from(&out_dir).join("..\\..\\hls");
let profile = std::env::var("PROFILE")?;
let build_profile = if profile.to_lowercase() == "debug" {
"dev".to_string()
} else {
profile.clone()
};
std::process::Command::new("cargo")
.env("CARGO_TARGET_DIR", &target_dir)
.arg("build")
.arg("--manifest-path")
.arg(&target_manifest_path)
.arg("--profile")
.arg(build_profile)
.arg("--verbose")
.output()
.unwrap();
println!("cargo:rustc-env=PROFILE={}", profile);
let surrogate_binary_dir = std::path::PathBuf::from(&target_dir).join(profile);
println!(
"cargo:rustc-env=HYPERLIGHT_SURROGATE_DIR={}",
&surrogate_binary_dir.display()
);
}
cfg_aliases::cfg_aliases! {
gdb: { all(feature = "gdb", debug_assertions) },
kvm: { all(feature = "kvm", target_os = "linux") },
mshv: { all(any(feature = "mshv2", feature = "mshv3"), target_os = "linux") },
crashdump: { all(feature = "crashdump") },
print_debug: { all(feature = "print_debug", debug_assertions) },
mshv2: { all(feature = "mshv2", not(feature="mshv3"), target_os = "linux") },
mshv3: { all(feature = "mshv3", target_os = "linux") },
}
#[cfg(feature = "build-metadata")]
write_built_file()?;
Ok(())
}