From 7ca44b567740e73058f232a11bc37f5b887b252e Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 17 Oct 2025 19:01:37 +0500 Subject: [PATCH] build-all.py wasm - move SIDE_MODULE=2 to cmake Next to `EXPORTED_FUNCTIONS` and avoid possible issues with pyodide in the future (pyodide is using `SIDE_MODULE=1`, but currently not providing it libraries of type `MODULE`, only for shared ones). --- nix/build-all.py | 2 +- src/ifcwrap/CMakeLists.txt | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/nix/build-all.py b/nix/build-all.py index 7b837cb399..1fbfab9349 100644 --- a/nix/build-all.py +++ b/nix/build-all.py @@ -1436,7 +1436,7 @@ if "IfcOpenShell-Python" in targets: ADDITIONAL_ARGS = "-Wl,-flat_namespace,-undefined,suppress" if "wasm" in flags: - ADDITIONAL_ARGS = "-Wl,-undefined,suppress -sSIDE_MODULE=2" + ADDITIONAL_ARGS = "-Wl,-undefined,suppress" # Override CMAKE_TOOLCHAIN_FILE because by default emscripten doesn't support building shared binaries. if WASM_DEBUG: os.environ["CMAKE_TOOLCHAIN_FILE"] = os.environ["WASM_TOOLCHAIN_FILE"] diff --git a/src/ifcwrap/CMakeLists.txt b/src/ifcwrap/CMakeLists.txt index 8e72463d66..156c731c67 100644 --- a/src/ifcwrap/CMakeLists.txt +++ b/src/ifcwrap/CMakeLists.txt @@ -92,7 +92,15 @@ set(SWIG_MODULE_ifcopenshell_wrapper_EXTRA_FLAGS "-interface" "_ifcopenshell_wra swig_add_library(ifcopenshell_wrapper LANGUAGE python SOURCES IfcPython.i) SET_PROPERTY(TARGET ${SWIG_MODULE_ifcopenshell_wrapper_REAL_NAME} PROPERTY SWIG_DEPENDS ${IFCOPENSHELL_LIBRARIES}) if (WASM_BUILD) - target_link_options(${SWIG_MODULE_ifcopenshell_wrapper_REAL_NAME} PRIVATE "-sEXPORTED_FUNCTIONS=_PyInit__ifcopenshell_wrapper") + # SIDE_MODULE=1 - add to .so all symbols from linked archives (default used by pyodide). + # Since currently libIfcGeom.a seems to be linked twice it results in duplicated symbols and compilation errors. + # Possibly in the future we can clean up linked libs and try `=1`. + # SIDE_MODULE=2 - add to .so only explicitly exported functions (`-s EXPORTED_FUNCTIONS). + # Have to provide it here to override possible `=1` coming from pyodide. + target_link_options( + ${SWIG_MODULE_ifcopenshell_wrapper_REAL_NAME} + PRIVATE "SHELL:-s EXPORTED_FUNCTIONS=_PyInit__ifcopenshell_wrapper -s SIDE_MODULE=2" + ) endif() if("$ENV{LDFLAGS}" MATCHES ".undefined.suppress") # On osx there is some state in the python dylib. With `-Wl,undefined,suppress` we can ignore the missing symbols at compile time.