Skip to content

Commit d9a9371

Browse files
authored
Introduce multi-engine franken-build. (#258)
This is intended for benchmarks and development, not for production. Fixes #139. Signed-off-by: Piotr Sikora <[email protected]>
1 parent af6391b commit d9a9371

File tree

7 files changed

+118
-8
lines changed

7 files changed

+118
-8
lines changed

BUILD

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,54 @@ cc_library(
127127
],
128128
)
129129

130-
cc_library(
131-
name = "wasmtime_lib",
130+
genrule(
131+
name = "prefixed_wasmtime_sources",
132132
srcs = [
133-
"src/common/types.h",
134133
"src/wasmtime/types.h",
135134
"src/wasmtime/wasmtime.cc",
136135
],
136+
outs = [
137+
"src/wasmtime/prefixed_types.h",
138+
"src/wasmtime/prefixed_wasmtime.cc",
139+
],
140+
cmd = """
141+
for file in $(SRCS); do
142+
sed -e 's/wasm_/wasmtime_wasm_/g' \
143+
-e 's/wasmtime\\/types.h/wasmtime\\/prefixed_types.h/g' \
144+
$$file >$(@D)/$$(dirname $$file)/prefixed_$$(basename $$file)
145+
done
146+
""",
147+
)
148+
149+
cc_library(
150+
name = "wasmtime_lib",
151+
srcs = [
152+
"src/common/types.h",
153+
] + select({
154+
"@proxy_wasm_cpp_host//bazel:multiengine": [
155+
"src/wasmtime/prefixed_types.h",
156+
"src/wasmtime/prefixed_wasmtime.cc",
157+
],
158+
"//conditions:default": [
159+
"src/wasmtime/types.h",
160+
"src/wasmtime/wasmtime.cc",
161+
],
162+
}),
137163
hdrs = ["include/proxy-wasm/wasmtime.h"],
138164
defines = [
139165
"PROXY_WASM_HAS_RUNTIME_WASMTIME",
140166
"PROXY_WASM_HOST_ENGINE_WASMTIME",
141167
],
142168
deps = [
143169
":wasm_vm_headers",
144-
"//external:wasmtime",
145-
],
170+
] + select({
171+
"@proxy_wasm_cpp_host//bazel:multiengine": [
172+
"//external:prefixed_wasmtime",
173+
],
174+
"//conditions:default": [
175+
"//external:wasmtime",
176+
],
177+
}),
146178
)
147179

148180
cc_library(

bazel/BUILD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ config_setting(
2020
values = {"define": "engine=wavm"},
2121
)
2222

23+
config_setting(
24+
name = "multiengine",
25+
values = {"define": "engine=multi"},
26+
)
27+
2328
config_setting(
2429
name = "requested_crypto_system",
2530
values = {"define": "crypto=system"},

bazel/external/v8.patch

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# Disable pointer compression (limits the maximum number of WasmVMs).
1+
# 1. Disable pointer compression (limits the maximum number of WasmVMs).
2+
# 2. Don't expose Wasm C API (only Wasm C++ API).
23

34
diff --git a/BUILD.bazel b/BUILD.bazel
4-
index 1cc0121e60..4947c1dba2 100644
5+
index 5fb10d3940..a19930d36e 100644
56
--- a/BUILD.bazel
67
+++ b/BUILD.bazel
78
@@ -161,7 +161,7 @@ v8_int(
@@ -13,3 +14,22 @@ index 1cc0121e60..4947c1dba2 100644
1314
)
1415

1516
# Default setting for v8_enable_pointer_compression.
17+
diff --git a/src/wasm/c-api.cc b/src/wasm/c-api.cc
18+
index ce3f569fd5..dc8a4c4f6a 100644
19+
--- a/src/wasm/c-api.cc
20+
+++ b/src/wasm/c-api.cc
21+
@@ -2238,6 +2238,8 @@ auto Instance::exports() const -> ownvec<Extern> {
22+
23+
} // namespace wasm
24+
25+
+#if 0
26+
+
27+
// BEGIN FILE wasm-c.cc
28+
29+
extern "C" {
30+
@@ -3257,3 +3259,5 @@ wasm_instance_t* wasm_frame_instance(const wasm_frame_t* frame) {
31+
#undef WASM_DEFINE_SHARABLE_REF
32+
33+
} // extern "C"
34+
+
35+
+#endif

bazel/external/wasm-c-api.BUILD

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,48 @@ cc_library(
1414
"@com_github_bytecodealliance_wasmtime//:rust_c_api",
1515
],
1616
)
17+
18+
genrule(
19+
name = "prefixed_wasmtime_c_api_headers",
20+
srcs = [
21+
"include/wasm.h",
22+
],
23+
outs = [
24+
"wasmtime/include/wasm.h",
25+
],
26+
cmd = """
27+
sed -e 's/\\ wasm_/\\ wasmtime_wasm_/g' \
28+
-e 's/\\*wasm_/\\*wasmtime_wasm_/g' \
29+
-e 's/(wasm_/(wasmtime_wasm_/g' \
30+
$(<) >$@
31+
""",
32+
)
33+
34+
genrule(
35+
name = "prefixed_wasmtime_c_api_lib",
36+
srcs = [
37+
"@com_github_bytecodealliance_wasmtime//:rust_c_api",
38+
],
39+
outs = [
40+
"prefixed_wasmtime_c_api.a",
41+
],
42+
cmd = """
43+
for symbol in $$(nm -P $(<) 2>/dev/null | grep -E ^_?wasm_ | cut -d" " -f1); do
44+
echo $$symbol | sed -r 's/^(_?)(wasm_[a-z_]+)$$/\\1\\2 \\1wasmtime_\\2/' >>prefixed
45+
done
46+
# This should be OBJCOPY, but bazel-zig-cc doesn't define it.
47+
objcopy --redefine-syms=prefixed $(<) $@
48+
""",
49+
toolchains = ["@bazel_tools//tools/cpp:current_cc_toolchain"],
50+
)
51+
52+
cc_library(
53+
name = "prefixed_wasmtime_lib",
54+
srcs = [
55+
":prefixed_wasmtime_c_api_lib",
56+
],
57+
hdrs = [
58+
":prefixed_wasmtime_c_api_headers",
59+
],
60+
linkstatic = 1,
61+
)

bazel/repositories.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ def proxy_wasm_cpp_host_repositories():
192192
actual = "@com_github_webassembly_wasm_c_api//:wasmtime_lib",
193193
)
194194

195+
native.bind(
196+
name = "prefixed_wasmtime",
197+
actual = "@com_github_webassembly_wasm_c_api//:prefixed_wasmtime_lib",
198+
)
199+
195200
# WAVM with dependencies.
196201

197202
maybe(

bazel/select.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,27 @@
1515
def proxy_wasm_select_engine_v8(xs):
1616
return select({
1717
"@proxy_wasm_cpp_host//bazel:engine_v8": xs,
18+
"@proxy_wasm_cpp_host//bazel:multiengine": xs,
1819
"//conditions:default": [],
1920
})
2021

2122
def proxy_wasm_select_engine_wamr(xs):
2223
return select({
2324
"@proxy_wasm_cpp_host//bazel:engine_wamr": xs,
25+
"@proxy_wasm_cpp_host//bazel:multiengine": xs,
2426
"//conditions:default": [],
2527
})
2628

2729
def proxy_wasm_select_engine_wasmtime(xs):
2830
return select({
2931
"@proxy_wasm_cpp_host//bazel:engine_wasmtime": xs,
32+
"@proxy_wasm_cpp_host//bazel:multiengine": xs,
3033
"//conditions:default": [],
3134
})
3235

3336
def proxy_wasm_select_engine_wavm(xs):
3437
return select({
3538
"@proxy_wasm_cpp_host//bazel:engine_wavm": xs,
39+
"@proxy_wasm_cpp_host//bazel:multiengine": xs,
3640
"//conditions:default": [],
3741
})

src/wasmtime/wasmtime.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <unordered_map>
2525
#include <vector>
2626

27-
#include "include/proxy-wasm/wasm_vm.h"
2827
#include "src/wasmtime/types.h"
2928

3029
#include "wasmtime/include/wasm.h"

0 commit comments

Comments
 (0)