From ae297be2521f32d3d9f75003d239895d376b7331 Mon Sep 17 00:00:00 2001 From: mathetake Date: Sat, 7 Nov 2020 16:04:59 +0900 Subject: [PATCH 01/31] wasm: add wasmtime runtime Signed-off-by: mathetake --- bazel/external/proxy_wasm_cpp_host.BUILD | 14 ++++++-- bazel/repositories.bzl | 14 ++++++++ bazel/repositories_extra.bzl | 2 ++ bazel/repository_locations.bzl | 44 ++++++++++++++++++++++-- source/extensions/common/wasm/wasm_vm.cc | 4 +-- 5 files changed, 70 insertions(+), 8 deletions(-) diff --git a/bazel/external/proxy_wasm_cpp_host.BUILD b/bazel/external/proxy_wasm_cpp_host.BUILD index 1b3f0829d7b25..b73d1c4d92b3e 100644 --- a/bazel/external/proxy_wasm_cpp_host.BUILD +++ b/bazel/external/proxy_wasm_cpp_host.BUILD @@ -33,14 +33,20 @@ cc_library( "src/**/*.h", "src/**/*.cc", ], - exclude = ["src/wavm/*"], + exclude = [ + "src/wavm/*", + "src/wasmtime/*", + ], ), glob( [ "src/**/*.h", "src/**/*.cc", ], - exclude = ["src/v8/*"], + exclude = [ + "src/v8/*", + "src/wavm/*", + ], ), glob( [ @@ -50,6 +56,7 @@ cc_library( exclude = [ "src/wavm/*", "src/v8/*", + "src/wasmtime/*", ], ), ), @@ -69,7 +76,8 @@ cc_library( "@proxy_wasm_cpp_sdk//:api_lib", "@proxy_wasm_cpp_sdk//:common_lib", ] + envoy_select_wasm_wavm([ - "@envoy//bazel/foreign_cc:wavm", + "@com_github_wasmtime_c_api//:lib", + # "@envoy//bazel/foreign_cc:wavm", ]) + envoy_select_wasm_v8([ "//external:wee8", ]), diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 3df2774717eda..c3b79b98061c1 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -182,6 +182,8 @@ def envoy_dependencies(skip_targets = []): _org_llvm_llvm() _com_github_wavm_wavm() + _com_github_wasmtime() + _com_github_wasmtime_c_api() switched_rules_by_language( name = "com_google_googleapis_imports", @@ -864,6 +866,18 @@ def _com_github_wavm_wavm(): actual = "@envoy//bazel/foreign_cc:wavm", ) +def _com_github_wasmtime(): + external_http_archive( + name = "com_github_wasmtime", + build_file = "@envoy//bazel/external:wasmtime.BUILD", + ) + +def _com_github_wasmtime_c_api(): + external_http_archive( + name = "com_github_wasmtime_c_api", + build_file = "@envoy//bazel/external:wasmtime-c-api.BUILD", + ) + def _kafka_deps(): # This archive contains Kafka client source code. # We are using request/response message format files to generate parser code. diff --git a/bazel/repositories_extra.bzl b/bazel/repositories_extra.bzl index 70fe69b6fa400..dbfc5221d0541 100644 --- a/bazel/repositories_extra.bzl +++ b/bazel/repositories_extra.bzl @@ -1,5 +1,6 @@ load("@rules_python//python:repositories.bzl", "py_repositories") load("@rules_python//python:pip.bzl", "pip3_import", "pip_repositories") +load("@proxy_wasm_cpp_host//bazel/cargo:crates.bzl", "proxy_wasm_cpp_host_raze__fetch_remote_crates") # Python dependencies. def _python_deps(): @@ -100,3 +101,4 @@ def _python_deps(): # Envoy deps that rely on a first stage of dependency loading in envoy_dependencies(). def envoy_dependencies_extra(): _python_deps() + proxy_wasm_cpp_host_raze__fetch_remote_crates() diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 974c9deea62b2..82ffbc74ff5ca 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -615,6 +615,44 @@ REPOSITORY_LOCATIONS_SPEC = dict( ], cpe = "cpe:2.3:a:webassembly_virtual_machine_project:webassembly_virtual_machine:*", ), + com_github_wasmtime = dict( + project_name = "wasmtime", + project_desc = "A standalone runtime for WebAssembly", + project_url = "https://github.com/bytecodealliance/wasmtime", + version = "0.20.0", + sha256 = "feb29c96e053d16fe3dc91b93d7a28ab24b9c390fbdf2580547ae7fa0b8eae95", + strip_prefix = "wasmtime-{version}", + urls = ["https://github.com//bytecodealliance/wasmtime/archive/v{version}.tar.gz"], + release_date = "2020-11-04", + use_category = ["dataplane_ext"], + extensions = [ + "envoy.access_loggers.wasm", + "envoy.bootstrap.wasm", + "envoy.filters.http.wasm", + "envoy.filters.network.wasm", + "envoy.stat_sinks.wasm", + ], + cpe = "cpe:2.3:a:webassembly_virtual_machine_project:webassembly_virtual_machine:*", + ), + com_github_wasmtime_c_api = dict( + project_name = "wasmtime-c-api", + project_desc = "wasmtime's c-api header files", + project_url = "https://github.com/bytecodealliance/wasmtime", + version = "v0.20.0", + sha256 = "fdbd6dbb58d15b3566abcc2c62ab18c348027e1620bc2ba0219017999504000e", + strip_prefix = "wasmtime-{version}-x86_64-linux-c-api", + urls = ["https://github.com/bytecodealliance/wasmtime/releases/download/{version}/wasmtime-{version}-x86_64-linux-c-api.tar.xz"], + release_date = "2020-11-04", + use_category = ["dataplane_ext"], + extensions = [ + "envoy.access_loggers.wasm", + "envoy.bootstrap.wasm", + "envoy.filters.http.wasm", + "envoy.filters.network.wasm", + "envoy.stat_sinks.wasm", + ], + cpe = "N/A", + ), io_opencensus_cpp = dict( project_name = "OpenCensus C++", project_desc = "OpenCensus tracing library", @@ -830,10 +868,10 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "WebAssembly for Proxies (C++ host implementation)", project_desc = "WebAssembly for Proxies (C++ host implementation)", project_url = "https://github.com/proxy-wasm/proxy-wasm-cpp-host", - version = "40fd3d03842c07d65fed907a6b6ed0f89d68d531", - sha256 = "b5ae746e66b6209ea0cce86d6c21de99dacbec1da9cdadd53a9ec46bc296a3ba", + version = "4a0bbd8370703e0e3196abcd8b732f18f868790a", + sha256 = "65ee4c7aa9a9f6dd39b4cbd77016f7057b7ca145003b8b5da7a2303893e1b809", strip_prefix = "proxy-wasm-cpp-host-{version}", - urls = ["https://github.com/proxy-wasm/proxy-wasm-cpp-host/archive/{version}.tar.gz"], + urls = ["https://github.com/mathetake/proxy-wasm-cpp-host/archive/{version}.tar.gz"], use_category = ["dataplane_ext"], extensions = [ "envoy.access_loggers.wasm", diff --git a/source/extensions/common/wasm/wasm_vm.cc b/source/extensions/common/wasm/wasm_vm.cc index 9f888b18f8f57..2dfc4ce118f4f 100644 --- a/source/extensions/common/wasm/wasm_vm.cc +++ b/source/extensions/common/wasm/wasm_vm.cc @@ -15,7 +15,7 @@ #include "include/proxy-wasm/v8.h" #endif #if defined(ENVOY_WASM_WAVM) -#include "include/proxy-wasm/wavm.h" +#include "include/proxy-wasm/wasmtime.h" #endif using ContextBase = proxy_wasm::ContextBase; @@ -79,7 +79,7 @@ WasmVmPtr createWasmVm(absl::string_view runtime, const Stats::ScopeSharedPtr& s #endif #if defined(ENVOY_WASM_WAVM) } else if (runtime == WasmRuntimeNames::get().Wavm) { - auto wasm = proxy_wasm::createWavmVm(); + auto wasm = proxy_wasm::createWasmtimeVm(); wasm->integration() = getWasmExtension()->createEnvoyWasmVmIntegration(scope, runtime, "wavm"); return wasm; #endif From ac09b65bd1e2790426c6a3cab349eb44d180ef34 Mon Sep 17 00:00:00 2001 From: mathetake Date: Sat, 7 Nov 2020 16:07:07 +0900 Subject: [PATCH 02/31] add build files for wasmtime/c-api Signed-off-by: mathetake --- bazel/external/wasmtime-c-api.BUILD | 15 +++++++++++++ bazel/external/wasmtime.BUILD | 35 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 bazel/external/wasmtime-c-api.BUILD create mode 100644 bazel/external/wasmtime.BUILD diff --git a/bazel/external/wasmtime-c-api.BUILD b/bazel/external/wasmtime-c-api.BUILD new file mode 100644 index 0000000000000..577e68b7c56ef --- /dev/null +++ b/bazel/external/wasmtime-c-api.BUILD @@ -0,0 +1,15 @@ +licenses(["notice"]) # Apache 2 + +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "lib", + hdrs = [ + "include/wasm.h", + ], + defines = ["ENVOY_WASM_WAVM"], + include_prefix = "wasmtime", + deps = [ + "@com_github_wasmtime//:rust_c_api", + ], +) diff --git a/bazel/external/wasmtime.BUILD b/bazel/external/wasmtime.BUILD new file mode 100644 index 0000000000000..fa5004dd05b5d --- /dev/null +++ b/bazel/external/wasmtime.BUILD @@ -0,0 +1,35 @@ +load("@io_bazel_rules_rust//rust:rust.bzl", "rust_library") + +licenses(["notice"]) # Apache 2 + +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "helpers_lib", + srcs = [ + "crates/runtime/src/helpers.c", + ], + visibility = ["//visibility:private"], +) + +rust_library( + name = "rust_c_api", + srcs = glob(["crates/c-api/src/**/*.rs"]), + crate_features = [ + "jitdump", + "cache", + ], + crate_root = "crates/c-api/src/lib.rs", + crate_type = "staticlib", + edition = "2018", + proc_macro_deps = [ + "@proxy_wasm_cpp_host//bazel/cargo:wasmtime_c_api_macros", + ], + deps = [ + ":helpers_lib", + "@proxy_wasm_cpp_host//bazel/cargo:anyhow", + "@proxy_wasm_cpp_host//bazel/cargo:env_logger", + "@proxy_wasm_cpp_host//bazel/cargo:once_cell", + "@proxy_wasm_cpp_host//bazel/cargo:wasmtime", + ], +) From 3f62cc67141c6f3d229bc70ed737073087ca10ac Mon Sep 17 00:00:00 2001 From: mathetake Date: Sat, 7 Nov 2020 16:49:56 +0900 Subject: [PATCH 03/31] fix doc checks Signed-off-by: mathetake --- bazel/repository_locations.bzl | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 82ffbc74ff5ca..5d8b20fcb6a33 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -622,7 +622,7 @@ REPOSITORY_LOCATIONS_SPEC = dict( version = "0.20.0", sha256 = "feb29c96e053d16fe3dc91b93d7a28ab24b9c390fbdf2580547ae7fa0b8eae95", strip_prefix = "wasmtime-{version}", - urls = ["https://github.com//bytecodealliance/wasmtime/archive/v{version}.tar.gz"], + urls = ["https://github.com/bytecodealliance/wasmtime/archive/v{version}.tar.gz"], release_date = "2020-11-04", use_category = ["dataplane_ext"], extensions = [ @@ -638,10 +638,10 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "wasmtime-c-api", project_desc = "wasmtime's c-api header files", project_url = "https://github.com/bytecodealliance/wasmtime", - version = "v0.20.0", + version = "0.20.0", sha256 = "fdbd6dbb58d15b3566abcc2c62ab18c348027e1620bc2ba0219017999504000e", - strip_prefix = "wasmtime-{version}-x86_64-linux-c-api", - urls = ["https://github.com/bytecodealliance/wasmtime/releases/download/{version}/wasmtime-{version}-x86_64-linux-c-api.tar.xz"], + strip_prefix = "wasmtime-v{version}-x86_64-linux-c-api", + urls = ["https://github.com/bytecodealliance/wasmtime/releases/download/v{version}/wasmtime-v{version}-x86_64-linux-c-api.tar.xz"], release_date = "2020-11-04", use_category = ["dataplane_ext"], extensions = [ @@ -902,8 +902,16 @@ REPOSITORY_LOCATIONS_SPEC = dict( sha256 = "426a7712af597d90301dcc29e63d62de5c2e09fb347692e89abb775ec97c74fe", strip_prefix = "rules_rust-{version}", urls = ["https://github.com/bazelbuild/rules_rust/archive/{version}.tar.gz"], - use_category = ["test_only"], + use_category = ["dataplane_ext"], + extensions = [ + "envoy.access_loggers.wasm", + "envoy.bootstrap.wasm", + "envoy.filters.http.wasm", + "envoy.filters.network.wasm", + "envoy.stat_sinks.wasm", + ], release_date = "2020-10-21", + cpe = "N/A", ), rules_antlr = dict( project_name = "ANTLR Rules for Bazel", From 6c370918c9a83f6311b8bc3cc3db41c4371bcaa5 Mon Sep 17 00:00:00 2001 From: mathetake Date: Sat, 7 Nov 2020 18:42:23 +0900 Subject: [PATCH 04/31] update proxy-wasm-cpp-host Signed-off-by: mathetake --- bazel/repository_locations.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 5d8b20fcb6a33..88c6bfe0e5259 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -868,8 +868,8 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "WebAssembly for Proxies (C++ host implementation)", project_desc = "WebAssembly for Proxies (C++ host implementation)", project_url = "https://github.com/proxy-wasm/proxy-wasm-cpp-host", - version = "4a0bbd8370703e0e3196abcd8b732f18f868790a", - sha256 = "65ee4c7aa9a9f6dd39b4cbd77016f7057b7ca145003b8b5da7a2303893e1b809", + version = "fcfd971ef3443cf447097d834e41306ac735a612", + sha256 = "45a4bbf99cf48b59792755c1fde59cf338b6547cedaf6909b459d11866b3adc2", strip_prefix = "proxy-wasm-cpp-host-{version}", urls = ["https://github.com/mathetake/proxy-wasm-cpp-host/archive/{version}.tar.gz"], use_category = ["dataplane_ext"], From 4b4f8b2d7d93d284807cfe98d9b10b986516154f Mon Sep 17 00:00:00 2001 From: mathetake Date: Sat, 7 Nov 2020 20:29:09 +0900 Subject: [PATCH 05/31] remove unnecessary wasmtime features Signed-off-by: mathetake --- bazel/external/wasmtime-c-api.BUILD | 7 ++++++- bazel/external/wasmtime.BUILD | 5 +---- source/extensions/common/wasm/wasm_vm.cc | 12 +++++++++++- source/extensions/common/wasm/well_known_names.h | 2 ++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/bazel/external/wasmtime-c-api.BUILD b/bazel/external/wasmtime-c-api.BUILD index 577e68b7c56ef..ac419e41a79a2 100644 --- a/bazel/external/wasmtime-c-api.BUILD +++ b/bazel/external/wasmtime-c-api.BUILD @@ -1,3 +1,5 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + licenses(["notice"]) # Apache 2 package(default_visibility = ["//visibility:public"]) @@ -7,7 +9,10 @@ cc_library( hdrs = [ "include/wasm.h", ], - defines = ["ENVOY_WASM_WAVM"], + defines = [ + "ENVOY_WASM_WAVM", # TODO: delete + "ENVOY_WASM_WASMTIME", + ], include_prefix = "wasmtime", deps = [ "@com_github_wasmtime//:rust_c_api", diff --git a/bazel/external/wasmtime.BUILD b/bazel/external/wasmtime.BUILD index fa5004dd05b5d..edb2ab30367ee 100644 --- a/bazel/external/wasmtime.BUILD +++ b/bazel/external/wasmtime.BUILD @@ -1,3 +1,4 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") load("@io_bazel_rules_rust//rust:rust.bzl", "rust_library") licenses(["notice"]) # Apache 2 @@ -15,10 +16,6 @@ cc_library( rust_library( name = "rust_c_api", srcs = glob(["crates/c-api/src/**/*.rs"]), - crate_features = [ - "jitdump", - "cache", - ], crate_root = "crates/c-api/src/lib.rs", crate_type = "staticlib", edition = "2018", diff --git a/source/extensions/common/wasm/wasm_vm.cc b/source/extensions/common/wasm/wasm_vm.cc index 2dfc4ce118f4f..b32a589bb28f2 100644 --- a/source/extensions/common/wasm/wasm_vm.cc +++ b/source/extensions/common/wasm/wasm_vm.cc @@ -15,6 +15,9 @@ #include "include/proxy-wasm/v8.h" #endif #if defined(ENVOY_WASM_WAVM) +#include "include/proxy-wasm/wavm.h" +#endif +#if defined(ENVOY_WASM_WASMTIME) #include "include/proxy-wasm/wasmtime.h" #endif @@ -79,9 +82,16 @@ WasmVmPtr createWasmVm(absl::string_view runtime, const Stats::ScopeSharedPtr& s #endif #if defined(ENVOY_WASM_WAVM) } else if (runtime == WasmRuntimeNames::get().Wavm) { - auto wasm = proxy_wasm::createWasmtimeVm(); + auto wasm = proxy_wasm::createWasmtimeVm(); // TODO: revert to WAVM wasm->integration() = getWasmExtension()->createEnvoyWasmVmIntegration(scope, runtime, "wavm"); return wasm; +#endif +#if defined(ENVOY_WASM_WASMTIME) + } else if (runtime == WasmRuntimeNames::get().Wasmtime) { + auto wasm = proxy_wasm::createWasmtimeVm(); + wasm->integration() = + getWasmExtension()->createEnvoyWasmVmIntegration(scope, runtime, "wasmtime"); + return wasm; #endif } else { ENVOY_LOG_TO_LOGGER( diff --git a/source/extensions/common/wasm/well_known_names.h b/source/extensions/common/wasm/well_known_names.h index 5fb8602bf831d..1175d796bb687 100644 --- a/source/extensions/common/wasm/well_known_names.h +++ b/source/extensions/common/wasm/well_known_names.h @@ -15,6 +15,8 @@ namespace Wasm { */ class WasmRuntimeValues { public: + // wasmtime (https://github.com/bytecodealliance/wasmtime). + const std::string Wasmtime = "envoy.wasm.runtime.wasmtime"; // WAVM (https://github.com/WAVM/WAVM) Wasm VM. const std::string Wavm = "envoy.wasm.runtime.wavm"; // Null sandbox: modules must be compiled into envoy and registered name is given in the From eb72994f84da254e1f59448e8c572069e1c12093 Mon Sep 17 00:00:00 2001 From: mathetake Date: Sat, 7 Nov 2020 22:07:21 +0900 Subject: [PATCH 06/31] add wasmtime to dictionary Signed-off-by: mathetake --- tools/spelling/spelling_dictionary.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/spelling/spelling_dictionary.txt b/tools/spelling/spelling_dictionary.txt index 53d6dc677a7d4..d9bcdc021e43e 100644 --- a/tools/spelling/spelling_dictionary.txt +++ b/tools/spelling/spelling_dictionary.txt @@ -1207,6 +1207,7 @@ wakeup wakeups websocket wepoll +wasmtime whitespace whitespaces wildcard From a67720a88450058474d2915a71b121a29a842fb4 Mon Sep 17 00:00:00 2001 From: mathetake Date: Sun, 8 Nov 2020 00:31:50 +0900 Subject: [PATCH 07/31] define ENVOY_WASM_WASMTIME Signed-off-by: mathetake --- bazel/BUILD | 5 +++ bazel/envoy_build_system.bzl | 2 ++ bazel/envoy_select.bzl | 12 +++++-- bazel/external/proxy_wasm_cpp_host.BUILD | 22 +++++++++++-- bazel/external/wasmtime-c-api.BUILD | 1 - source/extensions/common/wasm/wasm_vm.cc | 2 +- .../access_loggers/wasm/config_test.cc | 3 ++ test/extensions/bootstrap/wasm/config_test.cc | 3 ++ test/extensions/bootstrap/wasm/wasm_test.cc | 32 ++++++++++++++----- test/extensions/common/wasm/wasm_test.cc | 3 ++ .../filters/http/wasm/config_test.cc | 11 +++++-- .../filters/http/wasm/wasm_filter_test.cc | 5 ++- .../filters/network/wasm/config_test.cc | 3 ++ .../filters/network/wasm/wasm_filter_test.cc | 3 ++ .../stats_sinks/wasm/config_test.cc | 3 ++ .../stats_sinks/wasm/wasm_stat_sink_test.cc | 3 ++ tools/spelling/spelling_dictionary.txt | 2 +- 17 files changed, 97 insertions(+), 18 deletions(-) diff --git a/bazel/BUILD b/bazel/BUILD index d03b931018a3a..d2ad3d898c6fe 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -330,6 +330,11 @@ config_setting( values = {"define": "wasm=v8"}, ) +config_setting( + name = "wasm_wasmtime", + values = {"define": "wasm=wasmtime"}, +) + config_setting( name = "wasm_none", values = {"define": "wasm=disabled"}, diff --git a/bazel/envoy_build_system.bzl b/bazel/envoy_build_system.bzl index e95329095dcae..a1a78f7c3be30 100644 --- a/bazel/envoy_build_system.bzl +++ b/bazel/envoy_build_system.bzl @@ -22,6 +22,7 @@ load( _envoy_select_wasm = "envoy_select_wasm", _envoy_select_wasm_all_v8_wavm_none = "envoy_select_wasm_all_v8_wavm_none", _envoy_select_wasm_v8 = "envoy_select_wasm_v8", + _envoy_select_wasm_wasmtime = "envoy_select_wasm_wasmtime", _envoy_select_wasm_wavm = "envoy_select_wasm_wavm", ) load( @@ -183,6 +184,7 @@ envoy_select_hot_restart = _envoy_select_hot_restart envoy_select_wasm = _envoy_select_wasm envoy_select_wasm_all_v8_wavm_none = _envoy_select_wasm_all_v8_wavm_none envoy_select_wasm_wavm = _envoy_select_wasm_wavm +envoy_select_wasm_wasmtime = _envoy_select_wasm_wasmtime envoy_select_wasm_v8 = _envoy_select_wasm_v8 envoy_select_new_codecs_in_integration_tests = _envoy_select_new_codecs_in_integration_tests diff --git a/bazel/envoy_select.bzl b/bazel/envoy_select.bzl index 5a33e4da515d6..1abdae857e517 100644 --- a/bazel/envoy_select.bzl +++ b/bazel/envoy_select.bzl @@ -41,6 +41,7 @@ def envoy_select_wasm(xs): def envoy_select_wasm_v8(xs): return select({ + "@envoy//bazel:wasm_wasmtime": [], "@envoy//bazel:wasm_wavm": [], "@envoy//bazel:wasm_none": [], "//conditions:default": xs, @@ -53,12 +54,19 @@ def envoy_select_wasm_wavm(xs): "//conditions:default": [], }) -def envoy_select_wasm_all_v8_wavm_none(xs1, xs2, xs3, xs4): +def envoy_select_wasm_wasmtime(xs): + return select({ + "@envoy//bazel:wasm_wasmtime": xs, + "//conditions:default": [], + }) + +def envoy_select_wasm_all_v8_wavm_none(xs1, xs2, xs3, xs4, xs5): return select({ "@envoy//bazel:wasm_all": xs1, "@envoy//bazel:wasm_v8": xs2, "@envoy//bazel:wasm_wavm": xs3, - "@envoy//bazel:wasm_none": xs4, + "@envoy//bazel:wasm_wasmtime": xs4, + "@envoy//bazel:wasm_none": xs5, "//conditions:default": xs2, }) diff --git a/bazel/external/proxy_wasm_cpp_host.BUILD b/bazel/external/proxy_wasm_cpp_host.BUILD index b73d1c4d92b3e..3e1a9fc513178 100644 --- a/bazel/external/proxy_wasm_cpp_host.BUILD +++ b/bazel/external/proxy_wasm_cpp_host.BUILD @@ -3,6 +3,7 @@ load( "@envoy//bazel:envoy_build_system.bzl", "envoy_select_wasm_all_v8_wavm_none", "envoy_select_wasm_v8", + "envoy_select_wasm_wasmtime", "envoy_select_wasm_wavm", ) @@ -27,6 +28,12 @@ cc_library( "src/**/*.h", "src/**/*.cc", ], + exclude = [ + # TODO: currently we cannot link wasmtime with (v8, WAVM) due to symbol collision: + # - V8: wasm-c-api symbols + # - WAVM: LLVM's gdb JIT interface related symbols + "src/wasmtime/*", + ], ), glob( [ @@ -38,6 +45,16 @@ cc_library( "src/wasmtime/*", ], ), + glob( + [ + "src/**/*.h", + "src/**/*.cc", + ], + exclude = [ + "src/v8/*", + "src/wasmtime/*", + ], + ), glob( [ "src/**/*.h", @@ -76,9 +93,10 @@ cc_library( "@proxy_wasm_cpp_sdk//:api_lib", "@proxy_wasm_cpp_sdk//:common_lib", ] + envoy_select_wasm_wavm([ - "@com_github_wasmtime_c_api//:lib", - # "@envoy//bazel/foreign_cc:wavm", + "@envoy//bazel/foreign_cc:wavm", ]) + envoy_select_wasm_v8([ "//external:wee8", + ]) + envoy_select_wasm_wasmtime([ + "@com_github_wasmtime_c_api//:lib", ]), ) diff --git a/bazel/external/wasmtime-c-api.BUILD b/bazel/external/wasmtime-c-api.BUILD index ac419e41a79a2..de1aff799a0c3 100644 --- a/bazel/external/wasmtime-c-api.BUILD +++ b/bazel/external/wasmtime-c-api.BUILD @@ -10,7 +10,6 @@ cc_library( "include/wasm.h", ], defines = [ - "ENVOY_WASM_WAVM", # TODO: delete "ENVOY_WASM_WASMTIME", ], include_prefix = "wasmtime", diff --git a/source/extensions/common/wasm/wasm_vm.cc b/source/extensions/common/wasm/wasm_vm.cc index b32a589bb28f2..5b482e6bb8470 100644 --- a/source/extensions/common/wasm/wasm_vm.cc +++ b/source/extensions/common/wasm/wasm_vm.cc @@ -82,7 +82,7 @@ WasmVmPtr createWasmVm(absl::string_view runtime, const Stats::ScopeSharedPtr& s #endif #if defined(ENVOY_WASM_WAVM) } else if (runtime == WasmRuntimeNames::get().Wavm) { - auto wasm = proxy_wasm::createWasmtimeVm(); // TODO: revert to WAVM + auto wasm = proxy_wasm::createWavmVm(); wasm->integration() = getWasmExtension()->createEnvoyWasmVmIntegration(scope, runtime, "wavm"); return wasm; #endif diff --git a/test/extensions/access_loggers/wasm/config_test.cc b/test/extensions/access_loggers/wasm/config_test.cc index 02a71c9132b74..744f074fdb8cd 100644 --- a/test/extensions/access_loggers/wasm/config_test.cc +++ b/test/extensions/access_loggers/wasm/config_test.cc @@ -47,6 +47,9 @@ auto testing_values = testing::Values( #endif #if defined(ENVOY_WASM_WAVM) "wavm", +#endif +#if defined(ENVOY_WASM_WASMTIME) + "wasmtime", #endif "null"); INSTANTIATE_TEST_SUITE_P(Runtimes, WasmAccessLogConfigTest, testing_values); diff --git a/test/extensions/bootstrap/wasm/config_test.cc b/test/extensions/bootstrap/wasm/config_test.cc index 6fb99261a3f88..bd5d4b9471662 100644 --- a/test/extensions/bootstrap/wasm/config_test.cc +++ b/test/extensions/bootstrap/wasm/config_test.cc @@ -75,6 +75,9 @@ auto testing_values = testing::Values( #endif #if defined(ENVOY_WASM_WAVM) "wavm", +#endif +#if defined(ENVOY_WASM_WASMTIME) + "wasmtime", #endif "null"); INSTANTIATE_TEST_SUITE_P(Runtimes, WasmFactoryTest, testing_values); diff --git a/test/extensions/bootstrap/wasm/wasm_test.cc b/test/extensions/bootstrap/wasm/wasm_test.cc index 2befcbd97cba7..037eff3e09187 100644 --- a/test/extensions/bootstrap/wasm/wasm_test.cc +++ b/test/extensions/bootstrap/wasm/wasm_test.cc @@ -73,7 +73,7 @@ class WasmTestBase { std::shared_ptr wasm_; }; -#if defined(ENVOY_WASM_V8) || defined(ENVOY_WASM_WAVM) +#if defined(ENVOY_WASM_V8) || defined(ENVOY_WASM_WAVM) || defined(ENVOY_WASM_WASMTIME) class WasmTest : public WasmTestBase, public testing::TestWithParam { public: void createWasm() { WasmTestBase::createWasm(GetParam()); } @@ -85,13 +85,20 @@ auto testing_values = testing::Values( #if defined(ENVOY_WASM_V8) "v8" #endif -#if defined(ENVOY_WASM_V8) && defined(ENVOY_WASM_WAVM) +#if defined(ENVOY_WASM_V8) && (defined(ENVOY_WASM_WAVM) || defined(ENVOY_WASM_WASMTIME)) , #endif #if defined(ENVOY_WASM_WAVM) "wavm" #endif +#if (defined(ENVOY_WASM_V8) || defined(ENVOY_WASM_WAVM)) && defined(ENVOY_WASM_WASMTIME) + , +#endif +#if defined(ENVOY_WASM_WASMTIME) + "wasmtime" +#endif ); + INSTANTIATE_TEST_SUITE_P(Runtimes, WasmTest, testing_values); #endif @@ -117,11 +124,14 @@ auto testing_null_values = testing::Values( #endif #if defined(ENVOY_WASM_WAVM) "wavm", +#endif +#if defined(ENVOY_WASM_WASMTIME) + "wasmtime", #endif "null"); INSTANTIATE_TEST_SUITE_P(Runtimes, WasmNullTest, testing_null_values); -#if defined(ENVOY_WASM_V8) || defined(ENVOY_WASM_WAVM) +#if defined(ENVOY_WASM_V8) || defined(ENVOY_WASM_WAVM) || defined(ENVOY_WASM_WASMTIME) class WasmTestMatrix : public WasmTestBase, public testing::TestWithParam> { public: @@ -143,13 +153,19 @@ class WasmTestMatrix : public WasmTestBase, INSTANTIATE_TEST_SUITE_P(RuntimesAndLanguages, WasmTestMatrix, testing::Combine(testing::Values( #if defined(ENVOY_WASM_V8) - "v8" + "v8" #endif -#if defined(ENVOY_WASM_V8) && defined(ENVOY_WASM_WAVM) - , +#if defined(ENVOY_WASM_V8) && (defined(ENVOY_WASM_WAVM) || defined(ENVOY_WASM_WASMTIME)) + , #endif #if defined(ENVOY_WASM_WAVM) - "wavm" + "wavm" +#endif +#if (defined(ENVOY_WASM_V8) || defined(ENVOY_WASM_WAVM)) && defined(ENVOY_WASM_WASMTIME) + , +#endif +#if defined(ENVOY_WASM_WASMTIME) + "wasmtime" #endif ), testing::Values("cpp", "rust"))); @@ -188,7 +204,7 @@ TEST_P(WasmTestMatrix, Logging) { } #endif -#if defined(ENVOY_WASM_V8) || defined(ENVOY_WASM_WAVM) +#if defined(ENVOY_WASM_V8) || defined(ENVOY_WASM_WAVM) || defined(ENVOY_WASM_WASMTIME) TEST_P(WasmTest, BadSignature) { createWasm(); const auto code = TestEnvironment::readFileToStringForTest(TestEnvironment::substitute( diff --git a/test/extensions/common/wasm/wasm_test.cc b/test/extensions/common/wasm/wasm_test.cc index 0c84105cd778e..110f7f720eec4 100644 --- a/test/extensions/common/wasm/wasm_test.cc +++ b/test/extensions/common/wasm/wasm_test.cc @@ -97,6 +97,9 @@ auto test_values = testing::Values( #endif #if defined(ENVOY_WASM_WAVM) "wavm", +#endif +#if defined(ENVOY_WASM_WASMTIME) + "wasmtime", #endif "null"); INSTANTIATE_TEST_SUITE_P(Runtimes, WasmCommonTest, test_values); diff --git a/test/extensions/filters/http/wasm/config_test.cc b/test/extensions/filters/http/wasm/config_test.cc index 6b41185f79132..552aa61a9387a 100644 --- a/test/extensions/filters/http/wasm/config_test.cc +++ b/test/extensions/filters/http/wasm/config_test.cc @@ -29,7 +29,7 @@ using Common::Wasm::WasmException; namespace HttpFilters { namespace Wasm { -#if defined(ENVOY_WASM_V8) || defined(ENVOY_WASM_WAVM) +#if defined(ENVOY_WASM_V8) || defined(ENVOY_WASM_WAVM) || defined(ENVOY_WASM_WASMTIME) class WasmFilterConfigTest : public Event::TestUsingSimulatedTime, public testing::TestWithParam { protected: @@ -71,13 +71,20 @@ auto testing_values = testing::Values( #if defined(ENVOY_WASM_V8) "v8" #endif -#if defined(ENVOY_WASM_V8) && defined(ENVOY_WASM_WAVM) +#if defined(ENVOY_WASM_V8) && (defined(ENVOY_WASM_WAVM) || defined(ENVOY_WASM_WASMTIME)) , #endif #if defined(ENVOY_WASM_WAVM) "wavm" #endif +#if (defined(ENVOY_WASM_V8) || defined(ENVOY_WASM_WAVM)) && defined(ENVOY_WASM_WASMTIME) + , +#endif +#if defined(ENVOY_WASM_WASMTIME) + "wasmtime" +#endif ); + INSTANTIATE_TEST_SUITE_P(Runtimes, WasmFilterConfigTest, testing_values); TEST_P(WasmFilterConfigTest, JsonLoadFromFileWasm) { diff --git a/test/extensions/filters/http/wasm/wasm_filter_test.cc b/test/extensions/filters/http/wasm/wasm_filter_test.cc index 538481f36f6c8..4515c29f98b3f 100644 --- a/test/extensions/filters/http/wasm/wasm_filter_test.cc +++ b/test/extensions/filters/http/wasm/wasm_filter_test.cc @@ -102,6 +102,9 @@ auto testing_values = testing::Values( #endif #if defined(ENVOY_WASM_WAVM) std::make_tuple("wavm", "cpp"), std::make_tuple("wavm", "rust"), +#endif +#if defined(ENVOY_WASM_WASMTIME) + std::make_tuple("wasmtime", "cpp"), std::make_tuple("wasmtime", "rust"), #endif std::make_tuple("null", "cpp")); INSTANTIATE_TEST_SUITE_P(RuntimesAndLanguages, WasmHttpFilterTest, testing_values); @@ -1208,7 +1211,7 @@ TEST_P(WasmHttpFilterTest, GrpcStreamOpenAtShutdown) { // Test metadata access including CEL expressions. // TODO: re-enable this on Windows if and when the CEL `Antlr` parser compiles on Windows. -#if defined(ENVOY_WASM_V8) || defined(ENVOY_WASM_WAVM) +#if defined(ENVOY_WASM_V8) || defined(ENVOY_WASM_WAVM) || defined(ENVOY_WASM_WASMTIME) TEST_P(WasmHttpFilterTest, Metadata) { setupTest("", "metadata"); setupFilter(); diff --git a/test/extensions/filters/network/wasm/config_test.cc b/test/extensions/filters/network/wasm/config_test.cc index 58d17c177fb7b..f1507071ef781 100644 --- a/test/extensions/filters/network/wasm/config_test.cc +++ b/test/extensions/filters/network/wasm/config_test.cc @@ -64,6 +64,9 @@ auto testing_values = testing::Values( #endif #if defined(ENVOY_WASM_WAVM) "wavm", +#endif +#if defined(ENVOY_WASM_WASMTIME) + "wasmtime", #endif "null"); INSTANTIATE_TEST_SUITE_P(Runtimes, WasmNetworkFilterConfigTest, testing_values); diff --git a/test/extensions/filters/network/wasm/wasm_filter_test.cc b/test/extensions/filters/network/wasm/wasm_filter_test.cc index 6bf1ca8151e63..dd3a2e29a0c2a 100644 --- a/test/extensions/filters/network/wasm/wasm_filter_test.cc +++ b/test/extensions/filters/network/wasm/wasm_filter_test.cc @@ -90,6 +90,9 @@ auto testing_values = testing::Values( #endif #if defined(ENVOY_WASM_WAVM) std::make_tuple("wavm", "cpp"), std::make_tuple("wavm", "rust"), +#endif +#if defined(ENVOY_WASM_WASMTIME) + std::make_tuple("wasmtime", "cpp"), std::make_tuple("wasmtime", "rust"), #endif std::make_tuple("null", "cpp")); INSTANTIATE_TEST_SUITE_P(RuntimesAndLanguages, WasmNetworkFilterTest, testing_values); diff --git a/test/extensions/stats_sinks/wasm/config_test.cc b/test/extensions/stats_sinks/wasm/config_test.cc index 1e115dd2f9465..d9b1263215afd 100644 --- a/test/extensions/stats_sinks/wasm/config_test.cc +++ b/test/extensions/stats_sinks/wasm/config_test.cc @@ -73,6 +73,9 @@ auto testing_values = testing::Values( #endif #if defined(ENVOY_WASM_WAVM) "wavm", +#endif +#if defined(ENVOY_WASM_WASMTIME) + "wasmtime", #endif "null"); INSTANTIATE_TEST_SUITE_P(Runtimes, WasmStatSinkConfigTest, testing_values); diff --git a/test/extensions/stats_sinks/wasm/wasm_stat_sink_test.cc b/test/extensions/stats_sinks/wasm/wasm_stat_sink_test.cc index acd4df85dbde3..716925bfd12fc 100644 --- a/test/extensions/stats_sinks/wasm/wasm_stat_sink_test.cc +++ b/test/extensions/stats_sinks/wasm/wasm_stat_sink_test.cc @@ -62,6 +62,9 @@ auto testing_values = testing::Values( #endif #if defined(ENVOY_WASM_WAVM) "wavm", +#endif +#if defined(ENVOY_WASM_WASMTIME) + "wasmtime", #endif "null"); INSTANTIATE_TEST_SUITE_P(Runtimes, WasmCommonContextTest, testing_values); diff --git a/tools/spelling/spelling_dictionary.txt b/tools/spelling/spelling_dictionary.txt index d9bcdc021e43e..b0c7a7c98d5e2 100644 --- a/tools/spelling/spelling_dictionary.txt +++ b/tools/spelling/spelling_dictionary.txt @@ -1205,9 +1205,9 @@ virtualize vptr wakeup wakeups +wasmtime websocket wepoll -wasmtime whitespace whitespaces wildcard From 893a914d20f657c118f5d4c403f90125dbcc9147 Mon Sep 17 00:00:00 2001 From: mathetake Date: Sun, 8 Nov 2020 00:39:54 +0900 Subject: [PATCH 08/31] define=wasmtime in bazel.compile_time_options Signed-off-by: mathetake --- ci/do_ci.sh | 2 +- test/extensions/bootstrap/wasm/wasm_test.cc | 10 +++++----- test/extensions/common/wasm/wasm_test.cc | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 8a9e681821159..eabb7393cd918 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -280,7 +280,7 @@ elif [[ "$CI_TARGET" == "bazel.compile_time_options" ]]; then "--define" "boringssl=fips" "--define" "log_debug_assert_in_release=enabled" "--define" "quiche=enabled" - "--define" "wasm=wavm" + "--define" "wasm=wasmtime" "--define" "path_normalization_by_default=true" "--define" "deprecated_features=disabled" "--define" "use_new_codecs_in_integration_tests=false" diff --git a/test/extensions/bootstrap/wasm/wasm_test.cc b/test/extensions/bootstrap/wasm/wasm_test.cc index 037eff3e09187..fdfdd9536557e 100644 --- a/test/extensions/bootstrap/wasm/wasm_test.cc +++ b/test/extensions/bootstrap/wasm/wasm_test.cc @@ -153,19 +153,19 @@ class WasmTestMatrix : public WasmTestBase, INSTANTIATE_TEST_SUITE_P(RuntimesAndLanguages, WasmTestMatrix, testing::Combine(testing::Values( #if defined(ENVOY_WASM_V8) - "v8" + "v8" #endif #if defined(ENVOY_WASM_V8) && (defined(ENVOY_WASM_WAVM) || defined(ENVOY_WASM_WASMTIME)) - , + , #endif #if defined(ENVOY_WASM_WAVM) - "wavm" + "wavm" #endif #if (defined(ENVOY_WASM_V8) || defined(ENVOY_WASM_WAVM)) && defined(ENVOY_WASM_WASMTIME) - , + , #endif #if defined(ENVOY_WASM_WASMTIME) - "wasmtime" + "wasmtime" #endif ), testing::Values("cpp", "rust"))); diff --git a/test/extensions/common/wasm/wasm_test.cc b/test/extensions/common/wasm/wasm_test.cc index 110f7f720eec4..4bd138eec8cc2 100644 --- a/test/extensions/common/wasm/wasm_test.cc +++ b/test/extensions/common/wasm/wasm_test.cc @@ -21,6 +21,7 @@ #include "openssl/sha.h" #include "zlib.h" + using Envoy::Server::ServerLifecycleNotifier; using StageCallbackWithCompletion = Envoy::Server::ServerLifecycleNotifier::StageCallbackWithCompletion; From 28aefc439bf8248d3e67204494f32c377cf7a5ce Mon Sep 17 00:00:00 2001 From: mathetake Date: Sun, 8 Nov 2020 01:16:00 +0900 Subject: [PATCH 09/31] fix format Signed-off-by: mathetake --- test/extensions/common/wasm/wasm_test.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/test/extensions/common/wasm/wasm_test.cc b/test/extensions/common/wasm/wasm_test.cc index 4bd138eec8cc2..110f7f720eec4 100644 --- a/test/extensions/common/wasm/wasm_test.cc +++ b/test/extensions/common/wasm/wasm_test.cc @@ -21,7 +21,6 @@ #include "openssl/sha.h" #include "zlib.h" - using Envoy::Server::ServerLifecycleNotifier; using StageCallbackWithCompletion = Envoy::Server::ServerLifecycleNotifier::StageCallbackWithCompletion; From a871b148ed85f7be78c6b8df6b4f43b555813a30 Mon Sep 17 00:00:00 2001 From: mathetake Date: Sun, 8 Nov 2020 15:33:00 +0900 Subject: [PATCH 10/31] update wasmtime to 0.21.0 Signed-off-by: mathetake --- bazel/repository_locations.bzl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 88c6bfe0e5259..70ba4cf86fe4e 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -619,8 +619,8 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "wasmtime", project_desc = "A standalone runtime for WebAssembly", project_url = "https://github.com/bytecodealliance/wasmtime", - version = "0.20.0", - sha256 = "feb29c96e053d16fe3dc91b93d7a28ab24b9c390fbdf2580547ae7fa0b8eae95", + version = "0.21.0", + sha256 = "7874feb1026bbef06796bd5ab80e73f15b8e83752bde8dc93994f5bc039a4952", strip_prefix = "wasmtime-{version}", urls = ["https://github.com/bytecodealliance/wasmtime/archive/v{version}.tar.gz"], release_date = "2020-11-04", @@ -638,8 +638,8 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "wasmtime-c-api", project_desc = "wasmtime's c-api header files", project_url = "https://github.com/bytecodealliance/wasmtime", - version = "0.20.0", - sha256 = "fdbd6dbb58d15b3566abcc2c62ab18c348027e1620bc2ba0219017999504000e", + version = "0.21.0", + sha256 = "c0d4c9209ee25933665c2cfd9d5ff0956c02d4c52f57dfd61fb31fb7baa37f2a", strip_prefix = "wasmtime-v{version}-x86_64-linux-c-api", urls = ["https://github.com/bytecodealliance/wasmtime/releases/download/v{version}/wasmtime-v{version}-x86_64-linux-c-api.tar.xz"], release_date = "2020-11-04", @@ -868,8 +868,8 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "WebAssembly for Proxies (C++ host implementation)", project_desc = "WebAssembly for Proxies (C++ host implementation)", project_url = "https://github.com/proxy-wasm/proxy-wasm-cpp-host", - version = "fcfd971ef3443cf447097d834e41306ac735a612", - sha256 = "45a4bbf99cf48b59792755c1fde59cf338b6547cedaf6909b459d11866b3adc2", + version = "eab25ddd87fca08432d3ca806684b7fb3f89d56b", + sha256 = "c8a63922447b2cd51099d85d6042463f93eb062a0b26b8e72a8cec021384c29c", strip_prefix = "proxy-wasm-cpp-host-{version}", urls = ["https://github.com/mathetake/proxy-wasm-cpp-host/archive/{version}.tar.gz"], use_category = ["dataplane_ext"], From b156df5146da1e3e003829cc9cdc9c65bd99dc48 Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 10 Nov 2020 11:48:01 +0900 Subject: [PATCH 11/31] use wasm-c-api archive Signed-off-by: mathetake --- bazel/external/proxy_wasm_cpp_host.BUILD | 2 +- ...{wasmtime-c-api.BUILD => wasm-c-api.BUILD} | 2 +- bazel/repositories.bzl | 8 ++++---- bazel/repository_locations.bzl | 20 +++++++++---------- 4 files changed, 16 insertions(+), 16 deletions(-) rename bazel/external/{wasmtime-c-api.BUILD => wasm-c-api.BUILD} (92%) diff --git a/bazel/external/proxy_wasm_cpp_host.BUILD b/bazel/external/proxy_wasm_cpp_host.BUILD index 3e1a9fc513178..e2fa8b7dfd6a1 100644 --- a/bazel/external/proxy_wasm_cpp_host.BUILD +++ b/bazel/external/proxy_wasm_cpp_host.BUILD @@ -97,6 +97,6 @@ cc_library( ]) + envoy_select_wasm_v8([ "//external:wee8", ]) + envoy_select_wasm_wasmtime([ - "@com_github_wasmtime_c_api//:lib", + "@com_github_wasm_c_api//:wasmtime_lib", ]), ) diff --git a/bazel/external/wasmtime-c-api.BUILD b/bazel/external/wasm-c-api.BUILD similarity index 92% rename from bazel/external/wasmtime-c-api.BUILD rename to bazel/external/wasm-c-api.BUILD index de1aff799a0c3..abff294cf9c3f 100644 --- a/bazel/external/wasmtime-c-api.BUILD +++ b/bazel/external/wasm-c-api.BUILD @@ -5,7 +5,7 @@ licenses(["notice"]) # Apache 2 package(default_visibility = ["//visibility:public"]) cc_library( - name = "lib", + name = "wasmtime_lib", hdrs = [ "include/wasm.h", ], diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index c3b79b98061c1..557657b894317 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -183,7 +183,7 @@ def envoy_dependencies(skip_targets = []): _org_llvm_llvm() _com_github_wavm_wavm() _com_github_wasmtime() - _com_github_wasmtime_c_api() + _com_github_wasm_c_api() switched_rules_by_language( name = "com_google_googleapis_imports", @@ -872,10 +872,10 @@ def _com_github_wasmtime(): build_file = "@envoy//bazel/external:wasmtime.BUILD", ) -def _com_github_wasmtime_c_api(): +def _com_github_wasm_c_api(): external_http_archive( - name = "com_github_wasmtime_c_api", - build_file = "@envoy//bazel/external:wasmtime-c-api.BUILD", + name = "com_github_wasm_c_api", + build_file = "@envoy//bazel/external:wasm-c-api.BUILD", ) def _kafka_deps(): diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 70ba4cf86fe4e..66d2fd9a4a196 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -634,14 +634,14 @@ REPOSITORY_LOCATIONS_SPEC = dict( ], cpe = "cpe:2.3:a:webassembly_virtual_machine_project:webassembly_virtual_machine:*", ), - com_github_wasmtime_c_api = dict( - project_name = "wasmtime-c-api", - project_desc = "wasmtime's c-api header files", - project_url = "https://github.com/bytecodealliance/wasmtime", - version = "0.21.0", - sha256 = "c0d4c9209ee25933665c2cfd9d5ff0956c02d4c52f57dfd61fb31fb7baa37f2a", - strip_prefix = "wasmtime-v{version}-x86_64-linux-c-api", - urls = ["https://github.com/bytecodealliance/wasmtime/releases/download/v{version}/wasmtime-v{version}-x86_64-linux-c-api.tar.xz"], + com_github_wasm_c_api = dict( + project_name = "wasm-c-api", + project_desc = "WebAssembly C and C++ API", + project_url = "https://github.com/WebAssembly/wasm-c-api", + version = "d9a80099d496b5cdba6f3fe8fc77586e0e505ddc", + sha256 = "aea8cd095e9937f1e14f2c93e026317b197eb2345e7a817fe3932062eb7b792c", + strip_prefix = "wasm-c-api-{version}", + urls = ["https://github.com/WebAssembly/wasm-c-api/archive/{version}.tar.gz"], release_date = "2020-11-04", use_category = ["dataplane_ext"], extensions = [ @@ -868,8 +868,8 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "WebAssembly for Proxies (C++ host implementation)", project_desc = "WebAssembly for Proxies (C++ host implementation)", project_url = "https://github.com/proxy-wasm/proxy-wasm-cpp-host", - version = "eab25ddd87fca08432d3ca806684b7fb3f89d56b", - sha256 = "c8a63922447b2cd51099d85d6042463f93eb062a0b26b8e72a8cec021384c29c", + version = "ba07309719778e9d990012d9086d77b2453f066e", + sha256 = "c583a81e7c3a19d1a27bec18aa470f237247a668aa69cf4c4b2c9642338673ef", strip_prefix = "proxy-wasm-cpp-host-{version}", urls = ["https://github.com/mathetake/proxy-wasm-cpp-host/archive/{version}.tar.gz"], use_category = ["dataplane_ext"], From 6a8d0230297a25a7589585455339ab757b9eb118 Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 10 Nov 2020 12:02:02 +0900 Subject: [PATCH 12/31] Update cpp-host Signed-off-by: mathetake --- bazel/repository_locations.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 66d2fd9a4a196..8cd555c0298ba 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -868,8 +868,8 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "WebAssembly for Proxies (C++ host implementation)", project_desc = "WebAssembly for Proxies (C++ host implementation)", project_url = "https://github.com/proxy-wasm/proxy-wasm-cpp-host", - version = "ba07309719778e9d990012d9086d77b2453f066e", - sha256 = "c583a81e7c3a19d1a27bec18aa470f237247a668aa69cf4c4b2c9642338673ef", + version = "2bdf58fc5bec89544fd18af2a1f8f23dbeccf717", + sha256 = "a733a13a1d5191ac04e21e2f4e87e7021dfbfd89058c64072626911b1ee10986", strip_prefix = "proxy-wasm-cpp-host-{version}", urls = ["https://github.com/mathetake/proxy-wasm-cpp-host/archive/{version}.tar.gz"], use_category = ["dataplane_ext"], From 58e0a0301b9abf28ca9f44dab6116daf1f431937 Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 10 Nov 2020 15:30:56 +0900 Subject: [PATCH 13/31] review: wasmtime -> Wasmtime, update proxy-wasm-cpp-host Signed-off-by: mathetake --- bazel/repository_locations.bzl | 4 ++-- source/extensions/common/wasm/well_known_names.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 8cd555c0298ba..2bff86234fae4 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -868,8 +868,8 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "WebAssembly for Proxies (C++ host implementation)", project_desc = "WebAssembly for Proxies (C++ host implementation)", project_url = "https://github.com/proxy-wasm/proxy-wasm-cpp-host", - version = "2bdf58fc5bec89544fd18af2a1f8f23dbeccf717", - sha256 = "a733a13a1d5191ac04e21e2f4e87e7021dfbfd89058c64072626911b1ee10986", + version = "a584bd1bd8bfe8d1d5b9cc8f88555283e459a314", + sha256 = "d850783c4b0b77fde62eaf4148021e45e424c7a0f6eae1aed07196a9a1f3895d", strip_prefix = "proxy-wasm-cpp-host-{version}", urls = ["https://github.com/mathetake/proxy-wasm-cpp-host/archive/{version}.tar.gz"], use_category = ["dataplane_ext"], diff --git a/source/extensions/common/wasm/well_known_names.h b/source/extensions/common/wasm/well_known_names.h index 1175d796bb687..3904868bba880 100644 --- a/source/extensions/common/wasm/well_known_names.h +++ b/source/extensions/common/wasm/well_known_names.h @@ -15,7 +15,7 @@ namespace Wasm { */ class WasmRuntimeValues { public: - // wasmtime (https://github.com/bytecodealliance/wasmtime). + // Wasmtime (https://github.com/bytecodealliance/wasmtime). const std::string Wasmtime = "envoy.wasm.runtime.wasmtime"; // WAVM (https://github.com/WAVM/WAVM) Wasm VM. const std::string Wavm = "envoy.wasm.runtime.wavm"; From 660257a1baa107f231d6d07d7a9e58cd657cae8f Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Tue, 10 Nov 2020 08:19:00 +0000 Subject: [PATCH 14/31] review: drop "all", cleanup BUILD file. Signed-off-by: Piotr Sikora --- bazel/BUILD | 5 -- bazel/envoy_build_system.bzl | 2 - bazel/envoy_select.bzl | 13 ---- bazel/external/proxy_wasm_cpp_host.BUILD | 95 +++++++++--------------- 4 files changed, 36 insertions(+), 79 deletions(-) diff --git a/bazel/BUILD b/bazel/BUILD index d2ad3d898c6fe..e4def8093f521 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -315,11 +315,6 @@ config_setting( ) # TODO: consider converting WAVM VM support to an extension (https://github.com/envoyproxy/envoy/issues/12574) -config_setting( - name = "wasm_all", - values = {"define": "wasm=enabled"}, -) - config_setting( name = "wasm_wavm", values = {"define": "wasm=wavm"}, diff --git a/bazel/envoy_build_system.bzl b/bazel/envoy_build_system.bzl index a1a78f7c3be30..283cf130af221 100644 --- a/bazel/envoy_build_system.bzl +++ b/bazel/envoy_build_system.bzl @@ -20,7 +20,6 @@ load( _envoy_select_hot_restart = "envoy_select_hot_restart", _envoy_select_new_codecs_in_integration_tests = "envoy_select_new_codecs_in_integration_tests", _envoy_select_wasm = "envoy_select_wasm", - _envoy_select_wasm_all_v8_wavm_none = "envoy_select_wasm_all_v8_wavm_none", _envoy_select_wasm_v8 = "envoy_select_wasm_v8", _envoy_select_wasm_wasmtime = "envoy_select_wasm_wasmtime", _envoy_select_wasm_wavm = "envoy_select_wasm_wavm", @@ -182,7 +181,6 @@ envoy_select_boringssl = _envoy_select_boringssl envoy_select_google_grpc = _envoy_select_google_grpc envoy_select_hot_restart = _envoy_select_hot_restart envoy_select_wasm = _envoy_select_wasm -envoy_select_wasm_all_v8_wavm_none = _envoy_select_wasm_all_v8_wavm_none envoy_select_wasm_wavm = _envoy_select_wasm_wavm envoy_select_wasm_wasmtime = _envoy_select_wasm_wasmtime envoy_select_wasm_v8 = _envoy_select_wasm_v8 diff --git a/bazel/envoy_select.bzl b/bazel/envoy_select.bzl index 1abdae857e517..1c0b18543d67e 100644 --- a/bazel/envoy_select.bzl +++ b/bazel/envoy_select.bzl @@ -41,15 +41,12 @@ def envoy_select_wasm(xs): def envoy_select_wasm_v8(xs): return select({ - "@envoy//bazel:wasm_wasmtime": [], - "@envoy//bazel:wasm_wavm": [], "@envoy//bazel:wasm_none": [], "//conditions:default": xs, }) def envoy_select_wasm_wavm(xs): return select({ - "@envoy//bazel:wasm_all": xs, "@envoy//bazel:wasm_wavm": xs, "//conditions:default": [], }) @@ -60,16 +57,6 @@ def envoy_select_wasm_wasmtime(xs): "//conditions:default": [], }) -def envoy_select_wasm_all_v8_wavm_none(xs1, xs2, xs3, xs4, xs5): - return select({ - "@envoy//bazel:wasm_all": xs1, - "@envoy//bazel:wasm_v8": xs2, - "@envoy//bazel:wasm_wavm": xs3, - "@envoy//bazel:wasm_wasmtime": xs4, - "@envoy//bazel:wasm_none": xs5, - "//conditions:default": xs2, - }) - # Select the given values if use legacy codecs in test is on in the current build. def envoy_select_new_codecs_in_integration_tests(xs, repository = ""): return select({ diff --git a/bazel/external/proxy_wasm_cpp_host.BUILD b/bazel/external/proxy_wasm_cpp_host.BUILD index e2fa8b7dfd6a1..7e5d3685e2757 100644 --- a/bazel/external/proxy_wasm_cpp_host.BUILD +++ b/bazel/external/proxy_wasm_cpp_host.BUILD @@ -1,7 +1,7 @@ load("@rules_cc//cc:defs.bzl", "cc_library") load( "@envoy//bazel:envoy_build_system.bzl", - "envoy_select_wasm_all_v8_wavm_none", + "envoy_select_wasm", "envoy_select_wasm_v8", "envoy_select_wasm_wasmtime", "envoy_select_wasm_wavm", @@ -22,61 +22,38 @@ cc_library( cc_library( name = "lib", # Note that the select cannot appear in the glob. - srcs = envoy_select_wasm_all_v8_wavm_none( - glob( - [ - "src/**/*.h", - "src/**/*.cc", - ], - exclude = [ - # TODO: currently we cannot link wasmtime with (v8, WAVM) due to symbol collision: - # - V8: wasm-c-api symbols - # - WAVM: LLVM's gdb JIT interface related symbols - "src/wasmtime/*", - ], - ), - glob( - [ - "src/**/*.h", - "src/**/*.cc", - ], - exclude = [ - "src/wavm/*", - "src/wasmtime/*", - ], - ), - glob( - [ - "src/**/*.h", - "src/**/*.cc", - ], - exclude = [ - "src/v8/*", - "src/wasmtime/*", - ], - ), - glob( - [ - "src/**/*.h", - "src/**/*.cc", - ], - exclude = [ - "src/v8/*", - "src/wavm/*", - ], - ), - glob( - [ - "src/**/*.h", - "src/**/*.cc", - ], - exclude = [ - "src/wavm/*", - "src/v8/*", - "src/wasmtime/*", - ], - ), - ), + srcs = envoy_select_wasm([ + "include/proxy-wasm/context.h", + "include/proxy-wasm/context_interface.h", + "include/proxy-wasm/exports.h", + "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.h", + "include/proxy-wasm/wasm_api_impl.h", + "include/proxy-wasm/wasm_vm.h", + "include/proxy-wasm/word.h", + "src/context.cc", + "src/exports.cc", + "src/foreign.cc", + "src/wasm.cc", + "src/null/null.cc", + "src/null/null_plugin.cc", + "src/null/null_vm.cc", + "src/third_party/base64.cc", + "src/third_party/base64.h", + "src/third_party/picosha2.h", + ]) + envoy_select_wasm_v8([ + "include/proxy-wasm/v8.h", + "src/v8/v8.cc", + ]) + envoy_select_wasm_wavm([ + "include/proxy-wasm/wavm.h", + "src/wavm/wavm.cc", + ]) + envoy_select_wasm_wasmtime([ + "include/proxy-wasm/wasmtime.h", + "src/wasmtime/wasmtime.cc", + ]), copts = envoy_select_wasm_wavm([ '-DWAVM_API=""', "-Wno-non-virtual-dtor", @@ -92,10 +69,10 @@ cc_library( "//external:zlib", "@proxy_wasm_cpp_sdk//:api_lib", "@proxy_wasm_cpp_sdk//:common_lib", - ] + envoy_select_wasm_wavm([ - "@envoy//bazel/foreign_cc:wavm", - ]) + envoy_select_wasm_v8([ + ] + envoy_select_wasm_v8([ "//external:wee8", + ]) + envoy_select_wasm_wavm([ + "@envoy//bazel/foreign_cc:wavm", ]) + envoy_select_wasm_wasmtime([ "@com_github_wasm_c_api//:wasmtime_lib", ]), From b066ad8f0e2fe760052ffb339caf48ec57a5a127 Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Tue, 10 Nov 2020 08:26:32 +0000 Subject: [PATCH 15/31] review: add missing file. Signed-off-by: Piotr Sikora --- bazel/external/proxy_wasm_cpp_host.BUILD | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bazel/external/proxy_wasm_cpp_host.BUILD b/bazel/external/proxy_wasm_cpp_host.BUILD index 7e5d3685e2757..24609c63e747b 100644 --- a/bazel/external/proxy_wasm_cpp_host.BUILD +++ b/bazel/external/proxy_wasm_cpp_host.BUILD @@ -52,6 +52,8 @@ cc_library( "src/wavm/wavm.cc", ]) + envoy_select_wasm_wasmtime([ "include/proxy-wasm/wasmtime.h", + "src/common/types.h", + "src/wasmtime/types.h", "src/wasmtime/wasmtime.cc", ]), copts = envoy_select_wasm_wavm([ From e0c3cf1dc4b5117bab8969d9b0730ee52007bba8 Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 10 Nov 2020 17:34:19 +0900 Subject: [PATCH 16/31] Update proxy-wasm-cpp-host Signed-off-by: mathetake --- bazel/repository_locations.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 2bff86234fae4..a72b7cd24afcb 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -868,8 +868,8 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "WebAssembly for Proxies (C++ host implementation)", project_desc = "WebAssembly for Proxies (C++ host implementation)", project_url = "https://github.com/proxy-wasm/proxy-wasm-cpp-host", - version = "a584bd1bd8bfe8d1d5b9cc8f88555283e459a314", - sha256 = "d850783c4b0b77fde62eaf4148021e45e424c7a0f6eae1aed07196a9a1f3895d", + version = "ba7df1b7bc8f8982c7aff20004d3734bc799edb3", + sha256 = "f64d19254058b693718af13fad7d723cdb1f6faab9cdfcb9eb2d956abcdd02e0", strip_prefix = "proxy-wasm-cpp-host-{version}", urls = ["https://github.com/mathetake/proxy-wasm-cpp-host/archive/{version}.tar.gz"], use_category = ["dataplane_ext"], From 6d83c0f0a224d80dc16eaa4a97c41094b662f831 Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Tue, 10 Nov 2020 08:34:33 +0000 Subject: [PATCH 17/31] review: don't build V8 with other runtimes. Signed-off-by: Piotr Sikora --- bazel/envoy_select.bzl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bazel/envoy_select.bzl b/bazel/envoy_select.bzl index 1c0b18543d67e..8cbecb26075cc 100644 --- a/bazel/envoy_select.bzl +++ b/bazel/envoy_select.bzl @@ -41,6 +41,8 @@ def envoy_select_wasm(xs): def envoy_select_wasm_v8(xs): return select({ + "@envoy//bazel:wasm_wasmtime": [], + "@envoy//bazel:wasm_wavm": [], "@envoy//bazel:wasm_none": [], "//conditions:default": xs, }) From 21de7835e9583c38a931efb544e9780df4ee11b8 Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Tue, 10 Nov 2020 08:37:44 +0000 Subject: [PATCH 18/31] review: update examples. Signed-off-by: Piotr Sikora --- examples/wasm-cc/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/wasm-cc/BUILD b/examples/wasm-cc/BUILD index 3d139a68e0eaa..a6f1975445cab 100644 --- a/examples/wasm-cc/BUILD +++ b/examples/wasm-cc/BUILD @@ -11,7 +11,7 @@ envoy_package() selects.config_setting_group( name = "include_wasm_config", - match_all = ["//bazel:x86", "//bazel:wasm_all"], + match_all = ["//bazel:x86", "//bazel:wasm_v8"], ) filegroup( From b7d6930cbea67e4266965c654efe3f48ee72b5e4 Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 10 Nov 2020 17:47:28 +0900 Subject: [PATCH 19/31] Update proxy-wasm-cpp-host: point to origin Signed-off-by: mathetake --- bazel/repository_locations.bzl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index a72b7cd24afcb..5a87447d9602e 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -868,10 +868,10 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "WebAssembly for Proxies (C++ host implementation)", project_desc = "WebAssembly for Proxies (C++ host implementation)", project_url = "https://github.com/proxy-wasm/proxy-wasm-cpp-host", - version = "ba7df1b7bc8f8982c7aff20004d3734bc799edb3", - sha256 = "f64d19254058b693718af13fad7d723cdb1f6faab9cdfcb9eb2d956abcdd02e0", + version = "4741d2f1cd5eb250f66d0518238c333353259d56", + sha256 = "30fc4becfcc5a95ac875fc5a0658a91aa7ddedd763b52d7810c13ed35d9d81aa", strip_prefix = "proxy-wasm-cpp-host-{version}", - urls = ["https://github.com/mathetake/proxy-wasm-cpp-host/archive/{version}.tar.gz"], + urls = ["https://github.com/proxy-wasm/proxy-wasm-cpp-host/archive/{version}.tar.gz"], use_category = ["dataplane_ext"], extensions = [ "envoy.access_loggers.wasm", From 2c5dc57933607706b958d1442636ae3265cd12d1 Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 10 Nov 2020 18:21:37 +0900 Subject: [PATCH 20/31] Update release date of proxy-wasm-cpp-host Signed-off-by: mathetake --- bazel/repository_locations.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 5a87447d9602e..d815ce0a11f15 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -861,7 +861,7 @@ REPOSITORY_LOCATIONS_SPEC = dict( "envoy.filters.network.wasm", "envoy.stat_sinks.wasm", ], - release_date = "2020-10-22", + release_date = "2020-11-10", cpe = "N/A", ), proxy_wasm_cpp_host = dict( From ec4d2ddd33fefa7cee8508aaba7d499b968b0b85 Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 10 Nov 2020 22:01:20 +0900 Subject: [PATCH 21/31] Add wasmtime test in bazel.compile_time_options CI target Signed-off-by: mathetake --- ci/do_ci.sh | 5 ++++- test/extensions/filters/http/wasm/wasm_filter_test.cc | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index eabb7393cd918..e32b64f7c5a55 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -274,13 +274,13 @@ elif [[ "$CI_TARGET" == "bazel.compile_time_options" ]]; then # changes, this build type may need to be broken up. # TODO(mpwarres): remove quiche=enabled once QUICHE is built by default. COMPILE_TIME_OPTIONS=( + "--define" "wasm=wavm" "--define" "signal_trace=disabled" "--define" "hot_restart=disabled" "--define" "google_grpc=disabled" "--define" "boringssl=fips" "--define" "log_debug_assert_in_release=enabled" "--define" "quiche=enabled" - "--define" "wasm=wasmtime" "--define" "path_normalization_by_default=true" "--define" "deprecated_features=disabled" "--define" "use_new_codecs_in_integration_tests=false" @@ -300,6 +300,9 @@ elif [[ "$CI_TARGET" == "bazel.compile_time_options" ]]; then echo "Building and testing ${TEST_TARGETS[*]}" bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" "${COMPILE_TIME_OPTIONS[@]}" -c dbg "${TEST_TARGETS[@]}" --test_tag_filters=-nofips --build_tests_only + echo "Building and testing with wasm=wasmtime: ${TEST_TARGETS[*]}" + bazel_with_collection test --define wasm=wasmtime "${COMPILE_TIME_OPTIONS[@]:2}" "${COMPILE_TIME_OPTIONS[@]}" -c dbg "${TEST_TARGETS[@]}" --test_tag_filters=-nofips --build_tests_only + # Legacy codecs "--define legacy_codecs_in_integration_tests=true" should also be tested in # integration tests with asan. bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" "${COMPILE_TIME_OPTIONS[@]}" -c dbg @envoy//test/integration/... --config=clang-asan --build_tests_only diff --git a/test/extensions/filters/http/wasm/wasm_filter_test.cc b/test/extensions/filters/http/wasm/wasm_filter_test.cc index 4515c29f98b3f..19fa6f7c7d645 100644 --- a/test/extensions/filters/http/wasm/wasm_filter_test.cc +++ b/test/extensions/filters/http/wasm/wasm_filter_test.cc @@ -1439,7 +1439,7 @@ TEST_P(WasmHttpFilterTest, RootId2) { setupFilter("context2"); EXPECT_CALL(filter(), log_(spdlog::level::debug, Eq(absl::string_view("onRequestHeaders2 2")))); Http::TestRequestHeaderMapImpl request_headers; - EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter().decodeHeaders(request_headers, true)); + EXPECT_EQ(Http::FilterHeadersStatus::StopAllIterationAndWatermark, filter().decodeHeaders(request_headers, true)); } } // namespace Wasm From b00c82a6198f2242dc98b7606ae754b56d1fed61 Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 10 Nov 2020 22:24:20 +0900 Subject: [PATCH 22/31] Review: clean up proxy-wasm-cpp-host BUILD file Signed-off-by: mathetake --- bazel/external/proxy_wasm_cpp_host.BUILD | 52 ++++++++---------------- 1 file changed, 17 insertions(+), 35 deletions(-) diff --git a/bazel/external/proxy_wasm_cpp_host.BUILD b/bazel/external/proxy_wasm_cpp_host.BUILD index 24609c63e747b..6157654ed5ea2 100644 --- a/bazel/external/proxy_wasm_cpp_host.BUILD +++ b/bazel/external/proxy_wasm_cpp_host.BUILD @@ -1,7 +1,6 @@ load("@rules_cc//cc:defs.bzl", "cc_library") load( "@envoy//bazel:envoy_build_system.bzl", - "envoy_select_wasm", "envoy_select_wasm_v8", "envoy_select_wasm_wasmtime", "envoy_select_wasm_wavm", @@ -22,40 +21,23 @@ cc_library( cc_library( name = "lib", # Note that the select cannot appear in the glob. - srcs = envoy_select_wasm([ - "include/proxy-wasm/context.h", - "include/proxy-wasm/context_interface.h", - "include/proxy-wasm/exports.h", - "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.h", - "include/proxy-wasm/wasm_api_impl.h", - "include/proxy-wasm/wasm_vm.h", - "include/proxy-wasm/word.h", - "src/context.cc", - "src/exports.cc", - "src/foreign.cc", - "src/wasm.cc", - "src/null/null.cc", - "src/null/null_plugin.cc", - "src/null/null_vm.cc", - "src/third_party/base64.cc", - "src/third_party/base64.h", - "src/third_party/picosha2.h", - ]) + envoy_select_wasm_v8([ - "include/proxy-wasm/v8.h", - "src/v8/v8.cc", - ]) + envoy_select_wasm_wavm([ - "include/proxy-wasm/wavm.h", - "src/wavm/wavm.cc", - ]) + envoy_select_wasm_wasmtime([ - "include/proxy-wasm/wasmtime.h", - "src/common/types.h", - "src/wasmtime/types.h", - "src/wasmtime/wasmtime.cc", - ]), + srcs = glob( + [ + "src/**/*.h", + "src/**/*.cc", + ], + exclude = [ + "src/v8/*.cc", + "src/wavm/*.cc", + "src/wasmtime/*.cc", + ], + ) + envoy_select_wasm_v8(glob([ + "src/v8/*.cc", + ])) + envoy_select_wasm_wavm(glob([ + "src/wavm/*.cc", + ])) + envoy_select_wasm_wasmtime(glob([ + "src/wasmtime/*.cc", + ])), copts = envoy_select_wasm_wavm([ '-DWAVM_API=""', "-Wno-non-virtual-dtor", From c39664ef8808f603ebc0b8af8b4e6acd042bb2df Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 10 Nov 2020 23:12:40 +0900 Subject: [PATCH 23/31] Fix style Signed-off-by: mathetake --- test/extensions/filters/http/wasm/wasm_filter_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/extensions/filters/http/wasm/wasm_filter_test.cc b/test/extensions/filters/http/wasm/wasm_filter_test.cc index 19fa6f7c7d645..9d3cda60b6ec1 100644 --- a/test/extensions/filters/http/wasm/wasm_filter_test.cc +++ b/test/extensions/filters/http/wasm/wasm_filter_test.cc @@ -1439,7 +1439,8 @@ TEST_P(WasmHttpFilterTest, RootId2) { setupFilter("context2"); EXPECT_CALL(filter(), log_(spdlog::level::debug, Eq(absl::string_view("onRequestHeaders2 2")))); Http::TestRequestHeaderMapImpl request_headers; - EXPECT_EQ(Http::FilterHeadersStatus::StopAllIterationAndWatermark, filter().decodeHeaders(request_headers, true)); + EXPECT_EQ(Http::FilterHeadersStatus::StopAllIterationAndWatermark, + filter().decodeHeaders(request_headers, true)); } } // namespace Wasm From e4fa56ef895fff183abf84daf53a6d91227041bd Mon Sep 17 00:00:00 2001 From: mathetake Date: Wed, 11 Nov 2020 07:02:01 +0900 Subject: [PATCH 24/31] Review: specify wasm runtimes explicitly in ci, and fix release dates of deps Signed-off-by: mathetake --- bazel/repository_locations.bzl | 4 ++-- ci/do_ci.sh | 17 ++++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index d815ce0a11f15..a60cc9d7d7cc4 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -623,7 +623,7 @@ REPOSITORY_LOCATIONS_SPEC = dict( sha256 = "7874feb1026bbef06796bd5ab80e73f15b8e83752bde8dc93994f5bc039a4952", strip_prefix = "wasmtime-{version}", urls = ["https://github.com/bytecodealliance/wasmtime/archive/v{version}.tar.gz"], - release_date = "2020-11-04", + release_date = "2020-11-05", use_category = ["dataplane_ext"], extensions = [ "envoy.access_loggers.wasm", @@ -642,7 +642,7 @@ REPOSITORY_LOCATIONS_SPEC = dict( sha256 = "aea8cd095e9937f1e14f2c93e026317b197eb2345e7a817fe3932062eb7b792c", strip_prefix = "wasm-c-api-{version}", urls = ["https://github.com/WebAssembly/wasm-c-api/archive/{version}.tar.gz"], - release_date = "2020-11-04", + release_date = "2019-11-14", use_category = ["dataplane_ext"], extensions = [ "envoy.access_loggers.wasm", diff --git a/ci/do_ci.sh b/ci/do_ci.sh index e32b64f7c5a55..295faf8941d47 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -274,7 +274,6 @@ elif [[ "$CI_TARGET" == "bazel.compile_time_options" ]]; then # changes, this build type may need to be broken up. # TODO(mpwarres): remove quiche=enabled once QUICHE is built by default. COMPILE_TIME_OPTIONS=( - "--define" "wasm=wavm" "--define" "signal_trace=disabled" "--define" "hot_restart=disabled" "--define" "google_grpc=disabled" @@ -298,21 +297,25 @@ elif [[ "$CI_TARGET" == "bazel.compile_time_options" ]]; then fi # Building all the dependencies from scratch to link them against libc++. echo "Building and testing ${TEST_TARGETS[*]}" - bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" "${COMPILE_TIME_OPTIONS[@]}" -c dbg "${TEST_TARGETS[@]}" --test_tag_filters=-nofips --build_tests_only + bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wavm "${COMPILE_TIME_OPTIONS[@]}" -c dbg "${TEST_TARGETS[@]}" --test_tag_filters=-nofips --build_tests_only echo "Building and testing with wasm=wasmtime: ${TEST_TARGETS[*]}" - bazel_with_collection test --define wasm=wasmtime "${COMPILE_TIME_OPTIONS[@]:2}" "${COMPILE_TIME_OPTIONS[@]}" -c dbg "${TEST_TARGETS[@]}" --test_tag_filters=-nofips --build_tests_only + bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wasmtime "${COMPILE_TIME_OPTIONS[@]}" -c dbg "${TEST_TARGETS[@]}" --test_tag_filters=-nofips --build_tests_only # Legacy codecs "--define legacy_codecs_in_integration_tests=true" should also be tested in # integration tests with asan. - bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" "${COMPILE_TIME_OPTIONS[@]}" -c dbg @envoy//test/integration/... --config=clang-asan --build_tests_only + bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wavm "${COMPILE_TIME_OPTIONS[@]}" -c dbg @envoy//test/integration/... --config=clang-asan --build_tests_only # "--define log_debug_assert_in_release=enabled" must be tested with a release build, so run only # these tests under "-c opt" to save time in CI. - bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" "${COMPILE_TIME_OPTIONS[@]}" -c opt @envoy//test/common/common:assert_test @envoy//test/server:server_test + bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wavm "${COMPILE_TIME_OPTIONS[@]}" -c opt @envoy//test/common/common:assert_test @envoy//test/server:server_test - echo "Building binary..." - bazel build "${BAZEL_BUILD_OPTIONS[@]}" "${COMPILE_TIME_OPTIONS[@]}" -c dbg @envoy//source/exe:envoy-static --build_tag_filters=-nofips + echo "Building binary with wasm=wavm..." + bazel build "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wavm "${COMPILE_TIME_OPTIONS[@]}" -c dbg @envoy//source/exe:envoy-static --build_tag_filters=-nofips + collect_build_profile build + + echo "Building binary with wasm=wavm..." + bazel build "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wasmtime "${COMPILE_TIME_OPTIONS[@]}" -c dbg @envoy//source/exe:envoy-static --build_tag_filters=-nofips collect_build_profile build exit 0 elif [[ "$CI_TARGET" == "bazel.api" ]]; then From 6ed3a2b8d86854bf3d75db48103c28917bd8b77b Mon Sep 17 00:00:00 2001 From: mathetake Date: Wed, 11 Nov 2020 07:03:01 +0900 Subject: [PATCH 25/31] Fix typo in bazel build in bazel.compile_time_options target Signed-off-by: mathetake --- ci/do_ci.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 295faf8941d47..087ad304e880a 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -314,7 +314,7 @@ elif [[ "$CI_TARGET" == "bazel.compile_time_options" ]]; then bazel build "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wavm "${COMPILE_TIME_OPTIONS[@]}" -c dbg @envoy//source/exe:envoy-static --build_tag_filters=-nofips collect_build_profile build - echo "Building binary with wasm=wavm..." + echo "Building binary with wasm=wasmtime..." bazel build "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wasmtime "${COMPILE_TIME_OPTIONS[@]}" -c dbg @envoy//source/exe:envoy-static --build_tag_filters=-nofips collect_build_profile build exit 0 From c779e33069b190cd8c469040588515e7d73e086d Mon Sep 17 00:00:00 2001 From: mathetake Date: Wed, 11 Nov 2020 07:04:55 +0900 Subject: [PATCH 26/31] Fix typo in bazel build in bazel.compile_time_options target: 2 Signed-off-by: mathetake --- ci/do_ci.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 087ad304e880a..ca12f032a7a57 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -296,7 +296,7 @@ elif [[ "$CI_TARGET" == "bazel.compile_time_options" ]]; then TEST_TARGETS=("@envoy//test/...") fi # Building all the dependencies from scratch to link them against libc++. - echo "Building and testing ${TEST_TARGETS[*]}" + echo "Building and testing with wasm=wavm: ${TEST_TARGETS[*]}" bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wavm "${COMPILE_TIME_OPTIONS[@]}" -c dbg "${TEST_TARGETS[@]}" --test_tag_filters=-nofips --build_tests_only echo "Building and testing with wasm=wasmtime: ${TEST_TARGETS[*]}" From 1a6bf15c7ca4803cfc719231842de2d7cdc015c2 Mon Sep 17 00:00:00 2001 From: mathetake Date: Wed, 11 Nov 2020 07:07:20 +0900 Subject: [PATCH 27/31] Style: remove unnecessary white spaces Signed-off-by: mathetake --- ci/do_ci.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index ca12f032a7a57..b40b977a68f3a 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -304,18 +304,18 @@ elif [[ "$CI_TARGET" == "bazel.compile_time_options" ]]; then # Legacy codecs "--define legacy_codecs_in_integration_tests=true" should also be tested in # integration tests with asan. - bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wavm "${COMPILE_TIME_OPTIONS[@]}" -c dbg @envoy//test/integration/... --config=clang-asan --build_tests_only + bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wavm "${COMPILE_TIME_OPTIONS[@]}" -c dbg @envoy//test/integration/... --config=clang-asan --build_tests_only # "--define log_debug_assert_in_release=enabled" must be tested with a release build, so run only # these tests under "-c opt" to save time in CI. - bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wavm "${COMPILE_TIME_OPTIONS[@]}" -c opt @envoy//test/common/common:assert_test @envoy//test/server:server_test + bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wavm "${COMPILE_TIME_OPTIONS[@]}" -c opt @envoy//test/common/common:assert_test @envoy//test/server:server_test echo "Building binary with wasm=wavm..." - bazel build "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wavm "${COMPILE_TIME_OPTIONS[@]}" -c dbg @envoy//source/exe:envoy-static --build_tag_filters=-nofips + bazel build "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wavm "${COMPILE_TIME_OPTIONS[@]}" -c dbg @envoy//source/exe:envoy-static --build_tag_filters=-nofips collect_build_profile build echo "Building binary with wasm=wasmtime..." - bazel build "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wasmtime "${COMPILE_TIME_OPTIONS[@]}" -c dbg @envoy//source/exe:envoy-static --build_tag_filters=-nofips + bazel build "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wasmtime "${COMPILE_TIME_OPTIONS[@]}" -c dbg @envoy//source/exe:envoy-static --build_tag_filters=-nofips collect_build_profile build exit 0 elif [[ "$CI_TARGET" == "bazel.api" ]]; then From 4b314c5252a6f0479eb80647550857c1b9417161 Mon Sep 17 00:00:00 2001 From: mathetake Date: Wed, 11 Nov 2020 10:14:16 +0900 Subject: [PATCH 28/31] Review: fix release dates of proxy-wasm-cpp-{host,sdk} Signed-off-by: mathetake --- bazel/repository_locations.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index a60cc9d7d7cc4..30a380b0118d2 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -861,7 +861,7 @@ REPOSITORY_LOCATIONS_SPEC = dict( "envoy.filters.network.wasm", "envoy.stat_sinks.wasm", ], - release_date = "2020-11-10", + release_date = "2020-10-22", cpe = "N/A", ), proxy_wasm_cpp_host = dict( @@ -880,7 +880,7 @@ REPOSITORY_LOCATIONS_SPEC = dict( "envoy.filters.network.wasm", "envoy.stat_sinks.wasm", ], - release_date = "2020-10-27", + release_date = "2020-11-10", cpe = "N/A", ), emscripten_toolchain = dict( From 2dbbd268fa942a8cee737314ae0638d95dc57ded Mon Sep 17 00:00:00 2001 From: mathetake Date: Wed, 11 Nov 2020 12:49:13 +0900 Subject: [PATCH 29/31] Review: Build wasmtime first Signed-off-by: mathetake --- ci/do_ci.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index b40b977a68f3a..9f5a9efa85608 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -296,12 +296,12 @@ elif [[ "$CI_TARGET" == "bazel.compile_time_options" ]]; then TEST_TARGETS=("@envoy//test/...") fi # Building all the dependencies from scratch to link them against libc++. - echo "Building and testing with wasm=wavm: ${TEST_TARGETS[*]}" - bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wavm "${COMPILE_TIME_OPTIONS[@]}" -c dbg "${TEST_TARGETS[@]}" --test_tag_filters=-nofips --build_tests_only - echo "Building and testing with wasm=wasmtime: ${TEST_TARGETS[*]}" bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wasmtime "${COMPILE_TIME_OPTIONS[@]}" -c dbg "${TEST_TARGETS[@]}" --test_tag_filters=-nofips --build_tests_only + echo "Building and testing with wasm=wavm: ${TEST_TARGETS[*]}" + bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wavm "${COMPILE_TIME_OPTIONS[@]}" -c dbg "${TEST_TARGETS[@]}" --test_tag_filters=-nofips --build_tests_only + # Legacy codecs "--define legacy_codecs_in_integration_tests=true" should also be tested in # integration tests with asan. bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wavm "${COMPILE_TIME_OPTIONS[@]}" -c dbg @envoy//test/integration/... --config=clang-asan --build_tests_only From 2e38d0396c63358834760e5bf16eb4c7ae1b3878 Mon Sep 17 00:00:00 2001 From: mathetake Date: Wed, 11 Nov 2020 13:34:06 +0900 Subject: [PATCH 30/31] Review: Remove bazel build for wasmtime Signed-off-by: mathetake --- ci/do_ci.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 9f5a9efa85608..760c73a9dede8 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -313,10 +313,6 @@ elif [[ "$CI_TARGET" == "bazel.compile_time_options" ]]; then echo "Building binary with wasm=wavm..." bazel build "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wavm "${COMPILE_TIME_OPTIONS[@]}" -c dbg @envoy//source/exe:envoy-static --build_tag_filters=-nofips collect_build_profile build - - echo "Building binary with wasm=wasmtime..." - bazel build "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wasmtime "${COMPILE_TIME_OPTIONS[@]}" -c dbg @envoy//source/exe:envoy-static --build_tag_filters=-nofips - collect_build_profile build exit 0 elif [[ "$CI_TARGET" == "bazel.api" ]]; then # Use libstdc++ because the API booster links to prebuilt libclang*/libLLVM* installed in /opt/llvm/lib, From 0210faaa3c17f36b05046a411947b2d6d1d48d9a Mon Sep 17 00:00:00 2001 From: mathetake Date: Thu, 12 Nov 2020 10:52:09 +0900 Subject: [PATCH 31/31] Review: Add comment about wasm-c-api's version Signed-off-by: mathetake --- bazel/repository_locations.bzl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 7854b558a0fa5..ecb74393ffea1 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -638,6 +638,8 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_name = "wasm-c-api", project_desc = "WebAssembly C and C++ API", project_url = "https://github.com/WebAssembly/wasm-c-api", + # this is the submodule's specific commit used by wasmtime + # https://github.com/bytecodealliance/wasmtime/tree/v0.21.0/crates/c-api version = "d9a80099d496b5cdba6f3fe8fc77586e0e505ddc", sha256 = "aea8cd095e9937f1e14f2c93e026317b197eb2345e7a817fe3932062eb7b792c", strip_prefix = "wasm-c-api-{version}",