1{
2 bazel
3, bazelTest
4, bazel-examples
5, stdenv
6, darwin
7, extraBazelArgs ? ""
8, lib
9, runLocal
10, runtimeShell
11, writeScript
12, writeText
13, distDir
14, Foundation ? null
15}:
16
17let
18
19 toolsBazel = writeScript "bazel" ''
20 #! ${runtimeShell}
21
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'
26
27 # XXX: hack for macosX, this flags disable bazel usage of xcode
28 # See: https://github.com/bazelbuild/bazel/issues/4231
29 export BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
30
31 exec "$BAZEL_REAL" "$@"
32 '';
33
34 workspaceDir = runLocal "our_workspace" {} (''
35 cp -r ${bazel-examples}/cpp-tutorial/stage3 $out
36 find $out -type d -exec chmod 755 {} \;
37 ''
38 + (lib.optionalString stdenv.isDarwin ''
39 mkdir $out/tools
40 cp ${toolsBazel} $out/tools/bazel
41 ''));
42
43 testBazel = bazelTest {
44 name = "${bazel.pname}-test-cpp";
45 inherit workspaceDir;
46 bazelPkg = bazel;
47 bazelScript = ''
48 ${bazel}/bin/bazel build //... \
49 --verbose_failures \
50 --distdir=${distDir} \
51 --curses=no \
52 ${extraBazelArgs} \
53 '' + lib.optionalString (stdenv.isDarwin) ''
54 --cxxopt=-x --cxxopt=c++ --host_cxxopt=-x --host_cxxopt=c++ \
55 --linkopt=-stdlib=libc++ --host_linkopt=-stdlib=libc++ \
56 '' + lib.optionalString (stdenv.isDarwin && Foundation != null) ''
57 --linkopt=-Wl,-F${Foundation}/Library/Frameworks \
58 --linkopt=-L${darwin.libobjc}/lib \
59 '';
60 };
61
62in testBazel