Skip to content

Make Bazel rules usable in different workspaces. #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 93 additions & 36 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,87 +11,144 @@ licenses(["notice"]) # Apache 2

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

exports_files(["LICENSE"])

cc_library(
name = "include",
hdrs = glob(["include/proxy-wasm/**/*.h"]),
name = "wasm_vm_headers",
hdrs = [
"include/proxy-wasm/wasm_vm.h",
"include/proxy-wasm/word.h",
],
deps = [
"@proxy_wasm_cpp_sdk//:common_lib",
],
)

cc_library(
name = "common_lib",
srcs = glob([
"src/*.h",
"src/*.cc",
"src/common/*.h",
"src/null/*.cc",
]),
name = "headers",
hdrs = [
"include/proxy-wasm/context.h",
"include/proxy-wasm/context_interface.h",
"include/proxy-wasm/exports.h",
"include/proxy-wasm/vm_id_handle.h",
"include/proxy-wasm/wasm.h",
],
deps = [
":include",
":wasm_vm_headers",
],
)

cc_library(
name = "base_lib",
srcs = [
"src/bytecode_util.cc",
"src/context.cc",
"src/exports.cc",
"src/shared_data.cc",
"src/shared_data.h",
"src/shared_queue.cc",
"src/shared_queue.h",
"src/signature_util.cc",
"src/vm_id_handle.cc",
"src/wasm.cc",
],
hdrs = [
"include/proxy-wasm/bytecode_util.h",
"include/proxy-wasm/signature_util.h",
],
deps = [
":headers",
"@boringssl//:crypto",
],
)

cc_library(
name = "null_lib",
srcs = [
"src/null/null.cc",
"src/null/null_plugin.cc",
"src/null/null_vm.cc",
],
hdrs = [
"include/proxy-wasm/null.h",
"include/proxy-wasm/null_plugin.h",
"include/proxy-wasm/null_vm.h",
"include/proxy-wasm/null_vm_plugin.h",
"include/proxy-wasm/wasm_api_impl.h",
],
defines = ["PROXY_WASM_HAS_RUNTIME_NULL"],
deps = [
":headers",
"@proxy_wasm_cpp_sdk//:api_lib",
],
)

cc_library(
name = "v8_lib",
srcs = glob([
# TODO(@mathetake): Add V8 lib.
# "src/v8/*.h",
# "src/v8/*.cc",
]),
srcs = [
"src/v8/v8.cc",
],
hdrs = ["include/proxy-wasm/v8.h"],
defines = ["PROXY_WASM_HAS_RUNTIME_V8"],
deps = [
":common_lib",
# TODO(@mathetake): Add V8 lib.
":wasm_vm_headers",
"//external:wee8",
],
)

cc_library(
name = "wamr_lib",
srcs = glob([
"src/wamr/*.h",
"src/wamr/*.cc",
]),
srcs = [
"src/common/types.h",
"src/wamr/types.h",
"src/wamr/wamr.cc",
],
hdrs = ["include/proxy-wasm/wamr.h"],
defines = ["PROXY_WASM_HAS_RUNTIME_WAMR"],
deps = [
":common_lib",
"@wamr//:wamr_lib",
":wasm_vm_headers",
"//external:wamr",
],
)

cc_library(
name = "wasmtime_lib",
srcs = glob([
"src/wasmtime/*.h",
"src/wasmtime/*.cc",
]),
srcs = [
"src/common/types.h",
"src/wasmtime/types.h",
"src/wasmtime/wasmtime.cc",
],
hdrs = ["include/proxy-wasm/wasmtime.h"],
defines = ["PROXY_WASM_HAS_RUNTIME_WASMTIME"],
deps = [
":common_lib",
"@wasm_c_api//:wasmtime_lib",
":wasm_vm_headers",
"//external:wasmtime",
],
)

cc_library(
name = "wavm_lib",
srcs = glob([
"src/wavm/*.h",
"src/wavm/*.cc",
]),
srcs = [
"src/wavm/wavm.cc",
],
hdrs = ["include/proxy-wasm/wavm.h"],
copts = [
'-DWAVM_API=""',
"-Wno-non-virtual-dtor",
"-Wno-old-style-cast",
],
defines = ["PROXY_WASM_HAS_RUNTIME_WAVM"],
deps = [
":common_lib",
"@wavm//:wavm_lib",
":wasm_vm_headers",
"//external:wavm",
],
)

cc_library(
name = "lib",
deps = [
":common_lib",
":base_lib",
":null_lib",
] + proxy_wasm_select_runtime_v8(
[":v8_lib"],
) + proxy_wasm_select_runtime_wamr(
Expand Down
1 change: 0 additions & 1 deletion bazel/external/wamr.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ cmake(
"WAMR_BUILD_LIBC_WASI": "0",
"WAMR_BUILD_TAIL_CALL": "1",
},
defines = ["WASM_WAMR"],
generate_args = ["-GNinja"],
lib_source = ":srcs",
out_static_libs = ["libvmlib.a"],
Expand Down
3 changes: 1 addition & 2 deletions bazel/external/wasm-c-api.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ cc_library(
hdrs = [
"include/wasm.h",
],
defines = ["WASM_WASMTIME"],
include_prefix = "wasmtime",
deps = [
"@wasmtime//:rust_c_api",
"@com_github_bytecodealliance_wasmtime//:rust_c_api",
],
)
1 change: 0 additions & 1 deletion bazel/external/wavm.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ cmake(
# using -l:libstdc++.a.
"CMAKE_CXX_FLAGS": "-lstdc++ -Wno-unused-command-line-argument",
},
defines = ["WASM_WAVM"],
env_vars = {
# Workaround for the -DDEBUG flag added in fastbuild on macOS,
# which conflicts with DEBUG macro used in LLVM.
Expand Down
23 changes: 19 additions & 4 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,39 @@ def proxy_wasm_cpp_host_repositories():
)

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

native.bind(
name = "wamr",
actual = "@com_github_bytecodealliance_wasm_micro_runtime//:wamr_lib",
)

http_archive(
name = "wasmtime",
name = "com_github_bytecodealliance_wasmtime",
build_file = "@proxy_wasm_cpp_host//bazel/external:wasmtime.BUILD",
sha256 = "e95d274822ac72bf06355bdfbeddcacae60d7e98fec8ee4b2e21740636fb5c2c",
strip_prefix = "wasmtime-0.26.0",
url = "https://github.com/bytecodealliance/wasmtime/archive/v0.26.0.tar.gz",
)

http_archive(
name = "wasm_c_api",
name = "com_github_webassembly_wasm_c_api",
build_file = "@proxy_wasm_cpp_host//bazel/external:wasm-c-api.BUILD",
sha256 = "c774044f51431429e878bd1b9e2a4e38932f861f9211df72f75e9427eb6b8d32",
strip_prefix = "wasm-c-api-c9d31284651b975f05ac27cee0bab1377560b87e",
url = "https://github.com/WebAssembly/wasm-c-api/archive/c9d31284651b975f05ac27cee0bab1377560b87e.tar.gz",
)

native.bind(
name = "wasmtime",
actual = "@com_github_webassembly_wasm_c_api//:wasmtime_lib",
)

http_archive(
name = "rules_rust",
sha256 = "db182e96b5ed62b044142cdae096742fcfd1aa4febfe3af8afa3c0ee438a52a4",
Expand All @@ -83,9 +93,14 @@ def proxy_wasm_cpp_host_repositories():
)

http_archive(
name = "wavm",
name = "com_github_wavm_wavm",
build_file = "@proxy_wasm_cpp_host//bazel/external:wavm.BUILD",
sha256 = "fa9a8dece0f1a51f8789c07f7f0c1f817ceee54c57d85f22ab958e43cde648d3",
strip_prefix = "WAVM-93c3ad73e2938f19c8bb26d4f456b39d6bc4ca01",
url = "https://github.com/WAVM/WAVM/archive/93c3ad73e2938f19c8bb26d4f456b39d6bc4ca01.tar.gz",
)

native.bind(
name = "wavm",
actual = "@com_github_wavm_wavm//:wavm_lib",
)
2 changes: 0 additions & 2 deletions src/wamr/wamr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
#include <utility>
#include <vector>

#include "include/proxy-wasm/bytecode_util.h"

#include "src/wamr/types.h"
#include "wasm_c_api.h"

Expand Down
3 changes: 3 additions & 0 deletions test/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")

licenses(["notice"]) # Apache 2

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

cc_test(
Expand Down Expand Up @@ -117,6 +119,7 @@ cc_test(

cc_library(
name = "utility_lib",
testonly = True,
srcs = [
"utility.cc",
"utility.h",
Expand Down
2 changes: 2 additions & 0 deletions test/test_data/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
load("@proxy_wasm_cpp_host//bazel:wasm.bzl", "wasm_rust_binary")

licenses(["notice"]) # Apache 2

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

wasm_rust_binary(
Expand Down
8 changes: 4 additions & 4 deletions test/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ namespace proxy_wasm {

std::vector<std::string> getRuntimes() {
std::vector<std::string> runtimes = {
#if defined(WASM_V8)
#if defined(PROXY_WASM_HAS_RUNTIME_V8)
"v8",
#endif
#if defined(WASM_WAVM)
#if defined(PROXY_WASM_HAS_RUNTIME_WAVM)
"wavm",
#endif
#if defined(WASM_WASMTIME)
#if defined(PROXY_WASM_HAS_RUNTIME_WASMTIME)
"wasmtime",
#endif
#if defined(WASM_WAMR)
#if defined(PROXY_WASM_HAS_RUNTIME_WAMR)
"wamr",
#endif
""
Expand Down
19 changes: 11 additions & 8 deletions test/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
#include "include/proxy-wasm/context.h"
#include "include/proxy-wasm/wasm.h"

#if defined(WASM_V8)
#if defined(PROXY_WASM_HAS_RUNTIME_V8)
#include "include/proxy-wasm/v8.h"
#endif
#if defined(WASM_WAVM)
#if defined(PROXY_WASM_HAS_RUNTIME_WAVM)
#include "include/proxy-wasm/wavm.h"
#endif
#if defined(WASM_WASMTIME)
#if defined(PROXY_WASM_HAS_RUNTIME_WASMTIME)
#include "include/proxy-wasm/wasmtime.h"
#endif
#if defined(WASM_WAMR)
#if defined(PROXY_WASM_HAS_RUNTIME_WAMR)
#include "include/proxy-wasm/wamr.h"
#endif

Expand Down Expand Up @@ -71,22 +71,25 @@ class TestVM : public testing::TestWithParam<std::string> {
runtime_ = GetParam();
if (runtime_ == "") {
EXPECT_TRUE(false) << "runtime must not be empty";
#if defined(WASM_V8)
#if defined(PROXY_WASM_HAS_RUNTIME_V8)
} else if (runtime_ == "v8") {
vm_ = proxy_wasm::createV8Vm();
#endif
#if defined(WASM_WAVM)
#if defined(PROXY_WASM_HAS_RUNTIME_WAVM)
} else if (runtime_ == "wavm") {
vm_ = proxy_wasm::createWavmVm();
#endif
#if defined(WASM_WASMTIME)
#if defined(PROXY_WASM_HAS_RUNTIME_WASMTIME)
} else if (runtime_ == "wasmtime") {
vm_ = proxy_wasm::createWasmtimeVm();
#endif
#if defined(WASM_WAMR)
#if defined(PROXY_WASM_HAS_RUNTIME_WAMR)
} else if (runtime_ == "wamr") {
vm_ = proxy_wasm::createWamrVm();
#endif
} else {
EXPECT_TRUE(false) << "compiled without support for the requested \"" << runtime_
<< "\" runtime";
}
vm_->integration().reset(integration_);
}
Expand Down