- Reader: real blend block bases win over synthesized interior array addresses, fixing post-detect track truncation (19 exported vs 60 in Main). - Track color reads DNA float[3] with an alpha pad; bpy writes 3 components because RNA PROP_COLOR_GAMMA has no alpha. - Clamp track weight and weight_stab to the RNA 0..1 factor range. - Read the scene frame range from scenes[0].renderSettings. - Mask status phases poll with a stall-tolerant loop instead of expect.poll, which fails the whole run when one DOM query stalls during engine persist. - Continuation and module coverage record the 24/24 PASS receipt (tests/golden/CLIP-HEADED-20261204-052513); acceptance stays NOT_CLAIMED. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
153 lines
6.7 KiB
Python
153 lines
6.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Build the Blender-pinned Ceres Solver and Abseil libraries for the WASM libmv path.
|
|
|
|
libmv (browser-side marker tracking and camera solve) needs Ceres, which in turn
|
|
needs Abseil. Both sources ship inside the pinned Blender libraries archive, and
|
|
Eigen comes from the Blender source tree, so the build is reproducible offline.
|
|
|
|
The resulting static archives are picked up by
|
|
blender-5.2.0/build_files/cmake/platform/web.cmake from build_web_ceres/install.
|
|
"""
|
|
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import tarfile
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
ABSEIL_PACKAGE = "packages/abseil-cpp-20250814.1.tar.gz"
|
|
ABSEIL_SHA256 = "1692f77d1739bacf3f94337188b78583cf09bab7e420d2dc6c5605a4f86785a1"
|
|
CERES_PACKAGE = "packages/ceres-0c70ed3a1a2d6ba47c06c7e8b3b040880bc474db.tar.gz"
|
|
CERES_SHA256 = "bf0bcc78fae884e59dd893693e52510da7cc6866a7444fdae9ba8f19eae266cd"
|
|
LIBRARIES_ARCHIVE = ROOT / "blender-with-libraries-5.2.0.tar.xz"
|
|
|
|
|
|
def materialize_package(packages: Path, member: str, sha256: str) -> Path:
|
|
target = packages / Path(member).name
|
|
if not target.is_file():
|
|
if not LIBRARIES_ARCHIVE.is_file():
|
|
raise FileNotFoundError(LIBRARIES_ARCHIVE)
|
|
with tarfile.open(LIBRARIES_ARCHIVE) as archive:
|
|
source = archive.extractfile(member)
|
|
if source is None:
|
|
raise RuntimeError(f"{member} is missing from {LIBRARIES_ARCHIVE}")
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
with target.open("wb") as out:
|
|
shutil.copyfileobj(source, out)
|
|
if hashlib.sha256(target.read_bytes()).hexdigest() != sha256:
|
|
raise RuntimeError(f"Blender-pinned digest mismatch for {target.name}")
|
|
return target
|
|
|
|
|
|
def write_eigen_config(install: Path) -> Path:
|
|
"""Ceres finds Eigen through a config package; the Blender tree only ships headers."""
|
|
cmake_dir = install / "eigen3/share/eigen3/cmake"
|
|
cmake_dir.mkdir(parents=True, exist_ok=True)
|
|
include = ROOT / "blender-5.2.0/extern/eigen3"
|
|
(cmake_dir / "Eigen3Config.cmake").write_text(
|
|
f'set(EIGEN3_INCLUDE_DIR "{include}")\n'
|
|
'set(Eigen3_VERSION "3.4.0")\n'
|
|
"if(NOT TARGET Eigen3::Eigen)\n"
|
|
" add_library(Eigen3::Eigen INTERFACE IMPORTED)\n"
|
|
" set_target_properties(Eigen3::Eigen PROPERTIES\n"
|
|
' INTERFACE_INCLUDE_DIRECTORIES "${EIGEN3_INCLUDE_DIR}")\n'
|
|
"endif()\n")
|
|
(cmake_dir / "Eigen3ConfigVersion.cmake").write_text(
|
|
'set(PACKAGE_VERSION "3.4.0")\n'
|
|
"if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)\n"
|
|
" set(PACKAGE_VERSION_COMPATIBLE FALSE)\n"
|
|
"else()\n"
|
|
" set(PACKAGE_VERSION_COMPATIBLE TRUE)\n"
|
|
" if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)\n"
|
|
" set(PACKAGE_VERSION_EXACT TRUE)\n"
|
|
" endif()\n"
|
|
"endif()\n")
|
|
return cmake_dir
|
|
|
|
|
|
def configure_and_install(env: dict, source: Path, build: Path, prefix: Path,
|
|
toolchain: Path, extra: list[str], jobs: int) -> list[str]:
|
|
build.mkdir(parents=True, exist_ok=True)
|
|
settings = [str(toolchain), str(prefix), *extra]
|
|
stamp = build / "web-configure.json"
|
|
record = json.dumps(settings)
|
|
if not stamp.is_file() or stamp.read_text() != record:
|
|
command = ["cmake", "-S", str(source), "-B", str(build),
|
|
f"-DCMAKE_TOOLCHAIN_FILE={toolchain}",
|
|
"-DCMAKE_BUILD_TYPE=Release",
|
|
f"-DCMAKE_INSTALL_PREFIX={prefix}",
|
|
"-DCMAKE_CXX_FLAGS=-O2 -fexceptions",
|
|
"-DCMAKE_C_FLAGS=-O2 -fexceptions",
|
|
*extra]
|
|
subprocess.run(command, check=True, env=env)
|
|
stamp.write_text(record)
|
|
subprocess.run(["cmake", "--build", str(build), "--target", "install", f"-j{jobs}"],
|
|
check=True, env=env)
|
|
return command if not stamp.is_file() else settings
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--jobs", type=int, default=8)
|
|
args = parser.parse_args()
|
|
|
|
base = ROOT / "build_web_ceres"
|
|
packages = base / "packages"
|
|
src = base / "src"
|
|
install = base / "install"
|
|
em = ROOT / ".emsdk/upstream/emscripten"
|
|
toolchain = em / "cmake/Modules/Platform/Emscripten.cmake"
|
|
if not toolchain.is_file():
|
|
raise FileNotFoundError(toolchain)
|
|
|
|
env = dict(os.environ)
|
|
env["PATH"] = str(em) + os.pathsep + env["PATH"]
|
|
|
|
src.mkdir(parents=True, exist_ok=True)
|
|
for member, sha256 in ((ABSEIL_PACKAGE, ABSEIL_SHA256), (CERES_PACKAGE, CERES_SHA256)):
|
|
package = materialize_package(packages, member, sha256)
|
|
with tarfile.open(package) as archive:
|
|
archive.extractall(src, filter="data")
|
|
|
|
eigen_config = write_eigen_config(install)
|
|
abseil = install / "abseil"
|
|
ceres = install / "ceres"
|
|
|
|
abseil_settings = configure_and_install(
|
|
env, src / "abseil-cpp-20250814.1", base / "build_absl", abseil, toolchain,
|
|
["-DABSL_ENABLE_INSTALL=ON", "-DABSL_PROPAGATE_CXX_STD=ON",
|
|
"-DBUILD_TESTING=OFF", "-DCMAKE_CXX_STANDARD=17"], args.jobs)
|
|
ceres_settings = configure_and_install(
|
|
env, src / "ceres-solver-0c70ed3a1a2d6ba47c06c7e8b3b040880bc474db",
|
|
base / "build_ceres", ceres, toolchain,
|
|
["-DBUILD_SHARED_LIBS=OFF", "-DBUILD_TESTING=OFF", "-DBUILD_BENCHMARKS=OFF",
|
|
"-DBUILD_EXAMPLES=OFF", "-DUSE_CUDA=OFF", "-DLAPACK=OFF", "-DSUITESPARSE=OFF",
|
|
f"-Dabsl_DIR={abseil}/lib/cmake/absl",
|
|
f"-DEigen3_DIR={eigen_config}",
|
|
f"-DCMAKE_PREFIX_PATH={abseil}",
|
|
"-DCMAKE_CXX_STANDARD=17",
|
|
"-DCMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE_SUPPORTED=TRUE",
|
|
"-DCMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE=-Wl,--whole-archive;<LINK_ITEM>;-Wl,--no-whole-archive"],
|
|
args.jobs)
|
|
|
|
artifacts = {str(path.relative_to(ROOT)): hashlib.sha256(path.read_bytes()).hexdigest()
|
|
for path in sorted((install / "abseil/lib").glob("*.a"))}
|
|
artifacts.update({str(path.relative_to(ROOT)): hashlib.sha256(path.read_bytes()).hexdigest()
|
|
for path in sorted((install / "ceres/lib").glob("*.a"))})
|
|
(base / "build-manifest.json").write_text(json.dumps({
|
|
"abseil": {"version": "20250814.1", "packageSha256": ABSEIL_SHA256,
|
|
"settings": abseil_settings},
|
|
"ceres": {"version": "0c70ed3a1a2d6ba47c06c7e8b3b040880bc474db",
|
|
"packageSha256": CERES_SHA256, "settings": ceres_settings},
|
|
"eigen": {"include": str(ROOT / "blender-5.2.0/extern/eigen3")},
|
|
"artifacts": artifacts,
|
|
"validation": "NOT_RUN", "acceptance": "NOT_CLAIMED"}, indent=2) + "\n")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|