Skip to content

Commit 3f45df4

Browse files
committed
feat: implement hermetic Rust CLI for AOT embedding
Replace Python-based AOT embedding with native Rust implementation using wasm-encoder and wasmparser crates. This eliminates external Python dependency while maintaining full functionality for embedding and extracting AOT-compiled artifacts as WebAssembly custom sections. Key changes: - Add tools/wasm_embed_aot: Hermetic Rust CLI with embed/extract/list commands - Add wasm/wasm_embed_aot.bzl: Bazel rules for AOT artifact manipulation - Add examples/aot_embed_test: Test example demonstrating functionality - Update MODULE.bazel: Add wasm_embed_aot_crates for tool dependencies - Update wasm/defs.bzl: Export new AOT embedding rules The Rust implementation provides cross-platform compatibility and follows existing repository patterns for hermetic tool building with Bazel.
1 parent 5164023 commit 3f45df4

File tree

10 files changed

+1059
-2
lines changed

10 files changed

+1059
-2
lines changed

MODULE.bazel

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ module(
88

99
# Dependencies for WebAssembly tooling
1010
bazel_dep(name = "rules_rust", version = "0.65.0")
11-
1211
bazel_dep(name = "bazel_skylib", version = "1.8.1")
1312
bazel_dep(name = "platforms", version = "1.0.0")
1413
bazel_dep(name = "rules_cc", version = "0.2.4")
@@ -234,7 +233,19 @@ crate.from_cargo(
234233
"x86_64-pc-windows-msvc",
235234
],
236235
)
237-
use_repo(crate, "crates", "ssh_keygen_crates", "wasmsign2_crates", "wizer_crates")
236+
crate.from_cargo(
237+
name = "wasm_embed_aot_crates",
238+
cargo_lockfile = "//tools/wasm_embed_aot:Cargo.lock",
239+
manifests = ["//tools/wasm_embed_aot:Cargo.toml"],
240+
supported_platform_triples = [
241+
"x86_64-unknown-linux-gnu",
242+
"aarch64-unknown-linux-gnu",
243+
"x86_64-apple-darwin",
244+
"aarch64-apple-darwin",
245+
"x86_64-pc-windows-msvc",
246+
],
247+
)
248+
use_repo(crate, "crates", "ssh_keygen_crates", "wasm_embed_aot_crates", "wasmsign2_crates", "wizer_crates")
238249

239250
# Modernized WASM tool repositories using git_repository + rules_rust
240251
wasm_tool_repos = use_extension("//toolchains:extensions.bzl", "wasm_tool_repositories")
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
"""Test case for AOT embedding functionality"""
2+
3+
load("//wasm:defs.bzl", "wasm_precompile", "wasm_embed_aot", "wasm_extract_aot")
4+
5+
package(default_visibility = ["//visibility:public"])
6+
7+
# Create debug AOT artifacts with debug info (for comparison)
8+
wasm_precompile(
9+
name = "hello_linux_x64_debug",
10+
component = "//examples/basic:hello_component",
11+
target_triple = "x86_64-unknown-linux-gnu",
12+
optimization_level = "2",
13+
debug_info = True,
14+
)
15+
16+
wasm_precompile(
17+
name = "hello_linux_arm64_debug",
18+
component = "//examples/basic:hello_component",
19+
target_triple = "aarch64-unknown-linux-gnu",
20+
optimization_level = "2",
21+
debug_info = True,
22+
)
23+
24+
wasm_precompile(
25+
name = "hello_portable_debug",
26+
component = "//examples/basic:hello_component",
27+
target_triple = "pulley64",
28+
optimization_level = "2",
29+
debug_info = True,
30+
)
31+
32+
# Create production AOT artifacts for embedding (default - no debug info)
33+
wasm_precompile(
34+
name = "hello_linux_x64",
35+
component = "//examples/basic:hello_component",
36+
target_triple = "x86_64-unknown-linux-gnu",
37+
optimization_level = "2",
38+
)
39+
40+
wasm_precompile(
41+
name = "hello_linux_arm64",
42+
component = "//examples/basic:hello_component",
43+
target_triple = "aarch64-unknown-linux-gnu",
44+
optimization_level = "2",
45+
)
46+
47+
wasm_precompile(
48+
name = "hello_portable",
49+
component = "//examples/basic:hello_component",
50+
target_triple = "pulley64",
51+
optimization_level = "2",
52+
)
53+
54+
# Test embedding stripped AOT artifacts (production)
55+
wasm_embed_aot(
56+
name = "hello_with_embedded_aot",
57+
component = "//examples/basic:hello_component",
58+
aot_artifacts = {
59+
"linux_x64": ":hello_linux_x64",
60+
"linux_arm64": ":hello_linux_arm64",
61+
"portable": ":hello_portable",
62+
},
63+
)
64+
65+
# Test embedding debug AOT artifacts (with debug info)
66+
wasm_embed_aot(
67+
name = "hello_with_embedded_aot_debug",
68+
component = "//examples/basic:hello_component",
69+
aot_artifacts = {
70+
"linux_x64": ":hello_linux_x64_debug",
71+
"linux_arm64": ":hello_linux_arm64_debug",
72+
"portable": ":hello_portable_debug",
73+
},
74+
)
75+
76+
# Test extraction
77+
wasm_extract_aot(
78+
name = "extracted_linux_x64",
79+
component = ":hello_with_embedded_aot",
80+
target_name = "linux_x64",
81+
)
82+
83+
wasm_extract_aot(
84+
name = "extracted_portable",
85+
component = ":hello_with_embedded_aot",
86+
target_name = "portable",
87+
)

tools/wasm_embed_aot/BUILD.bazel

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""WebAssembly AOT embedding tool as a hermetic CLI"""
2+
3+
load("@rules_rust//rust:defs.bzl", "rust_binary")
4+
5+
package(default_visibility = ["//visibility:public"])
6+
7+
# Hermetic Rust CLI tool for AOT embedding and extraction
8+
rust_binary(
9+
name = "wasm_embed_aot",
10+
srcs = ["src/main.rs"],
11+
edition = "2021",
12+
deps = [
13+
"@wasm_embed_aot_crates//:anyhow",
14+
"@wasm_embed_aot_crates//:clap",
15+
"@wasm_embed_aot_crates//:wasm-encoder",
16+
"@wasm_embed_aot_crates//:wasmparser",
17+
],
18+
)

0 commit comments

Comments
 (0)