···8# updater
9, python3, writeScript
10# Apple dependencies
11-, cctools, libcxx, CoreFoundation, CoreServices, Foundation
12# Allow to independently override the jdks used to build and run respectively
13, buildJdk, runJdk
14, runtimeShell
···25}:
2627let
28- version = "6.4.0";
29 sourceRoot = ".";
3031 src = fetchurl {
32 url = "https://github.com/bazelbuild/bazel/releases/download/${version}/bazel-${version}-dist.zip";
33- hash = "sha256-vYj/YCyLuynugroqaxKtCS1R7GaMZXf5Yo8Y5I/05R4=";
34 };
3536 # Update with
···179180in
181stdenv.mkDerivation rec {
182- pname = "bazel";
183 inherit version;
184185 meta = with lib; {
···205 # the prebuilt one does not work in nix world.
206 ./java_toolchain.patch
207000000000000000000000208 # On Darwin, the last argument to gcc is coming up as an empty string. i.e: ''
209 # This is breaking the build of any C target. This patch removes the last
210 # argument if it's found to be an empty string.
···289 bazelTest = { name, bazelScript, workspaceDir, bazelPkg, buildInputs ? [] }:
290 let
291 be = extracted bazelPkg;
292- in runLocal name { inherit buildInputs; } (
0000293 # skip extraction caching on Darwin, because nobody knows how Darwin works
294 (lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
295 # set up home with pre-unpacked bazel
···403 export NIX_CFLAGS_COMPILE+=" -Wno-deprecated-builtins -Wno-gnu-offsetof-extensions"
404405 # don't use system installed Xcode to run clang, use Nix clang instead
406- sed -i -E "s;/usr/bin/xcrun (--sdk macosx )?clang;${stdenv.cc}/bin/clang $NIX_CFLAGS_COMPILE $(bazelLinkFlags) -framework CoreFoundation;g" \
000407 scripts/bootstrap/compile.sh \
408 tools/osx/BUILD
409···557 which
558 zip
559 python3.pkgs.absl-py # Needed to build fish completion
560- ] ++ lib.optionals (stdenv.isDarwin) [ cctools libcxx CoreFoundation CoreServices Foundation ];
561562 # Bazel makes extensive use of symlinks in the WORKSPACE.
563 # This causes problems with infinite symlinks if the build output is in the same location as the
···593 ${python3}/bin/python3 ./bazel_src/scripts/generate_fish_completion.py \
594 --bazel=./bazel_src/output/bazel \
595 --output=./bazel_src/output/bazel-complete.fish
596-000597 # need to change directory for bazel to find the workspace
598 cd ./bazel_src
599 # build execlog tooling
···617 wrapProgram $out/bin/bazel $wrapperfile --suffix PATH : ${defaultShellPath}
618 mv ./bazel_src/output/bazel $out/bin/bazel-${version}-${system}-${arch}
6190000620 mkdir $out/share
621 cp ./bazel_src/bazel-bin/src/tools/execlog/parser_deploy.jar $out/share/parser_deploy.jar
622 cat <<EOF > $out/bin/bazel-execlog
···624 ${runJdk}/bin/java -jar $out/share/parser_deploy.jar \$@
625 EOF
626 chmod +x $out/bin/bazel-execlog
627-628 # shell completion files
629 installShellCompletion --bash \
630 --name bazel.bash \
···677678 # second call succeeds because it defers to $out/bin/bazel-{version}-{os_arch}
679 hello_test
0000000680681 runHook postInstall
682 '';
···8# updater
9, python3, writeScript
10# Apple dependencies
11+, cctools, libcxx, CoreFoundation, CoreServices, Foundation, sigtool
12# Allow to independently override the jdks used to build and run respectively
13, buildJdk, runJdk
14, runtimeShell
···25}:
2627let
28+ version = "6.5.0";
29 sourceRoot = ".";
3031 src = fetchurl {
32 url = "https://github.com/bazelbuild/bazel/releases/download/${version}/bazel-${version}-dist.zip";
33+ hash = "sha256-/InakZQVKJ8p5P8YpeAScOzppv6Dy2CWchi6xKO7PtI=";
34 };
3536 # Update with
···179180in
181stdenv.mkDerivation rec {
182+ pname = "bazel${ lib.optionalString enableNixHacks "-hacks" }";
183 inherit version;
184185 meta = with lib; {
···205 # the prebuilt one does not work in nix world.
206 ./java_toolchain.patch
207208+ # Bazel integrates with apple IOKit to inhibit and track system sleep.
209+ # Inside the darwin sandbox, these API calls are blocked, and bazel
210+ # crashes. It seems possible to allow these APIs inside the sandbox, but it
211+ # feels simpler to patch bazel not to use it at all. So our bazel is
212+ # incapable of preventing system sleep, which is a small price to pay to
213+ # guarantee that it will always run in any nix context.
214+ #
215+ # See also ./bazel_darwin_sandbox.patch in bazel_5. That patch uses
216+ # NIX_BUILD_TOP env var to conditionnally disable sleep features inside the
217+ # sandbox.
218+ #
219+ # If you want to investigate the sandbox profile path,
220+ # IORegisterForSystemPower can be allowed with
221+ #
222+ # propagatedSandboxProfile = ''
223+ # (allow iokit-open (iokit-user-client-class "RootDomainUserClient"))
224+ # '';
225+ #
226+ # I do not know yet how to allow IOPMAssertion{CreateWithName,Release}
227+ ./darwin_sleep.patch
228+229 # On Darwin, the last argument to gcc is coming up as an empty string. i.e: ''
230 # This is breaking the build of any C target. This patch removes the last
231 # argument if it's found to be an empty string.
···310 bazelTest = { name, bazelScript, workspaceDir, bazelPkg, buildInputs ? [] }:
311 let
312 be = extracted bazelPkg;
313+ in runLocal name {
314+ inherit buildInputs;
315+ # Necessary for the tests to pass on Darwin with sandbox enabled.
316+ __darwinAllowLocalNetworking = true;
317+ } (
318 # skip extraction caching on Darwin, because nobody knows how Darwin works
319 (lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
320 # set up home with pre-unpacked bazel
···428 export NIX_CFLAGS_COMPILE+=" -Wno-deprecated-builtins -Wno-gnu-offsetof-extensions"
429430 # don't use system installed Xcode to run clang, use Nix clang instead
431+ sed -i -E \
432+ -e "s;/usr/bin/xcrun (--sdk macosx )?clang;${stdenv.cc}/bin/clang $NIX_CFLAGS_COMPILE $(bazelLinkFlags) -framework CoreFoundation;g" \
433+ -e "s;/usr/bin/codesign;CODESIGN_ALLOCATE=${cctools}/bin/${cctools.targetPrefix}codesign_allocate ${sigtool}/bin/codesign;" \
434+ -e "s;env -i codesign;env -i CODESIGN_ALLOCATE=${cctools}/bin/${cctools.targetPrefix}codesign_allocate ${sigtool}/bin/codesign;" \
435 scripts/bootstrap/compile.sh \
436 tools/osx/BUILD
437···585 which
586 zip
587 python3.pkgs.absl-py # Needed to build fish completion
588+ ] ++ lib.optionals (stdenv.isDarwin) [ cctools libcxx sigtool CoreFoundation CoreServices Foundation ];
589590 # Bazel makes extensive use of symlinks in the WORKSPACE.
591 # This causes problems with infinite symlinks if the build output is in the same location as the
···621 ${python3}/bin/python3 ./bazel_src/scripts/generate_fish_completion.py \
622 --bazel=./bazel_src/output/bazel \
623 --output=./bazel_src/output/bazel-complete.fish
624+ '' +
625+ # disable execlog parser on darwin, since it fails to build
626+ # see https://github.com/NixOS/nixpkgs/pull/273774#issuecomment-1865322055
627+ lib.optionalString (!stdenv.isDarwin) ''
628 # need to change directory for bazel to find the workspace
629 cd ./bazel_src
630 # build execlog tooling
···648 wrapProgram $out/bin/bazel $wrapperfile --suffix PATH : ${defaultShellPath}
649 mv ./bazel_src/output/bazel $out/bin/bazel-${version}-${system}-${arch}
650651+ '' +
652+ # disable execlog parser on darwin, since it fails to build
653+ # see https://github.com/NixOS/nixpkgs/pull/273774#issuecomment-1865322055
654+ (lib.optionalString (!stdenv.isDarwin) ''
655 mkdir $out/share
656 cp ./bazel_src/bazel-bin/src/tools/execlog/parser_deploy.jar $out/share/parser_deploy.jar
657 cat <<EOF > $out/bin/bazel-execlog
···659 ${runJdk}/bin/java -jar $out/share/parser_deploy.jar \$@
660 EOF
661 chmod +x $out/bin/bazel-execlog
662+ '') + ''
663 # shell completion files
664 installShellCompletion --bash \
665 --name bazel.bash \
···712713 # second call succeeds because it defers to $out/bin/bazel-{version}-{os_arch}
714 hello_test
715+716+ ## Test that the GSON serialisation files are present
717+ gson_classes=$(unzip -l $($out/bin/bazel info install_base)/A-server.jar | grep -F -c _GsonTypeAdapter.class)
718+ if [ "$gson_classes" -lt 10 ]; then
719+ echo "Missing GsonTypeAdapter classes in A-server.jar. Lockfile generation will not work"
720+ exit 1
721+ fi
722723 runHook postInstall
724 '';
···213 #
214 # See also ./bazel_darwin_sandbox.patch in bazel_5. That patch uses
215 # NIX_BUILD_TOP env var to conditionnally disable sleep features inside the
216- # sandbox. Oddly, bazel_6 does not need that patch :-/.
217 #
218 # If you want to investigate the sandbox profile path,
219 # IORegisterForSystemPower can be allowed with
···213 #
214 # See also ./bazel_darwin_sandbox.patch in bazel_5. That patch uses
215 # NIX_BUILD_TOP env var to conditionnally disable sleep features inside the
216+ # sandbox.
217 #
218 # If you want to investigate the sandbox profile path,
219 # IORegisterForSystemPower can be allowed with