Skip to content

Commit

Permalink
build: refactor Bazel configuration towards multiple runtime tests. (#…
Browse files Browse the repository at this point in the history
…160)

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
  • Loading branch information
mathetake authored May 7, 2021
1 parent e641ffa commit 314743b
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 75 deletions.
14 changes: 14 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
build --enable_platform_specific_config

build:linux --cxxopt=-std=c++17
# See https://bytecodealliance.github.io/wasmtime/c-api/
build:linux --linkopt=-lm
build:linux --linkopt=-lpthread
build:linux --linkopt=-ldl

build:macos --cxxopt=-std=c++17

# TODO(mathetake): Windows build is not verified yet.
# build:windows --cxxopt="/std:c++17"
# See https://bytecodealliance.github.io/wasmtime/c-api/
# build:windows --linkopt="ws2_32.lib advapi32.lib userenv.lib ntdll.lib shell32.lib ole32.lib"
11 changes: 8 additions & 3 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,22 @@ jobs:
build:
runs-on: ubuntu-latest


strategy:
matrix:
# TODO(mathetake): Add other runtimes.
runtime: [ "wasmtime" ]

steps:
- uses: actions/checkout@v2

- name: Mount bazel cache
uses: actions/cache@v1
with:
path: "/home/runner/.cache/bazel"
key: bazel
key: bazel-${{ matrix.runtime }}

- name: Test
run: |
bazel test //...
bazel test --define runtime=${{ matrix.runtime }} //...
99 changes: 82 additions & 17 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@proxy_wasm_cpp_host//bazel:variables.bzl", "COPTS")
load(
"@proxy_wasm_cpp_host//bazel:select.bzl",
"proxy_wasm_select_runtime_v8",
"proxy_wasm_select_runtime_wamr",
"proxy_wasm_select_runtime_wasmtime",
"proxy_wasm_select_runtime_wavm",
)

licenses(["notice"]) # Apache 2

Expand All @@ -13,28 +19,87 @@ cc_library(
],
)

# TODO(mathetkae): once other runtimes(WAVM,V8) can be linked in this repos,
# use -define=wasm=v8|wavm|wasmtime and switch
cc_library(
name = "lib",
srcs = glob(
[
"src/**/*.cc",
"src/**/*.h",
],
exclude = [
"src/**/v8*",
"src/**/wamr*",
"src/**/wavm*",
],
),
hdrs = glob(["src/**/*.h"]),
copts = COPTS,
name = "common_lib",
srcs = glob([
"src/*.h",
"src/*.cc",
"src/common/*.h",
"src/common/*.cc",
"src/third_party/*.h",
"src/third_party/*.cc",
"src/null/*.cc",
]),
deps = [
":include",
"@boringssl//:crypto",
"@com_google_protobuf//:protobuf_lite",
"@proxy_wasm_cpp_sdk//:api_lib",
],
)

cc_library(
name = "v8_lib",
srcs = glob([
# TODO(@mathetake): Add V8 lib.
# "src/v8/*.h",
# "src/v8/*.cc",
]),
deps = [
":common_lib",
# TODO(@mathetake): Add V8 lib.
],
)

cc_library(
name = "wamr_lib",
srcs = glob([
# TODO(@mathetake): Add WAMR lib.
# "src/wamr/*.h",
# "src/wamr/*.cc",
]),
deps = [
":common_lib",
# TODO(@mathetake): Add WAMR lib.
],
)

cc_library(
name = "wasmtime_lib",
srcs = glob([
"src/wasmtime/*.h",
"src/wasmtime/*.cc",
]),
deps = [
":common_lib",
"@wasm_c_api//:wasmtime_lib",
],
)

cc_library(
name = "wavm_lib",
srcs = glob([
# TODO(@mathetake): Add WAVM lib.
# "src/wavm/*.h",
# "src/wavm/*.cc",
]),
deps = [
":common_lib",
# TODO(@mathetake): Add WAVM lib.
],
)

cc_library(
name = "lib",
deps = [
":common_lib",
] + proxy_wasm_select_runtime_v8(
[":v8_lib"],
) + proxy_wasm_select_runtime_wamr(
[":wamr_lib"],
) + proxy_wasm_select_runtime_wasmtime(
[":wasmtime_lib"],
) + proxy_wasm_select_runtime_wavm(
[":wavm_lib"],
),
)
19 changes: 19 additions & 0 deletions bazel/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
config_setting(
name = "runtime_v8",
values = {"define": "runtime=v8"},
)

config_setting(
name = "runtime_wamr",
values = {"define": "runtime=wamr"},
)

config_setting(
name = "runtime_wasmtime",
values = {"define": "runtime=wasmtime"},
)

config_setting(
name = "runtime_wavm",
values = {"define": "runtime=wavm"},
)
37 changes: 37 additions & 0 deletions bazel/select.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

def proxy_wasm_select_runtime_v8(xs):
return select({
"@proxy_wasm_cpp_host//bazel:runtime_v8": xs,
"//conditions:default": [],
})

def proxy_wasm_select_runtime_wamr(xs):
return select({
"@proxy_wasm_cpp_host//bazel:runtime_wamr": xs,
"//conditions:default": [],
})

def proxy_wasm_select_runtime_wasmtime(xs):
return select({
"@proxy_wasm_cpp_host//bazel:runtime_wasmtime": xs,
"//conditions:default": [],
})

def proxy_wasm_select_runtime_wavm(xs):
return select({
"@proxy_wasm_cpp_host//bazel:runtime_wavm": xs,
"//conditions:default": [],
})
42 changes: 0 additions & 42 deletions bazel/variables.bzl

This file was deleted.

11 changes: 0 additions & 11 deletions test/BUILD
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("@proxy_wasm_cpp_host//bazel:variables.bzl", "COPTS", "LINKOPTS")

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

cc_test(
name = "null_vm_test",
srcs = ["null_vm_test.cc"],
copts = COPTS,
deps = [
"//:lib",
"@com_google_googletest//:gtest",
Expand All @@ -17,13 +15,11 @@ cc_test(
cc_test(
name = "runtime_test",
srcs = ["runtime_test.cc"],
copts = COPTS,
data = [
"//test/test_data:abi_export.wasm",
"//test/test_data:callback.wasm",
"//test/test_data:trap.wasm",
],
linkopts = LINKOPTS,
deps = [
":utility_lib",
"//:lib",
Expand All @@ -35,12 +31,10 @@ cc_test(
cc_test(
name = "exports_test",
srcs = ["exports_test.cc"],
copts = COPTS,
data = [
"//test/test_data:clock.wasm",
"//test/test_data:env.wasm",
],
linkopts = LINKOPTS,
deps = [
":utility_lib",
"//:lib",
Expand All @@ -52,7 +46,6 @@ cc_test(
cc_test(
name = "context_test",
srcs = ["context_test.cc"],
copts = COPTS,
deps = [
"//:lib",
"@com_google_googletest//:gtest",
Expand All @@ -63,7 +56,6 @@ cc_test(
cc_test(
name = "shared_data",
srcs = ["shared_data_test.cc"],
copts = COPTS,
deps = [
"//:lib",
"@com_google_googletest//:gtest",
Expand All @@ -74,7 +66,6 @@ cc_test(
cc_test(
name = "shared_queue",
srcs = ["shared_queue_test.cc"],
copts = COPTS,
deps = [
"//:lib",
"@com_google_googletest//:gtest",
Expand All @@ -85,7 +76,6 @@ cc_test(
cc_test(
name = "vm_id_handle",
srcs = ["vm_id_handle_test.cc"],
copts = COPTS,
deps = [
"//:lib",
"@com_google_googletest//:gtest",
Expand All @@ -100,7 +90,6 @@ cc_library(
"utility.h",
],
hdrs = ["utility.h"],
copts = COPTS,
deps = [
"//:lib",
"@com_google_googletest//:gtest",
Expand Down
2 changes: 0 additions & 2 deletions test/common/BUILD
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
load("@rules_cc//cc:defs.bzl", "cc_test")
load("@proxy_wasm_cpp_host//bazel:variables.bzl", "COPTS")

cc_test(
name = "bytecode_util_test",
srcs = ["bytecode_util_test.cc"],
copts = COPTS,
data = [
"//test/test_data:abi_export.wasm",
],
Expand Down

0 comments on commit 314743b

Please sign in to comment.