bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
22.95k stars 4.02k forks source link

Not able to build bazel from source on release-7.1.0 - macOS #21579

Open chiragramani opened 6 months ago

chiragramani commented 6 months ago

Description of the bug:

I can build Bazel from source on macOS on 7.0.2 but I see the following CppLink errors when building release-7.1.0

com/google/devtools/build/lib/server/BUILD:16:13 Building src/main/java/com/google/devtools/build/lib/server/libserver.jar (4 source files) and running annotation processors (OptionProcessor) failed: (Exit 1): cc_wrapper.sh failed: error executing CppLink command (from target //third_party/grpc-java:grpc-java-plugin_checked_in) external/bazel_tools~cc_configure_extension~local_config_cc/cc_wrapper.sh @bazel-out/darwin_arm64-opt-exec-ST-fad1763555eb/bin/third_party/grpc-java/grpc-java-plugin_checked_in-2.params

clang: error: unable to execute command: Segmentation fault: 11

I also see duplicate artifact versions warning

DEBUG: /private/var/tmp/_bazel_chirag.ramani/75ed9112e388ea277815e58b5410c9da/external/rules_jvm_external~5.2/coursier.bzl:600:18: Found duplicate artifact versions
    com.google.code.gson:gson has multiple versions 2.9.0, 2.8.9
    com.google.errorprone:error_prone_annotations has multiple versions 2.22.0, 2.3.2
    com.google.truth:truth has multiple versions 1.1.3, 1.1.2
    org.mockito:mockito-core has multiple versions 5.4.0, 4.3.1
Please remove duplicate artifacts from the artifact list so you do not get unexpected artifact versions

Which category does this issue belong to?

No response

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

OTHER_ARGS='--macos_minimum_os=10.11 --host_cxxopt='-Wno-deprecated-declarations' --host_cxxopt='-Wno-deprecated-builtins''
bazel build  //src:bazel --java_runtime_version=remotejdk_11 $OTHER_ARGS

On further investigation, 7.1.0 isn't picking up the Xcode toolchain. On release-7.1.0,

bazel aquery //third_party/ijar:zipper

action 'Linking third_party/ijar/zipper'
Mnemonic: CppLink
Target: //third_party/ijar:zipper
Configuration: darwin_arm64-fastbuild
Execution platform: //:default_host_platform
ActionKey: 37301c25948aff001579325a0d3fb068265804632b6d2bc67737d987a85683d3
Inputs: [bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/_objs/errors/errors_posix.o, bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/_objs/filesystem/file.o, bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/_objs/filesystem/file_posix.o, bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/_objs/filesystem/path.o, bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/_objs/filesystem/path_posix.o, bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/_objs/logging/logging.o, bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/_objs/port/port.o, bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/_objs/strings/strings.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/_objs/platform_utils/platform_utils.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/_objs/zip/mapped_file_unix.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/_objs/zip/zip.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/_objs/zipper/zip_main.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/_objs/zlib_client/zlib_client.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/zipper-2.params, bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/adler32.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/compress.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/crc32.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/deflate.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/gzclose.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/gzlib.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/gzread.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/gzwrite.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/infback.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/inffast.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/inflate.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/inftrees.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/trees.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/uncompr.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/zutil.o, external/bazel_tools/tools/cpp/build_interface_so, external/bazel_tools/tools/cpp/link_dynamic_library.sh, external/bazel_tools~cc_configure_extension~local_config_cc/builtin_include_directory_paths, external/bazel_tools~cc_configure_extension~local_config_cc/cc_wrapper.sh]
Outputs: [bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/zipper]
Command Line: (exec external/bazel_tools~cc_configure_extension~local_config_cc/cc_wrapper.sh \
-o \
bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/zipper \
bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/_objs/zipper/zip_main.o \
-Wl,--start-lib \
bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/_objs/zip/zip.o \
bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/_objs/zip/mapped_file_unix.o \
-Wl,--end-lib \
-Wl,--start-lib \
bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/_objs/platform_utils/platform_utils.o \
-Wl,--end-lib \
-Wl,--start-lib \
bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/_objs/filesystem/file.o \
bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/_objs/filesystem/path.o \
bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/_objs/filesystem/file_posix.o \
bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/_objs/filesystem/path_posix.o \
-Wl,--end-lib \
-Wl,--start-lib \
bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/_objs/errors/errors_posix.o \
-Wl,--end-lib \
-Wl,--start-lib \
bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/_objs/port/port.o \
-Wl,--end-lib \
-Wl,--start-lib \
bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/_objs/logging/logging.o \
-Wl,--end-lib \
-Wl,--start-lib \
bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/_objs/strings/strings.o \
-Wl,--end-lib \
-Wl,--start-lib \
bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/_objs/zlib_client/zlib_client.o \
-Wl,--end-lib \
-Wl,--start-lib \
bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/adler32.o \
bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/compress.o \
bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/crc32.o \
bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/deflate.o \
bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/gzclose.o \
bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/gzlib.o \
bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/gzread.o \
bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/gzwrite.o \
bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/infback.o \
bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/inffast.o \
bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/inflate.o \
bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/inftrees.o \
bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/trees.o \
bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/uncompr.o \
bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/_objs/zlib_checked_in/zutil.o \
-Wl,--end-lib \
-Wl,-S \
'-mmacos-version-min=10.11' \
-no-canonical-prefixes \
-fobjc-link-runtime \
'-fuse-ld=/opt/homebrew/opt/llvm/bin/ld64.lld' \
-headerpad_max_install_names \
-lc++ \
-lm \
@bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/zipper-2.params)
# Configuration: b04d7949b686a9d9b4b0b2f22b30f969926af966df7333c0c7f96857ebfd416c
# Execution platform: //:default_host_platform

On 7.0.2,

action 'Linking third_party/ijar/zipper'
  Mnemonic: CppLink
  Target: //third_party/ijar:zipper
  Configuration: darwin_arm64-fastbuild
  Execution platform: //:default_host_platform
  ActionKey: fd43be64cba83d3ea487fc0bb3f7a7cc4aaa0e78e6313a588c312ddc8a4bc307
  Inputs: [bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/liberrors.a, bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/libfilesystem.a, bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/liblogging.a, bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/libport.a, bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/libstrings.a, bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/_objs/zipper/zip_main.o, bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/libplatform_utils.a, bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/libzip.a, bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/libzlib_client.a, bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/zipper-2.params, bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/libzlib_checked_in.a, bazel-out/darwin_arm64-fastbuild/internal/_middlemen/_S_Sthird_Uparty_Sijar_Czipper-BazelCppSemantics_build_arch_darwin_arm64-fastbuild, external/bazel_tools~cc_configure_extension~local_config_cc/cc_wrapper.sh, external/bazel_tools~cc_configure_extension~local_config_cc/libtool, external/bazel_tools~cc_configure_extension~local_config_cc/libtool_check_unique, external/bazel_tools~cc_configure_extension~local_config_cc/make_hashed_objlist.py, external/bazel_tools~cc_configure_extension~local_config_cc/wrapped_clang, external/bazel_tools~cc_configure_extension~local_config_cc/wrapped_clang_pp, external/bazel_tools~cc_configure_extension~local_config_cc/xcrunwrapper.sh]
  Outputs: [bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/zipper]
  ExecutionInfo: {requires-darwin: '', supports-xcode-requirements-set: ''}
  Command Line: (exec external/bazel_tools~cc_configure_extension~local_config_cc/cc_wrapper.sh \
    -lc++ \
    -fobjc-link-runtime \
    -Wl,-S \
    -o \
    bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/zipper \
    bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/_objs/zipper/zip_main.o \
    bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/libzip.a \
    bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/libplatform_utils.a \
    bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/libfilesystem.a \
    bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/liberrors.a \
    bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/libport.a \
    bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/liblogging.a \
    bazel-out/darwin_arm64-fastbuild/bin/src/main/cpp/util/libstrings.a \
    bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/libzlib_client.a \
    bazel-out/darwin_arm64-fastbuild/bin/third_party/zlib/libzlib_checked_in.a \
    -headerpad_max_install_names \
    -no-canonical-prefixes \
    -target \
    arm64-apple-macosx10.11 \
    -Xlinker \
    -no_deduplicate \
    -lc++ \
    -target \
    arm64-apple-macosx10.11 \
    @bazel-out/darwin_arm64-fastbuild/bin/third_party/ijar/zipper-2.params)
# Configuration: 7fa23fa704816858a3a94a66be6fcb472e038c4b8c8828985a11c822692b6114
# Execution platform: //:default_host_platform
  ExecutionInfo: {requires-darwin: '', supports-xcode-requirements-set: ''}

Which operating system are you running Bazel on?

macOS 14.3 (23D56)

What is the output of bazel info release?

release 7.0.2

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

chiragramani commented 6 months ago

cc: @meteorcloudy

meteorcloudy commented 6 months ago

Our postsubmit is green for release-7.1.0: https://buildkite.com/bazel/bazel-bazel/builds/27092#_

OTHER_ARGS='--macos_minimum_os=10.11 --host_cxxopt='-Wno-deprecated-declarations' --host_cxxopt='-Wno-deprecated-builtins'' bazel build //src:bazel --java_runtime_version=remotejdk_11 $OTHER_ARGS

And I couldn't reproduce the issue with on a Mac machine. This is likely a specific issue in your build environment?

chiragramani commented 6 months ago

Our postsubmit is green for release-7.1.0: https://buildkite.com/bazel/bazel-bazel/builds/27092#_

OTHER_ARGS='--macos_minimum_os=10.11 --host_cxxopt='-Wno-deprecated-declarations' --host_cxxopt='-Wno-deprecated-builtins'' bazel build //src:bazel --java_runtime_version=remotejdk_11 $OTHER_ARGS

And I couldn't reproduce the issue with on a Mac machine. This is likely a specific issue in your build environment?

Unfortunately, I am able to repro this on a different machine as well. From all the commits on release-7.1.0, looks like it work all well until this commit https://github.com/bazelbuild/bazel/commit/8bb56622e6afd2e9e8c2697d25d6a53b5f742da6.

@Wyverald @meteorcloudy As base version is changed from 6.4 to 7.0.2, do you know what changes are needed to get the right toolchain selected (which was being done when 6.4 was used)?

chiragramani commented 6 months ago

Okay, so from toolchain debugging, looks like the one from apple_support wasn't selected because the other one was registered first. When I modify MODULE.bazel to mention bazel_dep(name = "apple_support", version = "1.8.1") at the very first, it all works as expected.

Is there a way to get control of this registration part without modifying MODULE.bazel here?

Wyverald commented 6 months ago

what do you have in your ~/.bazelrc, if any? (alternatively, try bazel --bazelrc=/dev/null build <the_rest>)

what do you have in your env? (please remember to scrub sensitive info)

chiragramani commented 6 months ago

what do you have in your ~/.bazelrc, if any? (alternatively, try bazel --bazelrc=/dev/null build <the_rest>)

what do you have in your env? (please remember to scrub sensitive info)

it's all the defaults that are present on the release-7.1.0 branch. I also see the same result with bazel --bazelrc=/dev/null build <the_rest>.

meteorcloudy commented 6 months ago

Maybe you can explicitly specify the toolchain with --extra_toolchains, it should take priority. The toolchains register by bazel_dep respect a BFS order.

elwin commented 5 months ago

I was facing a similar issue, not sure if it's related:

clang: error: unable to execute command: Segmentation fault: 11
clang: error: linker command failed due to signal (use -v to see invocation)

I've had a brew managed clang installation - removing it (brew uninstall llvm) and relying on the Apple/Xcode provided clang installation instead resolved the issue for me. May be the same for you?

dkoo2 commented 5 months ago

I'm seeing the same segfaults. I've noticed it only happens for me on -c opt. fastbuild and dbg options work fine.

I've had a brew managed clang installation - removing it (brew uninstall llvm) and relying on the Apple/Xcode provided clang installation instead resolved the issue for me. May be the same for you?

This does resolve the issue for me too. Very odd though.