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

Do not pass native libraries to rlib compilations #576

Merged
merged 2 commits into from
Feb 5, 2021

Conversation

hlopko
Copy link
Member

@hlopko hlopko commented Feb 3, 2021

When creating an rlib artifact, rustc will open every
native static library and "copy" its contents into the rlib. This
results in a quadratic disk usage growth and that's not necessary for
rules_rust because we track native dependencies and therefore we can pass
them to the final linking actions.

This fixes the build failure when a native dep is actually a linker
script. Rustc will try to open the linker script as if it was a static
archive, and then fail the build.

Creating shared library artifacts (dylib, cdylib) and binaries is not
affected, for those rustc uses the linker, and linker will consume the
linker script just fine. Rustc won't try to open/interpret the linker
script itself.

This also unblocks #562.

@google-cla google-cla bot added the cla: yes label Feb 3, 2021
@hlopko hlopko force-pushed the no_native_to_rlib branch 5 times, most recently from 483943f to 5671cd4 Compare February 4, 2021 08:31
When creating an rlib artifact, rustc will open every
native static library and "copy" its contents into the rlib. This
results in a quadratic disk usage growth and that's not necessary for
rules_rust because we track native dependencies are we can safely pass
them to the final linking actions.

This fixes the build failure when a native dep is actually a linker
script. Rustc will try to open the linker script as if it was a static
archive, and then fail the build.

Creating shared library artifacts (dylib, cdylib) and binaries is not
affected, for those rustc uses the linker, and linker will consume the
linker script just fine. Rustc won't try to open/interpret the linker
script itself.

This also unblocks bazelbuild#562.
@hlopko
Copy link
Member Author

hlopko commented Feb 4, 2021

CC @UebelAndre @dfreese feel free to add yourselves as reviewers :)

if ctx.attr.crate:
# Target is building the crate in `test` config
# Build the test binary using the dependency's srcs.
crate = ctx.attr.crate[rust_common.crate_info]
target = rust_common.crate_info(
name = crate_name,
type = crate.type,
type = crate_type,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this assert that crate.type == "bin"?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so? Crate under test can be a rust_library with crate type rlib or pretty much any other, it's only the test that will be "bin" in any case.

Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

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

This seems good to me but only have the bandwidth right now for a high level review. 😅

@hlopko hlopko marked this pull request as ready for review February 4, 2021 20:01
@hlopko
Copy link
Member Author

hlopko commented Feb 5, 2021

Oki, will merge now, feel free to review afterwards, I'm happy to address any feedback you might have. 🙇

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.

None yet

3 participants