From 440b4de588d950e7fcf7add3b049fb209f097367 Mon Sep 17 00:00:00 2001 From: Uri Baghin Date: Wed, 5 Apr 2023 12:59:54 +1000 Subject: [PATCH] buildBazelPackage: support multiple targets --- .../build-bazel-package/default.nix | 35 +++++++++---------- .../python-modules/jaxlib/default.nix | 2 +- .../tensorflow-probability/default.nix | 2 +- .../python-modules/tensorflow/default.nix | 2 +- .../tools/bazel-watcher/default.nix | 2 +- .../language-servers/verible/default.nix | 2 +- pkgs/servers/http/envoy/default.nix | 2 +- 7 files changed, 22 insertions(+), 25 deletions(-) diff --git a/pkgs/build-support/build-bazel-package/default.nix b/pkgs/build-support/build-bazel-package/default.nix index a3f331b23cb8..ab2014ea6a63 100644 --- a/pkgs/build-support/build-bazel-package/default.nix +++ b/pkgs/build-support/build-bazel-package/default.nix @@ -10,7 +10,7 @@ args@{ , bazelBuildFlags ? [] , bazelTestFlags ? [] , bazelFetchFlags ? [] -, bazelTarget +, bazelTargets , bazelTestTargets ? [] , buildAttrs , fetchAttrs @@ -69,11 +69,11 @@ let ''; in stdenv.mkDerivation (fBuildAttrs // { - inherit name bazelFlags bazelBuildFlags bazelTestFlags bazelFetchFlags bazelTarget bazelTestTargets; + inherit name bazelFlags bazelBuildFlags bazelTestFlags bazelFetchFlags bazelTargets bazelTestTargets; deps = stdenv.mkDerivation (fFetchAttrs // { name = "${name}-deps.tar.gz"; - inherit bazelFlags bazelBuildFlags bazelTestFlags bazelFetchFlags bazelTarget bazelTestTargets; + inherit bazelFlags bazelBuildFlags bazelTestFlags bazelFetchFlags bazelTargets bazelTestTargets; impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ fFetchAttrs.impureEnvVars or []; @@ -94,21 +94,18 @@ stdenv.mkDerivation (fBuildAttrs // { buildPhase = fFetchAttrs.buildPhase or '' runHook preBuild - # See footnote called [USER and BAZEL_USE_CPP_ONLY_TOOLCHAIN variables]. - # We disable multithreading for the fetching phase since it can lead to timeouts with many dependencies/threads: - # https://github.com/bazelbuild/bazel/issues/6502 - BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 \ - USER=homeless-shelter \ - bazel \ - --batch \ - --output_base="$bazelOut" \ - --output_user_root="$bazelUserRoot" \ - ${if fetchConfigured then "build --nobuild" else "fetch"} \ - --loading_phase_threads=1 \ - $bazelFlags \ - $bazelFetchFlags \ - ${bazelTarget} \ - ${lib.strings.concatStringsSep " " bazelTestTargets} + ${ + bazelCmd { + cmd = if fetchConfigured then "build --nobuild" else "fetch"; + additionalFlags = [ + # We disable multithreading for the fetching phase since it can lead to timeouts with many dependencies/threads: + # https://github.com/bazelbuild/bazel/issues/6502 + "--loading_phase_threads=1" + "$bazelFetchFlags" + ]; + targets = bazelTargets ++ bazelTestTargets; + } + } runHook postBuild ''; @@ -232,7 +229,7 @@ stdenv.mkDerivation (fBuildAttrs // { bazelCmd { cmd = "build"; additionalFlags = bazelBuildFlags; - targets = [bazelTarget]; + targets = bazelTargets; } } runHook postBuild diff --git a/pkgs/development/python-modules/jaxlib/default.nix b/pkgs/development/python-modules/jaxlib/default.nix index ad48af827ee5..ad0130d6462f 100644 --- a/pkgs/development/python-modules/jaxlib/default.nix +++ b/pkgs/development/python-modules/jaxlib/default.nix @@ -138,7 +138,7 @@ let rm -f .bazelversion ''; - bazelTarget = "//build:build_wheel"; + bazelTargets = [ "//build:build_wheel" ]; removeRulesCC = false; diff --git a/pkgs/development/python-modules/tensorflow-probability/default.nix b/pkgs/development/python-modules/tensorflow-probability/default.nix index b85eea444358..7bf73dff28d5 100644 --- a/pkgs/development/python-modules/tensorflow-probability/default.nix +++ b/pkgs/development/python-modules/tensorflow-probability/default.nix @@ -50,7 +50,7 @@ let bazel = bazel_6; - bazelTarget = ":pip_pkg"; + bazelTargets = [ ":pip_pkg" ]; LIBTOOL = lib.optionalString stdenv.isDarwin "${cctools}/bin/libtool"; fetchAttrs = { diff --git a/pkgs/development/python-modules/tensorflow/default.nix b/pkgs/development/python-modules/tensorflow/default.nix index 4e7ae3ef5704..b8306dff724c 100644 --- a/pkgs/development/python-modules/tensorflow/default.nix +++ b/pkgs/development/python-modules/tensorflow/default.nix @@ -385,7 +385,7 @@ let ] ++ lib.optionals (mklSupport) [ "--config=mkl" ]; - bazelTarget = "//tensorflow/tools/pip_package:build_pip_package //tensorflow/tools/lib_package:libtensorflow"; + bazelTargets = [ "//tensorflow/tools/pip_package:build_pip_package //tensorflow/tools/lib_package:libtensorflow" ]; removeRulesCC = false; # Without this Bazel complaints about sandbox violations. diff --git a/pkgs/development/tools/bazel-watcher/default.nix b/pkgs/development/tools/bazel-watcher/default.nix index 38ea03d9f95b..906403dcd1d5 100644 --- a/pkgs/development/tools/bazel-watcher/default.nix +++ b/pkgs/development/tools/bazel-watcher/default.nix @@ -45,7 +45,7 @@ buildBazelPackage rec { bazel = bazel_5; bazelFlags = [ "--override_repository=rules_proto=${rulesProto}" ]; bazelBuildFlags = lib.optionals stdenv.cc.isClang [ "--cxxopt=-x" "--cxxopt=c++" "--host_cxxopt=-x" "--host_cxxopt=c++" ]; - bazelTarget = "//cmd/ibazel"; + bazelTargets = [ "//cmd/ibazel" ]; fetchConfigured = false; # we want to fetch all dependencies, regardless of the current system fetchAttrs = { diff --git a/pkgs/development/tools/language-servers/verible/default.nix b/pkgs/development/tools/language-servers/verible/default.nix index 91ac7b7bce05..85c5991a5857 100644 --- a/pkgs/development/tools/language-servers/verible/default.nix +++ b/pkgs/development/tools/language-servers/verible/default.nix @@ -74,7 +74,7 @@ buildBazelPackage rec { bazel = bazel_4; removeRulesCC = false; - bazelTarget = ":install-binaries"; + bazelTargets = [ ":install-binaries" ]; bazelTestTargets = [ "//..." ]; bazelBuildFlags = [ "-c opt" diff --git a/pkgs/servers/http/envoy/default.nix b/pkgs/servers/http/envoy/default.nix index db040f8a2080..1d2c43467f86 100644 --- a/pkgs/servers/http/envoy/default.nix +++ b/pkgs/servers/http/envoy/default.nix @@ -140,7 +140,7 @@ buildBazelPackage rec { removeRulesCC = false; removeLocalConfigCc = true; removeLocal = false; - bazelTarget = "//source/exe:envoy-static"; + bazelTargets = [ "//source/exe:envoy-static" ]; bazelBuildFlags = [ "-c opt" "--spawn_strategy=standalone"