Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
build --cxxopt=-std=c++17
build --cxxopt=-O3
build --cxxopt=-no-canonical-prefixes
build --cxxopt=-DEMSCRIPTEN_PROTOBUF_LITE=1

# try to optimize un-used code
build --cxxopt=-fdata-sections
build --cxxopt=-ffunction-sections

build --linkopt=-Wl,--gc-sections

# https://github.com/bazelbuild/bazel/issues/9451
# ideally we want this, but it doesn't work...
# build --cxxopt=-fno-canonical-system-headers
# as a work around we use `sed` to "fix" the *.d files.

build --crosstool_top=//toolchain:emscripten

# Use --cpu as a differentiator.
build --cpu=wasm

# Use the default Bazel C++ toolchain to build the tools used during the
# build.

build --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
23 changes: 23 additions & 0 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,26 @@ jobs:
rm *.pb.{cc,h}
make
git diff --exit-code -G "(^[^ /])|(^\s+[^\*])" *.pb.{cc,h}

build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Mount bazel cache
uses: actions/cache@v1
with:
path: "/home/runner/.cache/bazel"
key: bazel

- name: Install bazelisk
run: |
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.1.0/bazelisk-linux-amd64"
mkdir -p "${GITHUB_WORKSPACE}/bin/"
mv bazelisk-linux-amd64 "${GITHUB_WORKSPACE}/bin/bazel"
chmod +x "${GITHUB_WORKSPACE}/bin/bazel"

- name: Test
run: |
"${GITHUB_WORKSPACE}/bin/bazel" build //...
52 changes: 52 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,55 @@ cc_library(
"proxy_wasm_enums.h",
],
)

cc_library(
name = "proxy_wasm_intrinsics_lite",
srcs = [
"proxy_wasm_intrinsics.cc",
"proxy_wasm_intrinsics_lite.pb.cc",
"struct_lite.pb.cc",
],
hdrs = [
"proxy_wasm_api.h",
"proxy_wasm_common.h",
"proxy_wasm_enums.h",
"proxy_wasm_externs.h",
"proxy_wasm_intrinsics.h",
"proxy_wasm_intrinsics_lite.pb.h",
"struct_lite.pb.h",
],
copts = ["-DPROXY_WASM_PROTOBUF_LITE=1"],
visibility = ["//visibility:public"],
deps = [
"@com_google_protobuf//:protobuf_lite",
],
)

cc_library(
name = "proxy_wasm_intrinsics",
srcs = [
"proxy_wasm_intrinsics.cc",
"proxy_wasm_intrinsics.pb.cc",
],
hdrs = [
"proxy_wasm_api.h",
"proxy_wasm_common.h",
"proxy_wasm_enums.h",
"proxy_wasm_externs.h",
"proxy_wasm_intrinsics.h",
"proxy_wasm_intrinsics.pb.h",
"struct_lite.pb.h",
],
visibility = ["//visibility:public"],
deps = [
"@com_google_protobuf//:protobuf",
],
)

filegroup(
name = "jslib",
srcs = [
"proxy_wasm_intrinsics.js",
],
visibility = ["//visibility:public"],
)
53 changes: 53 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1 +1,54 @@
workspace(name = "proxy_wasm_cpp_sdk")

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

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

http_archive(
name = "emscripten_toolchain",
build_file = "//:emscripten-toolchain.BUILD",
patch_cmds = [
"./emsdk install 1.39.0-upstream",
"./emsdk activate --embedded 1.39.0-upstream",
],
strip_prefix = "emsdk-a5082b232617c762cb65832429f896c838df2483",
url = "https://github.com/emscripten-core/emsdk/archive/a5082b232617c762cb65832429f896c838df2483.tar.gz",
)

# required by com_google_protobuf
http_archive(
name = "bazel_skylib",
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
],
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()


git_repository(
name = "com_google_protobuf",
remote = "https://github.com/protocolbuffers/protobuf",
commit = "655310ca192a6e3a050e0ca0b7084a2968072260",
)

http_archive(
name = "rules_proto",
sha256 = "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208",
strip_prefix = "rules_proto-97d8af4dc474595af3900dd85cb3a29ad28cc313",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
"https://github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
],
)

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")

rules_proto_dependencies()

rules_proto_toolchains()
8 changes: 8 additions & 0 deletions emscripten-toolchain.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
licenses(["notice"]) # Apache 2

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

filegroup(
name = "all",
srcs = glob(["**/*"]),
)
4 changes: 2 additions & 2 deletions proxy_wasm_externs.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ extern "C" WasmResult proxy_http_call(const char *uri_ptr, size_t uri_size, void
extern "C" WasmResult proxy_grpc_call(const char *service_ptr, size_t service_size,
const char *service_name_ptr, size_t service_name_size,
const char *method_name_ptr, size_t method_name_size,
size_t initial_metadata_pairs_size, const char *request_ptr,
void *initial_metadata_ptr, size_t initial_metadata_size,
const char *request_ptr, size_t request_size,
uint32_t timeout_milliseconds, uint32_t *token_ptr);
extern "C" WasmResult proxy_grpc_stream(const char *service_ptr, size_t service_size,
const char *service_name_ptr, size_t service_name_size,
const char *method_name_ptr, size_t method_name_size,
size_t initial_metadata_pairs_size, const char *request_ptr,
void *initial_metadata, size_t initial_metadata_size,
uint32_t *token_ptr);
extern "C" WasmResult proxy_grpc_cancel(uint32_t token);
extern "C" WasmResult proxy_grpc_close(uint32_t token);
Expand Down
46 changes: 46 additions & 0 deletions toolchain/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
licenses(["notice"]) # Apache 2

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

load(":cc_toolchain_config.bzl", "cc_toolchain_config")

cc_toolchain_suite(
name = "emscripten",
toolchains = {
"wasm": ":wasm_toolchain",
},
)

filegroup(name = "empty")

filegroup(
name = "emscripten_cache_content",
srcs = glob(["tmp/emscripten_cache/**/*"]),
)

filegroup(
name = "all",
srcs = [
"common.sh",
"emar.sh",
"emcc.sh",
":emscripten_cache_content",
"@emscripten_toolchain//:all",
],
)

cc_toolchain(
name = "wasm_toolchain",
all_files = ":all",
ar_files = ":all",
compiler_files = ":all",
dwp_files = ":empty",
linker_files = ":all",
objcopy_files = ":empty",
strip_files = ":empty",
supports_param_files = 0,
toolchain_config = ":wasm_toolchain_config",
toolchain_identifier = "wasm-toolchain",
)

cc_toolchain_config(name = "wasm_toolchain_config")
117 changes: 117 additions & 0 deletions toolchain/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Copyright 2019 Solo.io, Inc.
# 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.

load(
"@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
"feature",
"flag_group",
"flag_set",
"tool_path",
)
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")

def _impl(ctx):
tool_paths = [
tool_path(
name = "gcc",
path = "emcc.sh",
),
tool_path(
name = "ld",
path = "emcc.sh",
),
tool_path(
name = "ar",
path = "emar.sh",
),
tool_path(
name = "cpp",
path = "/bin/false",
),
tool_path(
name = "gcov",
path = "/bin/false",
),
tool_path(
name = "nm",
path = "/bin/false",
),
tool_path(
name = "objdump",
path = "/bin/false",
),
tool_path(
name = "strip",
path = "/bin/false",
),
]

toolchain_include_directories_feature = feature(
name = "toolchain_include_directories",
enabled = True,
flag_sets = [
flag_set(
actions = [
ACTION_NAMES.assemble,
ACTION_NAMES.preprocess_assemble,
ACTION_NAMES.linkstamp_compile,
ACTION_NAMES.c_compile,
ACTION_NAMES.cpp_compile,
ACTION_NAMES.cpp_header_parsing,
ACTION_NAMES.cpp_module_compile,
ACTION_NAMES.cpp_module_codegen,
ACTION_NAMES.lto_backend,
ACTION_NAMES.clif_match,
],
flag_groups = [
flag_group(
flags = [
"-isystem",
"external/emscripten_toolchain/upstream/emscripten/system/include/libcxx",
"-isystem",
"external/emscripten_toolchain/upstream/emscripten/system/include/libc",
],
),
],
),
],
)

return cc_common.create_cc_toolchain_config_info(
ctx = ctx,
toolchain_identifier = "wasm-toolchain",
host_system_name = "i686-unknown-linux-gnu",
target_system_name = "wasm32-unknown-emscripten",
target_cpu = "wasm",
target_libc = "unknown",
compiler = "emscripten",
abi_version = "unknown",
abi_libc_version = "unknown",
tool_paths = tool_paths,
# we don't need to use features, as emcc already adds the directories.
# we just need to include them here so that bazel doesn't complain on
# "this rule is missing dependency declarations for the following files included".
cxx_builtin_include_directories = [
"external/emscripten_toolchain/upstream/emscripten/system/include/libcxx",
"external/emscripten_toolchain/upstream/emscripten/system/include/libc",
],
# features = [toolchain_include_directories_feature],
)

cc_toolchain_config = rule(
implementation = _impl,
attrs = {},
provides = [CcToolchainConfigInfo],
)
35 changes: 35 additions & 0 deletions toolchain/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
# Copyright 2019 Solo.io, Inc.
# 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.

# emsdk_env.sh\emcc doesn't like the bazel sandbox
# specifically, emsdk_env.sh seems to try to `cd` and `cd` back which doesn't work well
if [[ "$OSTYPE" == "linux-gnu" ]]; then
cd -P /proc/self/cwd
fi

export NODE_JS=''
export EMSCRIPTEN_ROOT='external/emscripten_toolchain'
export SPIDERMONKEY_ENGINE=''
export EM_EXCLUSIVE_CACHE_ACCESS=1
export EMCC_SKIP_SANITY_CHECK=1
export EMCC_WASM_BACKEND=1

source external/emscripten_toolchain/emsdk_env.sh

# the emscripten sdk does some path comparison, so make EM_CACHE an absolute path to make it work.
mkdir -p "tmp/emscripten_cache"
export EM_CACHE=${PWD}"/tmp/emscripten_cache"
export TEMP_DIR="tmp"
Loading