#!/usr/bin/env bash # Compila o Decipherism (puzzle de Alex Sharipov / quasilyte, Game Off 2022, MIT; Ebitengine) para a web # a partir do fonte, num commit fixo, com Go 1.18.10 (o go.mod pede 1.18+): # GOOS=js GOARCH=wasm go build -trimpath -buildvcs=false (como o BUILD.md do autor) # # Uma mudanca no jogo: duas fontes dafont sem termos de redistribuicao sao trocadas por fontes SIL OFL 1.1 # do google/fonts (commit fixo): "Electronic Highway Sign" (visor, font.ttf; so "100% free") vira a VT323 e # "Tidy Hand" (manuscrita, TidyHand.ttf; so "free for all use") vira a Handlee. O patch # decipherism/decipherism-fonts.patch so aponta o main.go para os novos arquivos e ajusta os tamanhos (as # novas fontes sao mais estreitas); os originais nao entram na build. # # src/FredGames.Bundler/Builds/build-decipherism.sh # # Os modulos Go vem do go.sum do autor (conferidos pelo Go, GOPROXY padrao). O wasm_exec.js e o do proprio # Go 1.18.10 (misc/wasm), a mesma versao do compilador. Ferramentas em artifacts/tools/go-1.18.10. # Saida: artifacts/build/decipherism-03436d0/{main.wasm,wasm_exec.js,decipherism-03436d0.tar.gz, # go-licenses/}; main.wasm tem que sair igual em dois builds seguidos. set -euo pipefail COMMIT=03436d0ca6045664fbdfac2bab965f4541facb10 SHA256=4c1752ab3a1dbf458c3b51a8681f3e397e91b4e3378740551bacf89cfbe15bd4 GO=1.18.10 GO_SHA256_ARM64=718b32cb2c1d203ba2c5e6d2fc3cf96a6952b38e389d94ff6cdb099eb959dade GO_SHA256_AMD64=5614904f2b0b546b1493f294122fea7d67b2fbfc2efe84b1ab560fb678502e1f FONTS_COMMIT=9862abc066c9b83bf84c3e8ed1fc2d8d48f9bbf0 VT323_SHA256=cf4de751ada78ceac033dbe16a687742939995b77bc2a052ae17a4957958594d HANDLEE_SHA256=7b99c0f291b5d52e06c66498a1d0dd6dff45a32e32d13be089c60d2d8dc00445 here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" root="$(git -C "$here" rev-parse --show-toplevel 2>/dev/null || pwd)" out="$root/artifacts/build/decipherism-${COMMIT:0:7}" cache="$root/artifacts/build/cache" tools="$root/artifacts/tools" mkdir -p "$cache" fetch() { if [ ! -f "$cache/$2" ]; then curl -fsSL --retry 4 "$1" -o "$cache/$2.partial" && mv "$cache/$2.partial" "$cache/$2" fi echo "$3 $cache/$2" | shasum -a 256 -c - } case "$(uname -m)" in arm64) goarch=arm64; gosha=$GO_SHA256_ARM64 ;; *) goarch=amd64; gosha=$GO_SHA256_AMD64 ;; esac if [ ! -x "$tools/go-$GO/bin/go" ]; then fetch "https://go.dev/dl/go$GO.darwin-$goarch.tar.gz" "go$GO.darwin-$goarch.tar.gz" "$gosha" rm -rf "$tools/go-$GO.tmp"; mkdir -p "$tools/go-$GO.tmp" tar -xzf "$cache/go$GO.darwin-$goarch.tar.gz" -C "$tools/go-$GO.tmp" --strip-components 1 mv "$tools/go-$GO.tmp" "$tools/go-$GO" fi export GOROOT="$tools/go-$GO" export PATH="$GOROOT/bin:$PATH" export GOPATH="$cache/gopath-decipherism" GOCACHE="$cache/gocache-decipherism" export GOFLAGS=-modcacherw GOTOOLCHAIN=local CGO_ENABLED=0 GO111MODULE=on [ "$(go env GOVERSION)" = "go$GO" ] || { echo "Go inesperado: $(go version)"; exit 1; } fetch "https://github.com/quasilyte/decipherism-game/archive/$COMMIT.tar.gz" "decipherism-${COMMIT:0:7}.tar.gz" "$SHA256" fetch "https://raw.githubusercontent.com/google/fonts/$FONTS_COMMIT/ofl/vt323/VT323-Regular.ttf" "VT323-Regular-${FONTS_COMMIT:0:7}.ttf" "$VT323_SHA256" fetch "https://raw.githubusercontent.com/google/fonts/$FONTS_COMMIT/ofl/handlee/Handlee-Regular.ttf" "Handlee-Regular-${FONTS_COMMIT:0:7}.ttf" "$HANDLEE_SHA256" rm -rf "$out" mkdir -p "$out/tree" tar -xzf "$cache/decipherism-${COMMIT:0:7}.tar.gz" -C "$out/tree" --strip-components 1 # Fonte publicado (sem as alteracoes): o tarball do commit, regravado em tar deterministico. ( cd "$out/tree" && find . -type f | sed 's|^\./||' | LC_ALL=C sort > "$out/files.txt" ) ( cd "$out/tree" && COPYFILE_DISABLE=1 tar --format=ustar --uid 0 --gid 0 --uname root --gname root -n \ -cf - -T "$out/files.txt" ) | gzip -n -9 > "$out/decipherism-${COMMIT:0:7}.tar.gz" # As fontes: o patch aponta o jogo para VT323 e Handlee; Electronic Highway Sign e Tidy Hand saem do pacote. patch -s -p1 -d "$out/tree" < "$here/decipherism/decipherism-fonts.patch" cp "$cache/VT323-Regular-${FONTS_COMMIT:0:7}.ttf" "$out/tree/src/_assets/vt323.ttf" cp "$cache/Handlee-Regular-${FONTS_COMMIT:0:7}.ttf" "$out/tree/src/_assets/handlee.ttf" rm "$out/tree/src/_assets/font.ttf" "$out/tree/src/_assets/TidyHand.ttf" cd "$out/tree/src" GOOS=js GOARCH=wasm go build -trimpath -buildvcs=false -ldflags="-buildid=" -o "$out/main.wasm" . cp "$GOROOT/misc/wasm/wasm_exec.js" "$out/wasm_exec.js" # Licencas dos modulos que entram na build (go.sum travado; o Go confere os hashes). mkdir -p "$out/go-licenses" GOOS=js GOARCH=wasm go list -deps -f '{{with .Module}}{{.Path}} {{.Version}} {{.Dir}}{{end}}' . | sort -u | while read -r path ver dir; do [ -n "${dir:-}" ] || continue for f in "$dir"/LICEN[CS]E* "$dir"/COPYING* "$dir"/NOTICE*; do if [ -f "$f" ]; then echo "== $path $ver: $(basename "$f")"; cat "$f"; echo; fi done done > "$out/go-licenses/licenses.txt" GOOS=js GOARCH=wasm go list -deps -f '{{with .Module}}{{.Path}} {{.Version}}{{end}}' . | sort -u > "$out/go-licenses/modules.txt" ls -l "$out/main.wasm" "$out/wasm_exec.js" shasum -a 256 "$out/main.wasm" "$out/wasm_exec.js" "$out/decipherism-${COMMIT:0:7}.tar.gz"