Skip to content

Commit 334c776

Browse files
committed
bazel-registry: Add wamr@2.4.4.envoy
Signed-off-by: Ryan Northey <ryan@synca.io>
1 parent b914787 commit 334c776

File tree

8 files changed

+455
-0
lines changed

8 files changed

+455
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Example Usage
2+
3+
This directory contains example code showing how to use the WAMR bzlmod module.
4+
5+
## Basic Example
6+
7+
```c
8+
#include "wasm_export.h"
9+
#include <stdio.h>
10+
#include <string.h>
11+
12+
int main() {
13+
// Initialize WAMR runtime
14+
if (!wasm_runtime_init()) {
15+
printf("Failed to initialize WAMR runtime\n");
16+
return 1;
17+
}
18+
19+
printf("WAMR runtime initialized successfully\n");
20+
21+
// Your WASM loading and execution code here...
22+
23+
// Cleanup
24+
wasm_runtime_destroy();
25+
26+
return 0;
27+
}
28+
```
29+
30+
## BUILD.bazel
31+
32+
```starlark
33+
cc_binary(
34+
name = "wasm_runner",
35+
srcs = ["main.c"],
36+
deps = ["@wamr//:iwasm"],
37+
)
38+
```
39+
40+
## MODULE.bazel
41+
42+
```starlark
43+
module(name = "my_wasm_app", version = "1.0.0")
44+
45+
bazel_dep(name = "wamr", version = "2.4.4.envoy")
46+
```
47+
48+
## Build and Run
49+
50+
```bash
51+
# Default build (production settings)
52+
bazel build //:wasm_runner
53+
54+
# Development build with debugging
55+
bazel build //:wasm_runner \
56+
--@wamr//bazel:dump_call_stack=true \
57+
--@wamr//bazel:custom_name_section=true
58+
59+
# Build with SIMD support
60+
bazel build //:wasm_runner --@wamr//bazel:simd=true
61+
```
62+
63+
## Integration with proxy-wasm-cpp-host
64+
65+
Once this module is in the BCR, proxy-wasm-cpp-host can use it:
66+
67+
```starlark
68+
# In proxy-wasm-cpp-host MODULE.bazel
69+
bazel_dep(name = "wamr", version = "2.4.4.envoy")
70+
71+
# In BUILD file
72+
cc_library(
73+
name = "wamr",
74+
deps = ["@wamr//:iwasm"],
75+
# ... rest of the configuration
76+
)
77+
```
78+
79+
This replaces the current complex cmake-based foreign_cc approach with a simple bzlmod dependency.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module(
2+
name = "wamr",
3+
version = "2.4.4.envoy",
4+
compatibility_level = 1,
5+
)
6+
7+
bazel_dep(name = "bazel_skylib", version = "1.7.0")
8+
bazel_dep(name = "rules_cc", version = "0.1.5")
9+
bazel_dep(name = "platforms", version = "1.0.0")
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# WAMR (WebAssembly Micro Runtime) Bazel Module
2+
3+
This bzlmod module provides a pure `rules_cc` build for WAMR (WebAssembly Micro Runtime) version 2.4.4.
4+
5+
## Features
6+
7+
- **Pure rules_cc build**: No cmake or foreign_cc required
8+
- **Configurable features**: Control runtime behavior via build flags
9+
- **Cross-platform**: Supports Linux, macOS, with architecture-specific optimizations
10+
- **Production defaults**: Minimal footprint with optional debug features
11+
12+
## Usage
13+
14+
Add to your `MODULE.bazel`:
15+
16+
```starlark
17+
bazel_dep(name = "wamr", version = "2.4.4.envoy")
18+
```
19+
20+
Use in your BUILD file:
21+
22+
```starlark
23+
cc_binary(
24+
name = "my_wasm_runner",
25+
srcs = ["main.c"],
26+
deps = ["@wamr//:iwasm"],
27+
)
28+
```
29+
30+
## Available Targets
31+
32+
- `@wamr//:iwasm` - Main WAMR library
33+
- `@wamr//:wamr_lib` - Alias for compatibility
34+
35+
## Configuration Flags
36+
37+
### Runtime Mode
38+
- `--@wamr//bazel:fast_interp=true` (default: True)
39+
Enable fast interpreter for better performance
40+
41+
### Debug Features (default: False)
42+
- `--@wamr//bazel:dump_call_stack=true`
43+
Enable call stack dumping for debugging
44+
- `--@wamr//bazel:custom_name_section=true`
45+
Enable custom name section support
46+
- `--@wamr//bazel:load_custom_section=true`
47+
Enable loading custom sections
48+
49+
### WebAssembly Features
50+
- `--@wamr//bazel:bulk_memory=true` (default: True)
51+
Enable bulk memory operations
52+
- `--@wamr//bazel:ref_types=true` (default: True)
53+
Enable reference types
54+
- `--@wamr//bazel:tail_call=true` (default: True)
55+
Enable tail call optimization
56+
- `--@wamr//bazel:simd=true` (default: False)
57+
Enable SIMD support
58+
59+
## Examples
60+
61+
### Development build with debugging:
62+
```bash
63+
bazel build //your:target \
64+
--@wamr//bazel:dump_call_stack=true \
65+
--@wamr//bazel:custom_name_section=true
66+
```
67+
68+
### Production build (defaults are already optimized):
69+
```bash
70+
bazel build //your:target
71+
```
72+
73+
### Enable SIMD support:
74+
```bash
75+
bazel build //your:target --@wamr//bazel:simd=true
76+
```
77+
78+
## Platform Support
79+
80+
- **Linux**: x86_64, aarch64
81+
- **macOS**: x86_64, aarch64 (Apple Silicon)
82+
- **Architecture fallback**: Uses general C implementation for unsupported architectures
83+
84+
## Disabled Features
85+
86+
This module intentionally disables:
87+
- AOT (Ahead-of-Time compilation)
88+
- JIT (Just-in-Time compilation)
89+
- WASI libc (both builtin and full)
90+
- Multi-module support
91+
92+
These features are not needed for basic WebAssembly interpretation and keeping them disabled reduces binary size and complexity.
93+
94+
## Version
95+
96+
WAMR 2.4.4 (WAMR-2.4.4 tag from upstream)
97+
98+
## License
99+
100+
Apache 2.0 with LLVM exception (same as upstream WAMR)
101+
102+
## References
103+
104+
- Upstream: https://github.com/bytecodealliance/wasm-micro-runtime
105+
- WAMR Documentation: https://wamr.gitbook.io/
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_library")
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
licenses(["notice"]) # Apache 2.0 with LLVM exception
6+
7+
cc_library(
8+
name = "iwasm",
9+
srcs = [
10+
# Memory allocator sources (EMS only - tlsf has been removed from upstream)
11+
"core/shared/mem-alloc/ems/ems_alloc.c",
12+
"core/shared/mem-alloc/ems/ems_gc.c",
13+
"core/shared/mem-alloc/ems/ems_hmu.c",
14+
"core/shared/mem-alloc/ems/ems_kfc.c",
15+
"core/shared/mem-alloc/mem_alloc.c",
16+
# Shared utils
17+
"core/shared/utils/bh_assert.c",
18+
"core/shared/utils/bh_bitmap.c",
19+
"core/shared/utils/bh_common.c",
20+
"core/shared/utils/bh_hashmap.c",
21+
"core/shared/utils/bh_leb128.c",
22+
"core/shared/utils/bh_list.c",
23+
"core/shared/utils/bh_log.c",
24+
"core/shared/utils/bh_queue.c",
25+
"core/shared/utils/bh_vector.c",
26+
"core/shared/utils/runtime_timer.c",
27+
# IWASM common sources
28+
"core/iwasm/common/wasm_blocking_op.c",
29+
"core/iwasm/common/wasm_c_api.c",
30+
"core/iwasm/common/wasm_exec_env.c",
31+
"core/iwasm/common/wasm_loader_common.c",
32+
"core/iwasm/common/wasm_memory.c",
33+
"core/iwasm/common/wasm_native.c",
34+
"core/iwasm/common/wasm_runtime_common.c",
35+
"core/iwasm/common/wasm_shared_memory.c",
36+
# Interpreter sources
37+
"core/iwasm/interpreter/wasm_loader.c",
38+
"core/iwasm/interpreter/wasm_runtime.c",
39+
] + select({
40+
# Fast vs classic interpreter
41+
"//bazel:fast_interp_enabled": ["core/iwasm/interpreter/wasm_interp_fast.c"],
42+
"//conditions:default": ["core/iwasm/interpreter/wasm_interp_classic.c"],
43+
}) + select({
44+
# Platform-specific sources
45+
"@platforms//os:linux": [
46+
"core/shared/platform/linux/platform_init.c",
47+
"core/shared/platform/common/posix/posix_malloc.c",
48+
"core/shared/platform/common/posix/posix_memmap.c",
49+
"core/shared/platform/common/posix/posix_thread.c",
50+
"core/shared/platform/common/posix/posix_time.c",
51+
"core/shared/platform/common/posix/posix_sleep.c",
52+
"core/shared/platform/common/posix/posix_blocking_op.c",
53+
],
54+
"@platforms//os:macos": [
55+
"core/shared/platform/darwin/platform_init.c",
56+
"core/shared/platform/common/posix/posix_malloc.c",
57+
"core/shared/platform/common/posix/posix_memmap.c",
58+
"core/shared/platform/common/posix/posix_thread.c",
59+
"core/shared/platform/common/posix/posix_time.c",
60+
"core/shared/platform/common/posix/posix_sleep.c",
61+
"core/shared/platform/common/posix/posix_blocking_op.c",
62+
# macOS doesn't have mremap, use fallback
63+
"core/shared/platform/common/memory/mremap.c",
64+
],
65+
}) + select({
66+
# Architecture-specific native invoke sources
67+
"//bazel:x86_64_simd": ["core/iwasm/common/arch/invokeNative_em64_simd.s"],
68+
"//bazel:x86_64_no_simd": ["core/iwasm/common/arch/invokeNative_em64.s"],
69+
"//bazel:aarch64_simd": ["core/iwasm/common/arch/invokeNative_aarch64_simd.s"],
70+
"//bazel:aarch64_no_simd": ["core/iwasm/common/arch/invokeNative_aarch64.s"],
71+
# Fallback to general C implementation for other architectures
72+
"//conditions:default": ["core/iwasm/common/arch/invokeNative_general.c"],
73+
}),
74+
hdrs = glob([
75+
"core/*.h", # For version.h and config.h
76+
"core/iwasm/include/*.h",
77+
"core/shared/platform/include/*.h",
78+
"core/shared/platform/linux/*.h",
79+
"core/shared/platform/darwin/*.h",
80+
"core/shared/platform/common/posix/*.h",
81+
"core/shared/mem-alloc/*.h",
82+
"core/shared/mem-alloc/ems/*.h",
83+
"core/shared/utils/*.h",
84+
"core/iwasm/common/*.h",
85+
"core/iwasm/interpreter/*.h",
86+
"core/iwasm/aot/*.h",
87+
"core/iwasm/compilation/*.h",
88+
]),
89+
copts = select({
90+
"@platforms//os:windows": [],
91+
"//conditions:default": [
92+
"-std=gnu99",
93+
"-Wno-unused-parameter",
94+
"-Wno-pedantic",
95+
"-Wno-unused-command-line-argument",
96+
],
97+
}),
98+
includes = [
99+
".", # Root for all relative paths
100+
"core",
101+
"core/iwasm", # For relative paths like ../aot/ from common/
102+
"core/iwasm/include",
103+
"core/shared/platform/include",
104+
"core/shared/mem-alloc",
105+
"core/shared/mem-alloc/ems",
106+
"core/shared/utils",
107+
"core/iwasm/common",
108+
"core/iwasm/interpreter",
109+
"core/iwasm/aot",
110+
"core/iwasm/compilation",
111+
] + select({
112+
"@platforms//os:linux": ["core/shared/platform/linux"],
113+
"@platforms//os:macos": ["core/shared/platform/darwin"],
114+
"//conditions:default": [],
115+
}),
116+
linkopts = select({
117+
"@platforms//os:linux": ["-lpthread", "-lm"],
118+
"@platforms//os:macos": ["-lpthread"],
119+
"//conditions:default": [],
120+
}),
121+
local_defines = [
122+
# Core defines
123+
"WASM_ENABLE_INTERP=1",
124+
"BH_MALLOC=wasm_runtime_malloc",
125+
"BH_FREE=wasm_runtime_free",
126+
# Use EMS allocator (tlsf has been removed from upstream WAMR)
127+
"MEM_ALLOCATOR_EMS=0",
128+
"MEM_ALLOCATOR_TLSF=1",
129+
"DEFAULT_MEM_ALLOCATOR=MEM_ALLOCATOR_EMS",
130+
# Disable features we don't need
131+
"WASM_ENABLE_LIBC_WASI=0",
132+
"WASM_ENABLE_LIBC_BUILTIN=0",
133+
"WASM_ENABLE_MULTI_MODULE=0",
134+
"WASM_ENABLE_AOT=0",
135+
"WASM_ENABLE_JIT=0",
136+
] + select({
137+
"@platforms//os:linux": [
138+
"BH_PLATFORM_LINUX",
139+
"_GNU_SOURCE", # Required for mremap and MREMAP_MAYMOVE
140+
"WASM_HAVE_MREMAP=1", # Linux has native mremap syscall
141+
],
142+
"@platforms//os:macos": ["BH_PLATFORM_DARWIN"],
143+
"//conditions:default": [],
144+
}) + select({
145+
"//bazel:fast_interp_enabled": ["WASM_ENABLE_FAST_INTERP=1"],
146+
"//conditions:default": ["WASM_ENABLE_FAST_INTERP=0"],
147+
}) + select({
148+
"//bazel:dump_call_stack_enabled": ["WASM_ENABLE_DUMP_CALL_STACK=1"],
149+
"//conditions:default": ["WASM_ENABLE_DUMP_CALL_STACK=0"],
150+
}) + select({
151+
"//bazel:custom_name_section_enabled": ["WASM_ENABLE_CUSTOM_NAME_SECTION=1"],
152+
"//conditions:default": ["WASM_ENABLE_CUSTOM_NAME_SECTION=0"],
153+
}) + select({
154+
"//bazel:load_custom_section_enabled": ["WASM_ENABLE_LOAD_CUSTOM_SECTION=1"],
155+
"//conditions:default": ["WASM_ENABLE_LOAD_CUSTOM_SECTION=0"],
156+
}) + select({
157+
"//bazel:bulk_memory_enabled": ["WASM_ENABLE_BULK_MEMORY=1"],
158+
"//conditions:default": ["WASM_ENABLE_BULK_MEMORY=0"],
159+
}) + select({
160+
"//bazel:ref_types_enabled": ["WASM_ENABLE_REF_TYPES=1"],
161+
"//conditions:default": ["WASM_ENABLE_REF_TYPES=0"],
162+
}) + select({
163+
"//bazel:tail_call_enabled": ["WASM_ENABLE_TAIL_CALL=1"],
164+
"//conditions:default": ["WASM_ENABLE_TAIL_CALL=0"],
165+
}) + select({
166+
"//bazel:simd_enabled": ["WASM_ENABLE_SIMD=1"],
167+
"//conditions:default": ["WASM_ENABLE_SIMD=0"],
168+
}),
169+
)
170+
171+
# Alias for compatibility
172+
alias(
173+
name = "wamr_lib",
174+
actual = ":iwasm",
175+
)

0 commit comments

Comments
 (0)