Skip to content

Commit

Permalink
Support building with Bazel (#1033)
Browse files Browse the repository at this point in the history
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 <henryschreineriii@gmail.com>
Co-authored-by: Caleb Zulawski <caleb.zulawski@caci.com>
Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
4 people committed May 1, 2024
1 parent 74a3c0d commit 1a1d9d4
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,18 @@ jobs:
- name: Test
run: meson test -C build-meson

bazel-build:
name: Bazel build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build
run: bazel build //...

- name: Test
run: bazel test --test_output=errors //...

install:
name: install tests
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ a.out*
/html/*
!/meson.build
/CMakeUserPresets.json
/bazel-*
/MODULE.bazel.lock

/node_modules/*
/package.json
Expand Down
8 changes: 8 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cc_library(
name = "cli11",
srcs = glob(["src/**/*.cpp"]),
hdrs = glob(["include/**/*.hpp"]),
local_defines = ["CLI11_COMPILE"],
strip_include_prefix = "/include",
visibility = ["//visibility:public"],
)
3 changes: 3 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module(name = "cli11")

bazel_dep(name = "catch2", version = "3.5.4", dev_dependency = True)
75 changes: 75 additions & 0 deletions tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
cc_binary(
name = "ensure_utf8",
srcs = ["applications/ensure_utf8.cpp"],
deps = ["//:cli11"],
)

cc_binary(
name = "ensure_utf8_twice",
srcs = ["applications/ensure_utf8_twice.cpp"],
deps = ["//:cli11"],
)

cc_library(
name = "catch_main",
srcs = ["main.cpp"],
hdrs = ["catch.hpp"],
defines = ["CLI11_CATCH3"],
deps = ["@catch2//:catch2_main"],
)

cc_test(
name = "AppTest",
srcs = [
"AppTest.cpp",
"app_helper.hpp",
],
data = [
"ensure_utf8",
"ensure_utf8_twice",
],
local_defines = [
'CLI11_ENSURE_UTF8_EXE=\\"$(rootpath ensure_utf8)\\"',
'CLI11_ENSURE_UTF8_TWICE_EXE=\\"$(rootpath ensure_utf8_twice)\\"',
],
deps = [
"catch_main",
"//:cli11",
"@catch2",
],
)

[
cc_test(
name = test,
srcs = [
test + ".cpp",
"app_helper.hpp",
],
deps = [
"catch_main",
"//:cli11",
"@catch2",
],
)
for test in [
"HelpersTest",
"ConfigFileTest",
"OptionTypeTest",
"SimpleTest",
"SetTest",
"TransformTest",
"CreationTest",
"SubcommandTest",
"HelpTest",
"FormatterTest",
"NewParseTest",
"OptionalTest",
"DeprecatedTest",
"StringParseTest",
"ComplexTypeTest",
"TrueFalseTest",
"OptionGroupTest",
"EncodingTest",
]
]
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ file(
GLOB_RECURSE DATA_FILES
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/data/*")
"${CMAKE_CURRENT_SOURCE_DIR}/data/*" "${CMAKE_CURRENT_SOURCE_DIR}/tests/.gitkeep")

foreach(DATA_FILE IN LISTS DATA_FILES)
add_custom_command(
Expand Down
6 changes: 3 additions & 3 deletions tests/HelpersTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ TEST_CASE("Validators: FileIsDir", "[helpers]") {
}

TEST_CASE("Validators: DirectoryExists", "[helpers]") {
std::string mydir{"../tests"};
std::string mydir{"tests"};
CHECK(CLI::ExistingDirectory(mydir).empty());
}

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

TEST_CASE("Validators: PathExistsDir", "[helpers]") {
std::string mydir{"../tests"};
std::string mydir{"tests"};
CHECK(CLI::ExistingPath(mydir).empty());
}

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

std::string dir{"../tests"};
std::string dir{"tests"};
std::string notpath{"nondirectory"};

auto path_or_dir = CLI::ExistingPath | CLI::ExistingDirectory;
Expand Down
Empty file added tests/tests/.gitkeep
Empty file.

0 comments on commit 1a1d9d4

Please sign in to comment.