buildBazelPackage: support multiple targets

This commit is contained in:
Uri Baghin 2023-04-05 12:59:54 +10:00
parent 45306ddf55
commit 440b4de588
7 changed files with 22 additions and 25 deletions

View file

@ -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].
${
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
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}
"--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

View file

@ -138,7 +138,7 @@ let
rm -f .bazelversion
'';
bazelTarget = "//build:build_wheel";
bazelTargets = [ "//build:build_wheel" ];
removeRulesCC = false;

View file

@ -50,7 +50,7 @@ let
bazel = bazel_6;
bazelTarget = ":pip_pkg";
bazelTargets = [ ":pip_pkg" ];
LIBTOOL = lib.optionalString stdenv.isDarwin "${cctools}/bin/libtool";
fetchAttrs = {

View file

@ -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.

View file

@ -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 = {

View file

@ -74,7 +74,7 @@ buildBazelPackage rec {
bazel = bazel_4;
removeRulesCC = false;
bazelTarget = ":install-binaries";
bazelTargets = [ ":install-binaries" ];
bazelTestTargets = [ "//..." ];
bazelBuildFlags = [
"-c opt"

View file

@ -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"