-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking issue for #[link(kind)] connecting libraries on Windows #37403
Comments
Implement RFC 1717 Implement the first two points from #37403. r? @alexcrichton
If I specify Not sure if that's actually a problem, but maybe Rust could de-duplicate the linker arguments? |
Also, is it intentional that these changes are insta-stable? cc @vadimcn |
@dgrunwald: Could you coalesce those 30 extern blocks into one? You probably did it to keep extern declarations in the same file/module as the code using them, but this isn't really how we thought about The problem with de-duping is that most unix linkers resolve references using only libraries to the right on the command line. So if you know that Our approach so far has been to simply emit libraries in the order they appear in the source, followed by the ones specified on the command line. In order to optimize this, we'd need to provide some way of specifying library dependencies (e.g. "libraries {attached to the same extern block | within the same module | within the same source file} are guaranteed to be given to the linker in the same order"). For starters, some motivated person would need to write an RFC :)
Sort of. The changes in handling of |
When a new Python version is released, I diff the new Python headers against the old headers and apply the same changes to the Rust code (using |
@dgrunwald A similar situation will occur for me in |
The current logic seems to be: if both What if we just did this the other way around: if both are specified, ignore the |
In any case, this is not a new issue and has nothing to do with dllimport annotations. Let's continue this discussion in #38460. |
Implement kind="static-nobundle" (RFC 1717) This implements the "static-nobundle" library kind (last item from #37403). Rustc handles "static-nobundle" libs very similarly to dylibs, except that on Windows, uses of their symbols do not get marked with "dllimport". Which is the whole point of this feature.
Would it be possible to get some focus on bikeshedding the name of |
As part of developing PyOxidizer, I needed to force python3-sys to statically link against a Python library on Windows in a downstream crate of python3-sys. This requires the unstable `static-nobundle` link type so Cargo leaves symbols as unresolved when python3-sys is built. (Currently, the `static` linkage type verifies referenced symbols are present at crate build time.) See rust-lang/rust#37403 for more. Look for comments by me (@indygreg) to describe the issue in more detail. This commit teaches python3-sys a pair of new build features which enable more explicit control over the linker directives emitted by its build script. If no directive is specified, `link-mode-default` is used and the existing logic for linker directive emission is used. If `link-mode-unresolved-static` is used and we're on Windows, we emit a `static-nobundle=pythonXY` linker directive and omit the location of the library. This effectively says "I depend on a static `pythonXY` library but don't resolve the symbols when you build me and require someone else to specify the location to that library." What PyOxidizer does is emit its own linker directive that defines the location of a static `pythonXY` library, satisfying the linker constraint and enabling the build to work. If a downstream crate doesn't do this, the build should fail due to a missing library or symbols. I have purposefully designed the crate features to be extensible. If we want to add additional, mutually exclusive features in the future, we could do that. e.g. we could add a `link-mode-static` that force emits a `rustc-link-lib=static=pythonXY` directive to force static linking, even if a shared library is detected. But I have no need for this today and don't want to complicate the code, so I haven't added it. To round out the new feature, features have been added to the cpython crate to toggle the new features. Because Python 2.7 is end of life, I have not implemented the new feature for Python 2.7. I suspect very few people will use this feature anyway and I'm pretty confident that nobody will request this feature on Python 2.7. I concede that adding this feature to the crate to support PyOxidizer's esoteric use case is a bit unfortunate. I really wish Cargo allowed a crate to wholesale replace the build script output of a dependency, as PyOxidizer could statically resolve the Python settings for python3-sys since it brings its own Python library. But Cargo doesn't have this feature. So I'm stuck having to land this feature in the upstream crate to avoid having to maintain a permanent fork of `rust-cpython`. Sorry :/
I have submitted an RFC about re-branding "nobundle" as a modifier for the |
I also have a question - does anyone actually use the library renaming (the |
…ndle, r=petrochenkov Fix feature gate checking of static-nobundle and native_link_modifiers Feature native_link_modifiers_bundle don't need feature static-nobundle to work. Also check the feature gates when using native_link_modifiers from command line options. Current nighly compiler don't check those feature gate. ``` > touch lib.rs > rustc +nightly lib.rs -L /usr/lib -l static:+bundle=dl --crate-type=rlib > rustc +nightly lib.rs -L /usr/lib -l dylib:+as-needed=dl --crate-type=dylib -Ctarget-feature=-crt-static > rustc +nightly lib.rs -L /usr/lib -l static:-bundle=dl --crate-type=rlib error[E0658]: kind="static-nobundle" is unstable | = note: see issue rust-lang#37403 <rust-lang#37403> for more information = help: add `#![feature(static_nobundle)]` to the crate attributes to enable error: aborting due to previous error For more information about this error, try `rustc --explain E0658`. ``` First found this in rust-lang#85600 (comment)
I think I do! The Here's the wrinkle and my use case. The name of the actual Python library being linked is dynamic. And, the The However, because the actual library name is dynamic and sniffed out by the There is a wonky edge case where when using I recognize this use case is kinda wonky. If there were a better way to pass metadata from one build script to a dependent build script, I'd do that. But this |
... and a few hours later and I've refactored the I was fortunate to be working with a crate maintainer receptive to hacking up their build script to support my use case. Not everyone will be so fortunate, so this feature is still generally useful. |
@rustbot label +T-compiler -T-dev-tools |
Discussed in today's T-compiler backlog bonanza. From quickly skimming the comments here, I can tell there are people invested in this feature, but I cannot tell what its current status is (how much has been stabilized, how much was insta-stabilized, how much is still unstable), nor how much remains to be done, if anything. @rustbot label S-tracking-needs-summary |
This issue is basically tracking the removal of It's currently blocked on #93901 and on one more following PR stabilizing the |
Hi there: I am pointed here by this post, what I am actually trying to do now is that I want to find a way to link my rust final c dynamic library (.so) against stdlibc++ statically. So that this shared library can be used under another linux distribution which doesn't have the minimum requried stdlibc++ installed.. From the post, I fount that "static-nobundle" feature could help, but when I tried it in my lib, it shows me:
So I changed But still, I am not getting things compiled as expected:
I have enabled those two features in my lib.rs: #![feature(native_link_modifiers_bundle)]
#![feature(static_nobundle)] Anyone has ideas? Thanks in advance! |
Stabilize the `bundle` native library modifier And remove the legacy `static-nobundle` linking kind. Stabilization report - rust-lang#95818 (comment). cc rust-lang#81490 Closes rust-lang#37403
Stabilize the `bundle` native library modifier And remove the legacy `static-nobundle` linking kind. Stabilization report - rust-lang#95818 (comment). cc rust-lang#81490 Closes rust-lang#37403
Using |
@AlexTMjugador I can't get my cross-compiled executable to work. Running it always fails with "The code execution cannot proceed because libstdc++-6.dll was not found...". This is my build.rs:
This is my docker image I use for the build:
Output of "cargo version --verbose" inside the container:
Do you know why the library is not statically linked? |
My best guess as to why that occurred is that another thing is trying to dynamically link to the C++ stdlib. Most likely, that thing is another build script, or a configured linker flag. You can try building your project with Cargo's verbose flags to pinpoint the source of the troublesome linker parameters. I was able to verify that the
|
Tracking issue for rust-lang/rfcs#1717
-l[kind=][oldname:]libname
.dllimport
for dylib symbols.kind="static-nobundle"
.The text was updated successfully, but these errors were encountered: