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

rustc: correctly handle alwayslink staticlibs #606

Merged
merged 8 commits into from
Mar 2, 2021

Conversation

durin42
Copy link
Contributor

@durin42 durin42 commented Feb 25, 2021

In order to do this, we have to inline get_libs_for_static_executable so we
can interact with the LibraryToLink entity as we're categorizing staticlibs.

Fixes #325.

@google-cla google-cla bot added the cla: yes label Feb 25, 2021
@durin42 durin42 force-pushed the alwayslink branch 2 times, most recently from 27ed182 to 142134c Compare February 25, 2021 04:14
@hlopko hlopko self-requested a review February 25, 2021 13:05
Copy link
Member

@hlopko hlopko left a comment

Choose a reason for hiding this comment

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

Looks good, only some tweaks missing. Could you add a unit test?

rust/private/rustc.bzl Show resolved Hide resolved
rust/private/rustc.bzl Outdated Show resolved Hide resolved
rust/private/rustc.bzl Outdated Show resolved Hide resolved
rust/private/rustc.bzl Outdated Show resolved Hide resolved
@durin42 durin42 force-pushed the alwayslink branch 5 times, most recently from 7eb1c3f to 12bcb7c Compare February 25, 2021 23:20
@durin42
Copy link
Contributor Author

durin42 commented Feb 25, 2021

@hlopko I'm closer, all the tests pass, but it looks like I broke something that's only covered by examples and I'm not running those locally? Is that right?

(If so, what's the right way to run the examples? I'm not figuring it out...)

@illicitonion
Copy link
Collaborator

@hlopko I'm closer, all the tests pass, but it looks like I broke something that's only covered by examples and I'm not running those locally? Is that right?

(If so, what's the right way to run the examples? I'm not figuring it out...)

$ bazel build @examples//...

(Some don't run on non-Linux platforms, see https://github.com/bazelbuild/rules_rust/blob/main/.bazelci/presubmit.yml for a list of exceptions)

@durin42
Copy link
Contributor Author

durin42 commented Feb 25, 2021

@illicitonion thanks! Found my bug. :)

@illicitonion
Copy link
Collaborator

@illicitonion thanks! Found my bug. :)

Hurrah!

(Hi, by the way! Long time no see!)

@durin42
Copy link
Contributor Author

durin42 commented Feb 26, 2021 via email

@hlopko

This comment has been minimized.

@durin42 durin42 force-pushed the alwayslink branch 2 times, most recently from ccd3860 to 63e2b26 Compare February 26, 2021 16:46
@durin42
Copy link
Contributor Author

durin42 commented Feb 26, 2021

Alright, this now breaks @examples//ffi/rust_calling_c:matrix_dynamically_linked on windows and darwin, but I'm honestly a little confused if that's my fault. I think this is something that had to be broken all along and I'm merely exposing it?

@durin42
Copy link
Contributor Author

durin42 commented Feb 26, 2021

Okay, those broke in 3ad0e99, but it's not super obvious to me that that change is wrong. :(

@durin42
Copy link
Contributor Author

durin42 commented Feb 26, 2021

Did some other stuff, realized I could just "bake in" the old behavior in _compute_rpaths() with a TODO, so that's what did.

@durin42 durin42 force-pushed the alwayslink branch 4 times, most recently from 496dc81 to 93ff654 Compare February 26, 2021 20:01
rust/private/rustc.bzl Outdated Show resolved Hide resolved
rust/private/rustc.bzl Outdated Show resolved Hide resolved
rust/private/rustc.bzl Show resolved Hide resolved
rust/private/rustc.bzl Show resolved Hide resolved
rust/private/rustc.bzl Show resolved Hide resolved
bindgen/bindgen.bzl Show resolved Hide resolved
rust/private/rustdoc_test.bzl Show resolved Hide resolved
test/unit/native_deps/native_deps_test.bzl Show resolved Hide resolved
@durin42 durin42 force-pushed the alwayslink branch 2 times, most recently from aca6e17 to 01c5b55 Compare February 26, 2021 22:19
We then move the function to its only remaining caller in bindgen. I
didn't inline it there because it's used in a few different ways and
cleaning it up felt like more work than it was immediately worth.
We need this information to implement support for alwayslink, and it
cascaded around the codebase more than a little. The next change will
implement always link, which is currently left as a stub so that this
change has no functional changes.
Instead we just verify we're not going to link anything static. This
removes the need for a toolchain in _is_dylib, which will allow
further cleanups in a moment.
This allows us to use a more efficient construction to add linker
arguments to the command line.
This follows up on the previous commit's refactoring and actually adds
alwayslink support.

Fixes bazelbuild#325.
Makes sure that cdylibs also correctly pick up their alwayslink
dependencies.
This lets us avoid reifying a depset a little longer, which is nice.
@durin42 durin42 requested a review from hlopko March 2, 2021 16:21
Copy link
Member

@hlopko hlopko left a comment

Choose a reason for hiding this comment

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

Let's get this moving :)

@hlopko hlopko merged commit 1b7885a into bazelbuild:main Mar 2, 2021
@durin42 durin42 deleted the alwayslink branch January 12, 2022 19:05
"_macos_constraint": attr.label(default = Label("@platforms//os:macos")),
"_windows_constraint": attr.label(default = Label("@platforms//os:windows")),
})
cdylib_has_native_dep_and_alwayslink_test = analysistest.make(_cdylib_has_native_libs_test_impl, attrs = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like this this function is using the wrong implementation and correcting this causes a failure. @hlopko @durin42 would either of you be able to take a quick look? 🙏

Suggested change
cdylib_has_native_dep_and_alwayslink_test = analysistest.make(_cdylib_has_native_libs_test_impl, attrs = {
cdylib_has_native_dep_and_alwayslink_test = analysistest.make(_cdylib_has_native_dep_and_alwayslink_test_impl, attrs = {

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

Successfully merging this pull request may close these issues.

Linking fails for cc_library targets with "alwayslink = 1"
4 participants