Skip to content

Commit b7b33b1

Browse files
committed
Make Bazel rules usable in different workspaces.
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 b2e0caf commit b7b33b1

File tree

5 files changed

+120
-45
lines changed

5 files changed

+120
-45
lines changed

BUILD

Lines changed: 89 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,89 +12,140 @@ licenses(["notice"]) # Apache 2
1212
package(default_visibility = ["//visibility:public"])
1313

1414
cc_library(
15-
name = "include",
16-
hdrs = glob(["include/proxy-wasm/**/*.h"]),
15+
name = "wasm_vm_headers",
16+
hdrs = [
17+
"include/proxy-wasm/wasm_vm.h",
18+
"include/proxy-wasm/word.h",
19+
],
1720
deps = [
1821
"@proxy_wasm_cpp_sdk//:common_lib",
1922
],
2023
)
2124

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

4087
cc_library(
4188
name = "v8_lib",
42-
srcs = glob([
43-
# TODO(@mathetake): Add V8 lib.
44-
# "src/v8/*.h",
45-
# "src/v8/*.cc",
46-
]),
89+
srcs = [
90+
"src/v8/v8.cc",
91+
],
92+
hdrs = ["include/proxy-wasm/v8.h"],
4793
deps = [
48-
":common_lib",
49-
# TODO(@mathetake): Add V8 lib.
94+
":wasm_vm_headers",
95+
"//external:wee8",
5096
],
5197
)
5298

5399
cc_library(
54100
name = "wamr_lib",
55-
srcs = glob([
56-
"src/wamr/*.h",
57-
"src/wamr/*.cc",
58-
]),
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"],
59107
deps = [
60-
":common_lib",
61-
"@wamr//:wamr_lib",
108+
":wasm_vm_headers",
109+
"//external:wamr",
62110
],
63111
)
64112

65113
cc_library(
66114
name = "wasmtime_lib",
67-
srcs = glob([
68-
"src/wasmtime/*.h",
69-
"src/wasmtime/*.cc",
70-
]),
115+
srcs = [
116+
"src/common/types.h",
117+
"src/wasmtime/types.h",
118+
"src/wasmtime/wasmtime.cc",
119+
],
120+
hdrs = ["include/proxy-wasm/wasmtime.h"],
71121
deps = [
72-
":common_lib",
73-
"@wasm_c_api//:wasmtime_lib",
122+
":wasm_vm_headers",
123+
"//external:wasmtime",
74124
],
75125
)
76126

77127
cc_library(
78128
name = "wavm_lib",
79-
srcs = glob([
80-
"src/wavm/*.h",
81-
"src/wavm/*.cc",
82-
]),
129+
srcs = [
130+
"src/wavm/wavm.cc",
131+
],
132+
hdrs = ["include/proxy-wasm/wavm.h"],
83133
copts = [
84134
'-DWAVM_API=""',
85135
"-Wno-non-virtual-dtor",
86136
"-Wno-old-style-cast",
87137
],
88138
deps = [
89-
":common_lib",
90-
"@wavm//:wavm_lib",
139+
":wasm_vm_headers",
140+
"//external:wavm",
91141
],
92142
)
93143

94144
cc_library(
95145
name = "lib",
96146
deps = [
97-
":common_lib",
147+
":base_lib",
148+
":null_lib",
98149
] + proxy_wasm_select_runtime_v8(
99150
[":v8_lib"],
100151
) + proxy_wasm_select_runtime_wamr(

bazel/external/wasm-c-api.BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ cc_library(
1212
defines = ["WASM_WASMTIME"],
1313
include_prefix = "wasmtime",
1414
deps = [
15-
"@wasmtime//:rust_c_api",
15+
"@com_github_bytecodealliance_wasmtime//:rust_c_api",
1616
],
1717
)

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",
@@ -90,9 +100,14 @@ def proxy_wasm_cpp_host_repositories():
90100
)
91101

92102
http_archive(
93-
name = "wavm",
103+
name = "com_github_wavm_wavm",
94104
build_file = "@proxy_wasm_cpp_host//bazel/external:wavm.BUILD",
95105
sha256 = "fa9a8dece0f1a51f8789c07f7f0c1f817ceee54c57d85f22ab958e43cde648d3",
96106
strip_prefix = "WAVM-93c3ad73e2938f19c8bb26d4f456b39d6bc4ca01",
97107
url = "https://github.com/WAVM/WAVM/archive/93c3ad73e2938f19c8bb26d4f456b39d6bc4ca01.tar.gz",
98108
)
109+
110+
native.bind(
111+
name = "wavm",
112+
actual = "@com_github_wavm_wavm//:wavm_lib",
113+
)

include/proxy-wasm/wasm_api_impl.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515

1616
#pragma once
1717

18+
// Required by "proxy_wasm_api.h" included within null_plugin namespace.
19+
20+
#include <cstring>
21+
#include <functional>
22+
#include <memory>
23+
#include <string>
24+
#include <tuple>
25+
#include <unordered_map>
26+
#include <utility>
27+
#include <vector>
28+
1829
namespace proxy_wasm {
1930
namespace null_plugin {
2031

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

0 commit comments

Comments
 (0)