diff --git a/deployment/idunn/recipe.toml b/deployment/idunn/recipe.toml index 304ad29..c4ffef2 100644 --- a/deployment/idunn/recipe.toml +++ b/deployment/idunn/recipe.toml @@ -3,7 +3,7 @@ target = "vili" source_stamp_environment = "VILI_BUILD_COMMIT" required_gitlinks = ["vendor/CultLib", "vendor/kimodo", "vendor/SOMA-X"] -# The one external input: a relocatable CPython. The locked site-packages are installed into this tree itself: a copied +# External inputs: a relocatable CPython, then Blender and the libraries it loads. The locked site-packages are installed into this tree itself: a copied # environment would carry an absolute interpreter link and a recorded build path, and the seal refuses both. [[external_inputs]] id = "cpython" @@ -12,6 +12,83 @@ sha256 = "5ff9f0602ce964a529ed1e8555d3abab6341926d724402ba9a15e9e877191124" runner = "python-build" destination = "release/cpython.tar.gz" +# Blender 5.2.2 LTS, unpacked beside the interpreter. The tree is sealed whole; the daemon runs it with +# LD_LIBRARY_PATH=blender/lib (scripts/vili-daemon.mjs exportEnv). +[[external_inputs]] +id = "blender" +url = "https://download.blender.org/release/Blender5.2/blender-5.2.2-linux-x64.tar.xz" +sha256 = "84098912789dc450e95697c4184fb8a90acbe5111c2ba4aede3fecb57806a168" +runner = "python-build" +destination = "release/blender.tar.xz" + +# The nine Debian bookworm packages whose shared libraries Blender loads and its tree does not carry (the Blender +# tarball's loader reaches libGL and the X client libraries). Their usr/lib/x86_64-linux-gnu/*.so* go into blender/lib; +# nothing is installed on the host (motion-pipeline:ruling:blender-libs-bundled-in-release). One snapshot.debian.org +# timestamp, so the bytes are immutable; each sha256 is the package's own. + +[[external_inputs]] +id = "deb-libxrender1" +url = "https://snapshot.debian.org/archive/debian/20260301T000000Z/pool/main/libx/libxrender/libxrender1_0.9.10-1.1_amd64.deb" +sha256 = "b2a6d160578f359220101947c8d67059b44704a251e688de1d0b744fefedfd1a" +runner = "python-build" +destination = "release/deb-libxrender1.deb" + +[[external_inputs]] +id = "deb-libxfixes3" +url = "https://snapshot.debian.org/archive/debian/20260301T000000Z/pool/main/libx/libxfixes/libxfixes3_6.0.0-2_amd64.deb" +sha256 = "1cd616396ff2ecae77e6e8b5b7695d414f0146de2d147837a2a02165f99e1a2c" +runner = "python-build" +destination = "release/deb-libxfixes3.deb" + +[[external_inputs]] +id = "deb-libxi6" +url = "https://snapshot.debian.org/archive/debian/20260301T000000Z/pool/main/libx/libxi/libxi6_1.8-1+b1_amd64.deb" +sha256 = "6c2fb5f241b311788990122c6e693915867cd8ed9d6da2e3524aec7ed3cdb4c0" +runner = "python-build" +destination = "release/deb-libxi6.deb" + +[[external_inputs]] +id = "deb-libxkbcommon0" +url = "https://snapshot.debian.org/archive/debian/20260301T000000Z/pool/main/libx/libxkbcommon/libxkbcommon0_1.5.0-1_amd64.deb" +sha256 = "e3fe045b9a33a101de1c5a912a4a10928db055c3f68930f47eccbb44d7c7d54e" +runner = "python-build" +destination = "release/deb-libxkbcommon0.deb" + +[[external_inputs]] +id = "deb-libsm6" +url = "https://snapshot.debian.org/archive/debian/20260301T000000Z/pool/main/libs/libsm/libsm6_1.2.3-1_amd64.deb" +sha256 = "22a420890489023346f30fecef14ea900a0788e7bf959ef826aabb83944fccfb" +runner = "python-build" +destination = "release/deb-libsm6.deb" + +[[external_inputs]] +id = "deb-libice6" +url = "https://snapshot.debian.org/archive/debian/20260301T000000Z/pool/main/libi/libice/libice6_1.0.10-1_amd64.deb" +sha256 = "452796e565c9d42386bd59990000ae9c37d85e142e00ee2b14df0787e2bbf970" +runner = "python-build" +destination = "release/deb-libice6.deb" + +[[external_inputs]] +id = "deb-libgl1" +url = "https://snapshot.debian.org/archive/debian/20260301T000000Z/pool/main/libg/libglvnd/libgl1_1.6.0-1_amd64.deb" +sha256 = "6f89b1702c48e9a2437bb3c1ffac8e1ab2d828fc28b3d14b2eecd4cc19b2c790" +runner = "python-build" +destination = "release/deb-libgl1.deb" + +[[external_inputs]] +id = "deb-libglx0" +url = "https://snapshot.debian.org/archive/debian/20260301T000000Z/pool/main/libg/libglvnd/libglx0_1.6.0-1_amd64.deb" +sha256 = "95f568df73dedf43ae66834a75502112e0d4f3ad7124f3dbfa790b739383b896" +runner = "python-build" +destination = "release/deb-libglx0.deb" + +[[external_inputs]] +id = "deb-libglvnd0" +url = "https://snapshot.debian.org/archive/debian/20260301T000000Z/pool/main/libg/libglvnd/libglvnd0_1.6.0-1_amd64.deb" +sha256 = "b6da5b153dd62d8b5e5fbe25242db1fc05c068707c365db49abda8c2427c75f8" +runner = "python-build" +destination = "release/deb-libglvnd0.deb" + # ---- node-build: the daemon, the Idunn entry and its dependencies [[steps]] @@ -67,6 +144,30 @@ phase = "prepare" runner = "python-build" argv = ["tar", "-xzf", "release/cpython.tar.gz", "-C", "release"] +[[steps]] +id = "unpack-blender" +phase = "prepare" +runner = "python-build" +argv = ["tar", "-xJf", "release/blender.tar.xz", "-C", "release", "--transform", "s,^blender-5.2.2-linux-x64,blender,"] + +[[steps]] +id = "unpack-blender-libs" +phase = "prepare" +runner = "python-build" +required_environment = ["PATH"] +argv = [ + "python3.12", "deployment/idunn/unpack-debs.py", "release/blender/lib", + "release/deb-libxrender1.deb", + "release/deb-libxfixes3.deb", + "release/deb-libxi6.deb", + "release/deb-libxkbcommon0.deb", + "release/deb-libsm6.deb", + "release/deb-libice6.deb", + "release/deb-libgl1.deb", + "release/deb-libglx0.deb", + "release/deb-libglvnd0.deb", +] + [[steps]] id = "install-build-tools" phase = "prepare" @@ -93,7 +194,7 @@ id = "test-worker" phase = "test" runner = "python-build" working_directory = "." -required_environment = ["HOME", "TMPDIR", "PYTHONPATH", "PATH"] +required_environment = ["HOME", "TMPDIR", "PYTHONPATH", "PATH", "VILI_BLENDER"] argv = ["python3.12", "-m", "unittest", "discover", "-s", "scripts", "-p", "test_*.py"] # Every module the worker and the encoder child import at top level, kimodo.scripts.generate included. @@ -114,7 +215,7 @@ runner = "python-build" required_environment = ["PATH"] argv = ["python3.12", "-m", "compileall", "-q", "-j", "4", "--invalidation-mode", "unchecked-hash", "release/python/lib/python3.12"] -# ---- the sealed release: node, vili, python +# ---- the sealed release: node, vili, python, blender [[artifacts]] id = "node" @@ -139,9 +240,17 @@ source = "release/python" destination = "python" executable_members = ["bin/python3.12"] +[[artifacts]] +id = "blender" +source_kind = "runner-output" +runner = "python-build" +source = "release/blender" +destination = "blender" +executable_members = ["blender"] + [service] executable_artifact = "node" -required_adjacent_artifacts = ["vili", "python"] +required_adjacent_artifacts = ["vili", "python", "blender"] arguments = [ { kind = "literal", value = "vili/scripts/idunn-entry.mjs" }, { kind = "literal", value = "--state-root" }, @@ -187,7 +296,7 @@ startup = "create-or-open-after-write-lease" id = "jobs" relative_path = "jobs" kind = "external-directory" -schema = "gamecult.vili.motion_job.v0" +schema = "gamecult.vili.motion_job.v1" writer = "process-bound-single-writer" recovery = "preserve" startup = "create-or-open-after-write-lease" diff --git a/deployment/idunn/unpack-debs.py b/deployment/idunn/unpack-debs.py new file mode 100644 index 0000000..cf197fc --- /dev/null +++ b/deployment/idunn/unpack-debs.py @@ -0,0 +1,76 @@ +"""Unpacks the shared libraries of Debian packages into one directory (the recipe's unpack-blender-libs step): + + python3.12 deployment/idunn/unpack-debs.py ... + +Only usr/lib/x86_64-linux-gnu/*.so* is taken, flat: regular files and relative symlinks. Nothing else in a package +is read out, nothing is overwritten, and a package that yields no library is an error. Standard library only: the +step runs before any package is installed. +""" +import fnmatch +import io +import os +import pathlib +import sys +import tarfile + +LIBRARY_DIRECTORY = "usr/lib/x86_64-linux-gnu" + + +def data_archive(deb): + """The data.tar.* member of a .deb, an ar archive.""" + raw = deb.read_bytes() + if raw[:8] != b"!\n": + raise SystemExit("not an ar archive: " + deb.name) + position = 8 + while position + 60 <= len(raw): + header = raw[position:position + 60] + name = header[:16].decode("ascii").strip().rstrip("/") + size = int(header[48:58].decode("ascii").strip()) + position += 60 + if name.startswith("data.tar"): + return raw[position:position + size] + position += size + (size & 1) + raise SystemExit("no data archive in " + deb.name) + + +def unpack(deb, destination): + taken = [] + with tarfile.open(fileobj=io.BytesIO(data_archive(deb)), mode="r:*") as archive: + for member in archive: + directory, _, name = member.name.lstrip("./").rpartition("/") + if directory != LIBRARY_DIRECTORY or not fnmatch.fnmatch(name, "*.so*"): + continue + target = destination / name + if os.path.lexists(target): + raise SystemExit("already present: " + name) + if member.isreg(): + target.write_bytes(archive.extractfile(member).read()) + target.chmod(0o644) + elif member.issym(): + if "/" in member.linkname or member.linkname in ("", ".", ".."): + raise SystemExit("not a sibling link: " + name) + os.symlink(member.linkname, target) + else: + raise SystemExit("unexpected member type: " + name) + taken.append(name) + if not taken: + raise SystemExit("no library in " + deb.name) + return taken + + +def main(argv): + if len(argv) < 2: + raise SystemExit("usage: unpack-debs.py ...") + destination = pathlib.Path(argv[0]) + if not destination.is_dir(): + raise SystemExit("destination is not a directory") + total = 0 + for deb in argv[1:]: + taken = unpack(pathlib.Path(deb), destination) + total += len(taken) + print(f"{pathlib.Path(deb).name}: {len(taken)} libraries") + print(f"unpacked {total} libraries") + + +if __name__ == "__main__": + main(sys.argv[1:])