@@ -14,14 +14,16 @@
1414# Always assume all markers valid (don't redownload dependencies).
1515# Also, don't clean up environment variables.
1616, enableNixHacks ? false
17+, gcc-unwrapped
18+, autoPatchelfHook
1719}:
1820
1921let
20− version = "0.26.1";
22+ version = "0.27.0";
2123
2224 src = fetchurl {
2325 url = "https://github.com/bazelbuild/bazel/releases/download/${version}/bazel-${version}-dist.zip";
24− sha256 = "000ny51hwnjyizm1md4w8q7m832jhf3c767pgbvg6nc7h67lzsf0";
26+ sha256 = "0yn662dzgfr8ls4avfl12k5sr4f210bab12wml18bh4sjlxhs263";
2527 };
2628
2729 # Update with `eval $(nix-build -A bazel.updater)`,
@@ -40,12 +42,12 @@ let
4042 srcs.bazel_skylib
4143 srcs.io_bazel_rules_sass
4244 (if stdenv.hostPlatform.isDarwin
43− then srcs.${"java_tools_javac10_darwin-v3.2.zip"}
44− else srcs.${"java_tools_javac10_linux-v3.2.zip"})
45+ then srcs.${"java_tools_javac11_darwin-v2.0.zip"}
46+ else srcs.${"java_tools_javac11_linux-v2.0.zip"})
4547 srcs.${"coverage_output_generator-v1.0.zip"}
4648 srcs.build_bazel_rules_nodejs
47− srcs.${"android_tools_pkg-0.2.tar.gz"}
48− ];
49+ srcs.${"android_tools_pkg-0.4.tar.gz"}
50+ ];
4951
5052 distDir = runCommand "bazel-deps" {} ''
5153 mkdir -p $out
@@ -87,6 +89,36 @@ let
8789
8890 platforms = lib.platforms.linux ++ lib.platforms.darwin;
8991
92+ # This repository is fetched by bazel at runtime
93+ # however it contains prebuilt java binaries, with wrong interpreter
94+ # and libraries path.
95+ # We prefetch it, patch it, and override it in a global bazelrc.
96+ system = if stdenv.hostPlatform.isDarwin
97+ then "darwin" else "linux";
98+
99+ remote_java_tools = stdenv.mkDerivation {
100+ name = "remote_java_tools_${system}";
101+
102+ src = fetchurl {
103+ url = "https://mirror.bazel.build/bazel_java_tools/releases/javac11/v2.0/java_tools_javac11_${system}-v2.0.zip";
104+ sha256 = "074d624fb34441df369afdfd454e75dba821d5d54932fcfee5ba598d17dc1b99";
105+ };
106+
107+ nativeBuildInputs = [ autoPatchelfHook unzip ];
108+ buildInputs = [ gcc-unwrapped ];
109+
110+ sourceRoot = ".";
111+
112+ buildPhase = ''
113+ mkdir $out;
114+ '';
115+
116+ installPhase = ''
117+ cp -Ra * $out/
118+ touch $out/WORKSPACE
119+ '';
120+ };
121+
90122in
91123stdenv.mkDerivation rec {
92124 name = "bazel-${version}";
@@ -117,6 +149,7 @@ stdenv.mkDerivation rec {
117149 runLocal = name: attrs: script: runCommandCC name ({
118150 preferLocalBuild = true;
119151 meta.platforms = platforms;
152+ buildInputs = [ python3 ];
120153 } // attrs) script;
121154
122155 # bazel wants to extract itself into $install_dir/install every time it runs,
@@ -275,6 +308,11 @@ stdenv.mkDerivation rec {
275308 --replace /bin/true ${coreutils}/bin/true
276309 done
277310
311+ # bazel test runner include references to /bin/bash
312+ substituteInPlace tools/build_rules/test_rules.bzl \
313+ --replace /bin/bash ${customBash}/bin/bash
314+
315+
278316 # Fixup scripts that generate scripts. Not fixed up by patchShebangs below.
279317 substituteInPlace scripts/bootstrap/compile.sh \
280318 --replace /bin/bash ${customBash}/bin/bash
@@ -323,12 +361,20 @@ stdenv.mkDerivation rec {
323361 mv runfiles.bash.tmp tools/bash/runfiles/runfiles.bash
324362
325363 patchShebangs .
364+
365+ # bazel reads its system bazelrc in /etc
366+ # override this path to a builtin one
367+ substituteInPlace \
368+ src/main/cpp/option_processor.cc \
369+ --replace BAZEL_SYSTEM_BAZELRC_PATH "\"$out/etc/bazelrc\""
326370 '';
327371 in lib.optionalString stdenv.hostPlatform.isDarwin darwinPatches
328372 + genericPatches;
329373
330374 buildInputs = [
331375 buildJdk
376+ python3 # bazel build requires python3. However we still use python2 for most of the other tasks
377+ # This will have to be refactored later.
332378 ];
333379
334380 # when a command can’t be found in a bazel build, you might also
@@ -375,6 +421,12 @@ stdenv.mkDerivation rec {
375421
376422 wrapProgram "$out/bin/bazel" --add-flags --server_javabase="${runJdk}"
377423
424+ # generates the system bazelrc
425+ # warning: the name of the repository depends on the system, hence
426+ # the reference to .name
427+ mkdir $out/etc
428+ echo "build --override_repository=${remote_java_tools.name}=${remote_java_tools}" > $out/etc/bazelrc
429+
378430 # shell completion files
379431 mkdir -p $out/share/bash-completion/completions $out/share/zsh/site-functions
380432 mv ./bazel_src/output/bazel-complete.bash $out/share/bash-completion/completions/bazel