diff options
Diffstat (limited to 'nixpkgs/pkgs/build-support/build-bazel-package/default.nix')
-rw-r--r-- | nixpkgs/pkgs/build-support/build-bazel-package/default.nix | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/nixpkgs/pkgs/build-support/build-bazel-package/default.nix b/nixpkgs/pkgs/build-support/build-bazel-package/default.nix index 31c0c8e92e5..4d22a329e41 100644 --- a/nixpkgs/pkgs/build-support/build-bazel-package/default.nix +++ b/nixpkgs/pkgs/build-support/build-bazel-package/default.nix @@ -30,6 +30,19 @@ 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 + +# Donβt add Bazel --copt and --linkopt from NIX_CFLAGS_COMPILE / +# NIX_LDFLAGS. This is necessary when using a custom toolchain which +# Bazel wants all headers / libraries to come from, like when using +# CROSSTOOL. Weirdly, we can still get the flags through the wrapped +# compiler. +, dontAddBazelOpts ? false , ... }: @@ -79,7 +92,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 \ @@ -112,7 +125,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 @@ -162,6 +176,8 @@ in stdenv.mkDerivation (fBuildAttrs // { done '' + fBuildAttrs.preConfigure or ""; + inherit dontAddBazelOpts; + buildPhase = fBuildAttrs.buildPhase or '' runHook preBuild @@ -173,20 +189,22 @@ in stdenv.mkDerivation (fBuildAttrs // { # copts=() host_copts=() - for flag in $NIX_CFLAGS_COMPILE; do - copts+=( "--copt=$flag" ) - host_copts+=( "--host_copt=$flag" ) - done - for flag in $NIX_CXXSTDLIB_COMPILE; do - copts+=( "--copt=$flag" ) - host_copts+=( "--host_copt=$flag" ) - done linkopts=() host_linkopts=() - for flag in $NIX_LDFLAGS; do - linkopts+=( "--linkopt=-Wl,$flag" ) - host_linkopts+=( "--host_linkopt=-Wl,$flag" ) - done + if [ -z "''${dontAddBazelOpts:-}" ]; then + for flag in $NIX_CFLAGS_COMPILE; do + copts+=( "--copt=$flag" ) + host_copts+=( "--host_copt=$flag" ) + done + for flag in $NIX_CXXSTDLIB_COMPILE; do + copts+=( "--copt=$flag" ) + host_copts+=( "--host_copt=$flag" ) + done + for flag in $NIX_LDFLAGS; do + linkopts+=( "--linkopt=-Wl,$flag" ) + host_linkopts+=( "--host_linkopt=-Wl,$flag" ) + done + fi BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 \ USER=homeless-shelter \ |