From 30cbfd470de5879ce99e19d052b082d767418ea7 Mon Sep 17 00:00:00 2001 From: Guillaume Maudoux Date: Fri, 20 Oct 2023 04:34:23 +0200 Subject: [PATCH] bazel_7: More refactors --- .../bazel/bazel_7/actions_path.patch | 6 -- .../build-managers/bazel/bazel_7/default.nix | 64 ++++++++----------- .../bazel/bazel_7/java_toolchain.patch | 6 -- .../build-managers/bazel/bazel_7/no-arc.patch | 6 -- .../bazel/bazel_7/strict_proto_deps.patch | 6 -- .../trim-last-argument-to-gcc-if-empty.patch | 6 -- 6 files changed, 27 insertions(+), 67 deletions(-) diff --git a/pkgs/development/tools/build-managers/bazel/bazel_7/actions_path.patch b/pkgs/development/tools/build-managers/bazel/bazel_7/actions_path.patch index 00816b280fdb..3821b6a8c9dc 100644 --- a/pkgs/development/tools/build-managers/bazel/bazel_7/actions_path.patch +++ b/pkgs/development/tools/build-managers/bazel/bazel_7/actions_path.patch @@ -1,9 +1,3 @@ -commit 595756621dd858cf18033af2c4707d2fe8548350 -Author: Guillaume Maudoux -Date: Fri Oct 6 15:09:56 2023 +0200 - - actions_path.patch - diff --git a/src/main/java/com/google/devtools/build/lib/exec/local/PosixLocalEnvProvider.java b/src/main/java/com/google/devtools/build/lib/exec/local/PosixLocalEnvProvider.java index 8284eff943..a820037968 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/local/PosixLocalEnvProvider.java diff --git a/pkgs/development/tools/build-managers/bazel/bazel_7/default.nix b/pkgs/development/tools/build-managers/bazel/bazel_7/default.nix index 4bdb1d29ed76..ebd726bd4953 100644 --- a/pkgs/development/tools/build-managers/bazel/bazel_7/default.nix +++ b/pkgs/development/tools/build-managers/bazel/bazel_7/default.nix @@ -208,6 +208,10 @@ stdenv.mkDerivation rec { # incapable of preventing system sleep, which is a small price to pay to # guarantee that it will always run in any nix context. # + # See also ./bazel_darwin_sandbox.patch in bazel_5. That patch uses + # NIX_BUILD_TOP env var to conditionnally disable sleep features inside the + # sandbox. Oddly, bazel_6 does not need that patch :-/. + # # If you want to investigate the sandbox profile path, # IORegisterForSystemPower can be allowed with # @@ -224,6 +228,7 @@ stdenv.mkDerivation rec { ../trim-last-argument-to-gcc-if-empty.patch # XXX: This seems merged / not a real problem. See PR. + # TODO: Remove when protobuf tests confirm it is not needed. # `java_proto_library` ignores `strict_proto_deps` # https://github.com/bazelbuild/bazel/pull/16146 # ./strict_proto_deps.patch @@ -261,26 +266,16 @@ stdenv.mkDerivation rec { src = ../bazel_rc.patch; bazelSystemBazelRCPath = bazelRC; }) - ] ++ lib.optional enableNixHacks ./nix-hacks.patch; + ] + # See enableNixHacks argument above. + ++ lib.optional enableNixHacks ./nix-hacks.patch; - # Additional tests that check bazel’s functionality. Execute - # - # nix-build . -A bazel_7.tests - # - # in the nixpkgs checkout root to exercise them locally. - passthru.tests = callPackage ./tests.nix { - inherit Foundation bazel_self distDir repoCache runJdk; - }; - - passthru.updater = throw "TODO"; - # Bazel starts a local server and needs to bind a local address. __darwinAllowLocalNetworking = true; postPatch = let - darwinPatches = '' bazelLinkFlags () { eval set -- "$NIX_LDFLAGS" @@ -376,21 +371,11 @@ stdenv.mkDerivation rec { -e 's!/bin/bash!${bash}/bin/bash!g' \ -e 's!shasum -a 256!sha256sum!g' - ${bazelNixFlagsScript} > .bazelrc.nix - # export BAZELRC=$PWD/.bazelrc.nix - # export BAZEL_BOOTSTRAP_STARTUP_OPTIONS="" - # export DIST_BAZEL_ARGS= - #export EXTRA_BAZEL_ARGS="--rc_source=$PWD/.bazelrc.nix --announce_rc" - # Add compile options to command line. # XXX: It would suit a bazelrc file better, but I found no way to pass it. # It seems it is always ignored. # Passing EXTRA_BAZEL_ARGS is tricky due to quoting. - #which javac - #printenv JAVA_HOME - #exit 0 - sedVerbose compile.sh \ -e "/bazel_build /a\ --copt=\"$(echo $NIX_CFLAGS_COMPILE | sed -e 's/ /" --copt=\"/g')\" \\\\" \ -e "/bazel_build /a\ --host_copt=\"$(echo $NIX_CFLAGS_COMPILE | sed -e 's/ /" --host_copt=\"/g')\" \\\\" \ @@ -409,12 +394,6 @@ stdenv.mkDerivation rec { -e "/bazel_build /a\ --extra_toolchains=@local_jdk//:all \\\\" \ -e "/bazel_build /a\ --toolchain_resolution_debug=@bazel_tools//tools/jdk:runtime_toolchain_type \\\\" \ -e "/bazel_build /a\ --sandbox_debug --verbose_failures \\\\" \ - ${lib.optionalString isDarwin '' - -e "/bazel_build /a\ --cpu=${({aarch64-darwin = "darwin_arm64"; x86_64-darwin = "darwin_x86_64";}.${stdenv.hostPlatform.system})} \\\\" \'' - } - - #-e "/bazel_build /a\ --spawn_strategy=standalone \\\\" \ - # Also build parser_deploy.jar with bootstrap bazel # TODO: Turn into a proper patch @@ -448,8 +427,7 @@ stdenv.mkDerivation rec { patchShebangs . >/dev/null ''; in - lib.optionalString stdenv.hostPlatform.isDarwin darwinPatches - + genericPatches; + lib.optionalString isDarwin darwinPatches + genericPatches; buildInputs = [ buildJdk ] ++ defaultShellUtils; @@ -528,10 +506,10 @@ stdenv.mkDerivation rec { mkdir -p $out/bin - # official wrapper scripts that searches for $WORKSPACE_ROOT/tools/bazel - # if it can’t find something in tools, it calls $out/bin/bazel-{version}-{os_arch} - # The binary _must_ exist with this naming if your project contains a .bazelversion - # file. + # official wrapper scripts that searches for $WORKSPACE_ROOT/tools/bazel if + # it can’t find something in tools, it calls + # $out/bin/bazel-{version}-{os_arch} The binary _must_ exist with this + # naming if your project contains a .bazelversion file. cp ./bazel_src/scripts/packages/bazel.sh $out/bin/bazel wrapProgram $out/bin/bazel $wrapperfile --suffix PATH : ${defaultShellPath} mv ./bazel_src/output/bazel $out/bin/bazel-${version}-${system}-${arch} @@ -616,6 +594,18 @@ stdenv.mkDerivation rec { dontStrip = true; dontPatchELF = true; - passthru.repoCache = repoCache; - passthru.distDir = distDir; + passthru = { + # Additional tests that check bazel’s functionality. Execute + # + # nix-build . -A bazel_7.tests + # + # in the nixpkgs checkout root to exercise them locally. + tests = callPackage ./tests.nix { + inherit Foundation bazel_self distDir repoCache runJdk; + }; + + updater = throw "TODO"; + + inherit distDir repoCache; + }; } diff --git a/pkgs/development/tools/build-managers/bazel/bazel_7/java_toolchain.patch b/pkgs/development/tools/build-managers/bazel/bazel_7/java_toolchain.patch index 7a2623fa6dd3..d9c41c36b53a 100644 --- a/pkgs/development/tools/build-managers/bazel/bazel_7/java_toolchain.patch +++ b/pkgs/development/tools/build-managers/bazel/bazel_7/java_toolchain.patch @@ -1,9 +1,3 @@ -commit ef1f5586d3c7fb426af1df6ba650bbad98a5a78a -Author: Guillaume Maudoux -Date: Fri Oct 6 15:03:28 2023 +0200 - - java_toolchain.patch - diff --git a/tools/jdk/BUILD.tools b/tools/jdk/BUILD.tools index a8af76e90c..af2540f838 100644 --- a/tools/jdk/BUILD.tools diff --git a/pkgs/development/tools/build-managers/bazel/bazel_7/no-arc.patch b/pkgs/development/tools/build-managers/bazel/bazel_7/no-arc.patch index f43d03970eb8..69d7c47ffd00 100644 --- a/pkgs/development/tools/build-managers/bazel/bazel_7/no-arc.patch +++ b/pkgs/development/tools/build-managers/bazel/bazel_7/no-arc.patch @@ -1,9 +1,3 @@ -commit bb831fbf02535a3372f5c74dc49e668a2507efeb -Author: Guillaume Maudoux -Date: Fri Oct 6 15:06:35 2023 +0200 - - no-arc.patch - diff --git a/tools/osx/BUILD b/tools/osx/BUILD index 0358fb0ffe..baae1bf65b 100644 --- a/tools/osx/BUILD diff --git a/pkgs/development/tools/build-managers/bazel/bazel_7/strict_proto_deps.patch b/pkgs/development/tools/build-managers/bazel/bazel_7/strict_proto_deps.patch index 231ae7498bb7..009798c6f735 100644 --- a/pkgs/development/tools/build-managers/bazel/bazel_7/strict_proto_deps.patch +++ b/pkgs/development/tools/build-managers/bazel/bazel_7/strict_proto_deps.patch @@ -1,9 +1,3 @@ -commit c5cbdf1fcfb96299aaef7fb9909c2cc30b126568 -Author: Guillaume Maudoux -Date: Fri Oct 6 15:06:00 2023 +0200 - - strict_proto_deps.patch - diff --git a/src/main/starlark/builtins_bzl/common/java/proto/java_proto_library.bzl b/src/main/starlark/builtins_bzl/common/java/proto/java_proto_library.bzl index e2118aabea..6a33f03472 100644 --- a/src/main/starlark/builtins_bzl/common/java/proto/java_proto_library.bzl diff --git a/pkgs/development/tools/build-managers/bazel/bazel_7/trim-last-argument-to-gcc-if-empty.patch b/pkgs/development/tools/build-managers/bazel/bazel_7/trim-last-argument-to-gcc-if-empty.patch index 1173d7320108..c4a68218a0f8 100644 --- a/pkgs/development/tools/build-managers/bazel/bazel_7/trim-last-argument-to-gcc-if-empty.patch +++ b/pkgs/development/tools/build-managers/bazel/bazel_7/trim-last-argument-to-gcc-if-empty.patch @@ -1,9 +1,3 @@ -commit d2b4b1d748ec4fa302036b514377da4c4618177a -Author: Guillaume Maudoux -Date: Fri Oct 6 15:05:20 2023 +0200 - - trim-last-argument-to-gcc-if-empty.patch - diff --git a/tools/cpp/osx_cc_wrapper.sh.tpl b/tools/cpp/osx_cc_wrapper.sh.tpl index 8264090c29..b7b9e8537a 100644 --- a/tools/cpp/osx_cc_wrapper.sh.tpl