File tree Expand file tree Collapse file tree 8 files changed +141
-0
lines changed Expand file tree Collapse file tree 8 files changed +141
-0
lines changed Original file line number Diff line number Diff line change 1+ load ("@rules_cc//cc:defs.bzl" , "cc_test" )
2+ load ("@rules_foreign_cc//foreign_cc:defs.bzl" , "meson" )
3+ load ("@rules_shell//shell:sh_test.bzl" , "sh_test" )
4+
5+ meson (
6+ name = "meson_lib" ,
7+ build_data = ["//meson_simple/code:clang_wrapper.sh" ],
8+ env = select ({
9+ "//:windows" : {
10+ "CLANG_WRAPPER" : "$(execpath //meson_simple/code:clang_wrapper.sh)" ,
11+ "CXX_FLAGS" : "/MD" ,
12+ },
13+ "//conditions:default" : {
14+ "CLANG_WRAPPER" : "$(execpath //meson_simple/code:clang_wrapper.sh)" ,
15+ "CXX_FLAGS" : "-fPIC" ,
16+ },
17+ }),
18+ lib_source = "//meson_simple/code:srcs" ,
19+ out_static_libs = ["liba.a" ],
20+ )
21+
22+ cc_test (
23+ name = "test_lib" ,
24+ srcs = [
25+ "test_libb.cpp" ,
26+ ],
27+ deps = [
28+ ":meson_lib" ,
29+ ],
30+ )
31+
32+ meson (
33+ name = "meson_lib-introspect" ,
34+ lib_source = "//meson_simple/code:srcs" ,
35+ out_data_files = ["introspect.json" ],
36+ out_include_dir = "" ,
37+ out_lib_dir = "" ,
38+ targets = ["introspect" ],
39+ )
40+
41+ sh_test (
42+ name = "test_introspect" ,
43+ srcs = ["test_introspect.sh" ],
44+ args = ["$(location meson_lib-introspect)" ],
45+ data = [":meson_lib-introspect" ],
46+ deps = ["@bazel_tools//tools/bash/runfiles" ],
47+ )
Original file line number Diff line number Diff line change 1+ exports_files (["clang_wrapper.sh" ])
2+
3+ filegroup (
4+ name = "srcs" ,
5+ srcs = [
6+ "liba.cpp" ,
7+ "liba.h" ,
8+ "meson.build" ,
9+ ],
10+ visibility = ["//meson_simple:__subpackages__" ],
11+ )
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ set -o errexit
4+ set -o nounset
5+
6+ if [[ $( uname) == * " NT" * ]]; then
7+ # If Windows
8+ exec clang-cl " $@ "
9+ else
10+ exec clang " $@ "
11+ fi
Original file line number Diff line number Diff line change 1+ #include " liba.h"
2+
3+ std::string hello_liba (void ) { return " Hello from LIBA!" ; }
Original file line number Diff line number Diff line change 1+ #ifndef LIBA_H_
2+ #define LIBA_H_ (1 )
3+
4+ #include < stdio.h>
5+
6+ #include < string>
7+
8+ std::string hello_liba (void );
9+
10+ #endif
Original file line number Diff line number Diff line change 1+ project (' liba' , ' cpp' )
2+
3+ builddir = ' rules_foreign_cc_build'
4+
5+ cxx = meson .get_compiler(' cpp' )
6+
7+ liba = static_library (
8+ ' a' ,
9+ ' liba.cpp' ,
10+ cpp_args : cxx.get_supported_arguments(),
11+ include_directories : include_directories (' .' ),
12+ install : true ,
13+ install_dir : join_paths (get_option (' prefix' ), ' lib' ),
14+ )
15+
16+ install_headers (' liba.h' , subdir : ' include' )
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ # --- begin runfiles.bash initialization ---
4+ # The runfiles library itself defines rlocation which you would need to look
5+ # up the library's runtime location, thus we have a chicken-and-egg problem.
6+ #
7+ # Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash).
8+ set -euo pipefail
9+ if [[ ! -d " ${RUNFILES_DIR:-/ dev/ null} " && ! -f " ${RUNFILES_MANIFEST_FILE:-/ dev/ null} " ]]; then
10+ if [[ -f " $0 .runfiles_manifest" ]]; then
11+ export RUNFILES_MANIFEST_FILE=" $0 .runfiles_manifest"
12+ elif [[ -f " $0 .runfiles/MANIFEST" ]]; then
13+ export RUNFILES_MANIFEST_FILE=" $0 .runfiles/MANIFEST"
14+ elif [[ -f " $0 .runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
15+ export RUNFILES_DIR=" $0 .runfiles"
16+ fi
17+ fi
18+ if [[ -f " ${RUNFILES_DIR:-/ dev/ null} /bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
19+ source " ${RUNFILES_DIR} /bazel_tools/tools/bash/runfiles/runfiles.bash"
20+ elif [[ -f " ${RUNFILES_MANIFEST_FILE:-/ dev/ null} " ]]; then
21+ source " $( grep -m1 " ^bazel_tools/tools/bash/runfiles/runfiles.bash " \
22+ " $RUNFILES_MANIFEST_FILE " | cut -d ' ' -f 2-) "
23+ else
24+ echo >&2 " ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash"
25+ exit 1
26+ fi
27+ # --- end runfiles.bash initialization ---
28+
29+ [[ -f $( rlocation $TEST_WORKSPACE /$1 ) ]] && exit 0
30+ exit 1
Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ #include < stdexcept>
3+ #include < string>
4+
5+ #include " include/liba.h"
6+
7+ int main (int argc, char * argv[]) {
8+ std::string result = hello_liba ();
9+ if (result != " Hello from LIBA!" ) {
10+ throw std::runtime_error (" Wrong result: " + result);
11+ }
12+ std::cout << " Everything's fine!" ;
13+ }
You can’t perform that action at this time.
0 commit comments