-
Notifications
You must be signed in to change notification settings - Fork 42
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
Rust 1.61 in Linux does no add resources to the EXE #40
Comments
You can use https://crates.io/crates/version_check to do it conditionally. |
i just downgraded to 1.60 because i wasted 2.5 days with this cross compilation problem |
I probably run into the same problem with my tp-note/build.rs. |
This also affects Windows/MINGW. [EDIT: deleted some premature conclusions. My attempts to use @rodrigorc's solution 1 as a user-side workaround failed because they conflicted with cargo directives emitted by the unmodified Can confirm that PR #41 (which implements solution 1 on my rust version) fixes the issue for me. Leaving my ugly user-side workaround here just in case it might work as a stop-gap for someone who cannot use the PR branch: println!("cargo:rustc-link-arg=-Wl,--whole-archive");
println!("cargo:rustc-link-arg=-Wl,-Bstatic");
println!("cargo:rustc-link-arg=-lresource");
println!("cargo:rustc-link-arg=-Wl,--no-whole-archive"); |
This bug breaks this crate completely for up to date Rust toolchains. @mxre would it be possible to accept PR #41 and publish the fix on crates.io? The crate silently stops working whenever someone updates their toolchain to Rust 1.61 or higher, leading to unexpected outcomes and troubleshooting for every person who uses it. |
A temporary solution until the crate gets fixed would be to add @Nilstrieb's repo to Cargo.toml instead:
|
I know. But then you cannot publish it on crates.io. Ultimately, if this bug is not fixed, a fork is required. |
In early November 2022, I wrote an email to @mxre with the question whether he could accept PR #41 or give a short feedback on how to proceed. I did not receive an answer. Hence, with utmost respect for the original work, I forked the repository and created a new crate that is maintained again. https://github.com/BenjaminRi/winresource Everything is identical, except that this bug is fixed and the name is |
See * [Rust 1.61 in Linux does no add resources to the EXE · Issue #40 · mxre/winres · GitHub](mxre/winres#40 (comment)) * [winresource - crates.io: Rust Package Registry](https://crates.io/crates/winresource)
Fix mxre#40 by using different linking flags depending on rustc version
* winres is unmaintained, switch to winresource mxre/winres#40 (comment) * Double colon syntax for build script outputs is preferred https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script
Since Rust 1.61 1, the linker no longer includes the static libraries with the
--whole-archive
flag. This means that theresource.o
file is only added to the final EXE if it defines any symbol undefined elsewhere. But resource objects do not define any symbol at all!There are several solutions for this that I can think of:
Solution n.1: The fancy one.
This forces the
--whole-archive
flag for this particular library, restoring the old behavior. The drawback is that I think it will not be backwards compatible, it will require Rust 1.61.Solution n.2: The classic.
By passing the name of the object file instead of the library it will link the given object into the EXE, unconditionally. The nice thing is that it is backwards compatible. And the call to AR is not longer needed.
Solution #3: The hack.
And then removing the call to AR. Then when linking the static library
resource
the linker will find thelibresource.a
, that is not an archive but an object, thus it is included unconditionally. It is similar to n.2 but it still uses thestatic
flag.The text was updated successfully, but these errors were encountered: