bazel_6: fix darwin build

+156 -40
+10 -2
pkgs/development/tools/build-managers/bazel/bazel_6/default.nix
··· 185 185 # argument if it's found to be an empty string. 186 186 ../trim-last-argument-to-gcc-if-empty.patch 187 187 188 + # `java_proto_library` ignores `strict_proto_deps` 189 + # https://github.com/bazelbuild/bazel/pull/16146 190 + ./strict_proto_deps.patch 191 + 188 192 # On Darwin, using clang 6 to build fails because of a linker error (see #105573), 189 193 # but using clang 7 fails because libarclite_macosx.a cannot be found when linking 190 194 # the xcode_locator tool. ··· 218 222 src = ../bazel_rc.patch; 219 223 bazelSystemBazelRCPath = bazelRC; 220 224 }) 221 - ] ++ lib.optional enableNixHacks ../nix-hacks.patch; 225 + ] ++ lib.optional enableNixHacks ./nix-hacks.patch; 222 226 223 227 224 228 # Additional tests that check bazel’s functionality. Execute ··· 472 476 build --verbose_failures 473 477 build --curses=no 474 478 build --features=-layering_check 479 + build --experimental_strict_java_deps=off 480 + build --strict_proto_deps=off 475 481 EOF 476 482 477 483 cat >> third_party/grpc/bazel_1.41.0.patch <<EOF ··· 501 507 -e "/\$command \\\\$/a --verbose_failures \\\\" \ 502 508 -e "/\$command \\\\$/a --curses=no \\\\" \ 503 509 -e "/\$command \\\\$/a --features=-layering_check \\\\" \ 510 + -e "/\$command \\\\$/a --experimental_strict_java_deps=off \\\\" \ 511 + -e "/\$command \\\\$/a --strict_proto_deps=off \\\\" \ 504 512 -i scripts/bootstrap/compile.sh 505 513 506 514 # This is necessary to avoid: ··· 575 583 cd ./bazel_src 576 584 # build execlog tooling 577 585 export HOME=$(mktemp -d) 578 - ./output/bazel build src/tools/execlog:parser_deploy.jar 586 + ./output/bazel build src/tools/execlog:parser_deploy.jar 579 587 cd - 580 588 581 589 runHook postBuild
+40
pkgs/development/tools/build-managers/bazel/bazel_6/nix-hacks.patch
··· 1 + diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java 2 + index 25fbdcac9d..49616d37df 100644 3 + --- a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java 4 + +++ b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java 5 + @@ -568,22 +568,7 @@ public final class RepositoryDelegatorFunction implements SkyFunction { 6 + String content; 7 + try { 8 + content = FileSystemUtils.readContent(markerPath, StandardCharsets.UTF_8); 9 + - String markerRuleKey = readMarkerFile(content, markerData); 10 + - boolean verified = false; 11 + - if (Preconditions.checkNotNull(ruleKey).equals(markerRuleKey)) { 12 + - verified = handler.verifyMarkerData(rule, markerData, env); 13 + - if (env.valuesMissing()) { 14 + - return null; 15 + - } 16 + - } 17 + - 18 + - if (verified) { 19 + - return new Fingerprint().addString(content).digestAndReset(); 20 + - } else { 21 + - // So that we are in a consistent state if something happens while fetching the repository 22 + - markerPath.delete(); 23 + - return null; 24 + - } 25 + + return new Fingerprint().addString(content).digestAndReset(); 26 + } catch (IOException e) { 27 + throw new RepositoryFunctionException(e, Transience.TRANSIENT); 28 + } 29 + diff --git a/src/main/java/com/google/devtools/build/lib/shell/JavaSubprocessFactory.java b/src/main/java/com/google/devtools/build/lib/shell/JavaSubprocessFactory.java 30 + index 1a45b8a3a2..a6b73213f6 100644 31 + --- a/src/main/java/com/google/devtools/build/lib/shell/JavaSubprocessFactory.java 32 + +++ b/src/main/java/com/google/devtools/build/lib/shell/JavaSubprocessFactory.java 33 + @@ -152,7 +152,6 @@ public class JavaSubprocessFactory implements SubprocessFactory { 34 + ProcessBuilder builder = new ProcessBuilder(); 35 + builder.command(params.getArgv()); 36 + if (params.getEnv() != null) { 37 + - builder.environment().clear(); 38 + builder.environment().putAll(params.getEnv()); 39 + } 40 +
+21
pkgs/development/tools/build-managers/bazel/bazel_6/strict_proto_deps.patch
··· 1 + diff --git a/src/main/starlark/builtins_bzl/common/java/proto/java_proto_library.bzl b/src/main/starlark/builtins_bzl/common/java/proto/java_proto_library.bzl 2 + index 63f68167e4..f106e64c9b 100644 3 + --- a/src/main/starlark/builtins_bzl/common/java/proto/java_proto_library.bzl 4 + +++ b/src/main/starlark/builtins_bzl/common/java/proto/java_proto_library.bzl 5 + @@ -114,6 +114,7 @@ def java_compile_for_protos(ctx, output_jar_suffix, source_jar = None, deps = [] 6 + exports = exports, 7 + output = output_jar, 8 + output_source_jar = source_jar, 9 + + strict_deps = ctx.fragments.proto.strict_proto_deps(), 10 + injecting_rule_kind = injecting_rule_kind, 11 + javac_opts = java_toolchain.compatible_javacopts("proto"), 12 + enable_jspecify = False, 13 + @@ -140,7 +141,7 @@ bazel_java_proto_aspect = aspect( 14 + attr_aspects = ["deps", "exports"], 15 + required_providers = [ProtoInfo], 16 + provides = [JavaInfo, JavaProtoAspectInfo], 17 + - fragments = ["java"], 18 + + fragments = ["java", "proto"], 19 + ) 20 + 21 + def bazel_java_proto_library_rule(ctx):
+11 -6
pkgs/development/tools/build-managers/bazel/cpp-test.nix
··· 2 2 bazel 3 3 , bazelTest 4 4 , bazel-examples 5 - , gccStdenv 5 + , stdenv 6 + , darwin 6 7 , lib 7 8 , runLocal 8 9 , runtimeShell ··· 16 17 toolsBazel = writeScript "bazel" '' 17 18 #! ${runtimeShell} 18 19 19 - export CXX='${gccStdenv.cc}/bin/g++' 20 - export LD='${gccStdenv.cc}/bin/ld' 21 - export CC='${gccStdenv.cc}/bin/gcc' 20 + export CXX='${stdenv.cc}/bin/clang++' 21 + export LD='${darwin.cctools}/bin/ld' 22 + export LIBTOOL='${darwin.cctools}/bin/libtool' 23 + export CC='${stdenv.cc}/bin/clang' 22 24 23 25 # XXX: hack for macosX, this flags disable bazel usage of xcode 24 26 # See: https://github.com/bazelbuild/bazel/issues/4231 ··· 31 33 cp -r ${bazel-examples}/cpp-tutorial/stage3 $out 32 34 find $out -type d -exec chmod 755 {} \; 33 35 '' 34 - + (lib.optionalString gccStdenv.isDarwin '' 36 + + (lib.optionalString stdenv.isDarwin '' 35 37 mkdir $out/tools 36 38 cp ${toolsBazel} $out/tools/bazel 37 39 '')); ··· 46 48 --distdir=${distDir} \ 47 49 --curses=no \ 48 50 --sandbox_debug \ 49 - //... 51 + //... \ 52 + '' + lib.optionalString (stdenv.isDarwin) '' 53 + --cxxopt=-x --cxxopt=c++ --host_cxxopt=-x --host_cxxopt=c++ \ 54 + --linkopt=-stdlib=libc++ --host_linkopt=-stdlib=libc++ \ 50 55 ''; 51 56 }; 52 57
+15 -12
pkgs/development/tools/build-managers/bazel/java-test.nix
··· 2 2 bazel 3 3 , bazelTest 4 4 , bazel-examples 5 - , gccStdenv 5 + , stdenv 6 + , darwin 6 7 , lib 7 8 , openjdk8 8 9 , jdk11_headless ··· 18 19 toolsBazel = writeScript "bazel" '' 19 20 #! ${runtimeShell} 20 21 21 - export CXX='${gccStdenv.cc}/bin/g++' 22 - export LD='${gccStdenv.cc}/bin/ld' 23 - export CC='${gccStdenv.cc}/bin/gcc' 22 + export CXX='${stdenv.cc}/bin/clang++' 23 + export LD='${darwin.cctools}/bin/ld' 24 + export LIBTOOL='${darwin.cctools}/bin/libtool' 25 + export CC='${stdenv.cc}/bin/clang' 24 26 25 27 # XXX: hack for macosX, this flags disable bazel usage of xcode 26 28 # See: https://github.com/bazelbuild/bazel/issues/4231 ··· 33 35 cp -r ${bazel-examples}/java-tutorial $out 34 36 find $out -type d -exec chmod 755 {} \; 35 37 '' 36 - + (lib.optionalString gccStdenv.isDarwin '' 38 + + (lib.optionalString stdenv.isDarwin '' 37 39 mkdir $out/tools 38 40 cp ${toolsBazel} $out/tools/bazel 39 41 '')); ··· 47 49 ${bazel}/bin/bazel \ 48 50 run \ 49 51 --distdir=${distDir} \ 50 - --verbose_failures \ 51 - --curses=no \ 52 - --sandbox_debug \ 53 - //:ProjectRunner \ 52 + --verbose_failures \ 53 + --curses=no \ 54 + --sandbox_debug \ 55 + --strict_java_deps=off \ 56 + //:ProjectRunner \ 54 57 '' + lib.optionalString (lib.strings.versionOlder bazel.version "5.0.0") '' 55 - --host_javabase='@local_jdk//:jdk' \ 56 - --java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \ 57 - --javabase='@local_jdk//:jdk' \ 58 + --host_javabase='@local_jdk//:jdk' \ 59 + --java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \ 60 + --javabase='@local_jdk//:jdk' \ 58 61 ''; 59 62 }; 60 63
+19 -12
pkgs/development/tools/build-managers/bazel/protobuf-test.nix
··· 3 3 , bazelTest 4 4 , fetchFromGitHub 5 5 , fetchurl 6 - , gccStdenv 6 + , stdenv 7 + , darwin 7 8 , lib 8 9 , openjdk8 9 10 , jdk11_headless ··· 132 133 toolsBazel = writeScript "bazel" '' 133 134 #! ${runtimeShell} 134 135 135 - export CXX='${gccStdenv.cc}/bin/g++' 136 - export LD='${gccStdenv.cc}/bin/ld' 137 - export CC='${gccStdenv.cc}/bin/gcc' 136 + export CXX='${stdenv.cc}/bin/clang++' 137 + export LD='${darwin.cctools}/bin/ld' 138 + export LIBTOOL='${darwin.cctools}/bin/libtool' 139 + export CC='${stdenv.cc}/bin/clang' 138 140 139 141 # XXX: hack for macosX, this flags disable bazel usage of xcode 140 142 # See: https://github.com/bazelbuild/bazel/issues/4231 ··· 152 154 cp ${personProto} $out/person/person.proto 153 155 cp ${personBUILD} $out/person/BUILD.bazel 154 156 '' 155 - + (lib.optionalString gccStdenv.isDarwin '' 157 + + (lib.optionalString stdenv.isDarwin '' 156 158 mkdir $out/tools 157 159 cp ${toolsBazel} $out/tools/bazel 158 160 '')); ··· 166 168 ${bazel}/bin/bazel \ 167 169 build \ 168 170 --distdir=${distDir} \ 169 - --verbose_failures \ 170 - --curses=no \ 171 - --sandbox_debug \ 172 - //... \ 171 + --verbose_failures \ 172 + --curses=no \ 173 + --sandbox_debug \ 174 + --strict_java_deps=off \ 175 + --strict_proto_deps=off \ 176 + //... \ 173 177 '' + lib.optionalString (lib.strings.versionOlder bazel.version "5.0.0") '' 174 - --host_javabase='@local_jdk//:jdk' \ 175 - --java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \ 176 - --javabase='@local_jdk//:jdk' \ 178 + --host_javabase='@local_jdk//:jdk' \ 179 + --java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \ 180 + --javabase='@local_jdk//:jdk' \ 181 + '' + lib.optionalString (stdenv.isDarwin) '' 182 + --cxxopt=-x --cxxopt=c++ --host_cxxopt=-x --host_cxxopt=c++ \ 183 + --linkopt=-stdlib=libc++ --host_linkopt=-stdlib=libc++ \ 177 184 ''; 178 185 }; 179 186
+35 -5
pkgs/development/tools/build-managers/bazel/python-bin-path-test.nix
··· 1 - { writeText, bazel, bazelTest, runLocal, distDir }: 1 + { 2 + bazel 3 + , bazelTest 4 + , stdenv 5 + , darwin 6 + , lib 7 + , runLocal 8 + , runtimeShell 9 + , writeScript 10 + , writeText 11 + , distDir 12 + }: 2 13 3 14 let 15 + toolsBazel = writeScript "bazel" '' 16 + #! ${runtimeShell} 17 + 18 + export CXX='${stdenv.cc}/bin/clang++' 19 + export LD='${darwin.cctools}/bin/ld' 20 + export LIBTOOL='${darwin.cctools}/bin/libtool' 21 + export CC='${stdenv.cc}/bin/clang' 22 + 23 + # XXX: hack for macosX, this flags disable bazel usage of xcode 24 + # See: https://github.com/bazelbuild/bazel/issues/4231 25 + export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 26 + 27 + exec "$BAZEL_REAL" "$@" 28 + ''; 29 + 4 30 WORKSPACE = writeText "WORKSPACE" '' 5 31 workspace(name = "our_workspace") 6 32 ''; ··· 29 55 ) 30 56 ''; 31 57 32 - workspaceDir = runLocal "our_workspace" {} '' 58 + workspaceDir = runLocal "our_workspace" {} ('' 33 59 mkdir $out 34 60 cp ${WORKSPACE} $out/WORKSPACE 35 61 mkdir $out/python 36 62 cp ${pythonLib} $out/python/lib.py 37 63 cp ${pythonBin} $out/python/bin.py 38 64 cp ${pythonBUILD} $out/python/BUILD.bazel 39 - ''; 65 + '' 66 + + (lib.optionalString stdenv.isDarwin '' 67 + mkdir $out/tools 68 + cp ${toolsBazel} $out/tools/bazel 69 + '')); 40 70 41 71 testBazel = bazelTest { 42 72 name = "bazel-test-builtin-rules"; ··· 45 75 bazelScript = '' 46 76 ${bazel}/bin/bazel \ 47 77 run \ 48 - --distdir=${distDir} \ 49 - //python:bin 78 + --distdir=${distDir} \ 79 + //python:bin 50 80 ''; 51 81 }; 52 82
+5 -3
pkgs/top-level/all-packages.nix
··· 15459 15459 bazel_self = bazel_5; 15460 15460 }; 15461 15461 15462 - bazel_6 = callPackage ../development/tools/build-managers/bazel/bazel_6 { 15462 + bazel_6 = darwin.apple_sdk_11_0.callPackage ../development/tools/build-managers/bazel/bazel_6 { 15463 15463 inherit (darwin) cctools; 15464 - inherit (darwin.apple_sdk.frameworks) CoreFoundation CoreServices Foundation; 15464 + inherit (darwin.apple_sdk_11_0.frameworks) CoreFoundation CoreServices Foundation; 15465 15465 buildJdk = jdk11_headless; 15466 15466 runJdk = jdk11_headless; 15467 - stdenv = if stdenv.cc.isClang then llvmPackages.stdenv else stdenv; 15467 + stdenv = if stdenv.isDarwin then 15468 + darwin.apple_sdk_11_0.stdenv else 15469 + if stdenv.cc.isClang then llvmPackages.stdenv else stdenv; 15468 15470 bazel_self = bazel_6; 15469 15471 }; 15470 15472