Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

bazel_7: cleanup changes made to common tests

+293 -119
+1 -1
pkgs/development/tools/build-managers/bazel/bash-tools-test.nix
··· 1 - { lib, writeText, bazel, runLocal, bazelTest, distDir, extraBazelArgs ? ""}: 1 + { writeText, bazel, runLocal, bazelTest, distDir, extraBazelArgs ? ""}: 2 2 3 3 # Tests that certain executables are available in bazel-executed bash shells. 4 4
+1 -1
pkgs/development/tools/build-managers/bazel/bazel_5/default.nix
··· 287 287 sha256 = "1mm4awx6sa0myiz9j4hwp71rpr7yh8vihf3zm15n2ii6xb82r31k"; 288 288 }; 289 289 290 - in (lib.optionalSttrs (!stdenv.hostPlatform.isDarwin) { 290 + in (lib.optionalAttrs (!stdenv.hostPlatform.isDarwin) { 291 291 # `extracted` doesn’t work on darwin 292 292 shebang = callPackage ../shebang-test.nix { inherit runLocal extracted bazelTest distDir; bazel = bazel_self;}; 293 293 }) // {
+183
pkgs/development/tools/build-managers/bazel/bazel_7/protobuf-test.nix
··· 1 + { bazel 2 + , bazelTest 3 + , fetchFromGitHub 4 + , fetchurl 5 + , stdenv 6 + , darwin 7 + , extraBazelArgs ? "" 8 + , lib 9 + , openjdk8 10 + , jdk11_headless 11 + , runLocal 12 + , runtimeShell 13 + , writeScript 14 + , writeText 15 + , distDir 16 + , Foundation 17 + , callPackage 18 + , libtool 19 + , lndir 20 + , repoCache 21 + , tree 22 + }: 23 + 24 + let 25 + 26 + lockfile = ./tests.MODULE.bazel.lock; 27 + 28 + protocbufRepoCache = callPackage ./bazel-repository-cache.nix { 29 + # We are somewhat lucky that bazel's own lockfile works for our tests. 30 + # Use extraDeps if the tests need things that are not in that lockfile. 31 + # But most test dependencies are bazel's builtin deps, so that at least aligns. 32 + inherit lockfile; 33 + 34 + # Remove platform-specific binaries, as they are large and useless. 35 + requiredDepNamePredicate = name: 36 + null == builtins.match ".*(macos|osx|linux|win|android|maven).*" name; 37 + }; 38 + 39 + MODULE = writeText "MODULE.bazel" '' 40 + bazel_dep(name = "rules_proto", version = "5.3.0-21.7") 41 + bazel_dep(name = "protobuf", version = "21.7") 42 + bazel_dep(name = "zlib", version = "1.3") 43 + ''; 44 + 45 + WORKSPACE = writeText "WORKSPACE" '' 46 + workspace(name = "our_workspace") 47 + 48 + load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 49 + 50 + http_archive( 51 + name = "rules_proto", 52 + sha256 = "dc3fb206a2cb3441b485eb1e423165b231235a1ea9b031b4433cf7bc1fa460dd", 53 + strip_prefix = "rules_proto-5.3.0-21.7", 54 + urls = [ 55 + "https://github.com/bazelbuild/rules_proto/archive/refs/tags/5.3.0-21.7.tar.gz", 56 + ], 57 + ) 58 + load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains") 59 + rules_proto_dependencies() 60 + rules_proto_toolchains() 61 + ''; 62 + 63 + personProto = writeText "person.proto" '' 64 + syntax = "proto3"; 65 + 66 + package person; 67 + 68 + message Person { 69 + string name = 1; 70 + int32 id = 2; 71 + string email = 3; 72 + } 73 + ''; 74 + 75 + personBUILD = writeText "BUILD" '' 76 + load("@rules_proto//proto:defs.bzl", "proto_library") 77 + 78 + proto_library( 79 + name = "person_proto", 80 + srcs = ["person.proto"], 81 + visibility = ["//visibility:public"], 82 + ) 83 + 84 + java_proto_library( 85 + name = "person_java_proto", 86 + deps = [":person_proto"], 87 + ) 88 + 89 + cc_proto_library( 90 + name = "person_cc_proto", 91 + deps = [":person_proto"], 92 + ) 93 + ''; 94 + 95 + toolsBazel = writeScript "bazel" '' 96 + #! ${runtimeShell} 97 + 98 + export CXX='${stdenv.cc}/bin/clang++' 99 + export LD='${darwin.cctools}/bin/ld' 100 + export LIBTOOL='${darwin.cctools}/bin/libtool' 101 + export CC='${stdenv.cc}/bin/clang' 102 + 103 + # XXX: hack for macosX, this flags disable bazel usage of xcode 104 + # See: https://github.com/bazelbuild/bazel/issues/4231 105 + export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 106 + 107 + export HOMEBREW_RUBY_PATH="foo" 108 + 109 + exec "$BAZEL_REAL" "$@" 110 + ''; 111 + 112 + workspaceDir = runLocal "our_workspace" { } ('' 113 + mkdir $out 114 + cp --no-preserve=all ${MODULE} $out/MODULE.bazel 115 + cp --no-preserve=all ${./tests.MODULE.bazel.lock} $out/MODULE.bazel.lock 116 + #cp ${WORKSPACE} $out/WORKSPACE 117 + touch $out/WORKSPACE 118 + touch $out/BUILD.bazel 119 + mkdir $out/person 120 + cp --no-preserve=all ${personProto} $out/person/person.proto 121 + cp --no-preserve=all ${personBUILD} $out/person/BUILD.bazel 122 + '' 123 + + (lib.optionalString stdenv.isDarwin '' 124 + echo 'tools bazel created' 125 + mkdir $out/tools 126 + install ${toolsBazel} $out/tools/bazel 127 + '')); 128 + 129 + testBazel = bazelTest { 130 + name = "bazel-test-protocol-buffers"; 131 + inherit workspaceDir; 132 + bazelPkg = bazel; 133 + buildInputs = [ 134 + (if lib.strings.versionOlder bazel.version "5.0.0" then openjdk8 else jdk11_headless) 135 + tree 136 + bazel 137 + ] 138 + ++ lib.optionals stdenv.hostPlatform.isDarwin [ 139 + Foundation 140 + darwin.objc4 141 + ]; 142 + 143 + bazelScript = '' 144 + # Augment bundled repository_cache with our extra paths 145 + mkdir -p $PWD/.repository_cache/content_addressable 146 + cp -r --no-preserve=all ${repoCache}/content_addressable/* \ 147 + $PWD/.repository_cache/content_addressable 148 + cp -r --no-preserve=all ${protocbufRepoCache}/content_addressable/* \ 149 + $PWD/.repository_cache/content_addressable 150 + 151 + tree $PWD/.repository_cache 152 + 153 + ${bazel}/bin/bazel \ 154 + build \ 155 + --repository_cache=$PWD/.repository_cache \ 156 + ${extraBazelArgs} \ 157 + --enable_bzlmod \ 158 + --verbose_failures \ 159 + //... \ 160 + '' + lib.optionalString (lib.strings.versionOlder bazel.version "5.0.0") '' 161 + --host_javabase='@local_jdk//:jdk' \ 162 + --java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \ 163 + --javabase='@local_jdk//:jdk' \ 164 + '' + lib.optionalString (stdenv.isDarwin) '' 165 + --cxxopt=-x --cxxopt=c++ --host_cxxopt=-x --host_cxxopt=c++ \ 166 + --linkopt=-stdlib=libc++ --host_linkopt=-stdlib=libc++ \ 167 + ''; 168 + #--cxxopt=-framework --cxxopt=Foundation \ 169 + #--linkopt=-F${Foundation}/Library/Frameworks \ 170 + #--host_linkopt=-F${Foundation}/Library/Frameworks \ 171 + 172 + #--distdir=$PWD/.repository_cache \ 173 + #--verbose_failures \ 174 + #--curses=no \ 175 + #--sandbox_debug \ 176 + #--strict_java_deps=off \ 177 + #--strict_proto_deps=off \ 178 + #--repository_cache=${repoCache} \ 179 + #--distdir=${repoCache} \ 180 + }; 181 + 182 + in 183 + testBazel
+1 -1
pkgs/development/tools/build-managers/bazel/bazel_7/tests.nix
··· 145 145 cpp = callBazelTest ../cpp-test.nix args; 146 146 java = callBazelTest ../java-test.nix args; 147 147 pythonBinPath = callBazelTest ../python-bin-path-test.nix args; 148 - protobuf = callBazelTest ../protobuf-test.nix (args // { repoCache = testsRepoCache; }); 148 + protobuf = callBazelTest ./protobuf-test.nix (args // { repoCache = testsRepoCache; }); 149 149 }); 150 150 151 151 bazelWithNixHacks = bazel_self.override { enableNixHacks = true; };
+9 -11
pkgs/development/tools/build-managers/bazel/cpp-test.nix
··· 1 - { bazel 1 + { 2 + bazel 2 3 , bazelTest 3 4 , bazel-examples 4 5 , stdenv ··· 10 11 , writeScript 11 12 , writeText 12 13 , distDir 13 - , Foundation 14 + , Foundation ? null 14 15 }: 15 16 16 17 let ··· 30 31 exec "$BAZEL_REAL" "$@" 31 32 ''; 32 33 33 - workspaceDir = runLocal "our_workspace" { } ('' 34 + workspaceDir = runLocal "our_workspace" {} ('' 34 35 cp -r ${bazel-examples}/cpp-tutorial/stage3 $out 35 36 find $out -type d -exec chmod 755 {} \; 36 37 '' ··· 44 45 inherit workspaceDir; 45 46 bazelPkg = bazel; 46 47 bazelScript = '' 47 - ${bazel}/bin/bazel info output_base 48 48 ${bazel}/bin/bazel build //... \ 49 49 --verbose_failures \ 50 - --sandbox_debug \ 51 50 --distdir=${distDir} \ 52 51 --curses=no \ 53 52 ${extraBazelArgs} \ 54 53 '' + lib.optionalString (stdenv.isDarwin) '' 55 - --cxxopt=-x --cxxopt=c++ --host_cxxopt=-x --host_cxxopt=c++ \ 56 - --linkopt=-stdlib=libc++ --host_linkopt=-stdlib=libc++ \ 57 - --linkopt=-Wl,-F${Foundation}/Library/Frameworks \ 58 - --linkopt=-L${darwin.libobjc}/lib \ 54 + --cxxopt=-x --cxxopt=c++ --host_cxxopt=-x --host_cxxopt=c++ \ 55 + --linkopt=-stdlib=libc++ --host_linkopt=-stdlib=libc++ \ 56 + --linkopt=-Wl,-F${Foundation}/Library/Frameworks \ 57 + --linkopt=-L${darwin.libobjc}/lib \ 59 58 ''; 60 59 }; 61 60 62 - in 63 - testBazel 61 + in testBazel
+9 -18
pkgs/development/tools/build-managers/bazel/java-test.nix
··· 31 31 exec "$BAZEL_REAL" "$@" 32 32 ''; 33 33 34 - workspaceDir = runLocal "our_workspace" { } ('' 34 + workspaceDir = runLocal "our_workspace" {} ('' 35 35 cp -r ${bazel-examples}/java-tutorial $out 36 36 find $out -type d -exec chmod 755 {} \; 37 37 '' ··· 44 44 name = "bazel-test-java"; 45 45 inherit workspaceDir; 46 46 bazelPkg = bazel; 47 - buildInputs = [ 48 - (if lib.strings.versionOlder bazel.version "5.0.0" then openjdk8 else jdk11_headless) 49 - ]; 47 + buildInputs = [ (if lib.strings.versionOlder bazel.version "5.0.0" then openjdk8 else jdk11_headless) ]; 50 48 bazelScript = '' 51 49 ${bazel}/bin/bazel \ 52 50 run \ 53 51 --announce_rc \ 54 - --toolchain_resolution_debug='@bazel_tools//tools/jdk:(runtime_)?toolchain_type' \ 52 + ${lib.optionalString (lib.strings.versionOlder "5.0.0" bazel.version) 53 + "--toolchain_resolution_debug='@bazel_tools//tools/jdk:(runtime_)?toolchain_type'" 54 + } \ 55 55 --distdir=${distDir} \ 56 56 --verbose_failures \ 57 57 --curses=no \ 58 58 --strict_java_deps=off \ 59 59 //:ProjectRunner \ 60 60 '' + lib.optionalString (lib.strings.versionOlder bazel.version "5.0.0") '' 61 - --host_javabase='@local_jdk//:jdk' \ 62 - --java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \ 63 - --javabase='@local_jdk//:jdk' \ 61 + --host_javabase='@local_jdk//:jdk' \ 62 + --java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \ 63 + --javabase='@local_jdk//:jdk' \ 64 64 '' + extraBazelArgs; 65 65 }; 66 66 67 - # --repo_env=JAVA_HOME=${jdk11_headless}/${if stdenv.hostPlatform.isDarwin then "/zulu-17.jdk/Contents/Home" else "/lib/openjdk"} \ 68 - #--java_language_version=17 \ 69 - #--java_language_version=17 \ 70 - #--java_runtime_version=local_jdk \ 71 - # --java_language_version=11 \ 72 - # --tool_java_runtime_version=local_jdk_17 \ 73 - # --tool_java_language_version=17 \ 74 - #--java_runtime_version=local_jdk_11 \ 75 - in 76 - testBazel 67 + in testBazel 77 68
+89 -86
pkgs/development/tools/build-managers/bazel/protobuf-test.nix
··· 1 - { bazel 1 + { 2 + bazel 2 3 , bazelTest 3 4 , fetchFromGitHub 4 5 , fetchurl 5 6 , stdenv 6 7 , darwin 7 - , extraBazelArgs ? "" 8 8 , lib 9 9 , openjdk8 10 10 , jdk11_headless ··· 13 13 , writeScript 14 14 , writeText 15 15 , distDir 16 - , Foundation 17 - , callPackage 18 - , libtool 19 - , lndir 20 - , repoCache 21 - , tree 22 16 }: 23 17 24 18 let 19 + com_google_protobuf = fetchFromGitHub { 20 + owner = "protocolbuffers"; 21 + repo = "protobuf"; 22 + rev = "v3.13.0"; 23 + sha256 = "1nqsvi2yfr93kiwlinz8z7c68ilg1j75b2vcpzxzvripxx5h6xhd"; 24 + }; 25 25 26 - lockfile = ./bazel_7/tests.MODULE.bazel.lock; 26 + bazel_skylib = fetchFromGitHub { 27 + owner = "bazelbuild"; 28 + repo = "bazel-skylib"; 29 + rev = "2ec2e6d715e993d96ad6222770805b5bd25399ae"; 30 + sha256 = "1z2r2vx6kj102zvp3j032djyv99ski1x1sl4i3p6mswnzrzna86s"; 31 + }; 27 32 28 - protocbufRepoCache = callPackage ./bazel_7/bazel-repository-cache.nix { 29 - # We are somewhat lucky that bazel's own lockfile works for our tests. 30 - # Use extraDeps if the tests need things that are not in that lockfile. 31 - # But most test dependencies are bazel's builtin deps, so that at least aligns. 32 - inherit lockfile; 33 + rules_python = fetchFromGitHub { 34 + owner = "bazelbuild"; 35 + repo = "rules_python"; 36 + rev = "c8c79aae9aa1b61d199ad03d5fe06338febd0774"; 37 + sha256 = "1zn58wv5wcylpi0xj7riw34i1jjpqahanxx8y9srwrv0v93b6pqz"; 38 + }; 33 39 34 - # Take all the rules_ deps, bazel_ deps and their transitive dependencies, 35 - # but none of the platform-specific binaries, as they are large and useless. 36 - requiredDepNamePredicate = name: 37 - null == builtins.match ".*(macos|osx|linux|win|android|maven).*" name; 40 + rules_proto = fetchFromGitHub { 41 + owner = "bazelbuild"; 42 + repo = "rules_proto"; 43 + rev = "a0761ed101b939e19d83b2da5f59034bffc19c12"; 44 + sha256 = "09lqfj5fxm1fywxr5w8pnpqd859gb6751jka9fhxjxjzs33glhqf"; 38 45 }; 39 46 40 - MODULE = writeText "MODULE.bazel" '' 41 - bazel_dep(name = "rules_proto", version = "5.3.0-21.7") 42 - bazel_dep(name = "protobuf", version = "21.7") 43 - bazel_dep(name = "zlib", version = "1.3") 44 - ''; 47 + net_zlib = fetchurl rec { 48 + url = "https://zlib.net/zlib-1.2.11.tar.gz"; 49 + sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1"; 50 + 51 + passthru.sha256 = sha256; 52 + }; 45 53 46 54 WORKSPACE = writeText "WORKSPACE" '' 47 55 workspace(name = "our_workspace") 48 56 57 + load("//:proto-support.bzl", "protobuf_deps") 58 + protobuf_deps() 59 + load("@rules_proto//proto:repositories.bzl", "rules_proto_toolchains") 60 + rules_proto_toolchains() 61 + ''; 62 + 63 + protoSupport = writeText "proto-support.bzl" '' 64 + """Load dependencies needed to compile the protobuf library as a 3rd-party consumer.""" 65 + 49 66 load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 50 67 51 - http_archive( 52 - name = "rules_proto", 53 - sha256 = "dc3fb206a2cb3441b485eb1e423165b231235a1ea9b031b4433cf7bc1fa460dd", 54 - strip_prefix = "rules_proto-5.3.0-21.7", 55 - urls = [ 56 - "https://github.com/bazelbuild/rules_proto/archive/refs/tags/5.3.0-21.7.tar.gz", 57 - ], 58 - ) 59 - load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains") 60 - rules_proto_dependencies() 61 - rules_proto_toolchains() 68 + def protobuf_deps(): 69 + """Loads common dependencies needed to compile the protobuf library.""" 70 + 71 + if "zlib" not in native.existing_rules(): 72 + # proto_library, cc_proto_library, and java_proto_library rules implicitly 73 + # depend on @com_google_protobuf for protoc and proto runtimes. 74 + # This statement defines the @com_google_protobuf repo. 75 + native.local_repository( 76 + name = "com_google_protobuf", 77 + path = "${com_google_protobuf}", 78 + ) 79 + native.local_repository( 80 + name = "bazel_skylib", 81 + path = "${bazel_skylib}", 82 + ) 83 + native.local_repository( 84 + name = "rules_proto", 85 + path = "${rules_proto}", 86 + ) 87 + native.local_repository( 88 + name = "rules_python", 89 + path = "${rules_python}", 90 + ) 91 + 92 + http_archive( 93 + name = "zlib", 94 + build_file = "@com_google_protobuf//:third_party/zlib.BUILD", 95 + sha256 = "${net_zlib.sha256}", 96 + strip_prefix = "zlib-1.2.11", 97 + urls = ["file://${net_zlib}"], 98 + ) 62 99 ''; 63 100 64 101 personProto = writeText "person.proto" '' ··· 105 142 # See: https://github.com/bazelbuild/bazel/issues/4231 106 143 export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 107 144 108 - export HOMEBREW_RUBY_PATH="foo" 109 - 110 145 exec "$BAZEL_REAL" "$@" 111 146 ''; 112 147 113 - workspaceDir = runLocal "our_workspace" { } ('' 148 + workspaceDir = runLocal "our_workspace" {} ('' 114 149 mkdir $out 115 - cp --no-preserve=all ${MODULE} $out/MODULE.bazel 116 - cp --no-preserve=all ${./bazel_7/tests.MODULE.bazel.lock} $out/MODULE.bazel.lock 117 - #cp ${WORKSPACE} $out/WORKSPACE 118 - touch $out/WORKSPACE 150 + cp ${WORKSPACE} $out/WORKSPACE 119 151 touch $out/BUILD.bazel 152 + cp ${protoSupport} $out/proto-support.bzl 120 153 mkdir $out/person 121 - cp --no-preserve=all ${personProto} $out/person/person.proto 122 - cp --no-preserve=all ${personBUILD} $out/person/BUILD.bazel 154 + cp ${personProto} $out/person/person.proto 155 + cp ${personBUILD} $out/person/BUILD.bazel 123 156 '' 124 157 + (lib.optionalString stdenv.isDarwin '' 125 - echo 'tools bazel created' 126 158 mkdir $out/tools 127 - install ${toolsBazel} $out/tools/bazel 159 + cp ${toolsBazel} $out/tools/bazel 128 160 '')); 129 161 130 162 testBazel = bazelTest { 131 163 name = "bazel-test-protocol-buffers"; 132 164 inherit workspaceDir; 133 165 bazelPkg = bazel; 134 - buildInputs = [ 135 - (if lib.strings.versionOlder bazel.version "5.0.0" then openjdk8 else jdk11_headless) 136 - tree 137 - bazel 138 - ] 139 - ++ lib.optionals stdenv.hostPlatform.isDarwin [ 140 - Foundation 141 - darwin.objc4 142 - ]; 143 - 166 + buildInputs = [ (if lib.strings.versionOlder bazel.version "5.0.0" then openjdk8 else jdk11_headless) ]; 144 167 bazelScript = '' 145 - # Augment bundled repository_cache with our extra paths 146 - mkdir -p $PWD/.repository_cache/content_addressable 147 - cp -r --no-preserve=all ${repoCache}/content_addressable/* \ 148 - $PWD/.repository_cache/content_addressable 149 - cp -r --no-preserve=all ${protocbufRepoCache}/content_addressable/* \ 150 - $PWD/.repository_cache/content_addressable 151 - 152 - tree $PWD/.repository_cache 153 - 154 168 ${bazel}/bin/bazel \ 155 169 build \ 156 - --repository_cache=$PWD/.repository_cache \ 157 - ${extraBazelArgs} \ 158 - --enable_bzlmod \ 170 + --distdir=${distDir} \ 159 171 --verbose_failures \ 172 + --curses=no \ 173 + --sandbox_debug \ 174 + --strict_java_deps=off \ 175 + --strict_proto_deps=off \ 160 176 //... \ 161 177 '' + lib.optionalString (lib.strings.versionOlder bazel.version "5.0.0") '' 162 - --host_javabase='@local_jdk//:jdk' \ 163 - --java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \ 164 - --javabase='@local_jdk//:jdk' \ 178 + --host_javabase='@local_jdk//:jdk' \ 179 + --java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \ 180 + --javabase='@local_jdk//:jdk' \ 165 181 '' + lib.optionalString (stdenv.isDarwin) '' 166 - --cxxopt=-x --cxxopt=c++ --host_cxxopt=-x --host_cxxopt=c++ \ 167 - --linkopt=-stdlib=libc++ --host_linkopt=-stdlib=libc++ \ 182 + --cxxopt=-x --cxxopt=c++ --host_cxxopt=-x --host_cxxopt=c++ \ 183 + --linkopt=-stdlib=libc++ --host_linkopt=-stdlib=libc++ \ 168 184 ''; 169 - #--cxxopt=-framework --cxxopt=Foundation \ 170 - #--linkopt=-F${Foundation}/Library/Frameworks \ 171 - #--host_linkopt=-F${Foundation}/Library/Frameworks \ 172 - 173 - #--distdir=$PWD/.repository_cache \ 174 - #--verbose_failures \ 175 - #--curses=no \ 176 - #--sandbox_debug \ 177 - #--strict_java_deps=off \ 178 - #--strict_proto_deps=off \ 179 - #--repository_cache=${repoCache} \ 180 - #--distdir=${repoCache} \ 181 185 }; 182 186 183 - in 184 - testBazel 187 + in testBazel
-1
pkgs/development/tools/build-managers/bazel/shebang-test.nix
··· 22 22 bazelPkg = bazel; 23 23 bazelScript = '' 24 24 set -ueo pipefail 25 - 26 25 FAIL= 27 26 check_shebangs() { 28 27 local dir="$1"