-
Notifications
You must be signed in to change notification settings - Fork 402
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
Link actions don't get link_flags files propagated from transitive cargo_build_script targets #1702
Comments
Thanks for looking into this! |
I made a basic example repo that shows a working patch to the rust_rules repo: I have a rust_binary package (rust_bin) that depends on a c++ package (cxx_lib) that depends on a rust_library package (rust_lib) that has a number of cargo dependencies. (Sorry if that is a bit convoluted) |
I put together a draft of this in https://github.com/illicitonion/rules_rust/tree/link-action-flags but it uncovered an interesting issue... For context, the rough shape of the situation is: Rust depends on C++ depends on Rust depends on libopenssl-sys The cargo docs describe that:
We have some prior art in #448 where we started only propagating link flags to the parent crate. Per the cargo docs, I believe this is (roughly) the correct behaviour. (Roughly because, if there was no depending library, we should propagate the flag to the binary, but in practice people don't use rules_rust with a rust_binary depending directly on a cargo_build_script, so I think we can ignore that for now). In particular, my patch breaks a test added in that PR. Currently, if we write a simple rust_binary which uses reqwest (and in turn uses The problem arises when the dependency path from the rust_binary to the cargo build script emitting /cc @krasimirgg who knows a lot more about the Rust/C++ linking story than I do, in case this sparks any inspiration... |
Right, I think that's roughly what I'd expect. In general, we want the rust targets to be useable in a mixed c++ and rust context. In the C++ world, standard for Bazel is to use the cc_common linking infrastructure to describe the linker inputs of a final c++ binary. Whenever there's a rust dependency of a cc library, rules_rust establishes some common linker definitions ( |
From https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/rustc-link-lib.20propagation/near/320247453 it sounds like we realistically have two options to make this reliably work:
@krasimirgg How do the above options sound to you? It feels like 2 is probably the correct approach, because it would make cc_binary-drive graphs work more reliably, but that 1 is probably a far easier approach (because it doesn't require modifications to the core CcInfo provider)... Do you have any impressions on whether we could get CcInfo modified to support action-output flagfiles as well as known-up-front flags? |
This code diligently forwards all link search path files transitively from
cargo_build_script
targets, but not the link flag files from them:rules_rust/rust/private/rustc.bzl
Lines 1458 to 1493 in 1469cd7
This is buggy in two ways:
BuildInfo.link_flags
up to the link action (but only the link action, not compile actions)BuildInfo. link_search_path_files
s to compile actions, only up to the link action.The first matters quite a bit. The second is a relatively minor detail.
The text was updated successfully, but these errors were encountered: