From 9337c10824b7a0d9725b30b474d0e8c0ee65f638 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Wed, 12 May 2021 13:32:27 +0900 Subject: [PATCH 01/24] build: enable WAMR and LLVM builds. Signed-off-by: Takeshi Yoneda --- .github/workflows/cpp.yml | 2 +- BUILD | 7 +- bazel/external/llvm.BUILD | 114 ++++++++++++++++++++++++ bazel/external/llvm.patch | 25 ++++++ bazel/external/proxy-wasm-cpp-sdk.BUILD | 2 + bazel/external/wamr.BUILD | 14 ++- bazel/external/wasm-c-api.BUILD | 2 + bazel/external/wasmtime.BUILD | 1 + bazel/repositories.bzl | 10 +++ 9 files changed, 168 insertions(+), 9 deletions(-) create mode 100644 bazel/external/llvm.BUILD create mode 100644 bazel/external/llvm.patch diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index ab27b279..20227beb 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -60,7 +60,7 @@ jobs: strategy: matrix: # TODO(mathetake): Add other runtimes. - runtime: [ "wasmtime" ] + runtime: [ "wamr", "wasmtime" ] steps: - uses: actions/checkout@v2 diff --git a/BUILD b/BUILD index 2f760f84..bdb57d2f 100644 --- a/BUILD +++ b/BUILD @@ -54,13 +54,12 @@ cc_library( cc_library( name = "wamr_lib", srcs = glob([ - # TODO(@mathetake): Add WAMR lib. - # "src/wamr/*.h", - # "src/wamr/*.cc", + "src/wamr/*.h", + "src/wamr/*.cc", ]), deps = [ ":common_lib", - # TODO(@mathetake): Add WAMR lib. + "@wamr//:wamr_lib", ], ) diff --git a/bazel/external/llvm.BUILD b/bazel/external/llvm.BUILD new file mode 100644 index 00000000..8f1b8023 --- /dev/null +++ b/bazel/external/llvm.BUILD @@ -0,0 +1,114 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") + +licenses(["notice"]) # Apache 2 + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "srcs", + srcs = glob(["**"]), + visibility = ["//visibility:public"], +) + +cmake( + name = "llvm_lib", + cache_entries = { + # Disable both: BUILD and INCLUDE, since some of the INCLUDE + # targets build code instead of only generating build files. + "LLVM_BUILD_DOCS": "off", + "LLVM_INCLUDE_DOCS": "off", + "LLVM_BUILD_EXAMPLES": "off", + "LLVM_INCLUDE_EXAMPLES": "off", + "LLVM_BUILD_RUNTIME": "off", + "LLVM_BUILD_RUNTIMES": "off", + "LLVM_INCLUDE_RUNTIMES": "off", + "LLVM_BUILD_TESTS": "off", + "LLVM_INCLUDE_TESTS": "off", + "LLVM_BUILD_TOOLS": "off", + "LLVM_INCLUDE_TOOLS": "off", + "LLVM_BUILD_UTILS": "off", + "LLVM_INCLUDE_UTILS": "off", + "LLVM_ENABLE_LIBEDIT": "off", + "LLVM_ENABLE_LIBXML2": "off", + "LLVM_ENABLE_TERMINFO": "off", + "LLVM_ENABLE_ZLIB": "off", + "LLVM_TARGETS_TO_BUILD": "X86", + # Workaround for the issue with statically linked libstdc++ + # using -l:libstdc++.a. + "CMAKE_CXX_FLAGS": "-lstdc++", + }, + env_vars = { + # Workaround for the -DDEBUG flag added in fastbuild on macOS, + # which conflicts with DEBUG macro used in LLVM. + "CFLAGS": "-UDEBUG", + "CXXFLAGS": "-UDEBUG", + "ASMFLAGS": "-UDEBUG", + }, + lib_source = ":srcs", + out_static_libs = [ + # Order from llvm-config --libnames. + "libLLVMInterpreter.a", + "libLLVMWindowsManifest.a", + "libLLVMLibDriver.a", + "libLLVMObjectYAML.a", + "libLLVMCoverage.a", + "libLLVMLineEditor.a", + "libLLVMDlltoolDriver.a", + "libLLVMOption.a", + "libLLVMTableGen.a", + "libLLVMFuzzMutate.a", + "libLLVMSymbolize.a", + "libLLVMCoroutines.a", + "libLLVMDebugInfoPDB.a", + "libLLVMLTO.a", + "libLLVMObjCARCOpts.a", + "libLLVMMIRParser.a", + "libLLVMOrcJIT.a", + "libLLVMOrcError.a", + "libLLVMJITLink.a", + "libLLVMPasses.a", + "libLLVMipo.a", + "libLLVMInstrumentation.a", + "libLLVMVectorize.a", + "libLLVMLinker.a", + "libLLVMIRReader.a", + "libLLVMAsmParser.a", + "libLLVMX86Disassembler.a", + "libLLVMX86AsmParser.a", + "libLLVMX86CodeGen.a", + "libLLVMCFGuard.a", + "libLLVMGlobalISel.a", + "libLLVMSelectionDAG.a", + "libLLVMAsmPrinter.a", + "libLLVMDebugInfoDWARF.a", + "libLLVMCodeGen.a", + "libLLVMScalarOpts.a", + "libLLVMInstCombine.a", + "libLLVMAggressiveInstCombine.a", + "libLLVMTransformUtils.a", + "libLLVMBitWriter.a", + "libLLVMX86Desc.a", + "libLLVMMCDisassembler.a", + "libLLVMX86Utils.a", + "libLLVMX86Info.a", + "libLLVMMCJIT.a", + "libLLVMExecutionEngine.a", + "libLLVMTarget.a", + "libLLVMAnalysis.a", + "libLLVMProfileData.a", + "libLLVMRuntimeDyld.a", + "libLLVMObject.a", + "libLLVMTextAPI.a", + "libLLVMMCParser.a", + "libLLVMBitReader.a", + "libLLVMMC.a", + "libLLVMDebugInfoCodeView.a", + "libLLVMDebugInfoMSF.a", + "libLLVMCore.a", + "libLLVMRemarks.a", + "libLLVMBitstreamReader.a", + "libLLVMBinaryFormat.a", + "libLLVMSupport.a", + "libLLVMDemangle.a", + ], +) diff --git a/bazel/external/llvm.patch b/bazel/external/llvm.patch new file mode 100644 index 00000000..cd02f284 --- /dev/null +++ b/bazel/external/llvm.patch @@ -0,0 +1,25 @@ +# Workaround for Envoy's CMAKE_BUILD_TYPE=Bazel. +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -247,7 +247,7 @@ + string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) + + if (CMAKE_BUILD_TYPE AND +- NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL)$") ++ NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL|BAZEL)$") + message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") + endif() + +# Workaround for a missing -fuse-ld flag in CXXFLAGS, which results in +# different linkers being used during configure and compilation phases. +--- a/cmake/modules/HandleLLVMOptions.cmake ++++ b/cmake/modules/HandleLLVMOptions.cmake +@@ -718,8 +718,6 @@ endif() + if (UNIX AND CMAKE_GENERATOR STREQUAL "Ninja") + include(CheckLinkerFlag) + check_linker_flag("-Wl,--color-diagnostics" LINKER_SUPPORTS_COLOR_DIAGNOSTICS) +- append_if(LINKER_SUPPORTS_COLOR_DIAGNOSTICS "-Wl,--color-diagnostics" +- CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) + endif() + + # Add flags for add_dead_strip(). diff --git a/bazel/external/proxy-wasm-cpp-sdk.BUILD b/bazel/external/proxy-wasm-cpp-sdk.BUILD index 5df5ef81..ec99443c 100644 --- a/bazel/external/proxy-wasm-cpp-sdk.BUILD +++ b/bazel/external/proxy-wasm-cpp-sdk.BUILD @@ -1,3 +1,5 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + licenses(["notice"]) # Apache 2 package(default_visibility = ["//visibility:public"]) diff --git a/bazel/external/wamr.BUILD b/bazel/external/wamr.BUILD index f1d82a06..076215fd 100644 --- a/bazel/external/wamr.BUILD +++ b/bazel/external/wamr.BUILD @@ -1,7 +1,7 @@ -licenses(["notice"]) # Apache 2 - load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") +licenses(["notice"]) # Apache 2 + package(default_visibility = ["//visibility:public"]) filegroup( @@ -11,15 +11,21 @@ filegroup( ) cmake( - name = "libiwasm", + name = "wamr_lib", cache_entries = { + "LLVM_DIR": "$EXT_BUILD_DEPS/copy_llvm/llvm/lib/cmake/llvm", "WAMR_BUILD_INTERP": "1", "WAMR_BUILD_JIT": "0", "WAMR_BUILD_AOT": "0", "WAMR_BUILD_SIMD": "0", "WAMR_BUILD_MULTI_MODULE": "1", "WAMR_BUILD_LIBC_WASI": "0", + "WAMR_BUILD_TAIL_CALL": "1", }, + defines = ["WASM_WAMR"], lib_source = ":srcs", - out_shared_libs = ["libiwasm.so"], + out_static_libs = ["libvmlib.a"], + deps = [ + "@llvm//:llvm_lib", + ], ) diff --git a/bazel/external/wasm-c-api.BUILD b/bazel/external/wasm-c-api.BUILD index 22cd50da..06a7fa2f 100644 --- a/bazel/external/wasm-c-api.BUILD +++ b/bazel/external/wasm-c-api.BUILD @@ -1,3 +1,5 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + licenses(["notice"]) # Apache 2 package(default_visibility = ["//visibility:public"]) diff --git a/bazel/external/wasmtime.BUILD b/bazel/external/wasmtime.BUILD index f6feed7e..d8afdff3 100644 --- a/bazel/external/wasmtime.BUILD +++ b/bazel/external/wasmtime.BUILD @@ -1,3 +1,4 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") load("@rules_rust//rust:rust.bzl", "rust_library") licenses(["notice"]) # Apache 2 diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index d87c8fbb..05188e92 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -80,3 +80,13 @@ def proxy_wasm_cpp_host_repositories(): strip_prefix = "rules_foreign_cc-0.2.0", url = "https://github.com/bazelbuild/rules_foreign_cc/archive/0.2.0.tar.gz", ) + + http_archive( + name = "llvm", + build_file = "@proxy_wasm_cpp_host//bazel/external:llvm.BUILD", + sha256 = "df83a44b3a9a71029049ec101fb0077ecbbdf5fe41e395215025779099a98fdf", + strip_prefix = "llvm-10.0.0.src", + url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/llvm-10.0.0.src.tar.xz", + patch_args = ["-p1"], + patches = ["@proxy_wasm_cpp_host//bazel/external:llvm.patch"], + ) From fe09128dd93239a82781773f60da6ea519d31392 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Wed, 12 May 2021 14:13:45 +0900 Subject: [PATCH 02/24] Add WAVM. Signed-off-by: Takeshi Yoneda --- .github/workflows/cpp.yml | 6 +++--- BUILD | 7 +++---- bazel/external/llvm.BUILD | 2 -- bazel/external/wamr.BUILD | 1 - bazel/external/wavm.BUILD | 38 ++++++++++++++++++++++++++++++++++++++ bazel/repositories.bzl | 8 ++++++++ 6 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 bazel/external/wavm.BUILD diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index 20227beb..bc3990f3 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -59,8 +59,8 @@ jobs: strategy: matrix: - # TODO(mathetake): Add other runtimes. - runtime: [ "wamr", "wasmtime" ] + # TODO(mathetake): Add V8. + runtime: [ "wamr", "wasmtime", "wavm" ] steps: - uses: actions/checkout@v2 @@ -69,7 +69,7 @@ jobs: uses: actions/cache@v1 with: path: "/home/runner/.cache/bazel" - key: bazel-${{ matrix.runtime }} + key: bazel-${{ matrix.runtime }}- - name: Test run: | diff --git a/BUILD b/BUILD index bdb57d2f..a9f7fd2c 100644 --- a/BUILD +++ b/BUILD @@ -78,13 +78,12 @@ cc_library( cc_library( name = "wavm_lib", srcs = glob([ - # TODO(@mathetake): Add WAVM lib. - # "src/wavm/*.h", - # "src/wavm/*.cc", + "src/wavm/*.h", + "src/wavm/*.cc", ]), deps = [ ":common_lib", - # TODO(@mathetake): Add WAVM lib. + "@wavm//:wavm_lib", ], ) diff --git a/bazel/external/llvm.BUILD b/bazel/external/llvm.BUILD index 8f1b8023..acccdbd9 100644 --- a/bazel/external/llvm.BUILD +++ b/bazel/external/llvm.BUILD @@ -7,7 +7,6 @@ package(default_visibility = ["//visibility:public"]) filegroup( name = "srcs", srcs = glob(["**"]), - visibility = ["//visibility:public"], ) cmake( @@ -46,7 +45,6 @@ cmake( }, lib_source = ":srcs", out_static_libs = [ - # Order from llvm-config --libnames. "libLLVMInterpreter.a", "libLLVMWindowsManifest.a", "libLLVMLibDriver.a", diff --git a/bazel/external/wamr.BUILD b/bazel/external/wamr.BUILD index 076215fd..2c1b0b99 100644 --- a/bazel/external/wamr.BUILD +++ b/bazel/external/wamr.BUILD @@ -7,7 +7,6 @@ package(default_visibility = ["//visibility:public"]) filegroup( name = "srcs", srcs = glob(["**"]), - visibility = ["//visibility:public"], ) cmake( diff --git a/bazel/external/wavm.BUILD b/bazel/external/wavm.BUILD new file mode 100644 index 00000000..b9edd18d --- /dev/null +++ b/bazel/external/wavm.BUILD @@ -0,0 +1,38 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") + +licenses(["notice"]) # Apache 2 + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "srcs", + srcs = glob(["**"]), +) + +cmake( + name = "wavm_lib", + binaries = ["wavm"], + cache_entries = { + "LLVM_DIR": "$EXT_BUILD_DEPS/copy_llvm/llvm/lib/cmake/llvm", + "WAVM_ENABLE_STATIC_LINKING": "on", + "WAVM_ENABLE_RELEASE_ASSERTS": "on", + "WAVM_ENABLE_UNWIND": "on", + # Workaround for the issue with statically linked libstdc++ + # using -l:libstdc++.a. + "CMAKE_CXX_FLAGS": "-lstdc++ -Wno-unused-command-line-argument", + }, + defines = ["WASM_WAVM"], + env_vars = { + # Workaround for the -DDEBUG flag added in fastbuild on macOS, + # which conflicts with DEBUG macro used in LLVM. + "CFLAGS": "-UDEBUG", + "CXXFLAGS": "-UDEBUG", + "ASMFLAGS": "-UDEBUG", + }, + lib_source = ":srcs", + static_libraries = [ + "libWAVM.a", + "libWAVMUnwind.a", + ], + deps = ["@llvm//:llvm_lib"], +) diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 05188e92..4694b7a1 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -90,3 +90,11 @@ def proxy_wasm_cpp_host_repositories(): patch_args = ["-p1"], patches = ["@proxy_wasm_cpp_host//bazel/external:llvm.patch"], ) + + http_archive( + name = "wavm", + build_file = "@proxy_wasm_cpp_host//bazel/external:wavm.BUILD", + sha256 = "ce899269516313b400005a8cc9bc3bcd8329663f43f7b4baae211ea0cd456a39", + strip_prefix = "WAVM-79c3aa29366615d9b1593cd527e5b4b94cc6072a", + url = "https://github.com/WAVM/WAVM/archive/79c3aa29366615d9b1593cd527e5b4b94cc6072a.tar.gz", + ) From 26a0890c863dba1cc82960d3504d002280153cc4 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Wed, 12 May 2021 14:14:04 +0900 Subject: [PATCH 03/24] Use clang. Signed-off-by: Takeshi Yoneda --- .bazelrc | 2 ++ .github/workflows/cpp.yml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.bazelrc b/.bazelrc index d63c7058..75fdaa2c 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,4 +1,6 @@ build --enable_platform_specific_config +build --action_env=CC=clang +build --action_env=CXX=clnag++ build:linux --cxxopt=-std=c++17 # See https://bytecodealliance.github.io/wasmtime/c-api/ diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index bc3990f3..dbbdfda1 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -69,7 +69,7 @@ jobs: uses: actions/cache@v1 with: path: "/home/runner/.cache/bazel" - key: bazel-${{ matrix.runtime }}- + key: bazel-${{ matrix.runtime }}-clang - name: Test run: | From 8357beae05abe86007026b7141d6acf88446909e Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Wed, 12 May 2021 15:45:14 +0900 Subject: [PATCH 04/24] Fix test path Signed-off-by: Takeshi Yoneda --- .github/workflows/cpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index dbbdfda1..6ab33c85 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -73,5 +73,5 @@ jobs: - name: Test run: | - bazel test --define runtime=${{ matrix.runtime }} //... + bazel test --define runtime=${{ matrix.runtime }} //test/... From 9d15fb04ab46406cdba488553ed32e289cb94b8b Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Wed, 12 May 2021 16:57:23 +0900 Subject: [PATCH 05/24] Cache on runtime dependency versions. Signed-off-by: Takeshi Yoneda --- .github/workflows/cpp.yml | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index 6ab33c85..8244b792 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -55,21 +55,38 @@ jobs: addlicense -check . build: + name: build (${{ matrix.runtime }}) + runs-on: ubuntu-latest strategy: matrix: - # TODO(mathetake): Add V8. - runtime: [ "wamr", "wasmtime", "wavm" ] + # runtime: Wasm runtime. + # cache_key_regex: used for calculating Bazel cache key. + include: + # TODO(mathetake): Add V8. + - runtime: wamr + cache_key_regex: bytecodealliance/wasm-micro-runtime|llvm-project + - runtime: wasmtime + cache_key_regex: bytecodealliance/wasmtime + - runtime: wasmtime + cache_key_regex: WAVM/WAVM|llvm-project steps: - uses: actions/checkout@v2 + # Calculate the cache key by greping target repositories in repositories.bzl with "matrix.cache_key_regex". + # TODO(mathetake): Use native Bazel solution if possible. + - name: Setup Bazel cache key + run: | + GHA_BAZEL_CACHE_KEY=$(cat bazel/repositories.bzl | grep -E "${{ matrix.cache_key_regex }}" | sha1sum) + echo "GHA_BAZEL_CACHE_KEY=${GHA_BAZEL_CACHE_KEY}" >> $GITHUB_ENV + - name: Mount bazel cache uses: actions/cache@v1 with: path: "/home/runner/.cache/bazel" - key: bazel-${{ matrix.runtime }}-clang + key: ${{ env.GHA_BAZEL_CACHE_KEY }} - name: Test run: | From 8296f8ed42ce61471f20c2e291c1df296a1a52e8 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Wed, 12 May 2021 17:03:14 +0900 Subject: [PATCH 06/24] Fix WAVM build and disable runtime_test temporarily. Signed-off-by: Takeshi Yoneda --- BUILD | 5 +++++ test/BUILD | 30 +++++++++++++++--------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/BUILD b/BUILD index a9f7fd2c..4e5f83d8 100644 --- a/BUILD +++ b/BUILD @@ -81,6 +81,11 @@ cc_library( "src/wavm/*.h", "src/wavm/*.cc", ]), + copts = [ + '-DWAVM_API=""', + "-Wno-non-virtual-dtor", + "-Wno-old-style-cast", + ], deps = [ ":common_lib", "@wavm//:wavm_lib", diff --git a/test/BUILD b/test/BUILD index f1e179f3..af4a4505 100644 --- a/test/BUILD +++ b/test/BUILD @@ -12,21 +12,21 @@ cc_test( ], ) -cc_test( - name = "runtime_test", - srcs = ["runtime_test.cc"], - data = [ - "//test/test_data:abi_export.wasm", - "//test/test_data:callback.wasm", - "//test/test_data:trap.wasm", - ], - deps = [ - ":utility_lib", - "//:lib", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) +# cc_test( +# name = "runtime_test", +# srcs = ["runtime_test.cc"], +# data = [ +# "//test/test_data:abi_export.wasm", +# "//test/test_data:callback.wasm", +# "//test/test_data:trap.wasm", +# ], +# deps = [ +# ":utility_lib", +# "//:lib", +# "@com_google_googletest//:gtest", +# "@com_google_googletest//:gtest_main", +# ], +# ) cc_test( name = "exports_test", From cf4978d08097075a21d7c3e0396ea1df4a09fdc2 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Wed, 12 May 2021 17:05:02 +0900 Subject: [PATCH 07/24] Fix bazelrc. Signed-off-by: Takeshi Yoneda --- .bazelrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.bazelrc b/.bazelrc index 75fdaa2c..488d3dc2 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,6 +1,6 @@ -build --enable_platform_specific_config build --action_env=CC=clang -build --action_env=CXX=clnag++ +build --action_env=CXX=clang++ +build --enable_platform_specific_config build:linux --cxxopt=-std=c++17 # See https://bytecodealliance.github.io/wasmtime/c-api/ From 0e077c44adceb10e8eaf497f637c7972ef7d2534 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Wed, 12 May 2021 17:13:33 +0900 Subject: [PATCH 08/24] Fix runtime name. Signed-off-by: Takeshi Yoneda --- .github/workflows/cpp.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index 8244b792..b98b94c8 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -69,7 +69,7 @@ jobs: cache_key_regex: bytecodealliance/wasm-micro-runtime|llvm-project - runtime: wasmtime cache_key_regex: bytecodealliance/wasmtime - - runtime: wasmtime + - runtime: wavm cache_key_regex: WAVM/WAVM|llvm-project steps: @@ -86,7 +86,7 @@ jobs: uses: actions/cache@v1 with: path: "/home/runner/.cache/bazel" - key: ${{ env.GHA_BAZEL_CACHE_KEY }} + key: bazel-${{ env.GHA_BAZEL_CACHE_KEY }} - name: Test run: | From 5770ad417746e97f3951c38d7750e495feb77f94 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 13 May 2021 00:03:10 +0900 Subject: [PATCH 09/24] review: add Ninja options. Signed-off-by: Takeshi Yoneda --- .bazelrc | 1 + bazel/external/llvm.BUILD | 5 +++++ bazel/external/wamr.BUILD | 5 +++++ bazel/external/wavm.BUILD | 8 ++++++-- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.bazelrc b/.bazelrc index 488d3dc2..e0247e90 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,5 +1,6 @@ build --action_env=CC=clang build --action_env=CXX=clang++ + build --enable_platform_specific_config build:linux --cxxopt=-std=c++17 diff --git a/bazel/external/llvm.BUILD b/bazel/external/llvm.BUILD index acccdbd9..27767704 100644 --- a/bazel/external/llvm.BUILD +++ b/bazel/external/llvm.BUILD @@ -36,6 +36,7 @@ cmake( # using -l:libstdc++.a. "CMAKE_CXX_FLAGS": "-lstdc++", }, + cmake_options = ["-GNinja"], env_vars = { # Workaround for the -DDEBUG flag added in fastbuild on macOS, # which conflicts with DEBUG macro used in LLVM. @@ -44,6 +45,10 @@ cmake( "ASMFLAGS": "-UDEBUG", }, lib_source = ":srcs", + make_commands = [ + "ninja -v", + "ninja -v install", + ], out_static_libs = [ "libLLVMInterpreter.a", "libLLVMWindowsManifest.a", diff --git a/bazel/external/wamr.BUILD b/bazel/external/wamr.BUILD index 2c1b0b99..13c7001a 100644 --- a/bazel/external/wamr.BUILD +++ b/bazel/external/wamr.BUILD @@ -21,8 +21,13 @@ cmake( "WAMR_BUILD_LIBC_WASI": "0", "WAMR_BUILD_TAIL_CALL": "1", }, + cmake_options = ["-GNinja"], defines = ["WASM_WAMR"], lib_source = ":srcs", + make_commands = [ + "ninja -v", + "ninja -v install", + ], out_static_libs = ["libvmlib.a"], deps = [ "@llvm//:llvm_lib", diff --git a/bazel/external/wavm.BUILD b/bazel/external/wavm.BUILD index b9edd18d..aed90439 100644 --- a/bazel/external/wavm.BUILD +++ b/bazel/external/wavm.BUILD @@ -11,7 +11,6 @@ filegroup( cmake( name = "wavm_lib", - binaries = ["wavm"], cache_entries = { "LLVM_DIR": "$EXT_BUILD_DEPS/copy_llvm/llvm/lib/cmake/llvm", "WAVM_ENABLE_STATIC_LINKING": "on", @@ -21,6 +20,7 @@ cmake( # using -l:libstdc++.a. "CMAKE_CXX_FLAGS": "-lstdc++ -Wno-unused-command-line-argument", }, + cmake_options = ["-GNinja"], defines = ["WASM_WAVM"], env_vars = { # Workaround for the -DDEBUG flag added in fastbuild on macOS, @@ -30,7 +30,11 @@ cmake( "ASMFLAGS": "-UDEBUG", }, lib_source = ":srcs", - static_libraries = [ + make_commands = [ + "ninja -v", + "ninja -v install", + ], + out_static_libs = [ "libWAVM.a", "libWAVMUnwind.a", ], From c67261f9e91f8c89b46b884fd6e975486a32d895 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 13 May 2021 09:41:11 +0900 Subject: [PATCH 10/24] review: remove deprecated options, LLVM patch. Signed-off-by: Takeshi Yoneda --- bazel/external/llvm.BUILD | 7 ++----- bazel/external/llvm.patch | 25 ------------------------- bazel/external/wamr.BUILD | 5 ----- bazel/external/wavm.BUILD | 7 ++----- bazel/repositories.bzl | 2 -- 5 files changed, 4 insertions(+), 42 deletions(-) delete mode 100644 bazel/external/llvm.patch diff --git a/bazel/external/llvm.BUILD b/bazel/external/llvm.BUILD index 27767704..aab537b9 100644 --- a/bazel/external/llvm.BUILD +++ b/bazel/external/llvm.BUILD @@ -11,6 +11,7 @@ filegroup( cmake( name = "llvm_lib", + build_args = ["-v"], cache_entries = { # Disable both: BUILD and INCLUDE, since some of the INCLUDE # targets build code instead of only generating build files. @@ -36,7 +37,6 @@ cmake( # using -l:libstdc++.a. "CMAKE_CXX_FLAGS": "-lstdc++", }, - cmake_options = ["-GNinja"], env_vars = { # Workaround for the -DDEBUG flag added in fastbuild on macOS, # which conflicts with DEBUG macro used in LLVM. @@ -44,11 +44,8 @@ cmake( "CXXFLAGS": "-UDEBUG", "ASMFLAGS": "-UDEBUG", }, + generate_args = ["-GNinja"], lib_source = ":srcs", - make_commands = [ - "ninja -v", - "ninja -v install", - ], out_static_libs = [ "libLLVMInterpreter.a", "libLLVMWindowsManifest.a", diff --git a/bazel/external/llvm.patch b/bazel/external/llvm.patch deleted file mode 100644 index cd02f284..00000000 --- a/bazel/external/llvm.patch +++ /dev/null @@ -1,25 +0,0 @@ -# Workaround for Envoy's CMAKE_BUILD_TYPE=Bazel. ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -247,7 +247,7 @@ - string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) - - if (CMAKE_BUILD_TYPE AND -- NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL)$") -+ NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL|BAZEL)$") - message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") - endif() - -# Workaround for a missing -fuse-ld flag in CXXFLAGS, which results in -# different linkers being used during configure and compilation phases. ---- a/cmake/modules/HandleLLVMOptions.cmake -+++ b/cmake/modules/HandleLLVMOptions.cmake -@@ -718,8 +718,6 @@ endif() - if (UNIX AND CMAKE_GENERATOR STREQUAL "Ninja") - include(CheckLinkerFlag) - check_linker_flag("-Wl,--color-diagnostics" LINKER_SUPPORTS_COLOR_DIAGNOSTICS) -- append_if(LINKER_SUPPORTS_COLOR_DIAGNOSTICS "-Wl,--color-diagnostics" -- CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) - endif() - - # Add flags for add_dead_strip(). diff --git a/bazel/external/wamr.BUILD b/bazel/external/wamr.BUILD index 13c7001a..2c1b0b99 100644 --- a/bazel/external/wamr.BUILD +++ b/bazel/external/wamr.BUILD @@ -21,13 +21,8 @@ cmake( "WAMR_BUILD_LIBC_WASI": "0", "WAMR_BUILD_TAIL_CALL": "1", }, - cmake_options = ["-GNinja"], defines = ["WASM_WAMR"], lib_source = ":srcs", - make_commands = [ - "ninja -v", - "ninja -v install", - ], out_static_libs = ["libvmlib.a"], deps = [ "@llvm//:llvm_lib", diff --git a/bazel/external/wavm.BUILD b/bazel/external/wavm.BUILD index aed90439..673673ef 100644 --- a/bazel/external/wavm.BUILD +++ b/bazel/external/wavm.BUILD @@ -11,6 +11,7 @@ filegroup( cmake( name = "wavm_lib", + build_args = ["-v"], cache_entries = { "LLVM_DIR": "$EXT_BUILD_DEPS/copy_llvm/llvm/lib/cmake/llvm", "WAVM_ENABLE_STATIC_LINKING": "on", @@ -20,7 +21,6 @@ cmake( # using -l:libstdc++.a. "CMAKE_CXX_FLAGS": "-lstdc++ -Wno-unused-command-line-argument", }, - cmake_options = ["-GNinja"], defines = ["WASM_WAVM"], env_vars = { # Workaround for the -DDEBUG flag added in fastbuild on macOS, @@ -29,11 +29,8 @@ cmake( "CXXFLAGS": "-UDEBUG", "ASMFLAGS": "-UDEBUG", }, + generate_args = ["-GNinja"], lib_source = ":srcs", - make_commands = [ - "ninja -v", - "ninja -v install", - ], out_static_libs = [ "libWAVM.a", "libWAVMUnwind.a", diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 4694b7a1..eb3ee229 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -87,8 +87,6 @@ def proxy_wasm_cpp_host_repositories(): sha256 = "df83a44b3a9a71029049ec101fb0077ecbbdf5fe41e395215025779099a98fdf", strip_prefix = "llvm-10.0.0.src", url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/llvm-10.0.0.src.tar.xz", - patch_args = ["-p1"], - patches = ["@proxy_wasm_cpp_host//bazel/external:llvm.patch"], ) http_archive( From 117534a17e2154d4a40bc1a1db688b3f83ed2688 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 13 May 2021 09:52:07 +0900 Subject: [PATCH 11/24] Use cache@v2 for better compression Signed-off-by: Takeshi Yoneda --- .github/workflows/cpp.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index b98b94c8..fde6b109 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -79,11 +79,11 @@ jobs: # TODO(mathetake): Use native Bazel solution if possible. - name: Setup Bazel cache key run: | - GHA_BAZEL_CACHE_KEY=$(cat bazel/repositories.bzl | grep -E "${{ matrix.cache_key_regex }}" | sha1sum) + GHA_BAZEL_CACHE_KEY=$(grep -E "${{ matrix.cache_key_regex }}" bazel/repositories.bzl | sha1sum | head -c 40) echo "GHA_BAZEL_CACHE_KEY=${GHA_BAZEL_CACHE_KEY}" >> $GITHUB_ENV - name: Mount bazel cache - uses: actions/cache@v1 + uses: actions/cache@v2 with: path: "/home/runner/.cache/bazel" key: bazel-${{ env.GHA_BAZEL_CACHE_KEY }} From db4b0cebc33c3b2bd50a583de6a7b42fd82fe75e Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 13 May 2021 12:16:22 +0900 Subject: [PATCH 12/24] Fix runtime tests. Signed-off-by: Takeshi Yoneda --- .github/workflows/cpp.yml | 4 +++- src/wavm/wavm.cc | 2 +- test/BUILD | 30 +++++++++++++++--------------- test/runtime_test.cc | 26 +++++++++++++++++++++----- 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index fde6b109..c23609d5 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -75,6 +75,9 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Install dependency + run: sudo apt-get install ninja-build + # Calculate the cache key by greping target repositories in repositories.bzl with "matrix.cache_key_regex". # TODO(mathetake): Use native Bazel solution if possible. - name: Setup Bazel cache key @@ -91,4 +94,3 @@ jobs: - name: Test run: | bazel test --define runtime=${{ matrix.runtime }} //test/... - diff --git a/src/wavm/wavm.cc b/src/wavm/wavm.cc index 2c3a3adb..92b31468 100644 --- a/src/wavm/wavm.cc +++ b/src/wavm/wavm.cc @@ -101,7 +101,7 @@ namespace { } while (0) std::string getFailMessage(std::string_view function_name, WAVM::Runtime::Exception *exception) { - std::string message = "Function " + std::string(function_name) + + std::string message = "Function: " + std::string(function_name) + " failed: " + WAVM::Runtime::describeExceptionType(exception->type) + "\nProxy-Wasm plugin in-VM backtrace:\n"; std::vector callstack_descriptions = diff --git a/test/BUILD b/test/BUILD index ec0b4615..ec45c17b 100644 --- a/test/BUILD +++ b/test/BUILD @@ -26,21 +26,21 @@ cc_test( ], ) -# cc_test( -# name = "runtime_test", -# srcs = ["runtime_test.cc"], -# data = [ -# "//test/test_data:abi_export.wasm", -# "//test/test_data:callback.wasm", -# "//test/test_data:trap.wasm", -# ], -# deps = [ -# ":utility_lib", -# "//:lib", -# "@com_google_googletest//:gtest", -# "@com_google_googletest//:gtest_main", -# ], -# ) +cc_test( + name = "runtime_test", + srcs = ["runtime_test.cc"], + data = [ + "//test/test_data:abi_export.wasm", + "//test/test_data:callback.wasm", + "//test/test_data:trap.wasm", + ], + deps = [ + ":utility_lib", + "//:lib", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", + ], +) cc_test( name = "exports_test", diff --git a/test/runtime_test.cc b/test/runtime_test.cc index 3ee96ab4..44c1d6d7 100644 --- a/test/runtime_test.cc +++ b/test/runtime_test.cc @@ -34,7 +34,13 @@ auto test_values = testing::ValuesIn(getRuntimes()); INSTANTIATE_TEST_SUITE_P(Runtimes, TestVM, test_values); TEST_P(TestVM, Basic) { - EXPECT_EQ(vm_->cloneable(), proxy_wasm::Cloneable::CompiledBytecode); + if (runtime_ == "wavm") { + EXPECT_EQ(vm_->cloneable(), proxy_wasm::Cloneable::InstantiatedModule); + } else if (runtime_ == "wamr") { + EXPECT_EQ(vm_->cloneable(), proxy_wasm::Cloneable::NotCloneable); + } else { + EXPECT_EQ(vm_->cloneable(), proxy_wasm::Cloneable::CompiledBytecode); + } EXPECT_EQ(vm_->runtime(), runtime_); } @@ -57,6 +63,9 @@ TEST_P(TestVM, Memory) { } TEST_P(TestVM, Clone) { + if (vm_->cloneable() == proxy_wasm::Cloneable::NotCloneable) { + return; + } initialize("abi_export.wasm"); ASSERT_TRUE(vm_->load(source_, {}, {})); ASSERT_TRUE(vm_->link("")); @@ -66,7 +75,9 @@ TEST_P(TestVM, Clone) { auto clone = vm_->clone(); ASSERT_TRUE(clone != nullptr); ASSERT_NE(vm_, clone); - ASSERT_TRUE(clone->link("")); + if (vm_->cloneable() != proxy_wasm::Cloneable::InstantiatedModule) { + ASSERT_TRUE(clone->link("")); + } ASSERT_TRUE(clone->setWord(address, Word(100))); ASSERT_TRUE(clone->getWord(address, &word)); @@ -87,14 +98,19 @@ class TestContext : public ContextBase { void nopCallback(void *raw_context) {} -void callback(void *raw_context) { - TestContext *context = static_cast(raw_context); +void callback(void *) { + TestContext *context = static_cast(current_context_); context->increment(); } -Word callback2(void *raw_context, Word val) { return val + 100; } +Word callback2(void *, Word val) { return val + 100; } TEST_P(TestVM, StraceLogLevel) { + if (runtime_ == "wavm") { + // TODO(mathetake): strace is yet to be implemented for WAVM. + // See https://github.com/proxy-wasm/proxy-wasm-cpp-host/issues/120. + return; + } initialize("callback.wasm"); ASSERT_TRUE(vm_->load(source_, {}, {})); vm_->registerCallback("env", "callback", &nopCallback, From 180cfd0d6adaf523d04a9dbfc7396e9a4687f742 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 13 May 2021 16:24:38 +0900 Subject: [PATCH 13/24] Fix WAVM build with unresolved TODO. Signed-off-by: Takeshi Yoneda --- test/runtime_test.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/test/runtime_test.cc b/test/runtime_test.cc index 44c1d6d7..29d9fffe 100644 --- a/test/runtime_test.cc +++ b/test/runtime_test.cc @@ -175,12 +175,17 @@ TEST_P(TestVM, Trap) { std::string exp_message = "Function: trigger failed"; ASSERT_TRUE(integration_->error_message_.find(exp_message) != std::string::npos); - WasmCallWord<1> trigger2; - vm_->getFunction("trigger2", &trigger2); - EXPECT_TRUE(trigger2 != nullptr); - trigger2(current_context_, 0); - exp_message = "Function: trigger2 failed:"; - ASSERT_TRUE(integration_->error_message_.find(exp_message) != std::string::npos); + if (runtime_ != "wavm") { + // TODO(mathetake): Somehow WAVM exits with 'munmap_chunk(): invalid pointer' on unidentified + // build condition in 'libstdc++ abi::__cxa_demangle' originally from + // WAVM::Runtime::describeCallStack. Needs further investigation. + WasmCallWord<1> trigger2; + vm_->getFunction("trigger2", &trigger2); + EXPECT_TRUE(trigger2 != nullptr); + trigger2(current_context_, 0); + exp_message = "Function: trigger2 failed:"; + ASSERT_TRUE(integration_->error_message_.find(exp_message) != std::string::npos); + } } } // namespace From 72a81539866fe472564f7103afbe24b9b9d87a89 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 13 May 2021 21:09:50 +0900 Subject: [PATCH 14/24] review: use simple cache key. Signed-off-by: Takeshi Yoneda --- .github/workflows/cpp.yml | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index c23609d5..3af63789 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -61,16 +61,7 @@ jobs: strategy: matrix: - # runtime: Wasm runtime. - # cache_key_regex: used for calculating Bazel cache key. - include: - # TODO(mathetake): Add V8. - - runtime: wamr - cache_key_regex: bytecodealliance/wasm-micro-runtime|llvm-project - - runtime: wasmtime - cache_key_regex: bytecodealliance/wasmtime - - runtime: wavm - cache_key_regex: WAVM/WAVM|llvm-project + runtime: ["wamr", "wasmtime", "wavm"] steps: - uses: actions/checkout@v2 @@ -78,18 +69,11 @@ jobs: - name: Install dependency run: sudo apt-get install ninja-build - # Calculate the cache key by greping target repositories in repositories.bzl with "matrix.cache_key_regex". - # TODO(mathetake): Use native Bazel solution if possible. - - name: Setup Bazel cache key - run: | - GHA_BAZEL_CACHE_KEY=$(grep -E "${{ matrix.cache_key_regex }}" bazel/repositories.bzl | sha1sum | head -c 40) - echo "GHA_BAZEL_CACHE_KEY=${GHA_BAZEL_CACHE_KEY}" >> $GITHUB_ENV - - name: Mount bazel cache uses: actions/cache@v2 with: path: "/home/runner/.cache/bazel" - key: bazel-${{ env.GHA_BAZEL_CACHE_KEY }} + key: bazel-${{ hashFiles('WORKSPACE', '.bazelrc', '.bazelversion', 'bazel/cargo/Cargo.raze.lock', 'bazel/dependencies.bzl', 'bazel/repositories.bzl') }}-${{ matrix.runtime }} - name: Test run: | From f3d94963fe5e51adf3e7cff562970f221f7bef35 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 13 May 2021 21:15:12 +0900 Subject: [PATCH 15/24] Update WAMR and use Ninja. Signed-off-by: Takeshi Yoneda --- bazel/external/wamr.BUILD | 2 ++ bazel/repositories.bzl | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/bazel/external/wamr.BUILD b/bazel/external/wamr.BUILD index 2c1b0b99..d4077ee1 100644 --- a/bazel/external/wamr.BUILD +++ b/bazel/external/wamr.BUILD @@ -11,6 +11,7 @@ filegroup( cmake( name = "wamr_lib", + build_args = ["-v"], cache_entries = { "LLVM_DIR": "$EXT_BUILD_DEPS/copy_llvm/llvm/lib/cmake/llvm", "WAMR_BUILD_INTERP": "1", @@ -22,6 +23,7 @@ cmake( "WAMR_BUILD_TAIL_CALL": "1", }, defines = ["WASM_WAMR"], + generate_args = ["-GNinja"], lib_source = ":srcs", out_static_libs = ["libvmlib.a"], deps = [ diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index eb3ee229..ddaf3aba 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -39,9 +39,9 @@ def proxy_wasm_cpp_host_repositories(): http_archive( name = "wamr", build_file = "@proxy_wasm_cpp_host//bazel/external:wamr.BUILD", - sha256 = "1d870f396bb6bdcb5c816326655b19a2877bbdf879255c335b8e84ce4ee37780", - strip_prefix = "wasm-micro-runtime-9710d9325f426121cc1f2c62386a71d0c022d613", - url = "https://github.com/bytecodealliance/wasm-micro-runtime/archive/9710d9325f426121cc1f2c62386a71d0c022d613.tar.gz", + sha256 = "46ad365a1c0668797e69cb868574fd526cd8e26a503213caf782c39061e6d2e1", + strip_prefix = "wasm-micro-runtime-17a216748574499bd3a5130e7e6a20b84fe76798", + url = "https://github.com/bytecodealliance/wasm-micro-runtime/archive/17a216748574499bd3a5130e7e6a20b84fe76798.tar.gz", ) http_archive( From 90dc748c0f10d76b7a8b279f71f82782bc6d1e3f Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 13 May 2021 21:16:32 +0900 Subject: [PATCH 16/24] review: Delete trap2 test. Signed-off-by: Takeshi Yoneda --- test/runtime_test.cc | 12 ------------ test/test_data/trap.rs | 5 ----- 2 files changed, 17 deletions(-) diff --git a/test/runtime_test.cc b/test/runtime_test.cc index 29d9fffe..3d27be63 100644 --- a/test/runtime_test.cc +++ b/test/runtime_test.cc @@ -174,18 +174,6 @@ TEST_P(TestVM, Trap) { trigger(current_context_); std::string exp_message = "Function: trigger failed"; ASSERT_TRUE(integration_->error_message_.find(exp_message) != std::string::npos); - - if (runtime_ != "wavm") { - // TODO(mathetake): Somehow WAVM exits with 'munmap_chunk(): invalid pointer' on unidentified - // build condition in 'libstdc++ abi::__cxa_demangle' originally from - // WAVM::Runtime::describeCallStack. Needs further investigation. - WasmCallWord<1> trigger2; - vm_->getFunction("trigger2", &trigger2); - EXPECT_TRUE(trigger2 != nullptr); - trigger2(current_context_, 0); - exp_message = "Function: trigger2 failed:"; - ASSERT_TRUE(integration_->error_message_.find(exp_message) != std::string::npos); - } } } // namespace diff --git a/test/test_data/trap.rs b/test/test_data/trap.rs index 2be4cab2..ed9232b6 100644 --- a/test/test_data/trap.rs +++ b/test/test_data/trap.rs @@ -16,11 +16,6 @@ pub extern "C" fn trigger() { one(); } -#[no_mangle] -pub extern "C" fn trigger2(_val: i32) -> i32 { - three(); - 0 -} fn one() { two(); From 0bb696f4fc24f39f5d6373777e5f9b16d81d3476 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 13 May 2021 21:30:52 +0900 Subject: [PATCH 17/24] Add missing header in NullVm. Signed-off-by: Takeshi Yoneda --- src/null/null_vm.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/null/null_vm.cc b/src/null/null_vm.cc index de2511a0..aab2e323 100644 --- a/src/null/null_vm.cc +++ b/src/null/null_vm.cc @@ -17,6 +17,7 @@ #include +#include #include #include #include From cb274d3bb4fb2be6cf55e650e01b67361dc1bb18 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Fri, 14 May 2021 08:40:35 +0900 Subject: [PATCH 18/24] review: restore seprate trap2 test with TODO for WAVM and fix nits. Signed-off-by: Takeshi Yoneda --- .github/workflows/cpp.yml | 1 + test/runtime_test.cc | 28 ++++++++++++++++++++++++++-- test/test_data/trap.rs | 6 ++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index 3af63789..f2d9f4b4 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -60,6 +60,7 @@ jobs: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: runtime: ["wamr", "wasmtime", "wavm"] diff --git a/test/runtime_test.cc b/test/runtime_test.cc index 3d27be63..2bbd6558 100644 --- a/test/runtime_test.cc +++ b/test/runtime_test.cc @@ -38,8 +38,10 @@ TEST_P(TestVM, Basic) { EXPECT_EQ(vm_->cloneable(), proxy_wasm::Cloneable::InstantiatedModule); } else if (runtime_ == "wamr") { EXPECT_EQ(vm_->cloneable(), proxy_wasm::Cloneable::NotCloneable); - } else { + } else if (runtime_ == "v8" || runtime_ == "wasmtime") { EXPECT_EQ(vm_->cloneable(), proxy_wasm::Cloneable::CompiledBytecode); + } else { + FAIL(); } EXPECT_EQ(vm_->runtime(), runtime_); } @@ -75,7 +77,7 @@ TEST_P(TestVM, Clone) { auto clone = vm_->clone(); ASSERT_TRUE(clone != nullptr); ASSERT_NE(vm_, clone); - if (vm_->cloneable() != proxy_wasm::Cloneable::InstantiatedModule) { + if (clone->cloneable() != proxy_wasm::Cloneable::InstantiatedModule) { ASSERT_TRUE(clone->link("")); } @@ -168,6 +170,8 @@ TEST_P(TestVM, Trap) { initialize("trap.wasm"); ASSERT_TRUE(vm_->load(source_, {}, {})); ASSERT_TRUE(vm_->link("")); + TestContext context; + current_context_ = &context; WasmCallVoid<0> trigger; vm_->getFunction("trigger", &trigger); EXPECT_TRUE(trigger != nullptr); @@ -176,5 +180,25 @@ TEST_P(TestVM, Trap) { ASSERT_TRUE(integration_->error_message_.find(exp_message) != std::string::npos); } +TEST_P(TestVM, Trap2) { + if (runtime_ == "wavm") { + // TODO(mathetake): Somehow WAVM exits with 'munmap_chunk(): invalid pointer' on unidentified + // build condition in 'libstdc++ abi::__cxa_demangle' originally from + // WAVM::Runtime::describeCallStack. Needs further investigation. + return; + } + initialize("trap.wasm"); + ASSERT_TRUE(vm_->load(source_, {}, {})); + TestContext context; + current_context_ = &context; + ASSERT_TRUE(vm_->link("")); + WasmCallWord<1> trigger2; + vm_->getFunction("trigger2", &trigger2); + EXPECT_TRUE(trigger2 != nullptr); + trigger2(current_context_, 0); + std::string exp_message = "Function: trigger2 failed"; + ASSERT_TRUE(integration_->error_message_.find(exp_message) != std::string::npos); +} + } // namespace } // namespace proxy_wasm diff --git a/test/test_data/trap.rs b/test/test_data/trap.rs index ed9232b6..fe6f71f6 100644 --- a/test/test_data/trap.rs +++ b/test/test_data/trap.rs @@ -17,6 +17,12 @@ pub extern "C" fn trigger() { one(); } +#[no_mangle] +pub extern "C" fn trigger2(_val: i32) -> i32 { + three(); + 0 +} + fn one() { two(); } From 6fed6fe166e63480213ff6931cf137f9a546775b Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Fri, 14 May 2021 17:24:50 +0900 Subject: [PATCH 19/24] review: fix style. Signed-off-by: Takeshi Yoneda --- .github/workflows/cpp.yml | 6 ++++-- test/runtime_test.cc | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index f2d9f4b4..a9c6729c 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -70,10 +70,12 @@ jobs: - name: Install dependency run: sudo apt-get install ninja-build - - name: Mount bazel cache + - name: Mount Bazel cache uses: actions/cache@v2 with: - path: "/home/runner/.cache/bazel" + path: | + ~/.cache/bazel + ~/.cache/bazelisk key: bazel-${{ hashFiles('WORKSPACE', '.bazelrc', '.bazelversion', 'bazel/cargo/Cargo.raze.lock', 'bazel/dependencies.bzl', 'bazel/repositories.bzl') }}-${{ matrix.runtime }} - name: Test diff --git a/test/runtime_test.cc b/test/runtime_test.cc index 2bbd6558..11774f67 100644 --- a/test/runtime_test.cc +++ b/test/runtime_test.cc @@ -34,12 +34,12 @@ auto test_values = testing::ValuesIn(getRuntimes()); INSTANTIATE_TEST_SUITE_P(Runtimes, TestVM, test_values); TEST_P(TestVM, Basic) { - if (runtime_ == "wavm") { - EXPECT_EQ(vm_->cloneable(), proxy_wasm::Cloneable::InstantiatedModule); - } else if (runtime_ == "wamr") { + if (runtime_ == "wamr") { EXPECT_EQ(vm_->cloneable(), proxy_wasm::Cloneable::NotCloneable); - } else if (runtime_ == "v8" || runtime_ == "wasmtime") { + } else if (runtime_ == "wasmtime" || runtime_ == "v8") { EXPECT_EQ(vm_->cloneable(), proxy_wasm::Cloneable::CompiledBytecode); + } else if (runtime_ == "wavm") { + EXPECT_EQ(vm_->cloneable(), proxy_wasm::Cloneable::InstantiatedModule); } else { FAIL(); } @@ -189,9 +189,9 @@ TEST_P(TestVM, Trap2) { } initialize("trap.wasm"); ASSERT_TRUE(vm_->load(source_, {}, {})); + ASSERT_TRUE(vm_->link("")); TestContext context; current_context_ = &context; - ASSERT_TRUE(vm_->link("")); WasmCallWord<1> trigger2; vm_->getFunction("trigger2", &trigger2); EXPECT_TRUE(trigger2 != nullptr); From 502c42e1d1801e45f6c653074f38b3ea9063e21d Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Fri, 14 May 2021 17:25:42 +0900 Subject: [PATCH 20/24] try removing -v. Signed-off-by: Takeshi Yoneda --- bazel/external/llvm.BUILD | 1 - bazel/external/wamr.BUILD | 1 - bazel/external/wavm.BUILD | 1 - 3 files changed, 3 deletions(-) diff --git a/bazel/external/llvm.BUILD b/bazel/external/llvm.BUILD index aab537b9..efab7d45 100644 --- a/bazel/external/llvm.BUILD +++ b/bazel/external/llvm.BUILD @@ -11,7 +11,6 @@ filegroup( cmake( name = "llvm_lib", - build_args = ["-v"], cache_entries = { # Disable both: BUILD and INCLUDE, since some of the INCLUDE # targets build code instead of only generating build files. diff --git a/bazel/external/wamr.BUILD b/bazel/external/wamr.BUILD index d4077ee1..2d0af954 100644 --- a/bazel/external/wamr.BUILD +++ b/bazel/external/wamr.BUILD @@ -11,7 +11,6 @@ filegroup( cmake( name = "wamr_lib", - build_args = ["-v"], cache_entries = { "LLVM_DIR": "$EXT_BUILD_DEPS/copy_llvm/llvm/lib/cmake/llvm", "WAMR_BUILD_INTERP": "1", diff --git a/bazel/external/wavm.BUILD b/bazel/external/wavm.BUILD index 673673ef..55e4a81b 100644 --- a/bazel/external/wavm.BUILD +++ b/bazel/external/wavm.BUILD @@ -11,7 +11,6 @@ filegroup( cmake( name = "wavm_lib", - build_args = ["-v"], cache_entries = { "LLVM_DIR": "$EXT_BUILD_DEPS/copy_llvm/llvm/lib/cmake/llvm", "WAVM_ENABLE_STATIC_LINKING": "on", From 7492878a8a84c8bd61c42e54280f5834d218935e Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Sat, 15 May 2021 09:31:01 +0900 Subject: [PATCH 21/24] review: disable LLVM benchmark build. Signed-off-by: Takeshi Yoneda --- bazel/external/llvm.BUILD | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bazel/external/llvm.BUILD b/bazel/external/llvm.BUILD index efab7d45..2842cee4 100644 --- a/bazel/external/llvm.BUILD +++ b/bazel/external/llvm.BUILD @@ -14,6 +14,8 @@ cmake( cache_entries = { # Disable both: BUILD and INCLUDE, since some of the INCLUDE # targets build code instead of only generating build files. + "LLVM_BUILD_BENCHMARKS": "off", + "LLVM_INCLUDE_BENCHMARKS": "off", "LLVM_BUILD_DOCS": "off", "LLVM_INCLUDE_DOCS": "off", "LLVM_BUILD_EXAMPLES": "off", From 7822e89bb9d7bef7f86fde9c73d355dedcbe8cce Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Sat, 15 May 2021 04:31:52 +0000 Subject: [PATCH 22/24] Fix merge (missing new line at the end). Signed-off-by: Piotr Sikora --- .github/workflows/cpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index 9106c3cf..c47cb309 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -84,4 +84,4 @@ jobs: - name: Test (signed Wasm module) run: | - bazel test --define runtime=${{ matrix.runtime }} --cxxopt=-DPROXY_WASM_VERIFY_WITH_ED25519_PUBKEY=\"$(xxd -p -c 256 test/test_data/signature_key1.pub | cut -b9-)\" //test:signature_util_test \ No newline at end of file + bazel test --define runtime=${{ matrix.runtime }} --cxxopt=-DPROXY_WASM_VERIFY_WITH_ED25519_PUBKEY=\"$(xxd -p -c 256 test/test_data/signature_key1.pub | cut -b9-)\" //test:signature_util_test From d6ba6abc4ac0329893639c996b2ddb2e9f288afd Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Sat, 15 May 2021 02:15:44 -0700 Subject: [PATCH 23/24] review: use --per_file_copt. Signed-off-by: Piotr Sikora --- .github/workflows/cpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index c47cb309..837bea1c 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -84,4 +84,4 @@ jobs: - name: Test (signed Wasm module) run: | - bazel test --define runtime=${{ matrix.runtime }} --cxxopt=-DPROXY_WASM_VERIFY_WITH_ED25519_PUBKEY=\"$(xxd -p -c 256 test/test_data/signature_key1.pub | cut -b9-)\" //test:signature_util_test + bazel test --define runtime=${{ matrix.runtime }} --per_file_copt=//...@-DPROXY_WASM_VERIFY_WITH_ED25519_PUBKEY=\"$(xxd -p -c 256 test/test_data/signature_key1.pub | cut -b9-)\" //test:signature_util_test From 6cf8d7b53c4776771f1dd62ced8efa3681f442fd Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Sat, 15 May 2021 02:27:39 -0700 Subject: [PATCH 24/24] review: wipe cache. Signed-off-by: Piotr Sikora --- .github/workflows/cpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index 837bea1c..9e58e997 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -76,7 +76,7 @@ jobs: path: | ~/.cache/bazel ~/.cache/bazelisk - key: bazel-${{ hashFiles('WORKSPACE', '.bazelrc', '.bazelversion', 'bazel/cargo/Cargo.raze.lock', 'bazel/dependencies.bzl', 'bazel/repositories.bzl') }}-${{ matrix.runtime }} + key: bazel-${{ matrix.runtime }}-${{ hashFiles('WORKSPACE', '.bazelrc', '.bazelversion', 'bazel/cargo/Cargo.raze.lock', 'bazel/dependencies.bzl', 'bazel/repositories.bzl') }} - name: Test run: |