From 011ced83a6995167147c00d5baf40a7c356ceefa Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Mon, 17 Jan 2022 11:44:43 -0800 Subject: [PATCH 01/12] Update Emscripten to v3.1.1 with Bazel rules. Signed-off-by: Piotr Sikora --- .bazelrc | 15 +- BUILD | 2 +- README.md | 6 +- WORKSPACE | 12 +- bazel/BUILD | 6 + bazel/defs.bzl | 60 ++++++ bazel/dep/BUILD | 1 - .../{dep/deps_extra.bzl => dependencies.bzl} | 6 +- bazel/dependencies_extra.bzl | 19 ++ bazel/{dep/deps.bzl => repositories.bzl} | 36 ++-- bazel/wasm/BUILD | 1 - bazel/wasm/wasm.bzl | 87 --------- emscripten-toolchain.BUILD | 8 - example/BUILD | 9 +- sdk_container.sh | 4 +- toolchain/BUILD | 46 ----- toolchain/cc_toolchain_config.bzl | 174 ------------------ toolchain/common.sh | 41 ----- toolchain/emar.sh | 21 --- toolchain/emcc.sh | 37 ---- 20 files changed, 119 insertions(+), 472 deletions(-) create mode 100644 bazel/BUILD create mode 100644 bazel/defs.bzl delete mode 100644 bazel/dep/BUILD rename bazel/{dep/deps_extra.bzl => dependencies.bzl} (79%) create mode 100644 bazel/dependencies_extra.bzl rename bazel/{dep/deps.bzl => repositories.bzl} (58%) delete mode 100644 bazel/wasm/BUILD delete mode 100644 bazel/wasm/wasm.bzl delete mode 100644 emscripten-toolchain.BUILD delete mode 100644 toolchain/BUILD delete mode 100644 toolchain/cc_toolchain_config.bzl delete mode 100755 toolchain/common.sh delete mode 100755 toolchain/emar.sh delete mode 100755 toolchain/emcc.sh diff --git a/.bazelrc b/.bazelrc index e3263ef..5b3d13f 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,14 +1 @@ -# 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=wasm32 - -# Use the default Bazel C++ toolchain to build the tools used during the -# build. - -build --host_crosstool_top=@bazel_tools//tools/cpp:toolchain +build --cxxopt=-std=c++17 diff --git a/BUILD b/BUILD index ea654ea..f5b8ec3 100644 --- a/BUILD +++ b/BUILD @@ -104,7 +104,7 @@ proto_library( ) filegroup( - name = "jslib", + name = "proxy_wasm_intrinsics_js", srcs = [ "proxy_wasm_intrinsics.js", ], diff --git a/README.md b/README.md index a178431..dd5e416 100644 --- a/README.md +++ b/README.md @@ -175,8 +175,8 @@ sudo make install git clone https://github.com/emscripten-core/emsdk.git cd emsdk ./emsdk update-tags -./emsdk install 2.0.7 -./emsdk activate 2.0.7 +./emsdk install 3.1.1 +./emsdk activate 3.1.1 source ./emsdk\_env.sh ``` @@ -189,7 +189,7 @@ It is possible later versions will work, e.g. ./emsdk activate latest ``` -However 2.0.7 is known to work. +However 3.1.1 is known to work. ### Rebuilding the libprotobuf.a files diff --git a/WORKSPACE b/WORKSPACE index 3a04fb1..9818efa 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,9 +1,13 @@ workspace(name = "proxy_wasm_cpp_sdk") -load("@proxy_wasm_cpp_sdk//bazel/dep:deps.bzl", "wasm_dependencies") +load("@proxy_wasm_cpp_sdk//bazel:repositories.bzl", "proxy_wasm_cpp_host_repositories") -wasm_dependencies() +proxy_wasm_cpp_host_repositories() -load("@proxy_wasm_cpp_sdk//bazel/dep:deps_extra.bzl", "wasm_dependencies_extra") +load("@proxy_wasm_cpp_sdk//bazel:dependencies.bzl", "proxy_wasm_cpp_host_dependencies") -wasm_dependencies_extra() +proxy_wasm_cpp_host_dependencies() + +load("@proxy_wasm_cpp_sdk//bazel:dependencies_extra.bzl", "proxy_wasm_cpp_host_dependencies_extra") + +proxy_wasm_cpp_host_dependencies_extra() diff --git a/bazel/BUILD b/bazel/BUILD new file mode 100644 index 0000000..7264d3f --- /dev/null +++ b/bazel/BUILD @@ -0,0 +1,6 @@ +licenses(["notice"]) # Apache 2 + +config_setting( + name = "is_opt", + values = {"compilation_mode": "opt"}, +) diff --git a/bazel/defs.bzl b/bazel/defs.bzl new file mode 100644 index 0000000..ee79efa --- /dev/null +++ b/bazel/defs.bzl @@ -0,0 +1,60 @@ +# Copyright 2022 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("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary") +load("@rules_cc//cc:defs.bzl", "cc_binary") + +def proxy_wasm_cc_binary( + name, + additional_linker_inputs = [], + copts = [], + linkopts = [], + tags = [], + deps = [], + **kwargs): + cc_binary( + name = "proxy_wasm_" + name.rstrip(".wasm"), + additional_linker_inputs = additional_linker_inputs + [ + "@proxy_wasm_cpp_sdk//:proxy_wasm_intrinsics_js", + ], + copts = copts + [ + "-std=c++17", + ] + select({ + "@proxy_wasm_cpp_sdk//bazel:is_opt": [ + "-fdata-sections", + "-ffunction-sections", + "-flto", + "-O3", + ], + "//conditions:default": [], + }), + linkopts = linkopts + [ + "--no-entry", + "--js-library=$(location @proxy_wasm_cpp_sdk//:proxy_wasm_intrinsics_js)", + "-sSTANDALONE_WASM", + "-sEXPORTED_FUNCTIONS=_malloc", + ], + tags = tags + [ + "manual", + ], + deps = deps + [ + "@proxy_wasm_cpp_sdk//:proxy_wasm_intrinsics", + ], + **kwargs + ) + + wasm_cc_binary( + name = name, + cc_target = ":proxy_wasm_" + name.rstrip(".wasm"), + ) diff --git a/bazel/dep/BUILD b/bazel/dep/BUILD deleted file mode 100644 index 779d169..0000000 --- a/bazel/dep/BUILD +++ /dev/null @@ -1 +0,0 @@ -licenses(["notice"]) # Apache 2 diff --git a/bazel/dep/deps_extra.bzl b/bazel/dependencies.bzl similarity index 79% rename from bazel/dep/deps_extra.bzl rename to bazel/dependencies.bzl index 58bdac1..7c6b35d 100644 --- a/bazel/dep/deps_extra.bzl +++ b/bazel/dependencies.bzl @@ -13,7 +13,9 @@ # limitations under the License. load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") +load("@emsdk//:deps.bzl", emsdk_deps = "deps") -# Wasm deps that rely on a first stage of dependency loading in wasm_dependencies(). -def wasm_dependencies_extra(): +# Requires proxy_wasm_cpp_host_repositories() to be loaded first. +def proxy_wasm_cpp_host_dependencies(): protobuf_deps() + emsdk_deps() diff --git a/bazel/dependencies_extra.bzl b/bazel/dependencies_extra.bzl new file mode 100644 index 0000000..b999fe2 --- /dev/null +++ b/bazel/dependencies_extra.bzl @@ -0,0 +1,19 @@ +# 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("@emsdk//:emscripten_deps.bzl", emsdk_emscripten_deps = "emscripten_deps") + +# Requires proxy_wasm_cpp_host_dependencies() to be loaded first. +def proxy_wasm_cpp_host_dependencies_extra(): + emsdk_emscripten_deps(emscripten_version = "3.1.1") diff --git a/bazel/dep/deps.bzl b/bazel/repositories.bzl similarity index 58% rename from bazel/dep/deps.bzl rename to bazel/repositories.bzl index 0ec42e4..981cc56 100644 --- a/bazel/dep/deps.bzl +++ b/bazel/repositories.bzl @@ -12,35 +12,23 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file") +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -def wasm_dependencies(): - _http_archive( - name = "emscripten_toolchain", - build_file = "@proxy_wasm_cpp_sdk//:emscripten-toolchain.BUILD", - patch_cmds = [ - "./emsdk install 2.0.7", - "./emsdk activate --embedded 2.0.7", - ], - strip_prefix = "emsdk-2.0.7", - url = "https://github.com/emscripten-core/emsdk/archive/2.0.7.tar.gz", - sha256 = "ce7a5c76e8b425aca874cea329fd9ac44b203b777053453b6a37b4496c5ce34f" +def proxy_wasm_cpp_host_repositories(): + maybe( + http_archive, + name = "emsdk", + sha256 = "19851efd2616a66f9abd84f55f1d094e03252d87b1d78ae0f5d992121d1dd9cc", + # v3.1.1 with Bazel fixes + strip_prefix = "emsdk-7eecde8afcb89fbdff2597d6cce61a24ae2c34f3/bazel", + url = "https://github.com/emscripten-core/emsdk/archive/7eecde8afcb89fbdff2597d6cce61a24ae2c34f3.tar.gz", ) - _http_archive( + maybe( + http_archive, name = "com_google_protobuf", sha256 = "77ad26d3f65222fd96ccc18b055632b0bfedf295cb748b712a98ba1ac0b704b2", strip_prefix = "protobuf-3.17.3", url = "https://github.com/protocolbuffers/protobuf/releases/download/v3.17.3/protobuf-all-3.17.3.tar.gz", ) - -def _http_archive(name, **kwargs): - existing_rule_keys = native.existing_rules().keys() - if name in existing_rule_keys: - # This repository has already been defined. - return - - http_archive( - name = name, - **kwargs - ) diff --git a/bazel/wasm/BUILD b/bazel/wasm/BUILD deleted file mode 100644 index 779d169..0000000 --- a/bazel/wasm/BUILD +++ /dev/null @@ -1 +0,0 @@ -licenses(["notice"]) # Apache 2 diff --git a/bazel/wasm/wasm.bzl b/bazel/wasm/wasm.bzl deleted file mode 100644 index eaa1b0e..0000000 --- a/bazel/wasm/wasm.bzl +++ /dev/null @@ -1,87 +0,0 @@ -# Copyright 2016-2020 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. - -load("@rules_cc//cc:defs.bzl", "cc_binary") - -def _wasm_cc_transition_impl(settings, attr): - return { - "//command_line_option:cpu": "wasm32", - "//command_line_option:crosstool_top": "@proxy_wasm_cpp_sdk//toolchain:emscripten", - - # Overriding copt/cxxopt/linkopt to prevent sanitizers/coverage options leak - # into Wasm build configuration - "//command_line_option:copt": [], - "//command_line_option:cxxopt": [], - "//command_line_option:linkopt": [], - "//command_line_option:collect_code_coverage": "false", - "//command_line_option:fission": "no", - } - -wasm_cc_transition = transition( - implementation = _wasm_cc_transition_impl, - inputs = [], - outputs = [ - "//command_line_option:cpu", - "//command_line_option:crosstool_top", - "//command_line_option:copt", - "//command_line_option:cxxopt", - "//command_line_option:fission", - "//command_line_option:linkopt", - "//command_line_option:collect_code_coverage", - ], -) - -def wasm_binary_impl(ctx): - out = ctx.actions.declare_file(ctx.label.name) - ctx.actions.run( - executable = "cp", - arguments = [ctx.files.binary[0].path, out.path], - outputs = [out], - inputs = ctx.files.binary, - ) - - return [DefaultInfo(files = depset([out]), runfiles = ctx.runfiles([out]))] - -def _wasm_attrs(transition): - return { - "binary": attr.label(mandatory = True, cfg = transition), - "_whitelist_function_transition": attr.label(default = "@bazel_tools//tools/whitelists/function_transition_whitelist"), - } - -# Wasm binary rule implementation. -# This copies the binary specified in binary attribute in Wasm configuration to -# target configuration, so a binary in non-Wasm configuration can depend on them. -wasm_cc_binary_rule = rule( - implementation = wasm_binary_impl, - attrs = _wasm_attrs(wasm_cc_transition), -) - -def wasm_cc_binary(name, tags = [], **kwargs): - wasm_name = "_wasm_" + name - kwargs.setdefault("visibility", ["//visibility:public"]) - cc_binary( - name = wasm_name, - # Adding manual tag it won't be built in non-Wasm (e.g. x86_64 config) - # when an wildcard is specified, but it will be built in Wasm configuration - # when the wasm_binary below is built. - tags = ["manual"], - **kwargs - ) - - wasm_cc_binary_rule( - name = name, - binary = ":" + wasm_name, - tags = tags, - ) diff --git a/emscripten-toolchain.BUILD b/emscripten-toolchain.BUILD deleted file mode 100644 index 2aaa475..0000000 --- a/emscripten-toolchain.BUILD +++ /dev/null @@ -1,8 +0,0 @@ -licenses(["notice"]) # Apache 2 - -package(default_visibility = ["//visibility:public"]) - -filegroup( - name = "all", - srcs = glob(["**/*"]), -) diff --git a/example/BUILD b/example/BUILD index 82b05a3..1465b8e 100644 --- a/example/BUILD +++ b/example/BUILD @@ -1,11 +1,8 @@ -load("//bazel/wasm:wasm.bzl", "wasm_cc_binary") +load("@proxy_wasm_cpp_sdk//bazel:defs.bzl", "proxy_wasm_cc_binary") licenses(["notice"]) # Apache 2 -wasm_cc_binary( - name = "http_wasm_example.wasm", +proxy_wasm_cc_binary( + name = "http_wasm_example", srcs = ["http_wasm_example.cc"], - deps = [ - "@proxy_wasm_cpp_sdk//:proxy_wasm_intrinsics", - ], ) diff --git a/sdk_container.sh b/sdk_container.sh index daa5aff..0cab9e4 100755 --- a/sdk_container.sh +++ b/sdk_container.sh @@ -51,8 +51,8 @@ rm -rf protobuf git clone https://github.com/emscripten-core/emsdk.git cd emsdk ./emsdk update-tags -./emsdk install 2.0.7 -./emsdk activate 2.0.7 +./emsdk install 3.1.1 +./emsdk activate 3.1.1 source ./emsdk_env.sh cd diff --git a/toolchain/BUILD b/toolchain/BUILD deleted file mode 100644 index e5797d6..0000000 --- a/toolchain/BUILD +++ /dev/null @@ -1,46 +0,0 @@ -licenses(["notice"]) # Apache 2 - -package(default_visibility = ["//visibility:public"]) - -load(":cc_toolchain_config.bzl", "cc_toolchain_config") - -cc_toolchain_suite( - name = "emscripten", - toolchains = { - "wasm32": ":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") diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl deleted file mode 100644 index 288215a..0000000 --- a/toolchain/cc_toolchain_config.bzl +++ /dev/null @@ -1,174 +0,0 @@ -# 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", - ], - ), - ], - ), - ], - ) - - cxx17_feature = feature( - name = "c++17", - enabled = True, - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.cpp_compile], - flag_groups = [flag_group(flags = ["-std=c++17"])], - ), - ], - ) - - no_canonical_prefixes_feature = feature( - name = "no-canonical-prefixes", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ], - flag_groups = [ - flag_group( - flags = [ - "-no-canonical-prefixes", - ], - ), - ], - ), - ], - ) - - opt_feature = feature( - name = "opt", - enabled = True, - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [ - flag_group( - flags = ["-O3", "-ffunction-sections", "-fdata-sections", "-flto"], - ), - ], - ), - flag_set( - actions = [ - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ACTION_NAMES.cpp_link_executable, - ], - flag_groups = [flag_group(flags = ["-O3", "-Wl,--gc-sections", "-flto"])], - ), - ], - ) - - 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 = [cxx17_feature, no_canonical_prefixes_feature, opt_feature], - ) - -cc_toolchain_config = rule( - implementation = _impl, - attrs = {}, - provides = [CcToolchainConfigInfo], -) diff --git a/toolchain/common.sh b/toolchain/common.sh deleted file mode 100755 index 0ef8a0a..0000000 --- a/toolchain/common.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/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 - -TOOLCHAIN_ROOT=${EXT_BUILD_ROOT:-$PWD} - -export NODE_JS='' -export EMSCRIPTEN_ROOT="${TOOLCHAIN_ROOT}/external/emscripten_toolchain" -export SPIDERMONKEY_ENGINE='' -export EM_EXCLUSIVE_CACHE_ACCESS=1 -export EMCC_SKIP_SANITY_CHECK=1 -export EMCC_WASM_BACKEND=1 - -#echo "$(pwd)/external/emscripten_toolchain/emsdk_env.sh" -#realpath "external/emscripten_toolchain/emsdk_env.sh" -pushd "${EMSCRIPTEN_ROOT}" -source "./emsdk_env.sh" -popd - - # the emscripten sdk does some path comparison, so make EM_CACHE an absolute path to make it work. -mkdir -p "${TOOLCHAIN_ROOT}/tmp/emscripten_cache" -export EM_CACHE="${TOOLCHAIN_ROOT}/tmp/emscripten_cache" -export TEMP_DIR="${TOOLCHAIN_ROOT}/tmp" diff --git a/toolchain/emar.sh b/toolchain/emar.sh deleted file mode 100755 index 44910cc..0000000 --- a/toolchain/emar.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/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. - -set -euo pipefail - -. $(dirname $0)/common.sh - -emar "$@" diff --git a/toolchain/emcc.sh b/toolchain/emcc.sh deleted file mode 100755 index b7e2181..0000000 --- a/toolchain/emcc.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/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. - -set -euo pipefail - -. $(dirname $0)/common.sh - -emcc --no-entry -s EXPORTED_FUNCTIONS=['_malloc'] "$@" - -# clang doesn't support `-no-canonical-system-headers` so sed it -# find the .d file in the args and fix it: - -for arg in "$@" -do - if [ "${arg: -2}" == ".d" ]; then - echo Fixing $arg - sed -e 's%[^ ]*/external/emscripten_toolchain/upstream/emscripten/system/%external/emscripten_toolchain/upstream/emscripten/system/%' $arg > $arg.tmp - mv $arg.tmp $arg - # some zlib headers are treated as system headers - sed -e 's%[^ ]*/external/zlib/%external/zlib/%' $arg > $arg.tmp - mv $arg.tmp $arg - break - fi -done From 5987385c4fb3cde93c5f97596dcc44ae4595a93b Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Mon, 17 Jan 2022 19:46:06 -0800 Subject: [PATCH 02/12] review: use "tags" in cc_binary and wasm_cc_binary. Signed-off-by: Piotr Sikora --- bazel/defs.bzl | 1 + 1 file changed, 1 insertion(+) diff --git a/bazel/defs.bzl b/bazel/defs.bzl index ee79efa..0322a07 100644 --- a/bazel/defs.bzl +++ b/bazel/defs.bzl @@ -57,4 +57,5 @@ def proxy_wasm_cc_binary( wasm_cc_binary( name = name, cc_target = ":proxy_wasm_" + name.rstrip(".wasm"), + tags = tags, ) From edaa85e3943585f2a975c5f566d0b92e24fea578 Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Mon, 17 Jan 2022 20:18:48 -0800 Subject: [PATCH 03/12] review: use the default (latest) version of Emscripten. Signed-off-by: Piotr Sikora --- bazel/dependencies_extra.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bazel/dependencies_extra.bzl b/bazel/dependencies_extra.bzl index b999fe2..5ce686a 100644 --- a/bazel/dependencies_extra.bzl +++ b/bazel/dependencies_extra.bzl @@ -16,4 +16,4 @@ load("@emsdk//:emscripten_deps.bzl", emsdk_emscripten_deps = "emscripten_deps") # Requires proxy_wasm_cpp_host_dependencies() to be loaded first. def proxy_wasm_cpp_host_dependencies_extra(): - emsdk_emscripten_deps(emscripten_version = "3.1.1") + emsdk_emscripten_deps() From 65ba52dc076936c8f1d36f53ec5a80dfce23e4b0 Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Wed, 19 Jan 2022 11:40:43 -0800 Subject: [PATCH 04/12] review: re-add deprecated rules as failures. Signed-off-by: Piotr Sikora --- bazel/wasm/BUILD | 1 + bazel/wasm/wasm.bzl | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 bazel/wasm/BUILD create mode 100644 bazel/wasm/wasm.bzl diff --git a/bazel/wasm/BUILD b/bazel/wasm/BUILD new file mode 100644 index 0000000..779d169 --- /dev/null +++ b/bazel/wasm/BUILD @@ -0,0 +1 @@ +licenses(["notice"]) # Apache 2 diff --git a/bazel/wasm/wasm.bzl b/bazel/wasm/wasm.bzl new file mode 100644 index 0000000..ab316f2 --- /dev/null +++ b/bazel/wasm/wasm.bzl @@ -0,0 +1,19 @@ +# Copyright 2022 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. + +def wasm_cc_binary(**kwargs): + fail("`wasm_cc_binary` is deprecated. Please use `proxy_wasm_cc_binary` from `@proxy_wasm_cpp_sdk//bazel:defs.bzl`.") + +def proxy_wasm_cc_binary(**kwargs): + fail("Please use `proxy_wasm_cc_binary` from `@proxy_wasm_cpp_sdk//bazel:defs.bzl`.") From f5abd1897da938b4b37db63f2907e25d5cf41d8b Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Thu, 20 Jan 2022 13:48:21 -0800 Subject: [PATCH 05/12] review: force -O3 -flto regardless of the compilation mode. Signed-off-by: Piotr Sikora --- bazel/BUILD | 5 ----- bazel/defs.bzl | 12 +++--------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/bazel/BUILD b/bazel/BUILD index 7264d3f..779d169 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -1,6 +1 @@ licenses(["notice"]) # Apache 2 - -config_setting( - name = "is_opt", - values = {"compilation_mode": "opt"}, -) diff --git a/bazel/defs.bzl b/bazel/defs.bzl index 0322a07..cd37092 100644 --- a/bazel/defs.bzl +++ b/bazel/defs.bzl @@ -30,15 +30,9 @@ def proxy_wasm_cc_binary( ], copts = copts + [ "-std=c++17", - ] + select({ - "@proxy_wasm_cpp_sdk//bazel:is_opt": [ - "-fdata-sections", - "-ffunction-sections", - "-flto", - "-O3", - ], - "//conditions:default": [], - }), + "-flto", + "-O3", + ], linkopts = linkopts + [ "--no-entry", "--js-library=$(location @proxy_wasm_cpp_sdk//:proxy_wasm_intrinsics_js)", From 1f4c2db4030f8514548da6ad77a7ae17f4e805d1 Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Thu, 10 Mar 2022 16:09:24 -0800 Subject: [PATCH 06/12] review: restore previous copyright to cleanup diff. Signed-off-by: Piotr Sikora --- bazel/wasm/wasm.bzl | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/bazel/wasm/wasm.bzl b/bazel/wasm/wasm.bzl index ab316f2..b8727d9 100644 --- a/bazel/wasm/wasm.bzl +++ b/bazel/wasm/wasm.bzl @@ -1,16 +1,17 @@ -# Copyright 2022 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. +# Copyright 2016-2020 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. def wasm_cc_binary(**kwargs): fail("`wasm_cc_binary` is deprecated. Please use `proxy_wasm_cc_binary` from `@proxy_wasm_cpp_sdk//bazel:defs.bzl`.") From e7afdb47554cd16fda07b31652db43a67ec7dc4a Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Thu, 10 Mar 2022 16:10:13 -0800 Subject: [PATCH 07/12] review: use transitions to apply copts/linkopts to dependencies. Signed-off-by: Piotr Sikora --- .bazelrc | 1 - bazel/defs.bzl | 81 ++++++++++++++++++++++++++++++++++++++---- bazel/repositories.bzl | 14 +++----- 3 files changed, 80 insertions(+), 16 deletions(-) delete mode 100644 .bazelrc diff --git a/.bazelrc b/.bazelrc deleted file mode 100644 index 5b3d13f..0000000 --- a/.bazelrc +++ /dev/null @@ -1 +0,0 @@ -build --cxxopt=-std=c++17 diff --git a/bazel/defs.bzl b/bazel/defs.bzl index cd37092..464e00f 100644 --- a/bazel/defs.bzl +++ b/bazel/defs.bzl @@ -15,6 +15,72 @@ load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary") load("@rules_cc//cc:defs.bzl", "cc_binary") +def _optimized_wasm_cc_binary_transition_impl(settings, attr): + copts = list(settings["//command_line_option:copt"]) + copts.append("-std=c++17") + copts.append("-O3") + copts.append("-fno-sanitize=all") + + linkopts = list(settings["//command_line_option:linkopt"]) + linkopts.append("-std=c++17") + linkopts.append("-O3") + linkopts.append("-fno-sanitize=all") + + # TODO(PiotrSikora): Add LTO when fixed upstream, blocked on + # https://github.com/emscripten-core/emsdk/issues/971 + #copts.append("-flto") + #linkopts.append("-flto") + + return { + "//command_line_option:copt": copts, + "//command_line_option:linkopt": linkopts, + } + +_optimized_wasm_cc_binary_transition = transition( + implementation = _optimized_wasm_cc_binary_transition_impl, + inputs = [ + "//command_line_option:copt", + "//command_line_option:linkopt", + ], + outputs = [ + "//command_line_option:copt", + "//command_line_option:linkopt", + ], +) + +def _optimized_wasm_cc_binary_impl(ctx): + input_binary = ctx.attr.wasm_cc_target[0][DefaultInfo].files_to_run.executable + input_runfiles = ctx.attr.wasm_cc_target[0][DefaultInfo].default_runfiles + copied_binary = ctx.actions.declare_file(ctx.attr.name) + + ctx.actions.run( + mnemonic = "CopyFile", + executable = "cp", + arguments = [input_binary.path, copied_binary.path], + inputs = [input_binary], + outputs = [copied_binary], + ) + + return DefaultInfo( + executable = copied_binary, + runfiles = input_runfiles, + ) + +_optimized_wasm_cc_binary = rule( + implementation = _optimized_wasm_cc_binary_impl, + attrs = { + "wasm_cc_target": attr.label( + cfg = _optimized_wasm_cc_binary_transition, + mandatory = True, + doc = "The wasm_cc_binary to extract files from.", + ), + "_allowlist_function_transition": attr.label( + default = "@bazel_tools//tools/allowlists/function_transition_allowlist", + ), + }, + executable = True, +) + def proxy_wasm_cc_binary( name, additional_linker_inputs = [], @@ -28,11 +94,6 @@ def proxy_wasm_cc_binary( additional_linker_inputs = additional_linker_inputs + [ "@proxy_wasm_cpp_sdk//:proxy_wasm_intrinsics_js", ], - copts = copts + [ - "-std=c++17", - "-flto", - "-O3", - ], linkopts = linkopts + [ "--no-entry", "--js-library=$(location @proxy_wasm_cpp_sdk//:proxy_wasm_intrinsics_js)", @@ -49,7 +110,15 @@ def proxy_wasm_cc_binary( ) wasm_cc_binary( - name = name, + name = "default_" + name, cc_target = ":proxy_wasm_" + name.rstrip(".wasm"), + tags = tags + [ + "manual", + ], + ) + + _optimized_wasm_cc_binary( + name = name, + wasm_cc_target = ":default_" + name, tags = tags, ) diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index c5f0c76..ac6205b 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -18,15 +18,11 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") def proxy_wasm_cpp_host_repositories(): maybe( http_archive, - name = "emscripten_toolchain", - build_file = "@proxy_wasm_cpp_sdk//:emscripten-toolchain.BUILD", - patch_cmds = [ - "./emsdk install 3.1.7", - "./emsdk activate --embedded 3.1.7", - ], - strip_prefix = "emsdk-3.1.7", - url = "https://github.com/emscripten-core/emsdk/archive/3.1.7.tar.gz", - sha256 = "bcceced0b7cad2e08375adf74ef20fa431230abbae8766bdad268c43e34f8d03", + name = "emsdk", + sha256 = "1ca0ff918d476c55707bb99bc0452be28ac5fb8f22a9260a8aae8a38d1bc0e27", + # v3.1.7 with Bazel fixes + strip_prefix = "emsdk-0ea8f8a8707070e9a7c83fbb4a3065683bcf1799/bazel", + url = "https://github.com/emscripten-core/emsdk/archive/0ea8f8a8707070e9a7c83fbb4a3065683bcf1799.tar.gz", ) maybe( From 892cd4d3b9d6dea661cd269d10b3cfc560540264 Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Thu, 10 Mar 2022 16:52:40 -0800 Subject: [PATCH 08/12] review: don't force -std=c++17 on all dependencies. Instead, declare it only for Proxy-Wasm C++ SDK source files. Signed-off-by: Piotr Sikora --- BUILD | 9 +++++++-- bazel/defs.bzl | 3 --- example/BUILD | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/BUILD b/BUILD index f5b8ec3..5b2730e 100644 --- a/BUILD +++ b/BUILD @@ -13,6 +13,7 @@ cc_library( "proxy_wasm_api.h", "proxy_wasm_externs.h", ], + copts = ["-std=c++17"], deps = [ ":common_lib", "@com_google_protobuf//:protobuf_lite", @@ -25,6 +26,7 @@ cc_library( "proxy_wasm_common.h", "proxy_wasm_enums.h", ], + copts = ["-std=c++17"], ) cc_library( @@ -39,6 +41,7 @@ cc_library( "proxy_wasm_externs.h", "proxy_wasm_intrinsics.h", ], + copts = ["-std=c++17"], visibility = ["//visibility:public"], ) @@ -62,7 +65,8 @@ proto_library( cc_library( name = "proxy_wasm_intrinsics_lite", hdrs = ["proxy_wasm_intrinsics_lite.h"], - copts = ["-DPROXY_WASM_PROTOBUF_LITE=1"], + copts = ["-std=c++17"], + defines = ["PROXY_WASM_PROTOBUF_LITE"], visibility = ["//visibility:public"], deps = [ ":proxy_wasm_intrinsics", @@ -75,7 +79,8 @@ cc_library( cc_library( name = "proxy_wasm_intrinsics_full", hdrs = ["proxy_wasm_intrinsics_full.h"], - copts = ["-DPROXY_WASM_PROTOBUF_FULL=1"], + copts = ["-std=c++17"], + defines = ["PROXY_WASM_PROTOBUF_FULL"], visibility = ["//visibility:public"], deps = [ ":proxy_wasm_intrinsics", diff --git a/bazel/defs.bzl b/bazel/defs.bzl index 464e00f..4568ce7 100644 --- a/bazel/defs.bzl +++ b/bazel/defs.bzl @@ -17,12 +17,10 @@ load("@rules_cc//cc:defs.bzl", "cc_binary") def _optimized_wasm_cc_binary_transition_impl(settings, attr): copts = list(settings["//command_line_option:copt"]) - copts.append("-std=c++17") copts.append("-O3") copts.append("-fno-sanitize=all") linkopts = list(settings["//command_line_option:linkopt"]) - linkopts.append("-std=c++17") linkopts.append("-O3") linkopts.append("-fno-sanitize=all") @@ -84,7 +82,6 @@ _optimized_wasm_cc_binary = rule( def proxy_wasm_cc_binary( name, additional_linker_inputs = [], - copts = [], linkopts = [], tags = [], deps = [], diff --git a/example/BUILD b/example/BUILD index 0d41eb5..5399f41 100644 --- a/example/BUILD +++ b/example/BUILD @@ -5,4 +5,5 @@ licenses(["notice"]) # Apache 2 proxy_wasm_cc_binary( name = "http_wasm_example.wasm", srcs = ["http_wasm_example.cc"], + copts = ["-std=c++17"], ) From 952d4e05c05b3d8f5ad7ab7580e6bf61ec423c9b Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Thu, 10 Mar 2022 16:47:58 -0800 Subject: [PATCH 09/12] review: add proxy_wasm_cc_binary(protobuf="none|lite|full"). Signed-off-by: Piotr Sikora --- bazel/defs.bzl | 11 ++++++++--- example/BUILD | 14 ++++++++++++++ example/http_wasm_example.cc | 10 ++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/bazel/defs.bzl b/bazel/defs.bzl index 4568ce7..1cdb089 100644 --- a/bazel/defs.bzl +++ b/bazel/defs.bzl @@ -85,7 +85,14 @@ def proxy_wasm_cc_binary( linkopts = [], tags = [], deps = [], + protobuf = "", **kwargs): + proxy_wasm_deps = ["@proxy_wasm_cpp_sdk//:proxy_wasm_intrinsics"] + if protobuf == "lite": + proxy_wasm_deps.append("@proxy_wasm_cpp_sdk//:proxy_wasm_intrinsics_lite") + if protobuf == "full": + proxy_wasm_deps.append("@proxy_wasm_cpp_sdk//:proxy_wasm_intrinsics_full") + cc_binary( name = "proxy_wasm_" + name.rstrip(".wasm"), additional_linker_inputs = additional_linker_inputs + [ @@ -100,9 +107,7 @@ def proxy_wasm_cc_binary( tags = tags + [ "manual", ], - deps = deps + [ - "@proxy_wasm_cpp_sdk//:proxy_wasm_intrinsics", - ], + deps = deps + proxy_wasm_deps, **kwargs ) diff --git a/example/BUILD b/example/BUILD index 5399f41..ea2cc66 100644 --- a/example/BUILD +++ b/example/BUILD @@ -7,3 +7,17 @@ proxy_wasm_cc_binary( srcs = ["http_wasm_example.cc"], copts = ["-std=c++17"], ) + +proxy_wasm_cc_binary( + name = "http_wasm_example_with_protobuf_lite.wasm", + srcs = ["http_wasm_example.cc"], + copts = ["-std=c++17"], + protobuf = "lite", +) + +proxy_wasm_cc_binary( + name = "http_wasm_example_with_protobuf_full.wasm", + srcs = ["http_wasm_example.cc"], + copts = ["-std=c++17"], + protobuf = "full", +) diff --git a/example/http_wasm_example.cc b/example/http_wasm_example.cc index 23e6738..ca5998a 100644 --- a/example/http_wasm_example.cc +++ b/example/http_wasm_example.cc @@ -46,7 +46,17 @@ static RegisterContextFactory register_ExampleContext(CONTEXT_FACTORY(ExampleCon "my_root_id"); bool ExampleRootContext::onStart(size_t) { +#if defined(PROXY_WASM_PROTOBUF_FULL) + LOG_TRACE("onStart with protobuf (full)"); + google::protobuf::Value value; + value.set_string_value("unused"); +#elif defined(PROXY_WASM_PROTOBUF_LITE) + LOG_TRACE("onStart with protobuf (lite)"); + google::protobuf::Value value; + value.set_string_value("unused"); +#else LOG_TRACE("onStart"); +#endif return true; } From 05862acc58782f108d2193a7f2db461bb6601fdd Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Thu, 10 Mar 2022 17:58:11 -0800 Subject: [PATCH 10/12] review: style. Signed-off-by: Piotr Sikora --- bazel/defs.bzl | 6 +++--- bazel/dependencies_extra.bzl | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bazel/defs.bzl b/bazel/defs.bzl index 1cdb089..3f84b3d 100644 --- a/bazel/defs.bzl +++ b/bazel/defs.bzl @@ -68,9 +68,9 @@ _optimized_wasm_cc_binary = rule( implementation = _optimized_wasm_cc_binary_impl, attrs = { "wasm_cc_target": attr.label( + doc = "The wasm_cc_binary to extract files from.", cfg = _optimized_wasm_cc_binary_transition, mandatory = True, - doc = "The wasm_cc_binary to extract files from.", ), "_allowlist_function_transition": attr.label( default = "@bazel_tools//tools/allowlists/function_transition_allowlist", @@ -112,7 +112,7 @@ def proxy_wasm_cc_binary( ) wasm_cc_binary( - name = "default_" + name, + name = "wasm_" + name, cc_target = ":proxy_wasm_" + name.rstrip(".wasm"), tags = tags + [ "manual", @@ -121,6 +121,6 @@ def proxy_wasm_cc_binary( _optimized_wasm_cc_binary( name = name, - wasm_cc_target = ":default_" + name, + wasm_cc_target = ":wasm_" + name, tags = tags, ) diff --git a/bazel/dependencies_extra.bzl b/bazel/dependencies_extra.bzl index 5ce686a..d06a884 100644 --- a/bazel/dependencies_extra.bzl +++ b/bazel/dependencies_extra.bzl @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@emsdk//:emscripten_deps.bzl", emsdk_emscripten_deps = "emscripten_deps") +load("@emsdk//:emscripten_deps.bzl", "emscripten_deps") # Requires proxy_wasm_cpp_host_dependencies() to be loaded first. def proxy_wasm_cpp_host_dependencies_extra(): - emsdk_emscripten_deps() + emscripten_deps() From c0b49dbddf9d4f5a45119d2487b7e0e973714bc7 Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Sun, 13 Mar 2022 19:58:05 -0700 Subject: [PATCH 11/12] review: clear all global copts/linkopts. Signed-off-by: Piotr Sikora --- bazel/defs.bzl | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/bazel/defs.bzl b/bazel/defs.bzl index 3f84b3d..8bfa09b 100644 --- a/bazel/defs.bzl +++ b/bazel/defs.bzl @@ -16,32 +16,20 @@ load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary") load("@rules_cc//cc:defs.bzl", "cc_binary") def _optimized_wasm_cc_binary_transition_impl(settings, attr): - copts = list(settings["//command_line_option:copt"]) - copts.append("-O3") - copts.append("-fno-sanitize=all") - - linkopts = list(settings["//command_line_option:linkopt"]) - linkopts.append("-O3") - linkopts.append("-fno-sanitize=all") - - # TODO(PiotrSikora): Add LTO when fixed upstream, blocked on - # https://github.com/emscripten-core/emsdk/issues/971 - #copts.append("-flto") - #linkopts.append("-flto") - + # TODO(PiotrSikora): Add -flto to copts/linkopts when fixed in emsdk. + # See: https://github.com/emscripten-core/emsdk/issues/971 return { - "//command_line_option:copt": copts, - "//command_line_option:linkopt": linkopts, + "//command_line_option:copt": ["-O3"], + "//command_line_option:cxxopt": [], + "//command_line_option:linkopt": [], } _optimized_wasm_cc_binary_transition = transition( implementation = _optimized_wasm_cc_binary_transition_impl, - inputs = [ - "//command_line_option:copt", - "//command_line_option:linkopt", - ], + inputs = [], outputs = [ "//command_line_option:copt", + "//command_line_option:cxxopt", "//command_line_option:linkopt", ], ) From 820709e2d0ab471c1c05fa8eb17cf6d34bb64676 Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Sun, 13 Mar 2022 19:58:36 -0700 Subject: [PATCH 12/12] review: exclude proxy_wasm_cc_binary from coverage. Signed-off-by: Piotr Sikora --- bazel/defs.bzl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bazel/defs.bzl b/bazel/defs.bzl index 8bfa09b..2e20a86 100644 --- a/bazel/defs.bzl +++ b/bazel/defs.bzl @@ -22,6 +22,7 @@ def _optimized_wasm_cc_binary_transition_impl(settings, attr): "//command_line_option:copt": ["-O3"], "//command_line_option:cxxopt": [], "//command_line_option:linkopt": [], + "//command_line_option:collect_code_coverage": False, } _optimized_wasm_cc_binary_transition = transition( @@ -31,6 +32,7 @@ _optimized_wasm_cc_binary_transition = transition( "//command_line_option:copt", "//command_line_option:cxxopt", "//command_line_option:linkopt", + "//command_line_option:collect_code_coverage", ], )