proxy-wasm / proxy-wasm-cpp-sdk

WebAssembly for Proxies (C++ SDK)
Apache License 2.0
140 stars 68 forks source link

Migrate to Emscripten's native Bazel rules. #132

Closed PiotrSikora closed 2 years ago

PiotrSikora commented 2 years ago

Signed-off-by: Piotr Sikora piotrsikora@google.com

PiotrSikora commented 2 years ago

Envoy PR: https://github.com/envoyproxy/envoy/pull/19579.

PiotrSikora commented 2 years ago

@lambdai @kyessenov @douglas-reid FYI, as this is going to break the auto-update in Istio Proxy.

Most notably, the path to generated .wasm files changes (see Envoy PR: https://github.com/envoyproxy/envoy/pull/19579).

PiotrSikora commented 2 years ago

Hold for some fixes.

PiotrSikora commented 2 years ago

Splitting this into 2 parts: update to Emscripten v3.1.1 (#133) and migration to @emsdk toolchain (this PR), since the toolchain needs more work upstream to make it work for us.

PiotrSikora commented 2 years ago

This is on hold until https://github.com/emscripten-core/emsdk/issues/971 and https://github.com/emscripten-core/emsdk/issues/972 are fixed.

PiotrSikora commented 2 years ago

Note: This breaks Proxy-Wasm plugins that use abseil-cpp. The old toolchain's transition used --cpu=wasm32 (supported by abseil-cpp), but @emsdk toolchain's transition uses --cpu=wasm (not supported by abseil-cpp), and results in -pthread being added to linkopts, which emcc converts into WebAssemby threads proposal, which isn't enabled.

I've added support for --cpu=wasm in https://github.com/abseil/abseil-cpp/pull/1129, which fixes build of Proxy-Wasm plugins in Istio Proxy, but it requires either updating abseil-cpp past https://github.com/abseil/abseil-cpp/pull/1129 or cherry-picking it.

raakella commented 2 years ago

@PiotrSikora When I tried to upgrade to this SHA in our WASM module, it is breaking boost dependency. It works with previous SHA. Below is the error I am getting:

NFO: Analyzed 6 targets (0 packages loaded, 0 targets configured).
INFO: Found 6 targets...
ERROR: /private/var/tmp/_bazel_rakella/a6244b9ef447cd4131541c975f986f7f/external/boost/BUILD.bazel:795:14: Compiling libs/exception/src/clone_current_exception_non_intrusive.cpp failed: (Exit 1): emcc.sh failed: error executing command external/emsdk/emscripten_toolchain/emcc.sh '--sysroot=external/emscripten_bin_mac/emscripten/cache/sysroot' -fdiagnostics-color -fno-exceptions -fno-strict-aliasing -funsigned-char ... (remaining 34 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox
In file included from external/boost/libs/exception/src/clone_current_exception_non_intrusive.cpp:14:
external/boost/boost/exception/detail/clone_current_exception.hpp:22:6: error: This header requires exception handling to be enabled.
#    error This header requires exception handling to be enabled.
     ^

Any suggestions on how to proceed? It works with the previous commit.I suspect some defaults have changed with the bazel rules.

WORKSPACE:

workspace(name = "wasm-module")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# Pulls proxy wasm cpp SDK with a specific SHA
PROXY_WASM_CPP_SDK_SHA = "c32d380ca6c9b1afac38a3841be99c37af2698bf"
PROXY_WASM_CPP_SDK_SHA256 = "f83b83fe919905d8a6bb6ed6a0afb30d41a02cb52f33b616292c1de010d237db"

http_archive(
    name = "proxy_wasm_cpp_sdk",
    sha256 = PROXY_WASM_CPP_SDK_SHA256,
    strip_prefix = "proxy-wasm-cpp-sdk-" + PROXY_WASM_CPP_SDK_SHA,
    url = "https://github.com/proxy-wasm/proxy-wasm-cpp-sdk/archive/" + PROXY_WASM_CPP_SDK_SHA + ".tar.gz",
)

load("@proxy_wasm_cpp_sdk//bazel:repositories.bzl", "proxy_wasm_cpp_host_repositories")

proxy_wasm_cpp_host_repositories()

load("@proxy_wasm_cpp_sdk//bazel:dependencies.bzl", "proxy_wasm_cpp_host_dependencies")

proxy_wasm_cpp_host_dependencies()

load("@proxy_wasm_cpp_sdk//bazel:dependencies_extra.bzl", "proxy_wasm_cpp_host_dependencies_extra")

proxy_wasm_cpp_host_dependencies_extra()

local_repository(
    name = "mgw_wasm_websocket_api",
    path = "../../../../mgw-api/extensions/filters/http/mgw-wasm-websocket/v3"

)
############## changes to add boost ##############
git_repository(
    name = "com_github_nelhage_rules_boost",
    commit = "789a047e61c0292c3b989514f5ca18a9945b0029",
    remote = "https://github.com/nelhage/rules_boost",
    shallow_since = "1652895814 -0700",
)

load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps")
boost_deps()

bazel Build file:

load("@proxy_wasm_cpp_sdk//bazel:defs.bzl", "proxy_wasm_cc_binary")

proxy_wasm_cc_binary(
    name = "filtert.wasm",
    srcs = ["filter.cc", "filter.h"],
    deps = [
        "@proxy_wasm_cpp_sdk//:proxy_wasm_intrinsics_full",
        ############## changes to add boost ##############
        "@boost//:json"
    ],
)