From d6e946b101a872d1aaea0fedd8393ddaee091277 Mon Sep 17 00:00:00 2001 From: Viktor Vaczi Date: Thu, 27 Nov 2025 08:32:40 +0100 Subject: [PATCH 1/2] Add wxWidgets 3.2.6 submodule and wxBase WASM build script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add wxWidgets v3.2.6 as git submodule for wxBase utilities - Create build-wxbase-wasm.sh script to compile wxBase for Emscripten - Disable WASM-incompatible features: zlib, expat, xlocale, fswatcher - Successfully builds libwx_baseu-3.2-Emscripten.a (3.1MB) This provides wxString, wxFile, wxDateTime and other base utilities needed for the KiCad board data model without GUI dependencies. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .gitmodules | 3 ++ scripts/build-wxbase-wasm.sh | 67 ++++++++++++++++++++++++++++++++++++ wxwidgets | 1 + 3 files changed, 71 insertions(+) create mode 100755 scripts/build-wxbase-wasm.sh create mode 160000 wxwidgets diff --git a/.gitmodules b/.gitmodules index 55e859a..7e8d09f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "kicad"] path = kicad url = git@github.com:VV-EE/kicad-source-mirror.git +[submodule "wxwidgets"] + path = wxwidgets + url = https://github.com/wxWidgets/wxWidgets.git diff --git a/scripts/build-wxbase-wasm.sh b/scripts/build-wxbase-wasm.sh new file mode 100755 index 0000000..f74293f --- /dev/null +++ b/scripts/build-wxbase-wasm.sh @@ -0,0 +1,67 @@ +#!/bin/bash +# Build wxBase (non-GUI wxWidgets) for WebAssembly +# This builds only the base utilities needed by KiCad core (wxString, wxFile, etc.) + +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" +BUILD_DIR="$PROJECT_ROOT/build-wasm/wxwidgets" +WX_SOURCE="$PROJECT_ROOT/wxwidgets" + +echo "=== Building wxBase 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/CMakeLists.txt" ]; then + echo "ERROR: wxWidgets source not found at $WX_SOURCE" + echo "Make sure the wxwidgets submodule is initialized" + exit 1 +fi + +# Clean if requested (must be before mkdir to properly reset CMake cache) +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 emcmake +# Disable all GUI and most optional features - we only need wxBase utilities +# Note: zlib/expat "builtin" versions use POSIX file descriptors not available in WASM, +# so we disable them. We'll use Emscripten's ports if compression is needed. +emcmake cmake "$WX_SOURCE" \ + -DwxUSE_GUI=OFF \ + -DwxBUILD_SHARED=OFF \ + -DwxBUILD_SAMPLES=OFF \ + -DwxBUILD_TESTS=OFF \ + -DwxBUILD_DEMOS=OFF \ + -DwxBUILD_BENCHMARKS=OFF \ + -DwxUSE_REGEX=OFF \ + -DwxUSE_ZLIB=OFF \ + -DwxUSE_EXPAT=OFF \ + -DwxUSE_LIBJPEG=OFF \ + -DwxUSE_LIBPNG=OFF \ + -DwxUSE_LIBTIFF=OFF \ + -DwxUSE_WEBREQUEST=OFF \ + -DwxUSE_SECRETSTORE=OFF \ + -DwxUSE_LIBSDL=OFF \ + -DwxUSE_LIBMSPACK=OFF \ + -DwxUSE_FSWATCHER=OFF \ + -DwxUSE_XLOCALE=OFF \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_POLICY_VERSION_MINIMUM=3.5 + +# 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" \ No newline at end of file diff --git a/wxwidgets b/wxwidgets new file mode 160000 index 0000000..5ff2532 --- /dev/null +++ b/wxwidgets @@ -0,0 +1 @@ +Subproject commit 5ff25322553c1870cf20a2e1ba6f20ed50d9fe9a -- 2.50.1 (Apple Git-155) From 9305aa5afbbc9a3085c4e73e5469fa7e64616418 Mon Sep 17 00:00:00 2001 From: Viktor Vaczi Date: Thu, 27 Nov 2025 08:39:22 +0100 Subject: [PATCH 2/2] Update core library to use real wxBase instead of wx_shim MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update CMakeLists.txt to link against wxBase WASM build - Move config.h to wasm-config/ to avoid conflicts with wx headers - Add build-core-wasm.sh script for reproducible builds - Core now compiles with actual wxString, wxFile, etc. from wxWidgets Libraries built: - libkicad_core_utils.a (34K) - libkimath.a (969K) - libsexpr.a (45K) - libclipper2.a (169K) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- core/CMakeLists.txt | 42 +++++++++++++++++--- core/{include => wasm-config}/config.h | 2 +- scripts/build-core-wasm.sh | 53 ++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 6 deletions(-) rename core/{include => wasm-config}/config.h (88%) create mode 100755 scripts/build-core-wasm.sh diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 3b53175..5556c7e 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -14,6 +14,32 @@ endif() message(STATUS "Using KiCad source at: ${KICAD_SOURCE}") +# ============================================================================= +# wxWidgets Base (pre-built for WASM) +# ============================================================================= +set(WXWIDGETS_SOURCE "${CMAKE_SOURCE_DIR}/../wxwidgets" CACHE PATH "Path to wxWidgets source") +set(WXWIDGETS_BUILD "${CMAKE_SOURCE_DIR}/../build-wasm/wxwidgets" CACHE PATH "Path to wxWidgets WASM build") + +# Verify wxWidgets build exists +if(NOT EXISTS "${WXWIDGETS_BUILD}/lib/libwx_baseu-3.2-Emscripten.a") + message(FATAL_ERROR "wxBase WASM build not found. Run scripts/build-wxbase-wasm.sh first") +endif() + +# Create imported wxBase library +add_library(wxbase STATIC IMPORTED) +set_target_properties(wxbase PROPERTIES + IMPORTED_LOCATION "${WXWIDGETS_BUILD}/lib/libwx_baseu-3.2-Emscripten.a" +) + +# wxWidgets include directories +set(WX_INCLUDE_DIRS + "${WXWIDGETS_BUILD}/lib/wx/include/base-unicode-static-3.2" # Platform setup.h + "${WXWIDGETS_SOURCE}/include" # Main wx headers +) + +message(STATUS "Using wxWidgets source at: ${WXWIDGETS_SOURCE}") +message(STATUS "Using wxWidgets build at: ${WXWIDGETS_BUILD}") + # ============================================================================= # Options # ============================================================================= @@ -45,20 +71,24 @@ target_include_directories(rtree INTERFACE ) # ============================================================================= -# Core utilities library (minimal version without wx_stl_compat) +# Core utilities library (with wxBase support) # ============================================================================= add_library(kicad_core_utils STATIC ${KICAD_SOURCE}/libs/core/base64.cpp ${KICAD_SOURCE}/libs/core/observable.cpp ${KICAD_SOURCE}/libs/core/profile.cpp - # Skip utf8.cpp and wx_stl_compat.cpp - they have heavy wx dependencies + ${KICAD_SOURCE}/libs/core/utf8.cpp + ${KICAD_SOURCE}/libs/core/wx_stl_compat.cpp ) target_include_directories(kicad_core_utils PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/wasm-config # config.h for WASM build + ${WX_INCLUDE_DIRS} ${KICAD_SOURCE}/libs/core/include - ${CMAKE_CURRENT_SOURCE_DIR}/include # For wx_shim.h ) +target_link_libraries(kicad_core_utils PUBLIC wxbase) + # ============================================================================= # S-expression library (parser for .kicad_pcb files) # ============================================================================= @@ -68,9 +98,11 @@ add_library(sexpr STATIC ) target_include_directories(sexpr PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/include # wx_shim.h - FIRST! + ${CMAKE_CURRENT_SOURCE_DIR}/wasm-config # config.h for WASM build + ${WX_INCLUDE_DIRS} ${KICAD_SOURCE}/libs/sexpr/include ${KICAD_SOURCE}/libs/core/include + ${KICAD_SOURCE}/include # string_utils.h, etc. ) target_link_libraries(sexpr PUBLIC kicad_core_utils) @@ -121,7 +153,7 @@ set(KIMATH_SRCS add_library(kimath STATIC ${KIMATH_SRCS}) target_include_directories(kimath PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/include # wx_shim.h and wx/ stubs - FIRST! + ${WX_INCLUDE_DIRS} ${KICAD_SOURCE}/libs/kimath/include ${KICAD_SOURCE}/libs/core/include ${KICAD_SOURCE}/include # Main KiCad includes (units, etc.) diff --git a/core/include/config.h b/core/wasm-config/config.h similarity index 88% rename from core/include/config.h rename to core/wasm-config/config.h index d40b4e1..fdcec80 100644 --- a/core/include/config.h +++ b/core/wasm-config/config.h @@ -10,7 +10,7 @@ // Platform detection for timing functions #if defined(_WIN32) // Windows uses GetSystemTimeAsFileTime -#elif defined(__APPLE__) || defined(__linux__) || defined(__unix__) +#elif defined(__EMSCRIPTEN__) || defined(__APPLE__) || defined(__linux__) || defined(__unix__) #define HAVE_CLOCK_GETTIME 1 #else #define HAVE_GETTIMEOFDAY_FUNC 1 diff --git a/scripts/build-core-wasm.sh b/scripts/build-core-wasm.sh new file mode 100755 index 0000000..8155ad4 --- /dev/null +++ b/scripts/build-core-wasm.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# Build KiCad core library for WebAssembly +# This builds kimath, sexpr, and core utilities with wxBase + +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" +BUILD_DIR="$PROJECT_ROOT/build-wasm/core" +CORE_SOURCE="$PROJECT_ROOT/core" + +echo "=== Building KiCad Core for WASM ===" +echo "Project root: $PROJECT_ROOT" +echo "Build dir: $BUILD_DIR" +echo "Core source: $CORE_SOURCE" + +# Verify core source exists +if [ ! -f "$CORE_SOURCE/CMakeLists.txt" ]; then + echo "ERROR: Core source not found at $CORE_SOURCE" + exit 1 +fi + +# Verify wxBase was built +if [ ! -f "$PROJECT_ROOT/build-wasm/wxwidgets/lib/libwx_baseu-3.2-Emscripten.a" ]; then + echo "ERROR: wxBase not built. Run scripts/build-wxbase-wasm.sh first" + exit 1 +fi + +# Clean if requested (must be before mkdir to properly reset CMake cache) +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 emcmake +echo "" +echo "=== Configuring ===" +emcmake cmake "$CORE_SOURCE" \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_TESTS=OFF + +# Build +echo "" +echo "=== Building ===" +emmake make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu) + +echo "" +echo "=== Build complete ===" +ls -lh "$BUILD_DIR"/*.a 2>/dev/null || echo "Libraries built in $BUILD_DIR" -- 2.50.1 (Apple Git-155)