Skip to content

Commit d05171c

Browse files
committed
Support building with Bazel
1 parent b24c301 commit d05171c

File tree

6 files changed

+114
-0
lines changed

6 files changed

+114
-0
lines changed

.github/workflows/tests.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,18 @@ jobs:
169169
- name: Test
170170
run: meson test -C build-meson
171171

172+
bazel-build:
173+
name: Bazel build
174+
runs-on: ubuntu-latest
175+
steps:
176+
- uses: actions/checkout@v4
177+
178+
- name: Build
179+
run: bazel build //...
180+
181+
- name: Test
182+
run: bazel test --test_output=errors //...
183+
172184
install:
173185
name: install tests
174186
runs-on: ubuntu-latest

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ a.out*
1010
/html/*
1111
!/meson.build
1212
/CMakeUserPresets.json
13+
/bazel-*
14+
/MODULE.bazel.lock
1315

1416
/node_modules/*
1517
/package.json

BUILD.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cc_library(
2+
name = "cli11",
3+
srcs = glob(["src/**/*.cpp"]),
4+
hdrs = glob(["include/**/*.hpp"]),
5+
local_defines = ["CLI11_COMPILE"],
6+
strip_include_prefix = "/include",
7+
visibility = ["//visibility:public"],
8+
)

MODULE.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module(name = "cli11")
2+
3+
bazel_dep(name = "catch2", version = "3.5.4", dev_dependency = True)

tests/BUILD.bazel

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
cc_binary(
2+
name = "ensure_utf8",
3+
srcs = ["applications/ensure_utf8.cpp"],
4+
deps = ["//:cli11"],
5+
)
6+
7+
cc_binary(
8+
name = "ensure_utf8_twice",
9+
srcs = ["applications/ensure_utf8_twice.cpp"],
10+
deps = ["//:cli11"],
11+
)
12+
13+
cc_library(
14+
name = "catch_main",
15+
srcs = ["main.cpp"],
16+
hdrs = ["catch.hpp"],
17+
defines = ["CLI11_CATCH3"],
18+
deps = ["@catch2//:catch2_main"],
19+
)
20+
21+
cc_test(
22+
name = "AppTest",
23+
srcs = [
24+
"AppTest.cpp",
25+
"app_helper.hpp",
26+
],
27+
data = [
28+
"ensure_utf8",
29+
"ensure_utf8_twice",
30+
],
31+
local_defines = [
32+
"BAZEL",
33+
'CLI11_ENSURE_UTF8_EXE=\\"$(rootpath ensure_utf8)\\"',
34+
'CLI11_ENSURE_UTF8_TWICE_EXE=\\"$(rootpath ensure_utf8_twice)\\"',
35+
],
36+
deps = [
37+
"catch_main",
38+
"//:cli11",
39+
"@catch2",
40+
],
41+
)
42+
43+
[
44+
cc_test(
45+
name = test,
46+
srcs = [
47+
test + ".cpp",
48+
"app_helper.hpp",
49+
],
50+
local_defines = ["BAZEL"],
51+
deps = [
52+
"catch_main",
53+
"//:cli11",
54+
"@catch2",
55+
],
56+
)
57+
for test in [
58+
"HelpersTest",
59+
"ConfigFileTest",
60+
"OptionTypeTest",
61+
"SimpleTest",
62+
"SetTest",
63+
"TransformTest",
64+
"CreationTest",
65+
"SubcommandTest",
66+
"HelpTest",
67+
"FormatterTest",
68+
"NewParseTest",
69+
"OptionalTest",
70+
"DeprecatedTest",
71+
"StringParseTest",
72+
"ComplexTypeTest",
73+
"TrueFalseTest",
74+
"OptionGroupTest",
75+
"EncodingTest",
76+
]
77+
]

tests/HelpersTest.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,11 @@ TEST_CASE("Validators: FileIsDir", "[helpers]") {
522522
}
523523

524524
TEST_CASE("Validators: DirectoryExists", "[helpers]") {
525+
#ifdef BAZEL
526+
std::string mydir{"tests"};
527+
#else
525528
std::string mydir{"../tests"};
529+
#endif
526530
CHECK(CLI::ExistingDirectory(mydir).empty());
527531
}
528532

@@ -543,7 +547,11 @@ TEST_CASE("Validators: DirectoryIsFile", "[helpers]") {
543547
}
544548

545549
TEST_CASE("Validators: PathExistsDir", "[helpers]") {
550+
#ifdef BAZEL
551+
std::string mydir{"tests"};
552+
#else
546553
std::string mydir{"../tests"};
554+
#endif
547555
CHECK(CLI::ExistingPath(mydir).empty());
548556
}
549557

@@ -665,7 +673,11 @@ TEST_CASE("Validators: CombinedPaths", "[helpers]") {
665673
bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file
666674
CHECK(ok);
667675

676+
#ifdef BAZEL
677+
std::string dir{"tests"};
678+
#else
668679
std::string dir{"../tests"};
680+
#endif
669681
std::string notpath{"nondirectory"};
670682

671683
auto path_or_dir = CLI::ExistingPath | CLI::ExistingDirectory;

0 commit comments

Comments
 (0)