Skip to content

Commit 69eb08b

Browse files
slipherillwieckz
authored andcommitted
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.
1 parent 4f71c8b commit 69eb08b

4 files changed

Lines changed: 94 additions & 1 deletion

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ build
4040
#ignore external deps
4141
external_deps/*
4242
!external_deps/build.sh
43+
!external_deps/sdk-build.sh
4344
!external_deps/cygtar.py
4445
!external_deps/*.patch
4546

‎CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ endif()
200200

201201
# Dependencies versions
202202
set(DEPS_VERSION 11) # This must match the number in external_deps/build.sh
203-
set(SAIGOSDK_VERSION 20261030)
203+
set(SAIGOSDK_VERSION 20261030) # This must match the number in external_deps/sdk-build.sh
204204

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

‎cmake/DaemonDependenciesDownload.cmake‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ set(SAIGOSDK_BASENAME "saigosdk-${DEPS_SYSTEM}-${DEPS_ARCH}_${SAIGOSDK_VERSION}"
3434
set(SAIGOSDK_PREFIX "${EXTERNAL_DEPS_DIR}/${SAIGOSDK_BASENAME}" CACHE PATH "PNaCl SDK path")
3535
mark_as_advanced(SAIGOSDK_PREFIX)
3636

37+
# As an alternative to downloading, external_deps/sdk-build.sh can be used, to build the host-mode
38+
# dependencies and install them in the expected path.
3739
function(download_saigosdk)
3840
if (NOT EXISTS "${SAIGOSDK_PREFIX}")
3941
set(DEPS_FILENAME "${SAIGOSDK_BASENAME}.tar.xz")

‎external_deps/sdk-build.sh‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env bash
2+
3+
# Exit on undefined variable and error.
4+
set -u -e -o pipefail
5+
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
7+
WORK_DIR="${PWD}"
8+
DOWNLOAD_DIR="${WORK_DIR}/download_cache"
9+
10+
# This should match the SAIGOSDK_VERSION in CMakeLists.txt.
11+
# This is mostly to ensure the path the files end up at if you build deps yourself
12+
# are the same as the ones when extracting from the downloaded packages.
13+
SAIGOSDK_VERSION=20261030
14+
# Can be a tag like v${SAIGOSDK_VERSION}, or a full commit hash
15+
SAIGOSDK_REF="v${SAIGOSDK_VERSION}"
16+
17+
REPO_BASENAME=saigo-nacl-sdk
18+
REPO_URL="https://github.com/DaemonEngine/${REPO_BASENAME}"
19+
ARCHIVE_PATH="${DOWNLOAD_DIR}/saigosdk-${SAIGOSDK_REF}.tar.gz"
20+
21+
usage() {
22+
cat <<-EOF
23+
Usage: $0 <os>-<arch> (build | install | package | wipe)...
24+
<os>-<arch> should normally be your current native platform.
25+
For a list of supported platforms see ${REPO_URL}/tree/master/tools/release/conf
26+
Actions:
27+
build - build all tools and libraries in the SDK
28+
install - install final build products to ${WORK_DIR}/saigosdk-<os>-<arch>_${SAIGOSDK_VERSION}/
29+
wipe - delete build products (except download cache) AND install directory
30+
If you want to build only a subset of packages, prefer using the
31+
${REPO_URL} CMake build directly.
32+
Some global configuration options are available via environment
33+
variables; see ${REPO_URL}/tree/master/tools/release/build
34+
EOF
35+
}
36+
37+
download() {
38+
test -f "${ARCHIVE_PATH}" && return
39+
mkdir -p "${DOWNLOAD_DIR}"
40+
curl --fail -L "${DOWNLOAD_URL}" -o "${ARCHIVE_PATH}"
41+
}
42+
43+
if [ "$#" -lt 2 ]
44+
then
45+
usage
46+
exit 1
47+
fi
48+
49+
PLATFORM="$1"
50+
shift
51+
52+
if grep -q -E '^[0-9a-f]{40}$' <<< "${SAIGOSDK_REF}"
53+
then
54+
DOWNLOAD_URL="https://github.com/DaemonEngine/saigo-nacl-sdk/archive/${SAIGOSDK_REF}.tar.gz"
55+
TARBALL_OUTER_DIR="${REPO_BASENAME}-${SAIGOSDK_REF}"
56+
elif grep -q -E '^v[0-9]' <<< "${SAIGOSDK_REF}"
57+
then
58+
# The 'v' from the tag name is mysteriously removed???
59+
TARBALL_OUTER_DIR="${REPO_BASENAME}-${SAIGOSDK_REF:1}"
60+
DOWNLOAD_URL="https://github.com/DaemonEngine/saigo-nacl-sdk/archive/refs/tags/${SAIGOSDK_REF}.tar.gz"
61+
fi
62+
63+
INSTALL_DIR="${WORK_DIR}/saigosdk-${PLATFORM}_${SAIGOSDK_VERSION}"
64+
BUILD_DIR="${WORK_DIR}/build-saigosdk_${SAIGOSDK_VERSION}"
65+
REPO_DIR="${BUILD_DIR}/${TARBALL_OUTER_DIR}"
66+
67+
for target in "$@"
68+
do
69+
case "${target}" in
70+
build)
71+
download
72+
mkdir -p "${BUILD_DIR}"
73+
tar xzf "${ARCHIVE_PATH}" -C "${BUILD_DIR}"
74+
(
75+
cd "${REPO_DIR}"
76+
tools/release/build "${PLATFORM}"
77+
)
78+
;;
79+
install)
80+
cp -R "${REPO_DIR}/build/${PLATFORM}/install/." "${INSTALL_DIR}/"
81+
;;
82+
wipe)
83+
rm -rf "${BUILD_DIR}" "${INSTALL_DIR}"
84+
;;
85+
*)
86+
usage
87+
exit 1
88+
;;
89+
esac
90+
done

0 commit comments

Comments
 (0)