diff --git a/.bazelrc b/.bazelrc index ab9a27f84..b9b5de491 100644 --- a/.bazelrc +++ b/.bazelrc @@ -65,6 +65,8 @@ build:clang-tidy --output_groups=report build:gcc --action_env=BAZEL_COMPILER=gcc build:gcc --action_env=CC=gcc build:gcc --action_env=CXX=g++ +build:gcc --cxxopt -Wno-invalid-offsetof --host_cxxopt -Wno-invalid-offsetof +build:gcc --cxxopt -Wno-deprecated --host_cxxopt -Wno-deprecated # Use Zig C/C++ compiler. build:zig-cc --incompatible_enable_cc_toolchain_resolution @@ -80,10 +82,10 @@ build:zig-cc-linux-aarch64 --test_env=QEMU_LD_PREFIX=/usr/aarch64-linux-gnu/ build --enable_platform_specific_config -# Use C++17. -build:linux --cxxopt=-std=c++17 -build:macos --cxxopt=-std=c++17 -build:windows --cxxopt="/std:c++17" +# Use C++20. +build:linux --cxxopt=-std=c++20 --host_cxxopt=-std=c++20 +build:macos --cxxopt=-std=c++20 --host_cxxopt=-std=c++20 +build:windows --cxxopt="/std:c++20" --host_cxxopt="/std:c++20" # Enable symlinks and runfiles on Windows (enabled by default on other platforms). startup --windows_enable_symlinks diff --git a/.clang-tidy b/.clang-tidy index ceab9ad4a..ea657db54 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -19,5 +19,6 @@ Checks: clang-*, -readability-magic-numbers, -readability-make-member-function-const, -readability-simplify-boolean-expr, + -clang-diagnostic-builtin-macro-redefined, WarningsAsErrors: '*' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 66ec91bfc..548c099a6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -118,7 +118,7 @@ jobs: os: ubuntu-22.04 arch: x86_64 action: test - flags: --config=clang-asan-strict --define=crypto=system + flags: --config=clang-asan --define=crypto=system - name: 'NullVM on Linux/x86_64 with TSan' engine: 'null' os: ubuntu-22.04 @@ -235,7 +235,7 @@ jobs: os: ubuntu-22.04 arch: x86_64 action: test - flags: --config=clang-asan-strict --define=crypto=system + flags: --config=clang-asan --define=crypto=system - name: 'Wasmtime on Linux/aarch64' engine: 'wasmtime' repo: 'com_github_bytecodealliance_wasmtime' diff --git a/bazel/external/googletest.patch b/bazel/external/googletest.patch deleted file mode 100644 index 502ef58b3..000000000 --- a/bazel/external/googletest.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/BUILD.bazel b/BUILD.bazel -index 8099642a85..3598661079 100644 ---- a/BUILD.bazel -+++ b/BUILD.bazel -@@ -40,7 +40,7 @@ exports_files(["LICENSE"]) - - config_setting( - name = "windows", -- constraint_values = ["@bazel_tools//platforms:windows"], -+ constraint_values = ["@platforms//os:windows"], - ) - - config_setting( diff --git a/bazel/external/proxy_wasm_cpp_sdk.patch b/bazel/external/proxy_wasm_cpp_sdk.patch new file mode 100644 index 000000000..c9ef490c1 --- /dev/null +++ b/bazel/external/proxy_wasm_cpp_sdk.patch @@ -0,0 +1,33 @@ +# Address g++ -std=c++20 variadic template compilation issue: +# https://github.com/proxy-wasm/proxy-wasm-cpp-host/pull/411#issuecomment-2295429152 + +diff --git a/proxy_wasm_api.h b/proxy_wasm_api.h +index 166b49c..263d2b9 100644 +--- a/proxy_wasm_api.h ++++ b/proxy_wasm_api.h +@@ -1207,7 +1207,7 @@ struct SimpleHistogram { + template struct Counter : public MetricBase { + static Counter *New(std::string_view name, MetricTagDescriptor... fieldnames); + +- Counter(std::string_view name, MetricTagDescriptor... descriptors) ++ Counter(std::string_view name, MetricTagDescriptor... descriptors) + : Counter(std::string(name), std::vector({toMetricTag(descriptors)...})) { + } + +@@ -1256,7 +1256,7 @@ inline Counter *Counter::New(std::string_view name, + template struct Gauge : public MetricBase { + static Gauge *New(std::string_view name, MetricTagDescriptor... fieldnames); + +- Gauge(std::string_view name, MetricTagDescriptor... descriptors) ++ Gauge(std::string_view name, MetricTagDescriptor... descriptors) + : Gauge(std::string(name), std::vector({toMetricTag(descriptors)...})) {} + + SimpleGauge resolve(Tags... f) { +@@ -1302,6 +1302,6 @@ inline Gauge *Gauge::New(std::string_view name, + template struct Histogram : public MetricBase { + static Histogram *New(std::string_view name, MetricTagDescriptor... fieldnames); + +- Histogram(std::string_view name, MetricTagDescriptor... descriptors) ++ Histogram(std::string_view name, MetricTagDescriptor... descriptors) + : Histogram(std::string(name), + std::vector({toMetricTag(descriptors)...})) {} diff --git a/bazel/external/v8.patch b/bazel/external/v8.patch index 58e7f9ba0..b8e16c0b6 100644 --- a/bazel/external/v8.patch +++ b/bazel/external/v8.patch @@ -1,13 +1,20 @@ # 1. Disable pointer compression (limits the maximum number of WasmVMs). # 2. Don't expose Wasm C API (only Wasm C++ API). -# 3. Fix gcc build error by disabling nonnull warning. -# 4. Allow compiling v8 on macOS 10.15 to 13.0. TODO(dio): Will remove this patch when https://bugs.chromium.org/p/v8/issues/detail?id=13428 is fixed. +# 3. Revert v8 commit b26554ec368e9553782012c96aa5e99b163eaff2, which removed +# use of _allowlist_function_transition from v8 bazel/defs.bzl, since it is +# still required by the version of Bazel we currently use (6.5.0). +# 4. Tweak where v8 looks for its fp16 dependency, since it isn't downloaded by +# gn. +# 5. Set torque generator path to location where Bazel can find outputs. +# 6. Compile v8 with -Wno-deprecated-declarations +# 7. Cherrypick V8 commit 35888fee7bbaaaf1f02ccc88a95c9a336fc790bc to fix gcc +# build error. diff --git a/BUILD.bazel b/BUILD.bazel -index 4e89f90e7e..3fcb38b3f3 100644 +index 30be47fa333..72de2d422ca 100644 --- a/BUILD.bazel +++ b/BUILD.bazel -@@ -157,7 +157,7 @@ v8_int( +@@ -220,7 +220,7 @@ v8_int( # If no explicit value for v8_enable_pointer_compression, we set it to 'none'. v8_string( name = "v8_enable_pointer_compression", @@ -16,42 +23,129 @@ index 4e89f90e7e..3fcb38b3f3 100644 ) # Default setting for v8_enable_pointer_compression. +@@ -3698,14 +3698,22 @@ filegroup( + + v8_library( + name = "lib_fp16", +- srcs = ["third_party/fp16/src/include/fp16.h"], +- hdrs = [ +- "third_party/fp16/src/include/fp16/fp16.h", +- "third_party/fp16/src/include/fp16/bitcasts.h", ++ hdrs = ["@fp16//:include/fp16.h"], ++ srcs = [], ++ include_prefix = "third_party/fp16/src", ++ deps = [ ++ "lib_fp16_includes", + ], +- includes = [ +- "third_party/fp16/src/include", ++) ++ ++v8_library( ++ name = "lib_fp16_includes", ++ hdrs = [ ++ "@fp16//:include/fp16/fp16.h", ++ "@fp16//:include/fp16/bitcasts.h", + ], ++ srcs = [], ++ strip_include_prefix = "include", + ) + + filegroup( diff --git a/bazel/defs.bzl b/bazel/defs.bzl -index e957c0fad3..063627b72b 100644 +index 520a311595e..64b4928abe5 100644 --- a/bazel/defs.bzl +++ b/bazel/defs.bzl -@@ -131,6 +131,7 @@ def _default_args(): - "-Wno-redundant-move", - "-Wno-return-type", - "-Wno-stringop-overflow", -+ "-Wno-nonnull", - # Use GNU dialect, because GCC doesn't allow using - # ##__VA_ARGS__ when in standards-conforming mode. - "-std=gnu++17", -@@ -151,6 +152,18 @@ def _default_args(): - "-fno-integrated-as", +@@ -102,7 +102,9 @@ def _default_args(): ], "//conditions:default": [], -+ }) + select({ -+ "@v8//bazel/config:is_macos": [ -+ # The clang available on macOS catalina has a warning that isn't clean on v8 code. -+ "-Wno-range-loop-analysis", -+ -+ # To supress warning on deprecated declaration on v8 code. For example: -+ # external/v8/src/base/platform/platform-darwin.cc:56:22: 'getsectdatafromheader_64' -+ # is deprecated: first deprecated in macOS 13.0. -+ # https://bugs.chromium.org/p/v8/issues/detail?id=13428. -+ "-Wno-deprecated-declarations", -+ ], -+ "//conditions:default": [], }), - includes = ["include"], - linkopts = select({ +- copts = select({ ++ copts = [ ++ "-Wno-deprecated-declarations", ++ ] + select({ + "@v8//bazel/config:is_posix": [ + "-fPIC", + "-fno-strict-aliasing", +@@ -131,7 +133,6 @@ def _default_args(): + "-Wno-array-bounds", + "-Wno-class-memaccess", + "-Wno-comments", +- "-Wno-deprecated-declarations", + "-Wno-implicit-fallthrough", + "-Wno-int-in-bool-context", + "-Wno-maybe-uninitialized", +@@ -316,7 +317,7 @@ def v8_library( + # split the set of outputs by using OutputGroupInfo, that way we do not need to + # run the torque generator twice. + def _torque_files_impl(ctx): +- v8root = "." ++ v8root = "external/v8" + + # Arguments + args = [] +@@ -480,6 +481,9 @@ _v8_mksnapshot = rule( + cfg = "exec", + ), + "target_os": attr.string(mandatory = True), ++ "_allowlist_function_transition": attr.label( ++ default = "@bazel_tools//tools/allowlists/function_transition_allowlist", ++ ), + "prefix": attr.string(mandatory = True), + "suffix": attr.string(mandatory = True), + }, +diff --git a/bazel/v8-non-pointer-compression.bzl b/bazel/v8-non-pointer-compression.bzl +index 8c929454840..57336154cf7 100644 +--- a/bazel/v8-non-pointer-compression.bzl ++++ b/bazel/v8-non-pointer-compression.bzl +@@ -47,6 +47,17 @@ v8_binary_non_pointer_compression = rule( + # Note specificaly how it's configured with v8_target_cpu_transition, which + # ensures that setting propagates down the graph. + "binary": attr.label(cfg = v8_disable_pointer_compression), ++ # This is a stock Bazel requirement for any rule that uses Starlark ++ # transitions. It's okay to copy the below verbatim for all such rules. ++ # ++ # The purpose of this requirement is to give the ability to restrict ++ # which packages can invoke these rules, since Starlark transitions ++ # make much larger graphs possible that can have memory and performance ++ # consequences for your build. The whitelist defaults to "everything". ++ # But you can redefine it more strictly if you feel that's prudent. ++ "_allowlist_function_transition": attr.label( ++ default = "@bazel_tools//tools/allowlists/function_transition_allowlist", ++ ), + }, + # Making this executable means it works with "$ bazel run". + executable = True, +diff --git a/src/base/macros.h b/src/base/macros.h +index 794505278e1..890365bf3ae 100644 +--- a/src/base/macros.h ++++ b/src/base/macros.h +@@ -182,7 +182,7 @@ namespace base { + // base::is_trivially_copyable will differ for these cases. + template + struct is_trivially_copyable { +-#if V8_CC_MSVC ++#if V8_CC_MSVC || (__GNUC__ == 12 && __GNUC_MINOR__ <= 2) + // Unfortunately, MSVC 2015 is broken in that std::is_trivially_copyable can + // be false even though it should be true according to the standard. + // (status at 2018-02-26, observed on the msvc waterfall bot). +@@ -190,6 +190,11 @@ struct is_trivially_copyable { + // intended, so we reimplement this according to the standard. + // See also https://developercommunity.visualstudio.com/content/problem/ + // 170883/msvc-type-traits-stdis-trivial-is-bugged.html. ++ // ++ // GCC 12.1 and 12.2 are broken too, they are shipped by some stable Linux ++ // distributions, so the same polyfill is also used. ++ // See ++ // https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=aeba3e009b0abfccaf01797556445dbf891cc8dc + static constexpr bool value = + // Copy constructor is trivial or deleted. + (std::is_trivially_copy_constructible::value || diff --git a/src/wasm/c-api.cc b/src/wasm/c-api.cc -index 4473e205c0..65a6ec7e1d 100644 +index 2d6d0f6c270..61d071acd52 100644 --- a/src/wasm/c-api.cc +++ b/src/wasm/c-api.cc -@@ -2247,6 +2247,8 @@ auto Instance::exports() const -> ownvec { +@@ -2360,6 +2360,8 @@ auto Instance::exports() const -> ownvec { } // namespace wasm @@ -60,7 +154,7 @@ index 4473e205c0..65a6ec7e1d 100644 // BEGIN FILE wasm-c.cc extern "C" { -@@ -3274,3 +3276,5 @@ wasm_instance_t* wasm_frame_instance(const wasm_frame_t* frame) { +@@ -3386,3 +3388,5 @@ wasm_instance_t* wasm_frame_instance(const wasm_frame_t* frame) { #undef WASM_DEFINE_SHARABLE_REF } // extern "C" diff --git a/bazel/external/v8_include.patch b/bazel/external/v8_include.patch deleted file mode 100644 index 0d0fe210c..000000000 --- a/bazel/external/v8_include.patch +++ /dev/null @@ -1,41 +0,0 @@ -# fix include types for late clang (15.0.7) / gcc (13.2.1) -# for Arch linux / Fedora, like in -# In file included from external/v8/src/torque/torque.cc:5: -# In file included from external/v8/src/torque/source-positions.h:10: -# In file included from external/v8/src/torque/contextual.h:10: -# In file included from external/v8/src/base/macros.h:12: -# external/v8/src/base/logging.h:154:26: error: use of undeclared identifier 'uint16_t' - -diff --git a/src/base/logging.h b/src/base/logging.h ---- a/src/base/logging.h -+++ b/src/base/logging.h -@@ -5,6 +5,7 @@ - #ifndef V8_BASE_LOGGING_H_ - #define V8_BASE_LOGGING_H_ - -+#include - #include - #include - #include -diff --git a/src/base/macros.h b/src/base/macros.h ---- a/src/base/macros.h -+++ b/src/base/macros.h -@@ -5,6 +5,7 @@ - #ifndef V8_BASE_MACROS_H_ - #define V8_BASE_MACROS_H_ - -+#include - #include - #include - -diff --git a/src/inspector/v8-string-conversions.h b/src/inspector/v8-string-conversions.h ---- a/src/inspector/v8-string-conversions.h -+++ b/src/inspector/v8-string-conversions.h -@@ -5,6 +5,7 @@ - #ifndef V8_INSPECTOR_V8_STRING_CONVERSIONS_H_ - #define V8_INSPECTOR_V8_STRING_CONVERSIONS_H_ - -+#include - #include - - // Conversion routines between UT8 and UTF16, used by string-16.{h,cc}. You may diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 2586ed21b..e3f0b0fdc 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -133,6 +133,8 @@ def proxy_wasm_cpp_host_repositories(): sha256 = "89792fc1abca331f29f99870476a04146de5e82ff903bdffca90e6729c1f2470", strip_prefix = "proxy-wasm-cpp-sdk-95bb82ce45c41d9100fd1ec15d2ffc67f7f3ceee", urls = ["https://github.com/proxy-wasm/proxy-wasm-cpp-sdk/archive/95bb82ce45c41d9100fd1ec15d2ffc67f7f3ceee.tar.gz"], + patches = ["@proxy_wasm_cpp_host//bazel/external:proxy_wasm_cpp_sdk.patch"], + patch_args = ["-p1"], ) # Test dependencies. @@ -140,11 +142,9 @@ def proxy_wasm_cpp_host_repositories(): maybe( http_archive, name = "com_google_googletest", - sha256 = "9dc9157a9a1551ec7a7e43daea9a694a0bb5fb8bec81235d8a1e6ef64c716dcb", - strip_prefix = "googletest-release-1.10.0", - urls = ["https://github.com/google/googletest/archive/release-1.10.0.tar.gz"], - patches = ["@proxy_wasm_cpp_host//bazel/external:googletest.patch"], - patch_args = ["-p1"], + sha256 = "7b42b4d6ed48810c5362c265a17faebe90dc2373c885e5216439d37927f02926", + strip_prefix = "googletest-1.15.2", + urls = ["https://github.com/google/googletest/archive/refs/tags/v1.15.2.tar.gz"], ) # NullVM dependencies. @@ -162,13 +162,12 @@ def proxy_wasm_cpp_host_repositories(): maybe( git_repository, name = "v8", - # 10.7.193.13 - commit = "6c8b357a84847a479cd329478522feefc1c3195a", + # 12.7.224.18 + commit = "503eb7e9a50b0211f8db54ea362ea06ef56c940d", remote = "https://chromium.googlesource.com/v8/v8", - shallow_since = "1664374400 +0000", + shallow_since = "1722877350 -0400", patches = [ "@proxy_wasm_cpp_host//bazel/external:v8.patch", - "@proxy_wasm_cpp_host//bazel/external:v8_include.patch", ], patch_args = ["-p1"], ) @@ -178,18 +177,32 @@ def proxy_wasm_cpp_host_repositories(): actual = "@v8//:wee8", ) - maybe( - new_git_repository, - name = "com_googlesource_chromium_base_trace_event_common", - build_file = "@v8//:bazel/BUILD.trace_event_common", - commit = "521ac34ebd795939c7e16b37d9d3ddb40e8ed556", - remote = "https://chromium.googlesource.com/chromium/src/base/trace_event/common.git", - shallow_since = "1662508800 +0000", + native.bind( + name = "absl_optional", + actual = "@com_google_absl//absl/types:optional", + ) + + native.bind( + name = "absl_btree", + actual = "@com_google_absl//absl/container:btree", ) native.bind( - name = "base_trace_event_common", - actual = "@com_googlesource_chromium_base_trace_event_common//:trace_event_common", + name = "absl_flat_hash_map", + actual = "@com_google_absl//absl/container:flat_hash_map", + ) + + native.bind( + name = "absl_flat_hash_set", + actual = "@com_google_absl//absl/container:flat_hash_set", + ) + + maybe( + git_repository, + name = "fp16", + commit = "0a92994d729ff76a58f692d3028ca1b64b145d91", + build_file_content = "exports_files(glob([\"**\"]))", + remote = "https://chromium.googlesource.com/external/github.com/Maratyszcza/FP16.git", ) # WAMR with dependencies. diff --git a/test/utility.h b/test/utility.h index 27b3b0493..be60d3218 100644 --- a/test/utility.h +++ b/test/utility.h @@ -197,4 +197,7 @@ class TestVm : public testing::TestWithParam { std::string engine_; }; +// TODO: remove when #412 is fixed. +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(TestVm); + } // namespace proxy_wasm