Skip to content

Commit eba773f

Browse files
authored
wasmedge: add support for WasmEdge engine. (#193)
Signed-off-by: YiYing He <[email protected]>
1 parent 694a0b0 commit eba773f

File tree

12 files changed

+758
-1
lines changed

12 files changed

+758
-1
lines changed

.github/workflows/test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@ jobs:
166166
os: macos-11
167167
arch: x86_64
168168
action: test
169+
- name: 'WasmEdge on Linux/x86_64'
170+
engine: 'wasmedge'
171+
repo: 'com_github_wasmedge_wasmedge'
172+
os: ubuntu-20.04
173+
arch: x86_64
174+
action: test
175+
flags: --config=clang
169176
- name: 'Wasmtime on Linux/x86_64'
170177
engine: 'wasmtime'
171178
repo: 'com_github_bytecodealliance_wasmtime'

BUILD

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ load(
44
"proxy_wasm_select_engine_null",
55
"proxy_wasm_select_engine_v8",
66
"proxy_wasm_select_engine_wamr",
7+
"proxy_wasm_select_engine_wasmedge",
78
"proxy_wasm_select_engine_wasmtime",
89
"proxy_wasm_select_engine_wavm",
910
)
@@ -134,6 +135,28 @@ cc_library(
134135
],
135136
)
136137

138+
cc_library(
139+
name = "wasmedge_lib",
140+
srcs = [
141+
"src/common/types.h",
142+
"src/wasmedge/types.h",
143+
"src/wasmedge/wasmedge.cc",
144+
],
145+
hdrs = ["include/proxy-wasm/wasmedge.h"],
146+
defines = [
147+
"PROXY_WASM_HAS_RUNTIME_WASMEDGE",
148+
"PROXY_WASM_HOST_ENGINE_WASMEDGE",
149+
],
150+
linkopts = [
151+
"-lrt",
152+
"-ldl",
153+
],
154+
deps = [
155+
":wasm_vm_headers",
156+
"//external:wasmedge",
157+
],
158+
)
159+
137160
cc_library(
138161
name = "wasmtime_lib",
139162
srcs = [
@@ -270,6 +293,8 @@ cc_library(
270293
[":v8_lib"],
271294
) + proxy_wasm_select_engine_wamr(
272295
[":wamr_lib"],
296+
) + proxy_wasm_select_engine_wasmedge(
297+
[":wasmedge_lib"],
273298
) + proxy_wasm_select_engine_wasmtime(
274299
[":wasmtime_lib"],
275300
[":prefixed_wasmtime_lib"],

bazel/BUILD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ config_setting(
1515
values = {"define": "engine=wamr"},
1616
)
1717

18+
config_setting(
19+
name = "engine_wasmedge",
20+
values = {"define": "engine=wasmedge"},
21+
)
22+
1823
config_setting(
1924
name = "engine_wasmtime",
2025
values = {"define": "engine=wasmtime"},

bazel/external/wasmedge.BUILD

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
2+
3+
licenses(["notice"]) # Apache 2
4+
5+
package(default_visibility = ["//visibility:public"])
6+
7+
filegroup(
8+
name = "srcs",
9+
srcs = glob(["**"]),
10+
)
11+
12+
cmake(
13+
name = "wasmedge_lib",
14+
cache_entries = {
15+
"WASMEDGE_BUILD_AOT_RUNTIME": "Off",
16+
"WASMEDGE_BUILD_SHARED_LIB": "Off",
17+
"WASMEDGE_BUILD_STATIC_LIB": "On",
18+
"WASMEDGE_BUILD_TOOLS": "Off",
19+
"WASMEDGE_FORCE_DISABLE_LTO": "On",
20+
},
21+
generate_args = ["-GNinja"],
22+
lib_source = ":srcs",
23+
out_static_libs = ["libwasmedge_c.a"],
24+
)

bazel/repositories.bzl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,22 @@ def proxy_wasm_cpp_host_repositories():
181181
actual = "@com_github_bytecodealliance_wasm_micro_runtime//:wamr_lib",
182182
)
183183

184+
# WasmEdge with dependencies.
185+
186+
maybe(
187+
http_archive,
188+
name = "com_github_wasmedge_wasmedge",
189+
build_file = "@proxy_wasm_cpp_host//bazel/external:wasmedge.BUILD",
190+
sha256 = "6724955a967a1457bcf5dc1787a8da95feaba45d3b498ae42768ebf48f587299",
191+
strip_prefix = "WasmEdge-proxy-wasm-0.9.1",
192+
url = "https://github.com/WasmEdge/WasmEdge/archive/refs/tags/proxy-wasm/0.9.1.tar.gz",
193+
)
194+
195+
native.bind(
196+
name = "wasmedge",
197+
actual = "@com_github_wasmedge_wasmedge//:wasmedge_lib",
198+
)
199+
184200
# Wasmtime with dependencies.
185201

186202
maybe(

bazel/select.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ def proxy_wasm_select_engine_wasmtime(xs, xp):
4040
"//conditions:default": [],
4141
})
4242

43+
def proxy_wasm_select_engine_wasmedge(xs):
44+
return select({
45+
"@proxy_wasm_cpp_host//bazel:engine_wasmedge": xs,
46+
"@proxy_wasm_cpp_host//bazel:multiengine": xs,
47+
"//conditions:default": [],
48+
})
49+
4350
def proxy_wasm_select_engine_wavm(xs):
4451
return select({
4552
"@proxy_wasm_cpp_host//bazel:engine_wavm": xs,

include/proxy-wasm/wasmedge.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2016-2019 Envoy Project Authors
2+
// Copyright 2020 Google LLC
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#pragma once
17+
18+
#include <memory>
19+
20+
#include "include/proxy-wasm/wasm_vm.h"
21+
22+
namespace proxy_wasm {
23+
24+
std::unique_ptr<WasmVm> createWasmEdgeVm();
25+
26+
} // namespace proxy_wasm

src/wasmedge/types.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "src/common/types.h"
16+
#include "wasmedge/wasmedge.h"
17+
18+
namespace proxy_wasm::WasmEdge {
19+
20+
using WasmEdgeStorePtr = common::CSmartPtr<WasmEdge_StoreContext, WasmEdge_StoreDelete>;
21+
using WasmEdgeVMPtr = common::CSmartPtr<WasmEdge_VMContext, WasmEdge_VMDelete>;
22+
using WasmEdgeLoaderPtr = common::CSmartPtr<WasmEdge_LoaderContext, WasmEdge_LoaderDelete>;
23+
using WasmEdgeValidatorPtr = common::CSmartPtr<WasmEdge_ValidatorContext, WasmEdge_ValidatorDelete>;
24+
using WasmEdgeExecutorPtr = common::CSmartPtr<WasmEdge_ExecutorContext, WasmEdge_ExecutorDelete>;
25+
using WasmEdgeASTModulePtr = common::CSmartPtr<WasmEdge_ASTModuleContext, WasmEdge_ASTModuleDelete>;
26+
27+
} // namespace proxy_wasm::WasmEdge

0 commit comments

Comments
 (0)