Skip to content

Commit 60149bc

Browse files
committed
ci: add ABI compatibility matrix workflow
This adds a new GitHub Actions workflow to verify ABI compatibility across C++ standard boundaries. It explicitly tests the scenario where JsonCpp is built with one standard (e.g., C++11) and consumed by an application built with a newer one (e.g., C++23), and vice versa. To facilitate testing the specific `std::string_view` boundary that is conditionally compiled, a new `stringView` demo application has been added to the `example/` directory and is consumed directly by the CI matrix to ensure standard library symbols link correctly across standard versions, build types (shared/static), and operating systems.
1 parent f92bcba commit 60149bc

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: ABI Compatibility
2+
3+
on: [check_run, push, pull_request]
4+
5+
env:
6+
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
7+
8+
jobs:
9+
abi-compatibility:
10+
runs-on: ${{ matrix.os }}
11+
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
os: [ubuntu-latest, windows-latest, macos-latest]
16+
shared_libs: [ON, OFF]
17+
include:
18+
- jsoncpp_std: 11
19+
app_std: 23
20+
- jsoncpp_std: 23
21+
app_std: 11
22+
23+
steps:
24+
- name: checkout project
25+
uses: actions/checkout@v4
26+
27+
- name: build and install JsonCpp (C++${{ matrix.jsoncpp_std }})
28+
shell: bash
29+
run: |
30+
mkdir build-jsoncpp
31+
cd build-jsoncpp
32+
cmake .. -DCMAKE_CXX_STANDARD=${{ matrix.jsoncpp_std }} \
33+
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
34+
-DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install-jsoncpp \
35+
-DBUILD_SHARED_LIBS=${{ matrix.shared_libs }} \
36+
-DJSONCPP_WITH_TESTS=OFF
37+
cmake --build . --config Release
38+
cmake --install . --config Release
39+
40+
- name: create example app
41+
shell: bash
42+
run: |
43+
mkdir example-app
44+
cat << 'EOF' > example-app/CMakeLists.txt
45+
cmake_minimum_required(VERSION 3.10)
46+
project(abi_test)
47+
48+
find_package(jsoncpp REQUIRED CONFIG)
49+
50+
add_executable(abi_test stringView.cpp)
51+
target_link_libraries(abi_test PRIVATE JsonCpp::JsonCpp)
52+
EOF
53+
54+
cp $GITHUB_WORKSPACE/example/stringView/stringView.cpp example-app/stringView.cpp
55+
56+
- name: build example app (C++${{ matrix.app_std }})
57+
shell: bash
58+
run: |
59+
cd example-app
60+
mkdir build
61+
cd build
62+
cmake .. -DCMAKE_CXX_STANDARD=${{ matrix.app_std }} \
63+
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
64+
-DCMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/install-jsoncpp
65+
cmake --build . --config Release
66+
67+
- name: run example app
68+
shell: bash
69+
run: |
70+
if [ "$RUNNER_OS" == "Windows" ]; then
71+
export PATH=$GITHUB_WORKSPACE/install-jsoncpp/bin:$PATH
72+
./example-app/build/Release/abi_test.exe
73+
elif [ "$RUNNER_OS" == "macOS" ]; then
74+
export DYLD_LIBRARY_PATH=$GITHUB_WORKSPACE/install-jsoncpp/lib:$DYLD_LIBRARY_PATH
75+
./example-app/build/abi_test
76+
else
77+
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/install-jsoncpp/lib:$LD_LIBRARY_PATH
78+
./example-app/build/abi_test
79+
fi

example/BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ cc_binary(
3333
srcs = ["stringWrite/stringWrite.cpp"],
3434
deps = ["//:jsoncpp"],
3535
)
36+
37+
cc_binary(
38+
name = "stringView",
39+
srcs = ["stringView/stringView.cpp"],
40+
deps = ["//:jsoncpp"],
41+
)

example/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set(EXAMPLES
44
readFromStream
55
stringWrite
66
streamWrite
7+
stringView
78
)
89
add_definitions(-D_GLIBCXX_USE_CXX11_ABI)
910

example/stringView/stringView.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "json/json.h"
2+
#include <iostream>
3+
#include <cstdlib>
4+
5+
#if defined(JSONCPP_HAS_STRING_VIEW)
6+
#include <string_view>
7+
#endif
8+
9+
/**
10+
* \brief Example using std::string_view with JsonCpp.
11+
*/
12+
int main() {
13+
Json::Value root;
14+
root["key"] = "value";
15+
16+
#if defined(JSONCPP_HAS_STRING_VIEW)
17+
std::cout << "Has string_view support" << std::endl;
18+
std::string_view sv("key");
19+
if (root.isMember(sv)) {
20+
std::cout << root[sv].asString() << std::endl;
21+
}
22+
#else
23+
std::cout << "No string_view support" << std::endl;
24+
if (root.isMember("key")) {
25+
std::cout << root["key"].asString() << std::endl;
26+
}
27+
#endif
28+
return EXIT_SUCCESS;
29+
}

0 commit comments

Comments
 (0)