Skip to content

Commit

Permalink
Add support for WebAssembly Micro Runtime (WAMR). (#142)
Browse files Browse the repository at this point in the history
Fixes #134.

Signed-off-by: Le Yao <le.yao@intel.com>
Co-authored-by: Liang He <liang.he@intel.com>
  • Loading branch information
YaoLe and lum1n0us authored May 7, 2021
1 parent 31c75e0 commit e641ffa
Show file tree
Hide file tree
Showing 9 changed files with 758 additions and 1 deletion.
3 changes: 2 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ cc_library(
"src/**/*.h",
],
exclude = [
"src/**/wavm*",
"src/**/v8*",
"src/**/wamr*",
"src/**/wavm*",
],
),
hdrs = glob(["src/**/*.h"]),
Expand Down
4 changes: 4 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ proxy_wasm_cpp_host_repositories()
load("@proxy_wasm_cpp_host//bazel:dependencies.bzl", "proxy_wasm_cpp_host_dependencies")

proxy_wasm_cpp_host_dependencies()

load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")

rules_foreign_cc_dependencies()
25 changes: 25 additions & 0 deletions bazel/external/wamr.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
licenses(["notice"]) # Apache 2

load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")

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

filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)

cmake(
name = "libiwasm",
cache_entries = {
"WAMR_BUILD_INTERP": "1",
"WAMR_BUILD_JIT": "0",
"WAMR_BUILD_AOT": "0",
"WAMR_BUILD_SIMD": "0",
"WAMR_BUILD_MULTI_MODULE": "1",
"WAMR_BUILD_LIBC_WASI": "0",
},
lib_source = ":srcs",
out_shared_libs = ["libiwasm.so"],
)
15 changes: 15 additions & 0 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def proxy_wasm_cpp_host_repositories():
urls = ["https://github.com/google/googletest/archive/release-1.10.0.tar.gz"],
)

http_archive(
name = "wamr",
build_file = "@proxy_wasm_cpp_host//bazel/external:wamr.BUILD",
sha256 = "1d870f396bb6bdcb5c816326655b19a2877bbdf879255c335b8e84ce4ee37780",
strip_prefix = "wasm-micro-runtime-9710d9325f426121cc1f2c62386a71d0c022d613",
url = "https://github.com/bytecodealliance/wasm-micro-runtime/archive/9710d9325f426121cc1f2c62386a71d0c022d613.tar.gz",
)

http_archive(
name = "wasmtime",
build_file = "@proxy_wasm_cpp_host//bazel/external:wasmtime.BUILD",
Expand Down Expand Up @@ -65,3 +73,10 @@ def proxy_wasm_cpp_host_repositories():
strip_prefix = "protobuf-655310ca192a6e3a050e0ca0b7084a2968072260",
url = "https://github.com/protocolbuffers/protobuf/archive/655310ca192a6e3a050e0ca0b7084a2968072260.tar.gz",
)

http_archive(
name = "rules_foreign_cc",
sha256 = "d54742ffbdc6924f222d2179f0e10e911c5c659c4ae74158e9fe827aad862ac6",
strip_prefix = "rules_foreign_cc-0.2.0",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/0.2.0.tar.gz",
)
26 changes: 26 additions & 0 deletions include/proxy-wasm/wamr.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> createWamrVm();

} // namespace proxy_wasm
45 changes: 45 additions & 0 deletions src/wamr/types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 "wasm_c_api.h"

namespace proxy_wasm {
namespace wamr {

using WasmEnginePtr = common::CSmartPtr<wasm_engine_t, wasm_engine_delete>;
using WasmFuncPtr = common::CSmartPtr<wasm_func_t, wasm_func_delete>;
using WasmStorePtr = common::CSmartPtr<wasm_store_t, wasm_store_delete>;
using WasmModulePtr = common::CSmartPtr<wasm_module_t, wasm_module_delete>;
using WasmMemoryPtr = common::CSmartPtr<wasm_memory_t, wasm_memory_delete>;
using WasmTablePtr = common::CSmartPtr<wasm_table_t, wasm_table_delete>;
using WasmInstancePtr = common::CSmartPtr<wasm_instance_t, wasm_instance_delete>;
using WasmFunctypePtr = common::CSmartPtr<wasm_functype_t, wasm_functype_delete>;
using WasmTrapPtr = common::CSmartPtr<wasm_trap_t, wasm_trap_delete>;
using WasmExternPtr = common::CSmartPtr<wasm_extern_t, wasm_extern_delete>;

using WasmByteVec =
common::CSmartType<wasm_byte_vec_t, wasm_byte_vec_new_empty, wasm_byte_vec_delete>;
using WasmImporttypeVec = common::CSmartType<wasm_importtype_vec_t, wasm_importtype_vec_new_empty,
wasm_importtype_vec_delete>;
using WasmExportTypeVec = common::CSmartType<wasm_exporttype_vec_t, wasm_exporttype_vec_new_empty,
wasm_exporttype_vec_delete>;
using WasmExternVec =
common::CSmartType<wasm_extern_vec_t, wasm_extern_vec_new_empty, wasm_extern_vec_delete>;
using WasmValtypeVec =
common::CSmartType<wasm_valtype_vec_t, wasm_valtype_vec_new_empty, wasm_valtype_vec_delete>;

} // namespace wamr

} // namespace proxy_wasm
Loading

0 comments on commit e641ffa

Please sign in to comment.