Capability-aware WASI Preview 1 utilities for MoonBit
Dependencies
MoonBit WASI diagnostics
arguments: ["main.wasm"]
environment entries: 0
preopens: [{ guest_path: ".", fd: 3 }]
monotonic nanoseconds: 594900
random sample: <Bytes: [...]>wrote target/moon-wasi-example/demo.txt: enabled=true
target/moon-wasi-example
demo.txtmoon install
moon check --deny-warnmoon add Ag108/moon-wasiimport {
"Ag108/moon-wasi/fs" @wasi_fs,
"Ag108/moon-wasi/path",
"Ag108/moon-wasi/sys" @wasi_sys,
"moonbitlang/core/debug",
}
pkgtype(kind: "executable")
supported_targets = "wasm"moon build --target wasm --release examples/atomic-config
wasmtime run --dir .::. \
_build/wasm/release/build/examples/atomic-config/atomic-config.wasm \
target/moon-wasi-example/config.txt "enabled=true"moon build --target wasm --release cmd/main
wasmtime run --dir .::. _build/wasm/release/build/cmd/main/main.wasmmoon build --target wasm --release examples/tree
wasmtime run --dir .::. \
_build/wasm/release/build/examples/tree/tree.wasm target///|
fn main {
try {
let path = @path.GuestPath::new("state/config.txt")
match path.parent() {
Some(parent) => @wasi_fs.create_dir_all(parent)
None => ()
}
@wasi_fs.atomic_write_text(path, "enabled=true\n")
@wasi_sys.print(@wasi_fs.read_text(path))
} catch {
error => {
@wasi_sys.eprint("failed: \{@debug.to_string(error)}\n") catch {
_ => ()
}
@wasi_sys.exit(1)
}
}
}| 库名 | 版本 | 用途 |
|---|---|---|
| peter-jerry-ye/wasi | 0.25.0 | 提供 WASI Preview 1 ABI、类型和 syscall 绑定 |
| 包 | 用途 |
|---|---|
| Ag108/moon-wasi | WasiError、Operation 和通用错误上下文 |
| Ag108/moon-wasi/path | GuestPath 验证、规范化、join、parent 和包含关系 |
| Ag108/moon-wasi/fs | 文件、目录、metadata、遍历、复制、链接和原子写入 |
| Ag108/moon-wasi/sys | 进程信息、stdio、时钟、随机数和 poll |
# 将当前宿主目录映射为 guest 的相对根目录“.”
wasmtime run --dir .::. app.wasm
# 同时传入环境变量
wasmtime run --dir .::. --env APP_MODE=production app.wasmMOON_WASI_WASMTIME=/path/to/wasmtime bash scripts/test-wasi.sh.
├── cmd/main/ # WASI 系统能力诊断程序
├── path/ # 安全 guest 路径
├── fs/ # 文件系统增强层
├── sys/ # 进程与系统能力
├── integration/fs/ # Wasmtime 文件系统集成测试
├── integration/sys/ # Wasmtime 系统能力集成测试
├── examples/tree/ # 确定性目录树示例
├── examples/atomic-config/ # 原子配置写入示例
├── docs/ # 架构与兼容性说明
├── scripts/test-wasi.sh # 本地完整验收入口
├── moon.mod # 模块元数据和依赖
└── README.mbt.mdbash scripts/test-wasi.shmoon info
moon fmt
moon check --deny-warn
moon test --target wasm
moon package --frozen --list| 项目 | 0.1 支持状态 |
|---|---|
| MoonBit wasm 后端 | 支持 |
| WASI Preview 1 / wasi_snapshot_preview1 | 支持 |
| Wasmtime 47 | 已验证 |
| Windows + Wasmtime | 已验证;符号链接受宿主权限影响 |
| MoonBit js、wasm-gc、native | 不支持 |
| WASI Preview 2/3 component model | 不支持 |
Capability-aware WASI Preview 1 utilities for MoonBit
Dependencies