@@ -9,7 +9,7 @@
99}:
1010
1111let
12− srcDeps = stdenv.lib.singleton (
12+ srcDeps = lib.singleton (
1313 fetchurl {
1414 url = "https://github.com/google/desugar_jdk_libs/archive/f5e6d80c6b4ec6b0a46603f72b015d45cf3c11cd.zip";
1515 sha256 = "c80f3f3d442d8a6ca7adc83f90ecd638c3864087fdd6787ffac070b6f1cc8f9b";
@@ -28,7 +28,7 @@ stdenv.mkDerivation rec {
2828
2929 version = "0.15.2";
3030
31− meta = with stdenv.lib; {
31+ meta = with lib; {
3232 homepage = "https://github.com/bazelbuild/bazel/";
3333 description = "Build tool that builds code quickly and reliably";
3434 license = licenses.asl20;
@@ -74,71 +74,75 @@ stdenv.mkDerivation rec {
7474 }
7575 '';
7676
77− postPatch = stdenv.lib.optionalString stdenv.hostPlatform.isDarwin ''
78− # Disable Bazel's Xcode toolchain detection which would configure compilers
79− # and linkers from Xcode instead of from PATH
80− export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
81−
82− # Framework search paths aren't added by bintools hook
83− # https://github.com/NixOS/nixpkgs/pull/41914
84− export NIX_LDFLAGS="$NIX_LDFLAGS -F${CoreFoundation}/Library/Frameworks -F${CoreServices}/Library/Frameworks -F${Foundation}/Library/Frameworks"
85−
86− # libcxx includes aren't added by libcxx hook
87− # https://github.com/NixOS/nixpkgs/pull/41589
88− export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem ${libcxx}/include/c++/v1"
89−
90− # don't use system installed Xcode to run clang, use Nix clang instead
91− sed -i -e "s;/usr/bin/xcrun clang;${clang}/bin/clang $NIX_CFLAGS_COMPILE $NIX_LDFLAGS -framework CoreFoundation;g" \
92− scripts/bootstrap/compile.sh \
93− src/tools/xcode/realpath/BUILD \
94− src/tools/xcode/stdredirect/BUILD \
95− tools/osx/BUILD
96−
97− # clang installed from Xcode has a compatibility wrapper that forwards
98− # invocations of gcc to clang, but vanilla clang doesn't
99− sed -i -e 's;_find_generic(repository_ctx, "gcc", "CC", overriden_tools);_find_generic(repository_ctx, "clang", "CC", overriden_tools);g' tools/cpp/unix_cc_configure.bzl
100−
101− sed -i -e 's;/usr/bin/libtool;${cctools}/bin/libtool;g' tools/cpp/unix_cc_configure.bzl
102− wrappers=( tools/cpp/osx_cc_wrapper.sh tools/cpp/osx_cc_wrapper.sh.tpl )
103− for wrapper in "''${wrappers[@]}"; do
104− sed -i -e "s,/usr/bin/install_name_tool,${cctools}/bin/install_name_tool,g" $wrapper
105− done
106− '' + ''
107− find src/main/java/com/google/devtools -type f -print0 | while IFS="" read -r -d "" path; do
108− substituteInPlace "$path" \
109− --replace /bin/bash ${customBash}/bin/bash \
110− --replace /usr/bin/env ${coreutils}/bin/env
111− done
112− # Fixup scripts that generate scripts. Not fixed up by patchShebangs below.
113− substituteInPlace scripts/bootstrap/compile.sh \
114− --replace /bin/sh ${customBash}/bin/bash
115−
116− echo "build --experimental_distdir=${distDir}" >> .bazelrc
117− echo "fetch --experimental_distdir=${distDir}" >> .bazelrc
118− echo "build --copt=\"$(echo $NIX_CFLAGS_COMPILE | sed -e 's/ /" --copt=\"/g')\"" >> .bazelrc
119− echo "build --host_copt=\"$(echo $NIX_CFLAGS_COMPILE | sed -e 's/ /" --host_copt=\"/g')\"" >> .bazelrc
120− echo "build --linkopt=\"-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --linkopt=\"-Wl,/g')\"" >> .bazelrc
121− echo "build --host_linkopt=\"-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --host_linkopt=\"-Wl,/g')\"" >> .bazelrc
122− sed -i -e "361 a --copt=\"$(echo $NIX_CFLAGS_COMPILE | sed -e 's/ /" --copt=\"/g')\" \\\\" scripts/bootstrap/compile.sh
123− sed -i -e "361 a --host_copt=\"$(echo $NIX_CFLAGS_COMPILE | sed -e 's/ /" --host_copt=\"/g')\" \\\\" scripts/bootstrap/compile.sh
124− sed -i -e "361 a --linkopt=\"-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --linkopt=\"-Wl,/g')\" \\\\" scripts/bootstrap/compile.sh
125− sed -i -e "361 a --host_linkopt=\"-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --host_linkopt=\"-Wl,/g')\" \\\\" scripts/bootstrap/compile.sh
126−
127− # --experimental_strict_action_env (which will soon become the
128− # default, see bazelbuild/bazel#2574) hardcodes the default
129− # action environment to a value that on NixOS at least is bogus.
130− # So we hardcode it to something useful.
131− substituteInPlace \
132− src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java \
133− --replace /bin:/usr/bin ${defaultShellPath}
134−
135− # append the PATH with defaultShellPath in tools/bash/runfiles/runfiles.bash
136− echo "PATH=$PATH:${defaultShellPath}" >> runfiles.bash.tmp
137− cat tools/bash/runfiles/runfiles.bash >> runfiles.bash.tmp
138− mv runfiles.bash.tmp tools/bash/runfiles/runfiles.bash
139−
140− patchShebangs .
141− '';
77+ postPatch = let
78+ darwinPatches = ''
79+ # Disable Bazel's Xcode toolchain detection which would configure compilers
80+ # and linkers from Xcode instead of from PATH
81+ export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
82+
83+ # Framework search paths aren't added by bintools hook
84+ # https://github.com/NixOS/nixpkgs/pull/41914
85+ export NIX_LDFLAGS="$NIX_LDFLAGS -F${CoreFoundation}/Library/Frameworks -F${CoreServices}/Library/Frameworks -F${Foundation}/Library/Frameworks"
86+
87+ # libcxx includes aren't added by libcxx hook
88+ # https://github.com/NixOS/nixpkgs/pull/41589
89+ export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem ${libcxx}/include/c++/v1"
90+
91+ # don't use system installed Xcode to run clang, use Nix clang instead
92+ sed -i -e "s;/usr/bin/xcrun clang;${clang}/bin/clang $NIX_CFLAGS_COMPILE $NIX_LDFLAGS -framework CoreFoundation;g" \
93+ scripts/bootstrap/compile.sh \
94+ src/tools/xcode/realpath/BUILD \
95+ src/tools/xcode/stdredirect/BUILD \
96+ tools/osx/BUILD
97+
98+ # clang installed from Xcode has a compatibility wrapper that forwards
99+ # invocations of gcc to clang, but vanilla clang doesn't
100+ sed -i -e 's;_find_generic(repository_ctx, "gcc", "CC", overriden_tools);_find_generic(repository_ctx, "clang", "CC", overriden_tools);g' tools/cpp/unix_cc_configure.bzl
101+
102+ sed -i -e 's;/usr/bin/libtool;${cctools}/bin/libtool;g' tools/cpp/unix_cc_configure.bzl
103+ wrappers=( tools/cpp/osx_cc_wrapper.sh tools/cpp/osx_cc_wrapper.sh.tpl )
104+ for wrapper in "''${wrappers[@]}"; do
105+ sed -i -e "s,/usr/bin/install_name_tool,${cctools}/bin/install_name_tool,g" $wrapper
106+ done
107+ '';
108+ genericPatches = ''
109+ find src/main/java/com/google/devtools -type f -print0 | while IFS="" read -r -d "" path; do
110+ substituteInPlace "$path" \
111+ --replace /bin/bash ${customBash}/bin/bash \
112+ --replace /usr/bin/env ${coreutils}/bin/env
113+ done
114+ # Fixup scripts that generate scripts. Not fixed up by patchShebangs below.
115+ substituteInPlace scripts/bootstrap/compile.sh \
116+ --replace /bin/sh ${customBash}/bin/bash
117+
118+ echo "build --experimental_distdir=${distDir}" >> .bazelrc
119+ echo "fetch --experimental_distdir=${distDir}" >> .bazelrc
120+ echo "build --copt=\"$(echo $NIX_CFLAGS_COMPILE | sed -e 's/ /" --copt=\"/g')\"" >> .bazelrc
121+ echo "build --host_copt=\"$(echo $NIX_CFLAGS_COMPILE | sed -e 's/ /" --host_copt=\"/g')\"" >> .bazelrc
122+ echo "build --linkopt=\"-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --linkopt=\"-Wl,/g')\"" >> .bazelrc
123+ echo "build --host_linkopt=\"-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --host_linkopt=\"-Wl,/g')\"" >> .bazelrc
124+ sed -i -e "361 a --copt=\"$(echo $NIX_CFLAGS_COMPILE | sed -e 's/ /" --copt=\"/g')\" \\\\" scripts/bootstrap/compile.sh
125+ sed -i -e "361 a --host_copt=\"$(echo $NIX_CFLAGS_COMPILE | sed -e 's/ /" --host_copt=\"/g')\" \\\\" scripts/bootstrap/compile.sh
126+ sed -i -e "361 a --linkopt=\"-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --linkopt=\"-Wl,/g')\" \\\\" scripts/bootstrap/compile.sh
127+ sed -i -e "361 a --host_linkopt=\"-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --host_linkopt=\"-Wl,/g')\" \\\\" scripts/bootstrap/compile.sh
128+
129+ # --experimental_strict_action_env (which will soon become the
130+ # default, see bazelbuild/bazel#2574) hardcodes the default
131+ # action environment to a value that on NixOS at least is bogus.
132+ # So we hardcode it to something useful.
133+ substituteInPlace \
134+ src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java \
135+ --replace /bin:/usr/bin ${defaultShellPath}
136+
137+ # append the PATH with defaultShellPath in tools/bash/runfiles/runfiles.bash
138+ echo "PATH=$PATH:${defaultShellPath}" >> runfiles.bash.tmp
139+ cat tools/bash/runfiles/runfiles.bash >> runfiles.bash.tmp
140+ mv runfiles.bash.tmp tools/bash/runfiles/runfiles.bash
141+
142+ patchShebangs .
143+ '';
144+ in lib.optionalString stdenv.hostPlatform.isDarwin darwinPatches
145+ + genericPatches;
142146
143147 buildInputs = [
144148 jdk