Skip to content

Commit eb39eb6

Browse files
committed
feat: add AOT (Ahead-of-Time) compilation and embedding support
Implements multi-architecture AOT compilation using Wasmtime for faster startup times and better runtime performance. Features: - Individual wasm_precompile targets for 6 architectures: * Linux x64/ARM64 * macOS x64/ARM64 * Windows x64 * Pulley64 (portable interpreter) - wasm_embed_aot target to bundle all AOT artifacts as custom sections - Release workflow updated to build and publish both variants - AOT-embedded variant is ~26x larger (22MB vs 849KB) but provides instant execution with native code Architecture support: - x86_64-unknown-linux-gnu (Linux x64) - aarch64-unknown-linux-gnu (Linux ARM64) - x86_64-apple-darwin (macOS Intel) - aarch64-apple-darwin (macOS Apple Silicon) - x86_64-pc-windows-gnu (Windows x64) - pulley64 (portable/generic target) Release artifacts: - file_ops_component.wasm - Regular WASM component (849KB) - file_ops_component_aot.wasm - AOT-embedded variant (22MB) - Both variants published to OCI registry with Cosign signatures - Separate tags: :version for regular, :version-aot for AOT variant Testing: Successfully built and verified locally on macOS ARM64 Addresses user request to integrate latest rules_wasm_component AOT features for typical targets and generic/portable target (pulley64).
1 parent 092ba7d commit eb39eb6

File tree

3 files changed

+13696
-37
lines changed

3 files changed

+13696
-37
lines changed

.github/workflows/release.yml

Lines changed: 128 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,36 @@ jobs:
5959
file ./file_ops_component.wasm
6060
ls -lh ./file_ops_component.wasm
6161
62+
- name: Build AOT-Embedded WASM Component
63+
run: |
64+
echo "Building AOT-embedded WebAssembly component with multi-architecture support..."
65+
66+
# Build multi-architecture AOT compiled artifacts
67+
echo "Compiling WASM to native code for multiple architectures..."
68+
bazel build //tinygo:file_ops_aot_multi
69+
70+
# Build the component with embedded AOT artifacts
71+
echo "Embedding AOT artifacts as custom sections..."
72+
bazel build //tinygo:file_ops_component_aot
73+
74+
# Copy to a predictable location
75+
cp bazel-bin/tinygo/file_ops_component_aot.wasm ./file_ops_component_aot.wasm
76+
77+
# Verify it's a valid WebAssembly module
78+
file ./file_ops_component_aot.wasm
79+
ls -lh ./file_ops_component_aot.wasm
80+
81+
# Show size comparison
82+
echo "Size comparison:"
83+
echo " Regular WASM: $(ls -lh file_ops_component.wasm | awk '{print $5}')"
84+
echo " AOT-embedded: $(ls -lh file_ops_component_aot.wasm | awk '{print $5}')"
85+
6286
- name: Create SHA256 checksums
6387
run: |
6488
sha256sum file_ops_component.wasm > file_ops_component.wasm.sha256
89+
sha256sum file_ops_component_aot.wasm > file_ops_component_aot.wasm.sha256
6590
cat file_ops_component.wasm.sha256
91+
cat file_ops_component_aot.wasm.sha256
6692
6793
- name: Log in to Container Registry
6894
uses: docker/login-action@v3
@@ -94,27 +120,50 @@ jobs:
94120
# Create OCI artifact references
95121
IMAGE_TAG="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG}"
96122
IMAGE_LATEST="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest"
123+
IMAGE_AOT_TAG="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG}-aot"
124+
IMAGE_AOT_LATEST="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-aot"
97125
98-
# Push WASM file as OCI artifact
126+
# Push regular WASM file as OCI artifact
127+
echo "Publishing regular WASM component..."
99128
oras push "${IMAGE_TAG}" \
100129
--artifact-type application/vnd.wasm.component.layer.v1+wasm \
101130
file_ops_component.wasm:application/vnd.wasm.component.layer.v1+wasm
102131
103132
# Tag as latest
104133
oras tag "${IMAGE_TAG}" latest
105134
106-
echo "Published OCI artifact: ${IMAGE_TAG}"
107-
echo "Published OCI artifact: ${IMAGE_LATEST}"
135+
# Push AOT-embedded WASM file as OCI artifact
136+
echo "Publishing AOT-embedded WASM component..."
137+
oras push "${IMAGE_AOT_TAG}" \
138+
--artifact-type application/vnd.wasm.component.layer.v1+wasm \
139+
file_ops_component_aot.wasm:application/vnd.wasm.component.layer.v1+wasm
140+
141+
# Tag AOT as latest-aot
142+
oras tag "${IMAGE_AOT_TAG}" latest-aot
143+
144+
echo "Published OCI artifacts:"
145+
echo " Regular: ${IMAGE_TAG}"
146+
echo " Regular (latest): ${IMAGE_LATEST}"
147+
echo " AOT-embedded: ${IMAGE_AOT_TAG}"
148+
echo " AOT-embedded (latest): ${IMAGE_AOT_LATEST}"
149+
108150
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
109151
echo "IMAGE_LATEST=${IMAGE_LATEST}" >> $GITHUB_ENV
152+
echo "IMAGE_AOT_TAG=${IMAGE_AOT_TAG}" >> $GITHUB_ENV
153+
echo "IMAGE_AOT_LATEST=${IMAGE_AOT_LATEST}" >> $GITHUB_ENV
110154
111155
- name: Sign OCI Image with Cosign
112156
run: |
113157
# Sign using keyless signing with GitHub OIDC
158+
echo "Signing regular WASM component..."
114159
cosign sign --yes "${IMAGE_TAG}"
115160
cosign sign --yes "${IMAGE_LATEST}"
116161
117-
echo "✅ OCI images signed with Cosign (keyless)"
162+
echo "Signing AOT-embedded WASM component..."
163+
cosign sign --yes "${IMAGE_AOT_TAG}"
164+
cosign sign --yes "${IMAGE_AOT_LATEST}"
165+
166+
echo "✅ All OCI images signed with Cosign (keyless)"
118167
119168
- name: Generate SLSA Provenance
120169
run: |
@@ -152,13 +201,18 @@ jobs:
152201
}
153202
EOF
154203
155-
# Attest the provenance
204+
# Attest the provenance for both regular and AOT variants
156205
cosign attest --yes \
157206
--predicate provenance.json \
158207
--type slsaprovenance \
159208
"${IMAGE_TAG}"
160209
161-
echo "✅ SLSA provenance attestation created"
210+
cosign attest --yes \
211+
--predicate provenance.json \
212+
--type slsaprovenance \
213+
"${IMAGE_AOT_TAG}"
214+
215+
echo "✅ SLSA provenance attestation created for all variants"
162216
163217
- name: Verify Signatures
164218
run: |
@@ -176,32 +230,51 @@ jobs:
176230
files: |
177231
file_ops_component.wasm
178232
file_ops_component.wasm.sha256
233+
file_ops_component_aot.wasm
234+
file_ops_component_aot.wasm.sha256
179235
body: |
180236
## 🎉 Bazel File Operations Component Release
181237
182238
### 📦 What's Included
183239
184-
- **Unsigned WASM Component** (`file_ops_component.wasm`) - Ready to use
185-
- **SHA256 Checksum** - For integrity verification
186-
- **Signed OCI Artifact** - Available at `${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG}`
240+
**Regular WASM Component:**
241+
- `file_ops_component.wasm` - Standard WebAssembly component
242+
- `file_ops_component.wasm.sha256` - SHA256 checksum
243+
- Signed OCI artifact: `${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG}`
244+
245+
**AOT-Embedded WASM Component (NEW):**
246+
- `file_ops_component_aot.wasm` - Component with embedded AOT compiled artifacts
247+
- `file_ops_component_aot.wasm.sha256` - SHA256 checksum
248+
- Signed OCI artifact: `${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG}-aot`
249+
- **Includes native code for:** Linux x64/ARM64, macOS x64/ARM64, Windows x64, Pulley64 (portable)
250+
- **Benefits:** Faster startup times, better runtime performance
251+
- **Trade-off:** Larger file size (~6x) but instant execution
187252
188253
### 🔐 Security Features
189254
190-
- ✅ **OCI Artifact Signing** - Signed with Cosign using GitHub OIDC (keyless)
191-
- ✅ **SLSA Provenance** - Build attestation included
255+
- ✅ **OCI Artifact Signing** - All variants signed with Cosign using GitHub OIDC (keyless)
256+
- ✅ **SLSA Provenance** - Build attestation included for all variants
192257
- ✅ **SHA256 Checksums** - For download verification
193258
194259
### 🚀 Usage
195260
196-
#### Download WASM Component
261+
#### Download WASM Component (Regular)
197262
```bash
198263
# Download and verify checksum
199264
wget https://github.com/${{ github.repository }}/releases/download/${TAG}/file_ops_component.wasm
200265
wget https://github.com/${{ github.repository }}/releases/download/${TAG}/file_ops_component.wasm.sha256
201266
sha256sum -c file_ops_component.wasm.sha256
202267
```
203268
204-
#### Pull Signed OCI Artifact
269+
#### Download WASM Component (AOT-Embedded)
270+
```bash
271+
# Download AOT-embedded variant with native code for multiple platforms
272+
wget https://github.com/${{ github.repository }}/releases/download/${TAG}/file_ops_component_aot.wasm
273+
wget https://github.com/${{ github.repository }}/releases/download/${TAG}/file_ops_component_aot.wasm.sha256
274+
sha256sum -c file_ops_component_aot.wasm.sha256
275+
```
276+
277+
#### Pull Signed OCI Artifact (Regular)
205278
```bash
206279
# Pull the signed OCI artifact with oras
207280
oras pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG}
@@ -220,6 +293,25 @@ jobs:
220293
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG}
221294
```
222295
296+
#### Pull Signed OCI Artifact (AOT-Embedded)
297+
```bash
298+
# Pull the AOT-embedded variant
299+
oras pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG}-aot
300+
301+
# Verify signature
302+
cosign verify \
303+
--certificate-identity-regexp="https://github.com/${{ github.repository }}" \
304+
--certificate-oidc-issuer="https://token.actions.githubusercontent.com" \
305+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG}-aot
306+
307+
# Verify SLSA provenance
308+
cosign verify-attestation \
309+
--type slsaprovenance \
310+
--certificate-identity-regexp="https://github.com/${{ github.repository }}" \
311+
--certificate-oidc-issuer="https://token.actions.githubusercontent.com" \
312+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG}-aot
313+
```
314+
223315
### 📋 Integration with rules_wasm_component
224316
225317
See [INTEGRATION.md](https://github.com/${{ github.repository }}/blob/main/INTEGRATION.md) for details on using this component.
@@ -235,18 +327,35 @@ jobs:
235327

236328
- name: Create Release Summary
237329
run: |
330+
# Determine tag
331+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
332+
TAG="${{ inputs.tag }}"
333+
else
334+
TAG="${{ github.event.release.tag_name }}"
335+
fi
336+
238337
echo "## 🚀 Release Summary" >> $GITHUB_STEP_SUMMARY
239338
echo "" >> $GITHUB_STEP_SUMMARY
240339
echo "### 📦 Published Artifacts" >> $GITHUB_STEP_SUMMARY
241-
echo "- **WASM Component**: \`file_ops_component.wasm\` ($(ls -lh file_ops_component.wasm | awk '{print $5}'))" >> $GITHUB_STEP_SUMMARY
340+
echo "" >> $GITHUB_STEP_SUMMARY
341+
echo "**Regular WASM Component:**" >> $GITHUB_STEP_SUMMARY
342+
echo "- **File**: \`file_ops_component.wasm\` ($(ls -lh file_ops_component.wasm | awk '{print $5}'))" >> $GITHUB_STEP_SUMMARY
242343
echo "- **OCI Artifact**: \`${IMAGE_TAG}\`" >> $GITHUB_STEP_SUMMARY
243344
echo "- **OCI Artifact (latest)**: \`${IMAGE_LATEST}\`" >> $GITHUB_STEP_SUMMARY
244345
echo "" >> $GITHUB_STEP_SUMMARY
346+
echo "**AOT-Embedded WASM Component:**" >> $GITHUB_STEP_SUMMARY
347+
echo "- **File**: \`file_ops_component_aot.wasm\` ($(ls -lh file_ops_component_aot.wasm | awk '{print $5}'))" >> $GITHUB_STEP_SUMMARY
348+
echo "- **OCI Artifact**: \`${IMAGE_AOT_TAG}\`" >> $GITHUB_STEP_SUMMARY
349+
echo "- **OCI Artifact (latest)**: \`${IMAGE_AOT_LATEST}\`" >> $GITHUB_STEP_SUMMARY
350+
echo "- **Platforms**: Linux x64/ARM64, macOS x64/ARM64, Windows x64, Pulley64" >> $GITHUB_STEP_SUMMARY
351+
echo "" >> $GITHUB_STEP_SUMMARY
245352
echo "### 🔐 Security" >> $GITHUB_STEP_SUMMARY
246-
echo "- ✅ OCI artifact signed with Cosign (keyless OIDC)" >> $GITHUB_STEP_SUMMARY
247-
echo "- ✅ SLSA provenance attestation" >> $GITHUB_STEP_SUMMARY
248-
echo "- ✅ SHA256 checksums provided" >> $GITHUB_STEP_SUMMARY
353+
echo "- ✅ All OCI artifacts signed with Cosign (keyless OIDC)" >> $GITHUB_STEP_SUMMARY
354+
echo "- ✅ SLSA provenance attestation for all variants" >> $GITHUB_STEP_SUMMARY
355+
echo "- ✅ SHA256 checksums provided for all files" >> $GITHUB_STEP_SUMMARY
249356
echo "" >> $GITHUB_STEP_SUMMARY
250357
echo "### 🔗 Links" >> $GITHUB_STEP_SUMMARY
251-
echo "- [Download WASM](https://github.com/${{ github.repository }}/releases/tag/${TAG})" >> $GITHUB_STEP_SUMMARY
252-
echo "- [Pull OCI Artifact](${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG})" >> $GITHUB_STEP_SUMMARY
358+
echo "- [Download WASM (Regular)](https://github.com/${{ github.repository }}/releases/tag/${TAG})" >> $GITHUB_STEP_SUMMARY
359+
echo "- [Download WASM (AOT)](https://github.com/${{ github.repository }}/releases/tag/${TAG})" >> $GITHUB_STEP_SUMMARY
360+
echo "- [Pull OCI (Regular)](${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG})" >> $GITHUB_STEP_SUMMARY
361+
echo "- [Pull OCI (AOT)](${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG}-aot)" >> $GITHUB_STEP_SUMMARY

MODULE.bazel.lock

Lines changed: 13477 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tinygo/BUILD.bazel

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ with WIT interface bindings for secure, sandboxed file operations.
66

77
load("@rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
88
load("@rules_wasm_component//go:defs.bzl", "go_wasm_component")
9-
load("@rules_wasm_component//wasm:defs.bzl", "wasm_keygen", "wasm_sign", "wasm_verify")
9+
load("@rules_wasm_component//wasm:defs.bzl", "wasm_keygen", "wasm_sign", "wasm_verify", "wasm_precompile", "wasm_precompile_multi", "wasm_embed_aot")
1010
load("@rules_wasm_component//wkg:oci_signing.bzl", "wasm_component_signed_oci_image")
1111
load("@rules_wasm_component//wkg:defs.bzl", "wkg_publish")
1212

@@ -58,6 +58,96 @@ go_wasm_component(
5858
world = "wasi:cli/command",
5959
)
6060

61+
# AOT (Ahead-of-Time) compilation for individual architectures
62+
# Compiles the WASM component to native .cwasm files for faster startup times
63+
64+
# Linux x86_64
65+
wasm_precompile(
66+
name = "file_ops_aot_linux_x64",
67+
component = ":file_ops_component",
68+
optimization_level = "2",
69+
tags = ["manual"],
70+
target_triple = "x86_64-unknown-linux-gnu",
71+
)
72+
73+
# Linux ARM64
74+
wasm_precompile(
75+
name = "file_ops_aot_linux_arm64",
76+
component = ":file_ops_component",
77+
optimization_level = "2",
78+
tags = ["manual"],
79+
target_triple = "aarch64-unknown-linux-gnu",
80+
)
81+
82+
# macOS x86_64
83+
wasm_precompile(
84+
name = "file_ops_aot_darwin_x64",
85+
component = ":file_ops_component",
86+
optimization_level = "2",
87+
tags = ["manual"],
88+
target_triple = "x86_64-apple-darwin",
89+
)
90+
91+
# macOS ARM64
92+
wasm_precompile(
93+
name = "file_ops_aot_darwin_arm64",
94+
component = ":file_ops_component",
95+
optimization_level = "2",
96+
tags = ["manual"],
97+
target_triple = "aarch64-apple-darwin",
98+
)
99+
100+
# Windows x86_64
101+
wasm_precompile(
102+
name = "file_ops_aot_windows_x64",
103+
component = ":file_ops_component",
104+
optimization_level = "2",
105+
tags = ["manual"],
106+
target_triple = "x86_64-pc-windows-gnu",
107+
)
108+
109+
# Portable interpreter (Pulley64)
110+
wasm_precompile(
111+
name = "file_ops_aot_pulley64",
112+
component = ":file_ops_component",
113+
optimization_level = "2",
114+
tags = ["manual"],
115+
target_triple = "pulley64",
116+
)
117+
118+
# Multi-architecture AOT compilation (builds all platforms in parallel)
119+
wasm_precompile_multi(
120+
name = "file_ops_aot_multi",
121+
component = ":file_ops_component",
122+
optimization_level = "2",
123+
tags = ["manual"],
124+
targets = {
125+
"linux_x64": "x86_64-unknown-linux-gnu",
126+
"linux_arm64": "aarch64-unknown-linux-gnu",
127+
"darwin_x64": "x86_64-apple-darwin",
128+
"darwin_arm64": "aarch64-apple-darwin",
129+
"windows_x64": "x86_64-pc-windows-gnu",
130+
"pulley64": "pulley64",
131+
},
132+
)
133+
134+
# Embed all AOT-compiled artifacts as custom sections in the WASM component
135+
# The resulting component contains both the WASM bytecode and native code for multiple platforms
136+
# Runtime code can extract the appropriate AOT artifact for the current architecture
137+
wasm_embed_aot(
138+
name = "file_ops_component_aot",
139+
aot_artifacts = {
140+
"linux-x64": ":file_ops_aot_linux_x64",
141+
"linux-arm64": ":file_ops_aot_linux_arm64",
142+
"darwin-x64": ":file_ops_aot_darwin_x64",
143+
"darwin-arm64": ":file_ops_aot_darwin_arm64",
144+
"windows-x64": ":file_ops_aot_windows_x64",
145+
"portable": ":file_ops_aot_pulley64",
146+
},
147+
component = ":file_ops_component",
148+
tags = ["manual"],
149+
)
150+
61151
# Test suite
62152
go_test(
63153
name = "file_ops_test",

0 commit comments

Comments
 (0)