2020-04-24 23:36:52 +00:00
|
|
|
{
|
|
|
|
bazel
|
|
|
|
, bazelTest
|
|
|
|
, bazel-examples
|
2022-09-09 14:08:57 +00:00
|
|
|
, stdenv
|
2024-07-31 10:19:44 +00:00
|
|
|
, cctools
|
2022-09-09 14:08:57 +00:00
|
|
|
, darwin
|
2024-01-02 11:29:13 +00:00
|
|
|
, extraBazelArgs ? ""
|
2020-04-24 23:36:52 +00:00
|
|
|
, lib
|
|
|
|
, runLocal
|
|
|
|
, runtimeShell
|
|
|
|
, writeScript
|
|
|
|
, writeText
|
|
|
|
, distDir
|
2024-01-02 11:29:13 +00:00
|
|
|
, Foundation ? null
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
toolsBazel = writeScript "bazel" ''
|
|
|
|
#! ${runtimeShell}
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
export CXX='${stdenv.cc}/bin/clang++'
|
2024-07-31 10:19:44 +00:00
|
|
|
export LD='${cctools}/bin/ld'
|
|
|
|
export LIBTOOL='${cctools}/bin/libtool'
|
2022-09-09 14:08:57 +00:00
|
|
|
export CC='${stdenv.cc}/bin/clang'
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# XXX: hack for macosX, this flags disable bazel usage of xcode
|
|
|
|
# See: https://github.com/bazelbuild/bazel/issues/4231
|
|
|
|
export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
|
|
|
|
|
|
|
|
exec "$BAZEL_REAL" "$@"
|
|
|
|
'';
|
|
|
|
|
|
|
|
workspaceDir = runLocal "our_workspace" {} (''
|
|
|
|
cp -r ${bazel-examples}/cpp-tutorial/stage3 $out
|
|
|
|
find $out -type d -exec chmod 755 {} \;
|
|
|
|
''
|
2024-09-26 11:04:55 +00:00
|
|
|
+ (lib.optionalString stdenv.hostPlatform.isDarwin ''
|
2020-04-24 23:36:52 +00:00
|
|
|
mkdir $out/tools
|
|
|
|
cp ${toolsBazel} $out/tools/bazel
|
|
|
|
''));
|
|
|
|
|
|
|
|
testBazel = bazelTest {
|
2024-05-15 15:35:15 +00:00
|
|
|
name = "${bazel.pname}-test-cpp";
|
2020-04-24 23:36:52 +00:00
|
|
|
inherit workspaceDir;
|
|
|
|
bazelPkg = bazel;
|
|
|
|
bazelScript = ''
|
2024-01-02 11:29:13 +00:00
|
|
|
${bazel}/bin/bazel build //... \
|
|
|
|
--verbose_failures \
|
2020-04-24 23:36:52 +00:00
|
|
|
--distdir=${distDir} \
|
2021-12-21 02:18:32 +00:00
|
|
|
--curses=no \
|
2024-01-02 11:29:13 +00:00
|
|
|
${extraBazelArgs} \
|
2024-09-26 11:04:55 +00:00
|
|
|
'' + lib.optionalString (stdenv.hostPlatform.isDarwin) ''
|
2022-09-09 14:08:57 +00:00
|
|
|
--cxxopt=-x --cxxopt=c++ --host_cxxopt=-x --host_cxxopt=c++ \
|
|
|
|
--linkopt=-stdlib=libc++ --host_linkopt=-stdlib=libc++ \
|
2024-09-26 11:04:55 +00:00
|
|
|
'' + lib.optionalString (stdenv.hostPlatform.isDarwin && Foundation != null) ''
|
2024-01-02 11:29:13 +00:00
|
|
|
--linkopt=-Wl,-F${Foundation}/Library/Frameworks \
|
|
|
|
--linkopt=-L${darwin.libobjc}/lib \
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
in testBazel
|