Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use winresource instead of winres #44

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

Aerocatia
Copy link
Contributor

winresource is a more updated fork of the winres crate. winres does not work when cross-compiling from Linux, and it did not work for me when using mingw-w64 on a Windows host either. Switching to winresource and changing the build script to check CARGO_CFG_TARGET_OS fixed both of these cases.


fn main() {
if cfg!(target_os = "windows") {
winres::WindowsResource::new().compile().unwrap();
if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the behavior difference here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To quote winresource documentation:

Please note: Using #[cfg(target_os = "windows")] in build.rs may not work as expected because build.rs is executed on the host. This means that target_os is always equal to host_os when compiling build.rs. E.g. if we use rustc on Linux and want to cross-compile binaries that run on Windows, target_os in build.rs is "linux". However, CARGO_CFG_TARGET_OS should always be defined and contains the actual target operating system, though it can only be checked at runtime of the build script.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so that's because build script is always compiled for the host os. Understood, what an easy footgun 😅

@saschanaz saschanaz merged commit 685f814 into saschanaz:main Oct 8, 2024
2 checks passed
@saschanaz
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants