WASIp2-via-WASIp3 Adapter#73
Merged
Merged
Conversation
# Conflicts: # src/resolver/api-types.ts
Coverage Report
File Coverage |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the standalone WASIp2 host with a layered architecture: a native WASIp3 host plus a WASIp2-via-WASIp3 compatibility adapter. Adds auto-detection of WASI version from component imports/exports.
Motivation
The previous WASIp2 host was a standalone implementation that duplicated logic already present in the WASIp3 host. This PR consolidates both WASI versions under a single WASIp3 foundation, with WASIp2 support provided as a thin adapter layer. This reduces maintenance burden and ensures feature parity between the two versions.
Key Changes
1. WASIp2 → WASIp3 Adapter Architecture
src/host/wasip2/directorysrc/host/wasip2-via-wasip3/— a new compatibility shim layer that translates WASIp2 interface calls to the WASIp3 hostsrc/host/wasip3/with additional implementations and tests2. Auto-Detection API (
instantiateWasiComponent)New
src/wasi-auto.tsprovides:WasiTypeenum —None,P2,P3detectWasiType()— inspects component exports/imports forwasi:prefixes and@0.2version patterns to determine which WASI version the component targetscreateWasiImports()— creates the correct host (P3 direct or P2-via-P3 adapter) based on detected typeThe top-level
instantiateWasiComponent()insrc/index.tsnow auto-detects and instantiates with the appropriate host.3. Dynamic Code-Split Loaders
New
src/dynamic.tsprovides lazy-loaded entry points:loadWasiP3Host()— auto-selects Node.js or browser WASIp3 hostloadWasiP2ViaP3Adapter()— loads the P2-via-P3 adapterloadWasiP3Serve()— loads the P3 serve support5. BindingContext → MarshalingContext Rename
BindingContexttype moved fromsrc/resolver/model/types.tstosrc/marshal/model/types.tsand renamed toMarshalingContextbctxparameters renamed tomctxthroughout resolver and marshal codependingBackgroundTasks: []field added to support background tasks from synccanon.lowerwith stream/future params6. Trampoline-Lower Refactoring
processFlatResult,processSpilledResult,handleLowerResult,handleLowerResultSpilledhelper functionslowerFlatFlat,lowerFlatSpilled,lowerSpilledFlat,lowerSpilledSpilled) now delegate to these helpershasFutureOrStreamReturnflag in lowering plan distinguishes async returns that are future/stream values (should not be awaited) from regular async returns (should be.then()-chained through the result processor)7. Parser Enhancement
.wasmcore module instead of a component8. Build Configuration
wasip2bundles replaced withwasip2ViaP3andwasip2ViaP3Nodebundles9. Minor Changes
WasiExit.statusrenamed toWasiExit.exitCodecliMain()removed fromsrc/utils/args.tsgetBuildInfo()simplified to use plain string property names./dist/release/index.js)Breaking Changes
createWasiP2Host()removed — usecreateWasiP3Host()+createWasiP2ViaP3Adapter(), or the new auto-detectinginstantiateWasiComponent()WasiExit.status→WasiExit.exitCode@pavelsavara/jsco/wasip2→@pavelsavara/jsco/wasip2-via-wasip3.tag/.valproperties instead of symbol-keyed[TAG]/[VAL]setCreateComponent()removed from WASI instantiation API