Skip to content
This repository was archived by the owner on Dec 16, 2020. It is now read-only.

wasm: restructure wasm test flakes for bazel build #488

Closed
wants to merge 11 commits into from
Closed
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 .bazelignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
examples/grpc-bridge/script
tools/clang_tools
test/extensions/common/wasm/test_data/test_cpp
6 changes: 4 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ build:rbe-toolchain --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
build:rbe-toolchain-clang --config=rbe-toolchain
build:rbe-toolchain-clang --crosstool_top=@rbe_ubuntu_clang//cc:toolchain
build:rbe-toolchain-clang --extra_toolchains=@rbe_ubuntu_clang//config:cc-toolchain
build:rbe-toolchain-clang --action_env=CC=clang --action_env=CXX=clang++ --action_env=PATH=/usr/sbin:/usr/bin:/sbin:/bin:/opt/llvm/bin
build:rbe-toolchain-clang --action_env=CC=clang --action_env=CXX=clang++ --action_env=PATH=/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/llvm/bin

build:rbe-toolchain-clang-libc++ --config=rbe-toolchain
build:rbe-toolchain-clang-libc++ --crosstool_top=@rbe_ubuntu_clang_libcxx//cc:toolchain
build:rbe-toolchain-clang-libc++ --extra_toolchains=@rbe_ubuntu_clang_libcxx//config:cc-toolchain
build:rbe-toolchain-clang-libc++ --action_env=CC=clang --action_env=CXX=clang++ --action_env=PATH=/usr/sbin:/usr/bin:/sbin:/bin:/opt/llvm/bin
build:rbe-toolchain-clang-libc++ --action_env=CC=clang --action_env=CXX=clang++ --action_env=PATH=/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/llvm/bin
build:rbe-toolchain-clang-libc++ --action_env=CXXFLAGS=-stdlib=libc++
build:rbe-toolchain-clang-libc++ --action_env=LDFLAGS=-stdlib=libc++
build:rbe-toolchain-clang-libc++ --define force_libcpp=enabled
Expand All @@ -140,6 +140,8 @@ build:remote --spawn_strategy=remote,sandboxed,local
build:remote --strategy=Javac=remote,sandboxed,local
build:remote --strategy=Closure=remote,sandboxed,local
build:remote --strategy=Genrule=remote,sandboxed,local
# needs RBE image update
build:remote --strategy=BazelBuild=sandboxed,local
build:remote --remote_timeout=7200
build:remote --auth_enabled=true
build:remote --remote_download_toplevel
Expand Down
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ executors:
description: "A regular build executor based on ubuntu image"
docker:
# NOTE: Update bazel/toolchains/rbe_toolchains_config.bzl with sha256 digest to match the image here.
- image: piotrsikora/envoy-build-ubuntu@sha256:e2775df4cf57e86920ca39886a877b4ccc12dbcfaa2a7c2a804f4cb83c797952
- image: envoyproxy/envoy-build-ubuntu@sha256:b86043fc96cfb462bf9ff9369777baa8a240119c7fe3c78c80eabba98c945278
resource_class: xlarge
working_directory: /source

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/bazel-*
bazel-*
BROWSE
/build
/build_*
Expand Down
102 changes: 102 additions & 0 deletions bazel/bazel_repository.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
def _bazel_wasm_repository_impl(ctx):
root = ctx.path(ctx.attr.envoy_root).dirname
ctx.symlink(root.get_child(".bazelversion"), ".bazelversion")

path = root
for child in ctx.attr.reldir.split("/"):
path = path.get_child(child)

for p in path.readdir():
if not p.basename.startswith("bazel-"):
ctx.symlink(p, p.basename)

targets = ctx.execute(["bazel", "query", "--output=label", "filter('.wasm$', //:all)"]).stdout.splitlines()

ctx.file("BUILD.bazel", """
load("@envoy//bazel:bazel_repository.bzl", "bazel_build")

bazel_build(
name = "build",
srcs = [":all"],
outs = {},
log = "log.txt",
script = "build.sh",
visibility = ["//visibility:public"],
)

filegroup(
name = "all",
srcs = glob(
["**"],
exclude = ["BUILD.bazel"],
),
visibility = ["//visibility:public"],
)
""".format(str([t.replace(":", "/").replace("///", "") for t in targets])))

ctx.file("build.sh", """
#!/bin/bash

set -ex

export HOME="$(mktemp -d)"
export TEST_TMPDIR="$(mktemp -d)"
export USE_BAZEL_VERSION="{}"
SCRIPT_DIR="$(realpath "$(dirname "$0")")"

unset BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN

pushd $SCRIPT_DIR

BAZEL_STARTUP_OPTIONS=""
bazel $BAZEL_STARTUP_OPTIONS build --announce_rc --symlink_prefix=/ {}

BIN_DIR=$(bazel $BAZEL_STARTUP_OPTIONS info bazel-bin)
popd

for out in "$@"; do
cp $BIN_DIR/$(basename $out) $out
done

""".format(ctx.os.environ.get("USE_BAZEL_VERSION", ""), " ".join(targets)))

bazel_wasm_repository = repository_rule(
implementation = _bazel_wasm_repository_impl,
configure = True,
attrs = {
"envoy_root": attr.label(default = "@envoy//:BUILD"),
"reldir": attr.string(),
},
environ = ["USE_BAZEL_VERSION"],
)

def _bazel_build_impl(ctx):
sources = depset([], transitive = [t.files for t in ctx.attr.srcs])

command = """bash {} {}""".format(
ctx.file.script.path,
" ".join([f.path for f in ctx.outputs.outs]),
)

outs = [] + ctx.outputs.outs
if ctx.outputs.log:
command += " &> " + ctx.outputs.log.path
outs.append(ctx.outputs.log)

ctx.actions.run_shell(
command = command,
inputs = sources,
mnemonic = "BazelBuild",
outputs = outs,
use_default_shell_env = True,
)

bazel_build = rule(
implementation = _bazel_build_impl,
attrs = {
"srcs": attr.label_list(allow_files = True),
"script": attr.label(allow_single_file = True),
"log": attr.output(),
"outs": attr.output_list(),
},
)
6 changes: 2 additions & 4 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load(":dev_binding.bzl", "envoy_dev_binding")
load(":genrule_repository.bzl", "genrule_repository")
load(":bazel_repository.bzl", "bazel_wasm_repository")
load("@envoy_api//bazel:envoy_http_archive.bzl", "envoy_http_archive")
load(":repository_locations.bzl", "REPOSITORY_LOCATIONS")
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
Expand Down Expand Up @@ -166,10 +167,7 @@ def envoy_dependencies(skip_targets = []):
_go_deps(skip_targets)
_kafka_deps()

native.local_repository(
name = "common_wasm_test_cpp",
path = "test/extensions/common/wasm/test_data/test_cpp",
)
bazel_wasm_repository(name = "wasm_test_flakes", reldir = "test/extensions/wasm/test_wasm")

switched_rules_by_language(
name = "com_google_googleapis_imports",
Expand Down
4 changes: 4 additions & 0 deletions bazel/wasm_repositories.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# load("@envoy_api//bazel:wasm_repositories.bzl", "api_dependencies")

# def envoy_api_dependencies():
# api_dependencies()
2 changes: 1 addition & 1 deletion source/extensions/filters/http/lua/wrappers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,4 @@ int PublicKeyWrapper::luaGet(lua_State* state) {
} // namespace Lua
} // namespace HttpFilters
} // namespace Extensions
} // namespace Envoy
} // namespace Envoy
15 changes: 0 additions & 15 deletions test/extensions/access_loggers/wasm/test_data/BUILD

This file was deleted.

3 changes: 0 additions & 3 deletions test/extensions/access_loggers/wasm/test_data/Makefile

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
31 changes: 0 additions & 31 deletions test/extensions/common/wasm/test_data/BUILD

This file was deleted.

9 changes: 0 additions & 9 deletions test/extensions/common/wasm/test_data/Makefile

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

4 changes: 0 additions & 4 deletions test/extensions/common/wasm/test_data/docker_cpp_builder.sh

This file was deleted.

Binary file not shown.
19 changes: 0 additions & 19 deletions test/extensions/common/wasm/test_data/test_cpp/BUILD

This file was deleted.

3 changes: 0 additions & 3 deletions test/extensions/common/wasm/test_data/test_cpp/Makefile

This file was deleted.

10 changes: 0 additions & 10 deletions test/extensions/common/wasm/test_data/test_cpp/README.md

This file was deleted.

57 changes: 0 additions & 57 deletions test/extensions/common/wasm/test_data/test_cpp/WORKSPACE

This file was deleted.

Binary file not shown.
Loading