joeylib2/installer/components/sdl3Web.sh
2026-10-13 14:01:46 -05:00

63 lines
1.9 KiB
Bash

# Part of JoeyLib, Copyright (c) 2026 Scott Duensing, under the MIT License.
# See LICENSE.md for license information.
# SPDX-License-Identifier: MIT
#
# SDL 3 built with Emscripten, static, for the web port (make web): the same
# release source the sdl3 component builds for the host (its pin is read from
# sdl3.sh, so there is one), with JoeyLib's patches for SDL's Emscripten code
# (installer/patches/sdl3Web), compiled to WebAssembly into
# toolchains/opt/sdl3Web.
compDescription="web: SDL 3 for Emscripten, static (web port)"
compGroups="toolchain:web"
compRequires="host emsdk"
compHostDeps="cmake patch"
sdl3Url="$(compQuery sdl3 compUrl)"
sdl3Sha256="$(compQuery sdl3 compSha256)"
patchDir="$JOEY_PATCHES/sdl3Web"
# Editing a patch rebuilds SDL, so the patches are part of the pin.
compPin="$sdl3Sha256:$(compQuery emsdk compPin):$(cat "$patchDir"/*.patch | sha256sum | cut -d' ' -f1)"
compInstall() {
local archive
local src
local p
local emsdk="$JOEY_OPT/emsdk"
archive="$(fetchFile "$sdl3Url" "$sdl3Sha256")"
src="$(freshBuildDir "$compId")"
extractArchive "$archive" "$src" 1
for p in "$patchDir"/*.patch; do
info "applying $(basename "$p")"
patch -d "$src" -p1 -s -F0 --no-backup-if-mismatch < "$p"
done
export EM_CONFIG="$emsdk/.emscripten"
export EM_CACHE="$emsdk/cache"
"$emsdk/upstream/emscripten/emcmake" cmake -S "$src" -B "$src/build" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="$compDir" \
-DCMAKE_INSTALL_LIBDIR=lib \
-DSDL_SHARED=OFF \
-DSDL_STATIC=ON \
-DSDL_TESTS=OFF \
-DSDL_EXAMPLES=OFF
cmake --build "$src/build" -j"$JOEY_JOBS"
rm -rf "$compDir"
cmake --install "$src/build"
dropBuildDir "$compId"
}
compInstalled() {
[ -f "$compDir/lib/libSDL3.a" ] && [ -f "$compDir/include/SDL3/SDL.h" ]
}
compVerify() {
compInstalled
}
compEnv() {
envVar SDL3_WEB_DIR "$compDir"
}