Files
camoufox/scripts/stage-fonts.sh
T
Jake WriterandClaude Opus 5 41ba997799 build: stage bundled fonts into unpackaged builds
`mach build` leaves dist/bin/fonts holding only TwemojiMozilla.ttf -- the font
bundles and fontconfig are staged by scripts/package.py, so they exist only in
packaged builds. Anything launching the objdir binary through the Python
wrapper therefore starts a browser with no usable content font, because the
wrapper sets FONTCONFIG_FILE to a file that is not there.

It fails confusingly: the browser chrome still has system fonts, so the only
symptom is tofu boxes in page content, and through AsyncCamoufox it surfaces as
a TargetClosedError with no indication of the cause. That cost real time while
writing the tests/patches scripts, hence the note in their docstrings.

`make stage-fonts` copies them in. Idempotent, and a no-op when nothing is
built yet. Not needed by `make run` or `make tests`, which launch the binary
directly and fall back to the system fontconfig.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 14:32:42 -06:00

41 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
# Stage the bundled fonts and fontconfig into a local build's dist/bin.
#
# `mach build` leaves dist/bin/fonts holding only TwemojiMozilla.ttf; the font
# bundles and fontconfig are staged by scripts/package.py, so they exist only in
# packaged builds. Anything that runs the objdir binary directly -- `make run`,
# `make tests`, build-tester -- therefore starts a browser with no usable
# content font, and every glyph renders as a tofu box. That is silent: the
# browser chrome still has system fonts, so only page content is affected.
#
# Idempotent, and cheap enough to run before every launch.
set -e
version="$1"
release="$2"
if [ -z "$version" ] || [ -z "$release" ]; then
echo "Usage: $0 <version> <release>" >&2
exit 1
fi
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
dist_bin="$repo_root/camoufox-$version-$release/obj-x86_64-pc-linux-gnu/dist/bin"
if [ ! -d "$dist_bin" ]; then
exit 0 # nothing built yet
fi
for dir in linux macos windows; do
if [ ! -d "$dist_bin/fonts/$dir" ]; then
mkdir -p "$dist_bin/fonts"
cp -r "$repo_root/bundle/fonts/$dir" "$dist_bin/fonts/"
echo "staged fonts/$dir"
fi
if [ ! -d "$dist_bin/fontconfig/$dir" ]; then
mkdir -p "$dist_bin/fontconfig"
cp -r "$repo_root/bundle/fontconfig/$dir" "$dist_bin/fontconfig/"
echo "staged fontconfig/$dir"
fi
done