Skip to content

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

@calmette54

Description

@calmette54

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions