Skip to content

Commit 4ea77bf

Browse files
committed
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/.
1 parent 7e2341f commit 4ea77bf

2 files changed

Lines changed: 82 additions & 5 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ set(NACL_VM_INHERITED_OPTIONS "${DEFAULT_NACL_VM_INHERITED_OPTIONS}" CACHE STRIN
157157
"Semicolon-separated list of options for which NaCl game VMs should use the same value as the other binaries")
158158
mark_as_advanced(NACL_VM_INHERITED_OPTIONS)
159159

160+
# Warning: changing SAIGOSDK_ROOT/SAIGOSDK_VERSION after subprojects have been configured WILL
161+
# change the compiler, but it is a bad idea since flag tests and such (not to mention the actual
162+
# compiled artifacts) will be out of date.
163+
set(SAIGOSDK_ROOT "" CACHE PATH "Override Saigo NaCl SDK path")
164+
mark_as_advanced(SAIGOSDK_ROOT)
165+
160166
################################################################################
161167
# Directories
162168
################################################################################
@@ -189,8 +195,9 @@ else()
189195
set(FULL_OUTPUT_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR})
190196
endif()
191197

192-
# Dependencies version, this must match the number in external_deps/build.sh
193-
set(DEPS_VERSION 11)
198+
# Dependencies versions
199+
set(DEPS_VERSION 11) # This must match the number in external_deps/build.sh
200+
set(SAIGOSDK_VERSION 20260925)
194201

195202
option(USE_EXTERNAL_DEPS "Download or reuse dependencies from EXTERNAL_DEPS_DIR (mandatory for building and running NaCl .nexe binaries)." ON)
196203

@@ -263,9 +270,6 @@ if (USE_EXTERNAL_DEPS AND NOT YOKAI_TARGET_SYSTEM_NACL)
263270
endif()
264271
endif()
265272

266-
set(SAIGOSDK_ROOT "${DEPS_DIR}/saigo_newlib" CACHE PATH "Saigo NaCl SDK path")
267-
mark_as_advanced(SAIGOSDK_ROOT)
268-
269273
option(USE_EXTERNAL_DEPS_LIBS "Build and link against libraries from the EXTERNAL_DEPS_DIR" ${DEFAULT_USE_EXTERNAL_DEPS_LIBS})
270274

271275
if (USE_EXTERNAL_DEPS AND NOT YOKAI_TARGET_SYSTEM_NACL)
@@ -445,6 +449,11 @@ if (DEPS_DIR)
445449
endif()
446450
endif()
447451

452+
if (BUILD_GAME_NACL AND USE_NACL_SAIGO AND NOT SAIGOSDK_ROOT)
453+
include(DaemonDependenciesDownload)
454+
download_saigosdk()
455+
endif()
456+
448457
if (USE_EXTERNAL_DEPS_LIBS)
449458
# Add to paths
450459
set(CMAKE_FIND_ROOT_PATH ${DEPS_DIR} ${CMAKE_FIND_ROOT_PATH})
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Daemon BSD Source Code
2+
# Copyright (c) 2013-2026, Daemon Developers
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
# * Redistributions of source code must retain the above copyright
8+
# notice, this list of conditions and the following disclaimer.
9+
# * Redistributions in binary form must reproduce the above copyright
10+
# notice, this list of conditions and the following disclaimer in the
11+
# documentation and/or other materials provided with the distribution.
12+
# * Neither the name of the Daemon developers nor the
13+
# names of its contributors may be used to endorse or promote products
14+
# derived from this software without specific prior written permission.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY
20+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
# TODO: Move other deps downloading code in here.
28+
29+
set(SAIGOSDK_BASENAME saigosdk-${DEPS_SYSTEM}-${DEPS_ARCH}_${SAIGOSDK_VERSION})
30+
set(SAIGOSDK_ROOT ${EXTERNAL_DEPS_DIR}/${SAIGOSDK_BASENAME})
31+
set(SAIGOSDK_ROOT "${SAIGOSDK_ROOT}" PARENT_SCOPE)
32+
33+
function(download_saigosdk)
34+
if (NOT EXISTS ${SAIGOSDK_ROOT})
35+
set(DEPS_FILENAME "${SAIGOSDK_BASENAME}.tar.xz")
36+
set(REMOTE "https://github.com/DaemonEngine/saigo-nacl-sdk/releases/download/v${SAIGOSDK_VERSION}/${DEPS_FILENAME}")
37+
message(STATUS "Downloading NaCl SDK from '${REMOTE}'")
38+
39+
file(DOWNLOAD "${REMOTE}" "${OBJ_DIR}/${DEPS_FILENAME}"
40+
SHOW_PROGRESS
41+
STATUS DOWNLOAD_RESULT
42+
LOG DOWNLOAD_LOG
43+
)
44+
45+
list(GET DOWNLOAD_RESULT 0 DOWNLOAD_STATUS)
46+
list(GET DOWNLOAD_RESULT 1 DOWNLOAD_STRING)
47+
48+
if (NOT DOWNLOAD_STATUS EQUAL 0)
49+
message(FATAL_ERROR "Failed to download '${REMOTE}': This may be a network error, or your system may be an unsupported host platform.
50+
Status code: ${DOWNLOAD_STATUS}
51+
Error string: ${DOWNLOAD_STRING}
52+
Download log: ${DOWNLOAD_LOG}"
53+
)
54+
endif()
55+
56+
message(STATUS "SDK download completed successfully")
57+
58+
# Extract the downloaded archive
59+
execute_process(
60+
COMMAND ${CMAKE_COMMAND} -E tar xJf ${OBJ_DIR}/${DEPS_FILENAME}
61+
WORKING_DIRECTORY ${EXTERNAL_DEPS_DIR}
62+
RESULT_VARIABLE EXTRACT_RESULT
63+
)
64+
if (NOT EXTRACT_RESULT EQUAL 0)
65+
message(FATAL_ERROR "Could not extract ${DEPS_FILENAME}")
66+
endif()
67+
endif()
68+
endfunction()

0 commit comments

Comments
 (0)