Skip to content

Commit 4f71c8b

Browse files
slipherillwieckz
authored andcommitted
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 ea4ab12 commit 4f71c8b

2 files changed

Lines changed: 80 additions & 5 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,9 @@ else()
198198
set(FULL_OUTPUT_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR})
199199
endif()
200200

201-
# Dependencies version, this must match the number in external_deps/build.sh
202-
set(DEPS_VERSION 11)
201+
# Dependencies versions
202+
set(DEPS_VERSION 11) # This must match the number in external_deps/build.sh
203+
set(SAIGOSDK_VERSION 20261030)
203204

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

@@ -277,9 +278,6 @@ option(USE_EXTERNAL_DEPS_LIBS "Build and link against libraries from the EXTERNA
277278
set(PNACLSDK_PREFIX "${DEPS_DIR}/pnacl" CACHE PATH "PNaCl SDK path")
278279
mark_as_advanced(PNACLSDK_PREFIX)
279280

280-
set(SAIGOSDK_PREFIX "${DEPS_DIR}/saigo_newlib" CACHE PATH "Saigo NaCl SDK path")
281-
mark_as_advanced(SAIGOSDK_PREFIX)
282-
283281
if (USE_EXTERNAL_DEPS AND NOT YOKAI_TARGET_SYSTEM_NACL)
284282
if (DEPS_DIR)
285283
message(STATUS "Using external deps dir: ${DEPS_DIR}")
@@ -458,6 +456,11 @@ if (DEPS_DIR)
458456
endif()
459457
endif()
460458

459+
if (BUILD_GAME_NACL AND USE_NACL_SAIGO AND NOT SAIGOSDK_PREFIX)
460+
include(DaemonDependenciesDownload)
461+
download_saigosdk()
462+
endif()
463+
461464
if (USE_EXTERNAL_DEPS_LIBS)
462465
# Add to paths
463466
set(CMAKE_FIND_ROOT_PATH ${DEPS_DIR} ${CMAKE_FIND_ROOT_PATH})
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
31+
# Warning: changing SAIGOSDK_PREFIX/SAIGOSDK_VERSION after subprojects have been configured WILL
32+
# change the compiler, but it is a bad idea since flag tests and such (not to mention the actual
33+
# compiled artifacts) will be out of date.
34+
set(SAIGOSDK_PREFIX "${EXTERNAL_DEPS_DIR}/${SAIGOSDK_BASENAME}" CACHE PATH "PNaCl SDK path")
35+
mark_as_advanced(SAIGOSDK_PREFIX)
36+
37+
function(download_saigosdk)
38+
if (NOT EXISTS "${SAIGOSDK_PREFIX}")
39+
set(DEPS_FILENAME "${SAIGOSDK_BASENAME}.tar.xz")
40+
set(REMOTE "https://github.com/DaemonEngine/saigo-nacl-sdk/releases/download/v${SAIGOSDK_VERSION}/${DEPS_FILENAME}")
41+
message(STATUS "Downloading NaCl SDK from '${REMOTE}'")
42+
43+
file(DOWNLOAD "${REMOTE}" "${OBJ_DIR}/${DEPS_FILENAME}"
44+
SHOW_PROGRESS
45+
STATUS DOWNLOAD_RESULT
46+
LOG DOWNLOAD_LOG
47+
)
48+
49+
list(GET DOWNLOAD_RESULT 0 DOWNLOAD_STATUS)
50+
list(GET DOWNLOAD_RESULT 1 DOWNLOAD_STRING)
51+
52+
if (NOT DOWNLOAD_STATUS EQUAL 0)
53+
message(FATAL_ERROR "Failed to download '${REMOTE}': This may be a network error, or your system may be an unsupported host platform.
54+
Status code: ${DOWNLOAD_STATUS}
55+
Error string: ${DOWNLOAD_STRING}
56+
Download log: ${DOWNLOAD_LOG}"
57+
)
58+
endif()
59+
60+
message(STATUS "SDK download completed successfully")
61+
62+
# Extract the downloaded archive
63+
execute_process(
64+
COMMAND ${CMAKE_COMMAND} -E tar xJf ${OBJ_DIR}/${DEPS_FILENAME}
65+
WORKING_DIRECTORY ${EXTERNAL_DEPS_DIR}
66+
RESULT_VARIABLE EXTRACT_RESULT
67+
)
68+
if (NOT EXTRACT_RESULT EQUAL 0)
69+
message(FATAL_ERROR "Could not extract ${DEPS_FILENAME}")
70+
endif()
71+
endif()
72+
endfunction()

0 commit comments

Comments
 (0)