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-* instructions in build script runner #1062

Open
ddeville opened this issue Dec 9, 2021 · 1 comment
Open

Comments

@ddeville
Copy link
Contributor

ddeville commented Dec 9, 2021

#1061 is adding support for the cargo:rustc-link-arg instruction but cargo:rust-link-arg-bins, cargo:rustc-link-arg-bin and cargo:rustc-cdylib-link-arg are still not supported (they just print a warning).

Supporting them is a little more complex since it requires splitting some of the build script output into crate types. But that should be doable.

@ddeville ddeville changed the title Support cargo:rustc-link-arg-* instructions in build runner Support cargo:rustc-link-arg-* instructions in build script runner Dec 9, 2021
illicitonion pushed a commit that referenced this issue 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
@opicaud
Copy link

opicaud commented Feb 7, 2023

Hello :)

Many thanks for rules_rust!
Sorry to not propose any PR, i am using bazel for few weeks now and no nothing about rust/cargo..
I am using them today to build a library (pact_ffi in my case). It requires cargo:rustc-cdylib-link-arg and i see that this directive is currently not supported. Does the community has any news about this ?

Thanks!

Olivier

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

No branches or pull requests

3 participants