Skip to content

Commit

Permalink
buildBazelPackage: add "fetchConfigured" for fetching only things req…
Browse files Browse the repository at this point in the history
…uired 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).
  • Loading branch information
lukegb authored and Profpatsch committed Jul 17, 2020
1 parent b6eca9a commit d7d4a92
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkgs/build-support/build-bazel-package/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ args@{
, removeRulesCC ? true
, removeLocalConfigCc ? true
, removeLocal ? true

# Use build --nobuild instead of fetch. This allows fetching the dependencies
# required for the build as configured, rather than fetching all the dependencies
# which may not work in some situations (e.g. Java code which ends up relying on
# Debian-specific /usr/share/java paths, but doesn't in the configured build).
, fetchConfigured ? false

, ...
}:

Expand Down Expand Up @@ -79,7 +86,7 @@ in stdenv.mkDerivation (fBuildAttrs // {
bazel \
--output_base="$bazelOut" \
--output_user_root="$bazelUserRoot" \
fetch \
${if fetchConfigured then "build --nobuild" else "fetch"} \
--loading_phase_threads=1 \
$bazelFlags \
$bazelFetchFlags \
Expand Down Expand Up @@ -112,7 +119,8 @@ in stdenv.mkDerivation (fBuildAttrs // {
# platforms -> NIX_BUILD_TOP/tmp/install/35282f5123611afa742331368e9ae529/_embedded_binaries/platforms
find $bazelOut/external -maxdepth 1 -type l | while read symlink; do
name="$(basename "$symlink")"
rm "$symlink" "$bazelOut/external/@$name.marker"
rm "$symlink"
test -f "$bazelOut/external/@$name.marker" && rm "$bazelOut/external/@$name.marker"
done
# Patching symlinks to remove build directory reference
Expand Down

0 comments on commit d7d4a92

Please sign in to comment.