Skip to content

Commit 314743b

Browse files
authored
build: refactor Bazel configuration towards multiple runtime tests. (#160)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
1 parent e641ffa commit 314743b

File tree

8 files changed

+160
-75
lines changed

8 files changed

+160
-75
lines changed

.bazelrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
build --enable_platform_specific_config
2+
3+
build:linux --cxxopt=-std=c++17
4+
# See https://bytecodealliance.github.io/wasmtime/c-api/
5+
build:linux --linkopt=-lm
6+
build:linux --linkopt=-lpthread
7+
build:linux --linkopt=-ldl
8+
9+
build:macos --cxxopt=-std=c++17
10+
11+
# TODO(mathetake): Windows build is not verified yet.
12+
# build:windows --cxxopt="/std:c++17"
13+
# See https://bytecodealliance.github.io/wasmtime/c-api/
14+
# build:windows --linkopt="ws2_32.lib advapi32.lib userenv.lib ntdll.lib shell32.lib ole32.lib"

.github/workflows/cpp.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,22 @@ jobs:
5656
5757
build:
5858
runs-on: ubuntu-latest
59-
59+
60+
strategy:
61+
matrix:
62+
# TODO(mathetake): Add other runtimes.
63+
runtime: [ "wasmtime" ]
64+
6065
steps:
6166
- uses: actions/checkout@v2
6267

6368
- name: Mount bazel cache
6469
uses: actions/cache@v1
6570
with:
6671
path: "/home/runner/.cache/bazel"
67-
key: bazel
72+
key: bazel-${{ matrix.runtime }}
6873

6974
- name: Test
7075
run: |
71-
bazel test //...
76+
bazel test --define runtime=${{ matrix.runtime }} //...
7277

BUILD

Lines changed: 82 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
load("@rules_cc//cc:defs.bzl", "cc_library")
2-
load("@proxy_wasm_cpp_host//bazel:variables.bzl", "COPTS")
2+
load(
3+
"@proxy_wasm_cpp_host//bazel:select.bzl",
4+
"proxy_wasm_select_runtime_v8",
5+
"proxy_wasm_select_runtime_wamr",
6+
"proxy_wasm_select_runtime_wasmtime",
7+
"proxy_wasm_select_runtime_wavm",
8+
)
39

410
licenses(["notice"]) # Apache 2
511

@@ -13,28 +19,87 @@ cc_library(
1319
],
1420
)
1521

16-
# TODO(mathetkae): once other runtimes(WAVM,V8) can be linked in this repos,
17-
# use -define=wasm=v8|wavm|wasmtime and switch
1822
cc_library(
19-
name = "lib",
20-
srcs = glob(
21-
[
22-
"src/**/*.cc",
23-
"src/**/*.h",
24-
],
25-
exclude = [
26-
"src/**/v8*",
27-
"src/**/wamr*",
28-
"src/**/wavm*",
29-
],
30-
),
31-
hdrs = glob(["src/**/*.h"]),
32-
copts = COPTS,
23+
name = "common_lib",
24+
srcs = glob([
25+
"src/*.h",
26+
"src/*.cc",
27+
"src/common/*.h",
28+
"src/common/*.cc",
29+
"src/third_party/*.h",
30+
"src/third_party/*.cc",
31+
"src/null/*.cc",
32+
]),
3333
deps = [
3434
":include",
3535
"@boringssl//:crypto",
3636
"@com_google_protobuf//:protobuf_lite",
3737
"@proxy_wasm_cpp_sdk//:api_lib",
38+
],
39+
)
40+
41+
cc_library(
42+
name = "v8_lib",
43+
srcs = glob([
44+
# TODO(@mathetake): Add V8 lib.
45+
# "src/v8/*.h",
46+
# "src/v8/*.cc",
47+
]),
48+
deps = [
49+
":common_lib",
50+
# TODO(@mathetake): Add V8 lib.
51+
],
52+
)
53+
54+
cc_library(
55+
name = "wamr_lib",
56+
srcs = glob([
57+
# TODO(@mathetake): Add WAMR lib.
58+
# "src/wamr/*.h",
59+
# "src/wamr/*.cc",
60+
]),
61+
deps = [
62+
":common_lib",
63+
# TODO(@mathetake): Add WAMR lib.
64+
],
65+
)
66+
67+
cc_library(
68+
name = "wasmtime_lib",
69+
srcs = glob([
70+
"src/wasmtime/*.h",
71+
"src/wasmtime/*.cc",
72+
]),
73+
deps = [
74+
":common_lib",
3875
"@wasm_c_api//:wasmtime_lib",
3976
],
4077
)
78+
79+
cc_library(
80+
name = "wavm_lib",
81+
srcs = glob([
82+
# TODO(@mathetake): Add WAVM lib.
83+
# "src/wavm/*.h",
84+
# "src/wavm/*.cc",
85+
]),
86+
deps = [
87+
":common_lib",
88+
# TODO(@mathetake): Add WAVM lib.
89+
],
90+
)
91+
92+
cc_library(
93+
name = "lib",
94+
deps = [
95+
":common_lib",
96+
] + proxy_wasm_select_runtime_v8(
97+
[":v8_lib"],
98+
) + proxy_wasm_select_runtime_wamr(
99+
[":wamr_lib"],
100+
) + proxy_wasm_select_runtime_wasmtime(
101+
[":wasmtime_lib"],
102+
) + proxy_wasm_select_runtime_wavm(
103+
[":wavm_lib"],
104+
),
105+
)

bazel/BUILD

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
config_setting(
2+
name = "runtime_v8",
3+
values = {"define": "runtime=v8"},
4+
)
5+
6+
config_setting(
7+
name = "runtime_wamr",
8+
values = {"define": "runtime=wamr"},
9+
)
10+
11+
config_setting(
12+
name = "runtime_wasmtime",
13+
values = {"define": "runtime=wasmtime"},
14+
)
15+
16+
config_setting(
17+
name = "runtime_wavm",
18+
values = {"define": "runtime=wavm"},
19+
)

bazel/select.bzl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
def proxy_wasm_select_runtime_v8(xs):
16+
return select({
17+
"@proxy_wasm_cpp_host//bazel:runtime_v8": xs,
18+
"//conditions:default": [],
19+
})
20+
21+
def proxy_wasm_select_runtime_wamr(xs):
22+
return select({
23+
"@proxy_wasm_cpp_host//bazel:runtime_wamr": xs,
24+
"//conditions:default": [],
25+
})
26+
27+
def proxy_wasm_select_runtime_wasmtime(xs):
28+
return select({
29+
"@proxy_wasm_cpp_host//bazel:runtime_wasmtime": xs,
30+
"//conditions:default": [],
31+
})
32+
33+
def proxy_wasm_select_runtime_wavm(xs):
34+
return select({
35+
"@proxy_wasm_cpp_host//bazel:runtime_wavm": xs,
36+
"//conditions:default": [],
37+
})

bazel/variables.bzl

Lines changed: 0 additions & 42 deletions
This file was deleted.

test/BUILD

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
2-
load("@proxy_wasm_cpp_host//bazel:variables.bzl", "COPTS", "LINKOPTS")
32

43
package(default_visibility = ["//visibility:public"])
54

65
cc_test(
76
name = "null_vm_test",
87
srcs = ["null_vm_test.cc"],
9-
copts = COPTS,
108
deps = [
119
"//:lib",
1210
"@com_google_googletest//:gtest",
@@ -17,13 +15,11 @@ cc_test(
1715
cc_test(
1816
name = "runtime_test",
1917
srcs = ["runtime_test.cc"],
20-
copts = COPTS,
2118
data = [
2219
"//test/test_data:abi_export.wasm",
2320
"//test/test_data:callback.wasm",
2421
"//test/test_data:trap.wasm",
2522
],
26-
linkopts = LINKOPTS,
2723
deps = [
2824
":utility_lib",
2925
"//:lib",
@@ -35,12 +31,10 @@ cc_test(
3531
cc_test(
3632
name = "exports_test",
3733
srcs = ["exports_test.cc"],
38-
copts = COPTS,
3934
data = [
4035
"//test/test_data:clock.wasm",
4136
"//test/test_data:env.wasm",
4237
],
43-
linkopts = LINKOPTS,
4438
deps = [
4539
":utility_lib",
4640
"//:lib",
@@ -52,7 +46,6 @@ cc_test(
5246
cc_test(
5347
name = "context_test",
5448
srcs = ["context_test.cc"],
55-
copts = COPTS,
5649
deps = [
5750
"//:lib",
5851
"@com_google_googletest//:gtest",
@@ -63,7 +56,6 @@ cc_test(
6356
cc_test(
6457
name = "shared_data",
6558
srcs = ["shared_data_test.cc"],
66-
copts = COPTS,
6759
deps = [
6860
"//:lib",
6961
"@com_google_googletest//:gtest",
@@ -74,7 +66,6 @@ cc_test(
7466
cc_test(
7567
name = "shared_queue",
7668
srcs = ["shared_queue_test.cc"],
77-
copts = COPTS,
7869
deps = [
7970
"//:lib",
8071
"@com_google_googletest//:gtest",
@@ -85,7 +76,6 @@ cc_test(
8576
cc_test(
8677
name = "vm_id_handle",
8778
srcs = ["vm_id_handle_test.cc"],
88-
copts = COPTS,
8979
deps = [
9080
"//:lib",
9181
"@com_google_googletest//:gtest",
@@ -100,7 +90,6 @@ cc_library(
10090
"utility.h",
10191
],
10292
hdrs = ["utility.h"],
103-
copts = COPTS,
10493
deps = [
10594
"//:lib",
10695
"@com_google_googletest//:gtest",

test/common/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
load("@rules_cc//cc:defs.bzl", "cc_test")
2-
load("@proxy_wasm_cpp_host//bazel:variables.bzl", "COPTS")
32

43
cc_test(
54
name = "bytecode_util_test",
65
srcs = ["bytecode_util_test.cc"],
7-
copts = COPTS,
86
data = [
97
"//test/test_data:abi_export.wasm",
108
],

0 commit comments

Comments
 (0)