diff --git a/docker/build.sh b/docker/build.sh index 4dfdb66..e9d3fe2 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -11,11 +11,6 @@ set -e cd "$(dirname "$0")/.." -# Get wasm-opt (downloads Binaryen v121 if not cached) -echo "Checking wasm-opt..." -WASM_OPT=$(./scripts/common/get-wasm-opt.sh) -echo "Using: ${WASM_OPT}" - # Start container if not running docker compose -f docker/docker-compose.yml up -d @@ -29,21 +24,8 @@ docker compose -f docker/docker-compose.yml exec kicad-wasm-builder \ bash -c "mkdir -p /workspace/output && cp /workspace/build-wasm/kicad-pcbnew/pcbnew/pcbnew.{js,wasm,wasm.map,worker.js} /workspace/output/ 2>/dev/null || cp /workspace/build-wasm/kicad-pcbnew/pcbnew/pcbnew.{js,wasm} /workspace/output/" # Apply asyncify transformation on host -# This is done on the host because wasm-opt --asyncify needs 50GB+ RAM for KiCad, -# which exceeds typical Docker memory limits -echo "" -echo "Applying asyncify transformation on host..." -echo "This may take several minutes and use significant RAM..." - -# Asyncify import patterns (functions that trigger async suspension) -# - env.invoke_* : Exception handling trampolines -# - env.__asyncjs__* : EM_ASYNC_JS functions -ASYNCIFY_IMPORTS="env.invoke_*,env.__asyncjs__*" - -"${WASM_OPT}" --asyncify \ - --pass-arg=asyncify-imports@${ASYNCIFY_IMPORTS} \ - --pass-arg=asyncify-propagate-addlist \ - output/pcbnew.wasm -o output/pcbnew.wasm +# This is done on the host because wasm-opt --asyncify needs significant RAM +./scripts/common/apply-asyncify.sh output/pcbnew.wasm output/pcbnew.wasm echo "" echo "Build complete. Output files in ./output/" diff --git a/scripts/build-wxuniversal-wasm.sh b/scripts/build-wxuniversal-wasm.sh index 8a9629b..5e980af 100755 --- a/scripts/build-wxuniversal-wasm.sh +++ b/scripts/build-wxuniversal-wasm.sh @@ -98,6 +98,7 @@ emconfigure "$WX_SOURCE/configure" \ --disable-xlocale \ --with-cxx=17 \ --enable-utf8 \ + --with-zlib=sys \ ${WX_CONFIGURE_DEBUG} # Build PCRE first to avoid race condition with parallel builds diff --git a/scripts/common/apply-asyncify.sh b/scripts/common/apply-asyncify.sh new file mode 100755 index 0000000..3f837bc --- /dev/null +++ b/scripts/common/apply-asyncify.sh @@ -0,0 +1,60 @@ +#!/bin/bash +# Apply asyncify transformation to KiCad WASM +# +# Usage: ./scripts/common/apply-asyncify.sh +# +# This script is called by docker/build.sh but can also be run standalone +# for debugging asyncify issues. + +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" + +# Get wasm-opt path +WASM_OPT=$("${SCRIPT_DIR}/get-wasm-opt.sh") + +INPUT_WASM="${1:-output/pcbnew.wasm}" +OUTPUT_WASM="${2:-${INPUT_WASM}}" + +if [ ! -f "${INPUT_WASM}" ]; then + echo "ERROR: Input file not found: ${INPUT_WASM}" + exit 1 +fi + +echo "Applying asyncify transformation..." +echo " Input: ${INPUT_WASM}" +echo " Output: ${OUTPUT_WASM}" +echo " Tool: ${WASM_OPT}" + +# Asyncify import patterns (functions that trigger async suspension) +# - env.invoke_* : Exception handling trampolines +# - env.__asyncjs__* : EM_ASYNC_JS functions (like startModal()) +ASYNCIFY_IMPORTS="env.invoke_*,env.__asyncjs__*" + +# Functions to exclude from asyncify instrumentation +# These are large functions that inflate beyond V8's 7.65MB function limit +# The names must match exactly as they appear in the WASM (C++ mangled names) +ASYNCIFY_REMOVE=$(cat << 'REMOVELIST' +COLOR_SETTINGS::COLOR_SETTINGS(wxString const&, bool) +BuildBitmapInfo(std::__2::unordered_map>, std::__2::hash, std::__2::equal_to, std::__2::allocator>>>>&) +match +REMOVELIST +) + +# Convert newlines to commas for the removelist +ASYNCIFY_REMOVE_ARG=$(echo "${ASYNCIFY_REMOVE}" | tr '\n' ',' | sed 's/,$//') + +echo "" +echo "Running wasm-opt --asyncify..." +echo "This may take several minutes and use significant RAM..." + +"${WASM_OPT}" --asyncify \ + "--pass-arg=asyncify-imports@${ASYNCIFY_IMPORTS}" \ + "--pass-arg=asyncify-removelist@${ASYNCIFY_REMOVE_ARG}" \ + --pass-arg=asyncify-propagate-addlist \ + "${INPUT_WASM}" -o "${OUTPUT_WASM}" + +echo "" +echo "Asyncify complete: ${OUTPUT_WASM}" +ls -lh "${OUTPUT_WASM}" diff --git a/scripts/kicad/build-pcbnew.sh b/scripts/kicad/build-pcbnew.sh index 9346178..a8cc35b 100755 --- a/scripts/kicad/build-pcbnew.sh +++ b/scripts/kicad/build-pcbnew.sh @@ -157,6 +157,19 @@ emar rcs "${STUBS_BUILD}/libcurl_stub.a" "${STUBS_BUILD}/curl_stub.o" log_info "Stub libraries built" +# Step 6.2: Replace Emscripten's wasm-opt with stub to bypass asyncify transformation +# This allows Emscripten to generate JS with Asyncify runtime, but we run the real +# wasm-opt --asyncify on the host where more RAM is available (needs 50GB+ for KiCad) +EMSDK_WASM_OPT="/emsdk/upstream/bin/wasm-opt" +if [ -f "${EMSDK_WASM_OPT}" ] && [ ! -f "${EMSDK_WASM_OPT}.real" ]; then + log_info "Backing up real wasm-opt..." + mv "${EMSDK_WASM_OPT}" "${EMSDK_WASM_OPT}.real" +fi +# Always copy the latest stub (in case it was updated) +cp "${STUBS_DIR}/wasm-opt-stub.sh" "${EMSDK_WASM_OPT}" +chmod +x "${EMSDK_WASM_OPT}" +log_info "wasm-opt stub installed (asyncify will run on host)" + # Step 6.5: Verify WASM support is in KiCad fork # The kicad submodule should already have WASM port detection and kiplatform support KICAD_CMAKE="${KICAD_DIR}/CMakeLists.txt" @@ -184,7 +197,7 @@ emcmake cmake "${KICAD_DIR}" \ -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \ -DCMAKE_CXX_FLAGS="${EXTRA_FLAGS} -pthread -sUSE_ZLIB=1 -DKICAD_USE_PLATFORM_WASM=1 -I${SYSROOT}/include" \ -DCMAKE_C_FLAGS="${EXTRA_FLAGS} -pthread -sUSE_ZLIB=1 -I${SYSROOT}/include" \ - -DCMAKE_EXE_LINKER_FLAGS="${LINKER_DEBUG_FLAGS} -pthread -sUSE_ZLIB=1 -sUSE_PTHREADS=1 -sPTHREAD_POOL_SIZE=4 -sALLOW_MEMORY_GROWTH=1 -sINITIAL_MEMORY=256MB -sMAXIMUM_MEMORY=4GB -L${SYSROOT}/lib ${STUBS_BUILD}/libgit2_stub.a ${STUBS_BUILD}/libcurl_stub.a" \ + -DCMAKE_EXE_LINKER_FLAGS="${LINKER_DEBUG_FLAGS} -pthread -sUSE_ZLIB=1 -sASYNCIFY=1 -sASYNCIFY_STACK_SIZE=65536 -sUSE_PTHREADS=1 -sPTHREAD_POOL_SIZE=4 -sALLOW_MEMORY_GROWTH=1 -sINITIAL_MEMORY=256MB -sMAXIMUM_MEMORY=4GB -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap','UTF8ToString','stringToUTF8','lengthBytesUTF8'] -L${SYSROOT}/lib ${STUBS_BUILD}/libgit2_stub.a ${STUBS_BUILD}/libcurl_stub.a" \ -DCMAKE_PREFIX_PATH="${SYSROOT};${WX_BUILD}" \ -DwxWidgets_CONFIG_EXECUTABLE="${WX_BUILD}/wx-config" \ \ diff --git a/scripts/update-baseline-screenshots.sh b/scripts/update-baseline-screenshots.sh index e3d2de6..ddc290e 100755 --- a/scripts/update-baseline-screenshots.sh +++ b/scripts/update-baseline-screenshots.sh @@ -1,11 +1,28 @@ #!/bin/bash # Update baseline screenshots from test results +# Only copies: +# - NEW screenshots (not in baseline) +# - Screenshots with SIGNIFICANT differences (>5% size change) when --all flag used +# +# Usage: +# ./update-baseline-screenshots.sh # Only copy NEW screenshots +# ./update-baseline-screenshots.sh --all # Copy new + significantly different SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" TESTS_DIR="$SCRIPT_DIR/../tests" SOURCE_DIR="$TESTS_DIR/test-results" DEST_DIR="$TESTS_DIR/baseline-screenshots" +COPY_ALL=0 +THRESHOLD=5 # Percent threshold for "significant" difference + +if [ "$1" = "--all" ]; then + COPY_ALL=1 + echo "Mode: Copy NEW + SIGNIFICANTLY DIFFERENT screenshots" +else + echo "Mode: Copy NEW screenshots only (use --all to include significant changes)" +fi + if [ ! -d "$SOURCE_DIR" ]; then echo "Error: test-results directory not found at $SOURCE_DIR" echo "Run 'npm test' first to generate screenshots" @@ -14,15 +31,45 @@ fi mkdir -p "$DEST_DIR" -count=$(ls -1 "$SOURCE_DIR"/*.png 2>/dev/null | wc -l) -if [ "$count" -eq 0 ]; then - echo "No screenshots found in $SOURCE_DIR" - exit 1 +new_count=0 +updated_count=0 + +for src_file in "$SOURCE_DIR"/*.png; do + [ -f "$src_file" ] || continue + + filename=$(basename "$src_file") + dest_file="$DEST_DIR/$filename" + + if [ ! -f "$dest_file" ]; then + # NEW: Screenshot doesn't exist in baseline + echo "NEW: $filename" + cp "$src_file" "$dest_file" + ((new_count++)) + elif [ $COPY_ALL -eq 1 ]; then + # Check if significantly different + src_size=$(stat -f%z "$src_file" 2>/dev/null || stat -c%s "$src_file") + dest_size=$(stat -f%z "$dest_file" 2>/dev/null || stat -c%s "$dest_file") + + if [ "$dest_size" -eq 0 ]; then + diff_pct=100 + else + diff=$((src_size - dest_size)) + diff=${diff#-} # Absolute value + diff_pct=$((diff * 100 / dest_size)) + fi + + if [ "$diff_pct" -ge "$THRESHOLD" ]; then + echo "UPDATED ($diff_pct% diff): $filename" + cp "$src_file" "$dest_file" + ((updated_count++)) + fi + fi +done + +echo "" +echo "=== Summary ===" +echo "New screenshots added: $new_count" +if [ $COPY_ALL -eq 1 ]; then + echo "Significantly changed: $updated_count" fi - -echo "Copying $count screenshots to baseline..." -cp "$SOURCE_DIR"/*.png "$DEST_DIR/" - -echo "Updated baseline screenshots:" -ls -1 "$DEST_DIR"/*.png | wc -l -echo "screenshots in $DEST_DIR" +echo "Total in baseline: $(ls -1 "$DEST_DIR"/*.png 2>/dev/null | wc -l | tr -d ' ')" diff --git a/tests/baseline-screenshots/bitmapbuttons-01-loaded.png b/tests/baseline-screenshots/bitmapbuttons-01-loaded.png new file mode 100644 index 0000000..26878eb Binary files /dev/null and b/tests/baseline-screenshots/bitmapbuttons-01-loaded.png differ diff --git a/tests/baseline-screenshots/bitmapbuttons-02-toolbar-click.png b/tests/baseline-screenshots/bitmapbuttons-02-toolbar-click.png new file mode 100644 index 0000000..26878eb Binary files /dev/null and b/tests/baseline-screenshots/bitmapbuttons-02-toolbar-click.png differ diff --git a/tests/baseline-screenshots/bitmapbuttons-03-toggle.png b/tests/baseline-screenshots/bitmapbuttons-03-toggle.png new file mode 100644 index 0000000..26878eb Binary files /dev/null and b/tests/baseline-screenshots/bitmapbuttons-03-toggle.png differ diff --git a/tests/baseline-screenshots/bitmapbuttons-04-multi-toggle.png b/tests/baseline-screenshots/bitmapbuttons-04-multi-toggle.png new file mode 100644 index 0000000..26878eb Binary files /dev/null and b/tests/baseline-screenshots/bitmapbuttons-04-multi-toggle.png differ diff --git a/tests/baseline-screenshots/bitmapbuttons-05-enable-toggle.png b/tests/baseline-screenshots/bitmapbuttons-05-enable-toggle.png new file mode 100644 index 0000000..26878eb Binary files /dev/null and b/tests/baseline-screenshots/bitmapbuttons-05-enable-toggle.png differ diff --git a/tests/baseline-screenshots/bitmapbuttons-06-shapes.png b/tests/baseline-screenshots/bitmapbuttons-06-shapes.png new file mode 100644 index 0000000..26878eb Binary files /dev/null and b/tests/baseline-screenshots/bitmapbuttons-06-shapes.png differ diff --git a/tests/baseline-screenshots/bitmapbuttons-07-artprovider.png b/tests/baseline-screenshots/bitmapbuttons-07-artprovider.png new file mode 100644 index 0000000..26878eb Binary files /dev/null and b/tests/baseline-screenshots/bitmapbuttons-07-artprovider.png differ diff --git a/tests/baseline-screenshots/dnd-01-loaded.png b/tests/baseline-screenshots/dnd-01-loaded.png new file mode 100644 index 0000000..e1c77a8 Binary files /dev/null and b/tests/baseline-screenshots/dnd-01-loaded.png differ diff --git a/tests/baseline-screenshots/dnd-02-handlers.png b/tests/baseline-screenshots/dnd-02-handlers.png new file mode 100644 index 0000000..e1c77a8 Binary files /dev/null and b/tests/baseline-screenshots/dnd-02-handlers.png differ diff --git a/tests/baseline-screenshots/dnd-03-dragenter.png b/tests/baseline-screenshots/dnd-03-dragenter.png new file mode 100644 index 0000000..e1c77a8 Binary files /dev/null and b/tests/baseline-screenshots/dnd-03-dragenter.png differ diff --git a/tests/baseline-screenshots/dnd-04-dragleave.png b/tests/baseline-screenshots/dnd-04-dragleave.png new file mode 100644 index 0000000..e1c77a8 Binary files /dev/null and b/tests/baseline-screenshots/dnd-04-dragleave.png differ diff --git a/tests/baseline-screenshots/dnd-05-drop.png b/tests/baseline-screenshots/dnd-05-drop.png new file mode 100644 index 0000000..e1c77a8 Binary files /dev/null and b/tests/baseline-screenshots/dnd-05-drop.png differ diff --git a/tests/baseline-screenshots/dnd-06-file-written.png b/tests/baseline-screenshots/dnd-06-file-written.png new file mode 100644 index 0000000..e1c77a8 Binary files /dev/null and b/tests/baseline-screenshots/dnd-06-file-written.png differ diff --git a/tests/baseline-screenshots/dnd-07-event-fired.png b/tests/baseline-screenshots/dnd-07-event-fired.png new file mode 100644 index 0000000..e1c77a8 Binary files /dev/null and b/tests/baseline-screenshots/dnd-07-event-fired.png differ diff --git a/tests/baseline-screenshots/dnd-08-multiple-files.png b/tests/baseline-screenshots/dnd-08-multiple-files.png new file mode 100644 index 0000000..e1c77a8 Binary files /dev/null and b/tests/baseline-screenshots/dnd-08-multiple-files.png differ diff --git a/tests/baseline-screenshots/dnd-09-with-file.png b/tests/baseline-screenshots/dnd-09-with-file.png new file mode 100644 index 0000000..e1c77a8 Binary files /dev/null and b/tests/baseline-screenshots/dnd-09-with-file.png differ diff --git a/tests/baseline-screenshots/gridrenderers-01-loaded.png b/tests/baseline-screenshots/gridrenderers-01-loaded.png new file mode 100644 index 0000000..fecf134 Binary files /dev/null and b/tests/baseline-screenshots/gridrenderers-01-loaded.png differ diff --git a/tests/baseline-screenshots/gridrenderers-02-color-cells.png b/tests/baseline-screenshots/gridrenderers-02-color-cells.png new file mode 100644 index 0000000..fecf134 Binary files /dev/null and b/tests/baseline-screenshots/gridrenderers-02-color-cells.png differ diff --git a/tests/baseline-screenshots/gridrenderers-03-icon-text.png b/tests/baseline-screenshots/gridrenderers-03-icon-text.png new file mode 100644 index 0000000..ce94849 Binary files /dev/null and b/tests/baseline-screenshots/gridrenderers-03-icon-text.png differ diff --git a/tests/baseline-screenshots/gridrenderers-04-striped.png b/tests/baseline-screenshots/gridrenderers-04-striped.png new file mode 100644 index 0000000..ce94849 Binary files /dev/null and b/tests/baseline-screenshots/gridrenderers-04-striped.png differ diff --git a/tests/baseline-screenshots/gridrenderers-05-checkbox-toggle.png b/tests/baseline-screenshots/gridrenderers-05-checkbox-toggle.png new file mode 100644 index 0000000..e3d0e10 Binary files /dev/null and b/tests/baseline-screenshots/gridrenderers-05-checkbox-toggle.png differ diff --git a/tests/baseline-screenshots/kicad-pcbnew-01-initial.png b/tests/baseline-screenshots/kicad-pcbnew-01-initial.png new file mode 100644 index 0000000..e8c6ee2 Binary files /dev/null and b/tests/baseline-screenshots/kicad-pcbnew-01-initial.png differ diff --git a/tests/baseline-screenshots/printpreview-01-loaded.png b/tests/baseline-screenshots/printpreview-01-loaded.png new file mode 100644 index 0000000..9c65d18 Binary files /dev/null and b/tests/baseline-screenshots/printpreview-01-loaded.png differ diff --git a/tests/baseline-screenshots/printpreview-02-preview-area.png b/tests/baseline-screenshots/printpreview-02-preview-area.png new file mode 100644 index 0000000..9c65d18 Binary files /dev/null and b/tests/baseline-screenshots/printpreview-02-preview-area.png differ diff --git a/tests/baseline-screenshots/printpreview-03-preview-frame.png b/tests/baseline-screenshots/printpreview-03-preview-frame.png new file mode 100644 index 0000000..6657b48 Binary files /dev/null and b/tests/baseline-screenshots/printpreview-03-preview-frame.png differ diff --git a/tests/baseline-screenshots/printpreview-04-page-setup.png b/tests/baseline-screenshots/printpreview-04-page-setup.png new file mode 100644 index 0000000..25f39c9 Binary files /dev/null and b/tests/baseline-screenshots/printpreview-04-page-setup.png differ diff --git a/tests/baseline-screenshots/printpreview-05-settings.png b/tests/baseline-screenshots/printpreview-05-settings.png new file mode 100644 index 0000000..9c65d18 Binary files /dev/null and b/tests/baseline-screenshots/printpreview-05-settings.png differ diff --git a/tests/baseline-screenshots/specialized-01-loaded.png b/tests/baseline-screenshots/specialized-01-loaded.png new file mode 100644 index 0000000..bee65d8 Binary files /dev/null and b/tests/baseline-screenshots/specialized-01-loaded.png differ diff --git a/tests/baseline-screenshots/specialized-02-treebook-initial.png b/tests/baseline-screenshots/specialized-02-treebook-initial.png new file mode 100644 index 0000000..bee65d8 Binary files /dev/null and b/tests/baseline-screenshots/specialized-02-treebook-initial.png differ diff --git a/tests/baseline-screenshots/specialized-03-treebook-subpage.png b/tests/baseline-screenshots/specialized-03-treebook-subpage.png new file mode 100644 index 0000000..bee65d8 Binary files /dev/null and b/tests/baseline-screenshots/specialized-03-treebook-subpage.png differ diff --git a/tests/baseline-screenshots/specialized-04-treebook-expand.png b/tests/baseline-screenshots/specialized-04-treebook-expand.png new file mode 100644 index 0000000..bee65d8 Binary files /dev/null and b/tests/baseline-screenshots/specialized-04-treebook-expand.png differ diff --git a/tests/baseline-screenshots/specialized-05-bitmapcombo-dropdown.png b/tests/baseline-screenshots/specialized-05-bitmapcombo-dropdown.png new file mode 100644 index 0000000..bf97ddd Binary files /dev/null and b/tests/baseline-screenshots/specialized-05-bitmapcombo-dropdown.png differ diff --git a/tests/baseline-screenshots/specialized-06-bitmapcombo-select.png b/tests/baseline-screenshots/specialized-06-bitmapcombo-select.png new file mode 100644 index 0000000..bf97ddd Binary files /dev/null and b/tests/baseline-screenshots/specialized-06-bitmapcombo-select.png differ diff --git a/tests/baseline-screenshots/specialized-07-rearrange-list.png b/tests/baseline-screenshots/specialized-07-rearrange-list.png new file mode 100644 index 0000000..bee65d8 Binary files /dev/null and b/tests/baseline-screenshots/specialized-07-rearrange-list.png differ diff --git a/tests/baseline-screenshots/specialized-08-get-order.png b/tests/baseline-screenshots/specialized-08-get-order.png new file mode 100644 index 0000000..bf97ddd Binary files /dev/null and b/tests/baseline-screenshots/specialized-08-get-order.png differ diff --git a/tests/baseline-screenshots/wxgrid-controls.png b/tests/baseline-screenshots/wxgrid-controls.png index d909e5a..3421f48 100644 Binary files a/tests/baseline-screenshots/wxgrid-controls.png and b/tests/baseline-screenshots/wxgrid-controls.png differ diff --git a/tests/baseline-screenshots/wxgrid-dedicated-page.png b/tests/baseline-screenshots/wxgrid-dedicated-page.png index d909e5a..3421f48 100644 Binary files a/tests/baseline-screenshots/wxgrid-dedicated-page.png and b/tests/baseline-screenshots/wxgrid-dedicated-page.png differ diff --git a/wasm/stubs/wasm-opt-stub.sh b/wasm/stubs/wasm-opt-stub.sh new file mode 100755 index 0000000..0d4a1c5 --- /dev/null +++ b/wasm/stubs/wasm-opt-stub.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# Stub wasm-opt that does nothing +# This allows Emscripten to generate Asyncify JS runtime without running the actual transformation +# The real wasm-opt --asyncify is run on the host where more RAM is available + +# Handle --version query from Emscripten +if [[ "$1" == "--version" ]]; then + echo "wasm-opt version 121 (version_121)" + exit 0 +fi + +# Find the output file argument (-o) +OUTPUT="" +INPUT="" +PREV_ARG="" + +for arg in "$@"; do + if [ "$PREV_ARG" = "-o" ]; then + OUTPUT="$arg" + elif [[ "$arg" != -* ]] && [ -f "$arg" ]; then + INPUT="$arg" + fi + PREV_ARG="$arg" +done + +# If we have both input and output, copy input to output +if [ -n "$INPUT" ] && [ -n "$OUTPUT" ] && [ "$INPUT" != "$OUTPUT" ]; then + cp "$INPUT" "$OUTPUT" +fi + +# Exit successfully so Emscripten thinks wasm-opt ran +exit 0 diff --git a/wxwidgets b/wxwidgets index 40bf50f..08794a9 160000 --- a/wxwidgets +++ b/wxwidgets @@ -1 +1 @@ -Subproject commit 40bf50fe4ee6938894464e6039acacb38d55a227 +Subproject commit 08794a9f579d5fcdc08085e18f25f108446f46f0