git.iko.soy/typeable/nixpkgs
on master help sign in
bazel: 0.20.0 -> 0.21.0

0.21 removed the bundled openjdk-distribution. Instead, tries to fetch the “right” distribution on-the-fly when building. So we need to provide our own openjdk. According to https://github.com/bazelbuild/bazel/issues/6865#issuecomment-447261288 we should set `--host_javabase="@local_jdk//:jdk` if we want to do that. This uses the jdk that is currently in the environment, which is openjdk 8 in our case. 0.21 defaulted to a toolchain for JDK9, which we don’t package in nixpkgs, so we use the JDK8 toolchain. This commit also replaces the line-number-based sed invocations with something more stable.

commit9e9fec640edab8b92e84b6dfd8ea01c585715cea authorProfpatsch <mail@profpatsch.de> dateFri 4 Jan 2019, 18:06 (8 years ago) parent7e31406
1 file changed+33−15
pkgs/development/tools/build-managers/bazel/default.nix+33−15
pkgs/development/tools/build-managers/bazel/default.nix+33−15
@@ -13,8 +13,8 @@
1313let
1414 srcDeps = lib.singleton (
1515 fetchurl {
16− url = "https://github.com/google/desugar_jdk_libs/archive/fd937f4180c1b557805219af4482f1a27eb0ff2b.zip";
17− sha256 = "04hs399340xfwcdajbbcpywnb2syp6z5ydwg966if3hqdb2zrf23";
16+ url = "https://github.com/google/desugar_jdk_libs/archive/915f566d1dc23bc5a8975320cd2ff71be108eb9c.zip";
17+ sha256 = "0b926df7yxyyyiwm9cmdijy6kplf0sghm23sf163zh8wrk87wfi7";
1818 }
1919 );
2020
@@ -23,12 +23,12 @@ let
2323 for i in ${builtins.toString srcDeps}; do cp $i $out/$(stripHash $i); done
2424 '';
2525
26− defaultShellPath = lib.makeBinPath [ bash coreutils findutils gnugrep gnused which ];
26+ defaultShellPath = lib.makeBinPath [ bash coreutils findutils gnugrep gnused which unzip ];
2727
2828in
2929stdenv.mkDerivation rec {
3030
31− version = "0.20.0";
31+ version = "0.21.0";
3232
3333 meta = with lib; {
3434 homepage = "https://github.com/bazelbuild/bazel/";
@@ -42,7 +42,7 @@ stdenv.mkDerivation rec {
4242
4343 src = fetchurl {
4444 url = "https://github.com/bazelbuild/bazel/releases/download/${version}/bazel-${version}-dist.zip";
45− sha256 = "1g9hglly5199gcw929fzc5f0d0dwlharkh387h58p1fq9ylayi8r";
45+ sha256 = "1d3x0f1hzaiqq00pd65bks7v8kbv57m13jsing7y0y9id0g87jvc";
4646 };
4747
4848 sourceRoot = ".";
@@ -78,6 +78,7 @@ stdenv.mkDerivation rec {
7878 '';
7979
8080 postPatch = let
81+
8182 darwinPatches = ''
8283 # Disable Bazel's Xcode toolchain detection which would configure compilers
8384 # and linkers from Xcode instead of from PATH
@@ -115,6 +116,7 @@ stdenv.mkDerivation rec {
115116 sed -i -e "s,/usr/bin/install_name_tool,${cctools}/bin/install_name_tool,g" $wrapper
116117 done
117118 '';
119+
118120 genericPatches = ''
119121 # substituteInPlace is rather slow, so prefilter the files with grep
120122 grep -rlZ /bin src/main/java/com/google/devtools | while IFS="" read -r -d "" path; do
@@ -125,20 +127,34 @@ stdenv.mkDerivation rec {
125127 --replace /usr/bin/env ${coreutils}/bin/env \
126128 --replace /bin/true ${coreutils}/bin/true
127129 done
130+
128131 # Fixup scripts that generate scripts. Not fixed up by patchShebangs below.
129132 substituteInPlace scripts/bootstrap/compile.sh \
130133 --replace /bin/sh ${customBash}/bin/bash
131134
132− echo "build --experimental_distdir=${distDir}" >> .bazelrc
133− echo "fetch --experimental_distdir=${distDir}" >> .bazelrc
134− echo "build --copt=\"$(echo $NIX_CFLAGS_COMPILE | sed -e 's/ /" --copt=\"/g')\"" >> .bazelrc
135− echo "build --host_copt=\"$(echo $NIX_CFLAGS_COMPILE | sed -e 's/ /" --host_copt=\"/g')\"" >> .bazelrc
136− echo "build --linkopt=\"-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --linkopt=\"-Wl,/g')\"" >> .bazelrc
137− echo "build --host_linkopt=\"-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --host_linkopt=\"-Wl,/g')\"" >> .bazelrc
138− sed -i -e "420 a --copt=\"$(echo $NIX_CFLAGS_COMPILE | sed -e 's/ /" --copt=\"/g')\" \\\\" scripts/bootstrap/compile.sh
139− sed -i -e "420 a --host_copt=\"$(echo $NIX_CFLAGS_COMPILE | sed -e 's/ /" --host_copt=\"/g')\" \\\\" scripts/bootstrap/compile.sh
140− sed -i -e "420 a --linkopt=\"-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --linkopt=\"-Wl,/g')\" \\\\" scripts/bootstrap/compile.sh
141− sed -i -e "420 a --host_linkopt=\"-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --host_linkopt=\"-Wl,/g')\" \\\\" scripts/bootstrap/compile.sh
135+ # We only build with JDK8 for now, since JDK11 does not compile bazel
136+ substituteInPlace tools/jdk/default_java_toolchain.bzl \
137+ --replace '"jvm_opts": JDK9_JVM_OPTS' \
138+ '"jvm_opts": JDK8_JVM_OPTS'
139+
140+ # add nix environment vars to .bazelrc
141+ cat >> .bazelrc <<EOF
142+ build --experimental_distdir=${distDir}
143+ fetch --experimental_distdir=${distDir}
144+ build --copt="$(echo $NIX_CFLAGS_COMPILE | sed -e 's/ /" --copt="/g')"
145+ build --host_copt="$(echo $NIX_CFLAGS_COMPILE | sed -e 's/ /" --host_copt="/g')"
146+ build --linkopt="-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --linkopt="-Wl,/g')"
147+ build --host_linkopt="-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --host_linkopt="-Wl,/g')"
148+ build --host_javabase='@local_jdk//:jdk'
149+ EOF
150+
151+ # add the same environment vars to compile.sh
152+ sed -e "/\$command \\\\$/a --copt=\"$(echo $NIX_CFLAGS_COMPILE | sed -e 's/ /" --copt=\"/g')\" \\\\" \
153+ -e "/\$command \\\\$/a --host_copt=\"$(echo $NIX_CFLAGS_COMPILE | sed -e 's/ /" --host_copt=\"/g')\" \\\\" \
154+ -e "/\$command \\\\$/a --linkopt=\"-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --linkopt=\"-Wl,/g')\" \\\\" \
155+ -e "/\$command \\\\$/a --host_linkopt=\"-Wl,$(echo $NIX_LDFLAGS | sed -e 's/ /" --host_linkopt=\"-Wl,/g')\" \\\\" \
156+ -e "/\$command \\\\$/a --host_javabase='@local_jdk//:jdk' \\\\" \
157+ -i scripts/bootstrap/compile.sh
142158
143159 # --experimental_strict_action_env (which will soon become the
144160 # default, see bazelbuild/bazel#2574) hardcodes the default
@@ -162,6 +178,8 @@ stdenv.mkDerivation rec {
162178 buildJdk
163179 ];
164180
181+ # when a command can’t be found in a bazel build, you might also
182+ # need to add it to `defaultShellPath`.
165183 nativeBuildInputs = [
166184 zip
167185 python