Repository navigation
Conversation
1cfe609 to
90cbde9
Compare
e0c838f to
505e405
Compare
ComponentGenerator::generate now binds the WIT world, links the libraries and initializes the result as separate steps. Initialization follows an InitPlan: owned import stubs instead of the borrowed Resolve, the environment, preopens and entropy. The linker takes the adapter as input, and the Python path search sorts directory entries so that the library order does not depend on the file system.
BindingsPreparer resolves a WIT world once and returns Prepared assets: the bindings module, the generated Python bindings, the runtime libraries, the standard library, and the symbols and import stubs that initialization needs. Prepared::write stores them as content-addressed blobs and a manifest whose digest is their identity. Prepared::read verifies every blob, the manifest form and the initialization WIT before use. Assembler links prepared assets with an app and its native extensions without WIT processing. Each Python path entry has a mount name, so the library names of extensions do not depend on the order of the entries. An app that carries a componentize-py.toml file is rejected, because it would change the bindings. Assembly::initialize_with lets the caller supply the engine that runs initialization. The prepare and assemble subcommands expose this from the command line.
Golem's engine uses Wasmtime 50.0.1, so the crate can run initialization on an engine that Golem configures.
Assembly::initialize takes an Initializer: the engine, an optional linker setup and an optional store setup, such as fuel or an epoch deadline that the engine requires. componentize and assemble use default_engine. The embedded-runtime feature, on by default, builds CPython and the runtime into the crate. Without it the crate reads and assembles prepared assets, which carry their own runtime, and preparing or componentize fail with a clear error. The binary requires the feature.
Golem's Wasmtime has its own WASI implementation, so the crate cannot build the WASI context for it. Assembly::initialize now takes the caller's store and linker, and add_trapping_stubs adds the plan's import stubs to any linker. initialize_component runs initialization for either. Without the embedded-runtime feature the crate does not depend on wasmtime-wasi, and Assembly::initialize_default keeps the crate's own WASI setup for the CLI. Allow the deprecated filetime::set_file_times call: newer filetime releases deprecate it, and the std replacement does not set directory times on every platform.
Without the embedded-runtime feature the crate only reads, assembles and initializes prepared assets, so the WIT generator, registry client, CLI and async runtime become optional dependencies of that feature. An embedder that links the assembler then pulls in fewer crates.
90cbde9 to
3cf6e79
Compare
eb5a558 to
189e903
Compare
# Conflicts: # src/lib.rs
Unpacking a prepared blob created any symlink or hard link in it, and setting the build mtimes then followed the link to host files. Preparation writes only files and directories, so unpacking now rejects every other entry. The digest of the initialization WIT now normalizes CRLF, so assets prepared on one platform match an assembler built from a checkout that converted line endings. InitPlan::new takes the build entropy from its caller.
|
Review findings for the delta from runtime-baseline (7389c59) to this head (cad25ee), excluding PR #1. No confirmed runtime defect found. Two findings remain:
The separation into owned prepared assets, linking, and caller-owned initialization fits the intended integration. The review traced canonical manifest and blob validation, archive extraction, named native-library mounts, support-library resolution, and preservation of WASI/stub behavior and temporary-directory lifetimes. No additional architectural objection was found. Independent checks passed: Limits: CPython was not rebuilt and embedded-runtime integration tests were not independently rerun. Custom initialization, prepared resource finalization/support-library execution, and byte-identical assembly remain unverified. The reported author-run tests are not independent verification. |
Fixed in bbed742. |
Added in 40a5548. |
|
Follow-up review at 40a5548, against the updated runtime-baseline base (87f80f2), excluding PR #1. The engine-documentation finding is resolved: The new Medium — one narrower test-fidelity gap remains: the initialization WASI setup copies The passing test therefore establishes caller-owned initialization and resource/async operation, but not faithful construction of the build-time WASI context. Configure the secure/insecure random streams and seed from Formatting and diff-whitespace checks also passed. The full suites and Golem’s own WASI implementation were not exercised. The initial build attempt encountered an older SDK missing |
Fixed in 07fbd4e. The new |
vigoo
left a comment
There was a problem hiding this comment.
The initialization findings are resolved. The caller-owned and default initializers now use InitPlan::wasi_builder; the test reads back random bytes and both clocks captured at Python import. The targeted test passed with WASI SDK 34, and the library builds with --no-default-features.
One non-blocking correction to the PR description: it says disabling embedded-runtime removes the wasmtime-wasi dependency. cargo tree --no-default-features shows that wasmtime-wasi is now a direct dependency with p2 enabled. Please distinguish skipping the embedded CPython build from removing WASI, and remove the stale note that the engine docs omit map support.
Touches GOL-1850 (PY-02): the separate prepare and assemble steps that Golem's Python build uses. It does not resolve the issue.
Persisted prepare/assemble API for the Golem Python SDK. It builds on #1, which is merged.
ComponentGenerator::generatebinds the WIT world, links the libraries and initializes the result. Initialization follows anInitPlan: owned import stubs instead of the borrowedResolve, the environment, the preopens, and the entropy derived from the linked component, the app name and the Python path files. The Python path search sorts directory entries, so the library order does not depend on the file system.BindingsPreparer::prepareresolves a WIT world once and returnsPrepared: the bindings module, the generated Python bindings, the runtime libraries, the WASI adapter, the standard library, and the symbols and import stubs for initialization.Prepared::writestores content-addressed blobs and a manifest. The SHA-256 of the manifest is the identity.Prepared::readrejects a changed or missing blob, an extra file, a non-canonical manifest, another format and another initialization WIT. The initialization WIT digest normalizes CRLF, so a checkout that converts line endings builds a matching assembler. Unpacking a blob accepts only regular files and directories, so a link in a blob cannot point the build-time mtime update at host files.Assembler::assemblelinks the prepared assets with an app and its native extensions, without WIT processing or code generation. Each Python path entry has a mount name, and the library name of an extension is/{name}/{path}, so the names do not depend on the order of the entries. An app that carries acomponentize-py.tomlfile is rejected, because it would change the bindings.Assembler::outputnames the file that the caller writes. The build digest skips it, ascomponentizeskips its output, so an output inside a Python path entry does not change the next build.Assembly::initializetakes the caller'sStoreandLinker, built on the caller's engine with its own WASI implementation, asInitPlandescribes: environment, preopens, entropy and build clocks.InitPlan::wasi_builderreturns a WASI context builder with these settings. It opens each preopen read-only, so initialization cannot change the directories that it reads: a write fails in the guest with an error that Python can catch.add_trapping_stubsadds the plan's import stubs to any linker. The crate does not choose engine settings or WASI for the caller.componentizeandassemblekeep this crate's WASI setup anddefault_engine. Wasmtime moves to 50.0.1, the version that Golem's engine uses; this change alone needs no source change.embedded-runtimefeature, on by default, builds CPython and the runtime into the crate. Without the feature, the crate reads and assembles prepared assets, which carry their own runtime, and does not build CPython. Preparing andcomponentizeare then not compiled. The crate still depends onwasmtime-wasi, with only itsp2feature, forInitPlan::wasi_builder. The binary requires the feature.componentize-py prepare <dir>prints the identity.componentize-py assemble --prepared <dir> [--expect-identity <id>] <app> -p [name=]dirlinks and initializes. It passes its-ofile as the output, and creates the file's directory before the digest.Tests in
tests/componentize.rsprepare once and assemble two unrelated apps in separate processes, check that the prepared files do not change, and check that rejected assets do not import the app: the app raises a marker error on import, and the error appears only for intact assets. Another test tries to write into the app directory during import, and checks that each write fails, that the directory does not change and that the component runs. A third test assembles twice with the default Python path and output, so the second build has the first output in the app directory. The app prints a random value that it draws on import, and the value must stay the same; a changed source must change it.Known gaps: the
embedded-runtimecheck at the start ofbindcannot fail, becausebindexists only with the feature. No test covers support-library linking with prepared assets, finalization of exported resources, a non-canonical manifest, a missing blob or another format; the digest-mismatch test corrupts the first blob thatread_dirreturns.Not solved here: two assemblies of the same input can still differ in a few bytes. The difference follows host metadata of the build directories that assembly creates.
Verification
On this head, 45416d0 (Linux x86_64, local).
cargo test --release -- --skip http_p3_example: passed (123 lib, 21 bindings, 14 componentize tests).bash .github/workflows/lint.sh: passed.assemble_leaves_the_app_directory_unchangedfails, because the import writes/app/writer.py. WithNoneinstead of the output in the digest,assemble_skips_its_output_in_the_build_digestfails with two different values.http_p3_example, because its port is taken on the build machine.main, so the Test workflow runs on each head. It passed on Linux, macOS and Windows at 45416d0 (run 47111397895).