Skip to content

Cannot build the toy language example with bazel #71514

@tisonkun

Description

@tisonkun

Reproduce

The reproduce is simple, with file structure:

toy/
toy/BUILD
toy/MODULE.bazel
toy/WORKSPACE
toy/toy.cpp

where

  1. toy.cpp contains the example code
  2. WORKSPACE is empty.
  3. BUILD contains:
cc_binary(
  name = "toy",
  srcs = ["toy.cpp"],
  deps = [
    "@org_llvm_project//llvm:Core",
    "@org_llvm_project//llvm:Support",
  ]
)
  1. MODULE.bazel contains:
module(name = "toy", version = "0.1.0")
bazel_dep(name = "llvm-project", version = "17.0.3", repo_name = "org_llvm_project")

when build with:

$ bazel build --enable_bzlmod --action_env=BAZEL_CXXOPTS="-std=c++17" --sandbox_debug --verbose_failures //:toy

it fails with:

INFO: Analyzed target //:toy (58 packages loaded, 1490 targets configured).
INFO: Found 1 target...
ERROR: /private/var/tmp/_bazel_tison/c244744f015d9943cebd9b4c9b18d7b0/external/llvm-project~17.0.3/llvm/BUILD.bazel:600:10: Linking external/llvm-project~17.0.3/llvm/llvm-min-tblgen [for tool] failed: (Exit 254): sandbox-exec failed: error executing command 
  (cd /private/var/tmp/_bazel_tison/c244744f015d9943cebd9b4c9b18d7b0/sandbox/darwin-sandbox/338/execroot/_main && \
  exec env - \
    PATH='...' \
    PWD=/proc/self/cwd \
    TMPDIR=/var/folders/ts/160w4k_j5mv5bjk9rnjkzjpm0000gn/T/ \
  /usr/bin/sandbox-exec -f /private/var/tmp/_bazel_tison/c244744f015d9943cebd9b4c9b18d7b0/sandbox/darwin-sandbox/338/sandbox.sb /var/tmp/_bazel_tison/install/ba45a1a358416fb2acebb17d65c986f3/process-wrapper '--timeout=0' '--kill_delay=15' '--stats=/private/var/tmp/_bazel_tison/c244744f015d9943cebd9b4c9b18d7b0/sandbox/darwin-sandbox/338/stats.out' external/bazel_tools~cc_configure_extension~local_config_cc/cc_wrapper.sh @bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/llvm-project~17.0.3/llvm/llvm-min-tblgen-2.params)
clang: error: unable to execute command: Segmentation fault: 11
clang: error: linker command failed due to signal (use -v to see invocation)
Target //:toy failed to build
INFO: Elapsed time: 40.140s, Critical Path: 2.66s
INFO: 381 processes: 44 internal, 337 darwin-sandbox.

while if built with:

$ clang++ -g -O3 toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core` -o toy

It succeeds with preinstalled LLVM@17.

Environment

$ uname -a
Darwin xxx Darwin Kernel Version 22.5.0: Mon Apr 24 20:53:19 PDT 2023; root:xnu-xxx/RELEASE_ARM64_T6020 arm64

$ clang -v
Homebrew clang version 17.0.4
Target: arm64-apple-darwin22.5.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin

Reference

Metadata

Metadata

Assignees

No one assigned

    Labels

    bazel"Peripheral" support tier build system: utils/bazelbuild-problem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions