wasmtime-wasi: support both snapshots

This commit is contained in:
Pat Hickey
2021-01-29 12:11:38 -08:00
parent d738a4a588
commit c8e76b11ba

View File

@@ -3,27 +3,59 @@ pub use wasi_common::{
WasiCtx, WasiCtxBuilder, WasiDir, WasiFile, WasiCtx, WasiCtxBuilder, WasiDir, WasiFile,
}; };
// Defines a `struct Wasi` with member fields and appropriate APIs for dealing pub mod snapshots {
// with all the various WASI exports. pub mod preview_1 {
wasmtime_wiggle::wasmtime_integration!({ use wasi_common::WasiCtx;
// The wiggle code to integrate with lives here: // Defines a `struct Wasi` with member fields and appropriate APIs for dealing
target: wasi_common::snapshots::preview_1, // with all the various WASI exports.
// This must be the same witx document as used above. This should be ensured by wasmtime_wiggle::wasmtime_integration!({
// the `WASI_ROOT` env variable, which is set in wasi-common's `build.rs`. // The wiggle code to integrate with lives here:
witx: ["$WASI_ROOT/phases/snapshot/witx/wasi_snapshot_preview1.witx"], target: wasi_common::snapshots::preview_1,
// This must be the same ctx type as used for the target: // This must be the same witx document as used above. This should be ensured by
ctx: WasiCtx, // the `WASI_ROOT` env variable, which is set in wasi-common's `build.rs`.
// This macro will emit a struct to represent the instance, witx: ["$WASI_ROOT/phases/snapshot/witx/wasi_snapshot_preview1.witx"],
// with this name and docs: // This must be the same ctx type as used for the target:
modules: { wasi_snapshot_preview1 => ctx: WasiCtx,
{ name: Wasi, // This macro will emit a struct to represent the instance,
docs: "An instantiated instance of the wasi exports. // with this name and docs:
modules: { wasi_snapshot_preview1 =>
{ name: Wasi,
docs: "An instantiated instance of the wasi exports.
This represents a wasi module which can be used to instantiate other wasm This represents a wasi module which can be used to instantiate other wasm
modules. This structure exports all that various fields of the wasi instance modules. This structure exports all that various fields of the wasi instance
as fields which can be used to implement your own instantiation logic, if as fields which can be used to implement your own instantiation logic, if
necessary. Additionally [`Wasi::get_export`] can be used to do name-based necessary. Additionally [`Wasi::get_export`] can be used to do name-based
resolution.", resolution.",
}, },
}, },
}); });
}
pub mod preview_0 {
use wasi_common::WasiCtx;
// Defines a `struct Wasi` with member fields and appropriate APIs for dealing
// with all the various WASI exports.
wasmtime_wiggle::wasmtime_integration!({
// The wiggle code to integrate with lives here:
target: wasi_common::snapshots::preview_0,
// This must be the same witx document as used above. This should be ensured by
// the `WASI_ROOT` env variable, which is set in wasi-common's `build.rs`.
witx: ["$WASI_ROOT/phases/old/snapshot_0/witx/wasi_unstable.witx"],
// This must be the same ctx type as used for the target:
ctx: WasiCtx,
// This macro will emit a struct to represent the instance,
// with this name and docs:
modules: { wasi_unstable =>
{ name: Wasi,
docs: "An instantiated instance of the wasi exports.
This represents a wasi module which can be used to instantiate other wasm
modules. This structure exports all that various fields of the wasi instance
as fields which can be used to implement your own instantiation logic, if
necessary. Additionally [`Wasi::get_export`] can be used to do name-based
resolution.",
},
},
});
}
}