Skip to content

Commit 34a1bc6

Browse files
committed
WASM build changes #6794
1 parent 1511221 commit 34a1bc6

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

nix/build-all.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
OCCT_VERSION = "7.8.1"
9090
BOOST_VERSION = "1.86.0"
9191
PCRE_VERSION = "8.41"
92-
LIBXML2_VERSION = "2.9.11"
92+
LIBXML2_VERSION = "2.13.8"
9393
SWIG_VERSION = "4.0.2"
9494
OPENCOLLADA_VERSION = "v1.6.68"
9595
HDF5_VERSION = "1.12.1"
@@ -324,7 +324,7 @@ def run_autoconf(arg1, configure_args, cwd):
324324
if "wasm" in flags:
325325
wasm.append("emconfigure")
326326

327-
run([*wasm, "/bin/sh", "../configure"] + configure_args + [f"--prefix={prefix}"], cwd=cwd)
327+
run([*wasm, "/bin/sh", "../configure", *(["--host=wasm32"] if "wasm" in flags and not any(s.startswith('--host') for s in configure_args) else []), *configure_args, f"--prefix={prefix}"], cwd=cwd)
328328

329329

330330
def run_cmake(arg1, cmake_args, cmake_dir=None, cwd=None):
@@ -337,7 +337,7 @@ def run_cmake(arg1, cmake_args, cmake_dir=None, cwd=None):
337337
if "wasm" in flags:
338338
wasm.append("emcmake")
339339

340-
run([*wasm, "cmake", P, *cmake_args, f"-DCMAKE_BUILD_TYPE={BUILD_CFG}", f"-DBUILD_SHARED_LIBS={OFF_ON[not BUILD_STATIC]}"], cwd=cwd)
340+
run([*wasm, "cmake", P, *cmake_args, f"-DCMAKE_BUILD_TYPE={BUILD_CFG}", f"-DBUILD_SHARED_LIBS={OFF_ON[not BUILD_STATIC]}", f"-DCMAKE_CXX_FLAGS='{os.environ['CXXFLAGS']}'", f"-DCMAKE_C_FLAGS='{os.environ['CFLAGS']}'", f"-DCMAKE_SHARED_LINKER_FLAGS={os.environ['LDFLAGS']}"], cwd=cwd)
341341

342342

343343
def git_clone_or_pull_repository(clone_url, target_dir, revision=None):
@@ -363,7 +363,7 @@ def git_clone_or_pull_repository(clone_url, target_dir, revision=None):
363363
run([git, "checkout", revision], cwd=target_dir)
364364

365365

366-
def build_dependency(name, mode, build_tool_args, download_url, download_name, download_tool=download_tool_default, revision=None, patch=None, additional_files={}, no_append_name=False, **kwargs):
366+
def build_dependency(name, mode, build_tool_args, download_url, download_name, download_tool=download_tool_default, revision=None, patch=None, shell=None, pre_compile_subs=[], additional_files={}, no_append_name=False, **kwargs):
367367
"""Handles building of dependencies with different tools (which are
368368
distinguished with the `mode` argument. `build_tool_args` is expected to be
369369
a list which is necessary in order to not mess up quoting of compiler and
@@ -412,6 +412,8 @@ def build_dependency(name, mode, build_tool_args, download_url, download_name, d
412412
compr = "gz"
413413
elif download_name.endswith(".tar.bz2"):
414414
compr = "bz2"
415+
elif download_name.endswith(".tar.xz"):
416+
compr = "xz"
415417
else:
416418
raise RuntimeError("fix source for new download type")
417419
download_tarfile = tarfile.open(name=download_tarfile_path, mode=f"r:{compr}")
@@ -438,6 +440,9 @@ def build_dependency(name, mode, build_tool_args, download_url, download_name, d
438440
except Exception as e:
439441
# Assert that the patch has already been applied
440442
run(["patch", "-p1", "--batch", "--reverse", "--dry-run", "-i", patch_abs], cwd=extract_dir)
443+
444+
if shell is not None:
445+
sp.run(shell, shell=True, check=True, cwd=extract_dir)
441446

442447
if mode == "ctest":
443448
run(["ctest", "-S", "HDF5config.cmake,BUILD_GENERATOR=Unix", "-C", BUILD_CFG, "-V", "-O", "hdf5.log"], cwd=extract_dir)
@@ -459,6 +464,12 @@ def build_dependency(name, mode, build_tool_args, download_url, download_name, d
459464
run_cmake(name, build_tool_args, cwd=extract_build_dir)
460465
else:
461466
raise ValueError()
467+
for fn, before, after in pre_compile_subs:
468+
with open(os.path.join(extract_dir, fn), 'r') as f:
469+
s = f.read()
470+
s = s.replace(before, after)
471+
with open(os.path.join(extract_dir, fn), 'w') as f:
472+
f.write(s)
462473
logger.info(f"\rBuilding {name}... ")
463474
run([make, f"-j{IFCOS_NUM_BUILD_PROCS}", "VERBOSE=1"], cwd=extract_build_dir)
464475
logger.info(f"\rInstalling {name}... ")
@@ -486,9 +497,6 @@ def build_dependency(name, mode, build_tool_args, download_url, download_name, d
486497
if platform.system() == "Darwin":
487498
ADDITIONAL_ARGS = [f"-mmacosx-version-min={TOOLSET}"] + ADDITIONAL_ARGS
488499

489-
if "wasm" in flags:
490-
ADDITIONAL_ARGS.extend(("-sWASM_BIGINT", "-fwasm-exceptions", "-sSUPPORT_LONGJMP"))
491-
492500
# If the linker supports GC sections, set it up to reduce binary file size
493501
# -fPIC is required for the shared libraries to work
494502

@@ -499,7 +507,11 @@ def build_dependency(name, mode, build_tool_args, download_url, download_name, d
499507
LDFLAGS = os.environ.get("LDFLAGS", "")
500508

501509
ADDITIONAL_ARGS_STR = " ".join(ADDITIONAL_ARGS)
502-
if "wasm" not in flags and sp.call([bash, "-c", "ld --gc-sections 2>&1 | grep -- --gc-sections &> /dev/null"]) != 0:
510+
511+
if "wasm" in flags:
512+
CFLAGS_MINIMAL = CXXFLAGS_MINIMAL = CFLAGS = CXXFLAGS = os.environ['SIDE_MODULE_CFLAGS']
513+
LDFLAGS = os.environ['SIDE_MODULE_LDFLAGS']
514+
elif sp.call([bash, "-c", "ld --gc-sections 2>&1 | grep -- --gc-sections &> /dev/null"]) != 0:
503515
CXXFLAGS_MINIMAL = f"{CXXFLAGS} {PIC} {ADDITIONAL_ARGS_STR}"
504516
CFLAGS_MINIMAL = f"{CFLAGS} {PIC} {ADDITIONAL_ARGS_STR}"
505517
if BUILD_STATIC:
@@ -525,6 +537,7 @@ def build_dependency(name, mode, build_tool_args, download_url, download_name, d
525537
locals()[f] += f" -flto={IFCOS_NUM_BUILD_PROCS}"
526538

527539
os.environ["CXXFLAGS"] = CXXFLAGS
540+
os.environ["CPPFLAGS"] = CXXFLAGS
528541
os.environ["CFLAGS"] = CFLAGS
529542
os.environ["LDFLAGS"] = LDFLAGS
530543

@@ -661,8 +674,8 @@ def build_dependency(name, mode, build_tool_args, download_url, download_name, d
661674
"--without-iconv",
662675
"--without-lzma"
663676
],
664-
download_url="ftp://xmlsoft.org/libxml2/",
665-
download_name=f"libxml2-{LIBXML2_VERSION}.tar.gz"
677+
download_url=f"https://download.gnome.org/sources/libxml2/{'.'.join(LIBXML2_VERSION.split('.')[0:2])}/",
678+
download_name=f"libxml2-{LIBXML2_VERSION}.tar.xz"
666679
)
667680

668681
if "OpenCOLLADA" in targets:
@@ -695,9 +708,11 @@ def build_dependency(name, mode, build_tool_args, download_url, download_name, d
695708

696709
if "python" in targets and not USE_CURRENT_PYTHON_VERSION and "wasm" not in flags:
697710
# Python should not be built with -fvisibility=hidden, from experience that introduces segfaults
711+
OLD_CPP_FLAGS = os.environ["CPPFLAGS"]
698712
OLD_CXX_FLAGS = os.environ["CXXFLAGS"]
699713
OLD_C_FLAGS = os.environ["CFLAGS"]
700714
os.environ["CXXFLAGS"] = CXXFLAGS_MINIMAL
715+
os.environ["CPPFLAGS"] = CXXFLAGS_MINIMAL
701716
os.environ["CFLAGS"] = CFLAGS_MINIMAL
702717

703718
# On OSX a dynamic python library is built or it would not be compatible
@@ -727,6 +742,7 @@ def build_dependency(name, mode, build_tool_args, download_url, download_name, d
727742
):
728743
raise e
729744

745+
os.environ["CPPFLAGS"] = OLD_CPP_FLAGS
730746
os.environ["CXXFLAGS"] = OLD_CXX_FLAGS
731747
os.environ["CFLAGS"] = OLD_C_FLAGS
732748

@@ -772,6 +788,7 @@ def build_dependency(name, mode, build_tool_args, download_url, download_name, d
772788
name=f"gmp-{GMP_VERSION}",
773789
mode="autoconf",
774790
build_tool_args=[ENABLE_FLAG, DISABLE_FLAG, "--with-pic", *gmp_args],
791+
pre_compile_subs=([("build/config.h", "HAVE_OBSTACK_VPRINTF 1", "HAVE_OBSTACK_VPRINTF 0")] if "wasm" in flags else []),
775792
download_url="https://ftp.gnu.org/gnu/gmp/",
776793
download_name=f"gmp-{GMP_VERSION}.tar.bz2"
777794
)
@@ -956,6 +973,7 @@ def build_dependency(name, mode, build_tool_args, download_url, download_name, d
956973
if "wasm" in flags:
957974
ADDITIONAL_ARGS = f"-Wl,-undefined,suppress -sSIDE_MODULE=2 -sEXPORTED_FUNCTIONS=_PyInit__ifcopenshell_wrapper"
958975

976+
os.environ["CPPFLAGS"] = f"{CXXFLAGS_MINIMAL} {ADDITIONAL_ARGS}"
959977
os.environ["CXXFLAGS"] = f"{CXXFLAGS_MINIMAL} {ADDITIONAL_ARGS}"
960978
os.environ["CFLAGS"] = f"{CFLAGS_MINIMAL} {ADDITIONAL_ARGS}"
961979
os.environ["LDFLAGS"] = f"{LDFLAGS} {ADDITIONAL_ARGS}"

pyodide/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ source:
77

88
build:
99
script: |
10-
BUILD_CFG=Release python nix/build-all.py --without-hdf5 --without-opencollada --without-swig --without-pcre -v --wasm --py312 IfcOpenShell-Python
10+
BUILD_CFG=Release python nix/build-all.py --without-hdf5 --without-opencollada --without-swig --without-pcre -v --wasm --py313 IfcOpenShell-Python
1111
mv package/ifcopenshell .
1212
cp pyodide/setup.py .
1313

0 commit comments

Comments
 (0)