Skip to content

Commit 6d3612b

Browse files
committed
WASM build updates
1 parent 3592e3f commit 6d3612b

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

cmake/CMakeLists.txt

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,25 @@ foreach(option_flag IN LISTS option_flags)
196196
convert_env_var_to_bool("${option_flag}")
197197
endforeach()
198198

199+
set(CMAKE_FIND_ROOT_PATH_BACKUP "${CMAKE_FIND_ROOT_PATH}")
200+
201+
macro(clear_wasm_sysroot)
199202
if(WASM_BUILD)
200203
# when using the nix/build-all.py build script we should not
201204
# look into the sysroot for most of the dependencies but rather
202205
# in the designated build/ folder created by the script.
203-
set(CMAKE_FIND_ROOT_PATH_BACKUP "${CMAKE_FIND_ROOT_PATH}")
204206
set(CMAKE_FIND_ROOT_PATH "")
205207
endif()
208+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
209+
endmacro()
210+
211+
macro(restore_wasm_sysroot)
212+
if(WASM_BUILD)
213+
# reset to use sysroot
214+
set(CMAKE_FIND_ROOT_PATH "${CMAKE_FIND_ROOT_PATH_BACKUP}")
215+
endif()
216+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
217+
endmacro()
206218

207219
if(WITH_CGAL)
208220
add_definitions(-DIFOPSH_WITH_CGAL)
@@ -223,7 +235,9 @@ endif()
223235

224236
if(GLTF_SUPPORT OR CITYJSON_SUPPORT)
225237
UNIFY_ENVVARS_AND_CACHE(JSON_INCLUDE_DIR)
238+
clear_wasm_sysroot()
226239
find_path(json_header_path "nlohmann/json.hpp" HINTS ${JSON_INCLUDE_DIR})
240+
restore_wasm_sysroot()
227241
set(JSON_INCLUDE_DIR ${json_header_path})
228242

229243
if(json_header_path)
@@ -330,13 +344,17 @@ if(USE_MMAP)
330344
add_definitions(-DUSE_MMAP)
331345
endif()
332346

347+
clear_wasm_sysroot()
333348
find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS})
349+
restore_wasm_sysroot()
334350
message(STATUS "Boost include files found in ${Boost_INCLUDE_DIRS}")
335351
message(STATUS "Boost libraries found in ${Boost_LIBRARY_DIRS}")
336352

337353
if(NOT MINIMAL_BUILD)
338354
# libxml2 is required for IFCXML (optional) and SVGFILL (mandatory)
355+
clear_wasm_sysroot()
339356
find_package(LibXml2 REQUIRED)
357+
restore_wasm_sysroot()
340358
endif()
341359

342360
if(IFCXML_SUPPORT)
@@ -352,13 +370,15 @@ if(BUILD_IFCGEOM)
352370
# Open CASCADE
353371
if(WITH_OPENCASCADE)
354372
if("${OCC_INCLUDE_DIR}" STREQUAL "")
373+
clear_wasm_sysroot()
355374
find_path(OCC_INCLUDE_DIR Standard_Version.hxx
356375
PATHS
357376
/usr/include/occt
358377
/usr/include/oce
359378
/usr/include/opencascade
360379
REQUIRED
361380
)
381+
restore_wasm_sysroot()
362382

363383
if(OCC_INCLUDE_DIR)
364384
message(STATUS "Found Open CASCADE include files in: ${OCC_INCLUDE_DIR}")
@@ -418,7 +438,9 @@ if(BUILD_IFCGEOM)
418438
message(STATUS "Looking for Open CASCADE library files in: ${OCC_LIBRARY_DIR}")
419439
endif()
420440

441+
clear_wasm_sysroot()
421442
find_library(libTKernel NAMES TKernel TKerneld PATHS ${OCC_LIBRARY_DIR} NO_DEFAULT_PATH)
443+
restore_wasm_sysroot()
422444

423445
if(libTKernel)
424446
message(STATUS "Required Open Cascade Library files found")
@@ -641,11 +663,6 @@ if(HDF5_SUPPORT)
641663
set(SWIG_DEFINES ${SWIG_DEFINES} -DWITH_HDF5)
642664
endif(HDF5_SUPPORT)
643665

644-
if(WASM_BUILD)
645-
# reset to use sysroot
646-
set(CMAKE_FIND_ROOT_PATH "${CMAKE_FIND_ROOT_PATH_BACKUP}")
647-
endif()
648-
649666
if(ENABLE_BUILD_OPTIMIZATIONS)
650667
if(MSVC)
651668
# NOTE: RelWithDebInfo and Release use O2 (= /Ox /Gl /Gy/ = Og /Oi /Ot /Oy /Ob2 /Gs /GF /Gy) by default,
@@ -925,8 +942,10 @@ endif()
925942

926943
if(BUILD_IFCGEOM)
927944
if(WITH_CGAL)
945+
clear_wasm_sysroot()
928946
find_library(libGMP NAMES gmp mpir PATHS ${GMP_LIBRARY_DIR} NO_DEFAULT_PATH)
929947
find_library(libMPFR NAMES mpfr PATHS ${MPFR_LIBRARY_DIR} NO_DEFAULT_PATH)
948+
restore_wasm_sysroot()
930949
if(NOT libGMP)
931950
message(FATAL_ERROR "Unable to find GMP library files, aborting")
932951
endif()

nix/build-all.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ def build_dependency(name, mode, build_tool_args, download_url, download_name, d
479479
ADDITIONAL_ARGS = [f"-mmacosx-version-min={TOOLSET}"] + ADDITIONAL_ARGS
480480

481481
if "wasm" in flags:
482-
ADDITIONAL_ARGS.extend(("-sWASM_BIGINT", "-fexceptions"))
482+
ADDITIONAL_ARGS.extend(("-sWASM_BIGINT", "-fwasm-exceptions"))
483483

484484
# If the linker supports GC sections, set it up to reduce binary file size
485485
# -fPIC is required for the shared libraries to work
@@ -990,7 +990,11 @@ def compile_python_wrapper(python_version, python_library, python_include, pytho
990990
if platform.system() != "Darwin":
991991
if BUILD_CFG == "Release":
992992
# TODO: This symbol name depends on the Python version?
993-
run([strip, "-s", "-K", "PyInit__ifcopenshell_wrapper", glob.glob(os.path.join(module_dir, "_ifcopenshell_wrapper*.so"))[0]], cwd=module_dir)
993+
so = glob.glob(os.path.join(module_dir, "_ifcopenshell_wrapper*.so"))[0]
994+
if "wasm" in flags:
995+
run(['wasm-strip', so, '-k', "dylink.0"])
996+
else:
997+
run([strip, "-s", "-K", "PyInit__ifcopenshell_wrapper", so], cwd=module_dir)
994998

995999
return module_dir
9961000

pyodide/meta.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package:
33
version: 0.8.0
44

55
source:
6-
path: IfcOpenShell
6+
path: ../../IfcOpenShell
77

88
build:
99
script: |
10-
python nix/build-all.py --without-hdf5 --without-opencollada --without-swig --without-pcre -v --wasm --py310 IfcOpenShell-Python
10+
BUILD_CFG=Release python nix/build-all.py --without-hdf5 --without-opencollada --without-swig --without-pcre -v --wasm --py312 IfcOpenShell-Python
11+
mv package/ifcopenshell .
1112
cp pyodide/setup.py .
13+
mv dist/IfcOpenShell-0.8.0-py3-none-any.whl dist/ifcopenshell-python-v0.8.0-${GITHUB_SHA:0:7}-cp312-cp312-emscripten_3_1_58_wasm32.whl
1214
1315
about:
1416
home: http://ifcopenshell.org

src/ifcwrap/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,16 @@ endif()
8383
# directory in which the wrapper can be installed.
8484
FIND_PACKAGE(PythonInterp)
8585
IF((PYTHONINTERP_FOUND AND NOT "${PYTHON_EXECUTABLE}" STREQUAL "") OR PYTHON_MODULE_INSTALL_DIR)
86+
if (NOT WASM_BUILD)
8687
# Find Python interpreter and get its version
88+
# Not on WASM because we're cross compiling in that case
8789
EXECUTE_PROCESS(
8890
COMMAND ${PYTHON_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"
8991
OUTPUT_VARIABLE PYTHON_EXTENSION_SUFFIX
9092
OUTPUT_STRIP_TRAILING_WHITESPACE
9193
)
9294
SET_TARGET_PROPERTIES(${SWIG_MODULE_ifcopenshell_wrapper_REAL_NAME} PROPERTIES SUFFIX ${PYTHON_EXTENSION_SUFFIX})
95+
endif()
9396
if (PYTHON_MODULE_INSTALL_DIR)
9497
set(python_package_dir "${PYTHON_MODULE_INSTALL_DIR}")
9598
else()

0 commit comments

Comments
 (0)