@binblink/wasmnest-plugin-sdk-desktop 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -4
- package/README_en.md +1 -1
- package/bin/cli.js +5 -5
- package/bin/manifest-gen.js +4 -0
- package/bin/manifest-validate.js +68 -6
- package/bin/permission-vocabulary.json +2 -2
- package/dev-shell/README.md +6 -5
- package/dev-shell/src/loader.ts +0 -5
- package/dev-shell/src/mock/commands.ts +1 -1
- package/dev-shell/src/mock/domain-context.ts +1 -1
- package/dev-shell/src/shell/types.ts +21 -32
- package/dev-shell/src/styles/shell.css +208 -2
- package/dev-shell/src/styles/style.css +72 -26
- package/dist/index.d.ts +44 -3
- package/dist/index.js +69 -1
- package/dist/types.d.ts +52 -5
- package/go/.gitignore +5 -0
- package/go/README.md +80 -0
- package/go/gen/wasmnest/api-call/host-api-call/empty.s +3 -0
- package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wasm.go +13 -0
- package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wit.go +34 -0
- package/go/gen/wasmnest/app/host-app/empty.s +3 -0
- package/go/gen/wasmnest/app/host-app/host-app.wasm.go +29 -0
- package/go/gen/wasmnest/app/host-app/host-app.wit.go +108 -0
- package/go/gen/wasmnest/auth-center/host-auth-center/abi.go +14 -0
- package/go/gen/wasmnest/auth-center/host-auth-center/empty.s +3 -0
- package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wasm.go +49 -0
- package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wit.go +225 -0
- package/go/gen/wasmnest/clipboard/host-clipboard/abi.go +14 -0
- package/go/gen/wasmnest/clipboard/host-clipboard/empty.s +3 -0
- package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wasm.go +17 -0
- package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wit.go +68 -0
- package/go/gen/wasmnest/connection-registry/host-connection-registry/empty.s +3 -0
- package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wasm.go +13 -0
- package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wit.go +50 -0
- package/go/gen/wasmnest/crypto/host-crypto/abi.go +18 -0
- package/go/gen/wasmnest/crypto/host-crypto/empty.s +3 -0
- package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wasm.go +37 -0
- package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wit.go +139 -0
- package/go/gen/wasmnest/fs-desktop/host-fs-desktop/abi.go +14 -0
- package/go/gen/wasmnest/fs-desktop/host-fs-desktop/empty.s +3 -0
- package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wasm.go +21 -0
- package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wit.go +62 -0
- package/go/gen/wasmnest/http/host-http/abi.go +14 -0
- package/go/gen/wasmnest/http/host-http/empty.s +3 -0
- package/go/gen/wasmnest/http/host-http/host-http.wasm.go +13 -0
- package/go/gen/wasmnest/http/host-http/host-http.wit.go +40 -0
- package/go/gen/wasmnest/http-endpoint/host-http-endpoint/empty.s +3 -0
- package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wasm.go +17 -0
- package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wit.go +69 -0
- package/go/gen/wasmnest/mdns/host-mdns/empty.s +3 -0
- package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wasm.go +29 -0
- package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wit.go +101 -0
- package/go/gen/wasmnest/notify/host-notify/empty.s +3 -0
- package/go/gen/wasmnest/notify/host-notify/host-notify.wasm.go +13 -0
- package/go/gen/wasmnest/notify/host-notify/host-notify.wit.go +64 -0
- package/go/gen/wasmnest/peer/host-peer/abi.go +14 -0
- package/go/gen/wasmnest/peer/host-peer/empty.s +3 -0
- package/go/gen/wasmnest/peer/host-peer/host-peer.wasm.go +85 -0
- package/go/gen/wasmnest/peer/host-peer/host-peer.wit.go +357 -0
- package/go/gen/wasmnest/platform-desktop/host-platform-desktop/empty.s +3 -0
- package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wasm.go +21 -0
- package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wit.go +70 -0
- package/go/gen/wasmnest/plugin/abi-form/abi-form.exports.go +11 -0
- package/go/gen/wasmnest/plugin/abi-form/abi-form.wasm.go +13 -0
- package/go/gen/wasmnest/plugin/abi-form/abi-form.wit.go +7 -0
- package/go/gen/wasmnest/plugin/abi-form/empty.s +3 -0
- package/go/gen/wasmnest/plugin/command/command.exports.go +11 -0
- package/go/gen/wasmnest/plugin/command/command.wasm.go +19 -0
- package/go/gen/wasmnest/plugin/command/command.wit.go +6 -0
- package/go/gen/wasmnest/plugin/command/empty.s +3 -0
- package/go/gen/wasmnest/plugin/events/empty.s +3 -0
- package/go/gen/wasmnest/plugin/events/events.exports.go +52 -0
- package/go/gen/wasmnest/plugin/events/events.wasm.go +74 -0
- package/go/gen/wasmnest/plugin/events/events.wit.go +195 -0
- package/go/gen/wasmnest/plugin/host-bus/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-bus/host-bus.wasm.go +29 -0
- package/go/gen/wasmnest/plugin/host-bus/host-bus.wit.go +94 -0
- package/go/gen/wasmnest/plugin/host-config/abi.go +14 -0
- package/go/gen/wasmnest/plugin/host-config/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-config/host-config.wasm.go +13 -0
- package/go/gen/wasmnest/plugin/host-config/host-config.wit.go +21 -0
- package/go/gen/wasmnest/plugin/host-events/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-events/host-events.wasm.go +9 -0
- package/go/gen/wasmnest/plugin/host-events/host-events.wit.go +27 -0
- package/go/gen/wasmnest/plugin/host-fs/abi.go +14 -0
- package/go/gen/wasmnest/plugin/host-fs/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-fs/host-fs.wasm.go +33 -0
- package/go/gen/wasmnest/plugin/host-fs/host-fs.wit.go +86 -0
- package/go/gen/wasmnest/plugin/host-log/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-log/host-log.wasm.go +25 -0
- package/go/gen/wasmnest/plugin/host-log/host-log.wit.go +65 -0
- package/go/gen/wasmnest/plugin/host-metrics/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wasm.go +13 -0
- package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wit.go +34 -0
- package/go/gen/wasmnest/plugin/host-platform/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-platform/host-platform.wasm.go +21 -0
- package/go/gen/wasmnest/plugin/host-platform/host-platform.wit.go +85 -0
- package/go/gen/wasmnest/plugin/host-plugin-database/abi.go +14 -0
- package/go/gen/wasmnest/plugin/host-plugin-database/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wasm.go +29 -0
- package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wit.go +70 -0
- package/go/gen/wasmnest/plugin/host-storage/abi.go +14 -0
- package/go/gen/wasmnest/plugin/host-storage/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-storage/host-storage.wasm.go +21 -0
- package/go/gen/wasmnest/plugin/host-storage/host-storage.wit.go +44 -0
- package/go/gen/wasmnest/plugin/host-worker/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-worker/host-worker.wasm.go +17 -0
- package/go/gen/wasmnest/plugin/host-worker/host-worker.wit.go +50 -0
- package/go/gen/wasmnest/plugin/lifecycle/empty.s +3 -0
- package/go/gen/wasmnest/plugin/lifecycle/lifecycle.exports.go +32 -0
- package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wasm.go +41 -0
- package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wit.go +9 -0
- package/go/gen/wasmnest/plugin/manifest/empty.s +3 -0
- package/go/gen/wasmnest/plugin/manifest/manifest.exports.go +11 -0
- package/go/gen/wasmnest/plugin/manifest/manifest.wasm.go +13 -0
- package/go/gen/wasmnest/plugin/manifest/manifest.wit.go +6 -0
- package/go/gen/wasmnest/plugin/plugin/plugin.wit.go +4 -0
- package/go/gen/wasmnest/process/host-process/empty.s +3 -0
- package/go/gen/wasmnest/process/host-process/host-process.wasm.go +21 -0
- package/go/gen/wasmnest/process/host-process/host-process.wit.go +56 -0
- package/go/gen/wasmnest/pty/host-pty/abi.go +14 -0
- package/go/gen/wasmnest/pty/host-pty/empty.s +3 -0
- package/go/gen/wasmnest/pty/host-pty/host-pty.wasm.go +33 -0
- package/go/gen/wasmnest/pty/host-pty/host-pty.wit.go +164 -0
- package/go/gen/wasmnest/task/host-task/abi.go +14 -0
- package/go/gen/wasmnest/task/host-task/empty.s +3 -0
- package/go/gen/wasmnest/task/host-task/host-task.wasm.go +29 -0
- package/go/gen/wasmnest/task/host-task/host-task.wit.go +110 -0
- package/go/gen/wasmnest/timer/host-timer/empty.s +3 -0
- package/go/gen/wasmnest/timer/host-timer/host-timer.wasm.go +13 -0
- package/go/gen/wasmnest/timer/host-timer/host-timer.wit.go +25 -0
- package/go/gen/wasmnest/ws/host-websocket/empty.s +3 -0
- package/go/gen/wasmnest/ws/host-websocket/host-websocket.wasm.go +29 -0
- package/go/gen/wasmnest/ws/host-websocket/host-websocket.wit.go +109 -0
- package/go/gen/wasmnest/ws-server/host-websocket-server/empty.s +3 -0
- package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wasm.go +49 -0
- package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wit.go +220 -0
- package/go/go.mod +14 -0
- package/go/go.sum +2 -0
- package/go/sdk/dispatch.go +49 -0
- package/go/sdk/dispatch_test.go +81 -0
- package/go/sdk/entry_native.go +13 -0
- package/go/sdk/entry_wasip2.go +188 -0
- package/go/sdk/host_http_wasip2.go +42 -0
- package/go/sdk/host_wasip2.go +251 -0
- package/go/sdk/plugin.go +103 -0
- package/go/testplugin/index.js +1 -0
- package/go/testplugin/main.go +67 -0
- package/go/testplugin/plugin.json +24 -0
- package/go/tools/assemble-wit.mjs +152 -0
- package/go/tools/gen-bindings.mjs +51 -0
- package/go/wit/core.wit +273 -0
- package/go/wit/deps/api-call/cap-api-call.wit +20 -0
- package/go/wit/deps/app/cap-app.wit +54 -0
- package/go/wit/deps/auth-center/cap-auth-center.wit +124 -0
- package/go/wit/deps/clipboard/clipboard.wit +48 -0
- package/go/wit/deps/clocks/monotonic-clock.wit +45 -0
- package/go/wit/deps/clocks/wall-clock.wit +42 -0
- package/go/wit/deps/clocks/world.wit +6 -0
- package/go/wit/deps/connection-registry/cap-connection-registry.wit +40 -0
- package/go/wit/deps/crypto/cap-crypto.wit +68 -0
- package/go/wit/deps/filesystem/preopens.wit +8 -0
- package/go/wit/deps/filesystem/types.wit +634 -0
- package/go/wit/deps/filesystem/world.wit +6 -0
- package/go/wit/deps/fs-desktop/cap-fs-desktop.wit +29 -0
- package/go/wit/deps/http/http.wit +28 -0
- package/go/wit/deps/http-endpoint/cap-http.wit +44 -0
- package/go/wit/deps/io/error.wit +34 -0
- package/go/wit/deps/io/poll.wit +41 -0
- package/go/wit/deps/io/streams.wit +262 -0
- package/go/wit/deps/io/world.wit +6 -0
- package/go/wit/deps/mdns/mdns.wit +45 -0
- package/go/wit/deps/notify/notify.wit +51 -0
- package/go/wit/deps/peer/peer.wit +126 -0
- package/go/wit/deps/platform-desktop/cap-platform-desktop.wit +38 -0
- package/go/wit/deps/process/cap-process.wit +25 -0
- package/go/wit/deps/pty/pty.wit +80 -0
- package/go/wit/deps/random/insecure-seed.wit +25 -0
- package/go/wit/deps/random/insecure.wit +22 -0
- package/go/wit/deps/random/random.wit +26 -0
- package/go/wit/deps/random/world.wit +7 -0
- package/go/wit/deps/sockets/instance-network.wit +9 -0
- package/go/wit/deps/sockets/ip-name-lookup.wit +51 -0
- package/go/wit/deps/sockets/network.wit +145 -0
- package/go/wit/deps/sockets/tcp-create-socket.wit +27 -0
- package/go/wit/deps/sockets/tcp.wit +353 -0
- package/go/wit/deps/sockets/udp-create-socket.wit +27 -0
- package/go/wit/deps/sockets/udp.wit +266 -0
- package/go/wit/deps/sockets/world.wit +11 -0
- package/go/wit/deps/task/cap-task.wit +56 -0
- package/go/wit/deps/timer/cap-timer.wit +14 -0
- package/go/wit/deps/wasi-cli/command.wit +7 -0
- package/go/wit/deps/wasi-cli/environment.wit +18 -0
- package/go/wit/deps/wasi-cli/exit.wit +4 -0
- package/go/wit/deps/wasi-cli/imports.wit +20 -0
- package/go/wit/deps/wasi-cli/run.wit +4 -0
- package/go/wit/deps/wasi-cli/stdio.wit +17 -0
- package/go/wit/deps/wasi-cli/terminal.wit +49 -0
- package/go/wit/deps/ws/ws.wit +50 -0
- package/go/wit/deps/ws-server/cap-ws.wit +99 -0
- package/go/wit/go-plugin.wit +28 -0
- package/go/wit/plugin-face.wit +355 -0
- package/go/wit/wasmnest.wit +25 -0
- package/package.json +12 -1
- package/src/index.ts +8 -0
- package/src/types.ts +681 -630
- package/src/ui/AppUpdateSection.d.ts +44 -0
- package/src/ui/AppUpdateSection.vue +253 -0
- package/src/ui/NumberField.d.ts +49 -0
- package/src/ui/NumberField.vue +390 -0
- package/src/ui/Select.vue +4 -4
- package/src/update.ts +123 -0
- package/template/README.md +39 -39
- package/tools/componentize/Cargo.lock +30 -1
- package/tools/componentize/Cargo.toml +3 -0
- package/tools/componentize/src/main.rs +197 -94
- package/dev-shell/src/mock/agent-hub-commands.ts +0 -1065
- package/dev-shell/src/mock/agent-hub.ts +0 -42
|
@@ -1,94 +1,197 @@
|
|
|
1
|
-
//! 插件组件化工具(迁移阶段 B 构建链)
|
|
2
|
-
//!
|
|
3
|
-
//! 将 wit-bindgen 产出的 core module(含 `component-type` 自定义段)编码为
|
|
4
|
-
//! Component Model 组件,等价于 `wasm-tools component new`:
|
|
5
|
-
//! - 产物已是组件(魔法字节 `0d 00 01 00`)时直接复制(幂等,支持增量构建)
|
|
6
|
-
//! - 编码失败的输入(无组件元数据)给出明确错误
|
|
7
|
-
//!
|
|
8
|
-
//! 用法:`componentize <input.wasm> -o <output.wasm>`
|
|
9
|
-
//! 插件构建脚本(wasm-apps/*/scripts/build.js)在 cargo build 后调用本工具。
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
1
|
+
//! 插件组件化工具(迁移阶段 B 构建链)
|
|
2
|
+
//!
|
|
3
|
+
//! 将 wit-bindgen 产出的 core module(含 `component-type` 自定义段)编码为
|
|
4
|
+
//! Component Model 组件,等价于 `wasm-tools component new`:
|
|
5
|
+
//! - 产物已是组件(魔法字节 `0d 00 01 00`)时直接复制(幂等,支持增量构建)
|
|
6
|
+
//! - 编码失败的输入(无组件元数据)给出明确错误
|
|
7
|
+
//!
|
|
8
|
+
//! 用法:`componentize <input.wasm> -o <output.wasm>`
|
|
9
|
+
//! 插件构建脚本(wasm-apps/*/scripts/build.js)在 cargo build 后调用本工具。
|
|
10
|
+
//!
|
|
11
|
+
//! 另有只读模式 `componentize --list-packages <component.wasm>`:解码组件,
|
|
12
|
+
//! 输出其 world 实际 import / export 的 `wasmnest:` WIT 包 → 版本 JSON
|
|
13
|
+
//! (ADR 0061 拆包后的发布下限:`compat.witPackages` 必须来自**二进制本身**,
|
|
14
|
+
//! 不能从源码猜)。同一包出现两个版本即失败(组件不可能合法地同时依赖两版)。
|
|
15
|
+
|
|
16
|
+
use std::collections::BTreeMap;
|
|
17
|
+
use std::process::ExitCode;
|
|
18
|
+
|
|
19
|
+
use wit_parser::{WorldItem, WorldKey};
|
|
20
|
+
|
|
21
|
+
fn main() -> ExitCode {
|
|
22
|
+
let args: Vec<String> = std::env::args().collect();
|
|
23
|
+
let mut input: Option<String> = None;
|
|
24
|
+
let mut output: Option<String> = None;
|
|
25
|
+
let mut list_packages: Option<String> = None;
|
|
26
|
+
|
|
27
|
+
let mut i = 1;
|
|
28
|
+
while i < args.len() {
|
|
29
|
+
match args[i].as_str() {
|
|
30
|
+
"--list-packages" => {
|
|
31
|
+
if i + 1 < args.len() {
|
|
32
|
+
list_packages = Some(args[i + 1].clone());
|
|
33
|
+
i += 1;
|
|
34
|
+
} else {
|
|
35
|
+
eprintln!("Missing value after --list-packages");
|
|
36
|
+
return ExitCode::FAILURE;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
"-o" | "--output" => {
|
|
40
|
+
if i + 1 < args.len() {
|
|
41
|
+
output = Some(args[i + 1].clone());
|
|
42
|
+
i += 1;
|
|
43
|
+
} else {
|
|
44
|
+
eprintln!("Missing value after {}", args[i]);
|
|
45
|
+
return ExitCode::FAILURE;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
a if a.starts_with('-') => {
|
|
49
|
+
eprintln!("Unknown option: {}", a);
|
|
50
|
+
return ExitCode::FAILURE;
|
|
51
|
+
}
|
|
52
|
+
a => input = Some(a.to_string()),
|
|
53
|
+
}
|
|
54
|
+
i += 1;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if let Some(path) = list_packages {
|
|
58
|
+
return list_component_packages(&path);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let (Some(input), Some(output)) = (input, output) else {
|
|
62
|
+
eprintln!("Usage: componentize <input.wasm> -o <output.wasm>");
|
|
63
|
+
eprintln!(" componentize --list-packages <component.wasm>");
|
|
64
|
+
return ExitCode::FAILURE;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
let bytes = match std::fs::read(&input) {
|
|
68
|
+
Ok(b) => b,
|
|
69
|
+
Err(e) => {
|
|
70
|
+
eprintln!("Failed to read {}: {}", input, e);
|
|
71
|
+
return ExitCode::FAILURE;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// 幂等:产物已是组件(版本字 0d 00 01 00)则直接复制
|
|
76
|
+
if bytes.len() >= 8 && &bytes[0..4] == b"\0asm" && &bytes[4..8] == [0x0d, 0x00, 0x01, 0x00] {
|
|
77
|
+
return match std::fs::write(&output, &bytes) {
|
|
78
|
+
Ok(()) => {
|
|
79
|
+
println!("componentize: {} already a component, copied to {}", input, output);
|
|
80
|
+
ExitCode::SUCCESS
|
|
81
|
+
}
|
|
82
|
+
Err(e) => {
|
|
83
|
+
eprintln!("Failed to write {}: {}", output, e);
|
|
84
|
+
ExitCode::FAILURE
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let mut encoder = match wit_component::ComponentEncoder::default().module(&bytes) {
|
|
90
|
+
Ok(e) => e,
|
|
91
|
+
Err(e) => {
|
|
92
|
+
eprintln!(
|
|
93
|
+
"componentize: {} is not a componentizable core module (missing WIT metadata): {}",
|
|
94
|
+
input, e
|
|
95
|
+
);
|
|
96
|
+
return ExitCode::FAILURE;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
let encoded = match encoder.encode() {
|
|
100
|
+
Ok(b) => b,
|
|
101
|
+
Err(e) => {
|
|
102
|
+
eprintln!("componentize: encode {} failed: {}", input, e);
|
|
103
|
+
return ExitCode::FAILURE;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
match std::fs::write(&output, &encoded) {
|
|
108
|
+
Ok(()) => {
|
|
109
|
+
println!("componentize: {} -> {} ({} bytes)", input, output, encoded.len());
|
|
110
|
+
ExitCode::SUCCESS
|
|
111
|
+
}
|
|
112
|
+
Err(e) => {
|
|
113
|
+
eprintln!("Failed to write {}: {}", output, e);
|
|
114
|
+
ExitCode::FAILURE
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/// `--list-packages`:列出组件 world 实际 import/export 的 `wasmnest:` 包 → 版本
|
|
120
|
+
///
|
|
121
|
+
/// 只保留 `wasmnest:` 前缀(WASI 包由宿主运行时负责,不进本门禁)。输出为单行
|
|
122
|
+
/// JSON(键排序),供构建脚本写入 `compat.witPackages`。
|
|
123
|
+
fn list_component_packages(path: &str) -> ExitCode {
|
|
124
|
+
let bytes = match std::fs::read(path) {
|
|
125
|
+
Ok(b) => b,
|
|
126
|
+
Err(e) => {
|
|
127
|
+
eprintln!("Failed to read {}: {}", path, e);
|
|
128
|
+
return ExitCode::FAILURE;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
let decoded = match wit_component::decode(&bytes) {
|
|
132
|
+
Ok(d) => d,
|
|
133
|
+
Err(e) => {
|
|
134
|
+
eprintln!("list-packages: decode {} failed: {}", path, e);
|
|
135
|
+
return ExitCode::FAILURE;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
let (resolve, world_id) = match decoded {
|
|
139
|
+
wit_component::DecodedWasm::Component(resolve, world) => (resolve, world),
|
|
140
|
+
wit_component::DecodedWasm::WitPackage(..) => {
|
|
141
|
+
eprintln!(
|
|
142
|
+
"list-packages: {} 是 WIT 包而不是组件(需要构建后的 component)",
|
|
143
|
+
path
|
|
144
|
+
);
|
|
145
|
+
return ExitCode::FAILURE;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
let world = &resolve.worlds[world_id];
|
|
149
|
+
let mut packages: BTreeMap<String, String> = BTreeMap::new();
|
|
150
|
+
let push = |iface_id: wit_parser::InterfaceId, packages: &mut BTreeMap<String, String>| {
|
|
151
|
+
let iface = &resolve.interfaces[iface_id];
|
|
152
|
+
let Some(pkg_id) = iface.package else { return };
|
|
153
|
+
let pkg = &resolve.packages[pkg_id].name;
|
|
154
|
+
if pkg.namespace != "wasmnest" {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
let name = format!("{}:{}", pkg.namespace, pkg.name);
|
|
158
|
+
let version = pkg
|
|
159
|
+
.version
|
|
160
|
+
.as_ref()
|
|
161
|
+
.map(|v| v.to_string())
|
|
162
|
+
.unwrap_or_default();
|
|
163
|
+
match packages.get(&name) {
|
|
164
|
+
Some(prev) if *prev != version => {
|
|
165
|
+
eprintln!(
|
|
166
|
+
"list-packages: 包 {} 在组件里出现两个版本({} 与 {})",
|
|
167
|
+
name, prev, version
|
|
168
|
+
);
|
|
169
|
+
// 交给外层用 Err 语义处理:这里直接 panic 不如返回标记
|
|
170
|
+
packages.insert(name.clone(), format!("{}!{}", prev, version));
|
|
171
|
+
}
|
|
172
|
+
Some(_) => {}
|
|
173
|
+
None => {
|
|
174
|
+
packages.insert(name, version);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
for (key, item) in world.imports.iter().chain(world.exports.iter()) {
|
|
179
|
+
if let WorldKey::Interface(id) = key {
|
|
180
|
+
push(*id, &mut packages);
|
|
181
|
+
}
|
|
182
|
+
if let WorldItem::Interface { id, .. } = item {
|
|
183
|
+
push(*id, &mut packages);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if let Some((name, _)) = packages.iter().find(|(_, v)| v.contains('!')) {
|
|
187
|
+
eprintln!("list-packages: 包版本冲突 {}", name);
|
|
188
|
+
return ExitCode::FAILURE;
|
|
189
|
+
}
|
|
190
|
+
let body = packages
|
|
191
|
+
.iter()
|
|
192
|
+
.map(|(k, v)| format!("\"{}\":\"{}\"", k, v))
|
|
193
|
+
.collect::<Vec<_>>()
|
|
194
|
+
.join(",");
|
|
195
|
+
println!("{{{}}}", body);
|
|
196
|
+
ExitCode::SUCCESS
|
|
197
|
+
}
|