Skip to content

Commit 0656808

Browse files
committed
WasmEdge: Add the WasmEdge runtime supporting for WasmEdge-0.9.1.
Signed-off-by: YiYing He <[email protected]>
1 parent d75bfa4 commit 0656808

File tree

12 files changed

+747
-1
lines changed

12 files changed

+747
-1
lines changed

.github/workflows/cpp.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ jobs:
160160
os: macos-11
161161
arch: x86_64
162162
action: test
163+
- name: 'WasmEdge on Linux/x86_64'
164+
runtime: 'wasmedge'
165+
repo: 'com_github_wasmedge_wasmedge'
166+
os: ubuntu-20.04
167+
arch: x86_64
168+
action: test
169+
flags: --config=clang
163170
- name: 'Wasmtime on Linux/x86_64'
164171
engine: 'wasmtime'
165172
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
)
@@ -178,6 +179,28 @@ cc_library(
178179
}),
179180
)
180181

182+
cc_library(
183+
name = "wasmedge_lib",
184+
srcs = [
185+
"src/common/types.h",
186+
"src/wasmedge/types.h",
187+
"src/wasmedge/wasmedge.cc",
188+
],
189+
hdrs = ["include/proxy-wasm/wasmedge.h"],
190+
defines = [
191+
"PROXY_WASM_HAS_RUNTIME_WASMEDGE",
192+
"PROXY_WASM_HOST_ENGINE_WASMEDGE",
193+
],
194+
linkopts = [
195+
"-lrt",
196+
"-ldl",
197+
],
198+
deps = [
199+
":wasm_vm_headers",
200+
"//external:wasmedge",
201+
],
202+
)
203+
181204
cc_library(
182205
name = "wavm_lib",
183206
srcs = [
@@ -209,6 +232,8 @@ cc_library(
209232
[":v8_lib"],
210233
) + proxy_wasm_select_engine_wamr(
211234
[":wamr_lib"],
235+
) + proxy_wasm_select_engine_wasmedge(
236+
[":wasmedge_lib"],
212237
) + proxy_wasm_select_engine_wasmtime(
213238
[":wasmtime_lib"],
214239
) + proxy_wasm_select_engine_wavm(

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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,17 @@ def proxy_wasm_cpp_host_repositories():
229229
patches = ["@proxy_wasm_cpp_host//bazel/external:llvm.patch"],
230230
patch_args = ["-p1"],
231231
)
232+
233+
maybe(
234+
http_archive,
235+
name = "com_github_wasmedge_wasmedge",
236+
build_file = "@proxy_wasm_cpp_host//bazel/external:wasmedge.BUILD",
237+
sha256 = "6724955a967a1457bcf5dc1787a8da95feaba45d3b498ae42768ebf48f587299",
238+
strip_prefix = "WasmEdge-proxy-wasm-0.9.1",
239+
url = "https://github.com/WasmEdge/WasmEdge/archive/refs/tags/proxy-wasm/0.9.1.tar.gz",
240+
)
241+
242+
native.bind(
243+
name = "wasmedge",
244+
actual = "@com_github_wasmedge_wasmedge//:wasmedge_lib",
245+
)

bazel/select.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ def proxy_wasm_select_engine_wamr(xs):
3333
"//conditions:default": [],
3434
})
3535

36+
def proxy_wasm_select_engine_wasmedge(xs):
37+
return select({
38+
"@proxy_wasm_cpp_host//bazel:engine_wasmedge": xs,
39+
"//conditions:default": [],
40+
})
41+
3642
def proxy_wasm_select_engine_wasmtime(xs):
3743
return select({
3844
"@proxy_wasm_cpp_host//bazel:engine_wasmtime": 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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 {
19+
namespace WasmEdge {
20+
21+
using WasmEdgeStorePtr = common::CSmartPtr<WasmEdge_StoreContext, WasmEdge_StoreDelete>;
22+
using WasmEdgeVMPtr = common::CSmartPtr<WasmEdge_VMContext, WasmEdge_VMDelete>;
23+
using WasmEdgeLoaderPtr = common::CSmartPtr<WasmEdge_LoaderContext, WasmEdge_LoaderDelete>;
24+
using WasmEdgeValidatorPtr = common::CSmartPtr<WasmEdge_ValidatorContext, WasmEdge_ValidatorDelete>;
25+
using WasmEdgeExecutorPtr = common::CSmartPtr<WasmEdge_ExecutorContext, WasmEdge_ExecutorDelete>;
26+
using WasmEdgeASTModulePtr = common::CSmartPtr<WasmEdge_ASTModuleContext, WasmEdge_ASTModuleDelete>;
27+
28+
} // namespace WasmEdge
29+
} // namespace proxy_wasm

0 commit comments

Comments
 (0)