Skip to content

Commit 48a495e

Browse files
authored
Merge pull request #1 from jplevyak/review_wasm_vm
Review of WasmVM.
2 parents 0052667 + b618476 commit 48a495e

File tree

8 files changed

+525
-0
lines changed

8 files changed

+525
-0
lines changed

.bazelrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build --cxxopt="-std=c++17"

.clang-format

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
Language: Cpp
3+
ColumnLimit: 100
4+
AccessModifierOffset: -2
5+
DerivePointerAlignment: false
6+
PointerAlignment: Right
7+
SortIncludes: false
8+
...
9+
10+
---
11+
Language: Proto
12+
ColumnLimit: 100
13+
AllowShortFunctionsOnASingleLine: false
14+
ReflowComments: false
15+
SpacesInContainerLiterals: false
16+
...

BUILD

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
licenses(["notice"]) # Apache 2
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
cc_library(
6+
name = "include",
7+
hdrs = [
8+
"include/proxy-wasm/compat.h",
9+
"include/proxy-wasm/wasm_vm.h",
10+
"include/proxy-wasm/word.h",
11+
],
12+
deps = [
13+
"@proxy_wasm_cpp_sdk//:common_lib",
14+
],
15+
)
16+
17+
# TODO: remove when dependent projects have been upgraded.
18+
cc_library(
19+
name = "include14",
20+
hdrs = [
21+
"include/proxy-wasm/compat.h",
22+
"include/proxy-wasm/wasm_vm.h",
23+
"include/proxy-wasm/word.h",
24+
],
25+
copts = ["-std=c++14"],
26+
deps = [
27+
"@proxy_wasm_cpp_sdk//:common_lib",
28+
],
29+
)
30+
31+
cc_test(
32+
name = "wasm_vm_test",
33+
srcs = ["wasm_vm_test.cc"],
34+
deps = [
35+
":include",
36+
"@com_google_absl//absl/base",
37+
"@com_google_absl//absl/strings:strings",
38+
"@com_google_absl//absl/types:optional",
39+
"@com_google_googletest//:gtest",
40+
"@com_google_googletest//:gtest_main",
41+
],
42+
)
43+
44+
# TODO: remove when dependent projects have been upgraded.
45+
cc_test(
46+
name = "wasm_vm_14_test",
47+
srcs = ["wasm_vm_test.cc"],
48+
copts = ["-std=c++14"],
49+
deps = [
50+
":include14",
51+
"@com_google_absl//absl/base",
52+
"@com_google_absl//absl/strings:strings",
53+
"@com_google_absl//absl/types:optional",
54+
"@com_google_googletest//:gtest",
55+
"@com_google_googletest//:gtest_main",
56+
],
57+
)

WORKSPACE

+24
Original file line numberDiff line numberDiff line change
@@ -1 +1,25 @@
11
workspace(name = "proxy_wasm_cpp_host")
2+
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
5+
http_archive(
6+
name = "proxy_wasm_cpp_sdk",
7+
sha256 = "14f66f67e8f37ec81d28d7f5307be4407d206ac5f0daaf6d22fa5536797bcac1",
8+
strip_prefix = "proxy-wasm-cpp-sdk-31f1fc5b7e09f231fa532d2d296e479a113c3e10",
9+
urls = ["https://github.com/proxy-wasm/proxy-wasm-cpp-sdk/archive/31f1fc5b7e09f231fa532d2d296e479a113c3e10.tar.gz"],
10+
)
11+
12+
http_archive(
13+
name = "com_google_absl",
14+
sha256 = "19391fb4882601a65cb648d638c11aa301ce5f525ef02da1a9eafd22f72d7c59",
15+
strip_prefix = "abseil-cpp-37dd2562ec830d547a1524bb306be313ac3f2556",
16+
# 2020-01-29
17+
urls = ["https://github.com/abseil/abseil-cpp/archive/37dd2562ec830d547a1524bb306be313ac3f2556.tar.gz"],
18+
)
19+
20+
http_archive(
21+
name = "com_google_googletest",
22+
sha256 = "9dc9157a9a1551ec7a7e43daea9a694a0bb5fb8bec81235d8a1e6ef64c716dcb",
23+
strip_prefix = "googletest-release-1.10.0",
24+
urls = ["https://github.com/google/googletest/archive/release-1.10.0.tar.gz"],
25+
)

include/proxy-wasm/compat.h

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
#pragma once
16+
17+
// Provide compatibiliby for projects which have not yet moved to C++17.
18+
// TODO: remove this when all dependent projects have upgraded.
19+
20+
#ifndef __cpp_lib_optional
21+
#include "absl/types/optional.h"
22+
#else
23+
#include <optional>
24+
#endif
25+
26+
#ifndef __cpp_lib_string_view
27+
#include "absl/strings/string_view.h"
28+
#else
29+
#include <string_view>
30+
#endif
31+
32+
namespace proxy_wasm {
33+
#ifndef __cpp_lib_optional
34+
template <typename T> using optional = absl::optional<T>;
35+
// Only available in C++17
36+
// inline constexpr absl::nullopt_t nullopt = absl::nullopt;
37+
#define PROXY_WASM_NULLOPT absl::nullopt
38+
#else
39+
template <typename T> using optional = std::optional<T>;
40+
// Only available in C++17
41+
// inline constexpr std::nullopt_t nullopt = std::nullopt;
42+
#define PROXY_WASM_NULLOPT std::nullopt
43+
#endif
44+
45+
#ifndef __cpp_lib_string_view
46+
using string_view = absl::string_view;
47+
#else
48+
using string_view = std::string_view;
49+
#endif
50+
} // namespace proxy_wasm

0 commit comments

Comments
 (0)