pcbjam/scripts/deps/build-pixman.sh
Gergő Törcsvári f6b0aaf122
findings X-1: pin every dependency tarball fetch to a SHA256 and enforce it
security-audit-v3 #15. download_file already had a verify branch; no caller
used it and every *_SHA256 in versions.sh was a commented placeholder, so a
tampered mirror tarball flowed straight into configure/make and the shipped
WASM.

- versions.sh: 13 pins (cross-checked against Homebrew/Buildroot/nixpkgs/
  FreeBSD/vcpkg/boost.org/curl PGP; glm .zip is TOFU), boost/curl/libgit2
  versions moved beside their pins.
- all 13 download_file call sites pass "${NAME_SHA256}".
- download_file refuses an empty or malformed pin (PCBJAM_ALLOW_UNPINNED=1
  to bootstrap a new dep); file_sha256 prefers sha256sum, falls back to shasum.
- scripts/deps/check-pins.sh: static 3-arg check + offline file:// enforcement
  test; runs in wasm-build.yml before the deps cache, on cache hits too.

Expect one cold --build-deps run: the deps-cache key hashes versions.sh.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GcsgJZ77bhZatLAVU8R84H
2026-08-28 20:34:16 +02:00

98 lines
2.3 KiB
Shell
Executable file

#!/bin/bash
# Build Pixman for WebAssembly
# Pixman is required by Cairo for pixel manipulation
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/../common/env.sh"
source "${SCRIPT_DIR}/../common/versions.sh"
source "${SCRIPT_DIR}/../common/functions.sh"
PIXMAN_DIR="${DEPS_ROOT}/pixman-${PIXMAN_VERSION}"
PIXMAN_BUILD="${BUILD_ROOT}/deps/pixman"
PIXMAN_STAMP="${BUILD_ROOT}/stamps/pixman.stamp"
# Parse arguments
CLEAN=0
for arg in "$@"; do
case $arg in
--clean)
CLEAN=1
shift
;;
esac
done
if [ $CLEAN -eq 1 ]; then
log_info "Cleaning Pixman build..."
rm -rf "${PIXMAN_BUILD}" "${PIXMAN_STAMP}"
fi
# Check if already built
if check_stamp "${PIXMAN_STAMP}"; then
log_info "Pixman already built, skipping..."
exit 0
fi
# Download if needed
if [ ! -d "${PIXMAN_DIR}" ]; then
log_info "Downloading Pixman ${PIXMAN_VERSION}..."
mkdir -p "${DEPS_ROOT}"
cd "${DEPS_ROOT}"
PIXMAN_URL="https://cairographics.org/releases/pixman-${PIXMAN_VERSION}.tar.gz"
download_file "${PIXMAN_URL}" "pixman-${PIXMAN_VERSION}.tar.gz" "${PIXMAN_SHA256}"
tar -xzf "pixman-${PIXMAN_VERSION}.tar.gz"
rm "pixman-${PIXMAN_VERSION}.tar.gz"
fi
log_info "Building Pixman ${PIXMAN_VERSION} for WASM..."
mkdir -p "${PIXMAN_BUILD}"
cd "${PIXMAN_BUILD}"
# Determine meson build type based on DEBUG_BUILD
if [ "${DEBUG_BUILD:-1}" = "1" ]; then
MESON_BUILD_TYPE="debug"
MESON_DEBUG_FLAGS="'-g', '-O0'"
else
MESON_BUILD_TYPE="release"
MESON_DEBUG_FLAGS="'-O2'"
fi
# Pixman uses meson
cat > cross-file.txt << EOF
[binaries]
c = 'emcc'
cpp = 'em++'
ar = 'emar'
ranlib = 'emranlib'
strip = 'emstrip'
[host_machine]
system = 'emscripten'
cpu_family = 'wasm32'
cpu = 'wasm32'
endian = 'little'
[built-in options]
c_args = [${MESON_DEBUG_FLAGS}, '-pthread', '-matomics', '-mbulk-memory']
c_link_args = ['-pthread']
EOF
meson setup "${PIXMAN_DIR}" \
--cross-file cross-file.txt \
--prefix="${SYSROOT}" \
--default-library=static \
--buildtype=${MESON_BUILD_TYPE} \
-Dgtk=disabled \
-Dlibpng=disabled \
-Dtests=disabled
# JOBS is set in env.sh (default: 1 for sequential builds, use -j N to override)
ninja -j${JOBS}
ninja install
create_stamp "${PIXMAN_STAMP}"
log_info "Pixman build complete!"