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 65ff1a430b..4c360308eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -157,6 +157,12 @@ set(NACL_VM_INHERITED_OPTIONS "${DEFAULT_NACL_VM_INHERITED_OPTIONS}" CACHE STRIN "Semicolon-separated list of options for which NaCl game VMs should use the same value as the other binaries") mark_as_advanced(NACL_VM_INHERITED_OPTIONS) +# Warning: changing SAIGOSDK_ROOT/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_ROOT "" CACHE PATH "Override Saigo NaCl SDK path") +mark_as_advanced(SAIGOSDK_ROOT) + ################################################################################ # Directories ################################################################################ @@ -189,8 +195,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) # 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) @@ -442,6 +449,11 @@ if (DEPS_DIR) endif() endif() + if (BUILD_GAME_NACL AND USE_NACL_SAIGO AND NOT SAIGOSDK_ROOT) + include(DaemonDependenciesDownload) + download_saigosdk() + endif() + if (USE_EXTERNAL_DEPS_LIBS) # Add to paths set(CMAKE_FIND_ROOT_PATH ${DEPS_DIR} ${CMAKE_FIND_ROOT_PATH}) @@ -487,10 +499,10 @@ elseif (YOKAI_TARGET_SYSTEM_NACL) 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") + # Other builds may provide i686-nacl/lib instead. + AND EXISTS "${SAIGOSDK_ROOT}/x86_64-nacl/lib32") + set(NACL_EXCEPTION "${SAIGOSDK_ROOT}/x86_64-nacl/lib32/libnacl_exception.a") + set(NACL_MINIDUMP "${SAIGOSDK_ROOT}/x86_64-nacl/lib32/libminidump_generator.a") endif() set(LIBS_BASE ${LIBS_BASE} ${NACL_MINIDUMP} ${NACL_EXCEPTION}) diff --git a/cmake/DaemonDependenciesDownload.cmake b/cmake/DaemonDependenciesDownload.cmake new file mode 100644 index 0000000000..93f6aa45b9 --- /dev/null +++ b/cmake/DaemonDependenciesDownload.cmake @@ -0,0 +1,70 @@ +# 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}) +set(SAIGOSDK_ROOT ${EXTERNAL_DEPS_DIR}/${SAIGOSDK_BASENAME}) +set(SAIGOSDK_ROOT "${SAIGOSDK_ROOT}" PARENT_SCOPE) + +# 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_ROOT}) + 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() diff --git a/cmake/DaemonGame.cmake b/cmake/DaemonGame.cmake index f6adde3c7c..81dc9348cb 100644 --- a/cmake/DaemonGame.cmake +++ b/cmake/DaemonGame.cmake @@ -204,6 +204,9 @@ function(GAMEMODULE) if (BUILD_GAME_NACL) if (USE_NACL_SAIGO) + if (NOT IS_DIRECTORY "${SAIGOSDK_ROOT}") + message(FATAL_ERROR "SAIGOSDK_ROOT configured as '${SAIGOSDK_ROOT}' which is not an existing directory") + endif() add_custom_target(nacl-vms ALL) unset(NACL_VMS_PROJECTS) @@ -224,6 +227,7 @@ function(GAMEMODULE) gameSubProject( -DCMAKE_TOOLCHAIN_FILE=${Daemon_SOURCE_DIR}/cmake/toolchain-saigo.cmake + -DSAIGOSDK_ROOT=${SAIGOSDK_ROOT} -DBUILD_GAME_NACL=ON -DBUILD_GAME_NATIVE_DLL=OFF -DBUILD_GAME_NATIVE_EXE=OFF diff --git a/cmake/toolchain-saigo.cmake b/cmake/toolchain-saigo.cmake index 75374527b3..92a576c7d0 100644 --- a/cmake/toolchain-saigo.cmake +++ b/cmake/toolchain-saigo.cmake @@ -1,4 +1,4 @@ -set(PLATFORM_PREFIX "${DEPS_DIR}/saigo_newlib/bin") +set(PLATFORM_PREFIX "${SAIGOSDK_ROOT}/bin") set(PLATFORM_TRIPLET "${SAIGO_ARCH}-nacl") set(PLATFORM_EXE_SUFFIX ".nexe") 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