Skip to content

Commit

Permalink
build: migrate wee8 to genrule_repository. (#45)
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
  • Loading branch information
PiotrSikora authored Jun 11, 2019
1 parent 3b41f40 commit 96c49d5
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 125 deletions.
10 changes: 10 additions & 0 deletions bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,13 @@ alias(
},
),
)

# Alias pointing to a platform-specific version of wee8.
alias(
name = "wee8",
actual = select({
":darwin": "@wee8_macos//:wee8",
":darwin_x86_64": "@wee8_macos//:wee8",
"//conditions:default": "@wee8_linux//:wee8",
}),
)
27 changes: 27 additions & 0 deletions bazel/external/wee8.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
licenses(["notice"]) # Apache 2

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

cc_library(
name = "wee8",
srcs = select({
"@envoy//bazel:windows_x86_64": ["WINDOWS_IS_NOT_SUPPORTED_YET"],
"//conditions:default": [
"libwee8.a",
],
}),
hdrs = [
"wee8/third_party/wasm-api/wasm.hh",
],
includes = ["wee8/third_party"],
visibility = ["//visibility:public"],
)

genrule(
name = "build",
srcs = glob(["wee8/**"]),
outs = [
"libwee8.a",
],
cmd = genrule_cmd("@envoy//bazel/external:wee8.genrule_cmd"),
)
24 changes: 24 additions & 0 deletions bazel/external/wee8.genrule_cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -e

# This works only on Linux-x86_64 and macOS-x86_64.
if [[ ( `uname` != "Linux" && `uname` != "Darwin" ) || `uname -m` != "x86_64" ]]; then
echo "ERROR: wee8 is currently supported only on Linux-x86_64 and macOS-x86_64."
exit 1
fi

# Bazel magic.
ROOT=$$(dirname $(rootpath wee8/BUILD.gn))/..
pushd $$ROOT/wee8

# Clean after previous build.
rm -rf out/wee8

# Build wee8.
third_party/depot_tools/gn gen out/wee8 --args="v8_use_external_startup_data=false v8_enable_i18n_support=false v8_enable_gdbjit=false v8_expose_symbols=true is_component_build=false is_debug=false use_sysroot=false use_custom_libcxx=false"
third_party/depot_tools/ninja -C out/wee8 wee8

# Move compiled library to the expected destinations.
popd
mv $$ROOT/wee8/out/wee8/obj/libwee8.a $(execpath libwee8.a)
34 changes: 34 additions & 0 deletions bazel/external/wee8.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 1. Fix handling of f64 globals.
# 2. Force full GC when destroying VMs.
# 3. Fix build with -DDEBUG.
--- a/wee8/src/wasm/c-api.cc
+++ b/wee8/src/wasm/c-api.cc
@@ -825,7 +825,7 @@ void global_set_f32(v8::Local<v8::Object> global, float val) {
void global_set_f64(v8::Local<v8::Object> global, double val) {
auto v8_object = v8::Utils::OpenHandle<v8::Object, i::JSReceiver>(global);
auto v8_global = i::Handle<i::WasmGlobalObject>::cast(v8_object);
- v8_global->SetF32(val);
+ v8_global->SetF64(val);
}

// Tables
@@ -1107,7 +1107,7 @@ class StoreImpl {
StoreImpl() {}

~StoreImpl() {
-#ifdef DEBUG
+#if 1
reinterpret_cast<i::Isolate*>(isolate_)->heap()->PreciseCollectAllGarbage(
i::Heap::kNoGCFlags, i::GarbageCollectionReason::kTesting,
v8::kGCCallbackFlagForced);
--- a/wee8/third_party/wasm-api/wasm.hh
+++ b/wee8/third_party/wasm-api/wasm.hh
@@ -111,7 +111,7 @@ class vec {
size_t size_;
std::unique_ptr<T[]> data_;

-#ifdef DEBUG
+#if 0
void make_data();
void free_data();
#else
2 changes: 1 addition & 1 deletion bazel/genrule_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def _genrule_repository(ctx):
for ii, patch in enumerate(ctx.attr.patches):
patch_input = "patch-input-%d.patch" % (ii,)
ctx.symlink(patch, patch_input)
patch_result = ctx.execute(["patch", "-p0", "--input", patch_input])
patch_result = ctx.execute(["patch", "-p1", "--input", patch_input])
if patch_result.return_code != 0:
fail("Failed to apply patch %r: %s" % (patch, patch_result.stderr))

Expand Down
30 changes: 30 additions & 0 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ def envoy_dependencies(path = "@envoy_deps//", skip_targets = []):
actual = "@envoy//bazel:boringssl",
)

# Binding to an alias pointing to a platform-specific version of wee8.
_wee8_linux()
_wee8_macos()
native.bind(
name = "wee8",
actual = "@envoy//bazel:wee8",
)

# The long repo names (`com_github_fmtlib_fmt` instead of `fmtlib`) are
# semi-standard in the Bazel community, intended to avoid both duplicate
# dependencies and name conflicts.
Expand Down Expand Up @@ -707,6 +715,28 @@ def _com_github_gperftools_gperftools():
actual = "@envoy//bazel/foreign_cc:gperftools",
)

def _wee8_linux():
location = REPOSITORY_LOCATIONS["wee8_linux"]
genrule_repository(
name = "wee8_linux",
urls = location["urls"],
sha256 = location["sha256"],
genrule_cmd_file = "@envoy//bazel/external:wee8.genrule_cmd",
build_file = "@envoy//bazel/external:wee8.BUILD",
patches = ["@envoy//bazel/external:wee8.patch"],
)

def _wee8_macos():
location = REPOSITORY_LOCATIONS["wee8_macos"]
genrule_repository(
name = "wee8_macos",
urls = location["urls"],
sha256 = location["sha256"],
genrule_cmd_file = "@envoy//bazel/external:wee8.genrule_cmd",
build_file = "@envoy//bazel/external:wee8.BUILD",
patches = ["@envoy//bazel/external:wee8.patch"],
)

def _foreign_cc_dependencies():
_repository_impl("rules_foreign_cc")

Expand Down
14 changes: 14 additions & 0 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,20 @@ REPOSITORY_LOCATIONS = dict(
strip_prefix = "subpar-1.3.0",
urls = ["https://github.com/google/subpar/archive/1.3.0.tar.gz"],
),
wee8_linux = dict(
# This archive was created using https://storage.googleapis.com/envoyproxy-wee8/wee8-archive.sh
# and contains complete checkout of v8 with all dependencies necessary to build wee8 on Linux-x86_64.
# TODO(PiotrSikora): switch to local compiler and provide single platform-agnostic archive.
sha256 = "1caebced30cb9d3531be4720b70c9132c988b362160f7721bc01caeb572c0eb7",
urls = ["https://storage.googleapis.com/envoyproxy-wee8/wee8-7.5.288.22-linux-x86_64.tar.gz"],
),
wee8_macos = dict(
# This archive was created using https://storage.googleapis.com/envoyproxy-wee8/wee8-archive.sh
# and contains complete checkout of v8 with all dependencies necessary to build wee8 on macOS-x86_64.
# TODO(PiotrSikora): switch to local compiler and provide single platform-agnostic archive.
sha256 = "f84e423417db0b03b96e853b7d92f69be7d4936a33d1e8e05848fb146925ff68",
urls = ["https://storage.googleapis.com/envoyproxy-wee8/wee8-7.5.288.22-macos-x86_64.tar.gz"],
),
com_googlesource_quiche = dict(
# Static snapshot of https://quiche.googlesource.com/quiche/+archive/7bf7c3c358eb954e463bde14ea27444f4bd8ea05.tar.gz
sha256 = "36fe180d532a9ccb18cd32328af5231636c7408104523f9ed5eebbad75f1e039",
Expand Down
1 change: 0 additions & 1 deletion bazel/target_recipes.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
# target in //ci/prebuilt/BUILD to the underlying build recipe in
# ci/build_container/build_recipes.
TARGET_RECIPES = {
"wee8": "v8",
"wavm_with_llvm": "wavm",
}
108 changes: 0 additions & 108 deletions ci/build_container/build_recipes/v8.sh

This file was deleted.

14 changes: 0 additions & 14 deletions ci/prebuilt/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@ licenses(["notice"]) # Apache 2

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

cc_library(
name = "wee8",
srcs = select({
"@envoy//bazel:windows_x86_64": ["WINDOWS_IS_NOT_SUPPORTED_YET"],
"//conditions:default": [
"thirdparty_build/lib/libwee8.a",
],
}),
hdrs = [
"thirdparty_build/include/wasm-c-api/wasm.hh",
],
includes = ["thirdparty_build/include"],
)

cc_library(
name = "wavm_with_llvm",
srcs = select({
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/common/wasm/v8/v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "absl/strings/match.h"
#include "absl/types/span.h"
#include "absl/utility/utility.h"
#include "wasm-c-api/wasm.hh"
#include "wasm-api/wasm.hh"

namespace Envoy {
namespace Extensions {
Expand Down

0 comments on commit 96c49d5

Please sign in to comment.