Skip to content

Commit da30194

Browse files
committed
[none] Bazel build system support
- Added the `MODULE.bazel`, `BUILD.bazel` and `.bazelrc` configuration files - Aligned the `check_version` script to verify the Bazel module version - Reverted the naming of the CMake library target back to `cpp-ap` instead of `cpp-ap-2` to better match the naming of the Bazel module - Updated the `cpp-ap-demo` submodule: added the Bazel configuration files to enable building the demo projects using Bazel - Updated the `demo` workflow to build the demo projects using both CMake and Bazel and on both Linux and Windows platforms
1 parent f24f127 commit da30194

File tree

16 files changed

+192
-55
lines changed

16 files changed

+192
-55
lines changed

.bazelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build --enable_platform_specific_config
2+
3+
build:linux --cxxopt=-std=c++20
4+
build:windows --cxxopt=/std:c++20

.github/workflows/clang.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ jobs:
2626
CC: clang-17
2727
CXX: clang++-17
2828
run: |
29-
cmake -B build -DBUILD_TESTS=ON -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_C_COMPILER=$CC
29+
cmake -B build_clang -DBUILD_TESTS=ON -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_C_COMPILER=$CC
3030
continue-on-error: false
3131

3232
- name: Build tests
3333
run: |
34-
cmake --build build/ -j 4
34+
cmake --build build_clang/ -j 4
3535
continue-on-error: false
3636

3737
- name: Run tests
3838
run: |
39-
ctest --test-dir build/tests/ -V
39+
ctest --test-dir build_clang/tests/ -V

.github/workflows/demo.yaml

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ on:
99
- cpp-ap-demo
1010
- include/**
1111
- CMakeLists.txt
12+
- MODULE.bazel
13+
- BUILD.bazel
1214
pull_request:
1315
branches:
1416
- master
1517

1618
jobs:
17-
build-demo:
18-
name: Build cpp-ap-demo
19+
build-demo-linux:
20+
name: Build cpp-ap-demo (Linux)
1921
runs-on: ubuntu-24.04
2022

2123
steps:
@@ -25,7 +27,7 @@ jobs:
2527
fetch-depth: 0
2628
submodules: recursive
2729

28-
- name: Sync submodules to HTTPS
30+
- name: Sync submodules
2931
run: git submodule sync --recursive
3032

3133
- name: Update submodules
@@ -40,9 +42,71 @@ jobs:
4042
echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT
4143
fi
4244
43-
- name: Build cpp-ap-demo
45+
- name: Build cpp-ap-demo (CMake)
4446
run: |
4547
cd cpp-ap-demo
46-
cmake -B build -DAP_TAG=${{ steps.branch-name.outputs.branch }}
47-
cd build
48-
make -j 4
48+
cmake -B build_cmake -DAP_TAG=${{ steps.branch-name.outputs.branch }}
49+
cmake --build build_cmake/ -j 4
50+
51+
- name: Setup Bazel
52+
uses: bazel-contrib/setup-bazel@0.15.0
53+
with:
54+
bazelisk-cache: true
55+
disk-cache: ${{ github.workflow }}
56+
repository-cache: true
57+
58+
- name: Build cpp-ap-demo (Bazel)
59+
run: |
60+
cd cpp-ap-demo
61+
BRANCH="${{ steps.branch-name.outputs.branch }}"
62+
sed -i "s/branch = \".*\"/branch = \"$BRANCH\"/" MODULE.bazel
63+
bazel build //:all_demos
64+
65+
build-demo-windows:
66+
name: Build cpp-ap-demo (Windows)
67+
runs-on: windows-2022
68+
69+
steps:
70+
- name: Check out current branch
71+
uses: actions/checkout@v4
72+
with:
73+
fetch-depth: 0
74+
submodules: recursive
75+
76+
- name: Sync submodules
77+
run: git submodule sync --recursive
78+
shell: bash
79+
80+
- name: Update submodules
81+
run: git submodule update --init --recursive
82+
shell: bash
83+
84+
- name: Determine Current Branch
85+
id: branch-name
86+
run: |
87+
if ("${{ github.event_name }}" -eq "pull_request") {
88+
"branch=${{ github.event.pull_request.head.ref }}" >> $env:GITHUB_OUTPUT
89+
} else {
90+
$branch = "${env:GITHUB_REF}".Replace("refs/heads/", "")
91+
"branch=$branch" >> $env:GITHUB_OUTPUT
92+
}
93+
94+
- name: Build cpp-ap-demo (CMake)
95+
run: |
96+
cd cpp-ap-demo
97+
cmake -B build_cmake -DAP_TAG=${{ steps.branch-name.outputs.branch }}
98+
cmake --build build_cmake/ --config Release -j 4
99+
100+
- name: Setup Bazel
101+
uses: bazel-contrib/setup-bazel@0.15.0
102+
with:
103+
bazelisk-cache: true
104+
disk-cache: ${{ github.workflow }}
105+
repository-cache: true
106+
107+
- name: Build cpp-ap-demo (Bazel)
108+
run: |
109+
cd cpp-ap-demo
110+
$BRANCH="${{ steps.branch-name.outputs.branch }}"
111+
(Get-Content MODULE.bazel) -replace 'branch = ".*"', "branch = `"$BRANCH`"" | Set-Content MODULE.bazel
112+
bazel build //:all_demos

.github/workflows/gcc.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ jobs:
2626
CC: gcc-13
2727
CXX: g++-13
2828
run: |
29-
cmake -B build -DBUILD_TESTS=ON -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_C_COMPILER=$CC
29+
cmake -B build_gcc -DBUILD_TESTS=ON -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_C_COMPILER=$CC
3030
continue-on-error: false
3131

3232
- name: Build tests
3333
run: |
34-
cmake --build build/ -j 4
34+
cmake --build build_gcc/ -j 4
3535
continue-on-error: false
3636

3737
- name: Run tests
3838
run: |
39-
ctest --test-dir build/tests/ -V
39+
ctest --test-dir build_gcc/tests/ -V

.github/workflows/msvc.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ jobs:
2323

2424
- name: Configure CMake
2525
run: |
26-
cmake -B build -G "Visual Studio 17 2022" -A x64 -DBUILD_TESTS=ON
26+
cmake -B build_msvc -G "Visual Studio 17 2022" -A x64 -DBUILD_TESTS=ON
2727
shell: powershell
2828

2929
- name: Build tests
3030
run: |
31-
cmake --build build --config Debug --parallel
31+
cmake --build build_msvc --config Debug --parallel
3232
shell: powershell
3333

3434
- name: Run tests
3535
run: |
36-
ctest --test-dir build/tests -V -C Debug
36+
ctest --test-dir build_msvc/tests -V -C Debug
3737
shell: powershell

BUILD.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cc_library(
2+
name = "cpp-ap",
3+
hdrs = glob(["include/**/*.hpp"]),
4+
includes = ["include"],
5+
cxxopts = ["-std=c++20"],
6+
visibility = ["//visibility:public"],
7+
)

CMakeLists.txt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ else()
77
endif()
88

99
project(cpp-ap
10-
VERSION 2.4.1
10+
VERSION 2.5.0
1111
DESCRIPTION "Command-line argument parser for C++20"
1212
HOMEPAGE_URL "https://github.com/SpectraL519/cpp-ap"
1313
LANGUAGES CXX
@@ -17,12 +17,12 @@ project(cpp-ap
1717
option(BUILD_TESTS "Build project tests" OFF)
1818

1919
# The library target
20-
add_library(cpp-ap-2 INTERFACE)
21-
target_include_directories(cpp-ap-2 INTERFACE
20+
add_library(cpp-ap INTERFACE)
21+
target_include_directories(cpp-ap INTERFACE
2222
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
2323
$<INSTALL_INTERFACE:include>
2424
)
25-
set_target_properties(cpp-ap-2 PROPERTIES
25+
set_target_properties(cpp-ap PROPERTIES
2626
CXX_STANDARD 20
2727
CXX_STANDARD_REQUIRED YES
2828
)
@@ -31,37 +31,37 @@ set_target_properties(cpp-ap-2 PROPERTIES
3131
include(GNUInstallDirs)
3232
include(CMakePackageConfigHelpers)
3333

34-
set(INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/cpp-ap-2)
34+
set(INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/cpp-ap)
3535

3636
# Install the headers
3737
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
3838
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
3939

4040
# Install the library target
41-
install(TARGETS cpp-ap-2 EXPORT cpp-ap-2-targets)
41+
install(TARGETS cpp-ap EXPORT cpp-ap-targets)
4242

4343
# Create a config file for find_package
4444
configure_package_config_file(
45-
${CMAKE_CURRENT_SOURCE_DIR}/cmake/cpp-ap-2-config.cmake.in
46-
${CMAKE_CURRENT_BINARY_DIR}/cpp-ap-2-config.cmake
45+
${CMAKE_CURRENT_SOURCE_DIR}/cmake/cpp-ap-config.cmake.in
46+
${CMAKE_CURRENT_BINARY_DIR}/cpp-ap-config.cmake
4747
INSTALL_DESTINATION ${INSTALL_DIR}
4848
)
4949

5050
write_basic_package_version_file(
51-
${CMAKE_CURRENT_BINARY_DIR}/cpp-ap-2-config-version.cmake
51+
${CMAKE_CURRENT_BINARY_DIR}/cpp-ap-config-version.cmake
5252
VERSION ${PROJECT_VERSION}
5353
COMPATIBILITY ExactVersion
5454
)
5555

5656
install(FILES
57-
${CMAKE_CURRENT_BINARY_DIR}/cpp-ap-2-config.cmake
58-
${CMAKE_CURRENT_BINARY_DIR}/cpp-ap-2-config-version.cmake
57+
${CMAKE_CURRENT_BINARY_DIR}/cpp-ap-config.cmake
58+
${CMAKE_CURRENT_BINARY_DIR}/cpp-ap-config-version.cmake
5959
DESTINATION ${INSTALL_DIR}
6060
)
6161

62-
install(EXPORT cpp-ap-2-targets
63-
FILE cpp-ap-2-targets.cmake
64-
NAMESPACE cpp-ap-2::
62+
install(EXPORT cpp-ap-targets
63+
FILE cpp-ap-targets.cmake
64+
NAMESPACE cpp-ap::
6565
DESTINATION ${INSTALL_DIR}
6666
)
6767

@@ -71,9 +71,9 @@ if (CPP_AP_IS_TOP_LEVEL_PROJECT AND BUILD_TESTS)
7171
endif()
7272

7373
# Exporting from the build tree
74-
export(EXPORT cpp-ap-2-targets
75-
FILE ${CMAKE_CURRENT_BINARY_DIR}/cpp-ap-2-targets.cmake
76-
NAMESPACE cpp-ap-2::
74+
export(EXPORT cpp-ap-targets
75+
FILE ${CMAKE_CURRENT_BINARY_DIR}/cpp-ap-targets.cmake
76+
NAMESPACE cpp-ap::
7777
)
7878

79-
export(PACKAGE cpp-ap-2)
79+
export(PACKAGE cpp-ap)

Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ PROJECT_NAME = CPP-AP
4848
# could be handy for archiving the generated documentation or if some version
4949
# control system is used.
5050

51-
PROJECT_NUMBER = 2.4.1
51+
PROJECT_NUMBER = 2.5.0
5252

5353
# Using the PROJECT_BRIEF tag one can provide an optional one line description
5454
# for a project that appears at the top of each page and should give viewer a

MODULE.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module(
2+
name = "cpp-ap",
3+
version = "2.5.0",
4+
)

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h1>
2-
CPP-AP-2
2+
CPP-AP
33
<a href="https://github.com/SpectraL519/cpp-ap" target="_blank">
44
<i class="fa fa-github" style="font-size: 1.3em; margin-left: 6px; position: relative; top: -0.08em;"></i>
55
</a>
@@ -49,6 +49,7 @@ Command-line argument parser for C++20
4949
- [Tutorial](/docs/tutorial.md#tutorial)
5050
- [Setting Up CPP-AP](/docs/tutorial.md#setting-up-cpp-ap)
5151
- [CMake Integration](/docs/tutorial.md#cmake-integration)
52+
- [Bazel Build System](/docs/tutorial.md#bazel-build-system)
5253
- [Downloading the Library](/docs/tutorial.md#downloading-the-library)
5354
- [The Parser Class](/docs/tutorial.md#the-parser-class)
5455
- [Adding Arguments](/docs/tutorial.md#adding-arguments)

0 commit comments

Comments
 (0)