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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def _build_recipe_repository_impl(ctxt):
print("Fetching external dependencies...")
result = ctxt.execute(
["./repositories.sh"] + recipes,
timeout = 3600,
quiet = False,
)
print(result.stdout)
Expand Down
1 change: 1 addition & 0 deletions bazel/target_recipes.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ TARGET_RECIPES = {
"tcmalloc_and_profiler": "gperftools",
"tcmalloc_debug": "gperftools",
"luajit": "luajit",
"v8": "v8",
"wavm_with_llvm": "wavm",
}
116 changes: 116 additions & 0 deletions ci/build_container/build_recipes/v8.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/bin/bash

set -e

# Get wasm-c-api.

COMMIT=111a3e4a0962fae4da2428b8680f7dfbc8deef47 # Mon May 13 11:10:04 2019 +0200
SHA256=4eb700586902d0f6ebdcbc0147f5674df95743cc831495191b7df4cb32fb3ef0

curl https://github.com/WebAssembly/wasm-c-api/archive/"$COMMIT".tar.gz -sLo wasm-c-api-"$COMMIT".tar.gz \
&& echo "$SHA256" wasm-c-api-"$COMMIT".tar.gz | sha256sum --check
tar xf wasm-c-api-"$COMMIT".tar.gz
cd wasm-c-api-"$COMMIT"

# Build v8 inside v8 subdirectory to match wasm-c-api's Makefile.

mkdir v8
cd v8

# Get depot_tools.

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH="$PATH:$PWD/depot_tools"

# Get v8.

VERSION=7.4.288.28 # match wasm-c-api (branch-heads/7.4)

fetch v8
cd v8
git checkout "$VERSION"
gclient sync

# Patch v8 for wasm-c-api.

patch -p1 < ../../patch/0001-BUILD.gn-add-wasm-v8-lowlevel.patch
cp -p ../../src/wasm-v8-lowlevel.cc src/wasm-v8-lowlevel.cc
cp -p ../../src/wasm-v8-lowlevel.hh include/wasm-v8-lowlevel.hh

# Build v8 static library.

tools/dev/v8gen.py x64.release -- v8_monolithic=true v8_use_external_startup_data=false v8_enable_i18n_support=false v8_enable_gdbjit=false use_custom_libcxx=false
ninja -v -C out.gn/x64.release v8_monolith

# Install v8.

mkdir -p "$THIRDPARTY_BUILD/include/v8/libplatform"
cp -p include/v8*.h "$THIRDPARTY_BUILD/include/v8/"
cp -p include/libplatform/*.h "$THIRDPARTY_BUILD/include/v8/libplatform/"
cp -p out.gn/x64.release/obj/libv8_monolith.a "$THIRDPARTY_BUILD/lib/"

cd ../..

# Patch wasm-c-api.

# 1. Disable DEBUG (alloc/free accounting), since it seems to be broken
# in optimized builds and/or when using sanitizers.
# 2. Disable hardcoded sanitizers.

cat <<\EOF | patch -p1
--- a/Makefile
+++ b/Makefile
@@ -7,10 +7,10 @@ V8_VERSION = branch-heads/7.4
V8_ARCH = x64
V8_MODE = release

-WASM_FLAGS = -DDEBUG # -DDEBUG_LOG
-C_FLAGS = ${WASM_FLAGS} -Wall -Werror -ggdb -O -fsanitize=address
+WASM_FLAGS =
+C_FLAGS = ${WASM_FLAGS} -Wall -Werror -ggdb -O
CC_FLAGS = ${C_FLAGS}
-LD_FLAGS = -fsanitize-memory-track-origins -fsanitize-memory-use-after-dtor
+LD_FLAGS =

C_COMP = clang
EOF

# 3. Enable "wasm_bulk_memory" required to load WASM modules with DataCount
# section, even when DataCount = 1.
# 4. Force full GC when destroying VMs.

cat <<\EOF | patch -p1
--- a/src/wasm-v8.cc
+++ b/src/wasm-v8.cc
@@ -296,7 +296,7 @@ auto Engine::make(own<Config*>&& config) -> own<Engine*> {
v8::internal::FLAG_experimental_wasm_bigint = true;
v8::internal::FLAG_experimental_wasm_mv = true;
// v8::internal::FLAG_experimental_wasm_anyref = true;
- // v8::internal::FLAG_experimental_wasm_bulk_memory = true;
+ v8::internal::FLAG_experimental_wasm_bulk_memory = true;
// v8::V8::SetFlagsFromCommandLine(&argc, const_cast<char**>(argv), false);
auto engine = new(std::nothrow) EngineImpl;
if (!engine) return own<Engine*>();
@@ -349,7 +349,7 @@ public:
}

~StoreImpl() {
-#ifdef DEBUG
+#if 1 //def DEBUG
isolate_->RequestGarbageCollectionForTesting(
v8::Isolate::kFullGarbageCollection);
#endif
EOF

# Build wasm-c-api.

# TODO(PiotrSikora): respect CC/CXX/CFLAGS/CXXFLAGS/LDFLAGS upstream.

make wasm

# Install wasm-c-api.

mkdir -p "$THIRDPARTY_BUILD/include/wasm-c-api"
cp -p include/wasm.hh "$THIRDPARTY_BUILD/include/wasm-c-api/"
cp -p src/wasm-bin.hh "$THIRDPARTY_BUILD/include/wasm-c-api/"
ar -r -c -s "$THIRDPARTY_BUILD/lib/libwasm.a" out/wasm-bin.o out/wasm-v8.o
17 changes: 17 additions & 0 deletions ci/prebuilt/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ cc_library(
strip_include_prefix = "thirdparty_build/include",
)

cc_library(
name = "v8",
srcs = select({
"@envoy//bazel:windows_x86_64": ["WINDOWS_IS_NOT_SUPPORTED_YET"],
"//conditions:default": [
# Order matters!
"thirdparty_build/lib/libwasm.a",
"thirdparty_build/lib/libv8_monolith.a",
],
}),
hdrs = [
"thirdparty_build/include/wasm-c-api/wasm.hh",
"thirdparty_build/include/wasm-c-api/wasm-bin.hh",
],
includes = ["thirdparty_build/include"],
)

cc_library(
name = "wavm_with_llvm",
srcs = select({
Expand Down
1 change: 1 addition & 0 deletions source/extensions/common/wasm/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ envoy_cc_library(
"//source/common/http:message_lib",
"//source/common/http:utility_lib",
"//source/common/tracing:http_tracer_lib",
"//source/extensions/common/wasm/v8:v8_lib",
"//source/extensions/common/wasm/wavm:wavm_lib",
],
)
28 changes: 28 additions & 0 deletions source/extensions/common/wasm/v8/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
licenses(["notice"]) # Apache 2

load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_library",
"envoy_package",
)

envoy_package()

envoy_cc_library(
name = "v8_lib",
srcs = ["v8.cc"],
hdrs = ["v8.h"],
external_deps = [
"v8",
],
deps = [
"//include/envoy/server:wasm_interface",
"//include/envoy/thread_local:thread_local_interface",
"//source/common/common:assert_lib",
"//source/common/common:c_smart_ptr_lib",
"//source/common/protobuf",
"//source/extensions/common/wasm:wasm_hdr",
"//source/extensions/common/wasm:well_known_names",
"@envoy_api//envoy/config/wasm/v2:wasm_cc",
],
)
Loading