bazel-contrib / bazel-contrib/toolchains_llvm

Cannot get toolchains_llvm to work with the `rules_go` hello-world example.

Open
#503 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
Starlark
Stars
371
Forks
283
Avg merge
1d 55m
Merged PRs (30d)
25

Description

I'm trying to run the [hello-world example in rules_go](https://github.com/bazel-contrib/rules_go/tree/393faea31d43012fbb7887dfbddb869cb5cf58f5/examples/hello) with a minor twist. I appended the following snippet to the `MODULE.bazel`.

```
bazel_dep(name = "toolchains_llvm", version = "1.4.0", dev_dependency = True)
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

#--------------------- LLVM Toolchain --------------
SYSROOT_BUILD_CONTENT = """
filegroup(
name = "sysroot",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
"""

http_archive(
name = "sysroot_linux_x64",
build_file_content = SYSROOT_BUILD_CONTENT,
sha256 = "5df5be9357b425cdd70d92d4697d07e7d55d7a923f037c22dc80a78e85842d2c",
urls = ["https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/4f611ec025be98214164d4bf9fbe8843f58533f7/debian_bullseye_amd64_sysroot.tar.xz"],
)

llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm", dev_dependency = True)
llvm.toolchain(
name = "llvm_toolchain",
cxx_standard = {
"19.1.6": "c++23",
},
llvm_versions = {
"linux-x86_64": "19.1.6",
},
sha256 = {
"linux-x86_64": "d55dcbb309de7ade4e3073ec3ac3fac4d3ff236d54df3c4de04464fe68bec531",
},
stdlib = {
"linux-x86_64": "stdc++",
},
strip_prefix = {
"linux-x86_64": "LLVM-19.1.6-Linux-X64",
},
urls = {
"linux-x86_64": [
"https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.6/LLVM-19.1.6-Linux-X64.tar.xz",
],
},
)
llvm.sysroot(
name = "llvm_toolchain",
label = "@sysroot_linux_x64//:sysroot",
targets = ["linux-x86_64"],
)
use_repo(llvm, "llvm_toolchain")

register_toolchains(
"@llvm_toolchain//:all",
dev_dependency = True,
)
```

I'm using NixOS 24.11 (in case that makes any difference). And I'm making bazelisk available via `nix-shell -p bazelisk`

The error that I see is the following:

```
& bazelisk test :hello_test --shell_executable=$(which bash)
INFO: Analyzed target //:hello_test (90 packages loaded, 20949 targets configured).
ERROR: /home/user/.cache/bazel/_bazel_user/37c03041588fe875288f3fbbab4d38b5/external/rules_go+/BUILD.bazel:42:7: GoStdlib external/rules_go+/stdlib_/pkg failed: (Exit 1): builder failed: error executing GoStdlib command (from target @@rules_go+//:stdlib) bazel-out/k8-opt-exec-ST-d57f47055a04/bin/external/rules_go++go_sdk+hello__download_0/builder_reset/builder stdlib -sdk external/rules_go++go_sdk+hello__download_0 -goroot ... (remaining 11 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
# runtime/cgo
cc: no such file or directory
stdlib: error running subcommand external/rules_go++go_sdk+hello__download_0/bin/go: exit status 1
Target //:hello_test failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 19.814s, Critical Path: 16.81s
INFO: 2 processes: 7 action cache hit, 2 internal.
ERROR: Build did NOT complete successfully
//:hello_test FAILED TO BUILD

Executed 0 out of 1 test: 1 fails to build.
```

I decided to write an issue here since the [README.md](https://github.com/bazel-contrib/toolchains_llvm?tab=readme-ov-file#compatibility) says that `toolchains_llvm` is compatible with `rules_go`. So, I would appreciate some help.

Contributor guide

Open the contributing guide

Research direction

Start with the rules_go hello-world example and the appended MODULE.bazel configuration, then reproduce the failure with bazelisk test :hello_test --shell_executable=$(which bash). Read the toolchains_llvm README compatibility section and inspect the verbose failure around GoStdlib and runtime/cgo. Done means the hello-world test builds successfully in the reported NixOS setup, or the compatibility limitation is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, nixos
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.