Skip to content

Commit 1451029

Browse files
committed
chore: Add strict-abi support for macOS/iOS.
Also enable it for all binary deployment builds. This avoids exporting sodium/vpx/opus symbols through the toxcore library, which way conflict with other exported symbols if client code links to e.g. libsodium itself for its own purposes.
1 parent c53c30e commit 1451029

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-13
lines changed

cmake/StrictAbi.cmake

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ endmacro()
2020
function(_make_version_script target)
2121
set(${target}_VERSION_SCRIPT "${CMAKE_BINARY_DIR}/${target}.ld")
2222

23-
file(WRITE ${${target}_VERSION_SCRIPT}
24-
"{ global:\n")
23+
if(NOT APPLE)
24+
file(WRITE ${${target}_VERSION_SCRIPT}
25+
"{ global:\n")
26+
endif()
2527

2628
foreach(sublib ${ARGN})
2729
string(REPLACE "^" ";" sublib ${sublib})
@@ -38,21 +40,34 @@ function(_make_version_script target)
3840
string(REPLACE "\n" ";" sublib_SYMS ${sublib_SYMS})
3941

4042
foreach(sym ${sublib_SYMS})
41-
file(APPEND ${${target}_VERSION_SCRIPT}
42-
"${sym};\n")
43+
if(APPLE)
44+
file(APPEND ${${target}_VERSION_SCRIPT} "_")
45+
endif()
46+
file(APPEND ${${target}_VERSION_SCRIPT} "${sym}")
47+
if(NOT APPLE)
48+
file(APPEND ${${target}_VERSION_SCRIPT} ";")
49+
endif()
50+
file(APPEND ${${target}_VERSION_SCRIPT} "\n")
4351
endforeach(sym)
4452
endforeach(sublib)
4553

46-
file(APPEND ${${target}_VERSION_SCRIPT}
47-
"local: *; };\n")
54+
if(NOT APPLE)
55+
file(APPEND ${${target}_VERSION_SCRIPT}
56+
"local: *; };\n")
57+
endif()
4858

49-
set_target_properties(${target}_shared PROPERTIES
50-
LINK_FLAGS -Wl,--version-script,${${target}_VERSION_SCRIPT})
59+
if(APPLE)
60+
set_target_properties(${target}_shared PROPERTIES
61+
LINK_FLAGS -Wl,-exported_symbols_list,${${target}_VERSION_SCRIPT})
62+
else()
63+
set_target_properties(${target}_shared PROPERTIES
64+
LINK_FLAGS -Wl,--version-script,${${target}_VERSION_SCRIPT})
65+
endif()
5166
endfunction()
5267

5368
option(STRICT_ABI "Enforce strict ABI export in dynamic libraries" OFF)
54-
if((WIN32 AND NOT MINGW) OR APPLE)
55-
# Windows and macOS don't have this linker functionality.
69+
if(WIN32 AND NOT MINGW)
70+
# Windows doesn't have this linker functionality.
5671
set(STRICT_ABI OFF)
5772
endif()
5873

other/deploy/android.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ cmake -B _build -G Ninja \
9595
-DDHT_BOOTSTRAP=OFF \
9696
-DBOOTSTRAP_DAEMON=OFF \
9797
-DUNITTEST=OFF \
98+
-DSTRICT_ABI=ON \
9899
-DMIN_LOGGER_LEVEL=TRACE \
99100
-DEXPERIMENTAL_API=ON
100101
cmake --build _build

other/deploy/ios.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ cmake \
4444
-DDHT_BOOTSTRAP=OFF \
4545
-DBOOTSTRAP_DAEMON=OFF \
4646
-DUNITTEST=OFF \
47+
-DSTRICT_ABI=ON \
4748
-DMIN_LOGGER_LEVEL=TRACE \
4849
-DEXPERIMENTAL_API=ON \
4950
-DCMAKE_C_FLAGS="$IOS_FLAGS" \

other/deploy/linux.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ cmake \
2121
-DDHT_BOOTSTRAP=OFF \
2222
-DBOOTSTRAP_DAEMON=OFF \
2323
-DUNITTEST=OFF \
24+
-DSTRICT_ABI=ON \
2425
-DMIN_LOGGER_LEVEL=TRACE \
2526
-DEXPERIMENTAL_API=ON
2627

other/deploy/macos.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ ARCH="$1"
1313

1414
export PKG_CONFIG_PATH="$PWD/deps-prefix-macos-$ARCH/lib/pkgconfig"
1515

16+
BUILD_DIR="_build-macos-$ARCH"
17+
1618
# Build for macOS
1719
cmake \
18-
-B _build \
20+
-B "$BUILD_DIR" \
1921
-G Ninja \
2022
-DCMAKE_INSTALL_PREFIX="$PWD/toxcore-macos-$ARCH" \
2123
-DCMAKE_BUILD_TYPE=Release \
@@ -25,9 +27,10 @@ cmake \
2527
-DDHT_BOOTSTRAP=OFF \
2628
-DBOOTSTRAP_DAEMON=OFF \
2729
-DUNITTEST=OFF \
30+
-DSTRICT_ABI=ON \
2831
-DMIN_LOGGER_LEVEL=TRACE \
2932
-DEXPERIMENTAL_API=ON \
3033
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.15
3134

32-
cmake --build _build
33-
cmake --install _build
35+
cmake --build "$BUILD_DIR"
36+
cmake --install "$BUILD_DIR"

0 commit comments

Comments
 (0)