Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bazel_4: init at 4.0.0 #106984

Merged
merged 8 commits into from
Feb 9, 2021
Merged

bazel_4: init at 4.0.0 #106984

merged 8 commits into from
Feb 9, 2021

Conversation

divanorama
Copy link
Contributor

@divanorama divanorama commented Dec 15, 2020

Bazel 4 is going to be a long term support release.

Latest version in NixPkgs so far was 3.3.1
There's a need for more recent version
#97497

All versions from 3.5.0 to 3.7.1 had some reproducibility issues
as noted in issue above, but there also seems to be
a working PR for 3.7.1 now at
#105439

Notable changes from bazel_3 setup:

  • put python to default bash path

    For autodetecting python toolchain
    with strict action_env on and without this change
    bazel would fail to autodetect host python.

    There are some repos that define hermetic python
    toolchains, but they aren't easy to use yet. Also
    telling python paths to bazel isn't a 1-liner it
    seems:

    • action_env=PATH would affect cache
    • declaring toolchain via BUILD&WORKSPACE files
      is not per-user but more like per-repo and
      affects cache too

    Using python from nixpkgs shouldn't be too bad
    in the lack of simpler hermetic python toolchain
    options

  • bazel_4.updater is bazel on bazel query to support
    new constructs in WORKSPACE (load of vars, transitive
    load etc). This is more robust but requires bazel
    to run the updater, using bazel_3 for now. This is
    only needed to bump package version, doesn't introduce
    bazel_4 build dependency on bazel_3

https://blog.bazel.build/2020/11/10/bazel-4.0-announce.html
https://blog.bazel.build/2020/11/10/long-term-support-release.html
bazelbuild/bazel#12455
https://github.com/bazelbuild/bazel/releases/tag/4.0.0
https://blog.bazel.build/2021/01/19/bazel-4-0.html

@timothyklim
Copy link
Contributor

Awesome PR! Good to have early builds of new bazel to test scala 3.0 without custom nixpkgs overrides.

stolyaroleh added a commit to stolyaroleh/pesto that referenced this pull request Jan 20, 2021
@avdv
Copy link
Member

avdv commented Jan 21, 2021

Bazel 4.0 just has been released... 🎉 https://github.com/bazelbuild/bazel/releases/tag/4.0.0

Looking forward for an update here. 😄

(BTW, does this PR build on darwin?)

@divanorama divanorama changed the title bazel_4: init at 4.0.0rc7 bazel_4: init at 4.0.0 Jan 21, 2021
@divanorama
Copy link
Contributor Author

Updated to 4.0.0: squash, rebase and new title&description
Didn't test on darwin, only Gentoo amd64 with sandbox=true so far.

@stevana
Copy link
Contributor

stevana commented Jan 21, 2021

Works for me on linux, but my colleague using MacOS big sur got the following error when trying to build:

external/com_github_grpc_grpc/src/core/ext/xds/xds_api.h:30:
external/com_github_google_re2/re2/re2.h:973:8: error: thread-local
storage is not supported for the current target
extern thread_local const RE2* context;
       ^

Had a quick look around and found somebody suggesting to pass -stdlib=libc++ -std=c++11 to clang, because "OS X's outdated libstdc++ doesn't support TLS (thread-local storage)" (https://stackoverflow.com/questions/23791060/c-thread-local-storage-clang-503-0-40-mac-osx#23850891).

@divanorama
Copy link
Contributor Author

@divanorama
Copy link
Contributor Author

I've added --verbose_failures to build options, maybe it'll help investigate macos failure more

@groodt
Copy link
Contributor

groodt commented Jan 27, 2021

Any clues @divanorama ?

@divanorama
Copy link
Contributor Author

No, I don't know how to test on darwin, is there a public VM image or something?
Added --verbose_failures to build, so hopefully it can show if it is clang/gcc from nixpkgs, or from host, that is failing.
But other than that maybe we could merge it with broken flag on darwin and try investigating further?

@divanorama
Copy link
Contributor Author

By the way, would Hydra / NixPkgs infrastructure compile it on macos or cross-compile on matching arch with Nix? Maybe we're lucky and it'd populate nix cache?

@groodt
Copy link
Contributor

groodt commented Jan 27, 2021

By the way, would Hydra / NixPkgs infrastructure compile it on macos or cross-compile on matching arch with Nix? Maybe we're lucky and it'd populate nix cache?

There are Hydra builds for macos, so that is fine.

From the checks that ran in this PR it appears that the tests are failing on Linux, so I don't think it would be merged before the Linux tests are passing. Those need to be working first before any Darwin issues are investigated I think. I think the aarch64-linux tests aren't expected to pass for this package. Only linux and darwin.

@divanorama
Copy link
Contributor Author

Didn't notice the linux breakage, thanks! Will try to reproduce locally
Looks similar to bazelbuild/bazel#12887

@divanorama
Copy link
Contributor Author

checks are green now 🥳

@groodt
Copy link
Contributor

groodt commented Jan 27, 2021

checks are green now 🥳

Awesome!

I've quickly tried locally on Catalina (10.15.7) and it fails as follows:

[530 / 2,263] 16 actions running
    @com_google_protobuf//:protoc_lib; 6s local
    @com_google_protobuf//:protoc_lib; 6s local
    Compiling third_party/ijar/classfile.cc; 2s local
    Compiling src/google/protobuf/reflection_ops.cc; 1s local
    Compiling src/google/protobuf/compiler/importer.cc; 1s local
    Compiling src/google/protobuf/util/internal/json_escaping.cc; 1s local
    @com_google_protobuf//:protobuf; 1s local
    Linking external/bazel_tools/.../ijar/zipper [for host]; 1s local ...
ERROR: /private/tmp/nix-build-bazel-4.0.0.drv-0/bazel_tbc0uiNy/out/external/bazel_tools/third_party/ijar/BUILD:72:10: Linking external/bazel_tools/third_party/ijar/zipper [for host] failed: (Exit 1): cc_wrapper.sh failed: error executing command
  (cd /private/tmp/nix-build-bazel-4.0.0.drv-0/bazel_tbc0uiNy/out/execroot/io_bazel && \
  exec env - \
    PATH=/nix/store/ghdbgzd3rx7q497r7icff3hk83gn7v7c-zip-3.0/bin:/nix/store/nyrgyvvx7nz6ws6xy39wg8yysvgl0wxq-python3-3.8.7/bin:/nix/store/klwibpcnpx41nd07mglfqhqnv24qbyp4-unzip-6.0/bin:/nix/store/495qnygsihllpk2sf38mfk96n0bq954w-which-2.21/bin:/nix/store/5m5rqrpqfb7jhjy83fgql2qp3vhj4jpy-bash/bin:/nix/store/92c1pmlg9m6jdzpvrk5qy33sf1ya8zch-cctools-port-949.0.1/bin:/nix/store/njgrfgp7ws3mw2ipw9d56rac3irlk36f-clang-wrapper-6.0.1/bin:/nix/store/1fzlgsnkd232qq43lb5rl54rmwlggbmi-clang-6.0.1/bin:/nix/store/la203av8kn0ys79yykjbwkiip7li95c1-coreutils-8.32/bin:/nix/store/zfx9b0dkr3b04dx0lb7k2ryig0h04plh-cctools-binutils-darwin-wrapper-949.0.1/bin:/nix/store/rih2pjsr7p9dwwa6j3kdvpw4gdka7ik6-cctools-binutils-darwin-949.0.1/bin:/nix/store/la203av8kn0ys79yykjbwkiip7li95c1-coreutils-8.32/bin:/nix/store/xl4iq6714cjwcp52s9rsad09428qwv6g-zulu1.8.0_202-8.36.0.1/bin:/nix/store/nyrgyvvx7nz6ws6xy39wg8yysvgl0wxq-python3-3.8.7/bin:/nix/store/la203av8kn0ys79yykjbwkiip7li95c1-coreutils-8.32/bin:/nix/store/q1kcsx96nqr11lbzm5j7vnqhkim03syp-findutils-4.7.0/bin:/nix/store/3fvanh6lp4cimxy3l10mjhiijiqzisic-diffutils-3.7/bin:/nix/store/z7l0bq1fcz60v6h57xb4ad8wllma29hm-gnused-4.8/bin:/nix/store/47i2968jigckis49wgk1k1271dasjrz1-gnugrep-3.6/bin:/nix/store/sbjrzw1h529szdnypkalivarllcbj7zh-gawk-5.1.0/bin:/nix/store/3xfgx6c6y39pzrr6v4fbsifr5ga25z9b-gnutar-1.32/bin:/nix/store/v14kf9ixn5zbygh3vwij6cdr8x070h4z-gzip-1.10/bin:/nix/store/javc44l83416mp8m0d7w0zkxnxvnscky-bzip2-1.0.6.0.1-bin/bin:/nix/store/887s15ivmsxkbs9b2yklc0a41k4wwsnw-gnumake-4.3/bin:/nix/store/fb2pkc446jgwxn98hgabhsjkj7scb57y-bash-4.4-p23/bin:/nix/store/9mlh23a4ax1xnhhm1bp6agqn8ks1n48d-patch-2.7.6/bin:/nix/store/n79yia82bnf16y93nb3mr67ygdv6hdhh-xz-5.2.5-bin/bin:/nix/store/fb2pkc446jgwxn98hgabhsjkj7scb57y-bash-4.4-p23/bin:/nix/store/la203av8kn0ys79yykjbwkiip7li95c1-coreutils-8.32/bin:/nix/store/q1kcsx96nqr11lbzm5j7vnqhkim03syp-findutils-4.7.0/bin:/nix/store/sbjrzw1h529szdnypkalivarllcbj7zh-gawk-5.1.0/bin:/nix/store/47i2968jigckis49wgk1k1271dasjrz1-gnugrep-3.6/bin:/nix/store/jp629ddmy3yv4yrmrwi51bbg1zhaj5r3-gnutar-1.32/bin:/nix/store/z7l0bq1fcz60v6h57xb4ad8wllma29hm-gnused-4.8/bin:/nix/store/v14kf9ixn5zbygh3vwij6cdr8x070h4z-gzip-1.10/bin:/nix/store/495qnygsihllpk2sf38mfk96n0bq954w-which-2.21/bin:/nix/store/klwibpcnpx41nd07mglfqhqnv24qbyp4-unzip-6.0/bin:/nix/store/hk7cpj4ahiwn7b0chdh0a3gvs8y8xqd8-file-5.39/bin:/nix/store/ghdbgzd3rx7q497r7icff3hk83gn7v7c-zip-3.0/bin:/nix/store/pi9vvlavr5k7z65fpalb77vl71pxg212-python-2.7.18/bin:/nix/store/nyrgyvvx7nz6ws6xy39wg8yysvgl0wxq-python3-3.8.7/bin \
    PWD=/proc/self/cwd \
  external/local_config_cc/cc_wrapper.sh @bazel-out/host/bin/external/bazel_tools/third_party/ijar/zipper-2.params)
Execution platform: //:default_host_platform
[532 / 2,263] 15 actions running
    @com_google_protobuf//:protoc_lib; 6s local
    @com_google_protobuf//:protoc_lib; 6s local
    Compiling third_party/ijar/classfile.cc; 2s local
    Compiling src/google/protobuf/reflection_ops.cc; 1s local
    Compiling src/google/protobuf/compiler/importer.cc; 1s local
    Compiling src/google/protobuf/util/internal/json_escaping.cc; 1s local
    @com_google_protobuf//:protobuf; 1s local
    Compiling src/google/protobuf/dynamic_message.cc; 1s local ...
0  0x104223871  __assert_rtn + 129
1  0x1043fc424  ld::passes::stubs::x86_64::classic::LazyPointerAtom::LazyPointerAtom(ld::passes::stubs::Pass&, ld::Atom const&, bool, bool) + 420
2  0x1043f9c4a  ld::passes::stubs::Pass::makeStub(ld::Atom const&, bool) + 2762
3  0x1043fac3f  ld::passes::stubs::Pass::process(ld::Internal&) + 2511
4  0x1043fb2a0  ld::passes::stubs::doPass(Options const&, ld::Internal&) + 128
5  0x104224e14  main + 1860
A linker snapshot was created at:
        /tmp/zipper-2021-00-28-080003.ld-snapshot
ld: Assertion failed: (targetAtom != NULL), function Fixup, file ../../../../ld64/src/ld/ld.hpp, line 776.
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)
[532 / 2,263] 15 actions running
    @com_google_protobuf//:protoc_lib; 6s local
    @com_google_protobuf//:protoc_lib; 6s local
    Compiling third_party/ijar/classfile.cc; 2s local
    Compiling src/google/protobuf/reflection_ops.cc; 1s local
    Compiling src/google/protobuf/compiler/importer.cc; 1s local
    Compiling src/google/protobuf/util/internal/json_escaping.cc; 1s local
    @com_google_protobuf//:protobuf; 1s local
    Compiling src/google/protobuf/dynamic_message.cc; 1s local ...
Target //src:bazel_nojdk failed to build
[547 / 2,263] checking cached actions
INFO: Elapsed time: 81.207s, Critical Path: 51.60s
[547 / 2,263] checking cached actions
INFO: 547 processes: 181 internal, 329 local, 37 worker.
[547 / 2,263] checking cached actions
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully

ERROR: Could not build Bazel
builder for '/nix/store/a5c3a6bw3n0qkcqx3h01s20x7a347r81-bazel-4.0.0.drv' failed with exit code 1
error: build of '/nix/store/a5c3a6bw3n0qkcqx3h01s20x7a347r81-bazel-4.0.0.drv' failed

@divanorama
Copy link
Contributor Author

thanks, interesting bit is

 PATH=...:/nix/store/njgrfgp7ws3mw2ipw9d56rac3irlk36f-clang-wrapper-6.0.1/bin:/nix/store/1fzlgsnkd232qq43lb5rl54rmwlggbmi-clang-6.0.1/bin:... \
    PWD=/proc/self/cwd \
  external/local_config_cc/cc_wrapper.sh @bazel-out/host/bin/external/bazel_tools/third_party/ijar/zipper-2.params)
...
ld: Assertion failed: (targetAtom != NULL), function Fixup, file ../../../../ld64/src/ld/ld.hpp, line 776.
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)

so it's likely that clang 6 from NixPkgs is used, but fails

Wonder if

diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index bea1931aac9..b8e818288aa 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -11673,7 +11673,6 @@ in
     buildJdk = jdk8_headless;
     buildJdkName = "jdk8";
     runJdk = jdk11_headless;
-    stdenv = if stdenv.cc.isClang then llvmPackages_6.stdenv else stdenv;
     bazel_self = bazel_4;
   };

or maybe

diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index bea1931aac9..4485534bc52 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -11673,7 +11673,7 @@ in
     buildJdk = jdk8_headless;
     buildJdkName = "jdk8";
     runJdk = jdk11_headless;
-    stdenv = if stdenv.cc.isClang then llvmPackages_6.stdenv else stdenv;
+    stdenv = if stdenv.cc.isClang then llvmPackages_7.stdenv else stdenv;
     bazel_self = bazel_4;
   };

can help

@groodt
Copy link
Contributor

groodt commented Jan 27, 2021

I'll try those. It definitely seems like the error is similar to this suggestion from @kalbasit and @avdv #105439 (comment)

It seems like the linker is being passed a strange version of -macosx_version_min 10.4.0, but I have no idea where those values are coming from. It also seems that the -sdk_version 10.12 is more modern, in the same linker command. I don't know if that would be an issue.

/nix/store/rih2pjsr7p9dwwa6j3kdvpw4gdka7ik6-cctools-binutils-darwin-949.0.1/bin/ld -Z -demangle -lto_library data_files/libLTO.dylib -dynamic -arch x86_64 -headerpad_max_install_names -macosx_version_min 10.4.0 -undefined dynamic_lookup -undefined dynamic_lookup -sdk_version 10.12 -no_uuid -S -filelist objects/filelist archive_files/libzip.a archive_files/libplatform_utils.a dylibs/libSystem.tbd archive_files/libfilesystem.a archive_files/libzlib_client.a archive_files/liberrors.a archive_files/liblogging.a archive_files/libzlib_checked_in.a

@groodt
Copy link
Contributor

groodt commented Jan 27, 2021

Just for my own sanity, I've confirmed that it is possible to build Bazel 4.0.0 from source on my laptop running macos 10.15.7.

mkdir -p /tmp/bazel_4 && \
cd /tmp/bazel_4 && \
wget https://github.com/bazelbuild/bazel/releases/download/4.0.0/bazel-4.0.0-dist.zip && \
unzip bazel-4.0.0-dist.zip && \
./compile.sh && \
/tmp/bazel_4/output/bazel version

...

Build successful! Binary is here: /tmp/bazel_4/output/bazel
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
Build label: 4.0.0- (@non-git)
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed Jan 27 22:25:06 2021 (1611786306)
Build timestamp: 1611786306
Build timestamp as int: 1611786306

That at least gives me some comfort that it should be possible to get it building as a nixpkg.

@groodt
Copy link
Contributor

groodt commented Jan 27, 2021

@divanorama In terms of clang-7 on macos, it doesn't appear to work.

preBuildPhase building 🍃 Building Bazel from scratch....../nix/store/cy4zxw6zrcb60nx4g4k8362i4vvdjjfs-clang-wrapper-7.1.0/bin/clang -frandom-seed=gri47ap213 -Wno-deprecated-declarations -isystem /nix/store/nyrgyvvx7nz6ws6xy39wg8yysvgl0wxq-python3-3.8.7/include -isystem /nix/store/kdbfxp2p2jqjb0ic1yi9s9ppljv0y3r1-cctools-port-949.0.1-dev/include -isystem /nix/store/pmyayxmlajdabghlq3cj5qww7kqkabm7-libc++-7.1.0/include -iframework /nix/store/zjn2c2f5cfa42zz4g35i8s5cpmrgjc0s-apple-framework-CoreFoundation/Library/Frameworks -iframework /nix/store/0jqkrvv6h7n39h67mfrgcq76m5z6iymx-apple-framework-CoreServices/Library/Frameworks -iframework /nix/store/xwm6xiylcczv222n0qfd18ri9w5417ji-apple-framework-CFNetwork/Library/Frameworks -iframework /nix/store/qqp67bzq8ps1gfnpvgwzv3a634323yd0-apple-framework-CoreAudio/Library/Frameworks -iframework /nix/store/5rgj90395mycmbc0bz7mrnwrrg3i5lcj-apple-framework-IOKit/Library/Frameworks -iframework /nix/store/69qzcqx1is3mr96zp3paznfzc1bp8xm9-apple-framework-CoreData/Library/Frameworks -iframework /nix/store/m542v8zijnwvgj6jsrnbafi10f6h8gfj-apple-framework-DiskArbitration/Library/Frameworks -iframework /nix/store/r2ngnfmpg7q3cm0bv0qmyn2q79f8nfw7-apple-framework-NetFS/Library/Frameworks -iframework /nix/store/is50q2iypwyfqa60mpww5vxa4r7532ag-apple-framework-OpenDirectory/Library/Frameworks -iframework /nix/store/bd149c2zv27q6qa69mdkaxin1yr6l1m6-apple-framework-Security/Library/Frameworks -iframework /nix/store/p0x0mfnablf5zjvvg3zdpa47w9bglzdz-apple-framework-ServiceManagement/Library/Frameworks -iframework /nix/store/nxhb9wgcfyaw61iiil1kyk226rmz1fi9-apple-framework-Foundation/Library/Frameworks -iframework /nix/store/glvi60zsgkh6phzi6c1d4yj92xx44sbs-apple-framework-ApplicationServices/Library/Frameworks -iframework /nix/store/wg0chqi9vh13q8ga1n0nmr5rdksnyaxm-apple-framework-CoreGraphics/Library/Frameworks -iframework /nix/store/9c8j65wnk2cdyixrjiq33r71sgi4x1ii-apple-framework-Accelerate/Library/Frameworks -iframework /nix/store/hl1x98491nplrb8ybglkzf91m9mdmhvw-apple-framework-CoreWLAN/Library/Frameworks -iframework /nix/store/y6ai9cay32yfr08pil8jqm563vzxlfxf-apple-framework-SecurityFoundation/Library/Frameworks -iframework /nix/store/y4smd0ix309b1kc37f4g6d38hk16xd7s-apple-framework-IOBluetooth/Library/Frameworks -iframework /nix/store/x1mw9vp769igfkppxx91vm9sx2hddqr0-apple-framework-CoreBluetooth/Library/Frameworks -iframework /nix/store/jn9xah8yaibck12hf1srjk6pw0vfkr0y-apple-framework-IOSurface/Library/Frameworks -isystem /nix/store/j52papq5zz6xcjghxfiffa72wxdgnj06-apple-lib-xpc/include -iframework /nix/store/njnxkn6rb7nq4vrf7l4f4xwl0cz3fz4j-apple-framework-SystemConfiguration/Library/Frameworks -iframework /nix/store/dx2np5rn9844ax8992mgc16kfdncsr79-apple-framework-CoreText/Library/Frameworks -iframework /nix/store/4vn5gv07vx55qwn2rap2hsp10dyyphsz-apple-framework-ImageIO/Library/Frameworks -isystem /nix/store/n86k9z1cfqwbpv1iw5anrchnyncx5afd-objc4-osx-10.12.6/include -isystem /nix/store/wdcm5qprf631k0xd14136bx4nzmwjgcn-libc++abi-7.1.0/include -isystem /nix/store/r4qsc8j2bb0rl7hgpifrv7hvqlnp53kd-compiler-rt-7.1.0-dev/include -isystem /nix/store/xl4iq6714cjwcp52s9rsad09428qwv6g-zulu1.8.0_202-8.36.0.1/include -iframework /nix/store/a72hvn0fwdycxsg2bp4mwqy6gc32044s-swift-corefoundation/Library/Frameworks -isystem /nix/store/nyrgyvvx7nz6ws6xy39wg8yysvgl0wxq-python3-3.8.7/include -isystem /nix/store/kdbfxp2p2jqjb0ic1yi9s9ppljv0y3r1-cctools-port-949.0.1-dev/include -isystem /nix/store/pmyayxmlajdabghlq3cj5qww7kqkabm7-libc++-7.1.0/include -iframework /nix/store/zjn2c2f5cfa42zz4g35i8s5cpmrgjc0s-apple-framework-CoreFoundation/Library/Frameworks -iframework /nix/store/0jqkrvv6h7n39h67mfrgcq76m5z6iymx-apple-framework-CoreServices/Library/Frameworks -iframework /nix/store/xwm6xiylcczv222n0qfd18ri9w5417ji-apple-framework-CFNetwork/Library/Frameworks -iframework /nix/store/qqp67bzq8ps1gfnpvgwzv3a634323yd0-apple-framework-CoreAudio/Library/Frameworks -iframework /nix/store/5rgj90395mycmbc0bz7mrnwrrg3i5lcj-apple-framework-IOKit/Library/Frameworks -iframework /nix/store/69qzcqx1is3mr96zp3paznfzc1bp8xm9-apple-framework-CoreData/Library/Frameworks -iframework /nix/store/m542v8zijnwvgj6jsrnbafi10f6h8gfj-apple-framework-DiskArbitration/Library/Frameworks -iframework /nix/store/r2ngnfmpg7q3cm0bv0qmyn2q79f8nfw7-apple-framework-NetFS/Library/Frameworks -iframework /nix/store/is50q2iypwyfqa60mpww5vxa4r7532ag-apple-framework-OpenDirectory/Library/Frameworks -iframework /nix/store/bd149c2zv27q6qa69mdkaxin1yr6l1m6-apple-framework-Security/Library/Frameworks -iframework /nix/store/p0x0mfnablf5zjvvg3zdpa47w9bglzdz-apple-framework-ServiceManagement/Library/Frameworks -iframework /nix/store/nxhb9wgcfyaw61iiil1kyk226rmz1fi9-apple-framework-Foundation/Library/Frameworks -iframework /nix/store/glvi60zsgkh6phzi6c1d4yj92xx44sbs-apple-framework-ApplicationServices/Library/Frameworks -iframework /nix/store/wg0chqi9vh13q8ga1n0nmr5rdksnyaxm-apple-framework-CoreGraphics/Library/Frameworks -iframework /nix/store/9c8j65wnk2cdyixrjiq33r71sgi4x1ii-apple-framework-Accelerate/Library/Frameworks -iframework /nix/store/hl1x98491nplrb8ybglkzf91m9mdmhvw-apple-framework-CoreWLAN/Library/Frameworks -iframework /nix/store/y6ai9cay32yfr08pil8jqm563vzxlfxf-apple-framework-SecurityFoundation/Library/Frameworks -iframework /nix/store/y4smd0ix309b1kc37f4g6d38hk16xd7s-apple-framework-IOBluetooth/Library/Frameworks -iframework /nix/store/x1mw9vp769igfkppxx91vm9sx2hddqr0-apple-framework-CoreBluetooth/Library/Frameworks -iframework /nix/store/jn9xah8yaibck12hf1srjk6pw0vfkr0y-apple-framework-IOSurface/Library/Frameworks -isystem /nix/store/j52papq5zz6xcjghxfiffa72wxdgnj06-apple-lib-xpc/include -iframework /nix/store/njnxkn6rb7nq4vrf7l4f4xwl0cz3fz4j-apple-framework-SystemConfiguration/Library/Frameworks -iframework /nix/store/dx2np5rn9844ax8992mgc16kfdncsr79-apple-framework-CoreText/Library/Frameworks -iframework /nix/store/4vn5gv07vx55qwn2rap2hsp10dyyphsz-apple-framework-ImageIO/Library/Frameworks -isystem /nix/store/n86k9z1cfqwbpv1iw5anrchnyncx5afd-objc4-osx-10.12.6/include -isystem /nix/store/wdcm5qprf631k0xd14136bx4nzmwjgcn-libc++abi-7.1.0/include -isystem /nix/store/r4qsc8j2bb0rl7hgpifrv7hvqlnp53kd-compiler-rt-7.1.0-dev/include -isystem /nix/store/xl4iq6714cjwcp52s9rsad09428qwv6g-zulu1.8.0_202-8.36.0.1/include -iframework /nix/store/a72hvn0fwdycxsg2bp4mwqy6gc32044s-swift-corefoundation/Library/Frameworks -isystem /nix/store/pmyayxmlajdabghlq3cj5qww7kqkabm7-libc++-7.1.0/include/c++/v1 -Wl,-L/nix/store/nyrgyvvx7nz6ws6xy39wg8yysvgl0wxq-python3-3.8.7/lib -Wl,-L/nix/store/pmyayxmlajdabghlq3cj5qww7kqkabm7-libc++-7.1.0/lib -Wl,-L/nix/store/n86k9z1cfqwbpv1iw5anrchnyncx5afd-objc4-osx-10.12.6/lib -Wl,-L/nix/store/wdcm5qprf631k0xd14136bx4nzmwjgcn-libc++abi-7.1.0/lib -Wl,-L/nix/store/mlw1szrzpggfvsxm7c39m6qkrrhjjkgb-compiler-rt-7.1.0/lib -Wl,-L/nix/store/nyrgyvvx7nz6ws6xy39wg8yysvgl0wxq-python3-3.8.7/lib -Wl,-L/nix/store/pmyayxmlajdabghlq3cj5qww7kqkabm7-libc++-7.1.0/lib -Wl,-L/nix/store/n86k9z1cfqwbpv1iw5anrchnyncx5afd-objc4-osx-10.12.6/lib -Wl,-L/nix/store/wdcm5qprf631k0xd14136bx4nzmwjgcn-libc++abi-7.1.0/lib -Wl,-L/nix/store/mlw1szrzpggfvsxm7c39m6qkrrhjjkgb-compiler-rt-7.1.0/lib -Wl,-F/nix/store/zjn2c2f5cfa42zz4g35i8s5cpmrgjc0s-apple-framework-CoreFoundation/Library/Frameworks -Wl,-F/nix/store/0jqkrvv6h7n39h67mfrgcq76m5z6iymx-apple-framework-CoreServices/Library/Frameworks -Wl,-F/nix/store/nxhb9wgcfyaw61iiil1kyk226rmz1fi9-apple-framework-Foundation/Library/Frameworks -framework CoreFoundation -mmacosx-version-min=10.9 -fobjc-arc -framework CoreServices -framework Foundation -o /private/tmp/nix-build-bazel-4.0.0.drv-0/bazel_1KTk5o9j/archive/xcode-locator tools/osx/xcode_locator.m ld: file not found: /nix/store/1pf2sj7rp2wazrzb450kcpiigi8m6z82-clang-7.1.0/lib/arc/libarclite_macosx.a clang-7: error: linker command failed with exit code 1 (use -v to see invocation)

I'll need to pause my investigations for now.

@avdv
Copy link
Member

avdv commented Jan 29, 2021

@divanorama In terms of clang-7 on macos, it doesn't appear to work.

preBuildPhase building 🍃 Building Bazel from scratch....../nix/store/cy4zxw6zrcb60nx4g4k8362i4vvdjjfs-clang-wrapper-7.1.0/bin/clang -frandom-seed=gri47ap213 -Wno-deprecated-declarations -isystem /nix/store/nyrgyvvx7nz6ws6xy39wg8yysvgl0wxq-python3-3.8.7/include -isystem /nix/store/kdbfxp2p2jqjb0ic1yi9s9ppljv0y3r1-cctools-port-949.0.1-dev/include -isystem /nix/store/pmyayxmlajdabghlq3cj5qww7kqkabm7-libc++-7.1.0/include -iframework /nix/store/zjn2c2f5cfa42zz4g35i8s5cpmrgjc0s-apple-framework-CoreFoundation/Library/Frameworks -iframework /nix/store/0jqkrvv6h7n39h67mfrgcq76m5z6iymx-apple-framework-CoreServices/Library/Frameworks -iframework /nix/store/xwm6xiylcczv222n0qfd18ri9w5417ji-apple-framework-CFNetwork/Library/Frameworks -iframework /nix/store/qqp67bzq8ps1gfnpvgwzv3a634323yd0-apple-framework-CoreAudio/Library/Frameworks -iframework /nix/store/5rgj90395mycmbc0bz7mrnwrrg3i5lcj-apple-framework-IOKit/Library/Frameworks -iframework /nix/store/69qzcqx1is3mr96zp3paznfzc1bp8xm9-apple-framework-CoreData/Library/Frameworks -iframework /nix/store/m542v8zijnwvgj6jsrnbafi10f6h8gfj-apple-framework-DiskArbitration/Library/Frameworks -iframework /nix/store/r2ngnfmpg7q3cm0bv0qmyn2q79f8nfw7-apple-framework-NetFS/Library/Frameworks -iframework /nix/store/is50q2iypwyfqa60mpww5vxa4r7532ag-apple-framework-OpenDirectory/Library/Frameworks -iframework /nix/store/bd149c2zv27q6qa69mdkaxin1yr6l1m6-apple-framework-Security/Library/Frameworks -iframework /nix/store/p0x0mfnablf5zjvvg3zdpa47w9bglzdz-apple-framework-ServiceManagement/Library/Frameworks -iframework /nix/store/nxhb9wgcfyaw61iiil1kyk226rmz1fi9-apple-framework-Foundation/Library/Frameworks -iframework /nix/store/glvi60zsgkh6phzi6c1d4yj92xx44sbs-apple-framework-ApplicationServices/Library/Frameworks -iframework /nix/store/wg0chqi9vh13q8ga1n0nmr5rdksnyaxm-apple-framework-CoreGraphics/Library/Frameworks -iframework /nix/store/9c8j65wnk2cdyixrjiq33r71sgi4x1ii-apple-framework-Accelerate/Library/Frameworks -iframework /nix/store/hl1x98491nplrb8ybglkzf91m9mdmhvw-apple-framework-CoreWLAN/Library/Frameworks -iframework /nix/store/y6ai9cay32yfr08pil8jqm563vzxlfxf-apple-framework-SecurityFoundation/Library/Frameworks -iframework /nix/store/y4smd0ix309b1kc37f4g6d38hk16xd7s-apple-framework-IOBluetooth/Library/Frameworks -iframework /nix/store/x1mw9vp769igfkppxx91vm9sx2hddqr0-apple-framework-CoreBluetooth/Library/Frameworks -iframework /nix/store/jn9xah8yaibck12hf1srjk6pw0vfkr0y-apple-framework-IOSurface/Library/Frameworks -isystem /nix/store/j52papq5zz6xcjghxfiffa72wxdgnj06-apple-lib-xpc/include -iframework /nix/store/njnxkn6rb7nq4vrf7l4f4xwl0cz3fz4j-apple-framework-SystemConfiguration/Library/Frameworks -iframework /nix/store/dx2np5rn9844ax8992mgc16kfdncsr79-apple-framework-CoreText/Library/Frameworks -iframework /nix/store/4vn5gv07vx55qwn2rap2hsp10dyyphsz-apple-framework-ImageIO/Library/Frameworks -isystem /nix/store/n86k9z1cfqwbpv1iw5anrchnyncx5afd-objc4-osx-10.12.6/include -isystem /nix/store/wdcm5qprf631k0xd14136bx4nzmwjgcn-libc++abi-7.1.0/include -isystem /nix/store/r4qsc8j2bb0rl7hgpifrv7hvqlnp53kd-compiler-rt-7.1.0-dev/include -isystem /nix/store/xl4iq6714cjwcp52s9rsad09428qwv6g-zulu1.8.0_202-8.36.0.1/include -iframework /nix/store/a72hvn0fwdycxsg2bp4mwqy6gc32044s-swift-corefoundation/Library/Frameworks -isystem /nix/store/nyrgyvvx7nz6ws6xy39wg8yysvgl0wxq-python3-3.8.7/include -isystem /nix/store/kdbfxp2p2jqjb0ic1yi9s9ppljv0y3r1-cctools-port-949.0.1-dev/include -isystem /nix/store/pmyayxmlajdabghlq3cj5qww7kqkabm7-libc++-7.1.0/include -iframework /nix/store/zjn2c2f5cfa42zz4g35i8s5cpmrgjc0s-apple-framework-CoreFoundation/Library/Frameworks -iframework /nix/store/0jqkrvv6h7n39h67mfrgcq76m5z6iymx-apple-framework-CoreServices/Library/Frameworks -iframework /nix/store/xwm6xiylcczv222n0qfd18ri9w5417ji-apple-framework-CFNetwork/Library/Frameworks -iframework /nix/store/qqp67bzq8ps1gfnpvgwzv3a634323yd0-apple-framework-CoreAudio/Library/Frameworks -iframework /nix/store/5rgj90395mycmbc0bz7mrnwrrg3i5lcj-apple-framework-IOKit/Library/Frameworks -iframework /nix/store/69qzcqx1is3mr96zp3paznfzc1bp8xm9-apple-framework-CoreData/Library/Frameworks -iframework /nix/store/m542v8zijnwvgj6jsrnbafi10f6h8gfj-apple-framework-DiskArbitration/Library/Frameworks -iframework /nix/store/r2ngnfmpg7q3cm0bv0qmyn2q79f8nfw7-apple-framework-NetFS/Library/Frameworks -iframework /nix/store/is50q2iypwyfqa60mpww5vxa4r7532ag-apple-framework-OpenDirectory/Library/Frameworks -iframework /nix/store/bd149c2zv27q6qa69mdkaxin1yr6l1m6-apple-framework-Security/Library/Frameworks -iframework /nix/store/p0x0mfnablf5zjvvg3zdpa47w9bglzdz-apple-framework-ServiceManagement/Library/Frameworks -iframework /nix/store/nxhb9wgcfyaw61iiil1kyk226rmz1fi9-apple-framework-Foundation/Library/Frameworks -iframework /nix/store/glvi60zsgkh6phzi6c1d4yj92xx44sbs-apple-framework-ApplicationServices/Library/Frameworks -iframework /nix/store/wg0chqi9vh13q8ga1n0nmr5rdksnyaxm-apple-framework-CoreGraphics/Library/Frameworks -iframework /nix/store/9c8j65wnk2cdyixrjiq33r71sgi4x1ii-apple-framework-Accelerate/Library/Frameworks -iframework /nix/store/hl1x98491nplrb8ybglkzf91m9mdmhvw-apple-framework-CoreWLAN/Library/Frameworks -iframework /nix/store/y6ai9cay32yfr08pil8jqm563vzxlfxf-apple-framework-SecurityFoundation/Library/Frameworks -iframework /nix/store/y4smd0ix309b1kc37f4g6d38hk16xd7s-apple-framework-IOBluetooth/Library/Frameworks -iframework /nix/store/x1mw9vp769igfkppxx91vm9sx2hddqr0-apple-framework-CoreBluetooth/Library/Frameworks -iframework /nix/store/jn9xah8yaibck12hf1srjk6pw0vfkr0y-apple-framework-IOSurface/Library/Frameworks -isystem /nix/store/j52papq5zz6xcjghxfiffa72wxdgnj06-apple-lib-xpc/include -iframework /nix/store/njnxkn6rb7nq4vrf7l4f4xwl0cz3fz4j-apple-framework-SystemConfiguration/Library/Frameworks -iframework /nix/store/dx2np5rn9844ax8992mgc16kfdncsr79-apple-framework-CoreText/Library/Frameworks -iframework /nix/store/4vn5gv07vx55qwn2rap2hsp10dyyphsz-apple-framework-ImageIO/Library/Frameworks -isystem /nix/store/n86k9z1cfqwbpv1iw5anrchnyncx5afd-objc4-osx-10.12.6/include -isystem /nix/store/wdcm5qprf631k0xd14136bx4nzmwjgcn-libc++abi-7.1.0/include -isystem /nix/store/r4qsc8j2bb0rl7hgpifrv7hvqlnp53kd-compiler-rt-7.1.0-dev/include -isystem /nix/store/xl4iq6714cjwcp52s9rsad09428qwv6g-zulu1.8.0_202-8.36.0.1/include -iframework /nix/store/a72hvn0fwdycxsg2bp4mwqy6gc32044s-swift-corefoundation/Library/Frameworks -isystem /nix/store/pmyayxmlajdabghlq3cj5qww7kqkabm7-libc++-7.1.0/include/c++/v1 -Wl,-L/nix/store/nyrgyvvx7nz6ws6xy39wg8yysvgl0wxq-python3-3.8.7/lib -Wl,-L/nix/store/pmyayxmlajdabghlq3cj5qww7kqkabm7-libc++-7.1.0/lib -Wl,-L/nix/store/n86k9z1cfqwbpv1iw5anrchnyncx5afd-objc4-osx-10.12.6/lib -Wl,-L/nix/store/wdcm5qprf631k0xd14136bx4nzmwjgcn-libc++abi-7.1.0/lib -Wl,-L/nix/store/mlw1szrzpggfvsxm7c39m6qkrrhjjkgb-compiler-rt-7.1.0/lib -Wl,-L/nix/store/nyrgyvvx7nz6ws6xy39wg8yysvgl0wxq-python3-3.8.7/lib -Wl,-L/nix/store/pmyayxmlajdabghlq3cj5qww7kqkabm7-libc++-7.1.0/lib -Wl,-L/nix/store/n86k9z1cfqwbpv1iw5anrchnyncx5afd-objc4-osx-10.12.6/lib -Wl,-L/nix/store/wdcm5qprf631k0xd14136bx4nzmwjgcn-libc++abi-7.1.0/lib -Wl,-L/nix/store/mlw1szrzpggfvsxm7c39m6qkrrhjjkgb-compiler-rt-7.1.0/lib -Wl,-F/nix/store/zjn2c2f5cfa42zz4g35i8s5cpmrgjc0s-apple-framework-CoreFoundation/Library/Frameworks -Wl,-F/nix/store/0jqkrvv6h7n39h67mfrgcq76m5z6iymx-apple-framework-CoreServices/Library/Frameworks -Wl,-F/nix/store/nxhb9wgcfyaw61iiil1kyk226rmz1fi9-apple-framework-Foundation/Library/Frameworks -framework CoreFoundation -mmacosx-version-min=10.9 -fobjc-arc -framework CoreServices -framework Foundation -o /private/tmp/nix-build-bazel-4.0.0.drv-0/bazel_1KTk5o9j/archive/xcode-locator tools/osx/xcode_locator.m ld: file not found: /nix/store/1pf2sj7rp2wazrzb450kcpiigi8m6z82-clang-7.1.0/lib/arc/libarclite_macosx.a clang-7: error: linker command failed with exit code 1 (use -v to see invocation)

I'll need to pause my investigations for now.

I also thought about upgrading clang and ran into the same issue. I found out that libarclite is the automatic reference counting library of objective C which is needed when you use it within your code.

Which boils down to the question why clang 6 is able to compile this code but clang 7 fails. Could this be an issue within clang 7 itself?!

Where does this library come from?

@divanorama
Copy link
Contributor Author

https://discourse.nixos.org/t/linker-file-not-found-lib-arc-libarclite-macosx-a-on-darwin/10486
says -fobjc-arc links against closed-source macos lib

Which could be coming from https://github.com/bazelbuild/bazel/blob/4.0.0/scripts/bootstrap/compile.sh#L410
Or also from few other places in bazel code.

Though it was there in bazel-3.3.1 too, maybe clang-6 in NixPkgs can pick it up from host but clang-7 doesn't?

@divanorama divanorama mentioned this pull request Jan 30, 2021
10 tasks
@groodt
Copy link
Contributor

groodt commented Jan 30, 2021

Interestingly, this seems to improve things.

diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix
index 48a3ebb32df..49d662b263f 100644
--- a/pkgs/build-support/bintools-wrapper/default.nix
+++ b/pkgs/build-support/bintools-wrapper/default.nix
@@ -252,7 +252,7 @@ stdenv.mkDerivation {

     # Ensure consistent LC_VERSION_MIN_MACOSX and remove LC_UUID.
     + optionalString stdenv.targetPlatform.isMacOS ''
-      echo "-sdk_version 10.12 -no_uuid" >> $out/nix-support/libc-ldflags-before
+      echo "-macosx_version_min 10.12 -sdk_version 10.12 -no_uuid" >> $out/nix-support/libc-ldflags-before
     ''

     ##

This is similar advice to the comment here from @kalbasit: #105439 (comment)

It takes too long to build with this patch, so I'm not sure how to set -macosx_version_min 10.12 only for bazel.

The error then progresses to:

Execution platform: //:default_host_platform
[728 / 838] 15 actions running
    Compiling src/core/ext/filters/client_channel/client_channel.cc; 4s local
    @com_github_grpc_grpc//:grpc_lb_policy_weighted_target; 3s local
    Compiling src/main/protobuf/failure_details.pb.cc; 2s local
    Compiling src/main/protobuf/command_server.pb.cc; 2s local
    Compiling absl/time/internal/cctz/src/time_zone_impl.cc; 2s local
    Compiling absl/time/internal/cctz/src/time_zone_format.cc; 1s local
    Compiling absl/time/internal/cctz/src/time_zone_libc.cc; 1s local
    Compiling absl/time/internal/cctz/src/time_zone_info.cc; 0s local ...
In file included from external/com_github_grpc_grpc/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc:36:
In file included from external/com_github_grpc_grpc/src/core/ext/xds/xds_client.h:27:
In file included from external/com_github_grpc_grpc/src/core/ext/xds/xds_api.h:30:
external/com_github_google_re2/re2/re2.h:973:8: error: thread-local storage is not supported for the current target
extern thread_local const RE2* context;
       ^
1 error generated.
[728 / 838] 15 actions running

@groodt
Copy link
Contributor

groodt commented Jan 30, 2021

I've been trying to work out if the versoin of re2 in the prior version of Bazel in nix included the thread_local code.

It seems that the thread_local was introduced into re2 in this google/re2@4f5e6c2 commit on 14 Feb 2020, so fairly recent.

I've yet to work out the dependency graph that pulls in re2 and how to determine the version of re2 that was in Bazel 3.3.1 to see if it was a version of re2 prior to this.

I'll have to pause my investigations for now.

Summary of my view of the situation on Darwin

  1. Really confusing situation with bintools-wrapper. Without the reverted patch to bintools-wrapper there is a linker error on macos 1.15.7 (apparently this issue is not seen on macos Big Sur).
  2. With the patch to bintools-wrapper in place (or macos Big Sur apparently) the failure to build sits with a thread_local declaration in re2.
  3. Attempting to build with clang7 results in a linker error with a missing libarclite.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nixpkgs-bazel-4-darwin-assistance/11303/1

@groodt
Copy link
Contributor

groodt commented Jan 31, 2021

It appears that re2 started to appear as a dependency in the Bazel repo with this commit:
bazelbuild/bazel@a74096f on 10 October 2020.

I believe the dependencies are as follows:

Bazel 4.0.0 -> grpc 1.32.0 -> re2 aecba11114cf1fac5497aeb844b6966106de3eb6

It appears that Bazel 3.3.1 (release on 1 July 2020) had no directly listed dependency on re2. So it appears the thread_local compilation error was not present in this version.

From what I can gather:

Bazel 3.3.1 -> grpc 1.20.0 (no re2 dependency)

@divanorama
Copy link
Contributor Author

divanorama commented Jan 31, 2021

re2 had some fixes to disable thread local google/re2@f2a896b and google/re2@d8d0c66
both should be included in the version used in bazel.

Not clear whether clang on darwin in nix should have thread local support or not though.
Also found this https://stackoverflow.com/questions/28094794/why-does-apple-clang-disallow-c11-thread-local-when-official-clang-supports/29929949#29929949

@groodt
Copy link
Contributor

groodt commented Jan 31, 2021

re2 had some fixes to disable thread local google/re2@f2a896b and google/re2@d8d0c66
both should be included in the version used in bazel.

I believe that macro is to disable it for devices such as iphone, ipad etc. The authors would expect a mac to have thread_local support because it isn't written with Nix in mind, it is written expecting a standard OSX user with XCode etc. That is my reading of it anyway.

Not clear whether clang on darwin in nix should have thread local support or not though.
Also found this https://stackoverflow.com/questions/28094794/why-does-apple-clang-disallow-c11-thread-local-when-official-clang-supports/29929949#29929949

Yes, and if nixpkgs clang on darwin does not support thread_local, packages such as re2 would not expect it. They would assume that users would be compiling on the official Apple toolchains.

I'm not entirely sure where this leaves us.

I think we either need some nixpkgs Darwin experts or it might be the end of the road for nixpkgs Bazel on Darwin? I'm not sure how feasible it would be to patch ourselves out of this problem very easily. From my perspective I would still prefer to have bazel available on darwin nixpkgs.

@kalbasit
Copy link
Member

@LnL7 do you have any idea if nixpkgs could support clang thread_local and how much work could that take?

@divanorama
Copy link
Contributor Author

divanorama commented Jan 31, 2021

As for patching it, this https://github.com/divanorama/nixpkgs/pull/1/files may do it.
Nested patches, but essentially puts following into re2.h

#if defined(__APPLE__)
#undef RE2_HAVE_THREAD_LOCAL
#endif

There may be other failures, including on thread local, further down the build though

@groodt
Copy link
Contributor

groodt commented Feb 1, 2021

As for patching it, this https://github.com/divanorama/nixpkgs/pull/1/files may do it.

🎉 That has got it working locally for me @divanorama (with one large caveat)

/nix/store/x23wyhsyh254wk2lmkp14bqacq2hwwj1-bazel-4.0.0

~/repos/nixpkgs bazel_4_darwin* 7m 10s
❯
  /nix/store/x23wyhsyh254wk2lmkp14bqacq2hwwj1-bazel-4.0.0/bin/bazel version
Extracting Bazel installation...
Build label: 4.0.0- (@non-git)
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Jan 1 00:00:00 1980 (315532800)
Build timestamp: 315532800
Build timestamp as int: 315532800

Caveat:
I still need to include this change #106984 (comment) to the bintools-wrapper to make this work on my macos 10.15.7 (Catalina) machine.

Can you ask your friend with Big Sur to see if it works without the patch?

So I think we are close, but I still think this bintools-wrapper change needs some assistance to understand why it was made and why reverting it is necessary to allow this nixpkg to build successfully on Catalina.

@groodt
Copy link
Contributor

groodt commented Feb 1, 2021

In breaking news, @avdv may have found a patch to get things working on Clang7 which avoids the bintools-wrapper issue and possibly the re2 thread_local issue as well. 🎉

#105439 (comment)

divanorama and others added 8 commits February 4, 2021 20:24
Bazel 4 is going to be a long term support release.

Latest version in NixPkgs so far was 3.3.1
There's a need for more recent version
NixOS#97497

All versions from 3.5.0 to 3.7.1 had some reproducibility issues
as noted in issue above, but there also seems to be
a working PR for 3.7.1 now at
NixOS#105439

Notable changes from bazel_3 setup:
- put python to default bash path

  For autodetecting python toolchain
  with strict action_env on and without this change
  bazel would fail to autodetect host python.

  There are some repos that define hermetic python
  toolchains, but they aren't easy to use yet. Also
  telling python paths to bazel isn't a 1-liner it
  seems:
  - action_env=PATH would affect cache
  - declaring toolchain via BUILD&WORKSPACE files
    is not per-user but more like per-repo and
    affects cache too

  Using python from nixpkgs shouldn't be too bad
  in the lack of simpler hermetic python toolchain
  options

- bazel_4.updater is bazel on `bazel query` to support
  new constructs in WORKSPACE (load of vars, transitive
  load etc). This is more robust but requires bazel
  to run the updater, using bazel_3 for now. This is
  only needed to bump package version, doesn't introduce
  bazel_4 build dependency on bazel_3

https://blog.bazel.build/2020/11/10/bazel-4.0-announce.html
https://blog.bazel.build/2020/11/10/long-term-support-release.html
bazelbuild/bazel#12455
https://github.com/bazelbuild/bazel/releases/tag/4.0.0
https://blog.bazel.build/2021/01/19/bazel-4-0.html
- bump protobuf to 3.13.0
- use recent rules_proto
- use recent bazel-skylib
- remove use of native.bind

Hopefully this is backward-compatible with bazel_3 and below
* use default stdenv (clang 7)
* add no-arc.patch to make the xcode_locate tool compile without libarc-lite
* remove the `-mmacosx-version-min=10.9` flag from the bootstrap compile script
Use the same JDK for building bazel and for its runtime.

Effectively, the former `toolchain_hostjdk8` java toolchain has been deprecated
and should no longer be used (in newer bazel)[1]:

```
default_java_toolchain(
    name = "toolchain_hostjdk8",
    ...
)
```

[1]: https://github.com/bazelbuild/bazel/blob/4fc48680653a71aacbfd555436ba8f9a0742d3d9/tools/jdk/BUILD.tools#L384-L387
@groodt
Copy link
Contributor

groodt commented Feb 4, 2021

Thanks a lot @divanorama 🚀

Apologies for sending you down the rabbit hole to patch re2, but it does help set things on the right track for 3.7.2 and get this all moving again on darwin.

@groodt
Copy link
Contributor

groodt commented Feb 9, 2021

This works for me locally on Darwin. 🎉

❯ /nix/store/045scrssgyh0vrxhj0lf6ajjmx89wjb2-bazel-4.0.0/bin/bazel version
Build label: 4.0.0- (@non-git)
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue. Jan. 1 00:00:00 1980 (315532800)
Build timestamp: 315532800
Build timestamp as int: 315532800

Is there something more to be done before this can be merged @mboes @Profpatsch ?

@mboes
Copy link
Contributor

mboes commented Feb 9, 2021

@Profpatsch I don't have merge rights so passing the puck to you.

@kalbasit
Copy link
Member

kalbasit commented Feb 9, 2021

I can merge it..

Copy link
Member

@kalbasit kalbasit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants