Hope this is an appropriate place to ask this question.
As the subject says, what would be the correct/idiomatic way to detect whether a dependent cc_library is built with -fPIC? The question stems from https://github.com/bazelbuild/rules_rust/issues/118, which discusses an interop issue between Rust and C. In short, rustc defaults to building position-independent executables (i.e. PIE) on (at least) Linux. If a static lib is being linked in, it needs to have been built with -fPIC. This works perfectly fine with the dbg and fastbuild compilation modes, but fails with opt builds. The difference is opt does not produce PIC archives.
As an experiment, I wanted to see if I could detect the presence/absence of PIC archives of the transitive cc_library deps (or slightly more general, detect if PIC compilation was used or not for them). If PIC archives are absent, the rust rule would automatically turn off PIE generation.
Any suggestions/thoughts?
Thanks
hlo...@google.com, is this something you may have ideas about?
Well, I'm glad I caught you on the right day for this question :).
So the idea is I'd inspect the pic entries of the library_to_link struct hanging off the cpp provider, and if it's empty, build a non-PIE binary via rustc. And if both pic and nopic lists have artifacts, I can choose whether to build PIE or non-PIE. Ok, I think that ought to work.
And yeah - improving the docs would be much appreciated :).
I'm also assuming that there's no good answer to my original question in the context of Bazel 0.20, right?
Thanks!
I'm aware of the force_pic flag, but was hoping to avoid forcing things that way.