From ecc4955dee90069636b8da43dfc563b540ad98e6 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 01:16:29 +0200 Subject: [PATCH 01/61] external_deps: make possible to reconfigure for a different target --- external_deps/build.sh | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index eabe39a278..b019a5cee7 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -1325,23 +1325,34 @@ common_setup() { common_setup_arch EXE_EXT="${EXE_EXT:-}" - DOWNLOAD_DIR="${WORK_DIR}/download_cache" - PKG_BASEDIR="${PLATFORM}_${DEPS_VERSION}" - PKG_TARBALL="${PKG_BASEDIR}.tar.xz" - BUILD_BASEDIR="build-${PKG_BASEDIR}" - BUILD_DIR="${WORK_DIR}/${BUILD_BASEDIR}" - PREFIX="${BUILD_DIR}/prefix" - PATH="${PREFIX}/bin:${PATH}" + + if "${GLOBAL_SETUP_ONCE:-true}" + then + DOWNLOAD_DIR="${WORK_DIR}/download_cache" + PKG_BASEDIR="${PLATFORM}_${DEPS_VERSION}" + PKG_TARBALL="${PKG_BASEDIR}.tar.xz" + BUILD_BASEDIR="build-${PKG_BASEDIR}" + BUILD_DIR="${WORK_DIR}/${BUILD_BASEDIR}" + PREFIX="${BUILD_DIR}/prefix" + PATH="${PREFIX}/bin:${PATH}" + + mkdir -p "${DOWNLOAD_DIR}" + mkdir -p "${PREFIX}/bin" + mkdir -p "${PREFIX}/include" + mkdir -p "${PREFIX}/lib" + + export PATH + + GLOBAL_SETUP_ONCE='false' + fi + PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig:${CROSS_PKG_CONFIG_PATH}" CPPFLAGS+=" -I${PREFIX}/include" LDFLAGS+=" -L${PREFIX}/lib" - mkdir -p "${DOWNLOAD_DIR}" - mkdir -p "${PREFIX}/bin" - mkdir -p "${PREFIX}/include" - mkdir -p "${PREFIX}/lib" - - export CC CXX LD AR RANLIB STRIP PKG_CONFIG PKG_CONFIG_PATH PATH CFLAGS CXXFLAGS CPPFLAGS LDFLAGS + export PKG_CONFIG PKG_CONFIG_PATH + export CC CXX LD AR RANLIB STRIP + export CPPFLAGS CFLAGS CXXFLAGS LDFLAGS } common_setup_arch() { From 392d4afa5490dd16d9520c01cf72f42b83a1ad62 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 01:59:46 +0200 Subject: [PATCH 02/61] external_deps: make defaults resetable with setup_default() --- external_deps/build.sh | 64 +++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index b019a5cee7..4066cad2e8 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -64,26 +64,6 @@ NCURSES_VERSION=6.5 WASISDK_VERSION=16.0 WASMTIME_VERSION=2.0.2 -# Require the compiler names to be explicitly hardcoded, we should not inherit them -# from environment as we heavily cross-compile. -CC='false' -CXX='false' -# Set defaults. -LD='ld' -AR='ar' -RANLIB='ranlib' -PKG_CONFIG='pkg-config' -CROSS_PKG_CONFIG_PATH='' -LIBS_SHARED='OFF' -LIBS_STATIC='ON' -CMAKE_TOOLCHAIN='' -# Always reset flags, we heavily cross-compile and must not inherit any stray flag -# from environment. -CPPFLAGS='' -CFLAGS='-O3 -fPIC' -CXXFLAGS='-O3 -fPIC' -LDFLAGS='-O3 -fPIC' - log() { level="${1}"; shift printf '%s: %s\n' "${level}" "${@}" >&2 @@ -1324,8 +1304,6 @@ common_setup() { "common_setup_${1}" common_setup_arch - EXE_EXT="${EXE_EXT:-}" - if "${GLOBAL_SETUP_ONCE:-true}" then DOWNLOAD_DIR="${WORK_DIR}/download_cache" @@ -1431,8 +1409,42 @@ common_setup_linux() { CXXFLAGS+=' -fPIC' } +setup_default() { + # Require the compiler names to be explicitly hardcoded, we should not inherit them + # from environment as we heavily cross-compile. + export CC='false' + export CXX='false' + + # Set defaults. + export LD='ld' + export AR='ar' + export RANLIB='ranlib' + export STRIP='strip' + export PKG_CONFIG='pkg-config' + export CROSS_PKG_CONFIG_PATH='' + + LIBS_SHARED='OFF' + LIBS_STATIC='ON' + CMAKE_TOOLCHAIN='' + EXE_EXT='' + + # Always reset flags, we heavily cross-compile and must not inherit any stray flag + # from environment. + export CPPFLAGS='' + export CFLAGS='-O3 -fPIC' + export CXXFLAGS='-O3 -fPIC' + export LDFLAGS='-O3 -fPIC' + + unset BITNESS + unset MACOS_ARCH + unset CMAKE_OSX_ARCHITECTURES + unset CROSS_PKG_CONFIG_PATH + unset MACOSX_DEPLOYMENT_TARGET +} + # Set up environment for 32-bit i686 Windows for Visual Studio (compile all as .dll) setup_windows-i686-msvc() { + setup_default BITNESS=32 CFLAGS+=' -mpreferred-stack-boundary=2' CXXFLAGS+=' -mpreferred-stack-boundary=2' @@ -1441,24 +1453,28 @@ setup_windows-i686-msvc() { # Set up environment for 64-bit amd64 Windows for Visual Studio (compile all as .dll) setup_windows-amd64-msvc() { + setup_default BITNESS=64 common_setup msvc x86_64-w64-mingw32 } # Set up environment for 32-bit i686 Windows for MinGW (compile all as .a) setup_windows-i686-mingw() { + setup_default BITNESS=32 common_setup mingw i686-w64-mingw32 } # Set up environment for 64-bit amd64 Windows for MinGW (compile all as .a) setup_windows-amd64-mingw() { + setup_default BITNESS=64 common_setup mingw x86_64-w64-mingw32 } # Set up environment for 64-bit amd64 macOS setup_macos-amd64-default() { + setup_default MACOS_ARCH=x86_64 # OpenAL requires 10.14. export MACOSX_DEPLOYMENT_TARGET=10.14 # works with CMake @@ -1467,21 +1483,25 @@ setup_macos-amd64-default() { # Set up environment for 32-bit i686 Linux setup_linux-i686-default() { + setup_default common_setup linux i686-unknown-linux-gnu } # Set up environment for 64-bit amd64 Linux setup_linux-amd64-default() { + setup_default common_setup linux x86_64-unknown-linux-gnu } # Set up environment for 32-bit little-endian hard-float arm Linux setup_linux-armhf-default() { + setup_default common_setup linux arm-unknown-linux-gnueabihf } # Set up environment for 64-bit little-endian arm Linux setup_linux-arm64-default() { + setup_default common_setup linux aarch64-unknown-linux-gnu } From 8676ef9fddbf42875c0d27a0e1fe57f10d839e83 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 01:48:05 +0200 Subject: [PATCH 03/61] external_deps: extract platform components --- external_deps/build.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/external_deps/build.sh b/external_deps/build.sh index 4066cad2e8..a4444e8c88 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -1304,6 +1304,11 @@ common_setup() { "common_setup_${1}" common_setup_arch + PLATFORM_SYSTEM="$(echo "${PLATFORM}" | cut -f1 -d-)" + PLATFORM_ARCH="$(echo "${PLATFORM}" | cut -f2 -d-)" + PLATFORM_COMPILER="$(echo "${PLATFORM}" | cut -f3 -d-)" + PLATFORM_TARGET="${PLATFORM_SYSTEM}-${PLATFORM_ARCH}" + if "${GLOBAL_SETUP_ONCE:-true}" then DOWNLOAD_DIR="${WORK_DIR}/download_cache" From b010dfe0a1053be096f79d095c91e3547da688a6 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 08:31:21 +0200 Subject: [PATCH 04/61] external_deps: provide a reusable framework for building native tools needed for cross-compilation --- external_deps/build.sh | 71 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 10 deletions(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index a4444e8c88..f67c6c7cec 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -163,6 +163,18 @@ download_extract() { configure_build() { local configure_args=() + case "${HOST}" in + native) + configure_args+=(--prefix="${NATIVE_PREFIX}") + configure_args+=(--libdir="${NATIVE_PREFIX}/lib") + ;; + *) + configure_args+=(--host="${HOST}") + configure_args+=(--prefix="${PREFIX}") + configure_args+=(--libdir="${PREFIX}/lib") + ;; + esac + if [ "${LIBS_SHARED}" = 'ON' ] then configure_args+=(--enable-shared) @@ -184,9 +196,6 @@ configure_build() { fi ./configure \ - --host="${HOST}" \ - --prefix="${PREFIX}" \ - --libdir="${PREFIX}/lib" \ "${configure_args[@]}" make @@ -210,6 +219,17 @@ get_compiler_arg1() { cmake_build() { local cmake_args=() + case "${HOST}" in + native) + cmake_args+=(-DCMAKE_PREFIX_PATH="${NATIVE_PREFIX}") + cmake_args+=(-DCMAKE_INSTALL_PREFIX="${NATIVE_PREFIX}") + ;; + *) + cmake_args+=(-DCMAKE_PREFIX_PATH="${PREFIX}") + cmake_args+=(-DCMAKE_INSTALL_PREFIX="${PREFIX}") + ;; + esac + cmake_args+=(-DCMAKE_C_COMPILER="$(get_compiler_name ${CC})") cmake_args+=(-DCMAKE_CXX_COMPILER="$(get_compiler_name ${CXX})") cmake_args+=(-DCMAKE_C_COMPILER_ARG1="$(get_compiler_arg1 ${CC})") @@ -229,8 +249,6 @@ cmake_build() { cmake -S . -B build \ -DCMAKE_TOOLCHAIN_FILE="${CMAKE_TOOLCHAIN}" \ -DCMAKE_BUILD_TYPE='Release' \ - -DCMAKE_PREFIX_PATH="${PREFIX}" \ - -DCMAKE_INSTALL_PREFIX="${PREFIX}" \ -DBUILD_SHARED_LIBS="${LIBS_SHARED}" \ "${cmake_args[@]}" @@ -238,7 +256,6 @@ cmake_build() { cmake --install build --strip } -# Build pkg-config, needed for opusfile. # As a host-mode dependency it must be provided by the system when cross-compiling. build_pkgconfig() { local dir_name="pkg-config-${PKGCONFIG_VERSION}" @@ -1317,14 +1334,17 @@ common_setup() { BUILD_BASEDIR="build-${PKG_BASEDIR}" BUILD_DIR="${WORK_DIR}/${BUILD_BASEDIR}" PREFIX="${BUILD_DIR}/prefix" - PATH="${PREFIX}/bin:${PATH}" + NATIVE_PREFIX="${BUILD_DIR}/native-prefix" mkdir -p "${DOWNLOAD_DIR}" mkdir -p "${PREFIX}/bin" mkdir -p "${PREFIX}/include" mkdir -p "${PREFIX}/lib" + mkdir -p "${NATIVE_PREFIX}/bin" + mkdir -p "${NATIVE_PREFIX}/include" + mkdir -p "${NATIVE_PREFIX}/lib" - export PATH + PATH="${NATIVE_PREFIX}/bin:${PATH}" GLOBAL_SETUP_ONCE='false' fi @@ -1333,6 +1353,7 @@ common_setup() { CPPFLAGS+=" -I${PREFIX}/include" LDFLAGS+=" -L${PREFIX}/lib" + export PATH export PKG_CONFIG PKG_CONFIG_PATH export CC CXX LD AR RANLIB STRIP export CPPFLAGS CFLAGS CXXFLAGS LDFLAGS @@ -1356,6 +1377,8 @@ common_setup_arch() { CFLAGS+=' -march=armv7-a -mfpu=neon' CXXFLAGS+=' -march=armv7-a -mfpu=neon' ;; + *-native-*) + ;; *) log ERROR 'Unsupported platform' ;; @@ -1414,6 +1437,14 @@ common_setup_linux() { CXXFLAGS+=' -fPIC' } +common_setup_native() { + case "$(uname -s)" in + CYGWIN_NT-*|MSYS_NT-*|MINGW*_NT-*) + EXE_EXT='.exe' + ;; + esac +} + setup_default() { # Require the compiler names to be explicitly hardcoded, we should not inherit them # from environment as we heavily cross-compile. @@ -1443,7 +1474,6 @@ setup_default() { unset BITNESS unset MACOS_ARCH unset CMAKE_OSX_ARCHITECTURES - unset CROSS_PKG_CONFIG_PATH unset MACOSX_DEPLOYMENT_TARGET } @@ -1510,6 +1540,27 @@ setup_linux-arm64-default() { common_setup linux aarch64-unknown-linux-gnu } +# Set up environment for native host tools +setup_native() { + setup_default + CC='cc' + CXX='c++' + common_setup native native +} + +setup_platform() { + case "${1}" in + native) + export PLATFORM='native-native-native' + setup_native + ;; + *) + export PLATFORM="${1}" + "setup_${PLATFORM}" + ;; + esac +} + base_windows_amd64_msvc_packages='zlib gmp nettle curl sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk depcheck genlib' all_windows_amd64_msvc_packages="${base_windows_amd64_msvc_packages}" @@ -1697,6 +1748,6 @@ esac for PLATFORM in ${platform_list} do ( - "setup_${PLATFORM}" + setup_platform "${PLATFORM}" build "${@}" ) done From 426db9613f04d853c4cb24a851091536ee3e94fa Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 08:49:11 +0200 Subject: [PATCH 05/61] external_deps: build pkg-config as a native tool --- external_deps/build.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index f67c6c7cec..0932103bdb 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -256,26 +256,26 @@ cmake_build() { cmake --install build --strip } -# As a host-mode dependency it must be provided by the system when cross-compiling. -build_pkgconfig() { +# Build pkg-config, needed for opusfile on macos. +# It is part of the cross-compilation toolchain. +# As a host-mode native dependency it must be provided by the system when cross-compiling. +build_native-pkgconfig() { local dir_name="pkg-config-${PKGCONFIG_VERSION}" local archive_name="${dir_name}.tar.gz" - download_extract pkgconfig "${archive_name}" \ + download_extract native-pkgconfig "${archive_name}" \ "${PKGCONFIG_BASEURL}/${archive_name}" "${download_only}" && return cd "${dir_name}" - # Reset the environment variables, we don't cross-compile this, - # it is part of the cross-compilation toolchain. - # CXXFLAGS is unused. - CFLAGS='-Wno-error=int-conversion' \ - LDFLAGS='' \ - HOST='' \ - configure_build \ + ( + setup_platform 'native' + CFLAGS='-Wno-error=int-conversion' \ + configure_build \ --with-internal-glib + ) } # Build NASM @@ -1573,7 +1573,7 @@ all_windows_amd64_mingw_packages="${base_windows_amd64_mingw_packages}" base_windows_i686_mingw_packages="${base_windows_amd64_mingw_packages}" all_windows_i686_mingw_packages="${base_windows_amd64_mingw_packages}" -base_macos_amd64_default_packages='pkgconfig nasm gmp nettle sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk' +base_macos_amd64_default_packages='native-pkgconfig nasm gmp nettle sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk' all_macos_amd64_default_packages="${base_macos_amd64_default_packages}" base_linux_i686_default_packages='sdl3 naclsdk' @@ -1614,7 +1614,7 @@ printHelp() { all linux windows macos Packages: - pkgconfig nasm zlib gmp nettle curl sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk wasisdk wasmtime + native-pkgconfig nasm zlib gmp nettle curl sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk wasisdk wasmtime Virtual packages: base build packages for pre-built binaries to be downloaded when building the game From 1b90d307293aa4c388f337649d1d00ac0375691b Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 09:05:48 +0200 Subject: [PATCH 06/61] external_deps: build nasm as a native tool --- external_deps/build.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index 0932103bdb..84a21166ec 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -278,19 +278,21 @@ build_native-pkgconfig() { ) } -# Build NASM -build_nasm() { +# Build NASM, needed for jpeg on macos-amd64. +# It is part of the compilation toolchain. +# As a host-mode native dependency it must be provided by the system when compiling. +build_native-nasm() { case "${PLATFORM}" in macos-*-*) local dir_name="nasm-${NASM_VERSION}" local archive_name="${dir_name}-macosx.zip" - download_extract nasm "${archive_name}" \ + download_extract native-nasm "${archive_name}" \ "${NASM_BASEURL}/${NASM_VERSION}/macosx/${archive_name}" "${download_only}" && return - smart_copy "${dir_name}/nasm" "${PREFIX}/bin" + smart_copy "${dir_name}/nasm" "${NATIVE_PREFIX}/bin" ;; *) log ERROR 'Unsupported platform for NASM' @@ -1573,7 +1575,7 @@ all_windows_amd64_mingw_packages="${base_windows_amd64_mingw_packages}" base_windows_i686_mingw_packages="${base_windows_amd64_mingw_packages}" all_windows_i686_mingw_packages="${base_windows_amd64_mingw_packages}" -base_macos_amd64_default_packages='native-pkgconfig nasm gmp nettle sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk' +base_macos_amd64_default_packages='native-pkgconfig native-nasm gmp nettle sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk' all_macos_amd64_default_packages="${base_macos_amd64_default_packages}" base_linux_i686_default_packages='sdl3 naclsdk' @@ -1614,7 +1616,7 @@ printHelp() { all linux windows macos Packages: - native-pkgconfig nasm zlib gmp nettle curl sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk wasisdk wasmtime + native-pkgconfig native-nasm zlib gmp nettle curl sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk wasisdk wasmtime Virtual packages: base build packages for pre-built binaries to be downloaded when building the game From 189f294388f63996bb6295cdf0a8ac17b402a7b8 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Wed, 8 Jul 2026 14:39:34 +0200 Subject: [PATCH 07/61] cmake: remove unused DaemonCBSE.cmake (already moved to the game) --- cmake/DaemonCBSE.cmake | 81 ------------------------------------------ 1 file changed, 81 deletions(-) delete mode 100644 cmake/DaemonCBSE.cmake diff --git a/cmake/DaemonCBSE.cmake b/cmake/DaemonCBSE.cmake deleted file mode 100644 index 63019ace38..0000000000 --- a/cmake/DaemonCBSE.cmake +++ /dev/null @@ -1,81 +0,0 @@ -# Daemon BSD Source Code -# Copyright (c) 2013-2016, Daemon Developers -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# * Neither the name of the Daemon developers nor the -# names of its contributors may be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY -# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -# Allow overriding the python path with a cached variable. -set(DAEMON_CBSE_PYTHON_PATH "NOTFOUND" CACHE FILEPATH "Python executable for CBSE code generation") -if (NOT DAEMON_CBSE_PYTHON_PATH OR NOT EXISTS ${DAEMON_CBSE_PYTHON_PATH}) - find_package(Python REQUIRED) - set(DAEMON_CBSE_PYTHON_PATH "${Python_EXECUTABLE}" CACHE FILEPATH "Python executable for CBSE code generation" FORCE) -endif() -message(STATUS "Using CBSE Python executable: ${DAEMON_CBSE_PYTHON_PATH}") - -function(maybe_add_dep target dep) - if (TARGET ${target}) - add_dependencies(${target} ${dep}) - endif() -endfunction() - -function(CBSE target definition output) - # Check if python has all the dependencies - # TODO: Execute pip directly here and install them - execute_process( - COMMAND ${DAEMON_CBSE_PYTHON_PATH} -c "import jinja2, yaml, collections, argparse, sys, os.path, re" - RESULT_VARIABLE RET) - if (NOT RET EQUAL 0) - message(FATAL_ERROR "Missing dependences for CBSE generation. Please ensure you have python with python-yaml and python-jinja installed. - Use pip install -r src/utils/cbse/requirements.txt to install") - endif() - set(GENERATED_CBSE ${output}/backend/CBSEBackend.cpp - ${output}/backend/CBSEBackend.h - ${output}/backend/CBSEComponents.h - ${output}/backend/CBSEEntities.h) - add_custom_command( - OUTPUT ${GENERATED_CBSE} - COMMENT "Generating CBSE entities for ${definition}" - DEPENDS ${definition} - ${CMAKE_SOURCE_DIR}/src/utils/cbse/CBSE.py - ${CMAKE_SOURCE_DIR}/src/utils/cbse/templates/Backend.cpp - ${CMAKE_SOURCE_DIR}/src/utils/cbse/templates/Backend.h - ${CMAKE_SOURCE_DIR}/src/utils/cbse/templates/Component.cpp - ${CMAKE_SOURCE_DIR}/src/utils/cbse/templates/Component.h - ${CMAKE_SOURCE_DIR}/src/utils/cbse/templates/Components.h - ${CMAKE_SOURCE_DIR}/src/utils/cbse/templates/Entities.h - ${CMAKE_SOURCE_DIR}/src/utils/cbse/templates/Helper.h - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/utils/cbse - COMMAND - ${DAEMON_CBSE_PYTHON_PATH} - ${CMAKE_SOURCE_DIR}/src/utils/cbse/CBSE.py - -s -o - "${output}" - "${definition}" - ) - string(REPLACE ${CMAKE_SOURCE_DIR}/ "" rel_path ${definition}) - string(REPLACE "/" "-" new_target ${rel_path}) - add_custom_target(${new_target} ALL - DEPENDS ${GENERATED_CBSE} - ) - set(${target}_GENERATED_CBSE ${GENERATED_CBSE} PARENT_SCOPE) -endfunction() From 4430d172c7e1ab785fcf48eb7591d3be8cd66a5b Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 4 Jul 2026 09:17:07 +0200 Subject: [PATCH 08/61] bikeshedding: whitespace --- external_deps/build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index 84a21166ec..8ee5454d54 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -647,7 +647,7 @@ build_jpeg() { jpeg_cmake_args+=(-DUNIX=True) ;; esac - + cd "${dir_name}" # -DHAVE_THREAD_LOCAL=0 overrides the compiler test to avoid the silly thread_local variable, @@ -1657,7 +1657,7 @@ printHelp() { all ${all_linux_arm64_default_packages} EOF - + exit } From 696ff482230578d64c3966e20e54757081e00a2a Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 7 Jul 2026 22:56:39 +0200 Subject: [PATCH 09/61] primitives: do not complain about FileHandle.mode being unused --- src/common/IPC/Primitives.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/common/IPC/Primitives.h b/src/common/IPC/Primitives.h index e5c2bcf02d..36d489da81 100644 --- a/src/common/IPC/Primitives.h +++ b/src/common/IPC/Primitives.h @@ -62,6 +62,9 @@ namespace IPC { static FileHandle FromDesc(const FileDesc& desc); int GetHandle() const { + // Do not complain about mode being unused. + Q_UNUSED(mode); + return handle; } From cbfb510843738d1915a62f3454d5ae9803aa62a1 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 03:13:19 +0200 Subject: [PATCH 10/61] Append the architecture name to loader binaries, implement box64 fallback, detect armhf multiarch support --- CMakeLists.txt | 71 +-- src/engine/framework/VirtualMachine.cpp | 491 +++++++++++++----- .../nacl_multiarch.cpp} | 20 +- 3 files changed, 408 insertions(+), 174 deletions(-) rename tools/{nacl_helper_bootstrap-armhf/nacl_helper_bootstrap-armhf.cpp => nacl_multiarch/nacl_multiarch.cpp} (84%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65ff1a430b..91a484f9d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -397,33 +397,33 @@ if (DEPS_DIR) if (NOT EXISTS ${DEPS_DIR}) file(MAKE_DIRECTORY ${EXTERNAL_DEPS_DIR}) get_filename_component(BASENAME ${DEPS_DIR} NAME) - set(DEPS_FILENAME "${BASENAME}${DEPS_EXT}") - - # Download test DEPS archive if DEPS archive isn't available yet. - # This makes possible to get the CI working before releasing the DEPS archive. - foreach(REMOTE_BASEURL https://dl.unvanquished.net/deps;https://dl.unvanquished.net/test/deps) - set(REMOTE "${REMOTE_BASEURL}/${DEPS_FILENAME}") - message(STATUS "Downloading dependencies from '${REMOTE}'") - - file(DOWNLOAD "${REMOTE}" "${OBJ_DIR}/${DEPS_FILENAME}" - SHOW_PROGRESS - STATUS DOWNLOAD_RESULT - LOG DOWNLOAD_LOG - ) - - list(GET DOWNLOAD_RESULT 0 DOWNLOAD_STATUS) - list(GET DOWNLOAD_RESULT 1 DOWNLOAD_STRING) - - if (DOWNLOAD_STATUS EQUAL 0) - break() - else () - message(WARNING "Error downloading '${REMOTE}': - Status code: ${DOWNLOAD_STATUS} - Error string: ${DOWNLOAD_STRING} - Download log: ${DOWNLOAD_LOG}" - ) - endif() - endforeach() + set(DEPS_FILENAME "${BASENAME}${DEPS_EXT}") + + # Download test DEPS archive if DEPS archive isn't available yet. + # This makes possible to get the CI working before releasing the DEPS archive. + foreach(REMOTE_BASEURL https://dl.unvanquished.net/deps;https://dl.unvanquished.net/test/deps) + set(REMOTE "${REMOTE_BASEURL}/${DEPS_FILENAME}") + message(STATUS "Downloading dependencies from '${REMOTE}'") + + file(DOWNLOAD "${REMOTE}" "${OBJ_DIR}/${DEPS_FILENAME}" + SHOW_PROGRESS + STATUS DOWNLOAD_RESULT + LOG DOWNLOAD_LOG + ) + + list(GET DOWNLOAD_RESULT 0 DOWNLOAD_STATUS) + list(GET DOWNLOAD_RESULT 1 DOWNLOAD_STRING) + + if (DOWNLOAD_STATUS EQUAL 0) + break() + else () + message(WARNING "Error downloading '${REMOTE}': + Status code: ${DOWNLOAD_STATUS} + Error string: ${DOWNLOAD_STRING} + Download log: ${DOWNLOAD_LOG}" + ) + endif() + endforeach() if (NOT DOWNLOAD_STATUS EQUAL 0) message(FATAL_ERROR "Failed to download '${DEPS_FILENAME}'") @@ -973,7 +973,7 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER add_custom_command(TARGET runtime_deps PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DEPS_DIR}/nacl_loader${CMAKE_EXECUTABLE_SUFFIX} - ${FULL_OUTPUT_DIR}/nacl_loader${CMAKE_EXECUTABLE_SUFFIX} + ${FULL_OUTPUT_DIR}/nacl_loader-${DAEMON_NACL_ARCH_NAME}${CMAKE_EXECUTABLE_SUFFIX} ) add_custom_command(TARGET runtime_deps PRE_BUILD @@ -985,25 +985,28 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER # Linux uses a bootstrap program to reserve address space if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY) if (YOKAI_TARGET_ARCH_ARM64) - add_executable(nacl_helper_bootstrap-armhf tools/nacl_helper_bootstrap-armhf/nacl_helper_bootstrap-armhf.cpp) - add_dependencies(runtime_deps nacl_helper_bootstrap-armhf) + add_executable(nacl_multiarch-${DAEMON_NACL_ARCH_NAME} + tools/nacl_multiarch/nacl_multiarch.cpp + ${BUILDINFOLIST} + ) + add_dependencies(runtime_deps nacl_multiarch-${DAEMON_NACL_ARCH_NAME}) add_custom_command(TARGET runtime_deps PRE_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory - ${FULL_OUTPUT_DIR}/lib-armhf + ${FULL_OUTPUT_DIR}/lib-${DAEMON_NACL_ARCH_NAME} ) add_custom_command(TARGET runtime_deps PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory - ${DEPS_DIR}/lib-armhf - ${FULL_OUTPUT_DIR}/lib-armhf + ${DEPS_DIR}/linux-${DAEMON_NACL_ARCH_NAME} + ${FULL_OUTPUT_DIR}/linux-${DAEMON_NACL_ARCH_NAME} ) endif() add_custom_command(TARGET runtime_deps PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DEPS_DIR}/nacl_helper_bootstrap - ${FULL_OUTPUT_DIR}/nacl_helper_bootstrap + ${FULL_OUTPUT_DIR}/nacl_helper_bootstrap-${DAEMON_NACL_ARCH_NAME} ) endif() diff --git a/src/engine/framework/VirtualMachine.cpp b/src/engine/framework/VirtualMachine.cpp index df2739b9f3..dec5dc0bd5 100644 --- a/src/engine/framework/VirtualMachine.cpp +++ b/src/engine/framework/VirtualMachine.cpp @@ -75,12 +75,28 @@ static Cvar::Cvar workaround_naclSystem_freebsd_disableQualification( "Disable platform qualification when running Linux NaCl loader on FreeBSD through Linuxulator", Cvar::NONE, true); +#if defined(DAEMON_NACL_RUNTIME_ENABLED) +// Many BSDs have a Linuxulator, for now we only tested one. +#if defined(__linux__) || defined(__FreeBSD__) +#define DAEMON_NACL_RUNTIME_LINUX +#define DAEMON_NACL_BOOSTRAP_ENABLED +#endif // defined(__linux__) || defined(DAEMON_LINUXULATOR) +#endif // defined(DAEMON_NACL_RUNTIME_ENABLED) + +#if defined(DAEMON_NACL_RUNTIME_ENABLED) #if defined(DAEMON_NACL_BOX64_EMULATION) static Cvar::Cvar workaround_box64_disableQualification( "workaround.box64.disableQualification", "Disable platform qualification when running amd64 NaCl loader under Box64 emulation", Cvar::NONE, true); +#if defined(YOKAI_ARCH_ARM64) +static Cvar::Cvar workaround_box64_preferArmhf( + "workaround.box64.preferArmhf", + "Prefer armhf multiarch when available over Box64 emulation", + Cvar::NONE, true); +#endif // defined(YOKAI_ARCH_ARM64) + static Cvar::Cvar workaround_box64_disableBootstrap( "workaround.box64.disableBootstrap", "Disable NaCl bootstrap helper when using Box64 emulation", @@ -88,14 +104,41 @@ static Cvar::Cvar workaround_box64_disableBootstrap( static Cvar::Cvar vm_box64_path( "vm.box64.path", - "Path to the box64 binary for NaCl emulation (empty = search PATH)", + "Path to the box64 binary for NaCl emulation (empty = use provided one or search PATH if missing)", Cvar::NONE, ""); -// Resolve box64 binary path by searching PATH if not explicitly set. -static std::string ResolveBox64Path() { - std::string path = vm_box64_path.Get(); - if (!path.empty()) { - return path; +// Resolve box64 binary path by looking for a provided one or searching PATH if not explicitly set. +static std::string ResolveBox64Path(std::string naclPath) { + std::string requestedPath = vm_box64_path.Get(); + + if (requestedPath.empty()) { + std::string providedPath = FS::Path::Build(naclPath, "box64"); + + if (FS::RawPath::FileExists(providedPath)) { + const std::string libs_linux_amd64 = "libs-linux-amd64"; + const std::string libgcc_linux_amd64 = "libgcc_s.so.1"; + + std::string libsDirPath = FS::Path::Build(naclPath, libs_linux_amd64); + std::string libGccPath = FS::Path::Build(libsDirPath, libgcc_linux_amd64); + + if (FS::RawPath::FileExists(libGccPath)) { + Sys::SetEnv("BOX64_LD_LIBRARY_PATH", libsDirPath.c_str()); + } + else { + Log::Warn("Using provided Box64 executable but the libraries are missing."); + } + + return providedPath; + } + + Log::Warn("Box64 emulation is enabled but the executable is not provided with the engine: %s", providedPath); + } + + if (!FS::RawPath::FileExists(requestedPath)) { + Sys::Error("Box64 emulation is enabled but the requested executable is missing: %s", requestedPath); + } + else { + return requestedPath; } const char* envPath = getenv("PATH"); @@ -121,34 +164,39 @@ static std::string ResolveBox64Path() { "Install Box64 or set vm.box64.path to the full path of the box64 binary."); return ""; // unreachable } -#endif - -static Cvar::Cvar vm_nacl_qualification( - "vm.nacl.qualification", - "Enable NaCl loader platform qualification", - Cvar::INIT, true); - -static Cvar::Cvar vm_nacl_bootstrap( - "vm.nacl.bootstrap", - "Use NaCl bootstrap helper", - Cvar::INIT, true); - -static Cvar::Cvar vm_timeout( - "vm.timeout", - "Receive timeout in seconds", - Cvar::NONE, 2); +#endif // DAEMON_NACL_BOX64_EMULATION +#endif // DAEMON_NACL_RUNTIME_ENABLED #if defined(DAEMON_NACL_RUNTIME_ENABLED) static Cvar::Cvar vm_nacl_available( "vm.nacl.available", "Whether NaCl runtime is available on this platform", Cvar::ROM, true); -#else +#else // !defined(DAEMON_NACL_RUNTIME_ENABLED) static Cvar::Cvar vm_nacl_available( "vm.nacl.available", "Whether NaCl runtime is available on this platform", Cvar::ROM, false); -#endif +#endif // !defined(DAEMON_NACL_RUNTIME_ENABLED) + +#if defined(DAEMON_NACL_RUNTIME_ENABLED) +static Cvar::Cvar vm_timeout( + "vm.timeout", + "Receive timeout in seconds", + Cvar::NONE, 2); + +static Cvar::Cvar vm_nacl_qualification( + "vm.nacl.qualification", + "Enable NaCl loader platform qualification", + Cvar::INIT, true); +#endif // defined(DAEMON_NACL_RUNTIME_ENABLED) + +#if defined(DAEMON_NACL_BOOSTRAP_ENABLED) +static Cvar::Cvar vm_nacl_bootstrap( + "vm.nacl.bootstrap", + "Use NaCl bootstrap helper", + Cvar::INIT, true); +#endif // defined(DAEMON_NACL_BOOSTRAP_ENABLED) namespace VM { @@ -300,36 +348,228 @@ static std::pair InternalLoadModule(std::pair(probe.data()), + nullptr, + }; + + execve(probe.data(), argv, environ); + + switch (errno) + { + case ENOEXEC: + // The kernel cannot execute the probe. + _exit(100); + + case ENOENT: + case EACCES: + // Missing or inaccessible probe. + _exit(101); + + default: + _exit(102); + } + } + + int status; + if (waitpid(pid, &status, 0) < 0) { + return ExeSupport::Unknown; + } + + if (!WIFEXITED(status)) { + return ExeSupport::Unknown; + } + + switch (WEXITSTATUS(status)) + { + case 100: + return ExeSupport::Unsupported; + + case 101: + case 102: + return ExeSupport::Unknown; + + default: + // The probe has been executed properly. + return ExeSupport::Supported; + } +} +#endif // defined(DAEMON_NACL_RUNTIME_LINUX) && defined(NACL_ARCH_ARM64) + +#if defined(DAEMON_NACL_RUNTIME_ENABLED) static std::pair CreateNaClVM(std::pair pair, Str::StringRef name, bool debug, bool extract, int debugLoader) { CheckMinAddressSysctlTooLarge(); const std::string& libPath = FS::GetLibPath(); -#ifdef DAEMON_NACL_RUNTIME_PATH - const char* naclPath = DAEMON_NACL_RUNTIME_PATH_STRING; -#else - const std::string& naclPath = libPath; -#endif std::vector args; char rootSocketRedir[32]; - std::string module, nacl_loader, irt, bootstrap, modulePath, verbosity; FS::File stderrRedirect; -#if defined(DAEMON_NACL_BOX64_EMULATION) - std::string box64Path; - bool usingBox64 = false; -#endif + bool inheritEnvironment = false; + + std::string module, nacl_loader, irt, arch, modulePath, verbosity; + +#if defined(DAEMON_NACL_RUNTIME_PATH) + const char* naclPath = DAEMON_NACL_RUNTIME_PATH_STRING; +#else // !defined(DAEMON_NACL_RUNTIME_PATH) + const std::string& naclPath = libPath; +#endif // !defined(DAEMON_NACL_RUNTIME_PATH) + #if !defined(_WIN32) || defined(_WIN64) - constexpr bool win32Force64Bit = false; -#else + constexpr bool i686ForceAmd64 = false; +#else // !( !defined(_WIN32) || defined(_WIN64) ) // On Windows, even if we are running a 32-bit engine, we must use the // 64-bit nacl_loader if the host operating system is 64-bit. SYSTEM_INFO systemInfo; GetNativeSystemInfo(&systemInfo); - const bool win32Force64Bit = systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64; + constexpr bool i686ForceAmd64 = systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64; +#endif // !( !defined(_WIN32) || defined(_WIN64) ) + +#if defined(DAEMON_NACL_RUNTIME_LINUX) && defined(YOKAI_ARCH_ARM64) + std::string multiarchPath; + constexpr bool hasMultiarch = true; +#else + constexpr bool hasMultiarch = false; +#endif + +#if defined(DAEMON_NACL_BOOSTRAP_ENABLED) + std::string bootstrapPath; + constexpr bool hasBootstrap = true; +#else // !defined(DAEMON_NACL_BOOSTRAP_ENABLED) + constexpr bool hasBootstrap = false; +#endif // !defined(DAEMON_NACL_BOOSTRAP_ENABLED) + +#if defined(DAEMON_NACL_BOX64_EMULATION) + std::string box64Path; + constexpr bool hasBox64 = true; +#else // !defined(DAEMON_NACL_BOX64_EMULATION) + constexpr bool hasBox64 = false; +#endif // !defined(DAEMON_NACL_BOX64_EMULATION) + +#if defined(DAEMON_NACL_RUNTIME_LINUX) && defined(YOKAI_ARCH_ARM64) + /* We later turn this boolean off when we detect armhf support is not + provided on arm64. */ + bool hasArmhf = true; +#endif // !defined(YOKAI_ARCH_ARMHF) + + bool useBox64 = hasBox64; + +#if defined(DAEMON_NACL_RUNTIME_LINUX) && defined(YOKAI_ARCH_ARM64) + const std::string libs_linux_armhf = "linux-armhf"; + const std::string libld_linux_armhf = "ld-linux"; + + std::string libsDirPath = FS::Path::Build(libPath, libs_linux_armhf); + std::string libLoaderPath = FS::Path::Build(libsDirPath, libld_linux_armhf); + + switch (CheckExeSupport(libLoaderPath)) + { + case ExeSupport::Supported: + Log::Notice("Working armhf multiarch support."); + break; + + case ExeSupport::Unsupported: + Log::Notice("Unsupported armhf multiarch."); + hasArmhf = false; + break; + + case ExeSupport::Unknown: + Log::Warn("Could not determine armhf multiarch support."); + hasArmhf = false; + break; + } + +#if defined(DAEMON_NACL_BOX64_EMULATION) + if (hasArmhf) { + if (workaround_box64_preferArmhf.Get()) { + Log::Notice("Preferring armhf multiarch over Box64 emulation."); + useBox64 = false; + } + } +#endif // defined(DAEMON_NACL_BOX64_EMULATION) + + bool useMultiarch = hasMultiarch; + + if (hasMultiarch && useBox64) { + useMultiarch = false; + } +#endif // defined(DAEMON_NACL_RUNTIME_LINUX) && defined(YOKAI_ARCH_ARM64) + + bool useBootstrap = hasBootstrap; + +#if defined(DAEMON_NACL_BOOSTRAP_ENABLED) + + if (hasBootstrap) { + if (!vm_nacl_bootstrap.Get()) { + useBootstrap = false; + } + +#if defined(DAEMON_NACL_BOX64_EMULATION) + /* Use Box64 to run the x86_64 NaCl loader on non-x86 architectures. + The bootstrap helper uses a double-exec pattern that Box64 cannot handle, + so we skip it and prepend "box64" to the nacl_loader command instead. */ + if (useBootstrap + && useBox64 + && workaround_box64_disableBootstrap.Get()) { + useBootstrap = false; + } +#endif // defined(DAEMON_NACL_BOX64_EMULATION) + } +#endif // defined(DAEMON_NACL_BOOSTRAP_ENABLED) + + if (useBox64 || i686ForceAmd64) { + arch = "amd64"; + } + else { + arch = DAEMON_NACL_ARCH_STRING; + } + + module = Str::Format("%s-%s.nexe", name, arch); + irt = FS::Path::Build(naclPath, Str::Format("irt_core-%s.nexe", arch)); + nacl_loader = FS::Path::Build(naclPath, Str::Format("nacl_loader-%s%s", arch, EXE_EXT)); + +#if defined(DAEMON_NACL_RUNTIME_LINUX) && defined(YOKAI_ARCH_ARM64) + if (useMultiarch) { + multiarchPath = FS::Path::Build(naclPath, Str::Format("nacl_multiarch-%s", arch)); + } +#endif + +#if defined(DAEMON_NACL_BOOSTRAP_ENABLED) + if (useBootstrap) { + bootstrapPath = FS::Path::Build(naclPath, Str::Format("nacl_helper_bootstrap-%s", arch)); + } #endif // Extract the nexe from the pak so that nacl_loader can load it - module = win32Force64Bit - ? name + "-amd64.nexe" - : Str::Format("%s-%s.nexe", name, DAEMON_NACL_ARCH_STRING); if (extract) { try { FS::File out = FS::HomePath::OpenWrite(module); @@ -347,10 +587,6 @@ static std::pair CreateNaClVM(std::pair CreateNaClVM(std::pair Error while loading "sgame-armhf.nexe": CPU model is not supported + > Error while loading "sgame-armhf.nexe": CPU model is not supported - From nacl_loader --help we can read: + From nacl_loader --help we can read: - > -Q disable platform qualification (dangerous!) + > -Q disable platform qualification (dangerous!) - When this option is enabled, nacl_loader will print: + When this option is enabled, nacl_loader will print: - > PLATFORM QUALIFICATION DISABLED BY -Q - Native Client's sandbox will be unreliable! + > PLATFORM QUALIFICATION DISABLED BY -Q - Native Client's sandbox will be unreliable! - But the nexe will load and run. */ + But the nexe will load and run. */ - if (onArm64) { - Log::Warn("Disabling NaCL platform qualification on arm64 kernel architecture."); - enableQualification = false; - } + if (onArm64) { + Log::Warn("Disabling NaCl platform qualification on arm64 kernel architecture."); + enableQualification = false; } -#endif + } +#endif // defined(__linux__) && (defined(YOKAI_ARCH_ARM64) || defined(YOKAI_ARCH_ARMHF)) + +#if defined(DAEMON_NACL_BOX64_EMULATION) + if (enableQualification + && useBox64 + && workaround_box64_disableQualification.Get()) { + /* When running the amd64 NaCl loader under Box64, the loader's + platform qualification will fail because the CPU is not actually x86_64. + Disabling qualification allows the emulated loader to proceed. */ + + Log::Warn("Disabling NaCl platform qualification for Box64 emulation."); + enableQualification = false; + } +#endif // defined(DAEMON_NACL_BOX64_EMULATION) #if defined(__FreeBSD__) + if (enableQualification + && workaround_naclSystem_freebsd_disableQualification.Get()) { /* While it is possible to build a native FreeBSD engine, the only available NaCl loader is the Linux one, which can run on Linuxulator (the FreeBSD Linux compatibility layer). @@ -466,26 +708,10 @@ static std::pair CreateNaClVM(std::pair CreateNaClVM(std::pair CreateNativeVM(std::pair pair, Str::StringRef name, bool debug) { const std::string& libPath = FS::GetLibPath(); @@ -622,7 +845,9 @@ void VMBase::Create() } #endif if (type == TYPE_NACL || type == TYPE_NACL_LIBPATH) { +#if defined(DAEMON_NACL_RUNTIME_ENABLED) std::tie(processHandle, rootSocket) = CreateNaClVM(std::move(pair), name, params.debug.Get(), type == TYPE_NACL, params.debugLoader.Get()); +#endif // defined(DAEMON_NACL_RUNTIME_ENABLED) } else if (type == TYPE_NATIVE_EXE) { std::tie(processHandle, rootSocket) = CreateNativeVM(std::move(pair), name, params.debug.Get()); } else { diff --git a/tools/nacl_helper_bootstrap-armhf/nacl_helper_bootstrap-armhf.cpp b/tools/nacl_multiarch/nacl_multiarch.cpp similarity index 84% rename from tools/nacl_helper_bootstrap-armhf/nacl_helper_bootstrap-armhf.cpp rename to tools/nacl_multiarch/nacl_multiarch.cpp index ec16447482..ae7d8755d4 100644 --- a/tools/nacl_helper_bootstrap-armhf/nacl_helper_bootstrap-armhf.cpp +++ b/tools/nacl_multiarch/nacl_multiarch.cpp @@ -35,7 +35,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include "YokaiBuildInfo/DaemonEngine.h" + int main(int argc, char *argv[]) { + if (argc < 2) { + printf("nacl_multiarch-%s: missing command line\n", DAEMON_NACL_ARCH_STRING); + return 1; + } + char *directory = dirname(strdup(argv[0])); int err = chdir(directory); @@ -44,19 +51,18 @@ int main(int argc, char *argv[]) { return err; } - err = putenv(strdup("LD_LIBRARY_PATH=lib-armhf")); + char env[100]; + sprintf(env, "LD_LIBRARY_PATH=libs-linux-%s", DAEMON_NACL_ARCH_STRING); + + err = putenv(strdup(env)); if (err != 0) { return err; } - char *helper = strdup("./nacl_helper_bootstrap"); - argv[0] = helper; - - execv(helper, argv); + execv(argv[1], &argv[1]); // The execv() function returns only if an error has occurred. - printf("nacl_helper_bootstrap-armhf: %s\n", strerror(errno)); - + printf("nacl_multiarch-%s: %s\n", DAEMON_NACL_ARCH_STRING, strerror(errno)); return 1; } From 8db49427219a9aae71c23711e0b707a66508170d Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 04:12:38 +0200 Subject: [PATCH 11/61] cmake,VirtualMachine: add architecture suffix to the loader --- CMakeLists.txt | 9 +- src/engine/framework/VirtualMachine.cpp | 150 +++++++++++------------- 2 files changed, 68 insertions(+), 91 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 91a484f9d1..7da7b66b71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -972,7 +972,7 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER # The NaCl loader and IRT are required to load .nexe files add_custom_command(TARGET runtime_deps PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${DEPS_DIR}/nacl_loader${CMAKE_EXECUTABLE_SUFFIX} + ${DEPS_DIR}/nacl_loader-${DAEMON_NACL_ARCH_NAME}${CMAKE_EXECUTABLE_SUFFIX} ${FULL_OUTPUT_DIR}/nacl_loader-${DAEMON_NACL_ARCH_NAME}${CMAKE_EXECUTABLE_SUFFIX} ) @@ -991,15 +991,10 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER ) add_dependencies(runtime_deps nacl_multiarch-${DAEMON_NACL_ARCH_NAME}) - add_custom_command(TARGET runtime_deps PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory - ${FULL_OUTPUT_DIR}/lib-${DAEMON_NACL_ARCH_NAME} - ) - add_custom_command(TARGET runtime_deps PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${DEPS_DIR}/linux-${DAEMON_NACL_ARCH_NAME} - ${FULL_OUTPUT_DIR}/linux-${DAEMON_NACL_ARCH_NAME} + ${FULL_OUTPUT_DIR}/libs-linux-${DAEMON_NACL_ARCH_NAME} ) endif() diff --git a/src/engine/framework/VirtualMachine.cpp b/src/engine/framework/VirtualMachine.cpp index dec5dc0bd5..8ddab6486f 100644 --- a/src/engine/framework/VirtualMachine.cpp +++ b/src/engine/framework/VirtualMachine.cpp @@ -90,13 +90,6 @@ static Cvar::Cvar workaround_box64_disableQualification( "Disable platform qualification when running amd64 NaCl loader under Box64 emulation", Cvar::NONE, true); -#if defined(YOKAI_ARCH_ARM64) -static Cvar::Cvar workaround_box64_preferArmhf( - "workaround.box64.preferArmhf", - "Prefer armhf multiarch when available over Box64 emulation", - Cvar::NONE, true); -#endif // defined(YOKAI_ARCH_ARM64) - static Cvar::Cvar workaround_box64_disableBootstrap( "workaround.box64.disableBootstrap", "Disable NaCl bootstrap helper when using Box64 emulation", @@ -168,16 +161,15 @@ static std::string ResolveBox64Path(std::string naclPath) { #endif // DAEMON_NACL_RUNTIME_ENABLED #if defined(DAEMON_NACL_RUNTIME_ENABLED) -static Cvar::Cvar vm_nacl_available( - "vm.nacl.available", - "Whether NaCl runtime is available on this platform", - Cvar::ROM, true); +static constexpr bool vmAvailable = true; #else // !defined(DAEMON_NACL_RUNTIME_ENABLED) +static constexpr bool vmAvailable = false; +#endif // !defined(DAEMON_NACL_RUNTIME_ENABLED) + static Cvar::Cvar vm_nacl_available( "vm.nacl.available", "Whether NaCl runtime is available on this platform", - Cvar::ROM, false); -#endif // !defined(DAEMON_NACL_RUNTIME_ENABLED) + Cvar::ROM, vmAvailable); #if defined(DAEMON_NACL_RUNTIME_ENABLED) static Cvar::Cvar vm_timeout( @@ -191,6 +183,15 @@ static Cvar::Cvar vm_nacl_qualification( Cvar::INIT, true); #endif // defined(DAEMON_NACL_RUNTIME_ENABLED) +#if defined(DAEMON_NACL_RUNTIME_ENABLED) +#if defined(DAEMON_NACL_RUNTIME_LINUX) && defined(YOKAI_ARCH_ARM64) +static Cvar::Cvar vm_nacl_multiarch( + "vm.nacl.multiarch", + "Use multiarch to run the NaCl loader when needed and available", + Cvar::INIT, true); +#endif // defined(DAEMON_NACL_RUNTIME_LINUX) && defined(YOKAI_ARCH_ARM64) +#endif // defined(DAEMON_NACL_RUNTIME_ENABLED) + #if defined(DAEMON_NACL_BOOSTRAP_ENABLED) static Cvar::Cvar vm_nacl_bootstrap( "vm.nacl.bootstrap", @@ -437,8 +438,6 @@ static std::pair CreateNaClVM(std::pair CreateNaClVM(std::pair CreateNaClVM(std::pair CreateNaClVM(std::pairpath.c_str()); - FS::PakPath::CopyFile(module, out); + FS::File out = FS::HomePath::OpenWrite(moduleName); + if (const FS::LoadedPakInfo* pak = FS::PakPath::LocateFile(moduleName)) + Log::Notice("Extracting VM module %s from %s...", moduleName.c_str(), pak->path.c_str()); + FS::PakPath::CopyFile(moduleName, out); out.Close(); } catch (std::system_error& err) { - Sys::Drop("VM: Failed to extract VM module %s: %s", module, err.what()); + Sys::Drop("VM: Failed to extract VM module %s: %s", moduleName, err.what()); } - modulePath = FS::Path::Build(FS::GetHomePath(), module); + modulePath = FS::Path::Build(FS::GetHomePath(), moduleName); } else { - modulePath = FS::Path::Build(libPath, module); + modulePath = FS::Path::Build(libPath, moduleName); } // Generate command line @@ -600,37 +577,40 @@ static std::pair CreateNaClVM(std::pair CreateNaClVM(std::pair CreateNaClVM(std::pair Date: Mon, 29 Jun 2026 04:07:58 +0200 Subject: [PATCH 12/61] cmake: use box64 on loong64 --- cmake/DaemonNaclHost.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/DaemonNaclHost.cmake b/cmake/DaemonNaclHost.cmake index 7172e71d55..164fdf3071 100644 --- a/cmake/DaemonNaclHost.cmake +++ b/cmake/DaemonNaclHost.cmake @@ -30,7 +30,7 @@ function(daemon_detect_nacl_arch) if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY OR YOKAI_TARGET_SYSTEM_XDG_COMPATIBILITY) set(armhf_usage "arm64" "armel") - set(box64_usage "ppc64el" "riscv64") + set(box64_usage "ppc64el" "riscv64" "loong64") if ("${target_arch}" IN_LIST armhf_usage) # Load 32-bit armhf nexe on 64-bit arm64 engine on Linux with multiarch. From 519f70cd14cf2760ed5596dfe5d4a6ba7514ae2d Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 3 Jul 2026 12:40:34 +0200 Subject: [PATCH 13/61] cmake: rework the code enabling nexe build when there is an nacl sdk, taking saigo in account --- cmake/DaemonGame.cmake | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmake/DaemonGame.cmake b/cmake/DaemonGame.cmake index f6adde3c7c..c571e9c90d 100644 --- a/cmake/DaemonGame.cmake +++ b/cmake/DaemonGame.cmake @@ -68,10 +68,16 @@ set(SHAREDLIST_sgame # Function to setup all the Sgame/Cgame libraries include(CMakeParseArguments) -# The NaCl SDK only runs on amd64 or i686. if (NOT FORK EQUAL 2) - if (CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME + if (USE_NACL_SAIGO) + set(HAS_NACL_SDK ON) + elseif (CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME AND (YOKAI_TARGET_ARCH_AMD64 OR YOKAI_TARGET_ARCH_I686)) + # The PNaCl SDK only runs on amd64 or i686. + set(HAS_NACL_SDK ON) + endif() + + if (HAS_NACL_SDK) # can be loaded by daemon with vm.[sc]game.type 0 or 1 option(BUILD_GAME_NACL "Build the NaCl \"pexe\" and \"nexe\" gamelogic modules for enabled architecture targets, required to host mods." OFF) @@ -92,7 +98,7 @@ if (NOT FORK EQUAL 2) foreach(NACL_TARGET ${NACL_TARGETS}) set(IS_NACL_VALID_TARGET OFF) foreach(NACL_VALID_TARGET ${NACL_ALL_TARGETS}) - if(NACL_TARGET STREQUAL NACL_VALID_TARGET) + if (NACL_TARGET STREQUAL NACL_VALID_TARGET) set(IS_NACL_VALID_TARGET ON) endif() endforeach() From 6b802915621c65ee3291b6d01b83c21b45618c62 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 3 Jul 2026 07:34:38 +0200 Subject: [PATCH 14/61] cmake: implement multi nexe --- CMakeLists.txt | 69 ++++++++++--------- cmake/DaemonGame.cmake | 51 ++++++++------ ...ost.cmake => DaemonNaclArchitecture.cmake} | 66 +++++++++++------- 3 files changed, 108 insertions(+), 78 deletions(-) rename cmake/{DaemonNaclHost.cmake => DaemonNaclArchitecture.cmake} (68%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7da7b66b71..d2b6369b17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,7 +76,13 @@ if (Daemon_OUT) endif() include(Yokai/All) -include(DaemonNaclHost) + +include(DaemonNaclArchitecture) + +daemon_detect_nacl_arch("${YOKAI_TARGET_ARCH_NAME}") + +# Add printable strings to the executable. +yokai_add_buildinfo("char*" "DAEMON_NACL_ARCH_STRING" "\"${DAEMON_NACL_ARCH_NAME}\"") ################################################################################ # Configuration options @@ -969,22 +975,33 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER add_custom_target(runtime_deps) set_target_properties(runtime_deps PROPERTIES FOLDER "CMakePlumbing") - # The NaCl loader and IRT are required to load .nexe files - add_custom_command(TARGET runtime_deps PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${DEPS_DIR}/nacl_loader-${DAEMON_NACL_ARCH_NAME}${CMAKE_EXECUTABLE_SUFFIX} - ${FULL_OUTPUT_DIR}/nacl_loader-${DAEMON_NACL_ARCH_NAME}${CMAKE_EXECUTABLE_SUFFIX} - ) + foreach(arch_name IN LISTS DAEMON_NACL_ARCH_NAME_LIST) + # The NaCl loader and IRT are required to load .nexe files + if (YOKAI_TARGET_SYSTEM_WINDOWS AND YOKAI_TARGET_ARCH_I686 AND "${arch_name}" STREQUAL "amd64") + # Backport compatibility until the external_deps script properly suffixes names in the archives. + add_custom_command(TARGET runtime_deps PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${DEPS_DIR}/nacl_loader-${arch_name}${CMAKE_EXECUTABLE_SUFFIX} + ${FULL_OUTPUT_DIR}/nacl_loader-${arch_name}${CMAKE_EXECUTABLE_SUFFIX} + ) + else() + add_custom_command(TARGET runtime_deps PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${DEPS_DIR}/nacl_loader${CMAKE_EXECUTABLE_SUFFIX} + ${FULL_OUTPUT_DIR}/nacl_loader-${arch_name}${CMAKE_EXECUTABLE_SUFFIX} + ) + endif() - add_custom_command(TARGET runtime_deps PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${DEPS_DIR}/irt_core-${DAEMON_NACL_ARCH_NAME}.nexe - ${FULL_OUTPUT_DIR}/irt_core-${DAEMON_NACL_ARCH_NAME}.nexe - ) + add_custom_command(TARGET runtime_deps PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${DEPS_DIR}/irt_core-${arch_name}.nexe + ${FULL_OUTPUT_DIR}/irt_core-${arch_name}.nexe + ) + endforeach() # Linux uses a bootstrap program to reserve address space if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY) - if (YOKAI_TARGET_ARCH_ARM64) + if (DAEMON_NACL_MULTIARCH) add_executable(nacl_multiarch-${DAEMON_NACL_ARCH_NAME} tools/nacl_multiarch/nacl_multiarch.cpp ${BUILDINFOLIST} @@ -998,25 +1015,13 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER ) endif() - add_custom_command(TARGET runtime_deps PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${DEPS_DIR}/nacl_helper_bootstrap - ${FULL_OUTPUT_DIR}/nacl_helper_bootstrap-${DAEMON_NACL_ARCH_NAME} - ) - endif() - - # Win32 requires nacl_loader_amd64.exe in order to run on Win64 - if (YOKAI_TARGET_SYSTEM_WINDOWS AND YOKAI_TARGET_ARCH_I686) - add_custom_command(TARGET runtime_deps PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${DEPS_DIR}/nacl_loader-amd64${CMAKE_EXECUTABLE_SUFFIX} - ${FULL_OUTPUT_DIR}/nacl_loader-amd64${CMAKE_EXECUTABLE_SUFFIX} - ) - add_custom_command(TARGET runtime_deps PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${DEPS_DIR}/irt_core-amd64.nexe - ${FULL_OUTPUT_DIR}/irt_core-amd64.nexe - ) + foreach(arch_name IN LISTS DAEMON_NACL_ARCH_NAME_LIST) + add_custom_command(TARGET runtime_deps PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${DEPS_DIR}/nacl_helper_bootstrap + ${FULL_OUTPUT_DIR}/nacl_helper_bootstrap-${arch_name} + ) + endforeach() endif() # Mac requires some libraries from external_deps diff --git a/cmake/DaemonGame.cmake b/cmake/DaemonGame.cmake index c571e9c90d..053f44a567 100644 --- a/cmake/DaemonGame.cmake +++ b/cmake/DaemonGame.cmake @@ -78,35 +78,46 @@ if (NOT FORK EQUAL 2) endif() if (HAS_NACL_SDK) + include(DaemonNaclArchitecture) + # can be loaded by daemon with vm.[sc]game.type 0 or 1 option(BUILD_GAME_NACL "Build the NaCl \"pexe\" and \"nexe\" gamelogic modules for enabled architecture targets, required to host mods." OFF) set(NACL_ALL_TARGETS "amd64;i686;armhf") - set(BUILD_GAME_NACL_TARGETS "all" CACHE STRING "Enabled NaCl \"nexe\" architecture targets, values: ${NACL_ALL_TARGETS}, all, native, none.") + set(BUILD_GAME_NACL_TARGETS "all" CACHE STRING "Enabled NaCl \"nexe\" architecture targets, values: ${NACL_ALL_TARGETS};all;native;none") mark_as_advanced(BUILD_GAME_NACL_TARGETS) - if (BUILD_GAME_NACL_TARGETS STREQUAL "all") - set(NACL_TARGETS "${NACL_ALL_TARGETS}") - elseif (BUILD_GAME_NACL_TARGETS STREQUAL "native") - set(NACL_TARGETS "${YOKAI_TARGET_ARCH_NAME}") - elseif (BUILD_GAME_NACL_TARGETS STREQUAL "none") - set(NACL_TARGETS "") - else() - set(NACL_TARGETS "${BUILD_GAME_NACL_TARGETS}") - endif() + if (BUILD_GAME_NACL) + foreach(nacl_target ${BUILD_GAME_NACL_TARGETS}) + if (BUILD_GAME_NACL_TARGETS STREQUAL "all") + list(APPEND nacl_target_list ${NACL_ALL_TARGETS}) + elseif (BUILD_GAME_NACL_TARGETS STREQUAL "native") + list(APPEND nacl_target_list "${YOKAI_TARGET_ARCH_NAME}") + elseif (BUILD_GAME_NACL_TARGETS STREQUAL "none") + set(nacl_target_list "") + else() + list(APPEND nacl_target_list "${nacl_target}") + endif() + endforeach() + + foreach(nacl_target IN LISTS nacl_target_list) + daemon_detect_nacl_arch("${nacl_target}") - foreach(NACL_TARGET ${NACL_TARGETS}) - set(IS_NACL_VALID_TARGET OFF) - foreach(NACL_VALID_TARGET ${NACL_ALL_TARGETS}) - if (NACL_TARGET STREQUAL NACL_VALID_TARGET) - set(IS_NACL_VALID_TARGET ON) + foreach(detected_target IN LISTS DAEMON_NACL_ARCH_NAME_LIST) + if (NOT "${detected_target}" IN_LIST NACL_TARGETS) + list(APPEND NACL_TARGETS ${detected_target}) + endif() + endforeach() + endforeach() + + foreach(nacl_target IN LISTS NACL_TARGETS) + if (NOT nacl_target IN_LIST NACL_ALL_TARGETS) + message(FATAL_ERROR "Invalid NaCl target ${nacl_target}, must be one of ${NACL_ALL_TARGETS}") endif() endforeach() - if (NOT IS_NACL_VALID_TARGET) - message(FATAL_ERROR "Invalid NaCl target ${NACL_TARGET}, must be one of ${NACL_ALL_TARGETS}") - endif() - endforeach() + message(STATUS "Building NaCl targets: ${NACL_TARGETS}") + endif() else() set(BUILD_GAME_NACL OFF) set(NACL_TARGETS "") @@ -213,7 +224,7 @@ function(GAMEMODULE) add_custom_target(nacl-vms ALL) unset(NACL_VMS_PROJECTS) - foreach(NACL_TARGET ${NACL_TARGETS}) + foreach(NACL_TARGET IN LISTS NACL_TARGETS) if (NACL_TARGET STREQUAL "i686") set(SAIGO_ARCH "i686") elseif (NACL_TARGET STREQUAL "amd64") diff --git a/cmake/DaemonNaclHost.cmake b/cmake/DaemonNaclArchitecture.cmake similarity index 68% rename from cmake/DaemonNaclHost.cmake rename to cmake/DaemonNaclArchitecture.cmake index 164fdf3071..e0666c193b 100644 --- a/cmake/DaemonNaclHost.cmake +++ b/cmake/DaemonNaclArchitecture.cmake @@ -24,60 +24,74 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -function(daemon_detect_nacl_arch) - set(target_arch "${YOKAI_TARGET_ARCH_NAME}") - set(nacl_arch "${target_arch}") +function(daemon_detect_nacl_arch target_arch) + macro(add_nacl_arch arch_name) + list(APPEND nacl_arch_list "${arch_name}") + endmacro() + + # NaCl runtime is only available on architectures that have a NaCl loader. + set(nacl_runtime_arch "amd64" "i686" "armhf") + + if (YOKAI_TARGET_SYSTEM_WINDOWS) + if("${target_arch}" STREQUAL "amd64") + add_nacl_arch("${target_arch}") + elseif("${target_arch}" STREQUAL "i686") + # Win32 requires nacl_loader-amd64.exe in order to run on Win64 + add_nacl_arch("${target_arch}") + add_nacl_arch("amd64") + endif() + elseif (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY OR YOKAI_TARGET_SYSTEM_XDG_COMPATIBILITY) + if ("${target_arch}" IN_LIST nacl_runtime_arch) + add_nacl_arch("${target_arch}") + endif() - if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY OR YOKAI_TARGET_SYSTEM_XDG_COMPATIBILITY) set(armhf_usage "arm64" "armel") set(box64_usage "ppc64el" "riscv64" "loong64") if ("${target_arch}" IN_LIST armhf_usage) + set(DAEMON_NACL_MULTIARCH ON) + # Load 32-bit armhf nexe on 64-bit arm64 engine on Linux with multiarch. # The nexe is system agnostic so there should be no difference with armel. - set(nacl_arch "armhf") - elseif ("${target_arch}" IN_LIST box64_usage) + add_nacl_arch("armhf") + endif() + + if ("${target_arch}" IN_LIST box64_usage) option(DAEMON_NACL_BOX64_EMULATION "Use Box64 to emulate x86_64 NaCl loader on unsupported platforms" ON) + if (DAEMON_NACL_BOX64_EMULATION) # Use Box64 to run x86_64 NaCl loader and amd64 nexe. # Box64 must be installed and available in PATH at runtime. - set(nacl_arch "amd64") + add_nacl_arch("amd64") add_definitions(-DDAEMON_NACL_BOX64_EMULATION) endif() endif() elseif (YOKAI_TARGET_SYSTEM_MACOS) - if ("${target_arch}" STREQUAL "arm64") + if ("${target_arch}" STREQUAL "amd64") + add_nacl_arch("${target_arch}") + elseif ("${target_arch}" STREQUAL "arm64") # You can get emulated NaCl going like this: # cp external_deps/macos-amd64-default_10/{nacl_loader,irt_core-amd64.nexe} build/ - set(nacl_arch "amd64") + add_nacl_arch("amd64") endif() endif() - string(TOUPPER "${nacl_arch}" nacl_arch_upper) + if (nacl_arch_list) + message(STATUS "Available NaCl architectures: ${nacl_arch_list}") - # NaCl runtime is only available on architectures that have a NaCl loader. - set(nacl_runtime_arch "amd64" "i686" "armhf") - if ("${nacl_arch}" IN_LIST nacl_runtime_arch) - message(STATUS "Detected NaCl architecture: ${nacl_arch}") + list(GET nacl_arch_list 0 nacl_arch) + + message(STATUS "Primary NaCl architecture: ${nacl_arch}") add_definitions(-DDAEMON_NACL_RUNTIME_ENABLED) else() set(nacl_arch "unknown") - message(STATUS "No NaCl architecture detected") + message(STATUS "No known NaCl architecture") endif() # The DAEMON_NACL_ARCH_NAME variable contributes to the nexe file name. set(DAEMON_NACL_ARCH_NAME "${nacl_arch}" PARENT_SCOPE) - - set(DAEMON_NACL_ARCH_NAME_UPPER "${nacl_arch_upper}" PARENT_SCOPE) + # Those names are used to copy the loader and the IRT binaries. + set(DAEMON_NACL_ARCH_NAME_LIST "${nacl_arch_list}" PARENT_SCOPE) endfunction() - -daemon_detect_nacl_arch() - -# Makes possible to do that in CMake code: -# > if (DAEMON_NACL_ARCH_ARMHF) -set("DAEMON_NACL_ARCH_${DAEMON_NACL_ARCH_NAME_UPPER}" ON) - -# Add printable strings to the executable. -yokai_add_buildinfo("char*" "DAEMON_NACL_ARCH_STRING" "\"${DAEMON_NACL_ARCH_NAME}\"") From 01141fb51ad2dc8e86558d2d02650cf29ca73465 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 4 Jul 2026 14:19:36 +0200 Subject: [PATCH 15/61] cmake: reword DaemonFlags a bit --- cmake/DaemonFlags.cmake | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cmake/DaemonFlags.cmake b/cmake/DaemonFlags.cmake index 179835ddca..f999e5e272 100644 --- a/cmake/DaemonFlags.cmake +++ b/cmake/DaemonFlags.cmake @@ -260,10 +260,14 @@ if (USE_FLOAT_EXCEPTIONS) add_definitions(-DDAEMON_USE_FLOAT_EXCEPTIONS) endif() -if (NOT NACL AND BUILD_CLIENT) +if (NOT YOKAI_TARGET_SYSTEM_NACL AND BUILD_CLIENT) option(USE_OPENMP "Use OpenMP to parallelize some tasks" OFF) endif() +if (NOT YOKAI_TARGET_SYSTEM_NACL AND BUILD_CLIENT AND USE_OPENMP) + set(ENABLE_OPENMP ON) +endif() + if (YOKAI_CXX_COMPILER_MSVC_COMPATIBILITY) if (YOKAI_CXX_COMPILER_MSVC) # /MP doesn't do anything and prints a warning in the Clang clone. @@ -275,7 +279,7 @@ if (YOKAI_CXX_COMPILER_MSVC_COMPATIBILITY) set_cxx_flag("/std:c++23preview") endif() - if (NOT NACL AND BUILD_CLIENT AND USE_OPENMP) + if (ENABLE_OPENMP) # Flag checks doen't work with MSVC so we assume it's there. set(OPENMP_COMPILE_FLAG "/openmp") endif() @@ -385,7 +389,7 @@ else() endif() endif() - if (NOT NACL AND BUILD_CLIENT AND USE_OPENMP) + if (ENABLE_OPENMP) check_CXX_compiler_flag("-fopenmp" FLAG_FOPENMP) if (FLAG_FOPENMP) @@ -396,7 +400,7 @@ else() endif() endif() - if (YOKAI_TARGET_SYSTEM_NACL AND USE_NACL_SAIGO AND DAEMON_NACL_ARCH_ARMHF) + if (YOKAI_TARGET_SYSTEM_NACL AND YOKAI_CXX_COMPILER_SAIGO AND YOKAI_TARGET_ARCH_ARMHF) # Saigo produces broken arm builds when optimizing them. # See: https://github.com/Unvanquished/Unvanquished/issues/3297 # When setting this clang-specific option, we don't have to care @@ -445,7 +449,7 @@ else() try_flag(WARNINGS "-Werror") endif() - if (YOKAI_TARGET_SYSTEM_NACL AND NOT USE_NACL_SAIGO) + if (YOKAI_TARGET_SYSTEM_NACL AND YOKAI_CXX_COMPILER_PNACL) # PNaCl only supports libc++ as standard library. set_c_cxx_flag("-stdlib=libc++") set_c_cxx_flag("--pnacl-allow-exceptions") @@ -508,7 +512,7 @@ else() # Don't set _FORTIFY_SOURCE in debug builds. endif() - if (NOT NACL) + if (NOT YOKAI_TARGET_SYSTEM_NACL) # Saigo reports weird errors when building some cgame and sgame arm nexe with PIC: # > error: Cannot represent a difference across sections # > error: expected relocatable expression From 42576543c9f94af1fcda44ba5cbb6ce3ea5647b0 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 4 Jul 2026 10:57:36 +0200 Subject: [PATCH 16/61] cmake: deeply rewrite the NaCl toolchains --- CMakeLists.txt | 28 ++--- cmake/DaemonGame.cmake | 87 +++++++------ cmake/DaemonNacl.cmake | 81 ------------ cmake/DaemonNaclFlags.cmake | 75 +++++++++++ cmake/DaemonPNaClFinalize.cmake | 79 ++++++++++++ cmake/DaemonSaigoFinalize.cmake | 56 +++++++++ cmake/cross-toolchain-pnacl.cmake | 106 ++++++++++++++++ cmake/cross-toolchain-saigo-amd64.cmake | 28 +++++ cmake/cross-toolchain-saigo-armhf.cmake | 28 +++++ cmake/cross-toolchain-saigo-common.cmake | 79 ++++++++++++ cmake/cross-toolchain-saigo-i686.cmake | 39 ++++++ cmake/toolchain-pnacl.cmake | 151 ----------------------- cmake/toolchain-saigo.cmake | 75 ----------- 13 files changed, 554 insertions(+), 358 deletions(-) delete mode 100644 cmake/DaemonNacl.cmake create mode 100644 cmake/DaemonNaclFlags.cmake create mode 100644 cmake/DaemonPNaClFinalize.cmake create mode 100644 cmake/DaemonSaigoFinalize.cmake create mode 100644 cmake/cross-toolchain-pnacl.cmake create mode 100644 cmake/cross-toolchain-saigo-amd64.cmake create mode 100644 cmake/cross-toolchain-saigo-armhf.cmake create mode 100644 cmake/cross-toolchain-saigo-common.cmake create mode 100644 cmake/cross-toolchain-saigo-i686.cmake delete mode 100644 cmake/toolchain-pnacl.cmake delete mode 100644 cmake/toolchain-saigo.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index d2b6369b17..f012339cb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,12 +77,14 @@ endif() include(Yokai/All) -include(DaemonNaclArchitecture) +if (NOT YOKAI_TARGET_SYSTEM_NACL) + include(DaemonNaclArchitecture) -daemon_detect_nacl_arch("${YOKAI_TARGET_ARCH_NAME}") + daemon_detect_nacl_arch("${YOKAI_TARGET_ARCH_NAME}") -# Add printable strings to the executable. -yokai_add_buildinfo("char*" "DAEMON_NACL_ARCH_STRING" "\"${DAEMON_NACL_ARCH_NAME}\"") + # Add printable strings to the executable. + yokai_add_buildinfo("char*" "DAEMON_NACL_ARCH_STRING" "\"${DAEMON_NACL_ARCH_NAME}\"") +endif() ################################################################################ # Configuration options @@ -271,6 +273,12 @@ endif() option(USE_EXTERNAL_DEPS_LIBS "Build and link against libraries from the EXTERNAL_DEPS_DIR" ${DEFAULT_USE_EXTERNAL_DEPS_LIBS}) +set(PNACLSDK_PREFIX "${DEPS_DIR}/pnacl" CACHE PATH "PNaCl SDK path") +mark_as_advanced(PNACLSDK_PREFIX) + +set(SAIGOSDK_PREFIX "${DEPS_DIR}/saigo_newlib" CACHE PATH "Saigo NaCl SDK path") +mark_as_advanced(SAIGOSDK_PREFIX) + if (USE_EXTERNAL_DEPS AND NOT YOKAI_TARGET_SYSTEM_NACL) if (DEPS_DIR) message(STATUS "Using external deps dir: ${DEPS_DIR}") @@ -297,6 +305,7 @@ endif() # meaning we have to detect useless engine compiler to set # useless engine flags when only building vms. include(DaemonFlags) +include(DaemonNaclFlags) # FIXME: Once engine flags would be only set when building the engine # this would be likely unused by vms as they are built by DaemonGame. @@ -468,7 +477,6 @@ endif() # LIBS_BASE, LIBS_ENGINE_BASE LIBS_ENGINE, LIBS_BASECLIENT, LIBS_CLIENT # Native client -include(DaemonNacl) if (YOKAI_TARGET_SYSTEM_NACL) add_library(srclibs-nacl-module EXCLUDE_FROM_ALL ${NACLLIST_MODULE}) set(LIBS_BASE ${LIBS_BASE} srclibs-nacl-module) @@ -489,16 +497,6 @@ elseif (YOKAI_TARGET_SYSTEM_NACL) find_library(NACL_EXCEPTION nacl_exception) find_library(NACL_MINIDUMP minidump_generator) - # HACK: To be removed when Saigo is repackaged properly. - if (NOT NACL_MINIDUMP - # NACL_TARGET is specific to Saigo, PNaCl target is le32 and doesn't set NACL_TARGET. - AND "${NACL_TARGET}" STREQUAL "i686" - # x86_64-nacl/lib32 is specific to Google build, other builds may provide i686-nacl/lib instead. - AND EXISTS "${DEPS_DIR}/saigo_newlib/x86_64-nacl/lib32") - set(NACL_EXCEPTION "${DEPS_DIR}/saigo_newlib/x86_64-nacl/lib32/libnacl_exception.a") - set(NACL_MINIDUMP "${DEPS_DIR}/saigo_newlib/x86_64-nacl/lib32/libminidump_generator.a") - endif() - set(LIBS_BASE ${LIBS_BASE} ${NACL_MINIDUMP} ${NACL_EXCEPTION}) else() find_library(LIBM m) diff --git a/cmake/DaemonGame.cmake b/cmake/DaemonGame.cmake index 053f44a567..8a4cc2e4ff 100644 --- a/cmake/DaemonGame.cmake +++ b/cmake/DaemonGame.cmake @@ -44,9 +44,9 @@ include(Yokai/All) # Do not report unused native compiler if native vms are not built. # If only NACL vms are built, this will be reported in chainloaded build. -if (BUILD_GAME_NATIVE_DLL OR BUILD_GAME_NATIVE_EXE OR NACL) - include(DaemonNacl) +if (BUILD_GAME_NATIVE_DLL OR BUILD_GAME_NATIVE_EXE OR GAME_BUILD_SUBINVOCATION) include(DaemonFlags) + include(DaemonNaclFlags) endif() # Source lists for src/shared @@ -68,7 +68,11 @@ set(SHAREDLIST_sgame # Function to setup all the Sgame/Cgame libraries include(CMakeParseArguments) -if (NOT FORK EQUAL 2) +list(APPEND NACL_ALL_TARGETS "amd64" "i686" "armhf") + +if (NOT GAME_BUILD_SUBINVOCATION) + option(USE_NACL_SAIGO "Use the Saigo toolchain to build NaCl executables" OFF) + if (USE_NACL_SAIGO) set(HAS_NACL_SDK ON) elseif (CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME @@ -77,23 +81,24 @@ if (NOT FORK EQUAL 2) set(HAS_NACL_SDK ON) endif() + list(APPEND NACL_ALL_TARGETS "amd64" "i686" "armhf") + if (HAS_NACL_SDK) include(DaemonNaclArchitecture) # can be loaded by daemon with vm.[sc]game.type 0 or 1 option(BUILD_GAME_NACL "Build the NaCl \"pexe\" and \"nexe\" gamelogic modules for enabled architecture targets, required to host mods." OFF) - set(NACL_ALL_TARGETS "amd64;i686;armhf") set(BUILD_GAME_NACL_TARGETS "all" CACHE STRING "Enabled NaCl \"nexe\" architecture targets, values: ${NACL_ALL_TARGETS};all;native;none") mark_as_advanced(BUILD_GAME_NACL_TARGETS) if (BUILD_GAME_NACL) foreach(nacl_target ${BUILD_GAME_NACL_TARGETS}) - if (BUILD_GAME_NACL_TARGETS STREQUAL "all") + if ("${nacl_target}" STREQUAL "all") list(APPEND nacl_target_list ${NACL_ALL_TARGETS}) - elseif (BUILD_GAME_NACL_TARGETS STREQUAL "native") + elseif ("${nacl_target}" STREQUAL "native") list(APPEND nacl_target_list "${YOKAI_TARGET_ARCH_NAME}") - elseif (BUILD_GAME_NACL_TARGETS STREQUAL "none") + elseif ("${nacl_target}" STREQUAL "none") set(nacl_target_list "") else() list(APPEND nacl_target_list "${nacl_target}") @@ -105,7 +110,7 @@ if (NOT FORK EQUAL 2) foreach(detected_target IN LISTS DAEMON_NACL_ARCH_NAME_LIST) if (NOT "${detected_target}" IN_LIST NACL_TARGETS) - list(APPEND NACL_TARGETS ${detected_target}) + list(APPEND NACL_TARGETS "${detected_target}") endif() endforeach() endforeach() @@ -151,7 +156,7 @@ function(buildGameModule module_slug) if (module_slug STREQUAL "nacl") set_target_properties(${module_target} PROPERTIES OUTPUT_NAME "${GAMEMODULE_NAME}" - SUFFIX "${PLATFORM_EXE_SUFFIX}") + SUFFIX "${NACL_EXECUTABLE_SUFFIX}") target_link_libraries(${module_target} ${GAMEMODULE_LIBS} ${LIBS_BASE}) else() @@ -167,13 +172,13 @@ function(gameSubProject) BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${NACL_VMS_PROJECT} CMAKE_GENERATOR ${VM_GENERATOR} CMAKE_ARGS - -DFORK=2 - -DDAEMON_DIR=${Daemon_SOURCE_DIR} - -DDEPS_DIR=${DEPS_DIR} + "-DDAEMON_DIR=${Daemon_SOURCE_DIR}" + "-DDEPS_DIR=${DEPS_DIR}" -DBUILD_CLIENT=OFF -DBUILD_TTY_CLIENT=OFF -DBUILD_SERVER=OFF - -DBUILD_DUMMY_GAMELOGIC=${BUILD_DUMMY_GAMELOGIC} + "-DBUILD_DUMMY_GAMELOGIC=${BUILD_DUMMY_GAMELOGIC}" + -DGAME_BUILD_SUBINVOCATION=ON ${ARGV} ${INHERITED_OPTION_ARGS} INSTALL_COMMAND "" @@ -203,8 +208,9 @@ function(GAMEMODULE) buildGameModule("native-exe") endif() - if (NOT FORK) # create the nacl-vms target only the first time that GAMEMODULE is called - set(FORK 1 PARENT_SCOPE) + if (NOT NACL_VMS_TARGET_CREATED AND NOT GAME_BUILD_SUBINVOCATION) + # Create the nacl-vms target only the first time that GAMEMODULE is called. + set(NACL_VMS_TARGET_CREATED ON PARENT_SCOPE) if (CMAKE_GENERATOR MATCHES "Visual Studio") set(VM_GENERATOR "NMake Makefiles") @@ -219,34 +225,29 @@ function(GAMEMODULE) "-D${inherited_option}=${${inherited_option}}") endforeach(inherited_option) - if (BUILD_GAME_NACL) + if (BUILD_GAME_NACL AND NOT YOKAI_TARGET_SYSTEM_NACL) if (USE_NACL_SAIGO) add_custom_target(nacl-vms ALL) unset(NACL_VMS_PROJECTS) - foreach(NACL_TARGET IN LISTS NACL_TARGETS) - if (NACL_TARGET STREQUAL "i686") - set(SAIGO_ARCH "i686") - elseif (NACL_TARGET STREQUAL "amd64") - set(SAIGO_ARCH "x86_64") - elseif (NACL_TARGET STREQUAL "armhf") - set(SAIGO_ARCH "arm") - else() + foreach(nacl_target IN LISTS NACL_TARGETS) + if (NOT nacl_target IN_LIST NACL_ALL_TARGETS) message(FATAL_ERROR "Unknown NaCl architecture ${NACL_TARGET}") endif() - set(NACL_VMS_PROJECT nacl-vms-${NACL_TARGET}) + set(NACL_VMS_PROJECT nacl-vms-${nacl_target}) list(APPEND NACL_VMS_PROJECTS ${NACL_VMS_PROJECT}) add_dependencies(nacl-vms ${NACL_VMS_PROJECT}) + # TODO: Remove USE_NACL_SAIGO once the game uses YOKAI_TARGET_SYSTEM_NACL. gameSubProject( - -DCMAKE_TOOLCHAIN_FILE=${Daemon_SOURCE_DIR}/cmake/toolchain-saigo.cmake + "-DCMAKE_TOOLCHAIN_FILE=${Daemon_SOURCE_DIR}/cmake/cross-toolchain-saigo-${nacl_target}.cmake" + "-DSAIGOSDK_PREFIX=${SAIGOSDK_PREFIX}" + -DUSE_NACL_SAIGO=ON -DBUILD_GAME_NACL=ON -DBUILD_GAME_NATIVE_DLL=OFF -DBUILD_GAME_NATIVE_EXE=OFF -DUSE_NACL_SAIGO=ON - -DSAIGO_ARCH=${SAIGO_ARCH} - -DNACL_TARGET=${NACL_TARGET} ) endforeach() else() @@ -257,19 +258,21 @@ function(GAMEMODULE) string(REPLACE ";" "," NACL_TARGETS_STRING "${NACL_TARGETS}") gameSubProject( - -DCMAKE_TOOLCHAIN_FILE=${Daemon_SOURCE_DIR}/cmake/toolchain-pnacl.cmake + "-DCMAKE_TOOLCHAIN_FILE=${Daemon_SOURCE_DIR}/cmake/cross-toolchain-pnacl.cmake" + "-DPNACLSDK_PREFIX=${PNACLSDK_PREFIX}" + -DUSE_NACL_SAIGO=OFF -DBUILD_GAME_NACL=ON -DBUILD_GAME_NATIVE_DLL=OFF -DBUILD_GAME_NATIVE_EXE=OFF - -DNACL_TARGETS_STRING=${NACL_TARGETS_STRING} + "-DNACL_TARGETS_STRING=${NACL_TARGETS_STRING}" ) endif() endif() set(NACL_VMS_PROJECTS ${NACL_VMS_PROJECTS} PARENT_SCOPE) - elseif (FORK EQUAL 2) # we are in the CMake sub-invocation for NaCl + elseif (GAME_BUILD_SUBINVOCATION) if (BUILD_GAME_NACL) - if (USE_NACL_SAIGO) + if (YOKAI_CXX_COMPILER_SAIGO) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) else() # Put the .nexe and .pexe files in the same directory as the engine. @@ -278,16 +281,28 @@ function(GAMEMODULE) buildGameModule("nacl") - if (USE_NACL_SAIGO) + if (YOKAI_CXX_COMPILER_SAIGO) + include(DaemonSaigoFinalize) + # Finalize NaCl executables for supported architectures. - saigo_finalize(${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/.. ${GAMEMODULE_NAME} ${NACL_TARGET}) + saigo_finalize( + "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" + "${GAMEMODULE_NAME}" + "${YOKAI_TARGET_ARCH_NAME}" + ) else() + include(DaemonPNaClFinalize) + # Revert a workaround for a bug where CMake ExternalProject lists-as-args are cut on first “;” string(REPLACE "," ";" NACL_TARGETS "${NACL_TARGETS_STRING}") # Generate NaCl executables for supported architectures. - foreach(NACL_TARGET ${NACL_TARGETS}) - pnacl_finalize(${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${GAMEMODULE_NAME} ${NACL_TARGET}) + foreach(nacl_target ${NACL_TARGETS}) + pnacl_finalize( + "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" + "${GAMEMODULE_NAME}" + "${nacl_target}" + ) endforeach() endif() endif() diff --git a/cmake/DaemonNacl.cmake b/cmake/DaemonNacl.cmake deleted file mode 100644 index e37bf06844..0000000000 --- a/cmake/DaemonNacl.cmake +++ /dev/null @@ -1,81 +0,0 @@ -# Daemon BSD Source Code -# Copyright (c) 2013-2016, Daemon Developers -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# * Neither the name of the Daemon developers nor the -# names of its contributors may be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY -# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -# Native client - -option(USE_NACL_SAIGO "Use Saigo toolchain to build NaCl executables" OFF) - -if (YOKAI_TARGET_SYSTEM_NACL) - # Build nexe binary. - if(USE_NACL_SAIGO) - if (NACL_TARGET STREQUAL "amd64") - add_definitions(-DNACL_BUILD_ARCH=x86) - add_definitions(-DNACL_BUILD_SUBARCH=64) - elseif (NACL_TARGET STREQUAL "i686") - add_definitions(-DNACL_BUILD_ARCH=x86) - add_definitions(-DNACL_BUILD_SUBARCH=32) - elseif (NACL_TARGET STREQUAL "armhf") - add_definitions(-DNACL_BUILD_ARCH=arm) - else() - message(FATAL_ERROR "Unsupported architecture ${NACL_TARGET}") - endif() - else() - # Those defines looks to be meaningless to produce arch-independent pexe - # with PNaCl but they must be set to anything supported by native builds. - # This requirement looks to be a PNaCl bug. - add_definitions( -DNACL_BUILD_ARCH=x86 ) - add_definitions( -DNACL_BUILD_SUBARCH=64 ) - endif() -else() - # Build native dll or native exe. - if (YOKAI_TARGET_SYSTEM_MACOS) - add_definitions( -DNACL_WINDOWS=0 -DNACL_LINUX=0 -DNACL_ANDROID=0 -DNACL_FREEBSD=0 -DNACL_OSX=1 ) - elseif (YOKAI_TARGET_SYSTEM_LINUX) - add_definitions( -DNACL_WINDOWS=0 -DNACL_LINUX=1 -DNACL_ANDROID=0 -DNACL_FREEBSD=0 -DNACL_OSX=0 ) - elseif (YOKAI_TARGET_SYSTEM_FREEBSD) - add_definitions( -DNACL_WINDOWS=0 -DNACL_LINUX=0 -DNACL_ANDROID=0 -DNACL_FREEBSD=1 -DNACL_OSX=0 ) - elseif (YOKAI_TARGET_SYSTEM_WINDOWS) - add_definitions( -DNACL_WINDOWS=1 -DNACL_LINUX=0 -DNACL_ANDROID=0 -DNACL_FREEBSD=0 -DNACL_OSX=0 ) - endif() - - if (YOKAI_TARGET_ARCH_AMD64) - add_definitions( -DNACL_BUILD_ARCH=x86 ) - add_definitions( -DNACL_BUILD_SUBARCH=64 ) - elseif (YOKAI_TARGET_ARCH_I686) - add_definitions( -DNACL_BUILD_ARCH=x86 ) - add_definitions( -DNACL_BUILD_SUBARCH=32 ) - elseif (YOKAI_TARGET_ARCH_ARMHF) - add_definitions( -DNACL_BUILD_ARCH=arm ) - else() - # NaCl does not support this architecture natively, but these defines must - # be set because nacl_config.h is included unconditionally. Use dummy x86 - # values as PNaCl does for architecture-independent builds. - add_definitions( -DNACL_BUILD_ARCH=x86 ) - add_definitions( -DNACL_BUILD_SUBARCH=64 ) - endif() -endif() - -include_directories( ${LIB_DIR}/nacl ) diff --git a/cmake/DaemonNaclFlags.cmake b/cmake/DaemonNaclFlags.cmake new file mode 100644 index 0000000000..cbdc4b5a3f --- /dev/null +++ b/cmake/DaemonNaclFlags.cmake @@ -0,0 +1,75 @@ +# Daemon BSD Source Code +# Copyright (c) 2013-2026, Daemon Developers +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the Daemon developers nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Native Client build configuration. + +if (YOKAI_TARGET_SYSTEM_NACL) + # Build nexe binary. + + if (YOKAI_CXX_COMPILER_SAIGO) + if (YOKAI_TARGET_ARCH_AMD64) + add_definitions(-DNACL_BUILD_ARCH=x86 -DNACL_BUILD_SUBARCH=64) + elseif (YOKAI_TARGET_ARCH_I686) + add_definitions(-DNACL_BUILD_ARCH=x86 -DNACL_BUILD_SUBARCH=32) + elseif (YOKAI_TARGET_ARCH_ARMHF) + add_definitions(-DNACL_BUILD_ARCH=arm) + else() + message(FATAL_ERROR "Unsupported architecture ${NACL_TARGET}") + endif() + else() + # Those defines looks to be meaningless to produce arch-independent pexe + # with PNaCl but they must be set to anything supported by native builds. + # This requirement looks to be a PNaCl bug. + add_definitions(-DNACL_BUILD_ARCH=x86 -DNACL_BUILD_SUBARCH=64) + endif() +else() + # Build native dll or native exe. + + if (YOKAI_TARGET_SYSTEM_MACOS) + add_definitions(-DNACL_WINDOWS=0 -DNACL_LINUX=0 -DNACL_ANDROID=0 -DNACL_FREEBSD=0 -DNACL_OSX=1) + elseif (YOKAI_TARGET_SYSTEM_LINUX) + add_definitions(-DNACL_WINDOWS=0 -DNACL_LINUX=1 -DNACL_ANDROID=0 -DNACL_FREEBSD=0 -DNACL_OSX=0) + elseif (YOKAI_TARGET_SYSTEM_FREEBSD) + add_definitions(-DNACL_WINDOWS=0 -DNACL_LINUX=0 -DNACL_ANDROID=0 -DNACL_FREEBSD=1 -DNACL_OSX=0) + elseif (YOKAI_TARGET_SYSTEM_WINDOWS) + add_definitions(-DNACL_WINDOWS=1 -DNACL_LINUX=0 -DNACL_ANDROID=0 -DNACL_FREEBSD=0 -DNACL_OSX=0) + endif() + + if (YOKAI_TARGET_ARCH_AMD64) + add_definitions(-DNACL_BUILD_ARCH=x86 -DNACL_BUILD_SUBARCH=64) + elseif (YOKAI_TARGET_ARCH_I686) + add_definitions(-DNACL_BUILD_ARCH=x86 -DNACL_BUILD_SUBARCH=32) + elseif (YOKAI_TARGET_ARCH_ARMHF) + add_definitions(-DNACL_BUILD_ARCH=arm) + else() + # NaCl does not support this architecture natively, but these defines must + # be set because nacl_config.h is included unconditionally. Use dummy x86 + # values as PNaCl does for architecture-independent builds. + add_definitions(-DNACL_BUILD_ARCH=x86 -DNACL_BUILD_SUBARCH=64) + endif() +endif() + +include_directories(${LIB_DIR}/nacl) diff --git a/cmake/DaemonPNaClFinalize.cmake b/cmake/DaemonPNaClFinalize.cmake new file mode 100644 index 0000000000..2130490030 --- /dev/null +++ b/cmake/DaemonPNaClFinalize.cmake @@ -0,0 +1,79 @@ +# Daemon BSD Source Code +# Copyright (c) 2013-2026, Daemon Developers +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the Daemon developers nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +function(pnacl_finalize dir module arch) + include(DaemonBuildTypeGeneratorExpression) + + set(PNACL_TRANSLATE_OPTIONS + --allow-llvm-bitcode-input # FIXME: finalize as part of the build process + --pnacl-allow-exceptions + $<${RELEASE_GENEXP_COND}:-O3> + $<${DEBUG_GENEXP_COND}:-O0> + $<${RELWITHDEBINFO_GENEXP_COND}:-O2> + $<${MINSIZEREL_GENEXP_COND}:-O2> + ) + set(PEXE "${dir}/${module}${NACL_EXECUTABLE_SUFFIX}") + set(NEXE "${dir}/${module}-${arch}${NACL_TRANSLATED_EXECUTABLE_SUFFIX}") + set(STRIPPED_NEXE "${dir}/${module}-${arch}-stripped${NACL_TRANSLATED_EXECUTABLE_SUFFIX}") + + if (arch STREQUAL "i686") + set(PNACL_ARCH "i686") + elseif (arch STREQUAL "amd64") + set(PNACL_ARCH "x86-64") + elseif (arch STREQUAL "armhf") + set(PNACL_ARCH "arm") + else() + message(FATAL_ERROR "Unknown NaCl architecture ${arch}") + endif() + + add_custom_command( + OUTPUT ${NEXE} + COMMENT "Translating ${module} (${arch})" + DEPENDS ${PEXE} + COMMAND + ${PNACLPYTHON_PREFIX2} + "${PNACL_TRANSLATE}" + ${PNACL_TRANSLATE_OPTIONS} + -arch "${PNACL_ARCH}" + "${PEXE}" + -o "${NEXE}" + ) + + add_custom_command( + OUTPUT "${STRIPPED_NEXE}" + COMMENT "Stripping ${module} (${arch})" + DEPENDS "${NEXE}" + COMMAND + ${PNACLPYTHON_PREFIX2} + "${CMAKE_STRIP}" + -s + "${NEXE}" + -o "${STRIPPED_NEXE}" + ) + + add_custom_target("${module}-${arch}" ALL DEPENDS "${STRIPPED_NEXE}") + add_dependencies("${module}-${arch}" "${module}-nacl") +endfunction() diff --git a/cmake/DaemonSaigoFinalize.cmake b/cmake/DaemonSaigoFinalize.cmake new file mode 100644 index 0000000000..01f1cf1da5 --- /dev/null +++ b/cmake/DaemonSaigoFinalize.cmake @@ -0,0 +1,56 @@ +# Daemon BSD Source Code +# Copyright (c) 2023-2026, Daemon Developers +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the Daemon developers nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +function(saigo_finalize dir module arch) + set(SUBPROJECT_NEXE "${dir}/${module}${NACL_EXECUTABLE_SUFFIX}") + set(NEXE "${dir}/../${module}-${arch}${NACL_EXECUTABLE_SUFFIX}") + set(STRIPPED_NEXE "${dir}/../${module}-${arch}-stripped${NACL_EXECUTABLE_SUFFIX}") + + add_custom_command( + OUTPUT "${NEXE}" + COMMENT "Copying ${module} (${arch})" + DEPENDS "${SUBPROJECT_NEXE}" + COMMAND + ${CMAKE_COMMAND} + -E copy + "${SUBPROJECT_NEXE}" + "${NEXE}" + ) + + add_custom_command( + OUTPUT "${STRIPPED_NEXE}" + COMMENT "Stripping ${module} (${arch})" + DEPENDS "${NEXE}" + COMMAND + "${CMAKE_STRIP}" + -s + "${NEXE}" + -o "${STRIPPED_NEXE}" + ) + + add_custom_target("${module}-${arch}" ALL DEPENDS "${STRIPPED_NEXE}") + add_dependencies("${module}-${arch}" "${module}-nacl") +endfunction() diff --git a/cmake/cross-toolchain-pnacl.cmake b/cmake/cross-toolchain-pnacl.cmake new file mode 100644 index 0000000000..eb71dbc5cc --- /dev/null +++ b/cmake/cross-toolchain-pnacl.cmake @@ -0,0 +1,106 @@ +# Daemon BSD Source Code +# Copyright (c) 2013-2026, Daemon Developers +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the Daemon developers nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# We can't use CMAKE_EXECUTABLE_SUFFIX because the Generic Platform will reset it +# and creating a Platform module for setting CMAKE_EXECUTABLE_SUFFIX is overkill. +set(NACL_EXECUTABLE_SUFFIX ".pexe") +set(NACL_TRANSLATED_EXECUTABLE_SUFFIX ".nexe") + +if (CMAKE_HOST_WIN32) + set(PNACL_EXECUTABLE_SUFFIX ".bat") +else() + set(PNACL_EXECUTABLE_SUFFIX "") +endif() + +set(PNACL_TRIPLET "pnacl") + +if ("${PNACLSDK_PREFIX}" STREQUAL "") + find_program(PATH_PNACL_CLANG NAMES "${PNACL_TRIPLET}-clang${PNACL_EXECUTABLE_SUFFIX}") + get_filename_component(PNACLSDK_PREFIX ${PATH_PNACL_CLANG} DIRECTORY) +endif() + +list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES PNACLSDK_PREFIX) + +set(CMAKE_SYSTEM_NAME "Generic") + +set(CMAKE_C_COMPILER "${PNACLSDK_PREFIX}/bin/${PNACL_TRIPLET}-clang${PNACL_EXECUTABLE_SUFFIX}") +set(CMAKE_CXX_COMPILER "${PNACLSDK_PREFIX}/bin/${PNACL_TRIPLET}-clang++${PNACL_EXECUTABLE_SUFFIX}") +set(CMAKE_AR "${PNACLSDK_PREFIX}/bin/${PNACL_TRIPLET}-ar${PNACL_EXECUTABLE_SUFFIX}" CACHE FILEPATH "Archiver" FORCE) +set(CMAKE_RANLIB "${PNACLSDK_PREFIX}/bin/${PNACL_TRIPLET}-ranlib${PNACL_EXECUTABLE_SUFFIX}") +set(PNACL_TRANSLATE "${PNACLSDK_PREFIX}/bin/${PNACL_TRIPLET}-translate${PNACL_EXECUTABLE_SUFFIX}") +set(CMAKE_STRIP "${PNACLSDK_PREFIX}/bin/${PNACL_TRIPLET}-strip${PNACL_EXECUTABLE_SUFFIX}") +set(CMAKE_FIND_ROOT_PATH "${PNACLSDK_PREFIX}/le32-nacl") + +set(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES 1) +set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES 1) +set(CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS 1) +set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS 1) +set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES 1) +set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 1) +set(CMAKE_C_RESPONSE_FILE_LINK_FLAG "@") +set(CMAKE_CXX_RESPONSE_FILE_LINK_FLAG "@") + +set(CMAKE_C_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG") +set(CMAKE_C_FLAGS_RELEASE_INIT "-O3 -DNDEBUG") +set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O2 -g -DNDEBUG") +set(CMAKE_C_FLAGS_DEBUG_INIT "-g") + +set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "${CMAKE_C_FLAGS_MINSIZEREL_INIT}") +set(CMAKE_CXX_FLAGS_RELEASE_INIT "${CMAKE_C_FLAGS_RELEASE_INIT}") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "${CMAKE_C_FLAGS_RELWITHDEBINFO_INIT}") +set(CMAKE_CXX_FLAGS_DEBUG_INIT "${CMAKE_C_FLAGS_DEBUG_INIT}") + +if (NOT CMAKE_HOST_WIN32) + find_package(Python) + + if (Python_Interpreter_FOUND) + set(PNACLPYTHON_PREFIX "env PNACLPYTHON=${Python_EXECUTABLE} ") + set(PNACLPYTHON_PREFIX2 env "PNACLPYTHON=${Python_EXECUTABLE} ") + message(STATUS "Using PNACL Python executable: ${Python_EXECUTABLE}") + else() + message(FATAL_ERROR "Please install python (and run in a python virtualenv if that's not enough).") + endif() +endif() + +# These commands can fail on windows if there is a space at the beginning +set(CMAKE_C_CREATE_STATIC_LIBRARY "${PNACLPYTHON_PREFIX} rc ") +set(CMAKE_CXX_CREATE_STATIC_LIBRARY "${PNACLPYTHON_PREFIX} rc ") + +set(CMAKE_C_COMPILE_OBJECT "${PNACLPYTHON_PREFIX} -o -c ") +set(CMAKE_CXX_COMPILE_OBJECT "${PNACLPYTHON_PREFIX} -o -c ") + +set(CMAKE_C_LINK_EXECUTABLE "${PNACLPYTHON_PREFIX} -o ") +set(CMAKE_CXX_LINK_EXECUTABLE "${PNACLPYTHON_PREFIX} -o ") + +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) + +set(NACL ON) + +set(CMAKE_C_FLAGS "") +set(CMAKE_CXX_FLAGS "") diff --git a/cmake/cross-toolchain-saigo-amd64.cmake b/cmake/cross-toolchain-saigo-amd64.cmake new file mode 100644 index 0000000000..c755d9b2b1 --- /dev/null +++ b/cmake/cross-toolchain-saigo-amd64.cmake @@ -0,0 +1,28 @@ +# Daemon BSD Source Code +# Copyright (c) 2026, Daemon Developers +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the Daemon developers nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +set(SAIGO_ARCH "x86_64") +include("${CMAKE_CURRENT_LIST_DIR}/cross-toolchain-saigo-common.cmake") diff --git a/cmake/cross-toolchain-saigo-armhf.cmake b/cmake/cross-toolchain-saigo-armhf.cmake new file mode 100644 index 0000000000..7197c47049 --- /dev/null +++ b/cmake/cross-toolchain-saigo-armhf.cmake @@ -0,0 +1,28 @@ +# Daemon BSD Source Code +# Copyright (c) 2026, Daemon Developers +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the Daemon developers nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +set(SAIGO_ARCH "arm") +include("${CMAKE_CURRENT_LIST_DIR}/cross-toolchain-saigo-common.cmake") diff --git a/cmake/cross-toolchain-saigo-common.cmake b/cmake/cross-toolchain-saigo-common.cmake new file mode 100644 index 0000000000..0c7a928e40 --- /dev/null +++ b/cmake/cross-toolchain-saigo-common.cmake @@ -0,0 +1,79 @@ +# Daemon BSD Source Code +# Copyright (c) 2023-2026, Daemon Developers +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the Daemon developers nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# We can't use CMAKE_EXECUTABLE_SUFFIX because the Generic Platform will reset it +# and creating a Platform module for setting CMAKE_EXECUTABLE_SUFFIX is overkill. +set(NACL_EXECUTABLE_SUFFIX ".nexe") + +set(SAIGO_TRIPLET "${SAIGO_ARCH}-nacl") + +if ("${SAIGOSDK_PREFIX}" STREQUAL "") + find_program(PATH_SAIGO_CLANG NAMES "${SAIGO_TRIPLET}-clang") + get_filename_component(SAIGOSDK_PREFIX ${PATH_SAIGO_CLANG} DIRECTORY) +endif() + +list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES SAIGOSDK_PREFIX) + +set(CMAKE_SYSTEM_NAME "Generic") + +set(CMAKE_C_COMPILER "${SAIGOSDK_PREFIX}/bin/${SAIGO_TRIPLET}-clang") +set(CMAKE_CXX_COMPILER "${SAIGOSDK_PREFIX}/bin/${SAIGO_TRIPLET}-clang++") +set(CMAKE_AR "${SAIGOSDK_PREFIX}/bin/${SAIGO_TRIPLET}-ar" CACHE FILEPATH "Archiver" FORCE) +set(CMAKE_RANLIB "${SAIGOSDK_PREFIX}/bin/${SAIGO_TRIPLET}-ranlib") +set(CMAKE_STRIP "${SAIGOSDK_PREFIX}/bin/${SAIGO_TRIPLET}-strip") +set(CMAKE_FIND_ROOT_PATH "${SAIGOSDK_PREFIX}/${SAIGO_TRIPLET}") + +# Copy-pasted from the PNaCl toolchain, it's not sure we need it. +set(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES 1) +set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES 1) +set(CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS 1) +set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS 1) +set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES 1) +set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 1) +set(CMAKE_C_RESPONSE_FILE_LINK_FLAG "@") +set(CMAKE_CXX_RESPONSE_FILE_LINK_FLAG "@") + +# Copy-pasted from the PNaCl toolchain, it's not sure we need it. +# These commands can fail on windows if there is a space at the beginning +set(CMAKE_C_CREATE_STATIC_LIBRARY " rc ") +set(CMAKE_CXX_CREATE_STATIC_LIBRARY " rc ") + +set(CMAKE_C_COMPILE_OBJECT " -o -c ") +set(CMAKE_CXX_COMPILE_OBJECT " -o -c ") + +set(CMAKE_C_LINK_EXECUTABLE " -o ") +set(CMAKE_CXX_LINK_EXECUTABLE " -o ") + +# Copy-pasted from the PNaCl toolchain, it's not sure we need it. +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) + +set(NACL ON) + +set(CMAKE_C_FLAGS "") +set(CMAKE_CXX_FLAGS "") diff --git a/cmake/cross-toolchain-saigo-i686.cmake b/cmake/cross-toolchain-saigo-i686.cmake new file mode 100644 index 0000000000..1bd9b1f0c5 --- /dev/null +++ b/cmake/cross-toolchain-saigo-i686.cmake @@ -0,0 +1,39 @@ +# Daemon BSD Source Code +# Copyright (c) 2026, Daemon Developers +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the Daemon developers nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +set(SAIGO_ARCH "i686") +include("${CMAKE_CURRENT_LIST_DIR}/cross-toolchain-saigo-common.cmake") + +if (EXISTS "${SAIGOSDK_PREFIX}/x86_64-nacl/lib32") + # This will search libraries in paths in this order: + # - i686-nacl/lib + # - x86_64-nacl/lib32 + # - x86_64-nacl/lib + # The last path is wrong but is not used when the lib is found before, + # so it is meant to work on well-formed SDK installations. + list(APPEND CMAKE_FIND_ROOT_PATH "${SAIGOSDK_PREFIX}/x86_64-nacl") + set(CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX "32") +endif() diff --git a/cmake/toolchain-pnacl.cmake b/cmake/toolchain-pnacl.cmake deleted file mode 100644 index b19f61e8ec..0000000000 --- a/cmake/toolchain-pnacl.cmake +++ /dev/null @@ -1,151 +0,0 @@ -# Daemon BSD Source Code -# Copyright (c) 2013-2016, Daemon Developers -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# * Neither the name of the Daemon developers nor the -# names of its contributors may be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY -# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -set(PLATFORM_PREFIX ${DEPS_DIR}/pnacl/bin) -set(PLATFORM_TRIPLET "pnacl") - -if (WIN32) - set(PNACL_BIN_EXT ".bat") -else() - set(PNACL_BIN_EXT "") -endif() - -set(PLATFORM_EXE_SUFFIX ".pexe") - -set(CMAKE_SYSTEM_NAME "Generic") - -set(CMAKE_C_COMPILER "${PLATFORM_PREFIX}/${PLATFORM_TRIPLET}-clang${PNACL_BIN_EXT}") -set(CMAKE_CXX_COMPILER "${PLATFORM_PREFIX}/${PLATFORM_TRIPLET}-clang++${PNACL_BIN_EXT}") -set(CMAKE_AR "${PLATFORM_PREFIX}/${PLATFORM_TRIPLET}-ar${PNACL_BIN_EXT}" CACHE FILEPATH "Archiver" FORCE) -set(CMAKE_RANLIB "${PLATFORM_PREFIX}/${PLATFORM_TRIPLET}-ranlib${PNACL_BIN_EXT}") -set(PNACL_TRANSLATE "${PLATFORM_PREFIX}/${PLATFORM_TRIPLET}-translate${PNACL_BIN_EXT}") -set(PNACL_STRIP "${PLATFORM_PREFIX}/${PLATFORM_TRIPLET}-strip${PNACL_BIN_EXT}") -set(CMAKE_FIND_ROOT_PATH "${PLATFORM_PREFIX}/../le32-nacl") - -set(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES 1) -set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES 1) -set(CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS 1) -set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS 1) -set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES 1) -set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 1) -set(CMAKE_C_RESPONSE_FILE_LINK_FLAG "@") -set(CMAKE_CXX_RESPONSE_FILE_LINK_FLAG "@") - -set(CMAKE_C_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG") -set(CMAKE_C_FLAGS_RELEASE_INIT "-O3 -DNDEBUG") -set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O2 -g -DNDEBUG") -set(CMAKE_C_FLAGS_DEBUG_INIT "-g") - -set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "${CMAKE_C_FLAGS_MINSIZEREL_INIT}") -set(CMAKE_CXX_FLAGS_RELEASE_INIT "${CMAKE_C_FLAGS_RELEASE_INIT}") -set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "${CMAKE_C_FLAGS_RELWITHDEBINFO_INIT}") -set(CMAKE_CXX_FLAGS_DEBUG_INIT "${CMAKE_C_FLAGS_DEBUG_INIT}") - -if (NOT CMAKE_HOST_WIN32) - find_package(Python) - - if (Python_Interpreter_FOUND) - set(PNACLPYTHON_PREFIX "env PNACLPYTHON=${Python_EXECUTABLE} ") - set(PNACLPYTHON_PREFIX2 env "PNACLPYTHON=${Python_EXECUTABLE} ") - message(STATUS "Using PNACL Python executable: ${Python_EXECUTABLE}") - else() - message(FATAL_ERROR "Please install python (and run in a python virtualenv if that's not enough).") - endif() -endif() - -# These commands can fail on windows if there is a space at the beginning -set(CMAKE_C_CREATE_STATIC_LIBRARY "${PNACLPYTHON_PREFIX} rc ") -set(CMAKE_CXX_CREATE_STATIC_LIBRARY "${PNACLPYTHON_PREFIX} rc ") - -set(CMAKE_C_COMPILE_OBJECT "${PNACLPYTHON_PREFIX} -o -c ") -set(CMAKE_CXX_COMPILE_OBJECT "${PNACLPYTHON_PREFIX} -o -c ") - -set(CMAKE_C_LINK_EXECUTABLE "${PNACLPYTHON_PREFIX} -o ") -set(CMAKE_CXX_LINK_EXECUTABLE "${PNACLPYTHON_PREFIX} -o ") - -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) - -set(NACL ON) - -set(CMAKE_C_FLAGS "") -set(CMAKE_CXX_FLAGS "") - -function(pnacl_finalize dir module arch) - include(DaemonBuildTypeGeneratorExpression) - - set(PNACL_TRANSLATE_OPTIONS - --allow-llvm-bitcode-input # FIXME: finalize as part of the build process - --pnacl-allow-exceptions - $<${RELEASE_GENEXP_COND}:-O3> - $<${DEBUG_GENEXP_COND}:-O0> - $<${RELWITHDEBINFO_GENEXP_COND}:-O2> - $<${MINSIZEREL_GENEXP_COND}:-O2> - ) - set(PEXE ${dir}/${module}.pexe) - set(NEXE ${dir}/${module}-${arch}.nexe) - set(STRIPPED_NEXE ${dir}/${module}-${arch}-stripped.nexe) - - if (arch STREQUAL "i686") - set(PNACL_ARCH "i686") - elseif (arch STREQUAL "amd64") - set(PNACL_ARCH "x86-64") - elseif (arch STREQUAL "armhf") - set(PNACL_ARCH "arm") - else() - message(FATAL_ERROR "Unknown NaCl architecture ${arch}") - endif() - - add_custom_command( - OUTPUT ${NEXE} - COMMENT "Translating ${module} (${arch})" - DEPENDS ${PEXE} - COMMAND - ${PNACLPYTHON_PREFIX2} - "${PNACL_TRANSLATE}" - ${PNACL_TRANSLATE_OPTIONS} - -arch ${PNACL_ARCH} - ${PEXE} - -o ${NEXE} - ) - - add_custom_command( - OUTPUT ${STRIPPED_NEXE} - COMMENT "Stripping ${module} (${arch})" - DEPENDS ${NEXE} - COMMAND - ${PNACLPYTHON_PREFIX2} - "${PNACL_STRIP}" - -s - ${NEXE} - -o ${STRIPPED_NEXE} - ) - - add_custom_target(${module}-${arch} ALL DEPENDS ${STRIPPED_NEXE}) - add_dependencies(${module}-${arch} ${module}-nacl) -endfunction() diff --git a/cmake/toolchain-saigo.cmake b/cmake/toolchain-saigo.cmake deleted file mode 100644 index 75374527b3..0000000000 --- a/cmake/toolchain-saigo.cmake +++ /dev/null @@ -1,75 +0,0 @@ -set(PLATFORM_PREFIX "${DEPS_DIR}/saigo_newlib/bin") -set(PLATFORM_TRIPLET "${SAIGO_ARCH}-nacl") -set(PLATFORM_EXE_SUFFIX ".nexe") - -set(CMAKE_SYSTEM_NAME "Generic") - -set(CMAKE_C_COMPILER "${PLATFORM_PREFIX}/${PLATFORM_TRIPLET}-clang") -set(CMAKE_CXX_COMPILER "${PLATFORM_PREFIX}/${PLATFORM_TRIPLET}-clang++") -set(CMAKE_AR "${PLATFORM_PREFIX}/${PLATFORM_TRIPLET}-ar" CACHE FILEPATH "Archiver" FORCE) -set(CMAKE_RANLIB "${PLATFORM_PREFIX}/${PLATFORM_TRIPLET}-ranlib") -set(SAIGO_STRIP "${PLATFORM_PREFIX}/${PLATFORM_TRIPLET}-strip") -set(CMAKE_FIND_ROOT_PATH "${PLATFORM_PREFIX}/../${PLATFORM_TRIPLET}") - -# Copy-pasted from the PNaCl toolchain, it's not sure we need it. -set(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES 1) -set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES 1) -set(CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS 1) -set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS 1) -set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES 1) -set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 1) -set(CMAKE_C_RESPONSE_FILE_LINK_FLAG "@") -set(CMAKE_CXX_RESPONSE_FILE_LINK_FLAG "@") - -# Copy-pasted from the PNaCl toolchain, it's not sure we need it. -# These commands can fail on windows if there is a space at the beginning -set(CMAKE_C_CREATE_STATIC_LIBRARY " rc ") -set(CMAKE_CXX_CREATE_STATIC_LIBRARY " rc ") - -set(CMAKE_C_COMPILE_OBJECT " -o -c ") -set(CMAKE_CXX_COMPILE_OBJECT " -o -c ") - -set(CMAKE_C_LINK_EXECUTABLE " -o ") -set(CMAKE_CXX_LINK_EXECUTABLE " -o ") - -# Copy-pasted from the PNaCl toolchain, it's not sure we need it. -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) - -set(NACL ON) - -set(CMAKE_C_FLAGS "") -set(CMAKE_CXX_FLAGS "") - -function(saigo_finalize dir module arch) - set(SUBPROJECT_NEXE ${dir}/nacl-vms-${arch}/${module}.nexe) - set(NEXE ${dir}/${module}-${arch}.nexe) - set(STRIPPED_NEXE ${dir}/${module}-${arch}-stripped.nexe) - - add_custom_command( - OUTPUT ${NEXE} - COMMENT "Copying ${module} (${arch})" - DEPENDS ${SUBPROJECT_NEXE} - COMMAND - ${CMAKE_COMMAND} - -E copy - ${SUBPROJECT_NEXE} - ${NEXE} - ) - - add_custom_command( - OUTPUT ${STRIPPED_NEXE} - COMMENT "Stripping ${module} (${arch})" - DEPENDS ${NEXE} - COMMAND - "${SAIGO_STRIP}" - -s - ${NEXE} - -o ${STRIPPED_NEXE} - ) - - add_custom_target(${module}-${arch} ALL DEPENDS ${STRIPPED_NEXE}) - add_dependencies(${module}-${arch} ${module}-nacl) -endfunction() From 34b2e30e1c127571f4a6f7c76ec1a9d05c577fcd Mon Sep 17 00:00:00 2001 From: slipher Date: Thu, 30 Jul 2026 10:16:01 -0500 Subject: [PATCH 17/61] Refactor: function for Linux arm64 check for VM Co-authored-by: Thomas Debesse --- src/engine/framework/VirtualMachine.cpp | 29 +++++++++++++++---------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/engine/framework/VirtualMachine.cpp b/src/engine/framework/VirtualMachine.cpp index 8ddab6486f..c8445dff27 100644 --- a/src/engine/framework/VirtualMachine.cpp +++ b/src/engine/framework/VirtualMachine.cpp @@ -226,6 +226,22 @@ static void CheckMinAddressSysctlTooLarge() #endif // __linux__ } +#if defined(DAEMON_NACL_RUNTIME_LINUX) && (defined(YOKAI_ARCH_ARM64) || defined(YOKAI_ARCH_ARMHF)) +static bool OnArm64() +{ +#if defined(YOKAI_ARCH_ARM64) + return true; +#elif defined(YOKAI_ARCH_ARMHF) + struct utsname buf; + if (!uname(&buf)) { + return !strcmp(buf.machine, "aarch64"); + } + + return false; +#endif // defined(YOKAI_ARCH_ARMHF) +} +#endif + // Platform-specific code to load a module static std::pair InternalLoadModule(std::pair pair, const char* const* args, bool reserve_mem, FS::File stderrRedirect = FS::File(), bool inheritEnvironment = false) { @@ -630,17 +646,6 @@ static std::pair CreateNaClVM(std::pair CreateNaClVM(std::pair Date: Thu, 30 Jul 2026 11:28:20 -0500 Subject: [PATCH 18/61] Get rid of nacl_multiarch executable Set up the chdir and environment variable in posix_spawn. Fixes #1336. Co-authored-by: Thomas Debesse --- CMakeLists.txt | 8 +-- cmake/DaemonNaclArchitecture.cmake | 2 - src/engine/framework/VirtualMachine.cpp | 35 ++++--------- tools/nacl_multiarch/nacl_multiarch.cpp | 68 ------------------------- 4 files changed, 12 insertions(+), 101 deletions(-) delete mode 100644 tools/nacl_multiarch/nacl_multiarch.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f012339cb3..83ccdbfe1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1000,15 +1000,9 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER # Linux uses a bootstrap program to reserve address space if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY) if (DAEMON_NACL_MULTIARCH) - add_executable(nacl_multiarch-${DAEMON_NACL_ARCH_NAME} - tools/nacl_multiarch/nacl_multiarch.cpp - ${BUILDINFOLIST} - ) - add_dependencies(runtime_deps nacl_multiarch-${DAEMON_NACL_ARCH_NAME}) - add_custom_command(TARGET runtime_deps PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory - ${DEPS_DIR}/linux-${DAEMON_NACL_ARCH_NAME} + ${DEPS_DIR}/libs-${DAEMON_NACL_ARCH_NAME} ${FULL_OUTPUT_DIR}/libs-linux-${DAEMON_NACL_ARCH_NAME} ) endif() diff --git a/cmake/DaemonNaclArchitecture.cmake b/cmake/DaemonNaclArchitecture.cmake index e0666c193b..f23685f86f 100644 --- a/cmake/DaemonNaclArchitecture.cmake +++ b/cmake/DaemonNaclArchitecture.cmake @@ -49,8 +49,6 @@ function(daemon_detect_nacl_arch target_arch) set(box64_usage "ppc64el" "riscv64" "loong64") if ("${target_arch}" IN_LIST armhf_usage) - set(DAEMON_NACL_MULTIARCH ON) - # Load 32-bit armhf nexe on 64-bit arm64 engine on Linux with multiarch. # The nexe is system agnostic so there should be no difference with armel. add_nacl_arch("armhf") diff --git a/src/engine/framework/VirtualMachine.cpp b/src/engine/framework/VirtualMachine.cpp index c8445dff27..6508acc659 100644 --- a/src/engine/framework/VirtualMachine.cpp +++ b/src/engine/framework/VirtualMachine.cpp @@ -183,15 +183,6 @@ static Cvar::Cvar vm_nacl_qualification( Cvar::INIT, true); #endif // defined(DAEMON_NACL_RUNTIME_ENABLED) -#if defined(DAEMON_NACL_RUNTIME_ENABLED) -#if defined(DAEMON_NACL_RUNTIME_LINUX) && defined(YOKAI_ARCH_ARM64) -static Cvar::Cvar vm_nacl_multiarch( - "vm.nacl.multiarch", - "Use multiarch to run the NaCl loader when needed and available", - Cvar::INIT, true); -#endif // defined(DAEMON_NACL_RUNTIME_LINUX) && defined(YOKAI_ARCH_ARM64) -#endif // defined(DAEMON_NACL_RUNTIME_ENABLED) - #if defined(DAEMON_NACL_BOOSTRAP_ENABLED) static Cvar::Cvar vm_nacl_bootstrap( "vm.nacl.bootstrap", @@ -349,11 +340,20 @@ static std::pair InternalLoadModule(std::pair("LD_LIBRARY_PATH=lib-armhf"); + + if (0 != posix_spawn_file_actions_addchdir_np(&fileActions, FS::GetLibPath().c_str())) { + Sys::Error("failed posix_spawn_file_actions_addchdir"); + } + } +#endif // By default, the child process gets an empty environment for sandboxing. // When Box64 emulation is used, the child needs to inherit the parent's // environment so Box64 can find its configuration (e.g. ~/.box64rc, HOME) // and honor settings like BOX64_DYNAREC_PERFMAP. - char* emptyEnv[] = {nullptr}; char** envp = inheritEnvironment ? environ : emptyEnv; int err = posix_spawn(&pid, args[0], &fileActions, nullptr, const_cast(args), envp); posix_spawn_file_actions_destroy(&fileActions); @@ -470,13 +470,10 @@ static std::pair CreateNaClVM(std::pair CreateNaClVM(std::pair -#include -#include -#include -#include -#include - -#include "YokaiBuildInfo/DaemonEngine.h" - -int main(int argc, char *argv[]) { - if (argc < 2) { - printf("nacl_multiarch-%s: missing command line\n", DAEMON_NACL_ARCH_STRING); - return 1; - } - - char *directory = dirname(strdup(argv[0])); - - int err = chdir(directory); - - if (err != 0) { - return err; - } - - char env[100]; - sprintf(env, "LD_LIBRARY_PATH=libs-linux-%s", DAEMON_NACL_ARCH_STRING); - - err = putenv(strdup(env)); - - if (err != 0) { - return err; - } - - execv(argv[1], &argv[1]); - - // The execv() function returns only if an error has occurred. - printf("nacl_multiarch-%s: %s\n", DAEMON_NACL_ARCH_STRING, strerror(errno)); - return 1; -} From 31952ecd56c519d9367d40e13c8aa26083253f1b Mon Sep 17 00:00:00 2001 From: slipher Date: Mon, 7 Sep 2026 01:53:26 -0500 Subject: [PATCH 19/61] Don't use nacl_helper_bootstrap with x86-64 loader Remove cvars controlling whether the Linux bootstrap loader is used. Never use bootstrap with the amd64 loader. Always use bootstrap with 32-bit loaders. Co-authored-by: Thomas Debesse --- CMakeLists.txt | 14 +++++++----- src/engine/framework/VirtualMachine.cpp | 30 ++++--------------------- 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 83ccdbfe1f..62996c75a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -997,7 +997,6 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER ) endforeach() - # Linux uses a bootstrap program to reserve address space if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY) if (DAEMON_NACL_MULTIARCH) add_custom_command(TARGET runtime_deps PRE_BUILD @@ -1007,12 +1006,15 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER ) endif() + # Linux uses a bootstrap program to reserve address space for 32-bit runtimes. foreach(arch_name IN LISTS DAEMON_NACL_ARCH_NAME_LIST) - add_custom_command(TARGET runtime_deps PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${DEPS_DIR}/nacl_helper_bootstrap - ${FULL_OUTPUT_DIR}/nacl_helper_bootstrap-${arch_name} - ) + if ("${arch_name}" IN_LIST "i686;armhf") + add_custom_command(TARGET runtime_deps PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${DEPS_DIR}/nacl_helper_bootstrap + ${FULL_OUTPUT_DIR}/nacl_helper_bootstrap-${arch_name} + ) + endif() endforeach() endif() diff --git a/src/engine/framework/VirtualMachine.cpp b/src/engine/framework/VirtualMachine.cpp index 6508acc659..456e492401 100644 --- a/src/engine/framework/VirtualMachine.cpp +++ b/src/engine/framework/VirtualMachine.cpp @@ -79,7 +79,9 @@ static Cvar::Cvar workaround_naclSystem_freebsd_disableQualification( // Many BSDs have a Linuxulator, for now we only tested one. #if defined(__linux__) || defined(__FreeBSD__) #define DAEMON_NACL_RUNTIME_LINUX +#if YOKAI_ARCH_I686 || YOKAI_ARCH_ARM64 || YOKAI_ARCH_ARMHF #define DAEMON_NACL_BOOSTRAP_ENABLED +#endif // !(YOKAI_ARCH_I686 || YOKAI_ARCH_ARM64 || YOKAI_ARCH_ARMHF) #endif // defined(__linux__) || defined(DAEMON_LINUXULATOR) #endif // defined(DAEMON_NACL_RUNTIME_ENABLED) @@ -90,11 +92,6 @@ static Cvar::Cvar workaround_box64_disableQualification( "Disable platform qualification when running amd64 NaCl loader under Box64 emulation", Cvar::NONE, true); -static Cvar::Cvar workaround_box64_disableBootstrap( - "workaround.box64.disableBootstrap", - "Disable NaCl bootstrap helper when using Box64 emulation", - Cvar::NONE, true); - static Cvar::Cvar vm_box64_path( "vm.box64.path", "Path to the box64 binary for NaCl emulation (empty = use provided one or search PATH if missing)", @@ -183,13 +180,6 @@ static Cvar::Cvar vm_nacl_qualification( Cvar::INIT, true); #endif // defined(DAEMON_NACL_RUNTIME_ENABLED) -#if defined(DAEMON_NACL_BOOSTRAP_ENABLED) -static Cvar::Cvar vm_nacl_bootstrap( - "vm.nacl.bootstrap", - "Use NaCl bootstrap helper", - Cvar::INIT, true); -#endif // defined(DAEMON_NACL_BOOSTRAP_ENABLED) - namespace VM { // https://github.com/Unvanquished/Unvanquished/issues/944#issuecomment-744454772 @@ -479,7 +469,7 @@ static std::pair CreateNaClVM(std::pair CreateNaClVM(std::pair Date: Mon, 7 Sep 2026 03:10:10 -0500 Subject: [PATCH 20/61] Windows: block NaCl process from inheriting environment When creating a NaCl (or native exe) VM on Windows, block evironment variables from being passed through to the subprocess as is done on *nix. Probably we do this since there are NACL* variables that can disable secure sandboxing. inheritEnvironment is always false on Windows, but I implemented the true case anyway since it's less code than having the Q_UNUSED and asserting it's false. --- src/engine/framework/VirtualMachine.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/engine/framework/VirtualMachine.cpp b/src/engine/framework/VirtualMachine.cpp index 456e492401..c416c2647d 100644 --- a/src/engine/framework/VirtualMachine.cpp +++ b/src/engine/framework/VirtualMachine.cpp @@ -288,8 +288,12 @@ static std::pair InternalLoadModule(std::pair InternalLoadModule(std::pair Date: Tue, 15 Sep 2026 06:45:37 -0500 Subject: [PATCH 21/61] Check mmap_min_addr only if using NaCl bootstrap Check the Linux sysctl vm.mmap_min_addr only when using the NaCl bootstrap (rather than always when using NaCl). Or equivalently, check it only with 32-bit NaCl runtimes. The bootstrap fails to start when the value is too high to due low fixed address mappings. On ARM at least, sel_ldr proper would also fail with a too-high min address since that disturbs the address space layout. On 64-bit there is neither the bootstrap nor 0-based address space layout so it always works. Co-authored-by: Thomas Debesse --- src/engine/framework/VirtualMachine.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/engine/framework/VirtualMachine.cpp b/src/engine/framework/VirtualMachine.cpp index c416c2647d..ee0a47e053 100644 --- a/src/engine/framework/VirtualMachine.cpp +++ b/src/engine/framework/VirtualMachine.cpp @@ -440,7 +440,6 @@ static ExeSupport CheckExeSupport(Str::StringRef probe) #if defined(DAEMON_NACL_RUNTIME_ENABLED) static std::pair CreateNaClVM(std::pair pair, Str::StringRef name, bool debug, bool extract, int debugLoader) { - CheckMinAddressSysctlTooLarge(); const std::string& libPath = FS::GetLibPath(); std::vector args; char rootSocketRedir[32]; @@ -572,6 +571,8 @@ static std::pair CreateNaClVM(std::pair Date: Sun, 11 Oct 2026 21:09:44 -0500 Subject: [PATCH 22/61] cmake: raise an error when the SDK prefix is not a directory Co-authored-by: Thomas Debesse --- cmake/DaemonGame.cmake | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmake/DaemonGame.cmake b/cmake/DaemonGame.cmake index 8a4cc2e4ff..3e79b0b96f 100644 --- a/cmake/DaemonGame.cmake +++ b/cmake/DaemonGame.cmake @@ -227,6 +227,10 @@ function(GAMEMODULE) if (BUILD_GAME_NACL AND NOT YOKAI_TARGET_SYSTEM_NACL) if (USE_NACL_SAIGO) + if (NOT IS_DIRECTORY "${SAIGOSDK_PREFIX}") + message(FATAL_ERROR "SAIGOSDK_PREFIX configured as '${SAIGOSDK_PREFIX}' which is not an existing directory") + endif() + add_custom_target(nacl-vms ALL) unset(NACL_VMS_PROJECTS) @@ -251,6 +255,10 @@ function(GAMEMODULE) ) endforeach() else() + if (NOT IS_DIRECTORY "${PNACL_SDK_PREFIX}") + message(FATAL_ERROR "PNACL_SDK_PREFIX configured as '${SAIGOSDK_PREFIX}' which is not an existing directory") + endif() + set(NACL_VMS_PROJECT nacl-vms) set(NACL_VMS_PROJECTS ${NACL_VMS_PROJECT}) From bc81516d3cba6d59e7f698c7e5053180143d8579 Mon Sep 17 00:00:00 2001 From: slipher Date: Mon, 12 Oct 2026 02:29:55 -0500 Subject: [PATCH 23/61] Auto-download Saigo SDK for any supported host The old PNaCl toolchain has been being shipped as part of the deps package, with the host platform for the compilers assumed to be the same as the target platform of the deps package. Experimental Saigo support has thus far required manually downloading the SDK. Now, make the Saigo toolchain auto-downloadable (if USE_NACL_SAIGO=1) independently from the target platform dependencies. This has several advantages: - No need to download the NaCl toolchain if you are not building NaCl. - No need to download a useless NaCl toolchain when cross-compiling. - Toolchain can be downloaded for host systems that don't have a deps package, or where the deps package being used doesn't match the real host system. (The SDK is available for more systems than the deps package.) The toolchain is downloaded from Github and then, like the deps package, extracted into external_deps/. --- CMakeLists.txt | 17 +++--- cmake/DaemonDependenciesDownload.cmake | 72 ++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 cmake/DaemonDependenciesDownload.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 62996c75a7..6969189ab5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,8 +197,9 @@ else() set(FULL_OUTPUT_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}) endif() -# Dependencies version, this must match the number in external_deps/build.sh -set(DEPS_VERSION 11) +# Dependencies versions +set(DEPS_VERSION 11) # This must match the number in external_deps/build.sh +set(SAIGOSDK_VERSION 20260925) option(USE_EXTERNAL_DEPS "Download or reuse dependencies from EXTERNAL_DEPS_DIR (mandatory for building and running NaCl .nexe binaries)." ON) @@ -273,11 +274,8 @@ endif() option(USE_EXTERNAL_DEPS_LIBS "Build and link against libraries from the EXTERNAL_DEPS_DIR" ${DEFAULT_USE_EXTERNAL_DEPS_LIBS}) -set(PNACLSDK_PREFIX "${DEPS_DIR}/pnacl" CACHE PATH "PNaCl SDK path") -mark_as_advanced(PNACLSDK_PREFIX) - -set(SAIGOSDK_PREFIX "${DEPS_DIR}/saigo_newlib" CACHE PATH "Saigo NaCl SDK path") -mark_as_advanced(SAIGOSDK_PREFIX) +set(PNACL_SDK_PREFIX "${DEPS_DIR}/pnacl" CACHE PATH "PNaCl SDK path") +mark_as_advanced(PNACL_SDK_PREFIX) if (USE_EXTERNAL_DEPS AND NOT YOKAI_TARGET_SYSTEM_NACL) if (DEPS_DIR) @@ -457,6 +455,11 @@ if (DEPS_DIR) endif() endif() + if (BUILD_GAME_NACL AND USE_NACL_SAIGO AND NOT SAIGOSDK_PREFIX) + include(DaemonDependenciesDownload) + download_saigosdk() + endif() + if (USE_EXTERNAL_DEPS_LIBS) # Add to paths set(CMAKE_FIND_ROOT_PATH ${DEPS_DIR} ${CMAKE_FIND_ROOT_PATH}) diff --git a/cmake/DaemonDependenciesDownload.cmake b/cmake/DaemonDependenciesDownload.cmake new file mode 100644 index 0000000000..a4bc08a4c4 --- /dev/null +++ b/cmake/DaemonDependenciesDownload.cmake @@ -0,0 +1,72 @@ +# Daemon BSD Source Code +# Copyright (c) 2013-2026, Daemon Developers +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the Daemon developers nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# TODO: Move other deps downloading code in here. + +set(SAIGOSDK_BASENAME "saigosdk-${DEPS_SYSTEM}-${DEPS_ARCH}_${SAIGOSDK_VERSION}") + +# Warning: changing SAIGOSDK_PREFIX/SAIGOSDK_VERSION after subprojects have been configured WILL +# change the compiler, but it is a bad idea since flag tests and such (not to mention the actual +# compiled artifacts) will be out of date. +set(SAIGOSDK_PREFIX "${EXTERNAL_DEPS_DIR}/${SAIGOSDK_BASENAME}" CACHE PATH "PNaCl SDK path") +mark_as_advanced(SAIGOSDK_PREFIX) + +function(download_saigosdk) + if (NOT EXISTS "${SAIGOSDK_PREFIX}") + set(DEPS_FILENAME "${SAIGOSDK_BASENAME}.tar.xz") + set(REMOTE "https://github.com/DaemonEngine/saigo-nacl-sdk/releases/download/v${SAIGOSDK_VERSION}/${DEPS_FILENAME}") + message(STATUS "Downloading NaCl SDK from '${REMOTE}'") + + file(DOWNLOAD "${REMOTE}" "${OBJ_DIR}/${DEPS_FILENAME}" + SHOW_PROGRESS + STATUS DOWNLOAD_RESULT + LOG DOWNLOAD_LOG + ) + + list(GET DOWNLOAD_RESULT 0 DOWNLOAD_STATUS) + list(GET DOWNLOAD_RESULT 1 DOWNLOAD_STRING) + + if (NOT DOWNLOAD_STATUS EQUAL 0) + message(FATAL_ERROR "Failed to download '${REMOTE}': This may be a network error, or your system may be an unsupported host platform. + Status code: ${DOWNLOAD_STATUS} + Error string: ${DOWNLOAD_STRING} + Download log: ${DOWNLOAD_LOG}" + ) + endif() + + message(STATUS "SDK download completed successfully") + + # Extract the downloaded archive + execute_process( + COMMAND ${CMAKE_COMMAND} -E tar xJf ${OBJ_DIR}/${DEPS_FILENAME} + WORKING_DIRECTORY ${EXTERNAL_DEPS_DIR} + RESULT_VARIABLE EXTRACT_RESULT + ) + if (NOT EXTRACT_RESULT EQUAL 0) + message(FATAL_ERROR "Could not extract ${DEPS_FILENAME}") + endif() + endif() +endfunction() From de079e6e04bde1a04caa88234ac05bdae49811f4 Mon Sep 17 00:00:00 2001 From: slipher Date: Tue, 13 Oct 2026 02:56:50 -0500 Subject: [PATCH 24/61] Add build script for Saigo SDK (host-mode deps) Add external_deps/sdk-build.sh which can be used as an alternative to auto-downloading Saigo. Like external_deps/build.sh, it builds the dependency package and installs it to the expected location. It is a thin wrapper around the saigo-nacl-sdk CMake build; if you need more control it is better to use CMake directly. --- .gitignore | 1 + CMakeLists.txt | 2 +- cmake/DaemonDependenciesDownload.cmake | 2 + external_deps/sdk-build.sh | 88 ++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100755 external_deps/sdk-build.sh diff --git a/.gitignore b/.gitignore index 00e20db8da..b753d1cf66 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,7 @@ build #ignore external deps external_deps/* !external_deps/build.sh +!external_deps/sdk-build.sh !external_deps/cygtar.py !external_deps/*.patch diff --git a/CMakeLists.txt b/CMakeLists.txt index 6969189ab5..47797591c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -199,7 +199,7 @@ endif() # Dependencies versions set(DEPS_VERSION 11) # This must match the number in external_deps/build.sh -set(SAIGOSDK_VERSION 20260925) +set(SAIGOSDK_VERSION 20260925) # This must match the number in external_deps/sdk-build.sh option(USE_EXTERNAL_DEPS "Download or reuse dependencies from EXTERNAL_DEPS_DIR (mandatory for building and running NaCl .nexe binaries)." ON) diff --git a/cmake/DaemonDependenciesDownload.cmake b/cmake/DaemonDependenciesDownload.cmake index a4bc08a4c4..2313300d3e 100644 --- a/cmake/DaemonDependenciesDownload.cmake +++ b/cmake/DaemonDependenciesDownload.cmake @@ -34,6 +34,8 @@ set(SAIGOSDK_BASENAME "saigosdk-${DEPS_SYSTEM}-${DEPS_ARCH}_${SAIGOSDK_VERSION}" set(SAIGOSDK_PREFIX "${EXTERNAL_DEPS_DIR}/${SAIGOSDK_BASENAME}" CACHE PATH "PNaCl SDK path") mark_as_advanced(SAIGOSDK_PREFIX) +# As an alternative to downloading, external_deps/sdk-build.sh can be used, to build the host-mode +# dependencies and install them in the expected path. function(download_saigosdk) if (NOT EXISTS "${SAIGOSDK_PREFIX}") set(DEPS_FILENAME "${SAIGOSDK_BASENAME}.tar.xz") diff --git a/external_deps/sdk-build.sh b/external_deps/sdk-build.sh new file mode 100755 index 0000000000..e90e0ace1f --- /dev/null +++ b/external_deps/sdk-build.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash + +# Exit on undefined variable and error. +set -u -e -o pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" +WORK_DIR="${PWD}" +DOWNLOAD_DIR="${WORK_DIR}/download_cache" + +# This should match the SAIGOSDK_VERSION in CMakeLists.txt. +# This is mostly to ensure the path the files end up at if you build deps yourself +# are the same as the ones when extracting from the downloaded packages. +SAIGOSDK_VERSION=20261013 +# Can be a tag like v${SAIGOSDK_VERSION}, or a full commit hash +SAIGOSDK_REF="v${SAIGOSDK_VERSION}" + +REPO_BASENAME=saigo-nacl-sdk +REPO_URL="https://github.com/DaemonEngine/${REPO_BASENAME}" +ARCHIVE_PATH="${DOWNLOAD_DIR}/saigosdk-${SAIGOSDK_REF}.tar.gz" + +usage() { + echo "Usage: $0 - (build | install | package | wipe)..." + echo "- should normally be your current native platform." + echo "For a list of supported platforms see ${REPO_URL}/tree/master/tools/release/conf" + echo "Actions:" + echo " build - build all tools and libraries in the SDK" + echo " install - install final build products to ${WORK_DIR}/saigosdk--_${SAIGOSDK_VERSION}/" + echo " wipe - delete build products (except download cache) AND install directory" + echo "If you want to build only a subset of packages, prefer using the" + echo "${REPO_URL} CMake build directly." + echo "Some global configuration options are available via environment" + echo "variables; see ${REPO_URL}/tree/master/tools/release/build" +} + +download() { + test -f "${ARCHIVE_PATH}" && return + mkdir -p "${DOWNLOAD_DIR}" + curl --fail -L "${DOWNLOAD_URL}" -o "${ARCHIVE_PATH}" +} + +if [ "$#" -lt 2 ] +then + usage + exit 1 +fi + +PLATFORM="$1" +shift + +if grep -q -E '^[0-9a-f]{40}$' <<< "${SAIGOSDK_REF}" +then + DOWNLOAD_URL="https://github.com/DaemonEngine/saigo-nacl-sdk/archive/${SAIGOSDK_REF}.tar.gz" + TARBALL_OUTER_DIR="${REPO_BASENAME}-${SAIGOSDK_REF}" +elif grep -q -E '^v[0-9]' <<< "${SAIGOSDK_REF}" +then + # The 'v' from the tag name is mysteriously removed??? + TARBALL_OUTER_DIR="${REPO_BASENAME}-${SAIGOSDK_REF:1}" + DOWNLOAD_URL="https://github.com/DaemonEngine/saigo-nacl-sdk/archive/refs/tags/${SAIGOSDK_REF}.tar.gz" +fi + +INSTALL_DIR="${WORK_DIR}/saigosdk-${PLATFORM}_${SAIGOSDK_VERSION}" +BUILD_DIR="${WORK_DIR}/build-saigosdk_${SAIGOSDK_VERSION}" +REPO_DIR="${BUILD_DIR}/${TARBALL_OUTER_DIR}" + +for target in "$@" +do + case "${target}" in + build) + download + mkdir -p "${BUILD_DIR}" + tar xzf "${ARCHIVE_PATH}" -C "${BUILD_DIR}" + ( + cd "${REPO_DIR}" + tools/release/build "${PLATFORM}" + ) + ;; + install) + cp -R "${REPO_DIR}/build/${PLATFORM}/install/." "${INSTALL_DIR}/" + ;; + wipe) + rm -rf "${BUILD_DIR}" "${INSTALL_DIR}" + ;; + *) + usage + exit 1 + ;; + esac +done From e1d5ad71305b2a6e8f77107eacb73bcc1f51a847 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 16 Oct 2026 04:53:43 +0200 Subject: [PATCH 25/61] cmake,external_deps: bump deps version to 12, expect the loader be packaged with architecture suffix --- CMakeLists.txt | 15 +++------------ external_deps/build.sh | 23 +++++++++++++---------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 47797591c1..82689421df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -198,7 +198,7 @@ else() endif() # Dependencies versions -set(DEPS_VERSION 11) # This must match the number in external_deps/build.sh +set(DEPS_VERSION 12) # This must match the number in external_deps/build.sh set(SAIGOSDK_VERSION 20260925) # This must match the number in external_deps/sdk-build.sh option(USE_EXTERNAL_DEPS "Download or reuse dependencies from EXTERNAL_DEPS_DIR (mandatory for building and running NaCl .nexe binaries)." ON) @@ -978,20 +978,11 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER foreach(arch_name IN LISTS DAEMON_NACL_ARCH_NAME_LIST) # The NaCl loader and IRT are required to load .nexe files - if (YOKAI_TARGET_SYSTEM_WINDOWS AND YOKAI_TARGET_ARCH_I686 AND "${arch_name}" STREQUAL "amd64") - # Backport compatibility until the external_deps script properly suffixes names in the archives. add_custom_command(TARGET runtime_deps PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DEPS_DIR}/nacl_loader-${arch_name}${CMAKE_EXECUTABLE_SUFFIX} ${FULL_OUTPUT_DIR}/nacl_loader-${arch_name}${CMAKE_EXECUTABLE_SUFFIX} ) - else() - add_custom_command(TARGET runtime_deps PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${DEPS_DIR}/nacl_loader${CMAKE_EXECUTABLE_SUFFIX} - ${FULL_OUTPUT_DIR}/nacl_loader-${arch_name}${CMAKE_EXECUTABLE_SUFFIX} - ) - endif() add_custom_command(TARGET runtime_deps PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different @@ -1004,7 +995,7 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER if (DAEMON_NACL_MULTIARCH) add_custom_command(TARGET runtime_deps PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory - ${DEPS_DIR}/libs-${DAEMON_NACL_ARCH_NAME} + ${DEPS_DIR}/libs-linux-${DAEMON_NACL_ARCH_NAME} ${FULL_OUTPUT_DIR}/libs-linux-${DAEMON_NACL_ARCH_NAME} ) endif() @@ -1014,7 +1005,7 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER if ("${arch_name}" IN_LIST "i686;armhf") add_custom_command(TARGET runtime_deps PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${DEPS_DIR}/nacl_helper_bootstrap + ${DEPS_DIR}/nacl_helper_bootstrap-${arch_name} ${FULL_OUTPUT_DIR}/nacl_helper_bootstrap-${arch_name} ) endif() diff --git a/external_deps/build.sh b/external_deps/build.sh index 8ee5454d54..4d513aa983 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -9,7 +9,7 @@ WORK_DIR="${PWD}" # This should match the DEPS_VERSION in CMakeLists.txt. # This is mostly to ensure the path the files end up at if you build deps yourself # are the same as the ones when extracting from the downloaded packages. -DEPS_VERSION=11 +DEPS_VERSION=12 # Package download pages PKGCONFIG_BASEURL='https://pkg-config.freedesktop.org/releases' @@ -1033,7 +1033,7 @@ build_naclsdk() { linux-amd64-*) ;; # Get sel_ldr from naclruntime package *) - smart_copy pepper_*"/tools/sel_ldr_${NACLSDK_ARCH}${EXE_EXT}" "${PREFIX}/nacl_loader${EXE_EXT}" + smart_copy pepper_*"/tools/sel_ldr_${NACLSDK_ARCH}${EXE_EXT}" "${PREFIX}/nacl_loader-${DAEMON_ARCH}${EXE_EXT}" ;; esac case "${PLATFORM}" in @@ -1065,22 +1065,25 @@ build_naclsdk() { chmod 644 "${PREFIX}/irt_core-${DAEMON_ARCH}.nexe" ;; linux-i686-*|linux-armhf-*|linux-arm64-*) - smart_copy pepper_*"/tools/nacl_helper_bootstrap_${NACLSDK_ARCH}" "${PREFIX}/nacl_helper_bootstrap" + smart_copy pepper_*"/tools/nacl_helper_bootstrap_${NACLSDK_ARCH}" "${PREFIX}/nacl_helper_bootstrap-${DAEMON_ARCH}" # Fix permissions on a few files which deny access to non-owner chmod 644 "${PREFIX}/irt_core-${DAEMON_ARCH}.nexe" - chmod 755 "${PREFIX}/nacl_helper_bootstrap" "${PREFIX}/nacl_loader" + chmod 755 "${PREFIX}/nacl_helper_bootstrap-${DAEMON_ARCH}" "${PREFIX}/nacl_loader-${DAEMON_ARCH}" ;; esac case "${PLATFORM}" in linux-arm64-*) - mkdir -p "${PREFIX}/lib-armhf" - smart_copy -R pepper_*"/tools/lib/arm_trusted/lib/." "${PREFIX}/lib-armhf/." + local libdir_path='libs-linux-armhf' + local loader_path="${libdir_path}/loader" + mkdir -p "${PREFIX}/${libdir_path}" + smart_copy -R pepper_*"/tools/lib/arm_trusted/lib/." "${PREFIX}/${libdir_path}/." # Copy the library loader instead of renaming it because there may still be some # references to ld-linux-armhf.so.3 in binaries. - smart_copy "${PREFIX}/lib-armhf/ld-linux-armhf.so.3" "${PREFIX}/lib-armhf/ld-linux-armhf" + smart_copy "${PREFIX}/${libdir_path}/ld-linux-armhf.so.3" "${PREFIX}/${loader_path}" # We can't use patchelf or 'nacl_helper_bootstrap nacl_loader' will complain: # bootstrap_helper: nacl_loader: ELF file has unreasonable e_phnum=13 - sed -e 's|/lib/ld-linux-armhf.so.3|lib-armhf/ld-linux-armhf|' -i "${PREFIX}/nacl_loader" + # We're lucky that the replacement string isn't larger than the original one. + sed -e "s|/lib/ld-linux-armhf.so.3|${loader_path}|" -i "${PREFIX}/nacl_loader-armhf" ;; esac } @@ -1106,8 +1109,8 @@ build_naclruntime() { cd "${dir_name}" env -i /usr/bin/env bash -l -c "python3 /usr/bin/scons --mode=opt-linux 'platform=${NACL_ARCH}' werror=0 sysinfo=0 sel_ldr" - smart_copy "scons-out/opt-linux-${NACL_ARCH}/staging/nacl_helper_bootstrap" "${PREFIX}/nacl_helper_bootstrap" - smart_copy "scons-out/opt-linux-${NACL_ARCH}/staging/sel_ldr" "${PREFIX}/nacl_loader" + smart_copy "scons-out/opt-linux-${NACL_ARCH}/staging/nacl_helper_bootstrap" "${PREFIX}/nacl_helper_bootstrap-amd64" + smart_copy "scons-out/opt-linux-${NACL_ARCH}/staging/sel_ldr" "${PREFIX}/nacl_loader-amd64" } # Check for DLL dependencies on MinGW stuff. For MSVC platforms this is bad because it should work From 47a6e08e5b62e7506803d5875e3cbd77e2279f5d Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 00:29:15 +0200 Subject: [PATCH 26/61] external_deps: build naclruntime with cmake --- external_deps/build.sh | 152 ++++++++++++++++++++++++----------------- 1 file changed, 90 insertions(+), 62 deletions(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index 4d513aa983..460e4f1846 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -59,7 +59,7 @@ VORBIS_VERSION=1.3.7 OPUS_VERSION=1.5.2 OPUSFILE_VERSION=0.12 NACLSDK_VERSION=44.0.2403.155 -NACLRUNTIME_REVISION=2aea5fcfce504862a825920fcaea1a8426afbd6f +NACLRUNTIME_REVISION='70beec35eb5fa3ddd571f18f9ad57b5da674d85d' NCURSES_VERSION=6.5 WASISDK_VERSION=16.0 WASMTIME_VERSION=2.0.2 @@ -1006,6 +1006,7 @@ build_naclsdk() { local TAR_EXT=tar ;; esac + case "${PLATFORM}" in *-i686-*) local NACLSDK_ARCH=x86_32 @@ -1015,10 +1016,13 @@ build_naclsdk() { local NACLSDK_ARCH=x86_64 local DAEMON_ARCH=amd64 ;; - *-armhf-*|linux-arm64-*) + linux-armhf-*|linux-arm64-*) local NACLSDK_ARCH=arm local DAEMON_ARCH=armhf ;; + *) + log ERROR 'Unsupported platform for NaCl SDK' + ;; esac local archive_name="naclsdk_${NACLSDK_PLATFORM}-${NACLSDK_VERSION}.${TAR_EXT}.bz2" @@ -1029,13 +1033,7 @@ build_naclsdk() { "${download_only}" && return smart_copy pepper_*"/tools/irt_core_${NACLSDK_ARCH}.nexe" "${PREFIX}/irt_core-${DAEMON_ARCH}.nexe" - case "${PLATFORM}" in - linux-amd64-*) - ;; # Get sel_ldr from naclruntime package - *) - smart_copy pepper_*"/tools/sel_ldr_${NACLSDK_ARCH}${EXE_EXT}" "${PREFIX}/nacl_loader-${DAEMON_ARCH}${EXE_EXT}" - ;; - esac + case "${PLATFORM}" in windows-i686-*|*-amd64-*) smart_copy pepper_*"/toolchain/${NACLSDK_PLATFORM}_x86_newlib/bin/x86_64-nacl-gdb${EXE_EXT}" "${PREFIX}/nacl-gdb${EXE_EXT}" @@ -1057,42 +1055,41 @@ build_naclsdk() { esac case "${PLATFORM}" in windows-i686-*) - smart_copy pepper_*"/tools/sel_ldr_x86_64.exe" "${PREFIX}/nacl_loader-amd64.exe" smart_copy pepper_*"/tools/irt_core_x86_64.nexe" "${PREFIX}/irt_core-amd64.nexe" ;; - linux-amd64-*) - # Fix permissions on a few files which deny access to non-owner - chmod 644 "${PREFIX}/irt_core-${DAEMON_ARCH}.nexe" - ;; - linux-i686-*|linux-armhf-*|linux-arm64-*) - smart_copy pepper_*"/tools/nacl_helper_bootstrap_${NACLSDK_ARCH}" "${PREFIX}/nacl_helper_bootstrap-${DAEMON_ARCH}" + linux-*-*) # Fix permissions on a few files which deny access to non-owner chmod 644 "${PREFIX}/irt_core-${DAEMON_ARCH}.nexe" - chmod 755 "${PREFIX}/nacl_helper_bootstrap-${DAEMON_ARCH}" "${PREFIX}/nacl_loader-${DAEMON_ARCH}" - ;; - esac - case "${PLATFORM}" in - linux-arm64-*) - local libdir_path='libs-linux-armhf' - local loader_path="${libdir_path}/loader" - mkdir -p "${PREFIX}/${libdir_path}" - smart_copy -R pepper_*"/tools/lib/arm_trusted/lib/." "${PREFIX}/${libdir_path}/." - # Copy the library loader instead of renaming it because there may still be some - # references to ld-linux-armhf.so.3 in binaries. - smart_copy "${PREFIX}/${libdir_path}/ld-linux-armhf.so.3" "${PREFIX}/${loader_path}" - # We can't use patchelf or 'nacl_helper_bootstrap nacl_loader' will complain: - # bootstrap_helper: nacl_loader: ELF file has unreasonable e_phnum=13 - # We're lucky that the replacement string isn't larger than the original one. - sed -e "s|/lib/ld-linux-armhf.so.3|${loader_path}|" -i "${PREFIX}/nacl_loader-armhf" ;; esac } # Only builds nacl_loader and nacl_helper_bootstrap for now, not IRT. build_naclruntime() { + local nacl_arch_list=() + case "${PLATFORM}" in + windows-amd64-*) + nacl_arch_list+=('amd64') + ;; + windows-i686-*) + nacl_arch_list+=('i686') + nacl_arch_list+=('amd64') + ;; linux-amd64-*) - local NACL_ARCH=x86-64 + nacl_arch_list+=('amd64') + ;; + linux-i686-*) + nacl_arch_list+=('i686') + ;; + linux-arm64-*) + nacl_arch_list+=('armhf') + ;; + linux-armhf-*) + nacl_arch_list+=('armhf') + ;; + macos-amd64-*) + nacl_arch_list+=('amd64') ;; *) log ERROR 'Unsupported platform for naclruntime' @@ -1103,14 +1100,51 @@ build_naclruntime() { local archive_name="native_client-${NACLRUNTIME_REVISION}.zip" download_extract naclruntime "${archive_name}" \ - "{$NACLRUNTIME_BASEURL}/${NACLRUNTIME_REVISION}" + "${NACLRUNTIME_BASEURL}/${NACLRUNTIME_REVISION}" "${download_only}" && return cd "${dir_name}" - env -i /usr/bin/env bash -l -c "python3 /usr/bin/scons --mode=opt-linux 'platform=${NACL_ARCH}' werror=0 sysinfo=0 sel_ldr" - smart_copy "scons-out/opt-linux-${NACL_ARCH}/staging/nacl_helper_bootstrap" "${PREFIX}/nacl_helper_bootstrap-amd64" - smart_copy "scons-out/opt-linux-${NACL_ARCH}/staging/sel_ldr" "${PREFIX}/nacl_loader-amd64" + + for nacl_arch in "${nacl_arch_list[@]}" + do + ( + setup_platform "${PLATFORM_SYSTEM}-${nacl_arch}-${PLATFORM_COMPILER}" + cmake_build + ) + + case "${PLATFORM}" in + linux-*) + mv "${PREFIX}/bin/nacl_helper_bootstrap" "${PREFIX}/nacl_helper_bootstrap-${nacl_arch}" + ;; + esac + + mv "${PREFIX}/bin/sel_ldr${EXE_EXT}" "${PREFIX}/nacl_loader-${nacl_arch}${EXE_EXT}" + + case "${PLATFORM}" in + linux-arm64-*) + case "${nacl_arch}" in + armhf) + local libdir_path='libs-linux-armhf' + + mkdir -p "${PREFIX}/${libdir_path}" + + smart_copy -L \ + '/lib/arm-linux-gnueabihf/ld-linux-armhf.so.3' \ + '/lib/arm-linux-gnueabihf/libstdc++.so.6' \ + '/lib/arm-linux-gnueabihf/libc.so.6' \ + '/lib/arm-linux-gnueabihf/libm.so.6' \ + '/lib/arm-linux-gnueabihf/libgcc_s.so.1' \ + '/lib/arm-linux-gnueabihf/librt.so.1' \ + '/lib/arm-linux-gnueabihf/libpthread.so.0' \ + "${PREFIX}/${libdir_path}/" + + patchelf --set-interpreter "${libdir_path}/ld-linux-armhf.so.3" "${PREFIX}/nacl_loader-armhf" + ;; + esac + ;; + esac + done } # Check for DLL dependencies on MinGW stuff. For MSVC platforms this is bad because it should work @@ -1566,32 +1600,32 @@ setup_platform() { esac } -base_windows_amd64_msvc_packages='zlib gmp nettle curl sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk depcheck genlib' -all_windows_amd64_msvc_packages="${base_windows_amd64_msvc_packages}" - -base_windows_i686_msvc_packages="${base_windows_amd64_msvc_packages}" -all_windows_i686_msvc_packages="${base_windows_amd64_msvc_packages}" - -base_windows_amd64_mingw_packages='zlib gmp nettle curl sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk depcheck' +base_windows_amd64_mingw_packages='native-jwasm zlib gmp nettle curl sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk naclruntime depcheck' all_windows_amd64_mingw_packages="${base_windows_amd64_mingw_packages}" base_windows_i686_mingw_packages="${base_windows_amd64_mingw_packages}" all_windows_i686_mingw_packages="${base_windows_amd64_mingw_packages}" -base_macos_amd64_default_packages='native-pkgconfig native-nasm gmp nettle sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk' +base_windows_amd64_msvc_packages="${base_windows_amd64_mingw_packages} genlib" +all_windows_amd64_msvc_packages="${base_windows_amd64_msvc_packages}" + +base_windows_i686_msvc_packages="${base_windows_amd64_msvc_packages}" +all_windows_i686_msvc_packages="${base_windows_amd64_msvc_packages}" + +base_macos_amd64_default_packages='native-pkgconfig native-nasm gmp nettle sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk naclruntime' all_macos_amd64_default_packages="${base_macos_amd64_default_packages}" -base_linux_i686_default_packages='sdl3 naclsdk' -all_linux_i686_default_packages='zlib gmp nettle curl sdl3 glew png jpeg webp openal ogg vorbis opus opusfile ncurses naclsdk' +base_linux_amd64_default_packages='sdl3 naclsdk naclruntime' +all_linux_amd64_default_packages='zlib gmp nettle curl sdl3 glew png jpeg webp openal ogg vorbis opus opusfile ncurses naclsdk naclruntime' -base_linux_amd64_default_packages="${base_linux_i686_default_packages} naclruntime" -all_linux_amd64_default_packages="${all_linux_i686_default_packages} naclruntime" +base_linux_i686_default_packages="${base_linux_amd64_default_packages}" +all_linux_i686_default_packages="${all_linux_amd64_default_packages}" -base_linux_arm64_default_packages='sdl3 naclsdk' -all_linux_arm64_default_packages='zlib gmp nettle curl sdl3 glew png jpeg webp openal ogg vorbis opus opusfile ncurses naclsdk' +base_linux_arm64_default_packages="${base_linux_amd64_default_packages}" +all_linux_arm64_default_packages="${all_linux_amd64_default_packages}" -base_linux_armhf_default_packages="${base_linux_arm64_default_packages}" -all_linux_armhf_default_packages="${all_linux_arm64_default_packages}" +base_linux_armhf_default_packages="${base_linux_amd64_default_packages}" +all_linux_armhf_default_packages="${all_linux_amd64_default_packages}" all_linux_platforms='linux-amd64-default linux-arm64-default linux-armhf-default linux-i686-default' all_windows_platforms='windows-amd64-mingw windows-amd64-msvc windows-i686-mingw windows-i686-msvc' @@ -1619,7 +1653,7 @@ printHelp() { all linux windows macos Packages: - native-pkgconfig native-nasm zlib gmp nettle curl sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk wasisdk wasmtime + native-pkgconfig native-nasm zlib gmp nettle curl sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk naclruntime wasisdk wasmtime Virtual packages: base build packages for pre-built binaries to be downloaded when building the game @@ -1647,17 +1681,11 @@ printHelp() { all same linux-amd64-default: - base ${base_linux_amd64_default_packages} - all ${all_linux_amd64_default_packages} - linux-i686-default: - base ${base_linux_i686_default_packages} - all ${all_linux_i686_default_packages} - linux-arm64-default: linux-armhf-default: - base ${base_linux_arm64_default_packages} - all ${all_linux_arm64_default_packages} + base ${base_linux_amd64_default_packages} + all ${all_linux_amd64_default_packages} EOF From c7b31ef302d06781b4fefc87ddace090f0e36275 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 27 Jun 2026 04:42:36 +0200 Subject: [PATCH 27/61] external_deps: rework the cmake toolchain configuration --- external_deps/build.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index 460e4f1846..2c2d8d7a14 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -238,6 +238,11 @@ cmake_build() { cmake_args+=(-DCMAKE_CXX_FLAGS="${CXXFLAGS}") cmake_args+=(-DCMAKE_EXE_LINKER_FLAGS="${LDFLAGS}") + if [ -n "${CMAKE_TOOLCHAIN:-}" ] + then + cmake_args+=(-DCMAKE_TOOLCHAIN_FILE="${CMAKE_TOOLCHAIN}") + fi + # Check for ${@} not being empty to workaround a macOS bash limitation. if [ -n "${1:-}" ] then @@ -247,7 +252,6 @@ cmake_build() { rm -rf build cmake -S . -B build \ - -DCMAKE_TOOLCHAIN_FILE="${CMAKE_TOOLCHAIN}" \ -DCMAKE_BUILD_TYPE='Release' \ -DBUILD_SHARED_LIBS="${LIBS_SHARED}" \ "${cmake_args[@]}" @@ -1500,7 +1504,7 @@ setup_default() { LIBS_SHARED='OFF' LIBS_STATIC='ON' - CMAKE_TOOLCHAIN='' + EXE_EXT='' # Always reset flags, we heavily cross-compile and must not inherit any stray flag @@ -1512,8 +1516,7 @@ setup_default() { unset BITNESS unset MACOS_ARCH - unset CMAKE_OSX_ARCHITECTURES - unset MACOSX_DEPLOYMENT_TARGET + unset CMAKE_TOOLCHAIN } # Set up environment for 32-bit i686 Windows for Visual Studio (compile all as .dll) From bd92bc0acdfd596471ca4ba39a3a50ddd4658daf Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 27 Jun 2026 04:36:07 +0200 Subject: [PATCH 28/61] external_deps: rework the macos configuration --- external_deps/build.sh | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index 2c2d8d7a14..626f503593 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -230,6 +230,13 @@ cmake_build() { ;; esac + case "${HOST}" in + macos-*) + cmake_args+=(-DCMAKE_OSX_ARCHITECTURES="${MACOS_ARCH}") + cmake_args+=(-DCMAKE_OSX_DEPLOYMENT_TARGET="${MACOS_VERSION}") + ;; + esac + cmake_args+=(-DCMAKE_C_COMPILER="$(get_compiler_name ${CC})") cmake_args+=(-DCMAKE_CXX_COMPILER="$(get_compiler_name ${CXX})") cmake_args+=(-DCMAKE_C_COMPILER_ARG1="$(get_compiler_arg1 ${CC})") @@ -1465,10 +1472,9 @@ common_setup_macos() { CC='clang' CXX='clang++' STRIP='strip' - CFLAGS+=" -arch ${MACOS_ARCH}" - CXXFLAGS+=" -arch ${MACOS_ARCH}" - LDFLAGS+=" -arch ${MACOS_ARCH}" - export CMAKE_OSX_ARCHITECTURES="${MACOS_ARCH}" + CFLAGS+=" -arch ${MACOS_ARCH} -mmacosx-version-min=${MACOS_VERSION}" + CXXFLAGS+=" -arch ${MACOS_ARCH} -mmacosx-version-min=${MACOS_VERSION}" + LDFLAGS+=" -arch ${MACOS_ARCH} -mmacosx-version-min=${MACOS_VERSION}" } common_setup_linux() { @@ -1516,6 +1522,8 @@ setup_default() { unset BITNESS unset MACOS_ARCH + unset MACOS_VERSION + unset MACOS_HOST unset CMAKE_TOOLCHAIN } @@ -1549,13 +1557,18 @@ setup_windows-amd64-mingw() { common_setup mingw x86_64-w64-mingw32 } +setup_macos() { + MACOS_HOST="${MACOS_ARCH}-apple-macos${MACOS_VERSION}" + common_setup macos "${MACOS_HOST}" +} + # Set up environment for 64-bit amd64 macOS setup_macos-amd64-default() { setup_default MACOS_ARCH=x86_64 # OpenAL requires 10.14. - export MACOSX_DEPLOYMENT_TARGET=10.14 # works with CMake - common_setup macos "x86_64-apple-macos${MACOSX_DEPLOYMENT_TARGET}" + MACOS_VERSION='10.14' + setup_macos } # Set up environment for 32-bit i686 Linux From f63a5d325b09b76c105a22ece5d9f2623c4d6a80 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 02:28:57 +0200 Subject: [PATCH 29/61] external_deps: add macos-arm64-default --- external_deps/build.sh | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index 626f503593..233f038258 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -294,7 +294,7 @@ build_native-pkgconfig() { # As a host-mode native dependency it must be provided by the system when compiling. build_native-nasm() { case "${PLATFORM}" in - macos-*-*) + macos-amd64-*) local dir_name="nasm-${NASM_VERSION}" local archive_name="${dir_name}-macosx.zip" @@ -898,6 +898,8 @@ build_opusfile() { cd "${dir_name}" + # The old configure script doesn't recognize the arm64 prefix. + HOST="${HOST/arm64-apple/aarch64-apple}" \ configure_build \ --disable-http } @@ -1023,7 +1025,7 @@ build_naclsdk() { local NACLSDK_ARCH=x86_32 local DAEMON_ARCH=i686 ;; - *-amd64-*) + *-amd64-*|macos-arm64-*) local NACLSDK_ARCH=x86_64 local DAEMON_ARCH=amd64 ;; @@ -1102,6 +1104,9 @@ build_naclruntime() { macos-amd64-*) nacl_arch_list+=('amd64') ;; + macos-arm64-*) + nacl_arch_list+=('amd64') + ;; *) log ERROR 'Unsupported platform for naclruntime' ;; @@ -1565,12 +1570,20 @@ setup_macos() { # Set up environment for 64-bit amd64 macOS setup_macos-amd64-default() { setup_default - MACOS_ARCH=x86_64 + MACOS_ARCH='x86_64' # OpenAL requires 10.14. MACOS_VERSION='10.14' setup_macos } +# Set up environment for 64-bit arm64 macOS +setup_macos-arm64-default() { + setup_default + MACOS_ARCH='arm64' + MACOS_VERSION='11.7' + setup_macos +} + # Set up environment for 32-bit i686 Linux setup_linux-i686-default() { setup_default @@ -1628,7 +1641,10 @@ all_windows_amd64_msvc_packages="${base_windows_amd64_msvc_packages}" base_windows_i686_msvc_packages="${base_windows_amd64_msvc_packages}" all_windows_i686_msvc_packages="${base_windows_amd64_msvc_packages}" -base_macos_amd64_default_packages='native-pkgconfig native-nasm gmp nettle sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk naclruntime' +base_macos_arm64_default_packages='native-pkgconfig gmp nettle sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk naclruntime' +all_macos_arm64_default_packages="${base_macos_arm64_default_packages}" + +base_macos_amd64_default_packages="native-nasm ${base_macos_arm64_default_packages}" all_macos_amd64_default_packages="${base_macos_amd64_default_packages}" base_linux_amd64_default_packages='sdl3 naclsdk naclruntime' @@ -1645,7 +1661,7 @@ all_linux_armhf_default_packages="${all_linux_amd64_default_packages}" all_linux_platforms='linux-amd64-default linux-arm64-default linux-armhf-default linux-i686-default' all_windows_platforms='windows-amd64-mingw windows-amd64-msvc windows-i686-mingw windows-i686-msvc' -all_macos_platforms='macos-amd64-default' +all_macos_platforms='macos-amd64-default macos-arm64-default' all_platforms="${all_linux_platforms} ${all_windows_platforms} ${all_macos_platforms}" printHelp() { @@ -1696,6 +1712,10 @@ printHelp() { base ${base_macos_amd64_default_packages} all same + macos-arm64-default: + base ${base_macos_arm64_default_packages} + all same + linux-amd64-default: linux-i686-default: linux-arm64-default: From c8bf636e623fbaca4eba6f602da8df9fef807888 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 12:25:47 +0200 Subject: [PATCH 30/61] external_deps: upgrade sdl3 --- external_deps/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index 233f038258..3aa5f7cc6b 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -46,7 +46,7 @@ ZLIB_VERSION=1.3.1 GMP_VERSION=6.3.0 NETTLE_VERSION=3.10.2 CURL_VERSION=8.15.0 -SDL3_VERSION=3.2.22 +SDL3_VERSION=3.4.10 GLEW_VERSION=2.2.0 PNG_VERSION=1.6.50 JPEG_VERSION=3.1.1 From 16ea17c47b27f2a7724f6bd0c15495858377112a Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 12:27:16 +0200 Subject: [PATCH 31/61] external_deps: upgrade zlib --- external_deps/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index 3aa5f7cc6b..9f0624d14b 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -42,7 +42,7 @@ WASMTIME_BASEURL='https://github.com/bytecodealliance/wasmtime/releases' # Package versions PKGCONFIG_VERSION=0.29.2 NASM_VERSION=2.16.03 -ZLIB_VERSION=1.3.1 +ZLIB_VERSION=1.3.2 GMP_VERSION=6.3.0 NETTLE_VERSION=3.10.2 CURL_VERSION=8.15.0 From 2ad15b685000d62843d4ae766c5a1151de0c2611 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 12:28:12 +0200 Subject: [PATCH 32/61] external_deps: upgrade nettle --- external_deps/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index 9f0624d14b..4858fb820d 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -44,7 +44,7 @@ PKGCONFIG_VERSION=0.29.2 NASM_VERSION=2.16.03 ZLIB_VERSION=1.3.2 GMP_VERSION=6.3.0 -NETTLE_VERSION=3.10.2 +NETTLE_VERSION=4.0 CURL_VERSION=8.15.0 SDL3_VERSION=3.4.10 GLEW_VERSION=2.2.0 From a0fac240534ca2d4e6e6db29219e4e38a7017b70 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 12:29:11 +0200 Subject: [PATCH 33/61] external_deps: upgrade curl --- external_deps/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index 4858fb820d..8e7ca53407 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -45,7 +45,7 @@ NASM_VERSION=2.16.03 ZLIB_VERSION=1.3.2 GMP_VERSION=6.3.0 NETTLE_VERSION=4.0 -CURL_VERSION=8.15.0 +CURL_VERSION=8.21.0 SDL3_VERSION=3.4.10 GLEW_VERSION=2.2.0 PNG_VERSION=1.6.50 From 31b8fbee365c4abf1785980e4538b9985bb8dfe0 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 12:29:40 +0200 Subject: [PATCH 34/61] external_deps: upgrade glew --- external_deps/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index 8e7ca53407..6e51b2e152 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -47,7 +47,7 @@ GMP_VERSION=6.3.0 NETTLE_VERSION=4.0 CURL_VERSION=8.21.0 SDL3_VERSION=3.4.10 -GLEW_VERSION=2.2.0 +GLEW_VERSION=2.3.1 PNG_VERSION=1.6.50 JPEG_VERSION=3.1.1 # WebP 1.6.0 introduced AVX2 intrinsics that are not available on From a7f2eb45810fe0de61c5d23f52a16a27fa367f4f Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 12:30:32 +0200 Subject: [PATCH 35/61] external_deps: upgrade png --- external_deps/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index 6e51b2e152..dd0982e222 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -48,7 +48,7 @@ NETTLE_VERSION=4.0 CURL_VERSION=8.21.0 SDL3_VERSION=3.4.10 GLEW_VERSION=2.3.1 -PNG_VERSION=1.6.50 +PNG_VERSION=1.6.58 JPEG_VERSION=3.1.1 # WebP 1.6.0 introduced AVX2 intrinsics that are not available on # the GCC 10 compiler provided by Debian Bullseye. From 5c35f0357d39b69d13a66d7238e80de604e9c0cf Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 12:30:47 +0200 Subject: [PATCH 36/61] external_deps: upgrade jpeg --- external_deps/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index dd0982e222..41545aa0a9 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -49,7 +49,7 @@ CURL_VERSION=8.21.0 SDL3_VERSION=3.4.10 GLEW_VERSION=2.3.1 PNG_VERSION=1.6.58 -JPEG_VERSION=3.1.1 +JPEG_VERSION=3.1.4.1 # WebP 1.6.0 introduced AVX2 intrinsics that are not available on # the GCC 10 compiler provided by Debian Bullseye. WEBP_VERSION=1.5.0 From fa0b1e8a0a7140860d0eadbf913b9d60cb92c533 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 12:31:37 +0200 Subject: [PATCH 37/61] external_deps: do not upgrade openal --- external_deps/build.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/external_deps/build.sh b/external_deps/build.sh index 41545aa0a9..f06a42ee3a 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -53,6 +53,8 @@ JPEG_VERSION=3.1.4.1 # WebP 1.6.0 introduced AVX2 intrinsics that are not available on # the GCC 10 compiler provided by Debian Bullseye. WEBP_VERSION=1.5.0 +# OpenAL 0.25.0 requires C++20 that is not available on +# the GCC 10 compiler provided by Debian Bullseye. OPENAL_VERSION=1.24.3 OGG_VERSION=1.3.6 VORBIS_VERSION=1.3.7 From 4d2dc263fd4a7d0cd136efe23d18ea71f8e044f3 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 12:32:27 +0200 Subject: [PATCH 38/61] external_deps: upgrade opus --- external_deps/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index f06a42ee3a..5eedb6d457 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -58,7 +58,7 @@ WEBP_VERSION=1.5.0 OPENAL_VERSION=1.24.3 OGG_VERSION=1.3.6 VORBIS_VERSION=1.3.7 -OPUS_VERSION=1.5.2 +OPUS_VERSION=1.6.1 OPUSFILE_VERSION=0.12 NACLSDK_VERSION=44.0.2403.155 NACLRUNTIME_REVISION='70beec35eb5fa3ddd571f18f9ad57b5da674d85d' From 5db46440a1d55f02305325ecb5992bf8b473121d Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 16:10:18 +0200 Subject: [PATCH 39/61] external_deps: disable the GPU framework --- external_deps/build.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index 5eedb6d457..db4ba704fc 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -511,7 +511,8 @@ build_sdl3() { cmake_build \ -DSDL_TEST_LIBRARY=OFF \ - -DSDL_AUDIO=OFF + -DSDL_AUDIO=OFF \ + -DSDL_GPU=OFF ;; esac } From 6a3821116b3756a71d6710610647e9b079e5c97e Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 27 Jun 2026 05:49:16 +0200 Subject: [PATCH 40/61] cmake: download macos-arm64 deps archive --- CMakeLists.txt | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 82689421df..6ff67d09bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -229,17 +229,7 @@ if (USE_EXTERNAL_DEPS AND NOT YOKAI_TARGET_SYSTEM_NACL) set(SUPPORTED_${DEPS_SYSTEM}_ARCH amd64 i686) elseif (YOKAI_TARGET_SYSTEM_MACOS) set(DEPS_SYSTEM macos) - set(SUPPORTED_${DEPS_SYSTEM}_ARCH amd64) - - if (YOKAI_TARGET_ARCH_ARM64) - set(DEPS_ARCH amd64) - - set_deps_dir() - - if (NOT EXISTS ${DEPS_DIR}) - set(DEFAULT_USE_EXTERNAL_DEPS_LIBS OFF) - endif() - endif() + set(SUPPORTED_${DEPS_SYSTEM}_ARCH amd64 arm64) elseif (YOKAI_TARGET_SYSTEM_LINUX) set(DEPS_SYSTEM linux) set(SUPPORTED_${DEPS_SYSTEM}_ARCH amd64 i686 arm64 armhf) From 55ae2f3af1138bbcf640183fbe36a8068d183cab Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 3 Jul 2026 06:23:15 +0200 Subject: [PATCH 41/61] external_deps: box64 --- external_deps/build.sh | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index db4ba704fc..db0dfa256a 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -31,6 +31,7 @@ OGG_BASEURL='https://downloads.xiph.org/releases/ogg' VORBIS_BASEURL='https://downloads.xiph.org/releases/vorbis' OPUS_BASEURL='https://downloads.xiph.org/releases/opus' OPUSFILE_BASEURL='https://downloads.xiph.org/releases/opus' +BOX64_BASEURL='https://api.github.com/repos/ptitSeb/box64/zipball' # No index. NACLSDK_BASEURL='https://storage.googleapis.com/nativeclient-mirror/nacl/nacl_sdk' # No index. @@ -60,6 +61,7 @@ OGG_VERSION=1.3.6 VORBIS_VERSION=1.3.7 OPUS_VERSION=1.6.1 OPUSFILE_VERSION=0.12 +BOX64_REVISION='b1d094f9bd37cd69865c56d72a94747b22c16dd6' NACLSDK_VERSION=44.0.2403.155 NACLRUNTIME_REVISION='70beec35eb5fa3ddd571f18f9ad57b5da674d85d' NCURSES_VERSION=6.5 @@ -931,6 +933,23 @@ build_ncurses() { --with-default-terminfo-dir=/usr/share/terminfo } +# Build box64 +build_box64() { + local dir_name="ptitSeb-box64-${BOX64_REVISION:0:7}" + local archive_name="box64-${BOX64_REVISION}.zip" + + download_extract box64 "${archive_name}" \ + "${BOX64_BASEURL}/${BOX64_REVISION}" + + "${download_only}" && return + + cd "${dir_name}" + + cmake_build + + smart_copy 'build/box64' "${PREFIX}/box64" +} + # "Builds" (downloads) the WASI SDK build_wasisdk() { case "${PLATFORM}" in @@ -1688,7 +1707,7 @@ printHelp() { all linux windows macos Packages: - native-pkgconfig native-nasm zlib gmp nettle curl sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk naclruntime wasisdk wasmtime + native-pkgconfig native-nasm zlib gmp nettle curl sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk naclruntime wasisdk wasmtime box64 Virtual packages: base build packages for pre-built binaries to be downloaded when building the game From b706d180da0553d23667451445bc2b6606183b43 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 3 Jul 2026 07:16:22 +0200 Subject: [PATCH 42/61] external_deps: amd64 nacl_loader on arm64 --- external_deps/build.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index db0dfa256a..f318c803ef 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -1088,15 +1088,25 @@ build_naclsdk() { rm -rf "${PREFIX}/pnacl/x86_64-nacl" rm -rf "${PREFIX}/pnacl/x86_64_bc-nacl" esac + case "${PLATFORM}" in - windows-i686-*) + windows-i686-*|linux-arm64-*) smart_copy pepper_*"/tools/irt_core_x86_64.nexe" "${PREFIX}/irt_core-amd64.nexe" ;; + esac + + case "${PLATFORM}" in linux-*-*) # Fix permissions on a few files which deny access to non-owner chmod 644 "${PREFIX}/irt_core-${DAEMON_ARCH}.nexe" ;; esac + + case "${PLATFORM}" in + linux-arm64-*) + chmod 644 "${PREFIX}/irt_core-amd64.nexe" + ;; + esac } # Only builds nacl_loader and nacl_helper_bootstrap for now, not IRT. @@ -1119,6 +1129,7 @@ build_naclruntime() { ;; linux-arm64-*) nacl_arch_list+=('armhf') + nacl_arch_list+=('amd64') ;; linux-armhf-*) nacl_arch_list+=('armhf') From 5b1cb1d0ef9924969d5834bf76b00eaaaec0abab Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 3 Jul 2026 14:42:50 +0200 Subject: [PATCH 43/61] external_deps: box64 install for arm64 --- external_deps/build.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index f318c803ef..f52aa04476 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -948,6 +948,11 @@ build_box64() { cmake_build smart_copy 'build/box64' "${PREFIX}/box64" + + mkdir -p "${PREFIX}/libs-linux-amd64" + smart_copy -L \ + '/usr/lib/x86_64-linux-gnu/libgcc_s.so.1' \ + "${PREFIX}/libs-linux-amd64/" } # "Builds" (downloads) the WASI SDK @@ -1686,12 +1691,12 @@ all_linux_amd64_default_packages='zlib gmp nettle curl sdl3 glew png jpeg webp o base_linux_i686_default_packages="${base_linux_amd64_default_packages}" all_linux_i686_default_packages="${all_linux_amd64_default_packages}" -base_linux_arm64_default_packages="${base_linux_amd64_default_packages}" -all_linux_arm64_default_packages="${all_linux_amd64_default_packages}" - base_linux_armhf_default_packages="${base_linux_amd64_default_packages}" all_linux_armhf_default_packages="${all_linux_amd64_default_packages}" +base_linux_arm64_default_packages="${base_linux_amd64_default_packages} box64" +all_linux_arm64_default_packages="${all_linux_amd64_default_packages} box64" + all_linux_platforms='linux-amd64-default linux-arm64-default linux-armhf-default linux-i686-default' all_windows_platforms='windows-amd64-mingw windows-amd64-msvc windows-i686-mingw windows-i686-msvc' all_macos_platforms='macos-amd64-default macos-arm64-default' @@ -1751,11 +1756,14 @@ printHelp() { linux-amd64-default: linux-i686-default: - linux-arm64-default: linux-armhf-default: base ${base_linux_amd64_default_packages} all ${all_linux_amd64_default_packages} + linux-arm64-default: + base ${base_linux_arm64_default_packages} + all ${all_linux_arm64_default_packages} + EOF exit From c3a8be8b5f561c340505c1a27aaf26ae4d777f1c Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 3 Jul 2026 13:06:27 +0200 Subject: [PATCH 44/61] cmake: enable box64 on arm64 --- cmake/DaemonNaclArchitecture.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/DaemonNaclArchitecture.cmake b/cmake/DaemonNaclArchitecture.cmake index f23685f86f..0e16bc36ce 100644 --- a/cmake/DaemonNaclArchitecture.cmake +++ b/cmake/DaemonNaclArchitecture.cmake @@ -46,7 +46,7 @@ function(daemon_detect_nacl_arch target_arch) endif() set(armhf_usage "arm64" "armel") - set(box64_usage "ppc64el" "riscv64" "loong64") + set(box64_usage "arm64" "ppc64el" "riscv64" "loong64") if ("${target_arch}" IN_LIST armhf_usage) # Load 32-bit armhf nexe on 64-bit arm64 engine on Linux with multiarch. From 116acad6d767e9c47e326940a6d50a6ec9e6a657 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 3 Jul 2026 14:22:20 +0200 Subject: [PATCH 45/61] cmake: copy box64 --- CMakeLists.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ff67d09bf..7efd218985 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1000,6 +1000,20 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER ) endif() endforeach() + + if (DAEMON_NACL_BOX64_EMULATION) + add_custom_command(TARGET runtime_deps PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${DEPS_DIR}/box64 + ${FULL_OUTPUT_DIR}/box64 + ) + + add_custom_command(TARGET runtime_deps PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${DEPS_DIR}/libs-linux-amd64 + ${FULL_OUTPUT_DIR}/libs-linux-amd64 + ) + endif() endif() # Mac requires some libraries from external_deps From becbebe5d5208e152de2593fbd988796405b3804 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Sep 2025 01:25:59 +0200 Subject: [PATCH 46/61] external_deps: let jpeg build for unknown platforms --- external_deps/build.sh | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index f52aa04476..c5a041b7b4 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -627,29 +627,36 @@ build_jpeg() { ;; esac - local jpeg_cmake_args=(-DREQUIRE_SIMD=ON) + local jpeg_cmake_args=() + + local SYSTEM_PROCESSOR='unknown' + local jpeg_require_simd='OFF' case "${PLATFORM}" in *-amd64-*) - local SYSTEM_PROCESSOR='x86_64' + SYSTEM_PROCESSOR='x86_64' + jpeg_require_simd='ON' # Ensure NASM is available nasm --help >/dev/null ;; *-i686-*) - local SYSTEM_PROCESSOR='i386' + SYSTEM_PROCESSOR='i386' + jpeg_require_simd='ON' # Ensure NASM is available nasm --help >/dev/null ;; *-arm64-*) - local SYSTEM_PROCESSOR='aarch64' + SYSTEM_PROCESSOR='aarch64' + jpeg_require_simd='ON' jpeg_cmake_args+=(-DNEON_INTRINSICS=ON) ;; *-armhf-*) - local SYSTEM_PROCESSOR='arm' + SYSTEM_PROCESSOR='arm' + jpeg_require_simd='ON' jpeg_cmake_args+=(-DNEON_INTRINSICS=ON) ;; *) - log ERROR 'Unsupported platform for JPEG' + log WARNING 'Unknown platform for JPEG' ;; esac @@ -674,6 +681,7 @@ build_jpeg() { -DENABLE_STATIC="${LIBS_STATIC}" \ -DCMAKE_SYSTEM_NAME="${SYSTEM_NAME}" \ -DCMAKE_SYSTEM_PROCESSOR="${SYSTEM_PROCESSOR}" \ + -DREQUIRE_SIMD=${jpeg_require_simd} \ -DWITH_JPEG8=1 \ -DWITH_TURBOJPEG=0 \ "${jpeg_cmake_args[@]}" From ee45f9f340aa1de3b4dc1e9d7e41a079c6a4df23 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 4 Jul 2026 04:42:31 +0200 Subject: [PATCH 47/61] jpeg: default on PLATFORM_ARCH --- external_deps/build.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index c5a041b7b4..d4f514e181 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -629,7 +629,12 @@ build_jpeg() { local jpeg_cmake_args=() - local SYSTEM_PROCESSOR='unknown' + # When there is no platform code implemented in libjpeg yet, + # we can build it without SIMD code. + # This string will then only be used for warnings like that: + # > SIMD extensions not available for this CPU (riscv64). Performance will suffer. + local SYSTEM_PROCESSOR="${PLATFORM_ARCH}" + local jpeg_require_simd='OFF' case "${PLATFORM}" in @@ -655,9 +660,6 @@ build_jpeg() { jpeg_require_simd='ON' jpeg_cmake_args+=(-DNEON_INTRINSICS=ON) ;; - *) - log WARNING 'Unknown platform for JPEG' - ;; esac case "${PLATFORM}" in From ee7187a58c58c70eba689cf84d793ca866efba01 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 4 Jul 2026 03:58:05 +0200 Subject: [PATCH 48/61] external_deps: add linux-armel platform --- external_deps/build.sh | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index d4f514e181..b37e383ed4 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -660,6 +660,11 @@ build_jpeg() { jpeg_require_simd='ON' jpeg_cmake_args+=(-DNEON_INTRINSICS=ON) ;; + *-armel-*) + SYSTEM_PROCESSOR='arm' + jpeg_require_simd='OFF' + jpeg_cmake_args+=(-DNEON_INTRINSICS=OFF) + ;; esac case "${PLATFORM}" in @@ -770,6 +775,9 @@ build_openal() { *-armhf-*|*-arm64-*) openal_cmake_args+=(-DALSOFT_CPUEXT_NEON=ON -DALSOFT_REQUIRE_NEON=ON) ;; + *-armel-*) + openal_cmake_args+=(-DALSOFT_CPUEXT_NEON=ON -DALSOFT_REQUIRE_NEON=OFF) + ;; esac case "${PLATFORM}" in @@ -890,6 +898,9 @@ build_opus() { *-armhf-*|*-arm64-*) opus_cmake_args+=(-DOPUS_MAY_HAVE_NEON=OFF -DOPUS_PRESUME_NEON=ON) ;; + *-armel-*) + opus_cmake_args+=(-DOPUS_MAY_HAVE_NEON=ON -DOPUS_PRESUME_NEON=OFF) + ;; esac cd "${dir_name}" @@ -1066,7 +1077,7 @@ build_naclsdk() { local NACLSDK_ARCH=x86_64 local DAEMON_ARCH=amd64 ;; - linux-armhf-*|linux-arm64-*) + linux-armhf-*|linux-armel-*|linux-arm64-*) local NACLSDK_ARCH=arm local DAEMON_ARCH=armhf ;; @@ -1149,6 +1160,9 @@ build_naclruntime() { linux-armhf-*) nacl_arch_list+=('armhf') ;; + linux-armel-*) + nacl_arch_list+=('armhf') + ;; macos-amd64-*) nacl_arch_list+=('amd64') ;; @@ -1480,6 +1494,10 @@ common_setup_arch() { CFLAGS+=' -march=armv7-a -mfpu=neon' CXXFLAGS+=' -march=armv7-a -mfpu=neon' ;; + *-armel-*) + CFLAGS+=' -mfpu=vfp -mfloat-abi=softfp' + CXXFLAGS+=' -mfpu=vfp -mfloat-abi=softfp' + ;; *-native-*) ;; *) @@ -1644,6 +1662,12 @@ setup_linux-amd64-default() { common_setup linux x86_64-unknown-linux-gnu } +# Set up environment for 32-bit little-endian hard-float arm Linux +setup_linux-armel-default() { + setup_default + common_setup linux arm-unknown-linux-gnueabi +} + # Set up environment for 32-bit little-endian hard-float arm Linux setup_linux-armhf-default() { setup_default @@ -1704,6 +1728,9 @@ all_linux_i686_default_packages="${all_linux_amd64_default_packages}" base_linux_armhf_default_packages="${base_linux_amd64_default_packages}" all_linux_armhf_default_packages="${all_linux_amd64_default_packages}" +base_linux_armel_default_packages="${base_linux_armhf_default_packages}" +all_linux_armel_default_packages="${all_linux_armhf_default_packages}" + base_linux_arm64_default_packages="${base_linux_amd64_default_packages} box64" all_linux_arm64_default_packages="${all_linux_amd64_default_packages} box64" @@ -1767,6 +1794,7 @@ printHelp() { linux-amd64-default: linux-i686-default: linux-armhf-default: + linux-armel-default: base ${base_linux_amd64_default_packages} all ${all_linux_amd64_default_packages} From 302cb6ac524169665fa8d90b0d571628c86400f0 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Sep 2025 01:25:59 +0200 Subject: [PATCH 49/61] external_deps: add linux-riscv64 platform --- external_deps/build.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index b37e383ed4..83da669f1e 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -1073,7 +1073,7 @@ build_naclsdk() { local NACLSDK_ARCH=x86_32 local DAEMON_ARCH=i686 ;; - *-amd64-*|macos-arm64-*) + *-amd64-*|macos-arm64-*|linux-riscv64-*) local NACLSDK_ARCH=x86_64 local DAEMON_ARCH=amd64 ;; @@ -1163,6 +1163,9 @@ build_naclruntime() { linux-armel-*) nacl_arch_list+=('armhf') ;; + linux-riscv64-*) + nacl_arch_list+=('amd64') + ;; macos-amd64-*) nacl_arch_list+=('amd64') ;; @@ -1498,6 +1501,8 @@ common_setup_arch() { CFLAGS+=' -mfpu=vfp -mfloat-abi=softfp' CXXFLAGS+=' -mfpu=vfp -mfloat-abi=softfp' ;; + *-riscv64-*) + ;; *-native-*) ;; *) @@ -1680,6 +1685,12 @@ setup_linux-arm64-default() { common_setup linux aarch64-unknown-linux-gnu } +# Set up environment for 64-bit little-endian riscv Linux +setup_linux-riscv64-default() { + setup_default + common_setup linux riscv64-unknown-linux-gnu +} + # Set up environment for native host tools setup_native() { setup_default @@ -1734,6 +1745,9 @@ all_linux_armel_default_packages="${all_linux_armhf_default_packages}" base_linux_arm64_default_packages="${base_linux_amd64_default_packages} box64" all_linux_arm64_default_packages="${all_linux_amd64_default_packages} box64" +base_linux_riscv64_default_packages="${base_linux_arm64_default_packages}" +all_linux_riscv64_default_packages="${all_linux_arm64_default_packages}" + all_linux_platforms='linux-amd64-default linux-arm64-default linux-armhf-default linux-i686-default' all_windows_platforms='windows-amd64-mingw windows-amd64-msvc windows-i686-mingw windows-i686-msvc' all_macos_platforms='macos-amd64-default macos-arm64-default' @@ -1799,6 +1813,7 @@ printHelp() { all ${all_linux_amd64_default_packages} linux-arm64-default: + linux-riscv64-default: base ${base_linux_arm64_default_packages} all ${all_linux_arm64_default_packages} From dc2b850b3622b588558cac8034e30e451b18e31a Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 4 Jul 2026 04:06:34 +0200 Subject: [PATCH 50/61] external_deps: add linux-ppc64el platform --- external_deps/build.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index 83da669f1e..f414080ee6 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -1073,7 +1073,7 @@ build_naclsdk() { local NACLSDK_ARCH=x86_32 local DAEMON_ARCH=i686 ;; - *-amd64-*|macos-arm64-*|linux-riscv64-*) + *-amd64-*|macos-arm64-*|linux-riscv64-*|linux-ppc64el-*) local NACLSDK_ARCH=x86_64 local DAEMON_ARCH=amd64 ;; @@ -1166,6 +1166,9 @@ build_naclruntime() { linux-riscv64-*) nacl_arch_list+=('amd64') ;; + linux-ppc64el-*) + nacl_arch_list+=('amd64') + ;; macos-amd64-*) nacl_arch_list+=('amd64') ;; @@ -1503,6 +1506,8 @@ common_setup_arch() { ;; *-riscv64-*) ;; + *-ppc64el-*) + ;; *-native-*) ;; *) @@ -1691,6 +1696,12 @@ setup_linux-riscv64-default() { common_setup linux riscv64-unknown-linux-gnu } +# Set up environment for 64-bit little-endian ppc Linux +setup_linux-ppc64el-default() { + setup_default + common_setup linux powerpc64le-unknown-linux-gnu +} + # Set up environment for native host tools setup_native() { setup_default @@ -1748,6 +1759,9 @@ all_linux_arm64_default_packages="${all_linux_amd64_default_packages} box64" base_linux_riscv64_default_packages="${base_linux_arm64_default_packages}" all_linux_riscv64_default_packages="${all_linux_arm64_default_packages}" +base_linux_ppc64el_default_packages="${base_linux_arm64_default_packages}" +all_linux_ppc64el_default_packages="${all_linux_arm64_default_packages}" + all_linux_platforms='linux-amd64-default linux-arm64-default linux-armhf-default linux-i686-default' all_windows_platforms='windows-amd64-mingw windows-amd64-msvc windows-i686-mingw windows-i686-msvc' all_macos_platforms='macos-amd64-default macos-arm64-default' @@ -1814,6 +1828,7 @@ printHelp() { linux-arm64-default: linux-riscv64-default: + linux-ppc64el-default: base ${base_linux_arm64_default_packages} all ${all_linux_arm64_default_packages} From 096f94ae6bed70280855b3db345c3bd036cc374b Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 4 Jul 2026 04:34:43 +0200 Subject: [PATCH 51/61] external_deps: add linux-loong64 architecture --- external_deps/build.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index f414080ee6..520e01e019 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -1073,7 +1073,7 @@ build_naclsdk() { local NACLSDK_ARCH=x86_32 local DAEMON_ARCH=i686 ;; - *-amd64-*|macos-arm64-*|linux-riscv64-*|linux-ppc64el-*) + *-amd64-*|macos-arm64-*|linux-riscv64-*|linux-ppc64el-*|linux-loong64-*) local NACLSDK_ARCH=x86_64 local DAEMON_ARCH=amd64 ;; @@ -1169,6 +1169,9 @@ build_naclruntime() { linux-ppc64el-*) nacl_arch_list+=('amd64') ;; + linux-loong64-*) + nacl_arch_list+=('amd64') + ;; macos-amd64-*) nacl_arch_list+=('amd64') ;; @@ -1508,6 +1511,8 @@ common_setup_arch() { ;; *-ppc64el-*) ;; + *-loong64-*) + ;; *-native-*) ;; *) @@ -1702,6 +1707,12 @@ setup_linux-ppc64el-default() { common_setup linux powerpc64le-unknown-linux-gnu } +# Set up environment for 64-bit loongarch Linux +setup_linux-loong64-default() { + setup_default + common_setup linux loongarch64-linux-gnu +} + # Set up environment for native host tools setup_native() { setup_default @@ -1762,6 +1773,9 @@ all_linux_riscv64_default_packages="${all_linux_arm64_default_packages}" base_linux_ppc64el_default_packages="${base_linux_arm64_default_packages}" all_linux_ppc64el_default_packages="${all_linux_arm64_default_packages}" +base_linux_loong64_default_packages="${base_linux_arm64_default_packages}" +all_linux_loong64_default_packages="${all_linux_arm64_default_packages}" + all_linux_platforms='linux-amd64-default linux-arm64-default linux-armhf-default linux-i686-default' all_windows_platforms='windows-amd64-mingw windows-amd64-msvc windows-i686-mingw windows-i686-msvc' all_macos_platforms='macos-amd64-default macos-arm64-default' @@ -1829,6 +1843,7 @@ printHelp() { linux-arm64-default: linux-riscv64-default: linux-ppc64el-default: + linux-loong64-default: base ${base_linux_arm64_default_packages} all ${all_linux_arm64_default_packages} From a017fec1303498073d3375edf4b6a39f6801650d Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Sep 2025 01:25:59 +0200 Subject: [PATCH 52/61] external_deps: distinguish between supported and extra deps packages --- external_deps/build.sh | 48 +++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index 520e01e019..8febc720b0 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -1776,9 +1776,18 @@ all_linux_ppc64el_default_packages="${all_linux_arm64_default_packages}" base_linux_loong64_default_packages="${base_linux_arm64_default_packages}" all_linux_loong64_default_packages="${all_linux_arm64_default_packages}" -all_linux_platforms='linux-amd64-default linux-arm64-default linux-armhf-default linux-i686-default' -all_windows_platforms='windows-amd64-mingw windows-amd64-msvc windows-i686-mingw windows-i686-msvc' -all_macos_platforms='macos-amd64-default macos-arm64-default' +supported_linux_platforms='linux-amd64-default linux-arm64-default linux-armhf-default linux-i686-default' +supported_windows_platforms='windows-amd64-mingw windows-amd64-msvc windows-i686-mingw windows-i686-msvc' +supported_macos_platforms='macos-amd64-default macos-arm64-default' + +extra_linux_platforms='linux-armel-default linux-riscv64-default linux-ppc64el-default linux-loong64-default' + +supported_platforms="${supported_linux_platforms} ${supported_windows_platforms} ${supported_macos_platforms}" + +all_linux_platforms="${supported_linux_platforms} ${extra_linux_platforms}" +all_windows_platforms="${supported_windows_platforms}" +all_macos_platforms="${supported_macos_platforms}" + all_platforms="${all_linux_platforms} ${all_windows_platforms} ${all_macos_platforms}" printHelp() { @@ -1796,10 +1805,14 @@ printHelp() { ${all_platforms} Virtual platforms: - linux ${all_linux_platforms} - windows ${all_windows_platforms} - macos ${all_macos_platforms} - all linux windows macos + supported-linux ${supported_linux_platforms} + supported-windows ${supported_windows_platforms} + supported-macos ${supported_macos_platforms} + supported supported-linux supported-windows supported-macos + extra-linux ${extra_linux_platforms} + extra extra-linux + all-linux linux extra-linux + all supported extra Packages: native-pkgconfig native-nasm zlib gmp nettle curl sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk naclruntime wasisdk wasmtime box64 @@ -1914,15 +1927,30 @@ case "${platform}" in all) platform_list="${all_platforms}" ;; -linux) +supported) + platform_list="${supported_platforms}" + ;; +all-linux) platform_list="${all_linux_platforms}" ;; -windows) +supported-linux) + platform_list="${supported_linux_platforms}" + ;; +extra-linux) + platform_list="${extra_linux_platforms}" + ;; +all-windows) platform_list="${all_windows_platforms}" ;; -macos) +supported-windows) + platform_list="${supported_windows_platforms}" + ;; +all-macos) platform_list="${all_macos_platforms}" ;; +supported-macos) + platform_list="${supported_macos_platforms}" + ;; *) for known_platform in ${all_platforms} do From 95602baaa8164913737de66449f666300fe6d111 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Sep 2025 20:39:36 +0200 Subject: [PATCH 53/61] external_deps: use gmake instead of make on FreeBSD --- external_deps/build.sh | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index 8febc720b0..1e57401dc2 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -68,6 +68,16 @@ NCURSES_VERSION=6.5 WASISDK_VERSION=16.0 WASMTIME_VERSION=2.0.2 +case "$(uname -s)" in + 'FreeBSD') + # The builtin make isn't compatible enough. + MAKE='gmake' + ;; + *) + MAKE='make' + ;; +esac + log() { level="${1}"; shift printf '%s: %s\n' "${level}" "${@}" >&2 @@ -202,8 +212,8 @@ configure_build() { ./configure \ "${configure_args[@]}" - make - make install + "${MAKE}" + "${MAKE}" install } get_compiler_name() { @@ -287,8 +297,8 @@ build_native-pkgconfig() { ( setup_platform 'native' - CFLAGS='-Wno-error=int-conversion' \ - configure_build \ + CFLAGS='-Wno-error=int-conversion' \ + configure_build \ --with-internal-glib ) } @@ -332,8 +342,8 @@ build_zlib() { case "${PLATFORM}" in windows-*-*) - LOC="${CFLAGS}" make -f win32/Makefile.gcc PREFIX="${HOST}-" - make -f win32/Makefile.gcc install BINARY_PATH="${PREFIX}/bin" LIBRARY_PATH="${PREFIX}/lib" INCLUDE_PATH="${PREFIX}/include" SHARED_MODE=1 + LOC="${CFLAGS}" "${MAKE}" -f win32/Makefile.gcc PREFIX="${HOST}-" + "${MAKE}" -f win32/Makefile.gcc install BINARY_PATH="${PREFIX}/bin" LIBRARY_PATH="${PREFIX}/lib" INCLUDE_PATH="${PREFIX}/include" SHARED_MODE=1 ;; *) CFLAGS="${CFLAGS} -DZLIB_CONST" \ @@ -561,12 +571,12 @@ build_glew() { # manually re-add the required flags there. case "${PLATFORM}" in macos-*-*) - make "${glew_env[@]}" "${glew_options[@]}" - make install "${glew_env[@]}" "${glew_options[@]}" + "${MAKE}" "${glew_env[@]}" "${glew_options[@]}" + "${MAKE}" install "${glew_env[@]}" "${glew_options[@]}" ;; *) - env "${glew_env[@]}" make "${glew_options[@]}" - env "${glew_env[@]}" make install "${glew_options[@]}" + env "${glew_env[@]}" "${MAKE}" "${glew_options[@]}" + env "${glew_env[@]}" "${MAKE}" install "${glew_options[@]}" ;; esac From 4f3c3696bb89a21cf5385f91e81823b6ea1a6e22 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Sep 2025 23:53:28 +0200 Subject: [PATCH 54/61] external_deps: workaround a GLEW build error on FreeBSD --- external_deps/build.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/external_deps/build.sh b/external_deps/build.sh index 1e57401dc2..ca33b2ca0e 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -558,6 +558,11 @@ build_glew() { glew_env+=(CFLAGS.EXTRA="${CFLAGS}") glew_options+=(LIBDIR="${PREFIX}/lib" LD="${CC}") ;; + freebsd-*-*) + glew_env+=(CFLAGS.EXTRA="${CFLAGS}") + sed -e 's/ -soname / -Wl,-soname=/' config/Makefile.freebsd > config/Makefile.freebsd-fix + glew_options+=(SYSTEM=freebsd-fix LD="${CC}") + ;; *) log ERROR 'Unsupported platform for GLEW' ;; From b9754f8acde928f6f5c36064a14436eae7d42ea1 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 4 Jul 2026 07:31:52 +0200 Subject: [PATCH 55/61] external_deps: add freebsd-amd64 and freebsd-i686 platforms --- external_deps/build.sh | 51 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index ca33b2ca0e..7e48f61012 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -634,6 +634,9 @@ build_jpeg() { linux-*-*) local SYSTEM_NAME='Linux' ;; + freebsd-*-*) + local SYSTEM_NAME='FreeBSD' + ;; *) # Other platforms can build but we need to explicitly # set CMAKE_SYSTEM_NAME for CMAKE_CROSSCOMPILING to be set @@ -1077,7 +1080,7 @@ build_naclsdk() { local NACLSDK_PLATFORM=mac local TAR_EXT=tar ;; - linux-*-*) + linux-*-*|freebsd-*-*) local NACLSDK_PLATFORM=linux local TAR_EXT=tar ;; @@ -1137,7 +1140,7 @@ build_naclsdk() { esac case "${PLATFORM}" in - linux-*-*) + linux-*-*|freebsd-*-*) # Fix permissions on a few files which deny access to non-owner chmod 644 "${PREFIX}/irt_core-${DAEMON_ARCH}.nexe" ;; @@ -1374,7 +1377,7 @@ build_install() { # Fix import lib paths to use MSVC-style instead of MinGW ones (see 'genlib' target) find "${PKG_PREFIX}/lib/cmake" -name '*.cmake' -execdir sed -i -E 's@[.]dll[.]a\b@.lib@g' {} \; ;; - linux-*-*) + linux-*-*|freebsd-*-*) find "${PKG_PREFIX}/lib" -name '*.so' -execdir rm -f -- {} \; find "${PKG_PREFIX}/lib" -name '*.so.*' -execdir rm -f -- {} \; find "${PKG_PREFIX}/lib" -name '*_g.a' -execdir rm -f -- {} \; @@ -1587,6 +1590,15 @@ common_setup_linux() { CXXFLAGS+=' -fPIC' } +common_setup_freebsd() { + CC='clang' + CXX='clang++' + STRIP='strip' + CFLAGS+=" -target ${HOST}" + CXXFLAGS+=" -target ${HOST}" + LDFLAGS+=" -target ${HOST}" +} + common_setup_native() { case "$(uname -s)" in CYGWIN_NT-*|MSYS_NT-*|MINGW*_NT-*) @@ -1728,6 +1740,18 @@ setup_linux-loong64-default() { common_setup linux loongarch64-linux-gnu } +# Set up environment for 32-bit i686 FreeBSD +setup_freebsd-i686-default() { + setup_default + common_setup freebsd i386-unknown-freebsd +} + +# Set up environment for 64-bit amd64 FreeBSD +setup_freebsd-amd64-default() { + setup_default + common_setup freebsd x86_64-unknown-freebsd +} + # Set up environment for native host tools setup_native() { setup_default @@ -1791,11 +1815,19 @@ all_linux_ppc64el_default_packages="${all_linux_arm64_default_packages}" base_linux_loong64_default_packages="${base_linux_arm64_default_packages}" all_linux_loong64_default_packages="${all_linux_arm64_default_packages}" +# FIXME: The naclruntime will fail to build, we need to download a prebuilt one. +base_freebsd_amd64_default_packages='sdl3 naclsdk saigosdk' +all_freebsd_amd64_default_packages='gmp nettle sdl3 glew png jpeg webp openal ogg vorbis opus opusfile naclsdk saigosdk' + +base_freebsd_i686_default_packages="${base_freebsd_amd64_default_packages}" +all_freebsd_i686_default_packages="${all_freebsd_amd64_default_packages}" + supported_linux_platforms='linux-amd64-default linux-arm64-default linux-armhf-default linux-i686-default' supported_windows_platforms='windows-amd64-mingw windows-amd64-msvc windows-i686-mingw windows-i686-msvc' supported_macos_platforms='macos-amd64-default macos-arm64-default' extra_linux_platforms='linux-armel-default linux-riscv64-default linux-ppc64el-default linux-loong64-default' +extra_freebsd_platforms='freebsd-amd64-default freebsd-i686-default' supported_platforms="${supported_linux_platforms} ${supported_windows_platforms} ${supported_macos_platforms}" @@ -1803,7 +1835,7 @@ all_linux_platforms="${supported_linux_platforms} ${extra_linux_platforms}" all_windows_platforms="${supported_windows_platforms}" all_macos_platforms="${supported_macos_platforms}" -all_platforms="${all_linux_platforms} ${all_windows_platforms} ${all_macos_platforms}" +all_platforms="${all_linux_platforms} ${all_windows_platforms} ${all_macos_platforms} ${extra_freebsd_platforms}" printHelp() { # Please align to 4-space tabs. @@ -1825,7 +1857,8 @@ printHelp() { supported-macos ${supported_macos_platforms} supported supported-linux supported-windows supported-macos extra-linux ${extra_linux_platforms} - extra extra-linux + extra-freebsd ${extra_freebsd_platforms} + extra extra-linux extra-freebsd all-linux linux extra-linux all supported extra @@ -1875,6 +1908,11 @@ printHelp() { base ${base_linux_arm64_default_packages} all ${all_linux_arm64_default_packages} + freebsd-amd64-default: + freebsd-i686-default: + base ${base_freebsd_amd64_default_packages} + all ${all_freebsd_amd64_default_packages} + EOF exit @@ -1954,6 +1992,9 @@ supported-linux) extra-linux) platform_list="${extra_linux_platforms}" ;; +extra-freebsd) + platform_list="${extra_freebsd_platforms}" + ;; all-windows) platform_list="${all_windows_platforms}" ;; From 41415aae3b2592a83d4f2c3d4c6d4ee6bcc4e9e1 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 26 Jun 2026 06:45:18 +0200 Subject: [PATCH 56/61] cmake: use Saigo by default to compile NaCl binaries --- cmake/DaemonGame.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/DaemonGame.cmake b/cmake/DaemonGame.cmake index 3e79b0b96f..f10150518f 100644 --- a/cmake/DaemonGame.cmake +++ b/cmake/DaemonGame.cmake @@ -71,7 +71,7 @@ include(CMakeParseArguments) list(APPEND NACL_ALL_TARGETS "amd64" "i686" "armhf") if (NOT GAME_BUILD_SUBINVOCATION) - option(USE_NACL_SAIGO "Use the Saigo toolchain to build NaCl executables" OFF) + option(USE_NACL_SAIGO "Use the Saigo toolchain to build NaCl executables" ON) if (USE_NACL_SAIGO) set(HAS_NACL_SDK ON) From a46d090103cd59011606093f52ddf45f7f8072c9 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 7 Jul 2026 09:41:54 +0200 Subject: [PATCH 57/61] external_deps: set MinGW flags as flags --- external_deps/build.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index 7e48f61012..dda42ff8dd 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -251,10 +251,8 @@ cmake_build() { ;; esac - cmake_args+=(-DCMAKE_C_COMPILER="$(get_compiler_name ${CC})") - cmake_args+=(-DCMAKE_CXX_COMPILER="$(get_compiler_name ${CXX})") - cmake_args+=(-DCMAKE_C_COMPILER_ARG1="$(get_compiler_arg1 ${CC})") - cmake_args+=(-DCMAKE_CXX_COMPILER_ARG1="$(get_compiler_arg1 ${CXX})") + cmake_args+=(-DCMAKE_C_COMPILER="${CC}") + cmake_args+=(-DCMAKE_CXX_COMPILER="${CXX}") cmake_args+=(-DCMAKE_C_FLAGS="${CFLAGS}") cmake_args+=(-DCMAKE_CXX_FLAGS="${CXXFLAGS}") cmake_args+=(-DCMAKE_EXE_LINKER_FLAGS="${LDFLAGS}") @@ -1560,9 +1558,11 @@ common_setup_windows() { common_setup_msvc() { LIBS_SHARED='ON' LIBS_STATIC='OFF' + CC="${HOST}-gcc" + CXX="${HOST}-g++" # Libtool bug prevents -static-libgcc from being set in LDFLAGS - CC="${HOST}-gcc -static-libgcc" - CXX="${HOST}-g++ -static-libgcc" + CFLAGS+=' -static-libgcc' + CXXFLAGS+=' -static-libgcc' common_setup_windows } From 901ff6acd0cdc25174499659c107e4915cb88e9a Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 7 Jul 2026 09:49:40 +0200 Subject: [PATCH 58/61] external_deps: use ccache when available --- external_deps/build.sh | 57 +++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index dda42ff8dd..4c7ac73f6a 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -251,8 +251,14 @@ cmake_build() { ;; esac - cmake_args+=(-DCMAKE_C_COMPILER="${CC}") - cmake_args+=(-DCMAKE_CXX_COMPILER="${CXX}") + if [ -n "${COMPILER_LAUNCHER}" ] + then + cmake_args+=(-DCMAKE_C_COMPILER_LAUNCHER="${COMPILER_LAUNCHER}") + cmake_args+=(-DCMAKE_CXX_COMPILER_LAUNCHER="${COMPILER_LAUNCHER}") + fi + + cmake_args+=(-DCMAKE_C_COMPILER="${C_COMPILER}") + cmake_args+=(-DCMAKE_CXX_COMPILER="${CXX_COMPILER}") cmake_args+=(-DCMAKE_C_FLAGS="${CFLAGS}") cmake_args+=(-DCMAKE_CXX_FLAGS="${CXXFLAGS}") cmake_args+=(-DCMAKE_EXE_LINKER_FLAGS="${LDFLAGS}") @@ -1495,9 +1501,25 @@ common_setup() { CPPFLAGS+=" -I${PREFIX}/include" LDFLAGS+=" -L${PREFIX}/lib" + if command -v ccmake >/dev/null 2>&1 + then + export COMPILER_LAUNCHER='ccache' + export CCACHE_CPP2='true' + export CCACHE_HASHDIR='true' + fi + + if [ -n "${COMPILER_LAUNCHER}" ] + then + export CC="${COMPILER_LAUNCHER} ${C_COMPILER}" + export CXX="${COMPILER_LAUNCHER} ${CXX_COMPILER}" + else + export CC="${C_COMPILER}" + export CXX="${CXX_COMPILER}" + fi + export PATH export PKG_CONFIG PKG_CONFIG_PATH - export CC CXX LD AR RANLIB STRIP + export LD AR RANLIB STRIP export CPPFLAGS CFLAGS CXXFLAGS LDFLAGS } @@ -1558,8 +1580,8 @@ common_setup_windows() { common_setup_msvc() { LIBS_SHARED='ON' LIBS_STATIC='OFF' - CC="${HOST}-gcc" - CXX="${HOST}-g++" + C_COMPILER="${HOST}-gcc" + CXX_COMPILER="${HOST}-g++" # Libtool bug prevents -static-libgcc from being set in LDFLAGS CFLAGS+=' -static-libgcc' CXXFLAGS+=' -static-libgcc' @@ -1567,14 +1589,14 @@ common_setup_msvc() { } common_setup_mingw() { - CC="${HOST}-gcc" - CXX="${HOST}-g++" + C_COMPILER="${HOST}-gcc" + CXX_COMPILER="${HOST}-g++" common_setup_windows } common_setup_macos() { - CC='clang' - CXX='clang++' + C_COMPILER='clang' + CXX_COMPILER='clang++' STRIP='strip' CFLAGS+=" -arch ${MACOS_ARCH} -mmacosx-version-min=${MACOS_VERSION}" CXXFLAGS+=" -arch ${MACOS_ARCH} -mmacosx-version-min=${MACOS_VERSION}" @@ -1582,8 +1604,8 @@ common_setup_macos() { } common_setup_linux() { - CC="${HOST/-unknown-/-}-gcc" - CXX="${HOST/-unknown-/-}-g++" + C_COMPILER="${HOST/-unknown-/-}-gcc" + CXX_COMPILER="${HOST/-unknown-/-}-g++" STRIP="${HOST/-unknown-/-}-strip" CROSS_PKG_CONFIG_PATH="/usr/lib/${HOST/-unknown-/-}/pkgconfig" CFLAGS+=' -fPIC' @@ -1591,8 +1613,8 @@ common_setup_linux() { } common_setup_freebsd() { - CC='clang' - CXX='clang++' + C_COMPILER='clang' + CXX_COMPILER='clang++' STRIP='strip' CFLAGS+=" -target ${HOST}" CXXFLAGS+=" -target ${HOST}" @@ -1613,6 +1635,11 @@ setup_default() { export CC='false' export CXX='false' + export C_COMPILER='false' + export CXX_COMPILER='false' + + export COMPILER_LAUNCHER='' + # Set defaults. export LD='ld' export AR='ar' @@ -1755,8 +1782,8 @@ setup_freebsd-amd64-default() { # Set up environment for native host tools setup_native() { setup_default - CC='cc' - CXX='c++' + C_COMPILER='cc' + CXX_COMPILER='c++' common_setup native native } From 6f7c35eaf1bfd1d1872f17793e9b1c1470fb8766 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Wed, 8 Jul 2026 11:54:28 +0200 Subject: [PATCH 59/61] cmake: make possible for the game cmake to tell which variable to pass to the NaCl subinvocation It's used by Unvanquished to pass CBSE_PYTHON_PATH. Also delete DAEMON_CBSE_PYTHON_PATH (already moved to the game as CBSE_PYTHON_PATH). --- CMakeLists.txt | 1 - cmake/DaemonGame.cmake | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7efd218985..db9c9b4d2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,7 +149,6 @@ set(DEFAULT_NACL_VM_INHERITED_OPTIONS BUILD_CGAME BUILD_SGAME CMAKE_BUILD_TYPE - DAEMON_CBSE_PYTHON_PATH USE_ARCH_INTRINSICS USE_COMPILER_CUSTOMIZATION USE_COMPILER_INTRINSICS diff --git a/cmake/DaemonGame.cmake b/cmake/DaemonGame.cmake index f10150518f..4df694b4ac 100644 --- a/cmake/DaemonGame.cmake +++ b/cmake/DaemonGame.cmake @@ -220,8 +220,8 @@ function(GAMEMODULE) set(INHERITED_OPTION_ARGS) - foreach(inherited_option ${NACL_VM_INHERITED_OPTIONS}) - set(INHERITED_OPTION_ARGS ${INHERITED_OPTION_ARGS} + foreach(inherited_option IN LISTS NACL_VM_INHERITED_OPTIONS GAME_NACL_VM_INHERITED_OPTIONS) + list(APPEND INHERITED_OPTION_ARGS "-D${inherited_option}=${${inherited_option}}") endforeach(inherited_option) From f67ab196f5b634970d37546489c2a77d1312fb99 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 10 Jul 2026 11:01:37 +0200 Subject: [PATCH 60/61] virtualmachine: increase timeout --- src/engine/framework/VirtualMachine.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/engine/framework/VirtualMachine.cpp b/src/engine/framework/VirtualMachine.cpp index ee0a47e053..e8348cfe15 100644 --- a/src/engine/framework/VirtualMachine.cpp +++ b/src/engine/framework/VirtualMachine.cpp @@ -169,10 +169,15 @@ static Cvar::Cvar vm_nacl_available( Cvar::ROM, vmAvailable); #if defined(DAEMON_NACL_RUNTIME_ENABLED) +/* We were initially using 2, but loading a nexe on an emulator +like box64 can be much longer than that. +Also, increasing the timeout makes possible to run the game when +stored on very slow filesystems. +This doesn't make loading longer, it allows it to be longer. */ static Cvar::Cvar vm_timeout( "vm.timeout", "Receive timeout in seconds", - Cvar::NONE, 2); + Cvar::NONE, 10); static Cvar::Cvar vm_nacl_qualification( "vm.nacl.qualification", From 1b7e51134d63ae18dc505efded7c46fbb51ee40c Mon Sep 17 00:00:00 2001 From: slipher Date: Mon, 7 Sep 2026 01:53:26 -0500 Subject: [PATCH 61/61] external_deps: remove amd64 bootstrap usage from deps. Closes #1327. Co-authored-by: Thomas Debesse --- external_deps/build.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/external_deps/build.sh b/external_deps/build.sh index 4c7ac73f6a..aed00a1c00 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -1223,8 +1223,12 @@ build_naclruntime() { ) case "${PLATFORM}" in - linux-*) - mv "${PREFIX}/bin/nacl_helper_bootstrap" "${PREFIX}/nacl_helper_bootstrap-${nacl_arch}" + linux-i686-*|linux-arm64-*|linux-armhf-*) + case "${nacl_arch}" in + i686|armhf) + mv "${PREFIX}/bin/nacl_helper_bootstrap" "${PREFIX}/nacl_helper_bootstrap-${nacl_arch}" + ;; + esac ;; esac