Skip to content

Commit

Permalink
chore: Add strict-abi support for macOS/iOS.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
iphydf committed Feb 9, 2025
1 parent c53c30e commit 1451029
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
35 changes: 25 additions & 10 deletions cmake/StrictAbi.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ endmacro()
function(_make_version_script target)
set(${target}_VERSION_SCRIPT "${CMAKE_BINARY_DIR}/${target}.ld")

file(WRITE ${${target}_VERSION_SCRIPT}
"{ global:\n")
if(NOT APPLE)
file(WRITE ${${target}_VERSION_SCRIPT}
"{ global:\n")
endif()

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

foreach(sym ${sublib_SYMS})
file(APPEND ${${target}_VERSION_SCRIPT}
"${sym};\n")
if(APPLE)
file(APPEND ${${target}_VERSION_SCRIPT} "_")
endif()
file(APPEND ${${target}_VERSION_SCRIPT} "${sym}")
if(NOT APPLE)
file(APPEND ${${target}_VERSION_SCRIPT} ";")
endif()
file(APPEND ${${target}_VERSION_SCRIPT} "\n")
endforeach(sym)
endforeach(sublib)

file(APPEND ${${target}_VERSION_SCRIPT}
"local: *; };\n")
if(NOT APPLE)
file(APPEND ${${target}_VERSION_SCRIPT}
"local: *; };\n")
endif()

set_target_properties(${target}_shared PROPERTIES
LINK_FLAGS -Wl,--version-script,${${target}_VERSION_SCRIPT})
if(APPLE)
set_target_properties(${target}_shared PROPERTIES
LINK_FLAGS -Wl,-exported_symbols_list,${${target}_VERSION_SCRIPT})
else()
set_target_properties(${target}_shared PROPERTIES
LINK_FLAGS -Wl,--version-script,${${target}_VERSION_SCRIPT})
endif()
endfunction()

option(STRICT_ABI "Enforce strict ABI export in dynamic libraries" OFF)
if((WIN32 AND NOT MINGW) OR APPLE)
# Windows and macOS don't have this linker functionality.
if(WIN32 AND NOT MINGW)
# Windows doesn't have this linker functionality.
set(STRICT_ABI OFF)
endif()

Expand Down
1 change: 1 addition & 0 deletions other/deploy/android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ cmake -B _build -G Ninja \
-DDHT_BOOTSTRAP=OFF \
-DBOOTSTRAP_DAEMON=OFF \
-DUNITTEST=OFF \
-DSTRICT_ABI=ON \
-DMIN_LOGGER_LEVEL=TRACE \
-DEXPERIMENTAL_API=ON
cmake --build _build
Expand Down
1 change: 1 addition & 0 deletions other/deploy/ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ cmake \
-DDHT_BOOTSTRAP=OFF \
-DBOOTSTRAP_DAEMON=OFF \
-DUNITTEST=OFF \
-DSTRICT_ABI=ON \
-DMIN_LOGGER_LEVEL=TRACE \
-DEXPERIMENTAL_API=ON \
-DCMAKE_C_FLAGS="$IOS_FLAGS" \
Expand Down
1 change: 1 addition & 0 deletions other/deploy/linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cmake \
-DDHT_BOOTSTRAP=OFF \
-DBOOTSTRAP_DAEMON=OFF \
-DUNITTEST=OFF \
-DSTRICT_ABI=ON \
-DMIN_LOGGER_LEVEL=TRACE \
-DEXPERIMENTAL_API=ON

Expand Down
9 changes: 6 additions & 3 deletions other/deploy/macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ ARCH="$1"

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

BUILD_DIR="_build-macos-$ARCH"

# Build for macOS
cmake \
-B _build \
-B "$BUILD_DIR" \
-G Ninja \
-DCMAKE_INSTALL_PREFIX="$PWD/toxcore-macos-$ARCH" \
-DCMAKE_BUILD_TYPE=Release \
Expand All @@ -25,9 +27,10 @@ cmake \
-DDHT_BOOTSTRAP=OFF \
-DBOOTSTRAP_DAEMON=OFF \
-DUNITTEST=OFF \
-DSTRICT_ABI=ON \
-DMIN_LOGGER_LEVEL=TRACE \
-DEXPERIMENTAL_API=ON \
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.15

cmake --build _build
cmake --install _build
cmake --build "$BUILD_DIR"
cmake --install "$BUILD_DIR"

0 comments on commit 1451029

Please sign in to comment.