bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
23.2k stars 4.06k forks source link

Documentation issue: Configuring C++ toolchains misleading linker invocation #13917

Open jwbee opened 3 years ago

jwbee commented 3 years ago

Documentation URL: https://docs.bazel.build/versions/main/tutorial/cc-toolchain-config.html

As this documentation stands it misleads the user into believing that the ld stanza of tool_paths controls the invocation of the linker, but it doesn't. If you put /usr/games/cowsay in for the linker, it still invokes the default host linker. I'm not smart enough to know why yet, but I guess it is because the features override things.

It seems to me that if you want to influence the linker, you are required to provide a list of ActionConfigInfo.

scal444 commented 3 years ago

It may be because bazel invokes the compiler to do linking, and the compiler knows which ld it wants to use. I've worked around similar issues with (as you say) action modifiers adding the --dynamic-linker flag to the invocation.

UlrichEckhardt commented 2 years ago

The whole tutorial fails at step 7. There, it expects Bazel to throw an error, because no path to a compiler has been configured. However, it happily compiles and runs the hello world program.

For the record, I tried this using versions 4.1, 4.2, 5.0 and 5.1 on a recent Ubuntu system.

Note: I had some existing code in my workspace. Among that, there was a .bazelrc with the line

build --incompatible_enable_cc_toolchain_resolution

which makes the difference there.