Skip to content

Commit b75fa82

Browse files
committed
Rebuild C++ client when ABI changes
1 parent dafbbf9 commit b75fa82

2 files changed

Lines changed: 58 additions & 23 deletions

File tree

.github/scripts/package-client-cpp-manylinux-glibc217.sh

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,32 @@ fi
8585
cmake --version
8686
java -version
8787

88+
check_cxx11_abi_link() {
89+
local sdk_root="$1"
90+
local smoke_dir="$2"
91+
rm -rf "${smoke_dir}"
92+
mkdir -p "${smoke_dir}"
93+
cat > "${smoke_dir}/main.cpp" <<'EOF'
94+
#include "Session.h"
95+
96+
#include <string>
97+
98+
int main() {
99+
Session session(std::string("127.0.0.1"), 6667, std::string("root"), std::string("root"));
100+
session.setDatabase(std::string("root.test"));
101+
return 0;
102+
}
103+
EOF
104+
105+
c++ -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=1 \
106+
-I"${sdk_root}/include" \
107+
"${smoke_dir}/main.cpp" \
108+
-L"${sdk_root}/lib" \
109+
-Wl,-rpath,"${sdk_root}/lib" \
110+
-liotdb_session -pthread \
111+
-o "${smoke_dir}/abi-smoke"
112+
}
113+
88114
cd "${GITHUB_WORKSPACE:?GITHUB_WORKSPACE is not set}"
89115
./mvnw clean package -P with-cpp -pl iotdb-client/client-cpp -am -DskipTests \
90116
-Dspotless.skip=true \
@@ -123,32 +149,11 @@ else
123149
echo "No std::__cxx11 symbols found in the dynamic symbol table; verifying by link test."
124150
fi
125151

126-
ABI_SMOKE="/tmp/client-cpp-abi-smoke-glibc217"
127-
rm -rf "${ABI_SMOKE}"
128-
mkdir -p "${ABI_SMOKE}"
129-
cat > "${ABI_SMOKE}/main.cpp" <<'EOF'
130-
#include "Session.h"
131-
132-
#include <string>
133-
134-
int main() {
135-
Session session(std::string("127.0.0.1"), 6667, std::string("root"), std::string("root"));
136-
session.setDatabase(std::string("root.test"));
137-
return 0;
138-
}
139-
EOF
140-
141-
if ! c++ -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=1 \
142-
-I"iotdb-client/client-cpp/target/install/include" \
143-
"${ABI_SMOKE}/main.cpp" \
144-
-L"iotdb-client/client-cpp/target/install/lib" \
145-
-Wl,-rpath,"${GITHUB_WORKSPACE}/iotdb-client/client-cpp/target/install/lib" \
146-
-liotdb_session -pthread \
147-
-o "${ABI_SMOKE}/abi-smoke"; then
152+
if ! check_cxx11_abi_link "iotdb-client/client-cpp/target/install" "/tmp/client-cpp-abi-smoke-glibc217-install"; then
148153
echo "ERROR: libiotdb_session.so is not link-compatible with _GLIBCXX_USE_CXX11_ABI=1"
149154
exit 1
150155
fi
151-
echo "CXX11 ABI link check passed"
156+
echo "CXX11 ABI link check passed for target/install"
152157

153158
echo "=== Example package build/link/run smoke test ==="
154159
PKG_ZIP=$(find "${GITHUB_WORKSPACE}/iotdb-client/client-cpp/target" -maxdepth 1 -type f -name "iotdb-session-cpp-*-${PACKAGE_CLASSIFIER}.zip" -print -quit)
@@ -165,6 +170,11 @@ if [[ -z "${PKG_ROOT}" ]]; then
165170
echo "ERROR: could not find unpacked package directory for ${PACKAGE_CLASSIFIER}"
166171
exit 1
167172
fi
173+
if ! check_cxx11_abi_link "${PKG_ROOT}" "/tmp/client-cpp-abi-smoke-glibc217-package"; then
174+
echo "ERROR: packaged libiotdb_session.so is not link-compatible with _GLIBCXX_USE_CXX11_ABI=1"
175+
exit 1
176+
fi
177+
echo "CXX11 ABI link check passed for packaged SDK"
168178
EXAMPLE_BUILD="/tmp/client-cpp-example-smoke-glibc217"
169179
rm -rf "${EXAMPLE_BUILD}"
170180
mkdir -p "${EXAMPLE_BUILD}"

iotdb-client/client-cpp/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,31 @@ endif()
5252
if(IOTDB_USE_CXX11_ABI AND NOT IOTDB_USE_CXX11_ABI MATCHES "^[01]$")
5353
message(FATAL_ERROR "IOTDB_USE_CXX11_ABI must be empty, 0, or 1")
5454
endif()
55+
if(NOT MSVC)
56+
if(IOTDB_USE_CXX11_ABI)
57+
set(_iotdb_cxx11_abi_stamp_value "${IOTDB_USE_CXX11_ABI}")
58+
add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=${IOTDB_USE_CXX11_ABI})
59+
else()
60+
set(_iotdb_cxx11_abi_stamp_value "default")
61+
endif()
62+
set(_iotdb_cxx11_abi_stamp "${CMAKE_BINARY_DIR}/.iotdb-cxx11-abi")
63+
if(EXISTS "${_iotdb_cxx11_abi_stamp}")
64+
file(READ "${_iotdb_cxx11_abi_stamp}" _iotdb_previous_cxx11_abi)
65+
else()
66+
set(_iotdb_previous_cxx11_abi "")
67+
endif()
68+
if(NOT _iotdb_previous_cxx11_abi STREQUAL _iotdb_cxx11_abi_stamp_value)
69+
message(STATUS
70+
"IOTDB_USE_CXX11_ABI changed from '${_iotdb_previous_cxx11_abi}' "
71+
"to '${_iotdb_cxx11_abi_stamp_value}'; removing cached iotdb_session objects")
72+
file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/CMakeFiles/iotdb_session.dir")
73+
file(GLOB _iotdb_stale_session_libs "${CMAKE_BINARY_DIR}/libiotdb_session.so*")
74+
if(_iotdb_stale_session_libs)
75+
file(REMOVE ${_iotdb_stale_session_libs})
76+
endif()
77+
endif()
78+
file(WRITE "${_iotdb_cxx11_abi_stamp}" "${_iotdb_cxx11_abi_stamp_value}")
79+
endif()
5580

5681
option(WITH_SSL "Build with OpenSSL support" OFF)
5782
option(BUILD_TESTING "Build IT test executables" OFF)

0 commit comments

Comments
 (0)