Skip to content

Commit

Permalink
Support building with Bazel
Browse files Browse the repository at this point in the history
  • Loading branch information
calebzulawski authored and henryiii committed May 1, 2024
1 parent bd6462f commit 39a60e7
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 0 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)
77 changes: 77 additions & 0 deletions tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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 = [
"BAZEL",
'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",
],
local_defines = ["BAZEL"],
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",
]
]
12 changes: 12 additions & 0 deletions tests/HelpersTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,11 @@ TEST_CASE("Validators: FileIsDir", "[helpers]") {
}

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

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

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

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

#ifdef BAZEL
std::string dir{"tests"};
#else
std::string dir{"../tests"};
#endif
std::string notpath{"nondirectory"};

auto path_or_dir = CLI::ExistingPath | CLI::ExistingDirectory;
Expand Down

0 comments on commit 39a60e7

Please sign in to comment.