summaryrefslogtreecommitdiffstats
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorUri Baghin <uri@canva.com>2019-02-20 03:44:05 +1100
committerzimbatm <zimbatm@zimbatm.com>2019-02-19 16:44:05 +0000
commit718a82b108a465a7eef9ce56d77b67571d2015ba (patch)
treeee332d899bcda611e5ee8485c4ba0949d169f804 /pkgs/build-support
parent688ca701b239b77918c20ff2742ef53a44d1ec80 (diff)
buildBazelPackage: autodetect nix toolchain instead of Xcode one on macOS (#56033)
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/build-bazel-package/default.nix41
1 files changed, 39 insertions, 2 deletions
diff --git a/pkgs/build-support/build-bazel-package/default.nix b/pkgs/build-support/build-bazel-package/default.nix
index 931b68c6329f..f39f4e65e454 100644
--- a/pkgs/build-support/build-bazel-package/default.nix
+++ b/pkgs/build-support/build-bazel-package/default.nix
@@ -33,7 +33,9 @@ in stdenv.mkDerivation (fBuildAttrs // {
# sandbox enabled. Code here
# https://github.com/bazelbuild/bazel/blob/9323c57607d37f9c949b60e293b573584906da46/src/main/cpp/startup_options.cc#L123-L124
#
- USER=homeless-shelter bazel --output_base="$bazelOut" --output_user_root="$bazelUserRoot" fetch $bazelFlags $bazelTarget
+ # On macOS Bazel will use the system installed Xcode or CLT toolchain instead of the one in the PATH unless we pass BAZEL_USE_CPP_ONLY_TOOLCHAIN
+ #
+ BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 USER=homeless-shelter bazel --output_base="$bazelOut" --output_user_root="$bazelUserRoot" fetch $bazelFlags $bazelTarget
runHook postBuild
'';
@@ -90,7 +92,42 @@ in stdenv.mkDerivation (fBuildAttrs // {
buildPhase = fBuildAttrs.buildPhase or ''
runHook preBuild
- bazel --output_base="$bazelOut" --output_user_root="$bazelUserRoot" build -j $NIX_BUILD_CORES $bazelFlags $bazelTarget
+ # Bazel sandboxes the execution of the tools it invokes, so even though we are
+ # calling the correct nix wrappers, the values of the environment variables
+ # the wrappers are expecting will not be set. So instead of relying on the
+ # wrappers picking them up, pass them in explicitly via `--copt`, `--linkopt`
+ # and related flags.
+ #
+ 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_LD_FLAGS; do
+ linkopts+=( "--linkopt=$flag" )
+ host_linkopts+=( "--host_linkopt=$flag" )
+ done
+
+ BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 \
+ USER=homeless-shelter \
+ bazel \
+ --output_base="$bazelOut" \
+ --output_user_root="$bazelUserRoot" \
+ build \
+ -j $NIX_BUILD_CORES \
+ "''${copts[@]}" \
+ "''${host_copts[@]}" \
+ "''${linkopts[@]}" \
+ "''${host_linkopts[@]}" \
+ $bazelFlags \
+ $bazelTarget
runHook postBuild
'';