diff --git a/codex-rs/windows-sandbox-rs/BUILD.bazel b/codex-rs/windows-sandbox-rs/BUILD.bazel index 31dbd3d24..7e0de41ec 100644 --- a/codex-rs/windows-sandbox-rs/BUILD.bazel +++ b/codex-rs/windows-sandbox-rs/BUILD.bazel @@ -3,4 +3,7 @@ load("//:defs.bzl", "codex_rust_crate") codex_rust_crate( name = "windows-sandbox-rs", crate_name = "codex_windows_sandbox", + build_script_data = [ + "codex-windows-sandbox-setup.manifest", + ], ) diff --git a/codex-rs/windows-sandbox-rs/Cargo.toml b/codex-rs/windows-sandbox-rs/Cargo.toml index 53c81f0b0..31df9ad39 100644 --- a/codex-rs/windows-sandbox-rs/Cargo.toml +++ b/codex-rs/windows-sandbox-rs/Cargo.toml @@ -1,4 +1,5 @@ [package] +build = "build.rs" edition.workspace = true license.workspace = true name = "codex-windows-sandbox" diff --git a/codex-rs/windows-sandbox-rs/build.rs b/codex-rs/windows-sandbox-rs/build.rs new file mode 100644 index 000000000..af5aec78c --- /dev/null +++ b/codex-rs/windows-sandbox-rs/build.rs @@ -0,0 +1,39 @@ +use std::env; +use std::path::PathBuf; + +const SETUP_BIN: &str = "codex-windows-sandbox-setup"; +const SETUP_MANIFEST: &str = "codex-windows-sandbox-setup.manifest"; + +fn main() { + println!("cargo:rerun-if-changed={SETUP_MANIFEST}"); + + if env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") { + return; + } + + let manifest_path = PathBuf::from( + env::var_os("CARGO_MANIFEST_DIR") + .expect("CARGO_MANIFEST_DIR should be set for build scripts"), + ) + .join(SETUP_MANIFEST); + let manifest_path = manifest_path.display(); + + // Keep this scoped to the setup helper so Codex binaries that link the + // library do not inherit any resource metadata from this package. + match ( + env::var("CARGO_CFG_TARGET_ENV").as_deref(), + env::var("CARGO_CFG_TARGET_ABI").as_deref(), + ) { + (Ok("msvc"), _) => { + println!("cargo:rustc-link-arg-bin={SETUP_BIN}=/MANIFEST:EMBED"); + println!("cargo:rustc-link-arg-bin={SETUP_BIN}=/MANIFESTINPUT:{manifest_path}"); + } + (Ok("gnu"), Ok("llvm")) => { + println!("cargo:rustc-link-arg-bin={SETUP_BIN}=-Wl,-Xlink=/manifest:embed"); + println!( + "cargo:rustc-link-arg-bin={SETUP_BIN}=-Wl,-Xlink=/manifestinput:{manifest_path}" + ); + } + _ => {} + } +} diff --git a/codex-rs/windows-sandbox-rs/codex-windows-sandbox-setup.manifest b/codex-rs/windows-sandbox-rs/codex-windows-sandbox-setup.manifest new file mode 100644 index 000000000..14807962f --- /dev/null +++ b/codex-rs/windows-sandbox-rs/codex-windows-sandbox-setup.manifest @@ -0,0 +1,10 @@ + + + + + + + + + +