package-zip-archives: --shared flag

Currently adding `-shared-` suffix to all dependencies instead of overriding, to avoid mixups during transition period.
This commit is contained in:
Andrej730
2026-08-28 16:30:10 +05:00
parent 05152a5fc6
commit 914720c7ac
2 changed files with 221 additions and 94 deletions
+52 -21
View File
@@ -3,6 +3,7 @@
# ///
import argparse
import json
import logging
import os
import platform
@@ -76,18 +77,45 @@ def get_install_dir(arch_suffix: str) -> Path:
raise Exception("No install dir found")
def find_qt_dir(install_root: Path, qt6_version: str) -> Path | None:
for qt_candidate in install_root.glob(f"qt6-{qt6_version}-*/{qt6_version}/*"):
class RuntimeInfo(NamedTuple):
runtime_dirs: list[Path]
qt_dir: Path | None
def find_qt_dir(install_root: Path, qt6_version: str, qt6_install_root: str | None) -> Path | None:
search_root = Path(qt6_install_root).parent if qt6_install_root else install_root
for qt_candidate in search_root.glob(f"qt6-{qt6_version}-*/{qt6_version}/*"):
if (qt_candidate / "lib").is_dir():
return qt_candidate
return None
def find_occt_dir(install_root: Path) -> Path:
candidates = [candidate for candidate in install_root.glob("occt-shared-*") if candidate.is_dir()]
if len(candidates) != 1:
raise Exception(f"Expected exactly one OCCT shared candidate, found: {candidates}")
return candidates[0]
def get_runtime_info(install_root: Path, qt6_version: str) -> RuntimeInfo:
install_dirs_path = install_root / "install_dirs.json"
install_dirs: dict[str, str] = json.loads(install_dirs_path.read_text()) if install_dirs_path.is_file() else {}
# Qt is handled separately via `stage_qt_runtime_payload`.
qt6_install_root = None
if "qt6" in install_dirs:
qt6_install_root = install_dirs.pop("qt6")
qt_dir_env = os.getenv("QT_DIR")
qt_dir = Path(qt_dir_env) if qt_dir_env else find_qt_dir(install_root, qt6_version, qt6_install_root)
if ARGS.shared:
dependencies_to_stage = install_dirs.keys()
elif ARGS.occt_shared:
dependencies_to_stage = {"occt"}
else:
return RuntimeInfo([], qt_dir)
runtime_dirs = []
for name in dependencies_to_stage:
runtime_dir = Path(install_dirs[name])
assert "-shared-" in runtime_dir.name, f"Expected a shared build, found: {runtime_dir}"
runtime_dirs.append(runtime_dir)
return RuntimeInfo(runtime_dirs, qt_dir)
def ensure_soname_links(paths: list[Path]) -> None:
@@ -265,7 +293,7 @@ def package_python_wrapper(
github_sha: str,
output_dir: Path,
arch_suffix: str,
occt_dir: Path | None,
runtime_dirs: list[Path],
) -> None:
logger.info(f"Packaging python wrapper '{py_dir.name}'")
py_version = py_dir.name
@@ -306,8 +334,8 @@ def package_python_wrapper(
# TODO: packs qt libs also?
stage_runtime_payload(ifcopenshell_install_dir, ifcopenshell_dir)
if occt_dir:
stage_runtime_payload(occt_dir, ifcopenshell_dir)
for runtime_dir in runtime_dirs:
stage_runtime_payload(runtime_dir, ifcopenshell_dir)
if not is_platform("MAC"):
check_runtime_dependencies(ifcopenshell_dir)
@@ -330,7 +358,7 @@ def package_executable(
output_dir: Path,
autodesk_connector_dir: Path,
qt_dir: Path | None,
occt_dir: Path | None,
runtime_dirs: list[Path],
arch_suffix: str,
) -> None:
exe = exe_path.name
@@ -346,8 +374,8 @@ def package_executable(
# but is this guard needed or it should be always False?
stage_runtime_payload(ifcopenshell_install_dir, package_dir, include_geometry_writers=is_platform("MAC"))
if occt_dir:
stage_runtime_payload(occt_dir, package_dir)
for runtime_dir in runtime_dirs:
stage_runtime_payload(runtime_dir, package_dir)
# On macOS, rpath is already set at build time via CMake's INSTALL_RPATH, and
# QT apps are packaged as .app bundles (`package_app_bundle`) instead.
@@ -404,6 +432,7 @@ class Args(NamedTuple):
arch_suffix: str
log_level: str
occt_shared: bool
shared: bool
ARGS: Args
@@ -414,12 +443,17 @@ def main() -> None:
parser.add_argument("arch_suffix", choices=ARCH_SUFFIXES, help="Zip filename suffix.")
# TODO: relax default to INFO once things get more stable.
parser.add_argument("--log-level", default="DEBUG", choices=LOG_LEVELS, help="Logging verbosity.")
# TODO: add `--shared`.
parser.add_argument("--occt-shared", action="store_true", help="OCCT was built as shared libraries.")
parser.add_argument("--shared", action="store_true", help="Build was made with shared libraries.")
args = parser.parse_args()
global ARGS
ARGS = Args(arch_suffix=args.arch_suffix, log_level=args.log_level, occt_shared=args.occt_shared)
ARGS = Args(
arch_suffix=args.arch_suffix,
log_level=args.log_level,
occt_shared=args.occt_shared,
shared=args.shared,
)
logger.setLevel(ARGS.log_level)
# bonsaiviewer-autodesk is now a Rust connector. packaging/build.py
@@ -439,16 +473,13 @@ def main() -> None:
output_dir.mkdir(parents=True, exist_ok=True)
qt6_version = os.getenv("QT6_VERSION", "6.8.3")
qt_dir_env = os.getenv("QT_DIR")
qt_dir = Path(qt_dir_env) if qt_dir_env else find_qt_dir(install_root, qt6_version)
occt_dir = find_occt_dir(install_root) if ARGS.occt_shared else None
runtime_dirs, qt_dir = get_runtime_info(install_root, qt6_version)
# Iterate over all built Python wrappers in `install/ifcopenshell/python-x.y.z`
# and zip them, bundling all dynamic libs from `lib`.
github_sha = get_git_sha()
for py_dir in sorted(ifcopenshell_install_dir.glob("python-*")):
package_python_wrapper(py_dir, ifcopenshell_install_dir, github_sha, output_dir, ARGS.arch_suffix, occt_dir)
package_python_wrapper(py_dir, ifcopenshell_install_dir, github_sha, output_dir, ARGS.arch_suffix, runtime_dirs)
# Iterate over all executables in `install/ifcopenshell/bin` and zip them.
# Each zip bundles dynamic libs from `lib` and also qt libs.
@@ -462,7 +493,7 @@ def main() -> None:
output_dir,
autodesk_connector_dir,
qt_dir,
occt_dir,
runtime_dirs,
ARGS.arch_suffix,
)