diff --git a/BUILD b/BUILD index 3ad42cb37..c2eb5d8c2 100644 --- a/BUILD +++ b/BUILD @@ -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( diff --git a/bazel/external/wamr.BUILD b/bazel/external/wamr.BUILD index 2d0af954b..0b0df722f 100644 --- a/bazel/external/wamr.BUILD +++ b/bazel/external/wamr.BUILD @@ -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"], diff --git a/bazel/external/wasm-c-api.BUILD b/bazel/external/wasm-c-api.BUILD index 06a7fa2f8..5d4be94f5 100644 --- a/bazel/external/wasm-c-api.BUILD +++ b/bazel/external/wasm-c-api.BUILD @@ -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", ], ) diff --git a/bazel/external/wavm.BUILD b/bazel/external/wavm.BUILD index 55e4a81b0..a87ece7c1 100644 --- a/bazel/external/wavm.BUILD +++ b/bazel/external/wavm.BUILD @@ -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. diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index fb25fb781..c4a725c94 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -37,15 +37,20 @@ 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", @@ -53,13 +58,18 @@ def proxy_wasm_cpp_host_repositories(): ) 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", @@ -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", + ) diff --git a/src/wamr/wamr.cc b/src/wamr/wamr.cc index 9b7375137..06f9ce465 100644 --- a/src/wamr/wamr.cc +++ b/src/wamr/wamr.cc @@ -29,8 +29,6 @@ #include #include -#include "include/proxy-wasm/bytecode_util.h" - #include "src/wamr/types.h" #include "wasm_c_api.h" diff --git a/test/BUILD b/test/BUILD index d41c657a7..132404b3f 100644 --- a/test/BUILD +++ b/test/BUILD @@ -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( @@ -117,6 +119,7 @@ cc_test( cc_library( name = "utility_lib", + testonly = True, srcs = [ "utility.cc", "utility.h", diff --git a/test/test_data/BUILD b/test/test_data/BUILD index 571ca9304..c6ed213e3 100644 --- a/test/test_data/BUILD +++ b/test/test_data/BUILD @@ -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( diff --git a/test/utility.cc b/test/utility.cc index 5b999c0c4..e833f22e5 100644 --- a/test/utility.cc +++ b/test/utility.cc @@ -18,16 +18,16 @@ namespace proxy_wasm { std::vector getRuntimes() { std::vector 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 "" diff --git a/test/utility.h b/test/utility.h index 05ed1cf59..07094b893 100644 --- a/test/utility.h +++ b/test/utility.h @@ -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 @@ -71,22 +71,25 @@ class TestVM : public testing::TestWithParam { 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_); }