#!/usr/bin/env bash set -euo pipefail # Rebuild the TechDraw Web dependency closure with Emscripten atomics metadata. # The regular Web dependency set intentionally remains single-memory; this # opt-in closure is selected automatically when all *-pthread-install prefixes # exist and FREECAD_WEB_ENABLE_TECHDRAW_NATIVE is enabled. source_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) workspace_dir=$(cd "$source_dir/.." && pwd) base_lib_dir=${FREECAD_WEB_BASE_LIB_DIR:-"$workspace_dir/FreeCADBaseLib"} build_root=${FREECAD_WEB_BUILD_ROOT:-"$source_dir/build-web"} jobs=${FREECAD_WEB_JOBS:-8} cache=${EM_CACHE:-"$build_root/emscripten-cache"} python_source="$base_lib_dir/sources/src/Python-3.12.3" yaml_source="$base_lib_dir/sources/src/YAML-CPP-0.8.0" boost_source="$base_lib_dir/sources/src/Boost-1.83.0" occt_source="$base_lib_dir/sources/src/OpenCASCADE-7.6.3" toolchain=${FREECAD_WEB_EMSCRIPTEN_TOOLCHAIN:-} if [[ -z "$toolchain" ]]; then emcc_path=$(realpath "$(command -v emcc)") toolchain="$(dirname "$emcc_path")/cmake/Modules/Platform/Emscripten.cmake" fi emscripten_config=${EM_CONFIG:-"$build_root/emscripten-config.py"} if [[ ! -f "$emscripten_config" ]]; then printf 'Missing Emscripten config: %s\n' "$emscripten_config" >&2 exit 1 fi export EM_CONFIG="$emscripten_config" export EM_CACHE="$cache" export EM_FROZEN_CACHE= mkdir -p "$build_root" "$cache" "$build_root/occt-pthread-install" \ "$build_root/python-pthread-install" "$build_root/yaml-pthread-install" \ "$build_root/icu-pthread-install" "$build_root/boost-pthread-install" occt_build="$build_root/occt-pthread" cmake -S "$occt_source" -B "$occt_build" -G Ninja \ -DCMAKE_TOOLCHAIN_FILE="$toolchain" -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX="$build_root/occt-pthread-install" \ -DCMAKE_C_FLAGS=-pthread -DCMAKE_CXX_FLAGS=-pthread \ -DCMAKE_EXE_LINKER_FLAGS='-pthread -sUSE_PTHREADS=1 -sPTHREAD_POOL_SIZE=4' \ -DCMAKE_SHARED_LINKER_FLAGS='-pthread -sUSE_PTHREADS=1 -sPTHREAD_POOL_SIZE=4' \ -DBUILD_LIBRARY_TYPE=Static -DBUILD_USE_PCH=OFF \ -DBUILD_RELEASE_DISABLE_EXCEPTIONS=ON -DUSE_FREETYPE=OFF \ -DUSE_FREEIMAGE=OFF -DUSE_TBB=OFF -DUSE_FFMPEG=OFF -DUSE_OPENGL=OFF \ -DBUILD_MODULE_ApplicationFramework=OFF -DBUILD_MODULE_DataExchange=ON \ -DBUILD_MODULE_Draw=OFF -DBUILD_MODULE_FoundationClasses=ON \ -DBUILD_MODULE_ModelingAlgorithms=ON -DBUILD_MODULE_ModelingData=ON \ -DBUILD_MODULE_Visualization=OFF -DBUILD_Inspector=OFF \ -DBUILD_RESOURCES=OFF -DBUILD_SAMPLES_QT=OFF -DBUILD_YACCLEX=OFF \ -DBUILD_DOC_Overview=OFF -DBUILD_ENABLE_FPE_SIGNAL_HANDLER=OFF cmake --build "$occt_build" --target all -j"$jobs" cmake --install "$occt_build" python_build="$build_root/python-pthread" if [[ ! -f "$python_build/Makefile" ]]; then mkdir -p "$python_build" ( cd "$python_build" && CONFIG_SITE="$python_source/Tools/wasm/config.site-wasm32-emscripten" \ EM_CONFIG="$emscripten_config" EM_CACHE="$cache" EM_FROZEN_CACHE= \ emconfigure "$python_source/configure" -C --host=wasm32-unknown-emscripten \ --build=x86_64-pc-linux-gnu --with-emscripten-target=browser \ --with-build-python=/usr/bin/python3.12 --without-ensurepip ) fi EM_CONFIG="$emscripten_config" EM_CACHE="$cache" EM_FROZEN_CACHE= \ make -C "$python_build" -j"$jobs" CFLAGS=-pthread CXXFLAGS=-pthread EM_CONFIG="$emscripten_config" EM_CACHE="$cache" EM_FROZEN_CACHE= \ make -C "$python_build" -j"$jobs" prefix="$build_root/python-pthread-install" install yaml_build="$build_root/yaml-pthread" cmake -S "$yaml_source" -B "$yaml_build" -G Ninja \ -DCMAKE_TOOLCHAIN_FILE="$toolchain" -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX="$build_root/yaml-pthread-install" \ -DYAML_BUILD_SHARED_LIBS=OFF -DYAML_CPP_BUILD_TESTS=OFF \ -DYAML_CPP_BUILD_TOOLS=OFF -DYAML_CPP_INSTALL=ON -DCMAKE_CXX_FLAGS=-pthread cmake --build "$yaml_build" --target yaml-cpp -j"$jobs" cmake --install "$yaml_build" # Seed the verified ICU 68.2 source archive before asking the Emscripten port # machinery for its -mt libraries. This avoids a network fetch during builds. icu_port="$cache/ports/icu" mkdir -p "$icu_port" if [[ ! -f "$icu_port/icu/source/common/unicode/utypes.h" ]]; then archive="$build_root/icu-download/icu4c-68_2-src.tgz" [[ -f "$archive" ]] || { printf 'Missing ICU archive: %s\n' "$archive" >&2; exit 1; } tar -xzf "$archive" -C "$icu_port" fi printf '%s\n' 'https://github.com/unicode-org/icu/releases/download/release-68-2/icu4c-68_2-src.zip' > "$icu_port/.emscripten_url" printf 'int main(){return 0;}\n' | EM_CONFIG="$emscripten_config" EM_CACHE="$cache" \ EM_PORTS="$cache/ports" EM_FROZEN_CACHE= em++ -x c++ - -sUSE_ICU=1 \ -sUSE_PTHREADS=1 -pthread -o "$build_root/icu-pthread-port-smoke.js" mkdir -p "$build_root/icu-pthread-install/include" "$build_root/icu-pthread-install/lib" cp -a "$cache/sysroot/include/unicode" "$build_root/icu-pthread-install/include/" cp "$cache/sysroot/lib/wasm32-emscripten/libicu_common-mt.a" "$build_root/icu-pthread-install/lib/libicuuc.a" cp "$cache/sysroot/lib/wasm32-emscripten/libicu_i18n-mt.a" "$build_root/icu-pthread-install/lib/libicui18n.a" cp "$cache/sysroot/lib/wasm32-emscripten/libicu_stubdata-mt.a" "$build_root/icu-pthread-install/lib/libicudata.a" cp "$cache/sysroot/lib/wasm32-emscripten/libicu_stubdata-mt.a" "$build_root/icu-pthread-install/lib/libicudt.a" boost_user_config="$build_root/boost-pthread-user-config.jam" printf 'using clang : wasm : %s ;\n' "$(command -v em++)" > "$boost_user_config" b2 -q --user-config="$boost_user_config" --build-dir="$build_root/boost-pthread-build" \ --prefix="$build_root/boost-pthread-install" --layout=system -j"$jobs" \ toolset=clang-wasm variant=release link=static runtime-link=static threading=multi \ cxxflags=-pthread linkflags='-pthread -sUSE_PTHREADS=1 -sPTHREAD_POOL_SIZE=4' \ --with-program_options --with-regex --with-thread --with-date_time --with-atomic install printf 'TechDraw pthread dependency closure ready under %s\n' "$build_root"