Skip to content

wasmedge: add support for WasmEdge engine. #193

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 1 commit into from
Apr 7, 2022
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
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ jobs:
os: macos-11
arch: x86_64
action: test
- name: 'WasmEdge on Linux/x86_64'
engine: 'wasmedge'
repo: 'com_github_wasmedge_wasmedge'
os: ubuntu-20.04
arch: x86_64
action: test
flags: --config=clang
- name: 'Wasmtime on Linux/x86_64'
engine: 'wasmtime'
repo: 'com_github_bytecodealliance_wasmtime'
Expand Down
25 changes: 25 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ load(
"proxy_wasm_select_engine_null",
"proxy_wasm_select_engine_v8",
"proxy_wasm_select_engine_wamr",
"proxy_wasm_select_engine_wasmedge",
"proxy_wasm_select_engine_wasmtime",
"proxy_wasm_select_engine_wavm",
)
Expand Down Expand Up @@ -134,6 +135,28 @@ cc_library(
],
)

cc_library(
name = "wasmedge_lib",
srcs = [
"src/common/types.h",
"src/wasmedge/types.h",
"src/wasmedge/wasmedge.cc",
],
hdrs = ["include/proxy-wasm/wasmedge.h"],
defines = [
"PROXY_WASM_HAS_RUNTIME_WASMEDGE",
"PROXY_WASM_HOST_ENGINE_WASMEDGE",
],
linkopts = [
"-lrt",
"-ldl",
],
deps = [
":wasm_vm_headers",
"//external:wasmedge",
],
)

cc_library(
name = "wasmtime_lib",
srcs = [
Expand Down Expand Up @@ -270,6 +293,8 @@ cc_library(
[":v8_lib"],
) + proxy_wasm_select_engine_wamr(
[":wamr_lib"],
) + proxy_wasm_select_engine_wasmedge(
[":wasmedge_lib"],
) + proxy_wasm_select_engine_wasmtime(
[":wasmtime_lib"],
[":prefixed_wasmtime_lib"],
Expand Down
5 changes: 5 additions & 0 deletions bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ config_setting(
values = {"define": "engine=wamr"},
)

config_setting(
name = "engine_wasmedge",
values = {"define": "engine=wasmedge"},
)

config_setting(
name = "engine_wasmtime",
values = {"define": "engine=wasmtime"},
Expand Down
24 changes: 24 additions & 0 deletions bazel/external/wasmedge.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")

licenses(["notice"]) # Apache 2

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

filegroup(
name = "srcs",
srcs = glob(["**"]),
)

cmake(
name = "wasmedge_lib",
cache_entries = {
"WASMEDGE_BUILD_AOT_RUNTIME": "Off",
"WASMEDGE_BUILD_SHARED_LIB": "Off",
"WASMEDGE_BUILD_STATIC_LIB": "On",
"WASMEDGE_BUILD_TOOLS": "Off",
"WASMEDGE_FORCE_DISABLE_LTO": "On",
},
generate_args = ["-GNinja"],
lib_source = ":srcs",
out_static_libs = ["libwasmedge_c.a"],
)
16 changes: 16 additions & 0 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,22 @@ def proxy_wasm_cpp_host_repositories():
actual = "@com_github_bytecodealliance_wasm_micro_runtime//:wamr_lib",
)

# WasmEdge with dependencies.

maybe(
http_archive,
name = "com_github_wasmedge_wasmedge",
build_file = "@proxy_wasm_cpp_host//bazel/external:wasmedge.BUILD",
sha256 = "6724955a967a1457bcf5dc1787a8da95feaba45d3b498ae42768ebf48f587299",
strip_prefix = "WasmEdge-proxy-wasm-0.9.1",
url = "https://github.com/WasmEdge/WasmEdge/archive/refs/tags/proxy-wasm/0.9.1.tar.gz",
)

native.bind(
name = "wasmedge",
actual = "@com_github_wasmedge_wasmedge//:wasmedge_lib",
)

# Wasmtime with dependencies.

maybe(
Expand Down
7 changes: 7 additions & 0 deletions bazel/select.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ def proxy_wasm_select_engine_wasmtime(xs, xp):
"//conditions:default": [],
})

def proxy_wasm_select_engine_wasmedge(xs):
return select({
"@proxy_wasm_cpp_host//bazel:engine_wasmedge": xs,
"@proxy_wasm_cpp_host//bazel:multiengine": xs,
"//conditions:default": [],
})

def proxy_wasm_select_engine_wavm(xs):
return select({
"@proxy_wasm_cpp_host//bazel:engine_wavm": xs,
Expand Down
26 changes: 26 additions & 0 deletions include/proxy-wasm/wasmedge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2016-2019 Envoy Project Authors
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <memory>

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

namespace proxy_wasm {

std::unique_ptr<WasmVm> createWasmEdgeVm();

} // namespace proxy_wasm
27 changes: 27 additions & 0 deletions src/wasmedge/types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "src/common/types.h"
#include "wasmedge/wasmedge.h"

namespace proxy_wasm::WasmEdge {

using WasmEdgeStorePtr = common::CSmartPtr<WasmEdge_StoreContext, WasmEdge_StoreDelete>;
using WasmEdgeVMPtr = common::CSmartPtr<WasmEdge_VMContext, WasmEdge_VMDelete>;
using WasmEdgeLoaderPtr = common::CSmartPtr<WasmEdge_LoaderContext, WasmEdge_LoaderDelete>;
using WasmEdgeValidatorPtr = common::CSmartPtr<WasmEdge_ValidatorContext, WasmEdge_ValidatorDelete>;
using WasmEdgeExecutorPtr = common::CSmartPtr<WasmEdge_ExecutorContext, WasmEdge_ExecutorDelete>;
using WasmEdgeASTModulePtr = common::CSmartPtr<WasmEdge_ASTModuleContext, WasmEdge_ASTModuleDelete>;

} // namespace proxy_wasm::WasmEdge
Loading