diff options
author | Wael Nasreddine <wael.nasreddine@gmail.com> | 2019-07-25 02:43:45 -0700 |
---|---|---|
committer | Profpatsch <philip.patsch@tweag.io> | 2019-07-25 11:43:45 +0200 |
commit | a8f174ff7ceb3228175eed982ad1e86749654b8c (patch) | |
tree | e5c596fc76ed984de61a280d0cfdb5eef244f900 /pkgs/build-support/build-bazel-package | |
parent | b5d1d50aa90e0780c57fb4b323203ea5056be857 (diff) |
buildBazelPackage: autodetect nix toolchain instead of Xcode on Darwin (#65308)
* buildBazelPackage: autodetect nix toolchain instead of Xcode on Darwin
* do not export the variables outside of Darwin
* remove unecessary parens
* move comment within the darwin check
Diffstat (limited to 'pkgs/build-support/build-bazel-package')
-rw-r--r-- | pkgs/build-support/build-bazel-package/default.nix | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/pkgs/build-support/build-bazel-package/default.nix b/pkgs/build-support/build-bazel-package/default.nix index 4e19b244f3cb..72725f9818c0 100644 --- a/pkgs/build-support/build-bazel-package/default.nix +++ b/pkgs/build-support/build-bazel-package/default.nix @@ -1,4 +1,8 @@ -{ stdenv, bazel, cacert }: +{ stdenv +, bazel +, cacert +, lib +}: args@{ name, bazelFlags ? [], bazelTarget, buildAttrs, fetchAttrs, ... }: @@ -109,6 +113,31 @@ in stdenv.mkDerivation (fBuildAttrs // { buildPhase = fBuildAttrs.buildPhase or '' runHook preBuild + '' + lib.optionalString stdenv.isDarwin '' + # 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 \ @@ -116,6 +145,12 @@ in stdenv.mkDerivation (fBuildAttrs // { --output_user_root="$bazelUserRoot" \ build \ -j $NIX_BUILD_CORES \ + '' + lib.optionalString stdenv.isDarwin '' + "''${copts[@]}" \ + "''${host_copts[@]}" \ + "''${linkopts[@]}" \ + "''${host_linkopts[@]}" \ + '' + '' $bazelFlags \ $bazelTarget |