bazelbuild / rules_rust

Rust rules for Bazel
https://bazelbuild.github.io/rules_rust/
Apache License 2.0
671 stars 435 forks source link

Is bindgen object merging necessary? #2960

Open hlopko opened 1 month ago

hlopko commented 1 month ago

In https://github.com/bazelbuild/rules_rust/pull/2361 we have added logic (that became the default since then) to merge object files of cc_lib into the rlib produced by bindgen rules. The problem this is solving is related to some annoying ordering errors when using both Bazel and Cargo on a project using bindgen in a build script.

I can't say I understand exactly what the problem is, but it has bitten us recently (hence https://github.com/bazelbuild/rules_rust/pull/2959). But intuitively, if the problem is related to link ordering when build scripts are involved, maybe a better fix would be to propagate CcInfo from build scripts?

Any information/repro instructions of the original problem will be super useful.

@UebelAndre @krasimirgg

UebelAndre commented 1 month ago

Per https://github.com/bazelbuild/rules_rust/pull/2361, the change was designed to closer match Cargo behavior within these rules. I don't have a sharable repro right now but the issue was indeed extra link flags coming from the CcInfo that caused Bazel builds to fail due to the ordering of the flags where Cargo builds didn't have these flags and produced usable outputs. I don't know much about this dynamic mode but don't have major objections to a hole being poked in the bindgen rules to support it as long as the default behavior is not changed. 😄

hlopko commented 1 month ago

If it is about extra link flags, would it help to propagate CcInfo from build scripts?