Skip to content

Commit

Permalink
fix: set Windows executable metadata when cross-compiling
Browse files Browse the repository at this point in the history
Our build script only worked when compiling from a Windows host to a
Windows target.
  • Loading branch information
AlexTMjugador committed Nov 23, 2024
1 parent 90ad926 commit 92a231f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/packsquash_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
13 changes: 8 additions & 5 deletions packages/packsquash_cli/build.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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",
Expand All @@ -63,6 +69,3 @@ fn add_executable_metadata() {
.compile()
.expect("Windows executable resource build failure");
}

#[cfg(not(windows))]
fn add_executable_metadata() {}

0 comments on commit 92a231f

Please sign in to comment.