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