Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 18 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
################################################################################
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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})
Expand Down
70 changes: 70 additions & 0 deletions cmake/DaemonDependenciesDownload.cmake
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 4 additions & 0 deletions cmake/DaemonGame.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmake/toolchain-saigo.cmake
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
88 changes: 88 additions & 0 deletions external_deps/sdk-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env bash

@illwieckz illwieckz Oct 13, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bikeshedding from me, but it would be nice if brand new files can use tabs as indentation (same for CMake files).


# 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 <os>-<arch> (build | install | package | wipe)..."
echo "<os>-<arch> 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-<os>-<arch>_${SAIGOSDK_VERSION}/"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Terminology: we tend to use <system> not <os>.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the user-facing help so I think OS is easier to understand for someone unfamiliar.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, ”system” as a short-hand for operating system is consistent with all our other writing when we don't fully write “operating system“, and someone knowing that “OS” means “operating system” would understand what “systems” means in such context (and if the people really doesn't know that “OS” is for “operating system”, then “system” is less obscure). The fact that it's common knowledge that “OS” is “operating system” actually tells we can use “system”.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"System" as a shorthand for operating system never occurred to me. Generally I think of a system as comprising both the hardware and software components. So OS and architecture are both parts of defining a target system.

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
Loading