flan/vendor/raylib/build-web.sh
Joseph Ferano 57fe91f303 Five records become one, and every citation lands somewhere
FIX.org, NEXT.md, DISCUSS.org, docs/DISCUSS.md and the session handoff at the
root are one TODO.org now: 293 entries under seven subsystem headings, each
carrying an org keyword that says where it stands. A DONE entry is a few lines
saying what was decided and what that rules out; the reasoning that would not
compress — the embedding spike and the four reports the hand-written x86
backend was built from — moved into docs/BUILT.md instead, and its entries
point there in one line.

Every entry was checked against the tree before it got a keyword, and the
prose was wrong in both directions. Things the deleted files called open were
built: the first-evaluation stall, main being redefinable, macro parameter
lists, the type-limit constants, the array constructors, the byte fills,
inc/dec, the discard's fontification, the Emacs buffers, rt_die's _exit, the
backtrace surface, and the acceptance failure that could print and still exit
zero. Things they called done were not: the backend reports' no-plan buckets
had gone stale in the other direction, the value-dependent defvar was
superseded rather than built, and macro-expansion source locations are on an
unmerged lane, so that entry is NEXT and names the branch.

Every comment that cited one of the five by name now cites a heading that
exists, in TODO.org or in docs/BUILT.md. The session reports under
docs/handoffs/ keep naming the files they worked on, because rewriting them
would falsify what those sessions did; each carries a note saying where the
content went.
2026-09-21 21:05:48 +07:00

77 lines
2.7 KiB
Bash

#!/bin/sh
# raylib, built for the browser.
#
# The host half of this package needs no build: Fedora ships libraylib.so.550
# and `link` names it. The browser has no such thing, so the archive has to be
# made here, once, out of raylib's own sources with emscripten's clang.
#
# Pinned to the tag whose shared library the host links — 5.5 against
# libraylib.so.550 — because `raylib.flan` carries struct layouts and enum
# values that are raylib's, not ours, and a build where the two targets are
# different raylibs would disagree about them silently.
#
# The output is a plain static archive plus nothing else: no headers are
# installed, because the generated FFI shim declares the prototypes it uses
# (see docs/BUILT.md, "What a headless FFI test can and cannot pin").
#
# sh vendor/raylib/build-web.sh
#
# It prints the line to export. `vendor/raylib/link` points at the archive
# through ${FLAN_RAYLIB_WEB}, and a web build that names raylib with the
# variable unset is refused by name rather than met at the linker.
#
# Environment:
# FLAN_RAYLIB_TAG the raylib tag to build (default 5.5)
# FLAN_RAYLIB_WEB_DIR where to put it (default vendor/raylib/web)
# FLAN_RAYLIB_SRC an existing raylib checkout to build instead of cloning
set -eu
tag=${FLAN_RAYLIB_TAG:-5.5}
here=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
out=${FLAN_RAYLIB_WEB_DIR:-$here/web}
archive=$out/libraylib-$tag.a
command -v emcc > /dev/null 2>&1 || {
echo "build-web.sh: no emcc on PATH. Source an emsdk's emsdk_env.sh." >&2
exit 1
}
if [ -f "$archive" ]; then
echo "already built: $archive" >&2
else
mkdir -p "$out"
if [ -n "${FLAN_RAYLIB_SRC:-}" ]; then
src=$FLAN_RAYLIB_SRC
else
src=$out/raylib-$tag
[ -d "$src" ] || git clone --depth 1 --branch "$tag" \
https://github.com/raysan5/raylib "$src"
fi
objs=$out/obj-$tag
rm -rf "$objs"
mkdir -p "$objs"
# GRAPHICS_API_OPENGL_ES2 is what WebGL is. PLATFORM_WEB makes rcore.c
# include platforms/rcore_web.c, whose WindowShouldClose() is an
# emscripten_sleep that returns false — see docs/BUILT.md on why that is the whole
# reason a Flan `until` loop needs no rewriting for the browser.
#
# rglfw.c is not in the list: the web platform uses emscripten's own GLFW
# (-sUSE_GLFW=3, in `link`), not a compiled-in one.
for m in rcore rshapes rtextures rtext rmodels raudio utils; do
[ -f "$src/src/$m.c" ] || continue
echo " emcc $m.c" >&2
(cd "$src/src" && emcc -c -O2 -std=gnu99 \
-DPLATFORM_WEB -DGRAPHICS_API_OPENGL_ES2 \
-I. -Iexternal/glfw/include \
"$m.c" -o "$objs/$m.o")
done
emar rcs "$archive" "$objs"/*.o
rm -rf "$objs"
fi
echo
echo "export FLAN_RAYLIB_WEB=$archive"