Skip to content

Commit 605ee8a

Browse files
authored
Make Bazel rules usable in different workspaces. (#171)
1. None of the Wasm runtimes we use provide native Bazel support, so use //external bindings to match exposed targets across different workspaces. 2. Split runtime targets from the base library to allow consumers to create desired combination in their workspace. Signed-off-by: Piotr Sikora <[email protected]>
1 parent b974c2e commit 605ee8a

File tree

10 files changed

+133
-58
lines changed

10 files changed

+133
-58
lines changed

BUILD

Lines changed: 93 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,87 +11,144 @@ licenses(["notice"]) # Apache 2
1111

1212
package(default_visibility = ["//visibility:public"])
1313

14+
exports_files(["LICENSE"])
15+
1416
cc_library(
15-
name = "include",
16-
hdrs = glob(["include/proxy-wasm/**/*.h"]),
17+
name = "wasm_vm_headers",
18+
hdrs = [
19+
"include/proxy-wasm/wasm_vm.h",
20+
"include/proxy-wasm/word.h",
21+
],
1722
deps = [
1823
"@proxy_wasm_cpp_sdk//:common_lib",
1924
],
2025
)
2126

2227
cc_library(
23-
name = "common_lib",
24-
srcs = glob([
25-
"src/*.h",
26-
"src/*.cc",
27-
"src/common/*.h",
28-
"src/null/*.cc",
29-
]),
28+
name = "headers",
29+
hdrs = [
30+
"include/proxy-wasm/context.h",
31+
"include/proxy-wasm/context_interface.h",
32+
"include/proxy-wasm/exports.h",
33+
"include/proxy-wasm/vm_id_handle.h",
34+
"include/proxy-wasm/wasm.h",
35+
],
3036
deps = [
31-
":include",
37+
":wasm_vm_headers",
38+
],
39+
)
40+
41+
cc_library(
42+
name = "base_lib",
43+
srcs = [
44+
"src/bytecode_util.cc",
45+
"src/context.cc",
46+
"src/exports.cc",
47+
"src/shared_data.cc",
48+
"src/shared_data.h",
49+
"src/shared_queue.cc",
50+
"src/shared_queue.h",
51+
"src/signature_util.cc",
52+
"src/vm_id_handle.cc",
53+
"src/wasm.cc",
54+
],
55+
hdrs = [
56+
"include/proxy-wasm/bytecode_util.h",
57+
"include/proxy-wasm/signature_util.h",
58+
],
59+
deps = [
60+
":headers",
3261
"@boringssl//:crypto",
62+
],
63+
)
64+
65+
cc_library(
66+
name = "null_lib",
67+
srcs = [
68+
"src/null/null.cc",
69+
"src/null/null_plugin.cc",
70+
"src/null/null_vm.cc",
71+
],
72+
hdrs = [
73+
"include/proxy-wasm/null.h",
74+
"include/proxy-wasm/null_plugin.h",
75+
"include/proxy-wasm/null_vm.h",
76+
"include/proxy-wasm/null_vm_plugin.h",
77+
"include/proxy-wasm/wasm_api_impl.h",
78+
],
79+
defines = ["PROXY_WASM_HAS_RUNTIME_NULL"],
80+
deps = [
81+
":headers",
3382
"@proxy_wasm_cpp_sdk//:api_lib",
3483
],
3584
)
3685

3786
cc_library(
3887
name = "v8_lib",
39-
srcs = glob([
40-
# TODO(@mathetake): Add V8 lib.
41-
# "src/v8/*.h",
42-
# "src/v8/*.cc",
43-
]),
88+
srcs = [
89+
"src/v8/v8.cc",
90+
],
91+
hdrs = ["include/proxy-wasm/v8.h"],
92+
defines = ["PROXY_WASM_HAS_RUNTIME_V8"],
4493
deps = [
45-
":common_lib",
46-
# TODO(@mathetake): Add V8 lib.
94+
":wasm_vm_headers",
95+
"//external:wee8",
4796
],
4897
)
4998

5099
cc_library(
51100
name = "wamr_lib",
52-
srcs = glob([
53-
"src/wamr/*.h",
54-
"src/wamr/*.cc",
55-
]),
101+
srcs = [
102+
"src/common/types.h",
103+
"src/wamr/types.h",
104+
"src/wamr/wamr.cc",
105+
],
106+
hdrs = ["include/proxy-wasm/wamr.h"],
107+
defines = ["PROXY_WASM_HAS_RUNTIME_WAMR"],
56108
deps = [
57-
":common_lib",
58-
"@wamr//:wamr_lib",
109+
":wasm_vm_headers",
110+
"//external:wamr",
59111
],
60112
)
61113

62114
cc_library(
63115
name = "wasmtime_lib",
64-
srcs = glob([
65-
"src/wasmtime/*.h",
66-
"src/wasmtime/*.cc",
67-
]),
116+
srcs = [
117+
"src/common/types.h",
118+
"src/wasmtime/types.h",
119+
"src/wasmtime/wasmtime.cc",
120+
],
121+
hdrs = ["include/proxy-wasm/wasmtime.h"],
122+
defines = ["PROXY_WASM_HAS_RUNTIME_WASMTIME"],
68123
deps = [
69-
":common_lib",
70-
"@wasm_c_api//:wasmtime_lib",
124+
":wasm_vm_headers",
125+
"//external:wasmtime",
71126
],
72127
)
73128

74129
cc_library(
75130
name = "wavm_lib",
76-
srcs = glob([
77-
"src/wavm/*.h",
78-
"src/wavm/*.cc",
79-
]),
131+
srcs = [
132+
"src/wavm/wavm.cc",
133+
],
134+
hdrs = ["include/proxy-wasm/wavm.h"],
80135
copts = [
81136
'-DWAVM_API=""',
82137
"-Wno-non-virtual-dtor",
83138
"-Wno-old-style-cast",
84139
],
140+
defines = ["PROXY_WASM_HAS_RUNTIME_WAVM"],
85141
deps = [
86-
":common_lib",
87-
"@wavm//:wavm_lib",
142+
":wasm_vm_headers",
143+
"//external:wavm",
88144
],
89145
)
90146

91147
cc_library(
92148
name = "lib",
93149
deps = [
94-
":common_lib",
150+
":base_lib",
151+
":null_lib",
95152
] + proxy_wasm_select_runtime_v8(
96153
[":v8_lib"],
97154
) + proxy_wasm_select_runtime_wamr(

bazel/external/wamr.BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ cmake(
2121
"WAMR_BUILD_LIBC_WASI": "0",
2222
"WAMR_BUILD_TAIL_CALL": "1",
2323
},
24-
defines = ["WASM_WAMR"],
2524
generate_args = ["-GNinja"],
2625
lib_source = ":srcs",
2726
out_static_libs = ["libvmlib.a"],

bazel/external/wasm-c-api.BUILD

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ cc_library(
99
hdrs = [
1010
"include/wasm.h",
1111
],
12-
defines = ["WASM_WASMTIME"],
1312
include_prefix = "wasmtime",
1413
deps = [
15-
"@wasmtime//:rust_c_api",
14+
"@com_github_bytecodealliance_wasmtime//:rust_c_api",
1615
],
1716
)

bazel/external/wavm.BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ cmake(
2020
# using -l:libstdc++.a.
2121
"CMAKE_CXX_FLAGS": "-lstdc++ -Wno-unused-command-line-argument",
2222
},
23-
defines = ["WASM_WAVM"],
2423
env_vars = {
2524
# Workaround for the -DDEBUG flag added in fastbuild on macOS,
2625
# which conflicts with DEBUG macro used in LLVM.

bazel/repositories.bzl

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,39 @@ def proxy_wasm_cpp_host_repositories():
3737
)
3838

3939
http_archive(
40-
name = "wamr",
40+
name = "com_github_bytecodealliance_wasm_micro_runtime",
4141
build_file = "@proxy_wasm_cpp_host//bazel/external:wamr.BUILD",
4242
sha256 = "46ad365a1c0668797e69cb868574fd526cd8e26a503213caf782c39061e6d2e1",
4343
strip_prefix = "wasm-micro-runtime-17a216748574499bd3a5130e7e6a20b84fe76798",
4444
url = "https://github.com/bytecodealliance/wasm-micro-runtime/archive/17a216748574499bd3a5130e7e6a20b84fe76798.tar.gz",
4545
)
4646

47+
native.bind(
48+
name = "wamr",
49+
actual = "@com_github_bytecodealliance_wasm_micro_runtime//:wamr_lib",
50+
)
51+
4752
http_archive(
48-
name = "wasmtime",
53+
name = "com_github_bytecodealliance_wasmtime",
4954
build_file = "@proxy_wasm_cpp_host//bazel/external:wasmtime.BUILD",
5055
sha256 = "e95d274822ac72bf06355bdfbeddcacae60d7e98fec8ee4b2e21740636fb5c2c",
5156
strip_prefix = "wasmtime-0.26.0",
5257
url = "https://github.com/bytecodealliance/wasmtime/archive/v0.26.0.tar.gz",
5358
)
5459

5560
http_archive(
56-
name = "wasm_c_api",
61+
name = "com_github_webassembly_wasm_c_api",
5762
build_file = "@proxy_wasm_cpp_host//bazel/external:wasm-c-api.BUILD",
5863
sha256 = "c774044f51431429e878bd1b9e2a4e38932f861f9211df72f75e9427eb6b8d32",
5964
strip_prefix = "wasm-c-api-c9d31284651b975f05ac27cee0bab1377560b87e",
6065
url = "https://github.com/WebAssembly/wasm-c-api/archive/c9d31284651b975f05ac27cee0bab1377560b87e.tar.gz",
6166
)
6267

68+
native.bind(
69+
name = "wasmtime",
70+
actual = "@com_github_webassembly_wasm_c_api//:wasmtime_lib",
71+
)
72+
6373
http_archive(
6474
name = "rules_rust",
6575
sha256 = "db182e96b5ed62b044142cdae096742fcfd1aa4febfe3af8afa3c0ee438a52a4",
@@ -83,9 +93,14 @@ def proxy_wasm_cpp_host_repositories():
8393
)
8494

8595
http_archive(
86-
name = "wavm",
96+
name = "com_github_wavm_wavm",
8797
build_file = "@proxy_wasm_cpp_host//bazel/external:wavm.BUILD",
8898
sha256 = "fa9a8dece0f1a51f8789c07f7f0c1f817ceee54c57d85f22ab958e43cde648d3",
8999
strip_prefix = "WAVM-93c3ad73e2938f19c8bb26d4f456b39d6bc4ca01",
90100
url = "https://github.com/WAVM/WAVM/archive/93c3ad73e2938f19c8bb26d4f456b39d6bc4ca01.tar.gz",
91101
)
102+
103+
native.bind(
104+
name = "wavm",
105+
actual = "@com_github_wavm_wavm//:wavm_lib",
106+
)

src/wamr/wamr.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
#include <utility>
3030
#include <vector>
3131

32-
#include "include/proxy-wasm/bytecode_util.h"
33-
3432
#include "src/wamr/types.h"
3533
#include "wasm_c_api.h"
3634

test/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
22

3+
licenses(["notice"]) # Apache 2
4+
35
package(default_visibility = ["//visibility:public"])
46

57
cc_test(
@@ -117,6 +119,7 @@ cc_test(
117119

118120
cc_library(
119121
name = "utility_lib",
122+
testonly = True,
120123
srcs = [
121124
"utility.cc",
122125
"utility.h",

test/test_data/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
load("@proxy_wasm_cpp_host//bazel:wasm.bzl", "wasm_rust_binary")
22

3+
licenses(["notice"]) # Apache 2
4+
35
package(default_visibility = ["//visibility:public"])
46

57
wasm_rust_binary(

test/utility.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ namespace proxy_wasm {
1818

1919
std::vector<std::string> getRuntimes() {
2020
std::vector<std::string> runtimes = {
21-
#if defined(WASM_V8)
21+
#if defined(PROXY_WASM_HAS_RUNTIME_V8)
2222
"v8",
2323
#endif
24-
#if defined(WASM_WAVM)
24+
#if defined(PROXY_WASM_HAS_RUNTIME_WAVM)
2525
"wavm",
2626
#endif
27-
#if defined(WASM_WASMTIME)
27+
#if defined(PROXY_WASM_HAS_RUNTIME_WASMTIME)
2828
"wasmtime",
2929
#endif
30-
#if defined(WASM_WAMR)
30+
#if defined(PROXY_WASM_HAS_RUNTIME_WAMR)
3131
"wamr",
3232
#endif
3333
""

test/utility.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
#include "include/proxy-wasm/context.h"
2424
#include "include/proxy-wasm/wasm.h"
2525

26-
#if defined(WASM_V8)
26+
#if defined(PROXY_WASM_HAS_RUNTIME_V8)
2727
#include "include/proxy-wasm/v8.h"
2828
#endif
29-
#if defined(WASM_WAVM)
29+
#if defined(PROXY_WASM_HAS_RUNTIME_WAVM)
3030
#include "include/proxy-wasm/wavm.h"
3131
#endif
32-
#if defined(WASM_WASMTIME)
32+
#if defined(PROXY_WASM_HAS_RUNTIME_WASMTIME)
3333
#include "include/proxy-wasm/wasmtime.h"
3434
#endif
35-
#if defined(WASM_WAMR)
35+
#if defined(PROXY_WASM_HAS_RUNTIME_WAMR)
3636
#include "include/proxy-wasm/wamr.h"
3737
#endif
3838

@@ -71,22 +71,25 @@ class TestVM : public testing::TestWithParam<std::string> {
7171
runtime_ = GetParam();
7272
if (runtime_ == "") {
7373
EXPECT_TRUE(false) << "runtime must not be empty";
74-
#if defined(WASM_V8)
74+
#if defined(PROXY_WASM_HAS_RUNTIME_V8)
7575
} else if (runtime_ == "v8") {
7676
vm_ = proxy_wasm::createV8Vm();
7777
#endif
78-
#if defined(WASM_WAVM)
78+
#if defined(PROXY_WASM_HAS_RUNTIME_WAVM)
7979
} else if (runtime_ == "wavm") {
8080
vm_ = proxy_wasm::createWavmVm();
8181
#endif
82-
#if defined(WASM_WASMTIME)
82+
#if defined(PROXY_WASM_HAS_RUNTIME_WASMTIME)
8383
} else if (runtime_ == "wasmtime") {
8484
vm_ = proxy_wasm::createWasmtimeVm();
8585
#endif
86-
#if defined(WASM_WAMR)
86+
#if defined(PROXY_WASM_HAS_RUNTIME_WAMR)
8787
} else if (runtime_ == "wamr") {
8888
vm_ = proxy_wasm::createWamrVm();
8989
#endif
90+
} else {
91+
EXPECT_TRUE(false) << "compiled without support for the requested \"" << runtime_
92+
<< "\" runtime";
9093
}
9194
vm_->integration().reset(integration_);
9295
}

0 commit comments

Comments
 (0)