Skip to content

Commit 1a1d9d4

Browse files
calebzulawskihenryiiipre-commit-ci[bot]
authored
Support building with Bazel (#1033)
Adds support for building with Bazel. If merged, I can push this to https://registry.bazel.build/ when a new release is cut :) --------- Signed-off-by: Henry Schreiner <[email protected]> Co-authored-by: Caleb Zulawski <[email protected]> Co-authored-by: Henry Schreiner <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 74a3c0d commit 1a1d9d4

File tree

8 files changed

+104
-4
lines changed

8 files changed

+104
-4
lines changed

.github/workflows/tests.yml

+12
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

+2
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

+8
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

+3
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

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
'CLI11_ENSURE_UTF8_EXE=\\"$(rootpath ensure_utf8)\\"',
33+
'CLI11_ENSURE_UTF8_TWICE_EXE=\\"$(rootpath ensure_utf8_twice)\\"',
34+
],
35+
deps = [
36+
"catch_main",
37+
"//:cli11",
38+
"@catch2",
39+
],
40+
)
41+
42+
[
43+
cc_test(
44+
name = test,
45+
srcs = [
46+
test + ".cpp",
47+
"app_helper.hpp",
48+
],
49+
deps = [
50+
"catch_main",
51+
"//:cli11",
52+
"@catch2",
53+
],
54+
)
55+
for test in [
56+
"HelpersTest",
57+
"ConfigFileTest",
58+
"OptionTypeTest",
59+
"SimpleTest",
60+
"SetTest",
61+
"TransformTest",
62+
"CreationTest",
63+
"SubcommandTest",
64+
"HelpTest",
65+
"FormatterTest",
66+
"NewParseTest",
67+
"OptionalTest",
68+
"DeprecatedTest",
69+
"StringParseTest",
70+
"ComplexTypeTest",
71+
"TrueFalseTest",
72+
"OptionGroupTest",
73+
"EncodingTest",
74+
]
75+
]

tests/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ file(
106106
GLOB_RECURSE DATA_FILES
107107
LIST_DIRECTORIES false
108108
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
109-
"${CMAKE_CURRENT_SOURCE_DIR}/data/*")
109+
"${CMAKE_CURRENT_SOURCE_DIR}/data/*" "${CMAKE_CURRENT_SOURCE_DIR}/tests/.gitkeep")
110110

111111
foreach(DATA_FILE IN LISTS DATA_FILES)
112112
add_custom_command(

tests/HelpersTest.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ TEST_CASE("Validators: FileIsDir", "[helpers]") {
522522
}
523523

524524
TEST_CASE("Validators: DirectoryExists", "[helpers]") {
525-
std::string mydir{"../tests"};
525+
std::string mydir{"tests"};
526526
CHECK(CLI::ExistingDirectory(mydir).empty());
527527
}
528528

@@ -543,7 +543,7 @@ TEST_CASE("Validators: DirectoryIsFile", "[helpers]") {
543543
}
544544

545545
TEST_CASE("Validators: PathExistsDir", "[helpers]") {
546-
std::string mydir{"../tests"};
546+
std::string mydir{"tests"};
547547
CHECK(CLI::ExistingPath(mydir).empty());
548548
}
549549

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

668-
std::string dir{"../tests"};
668+
std::string dir{"tests"};
669669
std::string notpath{"nondirectory"};
670670

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

tests/tests/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)