From 1bd86828556b4d124e4a924ec0812530a10a3535 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Mon, 13 Jul 2026 18:14:09 -0600 Subject: [PATCH] Mods: Curate exports and generate link stubs `symgen exports` replaces -export_dynamic on Apple and curates Android's dynamic symbols with a version script. `symgen stub` then emits sdk/stub-{macos,ios,tvos}-, sdk/stub-android-.so, and sdk/windows-.lib. --- CMakeLists.txt | 9 ++++++--- cmake/AndroidExports.cmake | 10 ++-------- cmake/AppleExports.cmake | 2 +- cmake/SymbolManifest.cmake | 2 +- cmake/WindowsExports.cmake | 8 +++----- 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0f80651ac..bf35cb2e45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -491,9 +491,12 @@ if (WIN32) target_link_libraries(dusklight PRIVATE Psapi) endif () if (APPLE) - # Mods resolve game symbols from the executable at dlopen time. - target_link_options(dusklight PRIVATE -Wl,-export_dynamic) -elseif (UNIX AND NOT ANDROID) + include(cmake/AppleExports.cmake) + setup_apple_exports(dusklight) +elseif (ANDROID) + include(cmake/AndroidExports.cmake) + setup_android_exports(dusklight) +elseif (UNIX) target_link_options(dusklight PRIVATE -rdynamic) endif () diff --git a/cmake/AndroidExports.cmake b/cmake/AndroidExports.cmake index 6bc94b61dc..23e14898e0 100644 --- a/cmake/AndroidExports.cmake +++ b/cmake/AndroidExports.cmake @@ -36,7 +36,7 @@ function(setup_android_exports target) # TODO: src/dusk/ is NOT excluded: inline code in game headers # currently call into it (e.g. dusk::frame_interp::lookup_replacement). COMMAND "${SYMGEN_EXE}" exports - --rsp "${_rsp}" + "@${_rsp}" --out "${_vscript}" --format version-script --exclude cmake_pch @@ -53,16 +53,10 @@ function(setup_android_exports target) target_link_options(${target} PRIVATE "-Wl,--version-script=${_vscript}") string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" _arch) - if (_arch STREQUAL "aarch64") - set(_machine "arm64") - else () - set(_machine "amd64") - endif () - set(_stub "${CMAKE_BINARY_DIR}/stub-android-${_arch}.so") add_custom_command(TARGET ${target} POST_BUILD COMMAND "${SYMGEN_EXE}" stub -f elf "$" -o "${_stub}" - --soname "$" --machine "${_machine}" + --soname "$" --arch "${_arch}" BYPRODUCTS "${_stub}" COMMENT "Generating dusklight link stub" VERBATIM) diff --git a/cmake/AppleExports.cmake b/cmake/AppleExports.cmake index 47f45a9718..0b43fdb6ee 100644 --- a/cmake/AppleExports.cmake +++ b/cmake/AppleExports.cmake @@ -44,7 +44,7 @@ function(setup_apple_exports target) # TODO: src/dusk/ is NOT excluded: inline code in game headers # currently call into it (e.g. dusk::frame_interp::lookup_replacement). COMMAND "${_symgen}" exports - --rsp "${_rsp}" + "@${_rsp}" --out "${_exp}" --exclude cmake_pch --exclude miniz diff --git a/cmake/SymbolManifest.cmake b/cmake/SymbolManifest.cmake index 927040a47f..6d9b86de19 100644 --- a/cmake/SymbolManifest.cmake +++ b/cmake/SymbolManifest.cmake @@ -2,7 +2,7 @@ include_guard(GLOBAL) get_filename_component(_SYMBOL_MANIFEST_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY) -set(_SYMGEN_VERSION "1.1.1") +set(_SYMGEN_VERSION "1.2.0") set(_SYMGEN_RELEASE_BASE_URL "https://github.com/encounter/symgen/releases/download/v${_SYMGEN_VERSION}") set(SYMGEN_PATH "" CACHE FILEPATH "Path to a symgen executable; empty downloads the pinned release") mark_as_advanced(SYMGEN_PATH) diff --git a/cmake/WindowsExports.cmake b/cmake/WindowsExports.cmake index 3010c82f25..e9cea7074e 100644 --- a/cmake/WindowsExports.cmake +++ b/cmake/WindowsExports.cmake @@ -53,7 +53,7 @@ function(setup_windows_exports target) # TODO: src/dusk/ is NOT excluded: inline code in game headers # currently call into it (e.g. dusk::frame_interp::lookup_replacement). COMMAND "${_symgen}" def - --rsp "${_rsp}" + "@${_rsp}" --out "${_def}" --exclude cmake_pch --exclude miniz @@ -82,9 +82,7 @@ function(setup_windows_exports target) COMMENT "Generating dusklight import library" VERBATIM) set(DUSK_GAME_IMPLIB "${_implib}" CACHE INTERNAL "Import library for Windows mod linking") - set(DUSK_GAME_DEF "${_def}" CACHE INTERNAL "Curated export .def for the game executable") - # Ship the import library as sdk/dusklight.lib in the install tree: mods may use it to - # compile against Dusklight without having to build the whole game. (See DUSK_GAME_IMPLIB) - install(FILES "${_implib}" DESTINATION sdk RENAME dusklight.lib) + string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" _implib_arch) + install(FILES "${_implib}" DESTINATION sdk RENAME "windows-${_implib_arch}.lib") endfunction()