Files
rust-discovery/crates/agent-windows/build.rs
T
2026-11-14 02:39:39 +01:00

52 lines
1.9 KiB
Rust

use std::{env, path::PathBuf, process::Command};
fn main() {
println!("cargo:rerun-if-changed=native/w32time.idl");
println!("cargo:rerun-if-changed=native/clock_rpc.c");
println!("cargo:rerun-if-changed=native/clock_endpoints.c");
if env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") {
return;
}
assert_eq!(
env::var("CARGO_CFG_TARGET_ARCH").as_deref(),
Ok("x86_64"),
"Windows clock RPC is qualified only for x86-64"
);
assert_eq!(
env::var("CARGO_CFG_TARGET_ENV").as_deref(),
Ok("gnu"),
"Windows clock RPC currently requires the qualified GNU/clang toolchain"
);
let out = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let idl = env::current_dir().unwrap().join("native/w32time.idl");
for args in [
vec!["-h", "-H", "w32time.h"],
vec!["-c", "-o", "w32time_c.c"],
] {
assert!(
Command::new("x86_64-w64-mingw32-widl")
.current_dir(&out)
.args(["--win64", "-Oif"])
.args(args)
.arg(&idl)
.status()
.expect("Install mingw-w64-tools for the generated read-only RPC stub")
.success(),
"WIDL clock stub generation failed"
);
}
// Clang implements x64 Windows SEH in the C boundary. MinGW GCC's __try
// spelling is not sufficient; do not let an RPC exception unwind into Rust.
cc::Build::new()
.compiler("clang")
.flag("--target=x86_64-w64-windows-gnu")
.flag("-fms-extensions")
.flag("-Werror")
.include(&out)
.file(out.join("w32time_c.c"))
.file("native/clock_rpc.c")
.file("native/clock_endpoints.c")
.compile("rmm_clock_rpc");
println!("cargo:rustc-link-lib=rpcrt4");
println!("cargo:rustc-link-lib=advapi32");
}