git.iko.soy/typeable/nixpkgs
on master help sign in
buildBazelPackage: add "fetchConfigured" for fetching only things required for the build

"bazel fetch" will, by default, fetch everything that _might_ be used, including things that will later be discarded due to the way the build is configured. Concretely, this means that for some builds of Java packages, this will avoid failures where the builder tries to retrieve the JDK from /usr/share/java (or equivalent). This also means that for most packages we can fetch _fewer_ dependencies, since the standard tree pruning for artifacts to fetch will take effect. fetchConfigured is disabled by default since it changes the fetch hashes of tensorflow/tensorflow2 (since it ends up fetching less).

commitd7d4a926957de29e8e618d1c848e2036ea98d9cc authorLuke Granger-Brown <git@lukegb.com> dateSat 4 Jul 2020, 23:24 (6 years ago) parentb6eca9a
1 file changed+10−2
pkgs/build-support/build-bazel-package/default.nix+10−2
pkgs/build-support/build-bazel-package/default.nix+10−2
@@ -30,6 +30,13 @@ args@{
3030, removeRulesCC ? true
3131, removeLocalConfigCc ? true
3232, removeLocal ? true
33+
34+# Use build --nobuild instead of fetch. This allows fetching the dependencies
35+# required for the build as configured, rather than fetching all the dependencies
36+# which may not work in some situations (e.g. Java code which ends up relying on
37+# Debian-specific /usr/share/java paths, but doesn't in the configured build).
38+, fetchConfigured ? false
39+
3340, ...
3441}:
3542
@@ -79,7 +86,7 @@ in stdenv.mkDerivation (fBuildAttrs // {
7986 bazel \
8087 --output_base="$bazelOut" \
8188 --output_user_root="$bazelUserRoot" \
82− fetch \
89+ ${if fetchConfigured then "build --nobuild" else "fetch"} \
8390 --loading_phase_threads=1 \
8491 $bazelFlags \
8592 $bazelFetchFlags \
@@ -112,7 +119,8 @@ in stdenv.mkDerivation (fBuildAttrs // {
112119 # platforms -> NIX_BUILD_TOP/tmp/install/35282f5123611afa742331368e9ae529/_embedded_binaries/platforms
113120 find $bazelOut/external -maxdepth 1 -type l | while read symlink; do
114121 name="$(basename "$symlink")"
115− rm "$symlink" "$bazelOut/external/@$name.marker"
122+ rm "$symlink"
123+ test -f "$bazelOut/external/@$name.marker" && rm "$bazelOut/external/@$name.marker"
116124 done
117125
118126 # Patching symlinks to remove build directory reference