toolchains_llvm icon indicating copy to clipboard operation
toolchains_llvm copied to clipboard

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

Open calmette54 opened this issue 6 months ago • 3 comments

I'm trying to run the hello-world example in rules_go 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 says that toolchains_llvm is compatible with rules_go. So, I would appreciate some help.

calmette54 avatar May 25 '25 17:05 calmette54

does it work with --@rules_go//go/config:pure

scasagrande avatar Jul 05 '25 18:07 scasagrande

@calmette54 I'm running into this same issue. Did you ever solve it?

@scasagrande that did cause the build to succeed for me

NickCurranScout avatar Nov 03 '25 15:11 NickCurranScout

I cannot reproduce this error on Ubuntu 25.04.

I tested all combinations of the below:

  • rules_go: 0.5.0.0, 0.52.0, 0.59.0, HEAD as of 2025.11.12
  • toolchains_llvm: 0.1.4, 0.1.5, HEAD as of 2025.11.12
  • with and without '--shell_executable=$(which bash)'
  • OS = Linux XXX 6.14.0-33-generic #33-Ubuntu SMP PREEMPT_DYNAMIC Wed Sep 17 23:22:02 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

@calmette54 could you re-check on your system in with llvm 1.4.0, 1.5.0 and HEAD? (your original report appears to be from version 0.1.4).

helly25 avatar Nov 12 '25 16:11 helly25