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

ld not found (strict_action_env) #57

Open
bthmc opened this issue Oct 14, 2024 · 3 comments · May be fixed by #60
Open

ld not found (strict_action_env) #57

bthmc opened this issue Oct 14, 2024 · 3 comments · May be fixed by #60

Comments

@bthmc
Copy link

bthmc commented Oct 14, 2024

Describe the bug

ld cannot be found during build.

To Reproduce

[nix-shell:~/src/nix_bazel_codelab]$ bazel run //go/cmd/server:go-server
[...]
collect2: fatal error: cannot find 'ld'

Expected behavior

It should build the go-server binary.

Environment

  • Linux 6.11.2-arch1-1
  • Version of the code: 0d9160f

Suspicion

Inside the nix-shell, the linker is at /nix/store/bgcaxhhxswzvmxjbbgvvaximm5hwghz1-binutils-2.41/bin/ld. The dir of it is in the PATH envvar. However, because of --incompatible_strict_action_env is in the .bazelrc file, PATH is not inherited, and the build fails. Note, gcc can be found (Probably it is discovered during local_config_cc_toolchain generation, that runs with the repo env, that inherits PATH regardless), but gcc can't find ld. Perhaps an explicit tc_toolchain should be set up?

@bthmc
Copy link
Author

bthmc commented Oct 15, 2024

Possibly related: bazelbuild/bazel#21334

@bthmc
Copy link
Author

bthmc commented Oct 15, 2024

A potential workaround for this stage is in .bazelrc:

common --action_env=CC=clang
common --action_env=CXX=clang++

@malt3
Copy link
Collaborator

malt3 commented Oct 29, 2024

I cannot reproduce this on my machine, but I see that the path to the linker (gold on my machine) is chosen independently from the path to the compiler, which explains how this can fail, depending on what you have installed outside of nix.

I like your suggestion for adding an explicit cc_toolchain!
An alternative solution would be to remove C++ support from Go using the following flag in .bazelrc: --@rules_go//go/config:pure.

Setting the flag will enable -linkmode internal during Go linking, so Go will never call out to an external linker.

Can you test building with that flag (whenever you have capacity)?

@malt3 malt3 linked a pull request Oct 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants