Skip to content

Commit

Permalink
buildBazelPackage: support multiple targets
Browse files Browse the repository at this point in the history
  • Loading branch information
uri-canva committed Apr 5, 2023
1 parent 45306dd commit 440b4de
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 25 deletions.
35 changes: 16 additions & 19 deletions pkgs/build-support/build-bazel-package/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ args@{
, bazelBuildFlags ? []
, bazelTestFlags ? []
, bazelFetchFlags ? []
, bazelTarget
, bazelTargets
, bazelTestTargets ? []
, buildAttrs
, fetchAttrs
Expand Down Expand Up @@ -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 [];

Expand All @@ -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
'';
Expand Down Expand Up @@ -232,7 +229,7 @@ stdenv.mkDerivation (fBuildAttrs // {
bazelCmd {
cmd = "build";
additionalFlags = bazelBuildFlags;
targets = [bazelTarget];
targets = bazelTargets;
}
}
runHook postBuild
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/python-modules/jaxlib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ let
rm -f .bazelversion
'';

bazelTarget = "//build:build_wheel";
bazelTargets = [ "//build:build_wheel" ];

removeRulesCC = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let

bazel = bazel_6;

bazelTarget = ":pip_pkg";
bazelTargets = [ ":pip_pkg" ];
LIBTOOL = lib.optionalString stdenv.isDarwin "${cctools}/bin/libtool";

fetchAttrs = {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/python-modules/tensorflow/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/tools/bazel-watcher/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ buildBazelPackage rec {

bazel = bazel_4;
removeRulesCC = false;
bazelTarget = ":install-binaries";
bazelTargets = [ ":install-binaries" ];
bazelTestTargets = [ "//..." ];
bazelBuildFlags = [
"-c opt"
Expand Down
2 changes: 1 addition & 1 deletion pkgs/servers/http/envoy/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 440b4de

Please sign in to comment.