summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Maudoux <guillaume.maudoux@tweag.io>2023-12-14 13:11:19 +0100
committergithub-actions[bot] <github-actions[bot]@users.noreply.github.com>2024-01-02 08:19:49 +0000
commit9c50c447b9c88bee2d8ec97f9304f47d5a69428d (patch)
tree5cc10c5d380137a219babfa9ef516e3e532697fc
parentbazel_7: fix cpp-test with bzlmod, for linux (diff)
downloadnixpkgs-9c50c447b9c88bee2d8ec97f9304f47d5a69428d.tar.gz
bazel_7: fix protobuf test on darwin
(cherry picked from commit 459e800b0475d6804808798f67a5f58e3294a6e4)
-rw-r--r--pkgs/development/tools/build-managers/bazel/bazel_7/cpp-test.nix20
-rw-r--r--pkgs/development/tools/build-managers/bazel/bazel_7/protobuf-test.nix57
-rw-r--r--pkgs/development/tools/build-managers/bazel/bazel_7/tests.nix26
3 files changed, 51 insertions, 52 deletions
diff --git a/pkgs/development/tools/build-managers/bazel/bazel_7/cpp-test.nix b/pkgs/development/tools/build-managers/bazel/bazel_7/cpp-test.nix
index f81526240312..15854d524283 100644
--- a/pkgs/development/tools/build-managers/bazel/bazel_7/cpp-test.nix
+++ b/pkgs/development/tools/build-managers/bazel/bazel_7/cpp-test.nix
@@ -40,8 +40,6 @@ let
export LD='${darwin.cctools}/bin/ld'
export LIBTOOL='${darwin.cctools}/bin/libtool'
export CC='${stdenv.cc}/bin/clang'
- export BAZEL_LINKLIBS='-lstdc++:-lm'
- export BAZEL_LINKOPTS='-x:c++'
# XXX: hack for macosX, this flags disable bazel usage of xcode
# See: https://github.com/bazelbuild/bazel/issues/4231
@@ -67,33 +65,25 @@ let
inherit workspaceDir;
bazelPkg = bazel;
bazelScript = ''
- set -x
- env | grep c..abi
${bazel}/bin/bazel build //... \
--enable_bzlmod \
--verbose_failures \
--repository_cache=${mergedDistDir} \
- --action_env=NIX_DEBUG=1 \
- --announce_rc \
--curses=no \
'' + lib.optionalString (stdenv.isDarwin) ''
- --repo_env=BAZEL_LINKLIBS \
- --repo_env=BAZEL_LINKOPTS \
--cxxopt=-x --cxxopt=c++ \
--host_cxxopt=-x --host_cxxopt=c++ \
- --action_env=NIX_CFLAGS_COMPILE \
- --action_env=NIX_LDFLAGS \
+ '' + lib.optionalString (stdenv.cc.isClang && stdenv ? cc.libcxx.cxxabi.libName) ''
+ --linkopt=-Wl,-l${stdenv.cc.libcxx.cxxabi.libName} \
+ --linkopt=-L${stdenv.cc.libcxx.cxxabi}/lib \
+ --host_linkopt=-Wl,-l${stdenv.cc.libcxx.cxxabi.libName} \
+ --host_linkopt=-L${stdenv.cc.libcxx.cxxabi}/lib \
'' + lib.optionalString (stdenv.isDarwin && Foundation != null) ''
--linkopt=-Wl,-F${Foundation}/Library/Frameworks \
--linkopt=-L${darwin.libobjc}/lib \
'' + ''
'';
- #'' + lib.optionalString (stdenv.isDarwin) ''
- # --repo_env=BAZEL_LINKLIBS='-lstdc++:-lm' \
- #'' + lib.optionalString (stdenv.isDarwin) ''
- # --cxxopt=-x --cxxopt=c++ --host_cxxopt=-x --host_cxxopt=c++ \
- # --linkopt=-Wl,-lstdc++ --host_linkopt=-Wl,-lstdc++ \
};
in testBazel
diff --git a/pkgs/development/tools/build-managers/bazel/bazel_7/protobuf-test.nix b/pkgs/development/tools/build-managers/bazel/bazel_7/protobuf-test.nix
index 37520ad3008a..88867e89d620 100644
--- a/pkgs/development/tools/build-managers/bazel/bazel_7/protobuf-test.nix
+++ b/pkgs/development/tools/build-managers/bazel/bazel_7/protobuf-test.nix
@@ -1,24 +1,25 @@
{ bazel
+, Foundation
, bazelTest
-, fetchFromGitHub
-, fetchurl
-, stdenv
+, callPackage
, darwin
+, distDir
, extraBazelArgs ? ""
+, fetchFromGitHub
+, fetchurl
+, jdk11_headless
, lib
+, libtool
+, lndir
, openjdk8
-, jdk11_headless
+, repoCache
, runLocal
, runtimeShell
+, stdenv
+, symlinkJoin
+, tree
, writeScript
, writeText
-, distDir
-, Foundation
-, callPackage
-, libtool
-, lndir
-, repoCache
-, tree
}:
# This test uses bzlmod because I could not make it work without it.
@@ -35,7 +36,7 @@ let
# [nix-shell]$ cp MODULE.bazel.lock $HERE/protobuf-test.MODULE.bazel.lock
lockfile = ./protobuf-test.MODULE.bazel.lock;
- protocbufRepoCache = callPackage ./bazel-repository-cache.nix {
+ protobufRepoCache = callPackage ./bazel-repository-cache.nix {
# We are somewhat lucky that bazel's own lockfile works for our tests.
# Use extraDeps if the tests need things that are not in that lockfile.
# But most test dependencies are bazel's builtin deps, so that at least aligns.
@@ -46,6 +47,11 @@ let
null == builtins.match ".*(macos|osx|linux|win|android|maven).*" name;
};
+ mergedRepoCache = symlinkJoin {
+ name = "mergedDistDir";
+ paths = [ protobufRepoCache distDir ];
+ };
+
MODULE = writeText "MODULE.bazel" ''
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
bazel_dep(name = "protobuf", version = "21.7")
@@ -137,29 +143,26 @@ let
];
bazelScript = ''
- # Augment bundled repository_cache with our extra paths
- mkdir -p $PWD/.repository_cache/content_addressable
- ${lndir}/bin/lndir ${repoCache}/content_addressable \
- $PWD/.repository_cache/content_addressable
- ${lndir}/bin/lndir ${protocbufRepoCache}/content_addressable \
- $PWD/.repository_cache/content_addressable
-
- tree $PWD/.repository_cache
-
${bazel}/bin/bazel \
build \
- --repository_cache=$PWD/.repository_cache \
+ --repository_cache=${mergedRepoCache} \
${extraBazelArgs} \
--enable_bzlmod \
--verbose_failures \
//... \
'' + lib.optionalString (lib.strings.versionOlder bazel.version "5.0.0") ''
- --host_javabase='@local_jdk//:jdk' \
- --java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \
- --javabase='@local_jdk//:jdk' \
+ --host_javabase='@local_jdk//:jdk' \
+ --java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \
+ --javabase='@local_jdk//:jdk' \
'' + lib.optionalString (stdenv.isDarwin) ''
- --cxxopt=-x --cxxopt=c++ --host_cxxopt=-x --host_cxxopt=c++ \
- --linkopt=-stdlib=libc++ --host_linkopt=-stdlib=libc++ \
+ --cxxopt=-x --cxxopt=c++ --host_cxxopt=-x --host_cxxopt=c++ \
+ '' + lib.optionalString (stdenv.cc.isClang && stdenv ? cc.libcxx.cxxabi.libName) ''
+ --linkopt=-Wl,-l${stdenv.cc.libcxx.cxxabi.libName} \
+ --linkopt=-L${stdenv.cc.libcxx.cxxabi}/lib \
+ --host_linkopt=-Wl,-l${stdenv.cc.libcxx.cxxabi.libName} \
+ --host_linkopt=-L${stdenv.cc.libcxx.cxxabi}/lib \
+ '' + ''
+
'';
};
diff --git a/pkgs/development/tools/build-managers/bazel/bazel_7/tests.nix b/pkgs/development/tools/build-managers/bazel/bazel_7/tests.nix
index 15088ef84e6a..7aafce0f4619 100644
--- a/pkgs/development/tools/build-managers/bazel/bazel_7/tests.nix
+++ b/pkgs/development/tools/build-managers/bazel/bazel_7/tests.nix
@@ -126,26 +126,32 @@ let
hash = "sha256-DaPKp7Sn5uvfZRjdDx6grot3g3B7trqCyL0TRIdwg98=";
};
- callBazelTests = args:
+ callBazelTests = bazel:
let
callBazelTest = newScope {
inherit runLocal bazelTest bazel-examples;
inherit Foundation;
- bazel = bazel_self;
+ inherit bazel;
distDir = testsDistDir;
extraBazelArgs = "";
+ repoCache = testsRepoCache;
};
in
recurseIntoAttrs (
(lib.optionalAttrs (!isDarwin) {
# `extracted` doesn’t work on darwin
- shebang = callBazelTest ../shebang-test.nix (args // { inherit extracted; });
+ shebang = callBazelTest ../shebang-test.nix {
+ inherit extracted;
+ extraBazelArgs = "--noenable_bzlmod";
+ };
}) // {
- bashTools = callBazelTest ../bash-tools-test.nix args;
- cpp = callBazelTest ./cpp-test.nix args;
- java = callBazelTest ../java-test.nix args;
- pythonBinPath = callBazelTest ../python-bin-path-test.nix args;
- protobuf = callBazelTest ./protobuf-test.nix (args // { repoCache = testsRepoCache; });
+ bashTools = callBazelTest ../bash-tools-test.nix { };
+ cpp = callBazelTest ./cpp-test.nix { };
+ java = callBazelTest ../java-test.nix {
+ extraBazelArgs = "--noenable_bzlmod";
+ };
+ pythonBinPath = callBazelTest ../python-bin-path-test.nix { };
+ protobuf = callBazelTest ./protobuf-test.nix { };
}
);
@@ -156,8 +162,8 @@ recurseIntoAttrs {
distDir = testsDistDir;
testsRepoCache = testsRepoCache;
- vanilla = callBazelTests { };
- withNixHacks = callBazelTests { bazel = bazelWithNixHacks; };
+ vanilla = callBazelTests bazel_self;
+ withNixHacks = callBazelTests bazelWithNixHacks;
# add some downstream packages using buildBazelPackage
downstream = recurseIntoAttrs ({