Add reproducible build system for wxWidgets WASM port

- Add unified patch (wxwidgets-wasm.patch) for build validation
- Add scripts:
  - generate-wxwidgets-patches.sh: Extract patches from wxwidgets state
  - build-wxwidgets-wasm-clean.sh: Build from clean clone + patches
  - build-wxuniversal-wasm.sh: Build wxWidgets for WASM
- Add wxWidgets-wasm-reference submodule (ahilss/wxWidgets-wasm)
- Update .gitignore for wxwidgets-clean/ directory

Base commit: 5ff25322553c1870cf20a2e1ba6f20ed50d9fe9a

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Viktor Vaczi 2025-11-27 15:30:10 +01:00
commit b7d9d32acb
9 changed files with 122800 additions and 2 deletions

5
.gitignore vendored
View file

@ -26,4 +26,7 @@ cmake-build-*/
.DS_Store
# Emscripten cache
.emscripten_cache/
.emscripten_cache/
# Clean clone for reproducible builds (generated by build-wxwidgets-wasm-clean.sh)
wxwidgets-clean/

5
.gitmodules vendored
View file

@ -3,4 +3,7 @@
url = git@github.com:VV-EE/kicad-source-mirror.git
[submodule "wxwidgets"]
path = wxwidgets
url = https://github.com/wxWidgets/wxWidgets.git
url = git@github.com:VV-EE/wxWidgets.git
[submodule "wxWidgets-wasm-reference"]
path = wxWidgets-wasm-reference
url = git@github.com:ahilss/wxWidgets-wasm.git

View file

@ -0,0 +1,47 @@
# wxWidgets WASM Port Patch
Single unified patch that transforms wxWidgets into a WASM-capable build.
## Base Version
- Repository: git@github.com:VV-EE/wxWidgets.git
- Commit: 5ff25322553c1870cf20a2e1ba6f20ed50d9fe9a
- Generated: 2025-11-27 14:10:12 UTC
## Patch Contents
This single patch includes:
- Main wxWidgets modifications (config.sub, configure.in, headers, sources)
- New WASM platform: src/wasm/, include/wx/wasm/
- New build files: build/wasm/
- WASM theme renderer: src/univ/themes/wasm.cpp
- Submodule config.sub updates for emscripten/wasm32 support:
- 3rdparty/pcre/config.sub
- src/expat/expat/conftools/config.sub
- src/jpeg/config.sub
- src/png/config.sub
- src/tiff/config/config.sub
## Apply Instructions
```bash
# Clone wxWidgets fork at the base commit
git clone git@github.com:VV-EE/wxWidgets.git wxwidgets-clean
cd wxwidgets-clean
git checkout 5ff25322553c1870cf20a2e1ba6f20ed50d9fe9a
git submodule update --init --recursive
# Apply the unified patch
patch -p1 < /path/to/patches/wxwidgets-wasm/wxwidgets-wasm.patch
# Build
mkdir build && cd build
emconfigure ../configure --host=emscripten --enable-universal ...
emmake make
```
## Verification
```bash
shasum -a 256 -c checksums.sha256
```

View file

@ -0,0 +1 @@
bc0e065e90bd8ef278532d972e74e975e968e9c3cb0b4f50b989ca4bf2bc48ee wxwidgets-wasm.patch

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,72 @@
#!/bin/bash
# Build wxWidgets with wxUniversal for WebAssembly
# This builds the GUI-enabled wxWidgets needed for KiCad
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
BUILD_DIR="$PROJECT_ROOT/build-wasm/wxwidgets-universal"
WX_SOURCE="$PROJECT_ROOT/wxwidgets"
echo "=== Building wxWidgets wxUniversal for WASM ==="
echo "Project root: $PROJECT_ROOT"
echo "Build dir: $BUILD_DIR"
echo "wxWidgets source: $WX_SOURCE"
# Verify we're in the right place
if [ ! -f "$WX_SOURCE/configure" ]; then
echo "ERROR: wxWidgets source not found at $WX_SOURCE"
echo "Make sure the wxwidgets submodule is initialized"
exit 1
fi
# Clean if requested
if [ "$1" = "--clean" ]; then
echo "Cleaning build directory..."
rm -rf "$BUILD_DIR"
fi
# Create build directory
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
# Configure with emconfigure
# Key flags based on wxWidgets-wasm:
# --host=emscripten Host system (detected via config.sub)
# --enable-universal Use wxUniversal (draws widgets directly)
# --disable-shared Build static libraries
# --with-opengl Enable OpenGL/WebGL support
# --disable-exceptions Emscripten doesn't support C++ exceptions well
# --disable-richtext Not needed for KiCad, simplifies build
# --without-libtiff Avoid external dependencies
# --disable-xlocale Browser environment handles locale
echo ""
echo "=== Configuring ==="
# Set flags for Emscripten compatibility
# Z_HAVE_UNISTD_H ensures zlib includes <unistd.h> for read/write/lseek
export CFLAGS="-DZ_HAVE_UNISTD_H=1"
export CXXFLAGS="-DZ_HAVE_UNISTD_H=1"
emconfigure "$WX_SOURCE/configure" \
--host=emscripten \
--enable-universal \
--disable-shared \
--with-opengl \
--disable-exceptions \
--disable-richtext \
--without-libtiff \
--disable-xlocale \
--with-cxx=17 \
--enable-utf8
# Build
echo ""
echo "=== Building ==="
emmake make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu)
echo ""
echo "=== Build complete ==="
ls -lh "$BUILD_DIR"/lib/*.a 2>/dev/null || echo "Libraries built in $BUILD_DIR/lib"

View file

@ -0,0 +1,178 @@
#!/bin/bash
# Build wxWidgets for WASM from a clean clone + patches
# This tests that our patches can reproduce the build
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
PATCHES_DIR="$PROJECT_ROOT/patches/wxwidgets-wasm"
CLONE_DIR="$PROJECT_ROOT/wxwidgets-clean"
BUILD_DIR="$PROJECT_ROOT/build-wasm/wxwidgets-clean"
REFERENCE_BUILD="$PROJECT_ROOT/build-wasm/wxwidgets-universal"
# Configuration - fork URL and commit
WX_REPO="git@github.com:VV-EE/wxWidgets.git"
WX_COMMIT="5ff25322553c1870cf20a2e1ba6f20ed50d9fe9a"
# Parse arguments
CLEAN=false
SKIP_BUILD=false
while [[ $# -gt 0 ]]; do
case $1 in
--clean) CLEAN=true; shift ;;
--skip-build) SKIP_BUILD=true; shift ;;
--help)
echo "Usage: $0 [OPTIONS]"
echo " --clean Force fresh clone (remove existing)"
echo " --skip-build Only clone and patch, skip building"
exit 0
;;
*) echo "Unknown option: $1"; exit 1 ;;
esac
done
echo "=== wxWidgets WASM Clean Build ==="
echo "Repository: $WX_REPO"
echo "Commit: $WX_COMMIT"
echo "Clone dir: $CLONE_DIR"
echo "Build dir: $BUILD_DIR"
echo ""
# Verify patch exists
if [ ! -f "$PATCHES_DIR/wxwidgets-wasm.patch" ]; then
echo "ERROR: Patch not found: $PATCHES_DIR/wxwidgets-wasm.patch"
echo "Run ./scripts/generate-wxwidgets-patches.sh first"
exit 1
fi
# Verify checksums
echo "=== Verifying patch checksums ==="
cd "$PATCHES_DIR"
if ! shasum -a 256 -c checksums.sha256; then
echo "ERROR: Patch checksum verification failed"
exit 1
fi
echo "Checksums OK"
echo ""
# Step 1: Clone repository
echo "=== Step 1: Clone repository ==="
if [ "$CLEAN" = true ] || [ ! -d "$CLONE_DIR/.git" ]; then
rm -rf "$CLONE_DIR"
echo "Cloning $WX_REPO..."
git clone "$WX_REPO" "$CLONE_DIR"
cd "$CLONE_DIR"
git checkout "$WX_COMMIT"
else
echo "Using existing clone at $CLONE_DIR"
cd "$CLONE_DIR"
git fetch origin
git checkout "$WX_COMMIT"
git reset --hard "$WX_COMMIT"
fi
echo ""
# Step 2: Initialize submodules
echo "=== Step 2: Initialize submodules ==="
git submodule update --init --recursive
echo ""
# Step 3: Apply the unified patch
echo "=== Step 3: Apply unified patch ==="
echo "Applying wxwidgets-wasm.patch..."
patch -p1 < "$PATCHES_DIR/wxwidgets-wasm.patch"
echo ""
if [ "$SKIP_BUILD" = true ]; then
echo "=== Skipping build (--skip-build) ==="
echo "Clone and patch complete. Source ready at: $CLONE_DIR"
exit 0
fi
# Step 4: Configure and build
echo "=== Step 4: Configure ==="
rm -rf "$BUILD_DIR"
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
export CFLAGS="-DZ_HAVE_UNISTD_H=1"
export CXXFLAGS="-DZ_HAVE_UNISTD_H=1"
emconfigure "$CLONE_DIR/configure" \
--host=emscripten \
--enable-universal \
--disable-shared \
--with-opengl \
--disable-exceptions \
--disable-richtext \
--without-libtiff \
--disable-xlocale \
--with-cxx=17 \
--enable-utf8
echo ""
echo "=== Step 5: Build ==="
emmake make -j$(sysctl -n hw.ncpu 2>/dev/null || nproc 2>/dev/null || echo 4)
echo ""
echo "=== Step 6: Verify and compare ==="
# List built libraries
echo "Built libraries:"
ls -lh "$BUILD_DIR/lib/"*.a 2>/dev/null || echo "No libraries found"
# Compare with reference build if it exists
if [ -d "$REFERENCE_BUILD/lib" ]; then
echo ""
echo "=== Comparison with reference build ==="
printf "%-50s %12s %12s %10s\n" "Library" "Reference" "Clean" "Match"
printf "%-50s %12s %12s %10s\n" "-------" "---------" "-----" "-----"
MISMATCH=0
for lib in "$BUILD_DIR/lib/"*.a; do
basename=$(basename "$lib")
ref_lib="$REFERENCE_BUILD/lib/$basename"
if [ -f "$ref_lib" ]; then
# Get sizes (macOS stat syntax)
new_size=$(stat -f%z "$lib" 2>/dev/null || stat -c%s "$lib")
ref_size=$(stat -f%z "$ref_lib" 2>/dev/null || stat -c%s "$ref_lib")
if [ "$new_size" -eq "$ref_size" ]; then
match="YES"
else
match="NO (diff: $((new_size - ref_size)))"
MISMATCH=1
fi
printf "%-50s %12d %12d %10s\n" "$basename" "$ref_size" "$new_size" "$match"
else
printf "%-50s %12s %12d %10s\n" "$basename" "(missing)" "$new_size" "NEW"
fi
done
# Check for libraries in reference but not in clean build
for lib in "$REFERENCE_BUILD/lib/"*.a; do
basename=$(basename "$lib")
if [ ! -f "$BUILD_DIR/lib/$basename" ]; then
ref_size=$(stat -f%z "$lib" 2>/dev/null || stat -c%s "$lib")
printf "%-50s %12d %12s %10s\n" "$basename" "$ref_size" "(missing)" "MISSING"
MISMATCH=1
fi
done
echo ""
if [ "$MISMATCH" -eq 0 ]; then
echo "SUCCESS: All libraries match!"
else
echo "WARNING: Some libraries differ (this may be expected due to build timestamps)"
fi
else
echo ""
echo "No reference build found at $REFERENCE_BUILD"
echo "Run ./scripts/build-wxuniversal-wasm.sh first to create a reference"
fi
echo ""
echo "=== Build complete ==="
echo "Libraries in: $BUILD_DIR/lib/"

View file

@ -0,0 +1,163 @@
#!/bin/bash
# Generate a single unified patch from current wxwidgets state
# This captures ALL modifications including submodule config.sub changes
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
WX_SOURCE="$PROJECT_ROOT/wxwidgets"
PATCHES_DIR="$PROJECT_ROOT/patches/wxwidgets-wasm"
PATCH_FILE="$PATCHES_DIR/wxwidgets-wasm.patch"
echo "=== Generating wxWidgets WASM Unified Patch ==="
echo "Source: $WX_SOURCE"
echo "Output: $PATCH_FILE"
# Verify wxwidgets exists (check for .git as file or directory - submodules use a file)
if [ ! -e "$WX_SOURCE/.git" ]; then
echo "ERROR: wxwidgets is not a git repository"
exit 1
fi
# Create output directory
mkdir -p "$PATCHES_DIR"
cd "$WX_SOURCE"
# Capture current commit SHA (the base we're patching from)
CURRENT_COMMIT=$(git rev-parse HEAD)
echo ""
echo "Base commit: $CURRENT_COMMIT"
# Start with empty patch file
> "$PATCH_FILE"
echo ""
echo "=== Part 1: Main wxWidgets changes ==="
# Mark all untracked files as "intent to add" (allows git diff to see them)
git add -N .
# Generate main diff (excluding submodule directory pointers, but including everything else)
git diff HEAD -- . \
':!3rdparty/catch' \
':!3rdparty/nanosvg' \
':!3rdparty/pcre' \
':!src/expat' \
':!src/jpeg' \
':!src/png' \
':!src/tiff' \
':!src/zlib' \
>> "$PATCH_FILE"
# Undo the intent-to-add
git reset HEAD --quiet
MAIN_LINES=$(wc -l < "$PATCH_FILE")
echo "Added main changes ($MAIN_LINES lines so far)"
echo ""
echo "=== Part 2: Submodule config.sub changes ==="
# Process each submodule config.sub
add_submodule_config_sub() {
local submodule="$1"
local config_sub_path="$2"
local full_path="$WX_SOURCE/$config_sub_path"
if [ -d "$WX_SOURCE/$submodule" ] && [ -f "$full_path" ]; then
cd "$WX_SOURCE/$submodule"
# Get the relative path within the submodule
local rel_config_sub="${config_sub_path#$submodule/}"
# Check if config.sub is modified in this submodule
if ! git diff --quiet HEAD -- "$rel_config_sub" 2>/dev/null; then
echo " Adding $config_sub_path"
# Generate diff with paths rewritten to be relative to main repo
git diff HEAD -- "$rel_config_sub" | sed "s|a/$rel_config_sub|a/$config_sub_path|g; s|b/$rel_config_sub|b/$config_sub_path|g" >> "$PATCH_FILE"
else
echo " Skipping $config_sub_path (no changes)"
fi
else
echo " Skipping $submodule (not found)"
fi
}
add_submodule_config_sub "3rdparty/pcre" "3rdparty/pcre/config.sub"
add_submodule_config_sub "src/expat" "src/expat/expat/conftools/config.sub"
add_submodule_config_sub "src/jpeg" "src/jpeg/config.sub"
add_submodule_config_sub "src/png" "src/png/config.sub"
add_submodule_config_sub "src/tiff" "src/tiff/config/config.sub"
cd "$WX_SOURCE"
TOTAL_LINES=$(wc -l < "$PATCH_FILE")
echo ""
echo "Total patch: $TOTAL_LINES lines"
echo ""
echo "=== Generating checksums ==="
cd "$PATCHES_DIR"
shasum -a 256 *.patch > checksums.sha256
echo "Created checksums.sha256"
echo ""
echo "=== Generating README ==="
cat > README.md << EOF
# wxWidgets WASM Port Patch
Single unified patch that transforms wxWidgets into a WASM-capable build.
## Base Version
- Repository: git@github.com:VV-EE/wxWidgets.git
- Commit: $CURRENT_COMMIT
- Generated: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
## Patch Contents
This single patch includes:
- Main wxWidgets modifications (config.sub, configure.in, headers, sources)
- New WASM platform: src/wasm/, include/wx/wasm/
- New build files: build/wasm/
- WASM theme renderer: src/univ/themes/wasm.cpp
- Submodule config.sub updates for emscripten/wasm32 support:
- 3rdparty/pcre/config.sub
- src/expat/expat/conftools/config.sub
- src/jpeg/config.sub
- src/png/config.sub
- src/tiff/config/config.sub
## Apply Instructions
\`\`\`bash
# Clone wxWidgets fork at the base commit
git clone git@github.com:VV-EE/wxWidgets.git wxwidgets-clean
cd wxwidgets-clean
git checkout $CURRENT_COMMIT
git submodule update --init --recursive
# Apply the unified patch
patch -p1 < /path/to/patches/wxwidgets-wasm/wxwidgets-wasm.patch
# Build
mkdir build && cd build
emconfigure ../configure --host=emscripten --enable-universal ...
emmake make
\`\`\`
## Verification
\`\`\`bash
shasum -a 256 -c checksums.sha256
\`\`\`
EOF
echo "Created README.md"
echo ""
echo "=== Summary ==="
ls -lh "$PATCHES_DIR"
echo ""
echo "Unified patch generated successfully!"

@ -0,0 +1 @@
Subproject commit 293bd9febaea31375447a83f0aec79f022135ac1