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

Support cargo:rustc-link-arg=FLAG instruction in build script runner #1061

Merged
merged 1 commit into from
Dec 9, 2021

Conversation

ddeville
Copy link
Contributor

@ddeville ddeville commented Dec 9, 2021

Cargo 1.50 added support for cargo:rustc-link-arg and cargo:rust-link-arg-bins instructions in build script output (rustc-cdylib-link-arg has been supported since 1.35 and cargo:rustc-link-arg-bin was later added in 1.54).

The build script runner currently prints a warning when rustc-cdylib-link-arg is used but entirely ignores the other ones (likely setting them as BuildScriptOutput::DepEnv since this is the default branch).

This patch adds support for the cargo:rustc-link-arg instruction and prints an warning when cargo:rust-link-arg-bins and cargo:rust-link-arg-bin are used, just like rustc-cdylib-link-arg.

Note that cargo:rustc-link-arg is important because cargo errors when cargo:rustc-flags is used for anything that isn't a -l or -L flag (nb: this is enforced by cargo so it'd work with Bazel). There are cases (such as linking a -weak_framework or -weak_library on macos) that cannot use cargo:rustc-link-lib and passing a custom -Clink-arg is required)

I think that we should also support cargo:rust-link-arg-bins, rustc-cdylib-link-arg and cargo:rustc-link-arg-bin but that's a bigger task since it requires knowing the crate type the build output will apply to. I've made issue #1062 for it.

Ref: https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script

Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

Thanks!

@illicitonion illicitonion merged commit c1274b6 into bazelbuild:main Dec 9, 2021
@ddeville ddeville deleted the rustc-link-arg branch December 9, 2021 20:00
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

2 participants