diff options
Diffstat (limited to 'nixpkgs/pkgs/development/tools/build-managers/bazel/default.nix')
-rw-r--r-- | nixpkgs/pkgs/development/tools/build-managers/bazel/default.nix | 102 |
1 files changed, 63 insertions, 39 deletions
diff --git a/nixpkgs/pkgs/development/tools/build-managers/bazel/default.nix b/nixpkgs/pkgs/development/tools/build-managers/bazel/default.nix index 01619e0cb117..da69000a5e49 100644 --- a/nixpkgs/pkgs/development/tools/build-managers/bazel/default.nix +++ b/nixpkgs/pkgs/development/tools/build-managers/bazel/default.nix @@ -5,7 +5,7 @@ , lr, xe, zip, unzip, bash, writeCBin, coreutils , which, gawk, gnused, gnutar, gnugrep, gzip, findutils # updater -, python3, writeScript +, python27, python3, writeScript # Apple dependencies , cctools, libcxx, CoreFoundation, CoreServices, Foundation # Allow to independently override the jdks used to build and run respectively @@ -19,14 +19,17 @@ , enableNixHacks ? false , gcc-unwrapped , autoPatchelfHook +, file +, substituteAll +, writeTextFile }: let - version = "0.29.0"; + version = "2.0.0"; src = fetchurl { url = "https://github.com/bazelbuild/bazel/releases/download/${version}/bazel-${version}-dist.zip"; - sha256 = "01cb6f2e808bd016cf0e217e12373c9efb808123e58b37885be8364458d3a40a"; + sha256 = "1fvc7lakdczim1i99hrwhwx2w75afd3q9fgbhrx7i3pnav3a6kbj"; }; # Update with `eval $(nix-build -A bazel.updater)`, @@ -46,15 +49,16 @@ let srcs.io_bazel_rules_sass srcs.platforms (if stdenv.hostPlatform.isDarwin - then srcs."java_tools_javac11_darwin-v4.0.zip" - else srcs."java_tools_javac11_linux-v4.0.zip") - srcs."coverage_output_generator-v1.0.zip" + then srcs."java_tools_javac11_darwin-v7.0.zip" + else srcs."java_tools_javac11_linux-v7.0.zip") + srcs."coverage_output_generator-v2.0.zip" srcs.build_bazel_rules_nodejs - srcs."android_tools_pkg-0.8.tar.gz" - srcs."0.27.1.tar.gz" + srcs."android_tools_pkg-0.12.tar.gz" + srcs."0.28.3.tar.gz" srcs.rules_pkg srcs.rules_cc srcs.rules_java + srcs.rules_proto ]); distDir = runCommand "bazel-deps" {} '' @@ -90,7 +94,7 @@ let # ], # ) # - [ bash coreutils findutils gawk gnugrep gnutar gnused gzip which unzip ]; + [ bash coreutils findutils gawk gnugrep gnutar gnused gzip which unzip file zip ]; # Java toolchain used for the build and tests javaToolchain = "@bazel_tools//tools/jdk:toolchain_host${buildJdkName}"; @@ -106,7 +110,7 @@ let remote_java_tools = stdenv.mkDerivation { name = "remote_java_tools_${system}"; - src = srcDepsSet."java_tools_javac11_${system}-v4.0.zip"; + src = srcDepsSet."java_tools_javac11_${system}-v7.0.zip"; nativeBuildInputs = [ autoPatchelfHook unzip ]; buildInputs = [ gcc-unwrapped ]; @@ -123,6 +127,18 @@ let ''; }; + bazelRC = writeTextFile { + name = "bazel-rc"; + text = '' + build --override_repository=${remote_java_tools.name}=${remote_java_tools} + build --distdir=${distDir} + startup --server_javabase=${runJdk} + + # load default location for the system wide configuration + try-import /etc/bazel.bazelrc + ''; + }; + in stdenv.mkDerivation rec { pname = "bazel"; @@ -144,6 +160,24 @@ stdenv.mkDerivation rec { # This is breaking the build of any C target. This patch removes the last # argument if it's found to be an empty string. ./trim-last-argument-to-gcc-if-empty.patch + + # --experimental_strict_action_env (which may one day become the default + # see bazelbuild/bazel#2574) hardcodes the default + # action environment to a non hermetic value (e.g. "/usr/local/bin"). + # This is non hermetic on non-nixos systems. On NixOS, bazel cannot find the required binaries. + # So we are replacing this bazel paths by defaultShellPath, + # improving hermeticity and making it work in nixos. + (substituteAll { + src = ./strict_action_env.patch; + strictActionEnvPatch = defaultShellPath; + }) + + # bazel reads its system bazelrc in /etc + # override this path to a builtin one + (substituteAll { + src = ./bazel_rc.patch; + bazelSystemBazelRCPath = bazelRC; + }) ] ++ lib.optional enableNixHacks ./nix-hacks.patch; @@ -221,7 +255,10 @@ stdenv.mkDerivation rec { sha256 = "03c1bwlq5bs3hg96v4g4pg2vqwhqq6w538h66rcpw02f83yy7fs8"; }; - in { + in (if !stdenv.hostPlatform.isDarwin then { + # `extracted` doesn’t work on darwin + shebang = callPackage ./shebang-test.nix { inherit runLocal extracted bazelTest distDir; }; + } else {}) // { bashTools = callPackage ./bash-tools-test.nix { inherit runLocal bazelTest distDir; }; cpp = callPackage ./cpp-test.nix { inherit runLocal bazelTest bazel-examples distDir; }; java = callPackage ./java-test.nix { inherit runLocal bazelTest bazel-examples distDir; }; @@ -305,7 +342,7 @@ stdenv.mkDerivation rec { export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem ${libcxx}/include/c++/v1" # don't use system installed Xcode to run clang, use Nix clang instead - sed -i -e "s;/usr/bin/xcrun clang;${stdenv.cc}/bin/clang $NIX_CFLAGS_COMPILE $NIX_LDFLAGS -framework CoreFoundation;g" \ + sed -i -E "s;/usr/bin/xcrun (--sdk macosx )?clang;${stdenv.cc}/bin/clang $NIX_CFLAGS_COMPILE $NIX_LDFLAGS -framework CoreFoundation;g" \ scripts/bootstrap/compile.sh \ src/tools/xcode/realpath/BUILD \ src/tools/xcode/stdredirect/BUILD \ @@ -326,10 +363,12 @@ stdenv.mkDerivation rec { ''; genericPatches = '' - # Substitute python's stub shebang to plain python path. (see TODO add pr URL) - # See also `postFixup` where python is added to $out/nix-support - substituteInPlace src/main/java/com/google/devtools/build/lib/bazel/rules/python/python_stub_template.txt \ - --replace "#!/usr/bin/env python" "#!${python3}/bin/python" + # Substitute j2objc and objc wrapper's python shebang to plain python path. + # These scripts explicitly depend on Python 2.7, hence we use python27. + # See also `postFixup` where python27 is added to $out/nix-support + substituteInPlace tools/j2objc/j2objc_header_map.py --replace "$!/usr/bin/python2.7" "#!${python27}/bin/python" + substituteInPlace tools/j2objc/j2objc_wrapper.py --replace "$!/usr/bin/python2.7" "#!${python27}/bin/python" + substituteInPlace tools/objc/j2objc_dead_code_pruner.py --replace "$!/usr/bin/python2.7" "#!${python27}/bin/python" # md5sum is part of coreutils sed -i 's|/sbin/md5|md5sum|' \ @@ -339,8 +378,12 @@ stdenv.mkDerivation rec { grep -rlZ /bin src/main/java/com/google/devtools | while IFS="" read -r -d "" path; do # If you add more replacements here, you must change the grep above! # Only files containing /bin are taken into account. + # We default to python3 where possible. See also `postFixup` where + # python3 is added to $out/nix-support substituteInPlace "$path" \ --replace /bin/bash ${customBash}/bin/bash \ + --replace "/usr/bin/env bash" ${customBash}/bin/bash \ + --replace "/usr/bin/env python" ${python3}/bin/python \ --replace /usr/bin/env ${coreutils}/bin/env \ --replace /bin/true ${coreutils}/bin/true done @@ -380,14 +423,6 @@ stdenv.mkDerivation rec { -e "/\$command \\\\$/a --host_java_toolchain='${javaToolchain}' \\\\" \ -i scripts/bootstrap/compile.sh - # --experimental_strict_action_env (which will soon become the - # default, see bazelbuild/bazel#2574) hardcodes the default - # action environment to a value that on NixOS at least is bogus. - # So we hardcode it to something useful. - substituteInPlace \ - src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java \ - --replace /bin:/usr/bin ${defaultShellPath} - # This is necessary to avoid: # "error: no visible @interface for 'NSDictionary' declares the selector # 'initWithContentsOfURL:error:'" @@ -403,12 +438,6 @@ stdenv.mkDerivation rec { mv runfiles.bash.tmp tools/bash/runfiles/runfiles.bash patchShebangs . - - # bazel reads its system bazelrc in /etc - # override this path to a builtin one - substituteInPlace \ - src/main/cpp/option_processor.cc \ - --replace BAZEL_SYSTEM_BAZELRC_PATH "\"$out/etc/bazelrc\"" ''; in lib.optionalString stdenv.hostPlatform.isDarwin darwinPatches + genericPatches; @@ -460,15 +489,6 @@ stdenv.mkDerivation rec { cp ./bazel_src/scripts/packages/bazel.sh $out/bin/bazel mv ./bazel_src/output/bazel $out/bin/bazel-real - wrapProgram "$out/bin/bazel" --add-flags --server_javabase="${runJdk}" - - # generates the system bazelrc - # warning: the name of the repository depends on the system, hence - # the reference to .name - mkdir $out/etc - echo "build --override_repository=${remote_java_tools.name}=${remote_java_tools}" > $out/etc/bazelrc - echo "build --distdir=${distDir}" >> $out/etc/bazelrc - # shell completion files mkdir -p $out/share/bash-completion/completions $out/share/zsh/site-functions mv ./bazel_src/output/bazel-complete.bash $out/share/bash-completion/completions/bazel @@ -516,6 +536,10 @@ stdenv.mkDerivation rec { echo "${customBash} ${defaultShellPath}" >> $out/nix-support/depends # The templates get tar’d up into a .jar, # so nix can’t detect python is needed in the runtime closure + # Some of the scripts explicitly depend on Python 2.7. Otherwise, we + # default to using python3. Therefore, both python27 and python3 are + # runtime dependencies. + echo "${python27}" >> $out/nix-support/depends echo "${python3}" >> $out/nix-support/depends '' + lib.optionalString stdenv.isDarwin '' echo "${cctools}" >> $out/nix-support/depends |