Skip to content

Commit f44fd50

Browse files
committed
feat: add comprehensive wasmtime runtime integration example
Implement production-ready example demonstrating WebAssembly component execution with wasmtime runtime for real-world deployment scenarios. Runtime Integration Features: - Complete wasmtime host application with component loading - WASI Preview 2 support for modern WebAssembly components - Interface binding and function call examples - Resource management and lifecycle handling - Error handling and debugging capabilities Example Applications: - Calculator component integration with mathematical operations - Multi-component system coordination and communication - Performance benchmarking and optimization demonstrations - Security sandboxing and capability-based access control Build System Integration: - Bazel-native build rules for wasmtime integration - Cross-platform compatibility for development and deployment - Proper dependency management for wasmtime and WASI libraries - Test infrastructure for validating component behavior This example serves as a reference implementation for deploying WebAssembly components in production environments using wasmtime as the runtime engine, demonstrating the complete toolchain integration from component compilation to runtime execution.
1 parent 74c83a8 commit f44fd50

File tree

8 files changed

+2778
-0
lines changed

8 files changed

+2778
-0
lines changed
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
"""
2+
Enhanced real-world examples demonstrating Wasmtime WebAssembly runtime integration
3+
"""
4+
5+
load("//rust:defs.bzl", "rust_binary", "rust_library")
6+
load("//wasm:defs.bzl", "wasm_component_test")
7+
load("@rules_rust//rust:defs.bzl", "rust_doc", "rust_test")
8+
9+
package(default_visibility = ["//visibility:public"])
10+
11+
# Host application for component execution and testing
12+
rust_binary(
13+
name = "component_runner",
14+
srcs = ["src/bin/component_runner.rs"],
15+
deps = [
16+
":wasmtime_utils",
17+
"@crates//:anyhow",
18+
"@crates//:clap",
19+
"@crates//:serde_json",
20+
"@crates//:tokio",
21+
"@crates//:tracing",
22+
"@crates//:tracing-subscriber",
23+
"@crates//:wasmtime",
24+
"@crates//:wasmtime-wasi",
25+
],
26+
)
27+
28+
# Performance benchmarking tool
29+
rust_binary(
30+
name = "component_benchmark",
31+
srcs = ["src/bin/component_benchmark.rs"],
32+
deps = [
33+
":wasmtime_utils",
34+
"@crates//:anyhow",
35+
"@crates//:clap",
36+
"@crates//:criterion",
37+
"@crates//:serde_json",
38+
"@crates//:tokio",
39+
"@crates//:wasmtime",
40+
"@crates//:wasmtime-wasi",
41+
],
42+
)
43+
44+
# Plugin system demonstrator
45+
rust_binary(
46+
name = "plugin_system",
47+
srcs = ["src/bin/plugin_system.rs"],
48+
deps = [
49+
":wasmtime_utils",
50+
"@crates//:anyhow",
51+
"@crates//:clap",
52+
"@crates//:serde_json",
53+
"@crates//:tokio",
54+
"@crates//:wasmtime",
55+
"@crates//:wasmtime-wasi",
56+
],
57+
)
58+
59+
# Multi-component orchestration
60+
rust_binary(
61+
name = "component_orchestrator",
62+
srcs = ["src/bin/component_orchestrator.rs"],
63+
deps = [
64+
":wasmtime_utils",
65+
"@crates//:anyhow",
66+
"@crates//:async-trait",
67+
"@crates//:clap",
68+
"@crates//:futures",
69+
"@crates//:serde_json",
70+
"@crates//:tokio",
71+
"@crates//:wasmtime",
72+
"@crates//:wasmtime-wasi",
73+
],
74+
)
75+
76+
# Shared utilities library
77+
rust_library(
78+
name = "wasmtime_utils",
79+
srcs = [
80+
"src/lib.rs",
81+
"src/component_loader.rs",
82+
"src/host_functions.rs",
83+
"src/metrics.rs",
84+
"src/runtime_config.rs",
85+
],
86+
deps = [
87+
"@crates//:anyhow",
88+
"@crates//:serde",
89+
"@crates//:serde_json",
90+
"@crates//:tokio",
91+
"@crates//:tracing",
92+
"@crates//:wasmtime",
93+
"@crates//:wasmtime-wasi",
94+
],
95+
)
96+
97+
# Unit tests for utilities
98+
rust_test(
99+
name = "wasmtime_utils_test",
100+
crate = ":wasmtime_utils",
101+
deps = [
102+
"@crates//:tokio-test",
103+
],
104+
)
105+
106+
# Documentation
107+
rust_doc(
108+
name = "wasmtime_docs",
109+
crate = ":wasmtime_utils",
110+
)
111+
112+
# Integration tests that use real components
113+
wasm_component_test(
114+
name = "calculator_runtime_test",
115+
srcs = ["tests/calculator_runtime_test.rs"],
116+
data = [
117+
"//examples/cpp_component/calculator:calculator_component",
118+
"//examples/go_component:calculator_component",
119+
"//examples/basic:basic_component",
120+
],
121+
deps = [
122+
":wasmtime_utils",
123+
"@crates//:anyhow",
124+
"@crates//:tokio-test",
125+
"@crates//:wasmtime",
126+
"@crates//:wasmtime-wasi",
127+
],
128+
)
129+
130+
# Performance test suite
131+
wasm_component_test(
132+
name = "performance_test",
133+
srcs = ["tests/performance_test.rs"],
134+
data = [
135+
"//examples/cpp_component/image_processing:simd_utils",
136+
"//examples/wizer_example:wizer_example_component",
137+
],
138+
deps = [
139+
":wasmtime_utils",
140+
"@crates//:anyhow",
141+
"@crates//:criterion",
142+
"@crates//:tokio-test",
143+
"@crates//:wasmtime",
144+
"@crates//:wasmtime-wasi",
145+
],
146+
)
147+
148+
# Plugin system test
149+
wasm_component_test(
150+
name = "plugin_system_test",
151+
srcs = ["tests/plugin_system_test.rs"],
152+
data = [
153+
"//examples/js_component:calculator_component",
154+
"//examples/basic:basic_component",
155+
],
156+
deps = [
157+
":wasmtime_utils",
158+
"@crates//:anyhow",
159+
"@crates//:tokio-test",
160+
"@crates//:wasmtime",
161+
"@crates//:wasmtime-wasi",
162+
],
163+
)
164+
165+
# Multi-component orchestration test
166+
wasm_component_test(
167+
name = "orchestration_test",
168+
srcs = ["tests/orchestration_test.rs"],
169+
data = [
170+
"//examples/cpp_component/multi_component_system:analytics_service",
171+
"//examples/cpp_component/multi_component_system:auth_service",
172+
"//examples/cpp_component/multi_component_system:user_service",
173+
],
174+
deps = [
175+
":wasmtime_utils",
176+
"@crates//:anyhow",
177+
"@crates//:futures",
178+
"@crates//:tokio-test",
179+
"@crates//:wasmtime",
180+
"@crates//:wasmtime-wasi",
181+
],
182+
)

0 commit comments

Comments
 (0)