#!/usr/bin/env bash # Compila o Last Stand (ShanPla, MIT; C++20 + raylib 6.2 + Emscripten) do commit a77f8f6 para o fredygames.com, com o # Emscripten 6.0.10 (o repositorio usa o 6.0.13 no CI dele). # # source /emsdk_env.sh # emsdk install 6.0.10 && emsdk activate 6.0.10 # src/FredGames.Bundler/Builds/build-last-stand.sh # precisa tambem de cmake, make e python3 # # O jogo gera arte, musica e sons em codigo; a unica coisa de terceiros e a fonte Pixelify Sans (OFL), embutida no binario. # Mudancas nossas (last-stand/last-stand-fredygames.patch): sem app instalavel (manifest, icones, botao "Install app") e sem # service worker (offline); uma CSP na pagina; o FinishWebBuild.cmake so copia os componentes e grava o tamanho do .wasm. # O script apaga do build os arquivos que o patch deixa sem uso (InstallApp, OfflineCache, sw.js, manifest, gerador de icones). # O raylib 6.2 (zlib) vem do tarball com sha256 conferido (FETCHCONTENT_SOURCE_DIR_RAYLIB), nao da rede do CMake. # # Saida: artifacts/build/last-stand-a77f8f6/last-stand-a77f8f6-dist.tar.gz + licenses.txt set -euo pipefail COMMIT=a77f8f686ac1b5f93374af3d100b25fb74742d7f SHA256=c976ffc02cc93121c42e4ccc84ea05d59dbe4797fc6859e57c3c2f9999fc42a6 RAYLIB_SHA256=df7a13129b1bec9e73a6962efff170beba310ee6eab8f94cd000b7316b4db5ee EMSCRIPTEN=6.0.10 here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" root="$(git -C "$here" rev-parse --show-toplevel 2>/dev/null || pwd)" out="$root/artifacts/build/last-stand-${COMMIT:0:7}" cache="$root/artifacts/build/cache" if ! emcc --version 2>/dev/null | head -1 | grep -q " $EMSCRIPTEN "; then [ -f "$root/artifacts/tools/emsdk/emsdk_env.sh" ] && source "$root/artifacts/tools/emsdk/emsdk_env.sh" >/dev/null 2>&1 fi emcc --version 2>/dev/null | head -1 | grep -q " $EMSCRIPTEN " || { echo "Precisa do Emscripten $EMSCRIPTEN no PATH." >&2; exit 1; } for tool in cmake make python3; do command -v "$tool" >/dev/null || { echo "Precisa do $tool no PATH." >&2; exit 1; }; done aux() { if [ -f "$here/last-stand/$1" ]; then echo "$here/last-stand/$1"; else echo "$here/$1"; fi; } mkdir -p "$cache" fetch() { # nome url sha256 if [ ! -f "$cache/$1" ]; then curl -fsSL --retry 4 "$2" -o "$cache/$1.partial" && mv "$cache/$1.partial" "$cache/$1" fi echo "$3 $cache/$1" | shasum -a 256 -c - >/dev/null } fetch "last-stand-${COMMIT:0:7}.tar.gz" "https://github.com/ShanPla/Last-Stand/archive/$COMMIT.tar.gz" "$SHA256" fetch "raylib-6.2.tar.gz" "https://github.com/raysan5/raylib/archive/refs/tags/6.2.tar.gz" "$RAYLIB_SHA256" rm -rf "$out" mkdir -p "$out/tree" "$out/raylib" "$out/build" "$out/dist" tar -xzf "$cache/last-stand-${COMMIT:0:7}.tar.gz" -C "$out/tree" --strip-components 1 tar -xzf "$cache/raylib-6.2.tar.gz" -C "$out/raylib" --strip-components 1 ( cd "$out/tree" && patch -s -p1 < "$(aux last-stand-fredygames.patch)" ) rm -rf "$out/tree/web/components/InstallApp" "$out/tree/web/components/OfflineCache" "$out/tree/web/sw.js" \ "$out/tree/web/manifest.webmanifest" "$out/tree/tools/generate-icons.mjs" cd "$out/build" emcmake cmake ../tree -DCMAKE_BUILD_TYPE=Release -DFETCHCONTENT_SOURCE_DIR_RAYLIB="$out/raylib" \ -DFETCHCONTENT_FULLY_DISCONNECTED=ON > cmake.log 2>&1 || { tail -30 cmake.log; exit 1; } emmake make -j"$(sysctl -n hw.ncpu 2>/dev/null || nproc)" laststand > make.log 2>&1 || { tail -30 make.log; exit 1; } for f in index.html index.js index.wasm; do cp "$f" "$out/dist/"; done cp -R components "$out/dist/components" { echo "== Last Stand (LICENSE, MIT): ver o LICENSE.txt do jogo no site" echo echo "== Pixelify Sans (OFL.txt, SIL Open Font License 1.1)" cat "$out/tree/src/components/Ui/Font/OFL.txt" echo echo "== raylib 6.2 (LICENSE, zlib)" cat "$out/raylib/LICENSE" echo echo "== Emscripten (LICENSE, MIT / UIUC)" cat "$root/artifacts/tools/emsdk/upstream/emscripten/LICENSE" } > "$out/licenses.txt" find "$out/dist" -exec touch -t 202404180000 {} + ( cd "$out" && find dist -type f | LC_ALL=C sort > files.txt \ && COPYFILE_DISABLE=1 tar --format=ustar --uid 0 --gid 0 --uname root --gname root -n -cf - -T files.txt \ | gzip -n -9 > "last-stand-${COMMIT:0:7}-dist.tar.gz" && rm files.txt ) rm -rf "$out/tree" "$out/raylib" "$out/build" ls -l "$out/last-stand-${COMMIT:0:7}-dist.tar.gz" shasum -a 256 "$out/last-stand-${COMMIT:0:7}-dist.tar.gz" "$out/licenses.txt"