Skip to content

Commit 0505324

Browse files
committed
add wasmtime runtime
Signed-off-by: mathetake <[email protected]>
1 parent d54b379 commit 0505324

File tree

14 files changed

+1073
-29
lines changed

14 files changed

+1073
-29
lines changed

BUILD

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1+
load("//:variables.bzl", "COPTS", "LINKOPTS")
2+
13
licenses(["notice"]) # Apache 2
24

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

5-
COPTS = select({
6-
"@bazel_tools//src/conditions:windows": [
7-
"/std:c++17",
8-
"-DWITHOUT_ZLIB",
9-
],
10-
"//conditions:default": [
11-
"-std=c++17",
12-
"-DWITHOUT_ZLIB",
13-
],
14-
})
15-
167
cc_library(
178
name = "include",
189
hdrs = glob(["include/proxy-wasm/**/*.h"]),
@@ -28,6 +19,7 @@ cc_library(
2819
exclude = [
2920
"src/**/wavm*",
3021
"src/**/v8*",
22+
"src/**/wasmtime*",
3123
],
3224
) + glob(["src/**/*.h"]),
3325
copts = COPTS,
@@ -39,24 +31,23 @@ cc_library(
3931
],
4032
)
4133

42-
cc_test(
43-
name = "wasm_vm_test",
44-
srcs = ["wasm_vm_test.cc"],
45-
copts = COPTS,
46-
deps = [
47-
":lib",
48-
"@com_google_googletest//:gtest",
49-
"@com_google_googletest//:gtest_main",
50-
],
51-
)
52-
53-
cc_test(
54-
name = "context_test",
55-
srcs = ["context_test.cc"],
34+
cc_library(
35+
name = "lib_test",
36+
srcs = glob(
37+
["src/**/*.cc"],
38+
exclude = [
39+
# TODO: test WAVM, v8 here
40+
"src/**/wavm*",
41+
"src/**/v8*",
42+
],
43+
) + glob(["src/**/*.h"]),
5644
copts = COPTS,
45+
linkopts = LINKOPTS,
5746
deps = [
5847
":include",
59-
"@com_google_googletest//:gtest",
60-
"@com_google_googletest//:gtest_main",
48+
"@boringssl//:crypto",
49+
"@com_google_protobuf//:protobuf_lite",
50+
"@proxy_wasm_cpp_sdk//:api_lib",
51+
"@wasmtime//:c_api",
6152
],
6253
)

WORKSPACE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,12 @@ http_archive(
5151
strip_prefix = "googletest-release-1.10.0",
5252
urls = ["https://github.com/google/googletest/archive/release-1.10.0.tar.gz"],
5353
)
54+
55+
http_archive(
56+
# TODO: use non-prebuild library, or download separate archives for each architecture
57+
name = "wasmtime",
58+
build_file = "//bazel/external:wasmtime.BUILD",
59+
sha256 = "fdbd6dbb58d15b3566abcc2c62ab18c348027e1620bc2ba0219017999504000e",
60+
strip_prefix = "wasmtime-v0.20.0-x86_64-linux-c-api",
61+
url = "https://github.com/bytecodealliance/wasmtime/releases/download/v0.20.0/wasmtime-v0.20.0-x86_64-linux-c-api.tar.xz",
62+
)

bazel/external/wasmtime.BUILD

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
licenses(["notice"]) # Apache 2
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
cc_library(
6+
name = "c_api",
7+
srcs = glob([
8+
"include/*.h",
9+
"lib/*.a",
10+
]),
11+
hdrs = [
12+
"include/wasm.h",
13+
"include/wasmtime.h",
14+
],
15+
include_prefix = "wasmtime",
16+
includes = ["include/"],
17+
)

include/proxy-wasm/wasmtime.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 "include/proxy-wasm/wasm_vm.h"
19+
20+
namespace proxy_wasm {
21+
22+
std::unique_ptr<WasmVm> createWasmtimeVm();
23+
24+
} // namespace proxy_wasm

src/common/c_smart_ptr.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
namespace proxy_wasm {
21+
namespace common {
22+
23+
template <typename T, void (*deleter)(T *)>
24+
class CSmartPtr : public std::unique_ptr<T, void (*)(T *)> {
25+
public:
26+
CSmartPtr() : std::unique_ptr<T, void (*)(T *)>(nullptr, deleter) {}
27+
CSmartPtr(T *object) : std::unique_ptr<T, void (*)(T *)>(object, deleter) {}
28+
};
29+
30+
} // namespace common
31+
} // namespace proxy_wasm

src/v8/v8.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,10 @@ bool V8::load(const std::string &code, bool allow_precompiled) {
268268

269269
std::unique_ptr<WasmVm> V8::clone() {
270270
assert(shared_module_ != nullptr);
271-
272271
auto clone = std::make_unique<V8>();
273272
clone->integration().reset(integration()->clone());
274-
clone->store_ = wasm::Store::make(engine());
275273

274+
clone->store_ = wasm::Store::make(engine());
276275
clone->module_ = wasm::Module::obtain(clone->store_.get(), shared_module_.get());
277276

278277
return clone;

src/wasmtime/pointers.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
// Copyright 2016-2019 Envoy Project Authors
3+
// Copyright 2020 Google LLC
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
#include "src/common/c_smart_ptr.h"
18+
#include "wasmtime/include/wasm.h"
19+
#include "wasmtime/include/wasmtime.h"
20+
21+
namespace proxy_wasm {
22+
namespace wasmtime {
23+
24+
using WasmEnginePtr = common::CSmartPtr<wasm_engine_t, wasm_engine_delete>;
25+
using WasmFuncPtr = common::CSmartPtr<wasm_func_t, wasm_func_delete>;
26+
using WasmStorePtr = common::CSmartPtr<wasm_store_t, wasm_store_delete>;
27+
using WasmModulePtr = common::CSmartPtr<wasm_module_t, wasm_module_delete>;
28+
using WasmSharedModulePtr = common::CSmartPtr<wasm_shared_module_t, wasm_shared_module_delete>;
29+
using WasmMemoryPtr = common::CSmartPtr<wasm_memory_t, wasm_memory_delete>;
30+
using WasmTablePtr = common::CSmartPtr<wasm_table_t, wasm_table_delete>;
31+
using WasmInstancePtr = common::CSmartPtr<wasm_instance_t, wasm_instance_delete>;
32+
using WasmFunctypePtr = common::CSmartPtr<wasm_functype_t, wasm_functype_delete>;
33+
using WasmTrapPtr = common::CSmartPtr<wasm_trap_t, wasm_trap_delete>;
34+
35+
} // namespace wasmtime
36+
37+
} // namespace proxy_wasm

0 commit comments

Comments
 (0)