#!/usr/bin/env bash # Compila o Motumbo (sumo de fisica em 3D de axelromero99 / destap, MIT; simulacao inteira em C sobre o Box3D de Erin Catto, MIT, # compilada para WebAssembly, mais Vite + TypeScript + three.js; escrito com ajuda de um agente de IA, como mostra o CLAUDE.md do # repositorio) a partir do commit 141cb97 de github.com/axelromero99/motumbo, com o Box3D no commit 1c5ac42 (o mesmo que o autor fixa # no setup.ps1 e no ci.yml), Emscripten 6.0.10 de artifacts/tools/emsdk (o autor usa 6.0.2; para jogar sozinho a diferenca nao importa), # CMake do sistema (so gera os Makefiles) e o "npm ci" do package-lock.json do autor com o Node 24.21.0 de artifacts/tools. # # Mudancas (motumbo/patch.py, publicado junto do fonte): o jogo online (matchmaking e salas por MQTT publico, WebRTC com STUN do Google, # relay) sai, JUGAR vira partida rapida contra bots; a interface, em espanhol, vai para o ingles; e uma CSP bloqueia qualquer requisicao # fora da propria pagina. O fonte (C e TypeScript) fica como esta, so com isso. # # src/FredGames.Bundler/Builds/build-motumbo.sh # # Saida: artifacts/build/motumbo-141cb97/{motumbo-141cb97-dist.tar.gz,licenses.txt}; o tar.gz (pasta dist/) tem que sair igual em dois # builds seguidos (no mesmo caminho: o wasm leva o caminho dos fontes nas mensagens de assert). licenses.txt traz a licenca do three.js. set -euo pipefail COMMIT=141cb972982e08b3ca5552ae75a7e58388314e4b SHA256=fa584711aa9971a4730098f554356061480b8e2d11f5ca4436318b45053e8389 BOX3D=1c5ac42c376eb216734df1f35d14bf33c29bb6e7 BOX3D_SHA256=1dd676aa7790a6f331ce8f0f0a095e97eaa44f8ca65354a8cc72cc4edcd44be6 NODE=24.21.0 here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" root="$(git -C "$here" rev-parse --show-toplevel 2>/dev/null || pwd)" out="$root/artifacts/build/motumbo-${COMMIT:0:7}" cache="$root/artifacts/build/cache" nodebin="$root/artifacts/tools/node-v$NODE/bin" [ -x "$nodebin/node" ] && [ "$("$nodebin/node" -v)" = "v$NODE" ] || { echo "Precisa do Node $NODE em $nodebin." >&2; exit 1; } export PATH="$nodebin:$PATH" # shellcheck disable=SC1091 source "$root/artifacts/tools/emsdk/emsdk_env.sh" > /dev/null 2>&1 [ "$(emcc --version | head -1 | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' | head -1)" = "6.0.10" ] || { echo "Precisa do Emscripten 6.0.10." >&2; exit 1; } 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 - } fetch "https://github.com/axelromero99/motumbo/archive/$COMMIT.tar.gz" "motumbo-${COMMIT:0:7}.tar.gz" "$SHA256" fetch "https://github.com/erincatto/box3d/archive/$BOX3D.tar.gz" "box3d-${BOX3D:0:7}.tar.gz" "$BOX3D_SHA256" rm -rf "$out" mkdir -p "$out/tree/vendor/box3d" tar -xzf "$cache/motumbo-${COMMIT:0:7}.tar.gz" -C "$out/tree" --strip-components 1 tar -xzf "$cache/box3d-${BOX3D:0:7}.tar.gz" -C "$out/tree/vendor/box3d" --strip-components 1 cd "$out/tree" python3 -I "$here/motumbo/patch.py" . # simulacao em C -> WebAssembly (o mesmo que scripts/build-sim.ps1 faz no Windows) emcmake cmake -S . -B build/wasm -DCMAKE_BUILD_TYPE=Release > "$out/cmake.log" 2>&1 || { tail -20 "$out/cmake.log"; exit 1; } cmake --build build/wasm --target sim -j4 > "$out/make.log" 2>&1 || { tail -30 "$out/make.log"; exit 1; } mkdir -p web/src/gen cp build/wasm/motumbo.js build/wasm/motumbo.wasm web/src/gen/ # web: Vite + TypeScript + three.js cd web export npm_config_cache="$cache/npm-motumbo" npm_config_update_notifier=false PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm ci --ignore-scripts --no-audit --no-fund --loglevel=error npx tsc --noEmit > "$out/tsc.log" 2>&1 || { tail -30 "$out/tsc.log"; exit 1; } npx vite build > "$out/build.log" 2>&1 || { tail -30 "$out/build.log"; exit 1; } [ -f dist/index.html ] if grep -rIE "stun:|wss?://|RTCPeerConnection\(|broker\." dist --include='*.js' | grep -v '^$' | head -3 | grep .; then echo "Sobrou codigo de rede no dist." >&2; exit 1 fi { echo "== three $(node -p "require('./node_modules/three/package.json').version"): LICENSE" cat node_modules/three/LICENSE } > "$out/licenses.txt" # dist/ vira um tar.gz deterministico (datas fixas, ordem fixa, sem dono). cp -R dist "$out/dist" find "$out/dist" -exec touch -t 202611060000 {} + ( 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 > "motumbo-${COMMIT:0:7}-dist.tar.gz" && rm files.txt ) rm -rf "$out/tree" ls -l "$out/motumbo-${COMMIT:0:7}-dist.tar.gz" shasum -a 256 "$out/motumbo-${COMMIT:0:7}-dist.tar.gz" "$out/licenses.txt" find "$out/dist" -type f | sed "s|$out/||"