diff --git a/packages/packsquash_cli/Cargo.toml b/packages/packsquash_cli/Cargo.toml index 0cadceedd..cbe40c551 100644 --- a/packages/packsquash_cli/Cargo.toml +++ b/packages/packsquash_cli/Cargo.toml @@ -40,7 +40,7 @@ mimalloc = { version = "0.1.43", default-features = false, features = [ "override", ] } -[target.'cfg(windows)'.build-dependencies] +[build-dependencies] winresource = "0.1.17" [[bin]] diff --git a/packages/packsquash_cli/build.rs b/packages/packsquash_cli/build.rs index 8793004e8..a8c547b66 100644 --- a/packages/packsquash_cli/build.rs +++ b/packages/packsquash_cli/build.rs @@ -1,6 +1,7 @@ //! Build helper for the `PackSquash` CLI. use std::env; +use winresource::WindowsResource; /// Initializes environment variables that will be accessible in the source /// code via the env! macro, and takes care of build-time metadata. @@ -47,9 +48,14 @@ fn main() { add_executable_metadata(); } -#[cfg(windows)] fn add_executable_metadata() { - let mut windows_resource = winresource::WindowsResource::new(); + // Build scripts are always compiled for the host target, so to make sure metadata is + // added when cross-compiling to Windows, we need to check the target OS during runtime + if env::var_os("CARGO_CFG_WINDOWS").is_none() { + return; + } + + let mut windows_resource = WindowsResource::new(); windows_resource.set("LegalCopyright", env!("CARGO_PKG_AUTHORS")); windows_resource.set( "FileDescription", @@ -63,6 +69,3 @@ fn add_executable_metadata() { .compile() .expect("Windows executable resource build failure"); } - -#[cfg(not(windows))] -fn add_executable_metadata() {}