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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use output hash in filename for crates of type cdylib #1066

Merged
merged 2 commits into from
Dec 20, 2021

Conversation

ddeville
Copy link
Contributor

Cdylib crates, similarly to binaries, are meant for consumption outside of the rust ecosystem. For this reason, there is no need to attempt making their name unique to disambiguate them from other crates with the same name but different features/versions in the Rust/Cargo dependency graph (as discussed in #405).

In fact, when distributing dynamic libraries or embedding them into applications, it is critical for their name to be deterministic since it ends up embedded into the executable itself, that the linker uses to link/resolve the library. On macOS, this requires the use of install_name_tool to tweak the id/name after it's build. On Windows, one has to re-generate the LIB file to embed the new name (which afaict can only be done via the hacky intermediary export to a DEF file) and live with the fact that the associated pdb will embed the previous library name.

This patch just doesn't use the hash for cdylib library crates. It solves the problem above and all tests still pass so I assume it's not breaking anything crucial that was depending on this before 馃槂

@hlopko
Copy link
Member

hlopko commented Dec 16, 2021

Looks good, could you please add a test?

@hlopko hlopko self-requested a review December 16, 2021 14:40
@ddeville ddeville force-pushed the cdylib-name branch 2 times, most recently from 4d323e3 to 0cea26b Compare December 16, 2021 18:37
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.

Small nit from me but otherwise looks good!

rust/private/rust.bzl Outdated Show resolved Hide resolved
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.

Sorry to flip-flop 馃槄 I noticed two things before merging

test/unit/cdylib_name/cdylib_name_analysis_test.bzl Outdated Show resolved Hide resolved
test/unit/cdylib_name/cdylib_name_analysis_test.bzl Outdated Show resolved Hide resolved
@ddeville ddeville force-pushed the cdylib-name branch 3 times, most recently from 2f8da87 to 30050be Compare December 17, 2021 00:50
@UebelAndre UebelAndre merged commit 38211c2 into bazelbuild:main Dec 20, 2021
@ddeville ddeville deleted the cdylib-name branch December 20, 2021 20:13
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.

None yet

3 participants