diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 00000000..b7c51210 --- /dev/null +++ b/.bazelrc @@ -0,0 +1,5 @@ +build --copt=-fPIC +build --cxxopt=-std=c++17 +build --conlyopt=-fexceptions +build --fission=dbg,opt +build --features=per_object_debug_info diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 00000000..40c341bd --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +3.6.0 diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index 59713c0a..f9d2ecbe 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -74,4 +74,22 @@ jobs: - name: Test run: | - "${GITHUB_WORKSPACE}/bin/bazel" test //... + "${GITHUB_WORKSPACE}/bin/bazel" test //test/... + + integration-test-envoy: + runs-on: ubuntu-latest + container: + image: gcr.io/envoy-ci/envoy-build:19a268cfe3d12625380e7c61d2467c8779b58b56 + steps: + - uses: actions/checkout@v2 + + - uses: actions/cache@v2 + with: + path: ~/.cache/bazel + # TODO: find better keys + # ${ENVOY_HASH}-YYYY-MM-DD + key: 0f7952d1850be92620f2add304c8d95fce028f93-2020-11-27 + + - name: Test + run: | + "bazel" test //integration_test/envoy/... --define wasm=wasmtime --verbose_failures diff --git a/BUILD b/BUILD index e9d434b2..d81c0d38 100644 --- a/BUILD +++ b/BUILD @@ -1,4 +1,5 @@ -load("//:bazel/variables.bzl", "COPTS", "LINKOPTS") +load("@rules_cc//cc:defs.bzl", "cc_library") +load("@proxy_wasm_cpp_host//bazel:variables.bzl", "COPTS") licenses(["notice"]) # Apache 2 @@ -36,3 +37,48 @@ cc_library( "@wasm_c_api//:wasmtime_lib", ], ) + +cc_library( + name = "common_lib", + srcs = glob([ + "src/*.h", + "src/*.cc", + "src/common/*.h", + "src/common/*.cc", + "src/third_party/*.h", + "src/third_party/*.cc", + ]), + deps = [ + ":include", + "//external:abseil_flat_hash_map", + "//external:abseil_optional", + "//external:abseil_strings", + "//external:protobuf", + "//external:ssl", + "//external:zlib", + "@proxy_wasm_cpp_sdk//:api_lib", + "@proxy_wasm_cpp_sdk//:common_lib", + ], +) + +cc_library( + name = "null_lib", + srcs = glob([ + "src/null/*.cc", + ]), + deps = [ + ":common_lib", + ], +) + +cc_library( + name = "wasmtime_lib", + srcs = glob([ + "src/wasmtime/*.h", + "src/wasmtime/*.cc", + ]), + deps = [ + ":common_lib", + "@com_github_wasm_c_api//:wasmtime_lib", + ], +) diff --git a/WORKSPACE b/WORKSPACE index 874d39b1..5b08a7b4 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,89 +1,29 @@ workspace(name = "proxy_wasm_cpp_host") -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") +load("@proxy_wasm_cpp_host//bazel:dependencies.bzl", proxy_wasm_cpp_host_dependencies = "dependencies") -git_repository( - name = "proxy_wasm_cpp_sdk", - commit = "1b5f69ce1535b0c21f88c4af4ebf0ec51d255abe", - remote = "https://github.com/proxy-wasm/proxy-wasm-cpp-sdk", -) +proxy_wasm_cpp_host_dependencies() -http_archive( - name = "com_google_absl", - sha256 = "19391fb4882601a65cb648d638c11aa301ce5f525ef02da1a9eafd22f72d7c59", - strip_prefix = "abseil-cpp-37dd2562ec830d547a1524bb306be313ac3f2556", - # 2020-01-29 - urls = ["https://github.com/abseil/abseil-cpp/archive/37dd2562ec830d547a1524bb306be313ac3f2556.tar.gz"], -) +load("@proxy_wasm_cpp_host//bazel:dependencies_extra.bzl", proxy_wasm_cpp_host_dependencies_extra = "dependencies_extra") -# required by com_google_protobuf -http_archive( - name = "bazel_skylib", - sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", - ], -) +proxy_wasm_cpp_host_dependencies_extra() -load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") +load("@envoy//bazel:api_binding.bzl", "envoy_api_binding") -bazel_skylib_workspace() +envoy_api_binding() -# rust rules -http_archive( - name = "io_bazel_rules_rust", - sha256 = "7401878bf966325bbec5224eeb4ff7e8762681070b401acaa168da68d383563a", - strip_prefix = "rules_rust-9741a32e50a8c50c504c0931111bb6048d6d6888", - url = "https://github.com/bazelbuild/rules_rust/archive/9741a32e50a8c50c504c0931111bb6048d6d6888.tar.gz", -) +load("@envoy//bazel:api_repositories.bzl", "envoy_api_dependencies") -load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories") +envoy_api_dependencies() -rust_repositories() +load("@envoy//bazel:repositories.bzl", "envoy_dependencies") -load("@io_bazel_rules_rust//:workspace.bzl", "rust_workspace") +envoy_dependencies() -rust_workspace() +load("@envoy//bazel:repositories_extra.bzl", "envoy_dependencies_extra") -load("//bazel/cargo:crates.bzl", "proxy_wasm_cpp_host_raze__fetch_remote_crates") +envoy_dependencies_extra() -proxy_wasm_cpp_host_raze__fetch_remote_crates() +load("@envoy//bazel:dependency_imports.bzl", "envoy_dependency_imports") -git_repository( - name = "com_google_protobuf", - commit = "655310ca192a6e3a050e0ca0b7084a2968072260", - remote = "https://github.com/protocolbuffers/protobuf", - shallow_since = "1565024848 -0700", -) - -http_archive( - name = "boringssl", - sha256 = "bb55b0ed2f0cb548b5dce6a6b8307ce37f7f748eb9f1be6bfe2d266ff2b4d52b", - strip_prefix = "boringssl-2192bbc878822cf6ab5977d4257a1339453d9d39", - urls = ["https://github.com/google/boringssl/archive/2192bbc878822cf6ab5977d4257a1339453d9d39.tar.gz"], -) - -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"], -) - -http_archive( - name = "wasmtime", - build_file = "@proxy_wasm_cpp_host//bazel/external:wasmtime.BUILD", - sha256 = "7874feb1026bbef06796bd5ab80e73f15b8e83752bde8dc93994f5bc039a4952", - strip_prefix = "wasmtime-0.21.0", - url = "https://github.com/bytecodealliance/wasmtime/archive/v0.21.0.tar.gz", -) - -http_archive( - name = "wasm_c_api", - build_file = "@proxy_wasm_cpp_host//bazel/external:wasm-c-api.BUILD", - sha256 = "aea8cd095e9937f1e14f2c93e026317b197eb2345e7a817fe3932062eb7b792c", - strip_prefix = "wasm-c-api-d9a80099d496b5cdba6f3fe8fc77586e0e505ddc", - url = "https://github.com/WebAssembly/wasm-c-api/archive/d9a80099d496b5cdba6f3fe8fc77586e0e505ddc.tar.gz", -) +envoy_dependency_imports() diff --git a/bazel/BUILD b/bazel/BUILD new file mode 100644 index 00000000..e69de29b diff --git a/bazel/dependencies.bzl b/bazel/dependencies.bzl new file mode 100644 index 00000000..2a79cab3 --- /dev/null +++ b/bazel/dependencies.bzl @@ -0,0 +1,110 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def dependencies(name = ""): + _envoy_deps() + _http_archives() + +def _http_archives(): + http_archive( + name = "rules_cc", + sha256 = "9d48151ea71b3e225adfb6867e6d2c7d0dce46cbdc8710d9a9a628574dfd40a0", + strip_prefix = "rules_cc-818289e5613731ae410efb54218a4077fb9dbb03", + urls = ["https://github.com/bazelbuild/rules_cc/archive/818289e5613731ae410efb54218a4077fb9dbb03.tar.gz"], + ) + + http_archive( + name = "proxy_wasm_cpp_sdk", + sha256 = "b97e3e716b1f38dc601487aa0bde72490bbc82b8f3ad73f1f3e69733984955df", + strip_prefix = "proxy-wasm-cpp-sdk-956f0d500c380cc1656a2d861b7ee12c2515a664", + urls = ["https://github.com/proxy-wasm/proxy-wasm-cpp-sdk/archive/956f0d500c380cc1656a2d861b7ee12c2515a664.tar.gz"], + ) + + http_archive( + name = "boringssl", + sha256 = "bb55b0ed2f0cb548b5dce6a6b8307ce37f7f748eb9f1be6bfe2d266ff2b4d52b", + strip_prefix = "boringssl-2192bbc878822cf6ab5977d4257a1339453d9d39", + urls = ["https://github.com/google/boringssl/archive/2192bbc878822cf6ab5977d4257a1339453d9d39.tar.gz"], + ) + + 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"], + ) + + http_archive( + name = "wasmtime", + build_file = "@proxy_wasm_cpp_host//bazel/external:wasmtime.BUILD", + sha256 = "7874feb1026bbef06796bd5ab80e73f15b8e83752bde8dc93994f5bc039a4952", + strip_prefix = "wasmtime-0.21.0", + url = "https://github.com/bytecodealliance/wasmtime/archive/v0.21.0.tar.gz", + ) + + http_archive( + name = "wasm_c_api", + build_file = "@proxy_wasm_cpp_host//bazel/external:wasm-c-api.BUILD", + sha256 = "aea8cd095e9937f1e14f2c93e026317b197eb2345e7a817fe3932062eb7b792c", + strip_prefix = "wasm-c-api-d9a80099d496b5cdba6f3fe8fc77586e0e505ddc", + url = "https://github.com/WebAssembly/wasm-c-api/archive/d9a80099d496b5cdba6f3fe8fc77586e0e505ddc.tar.gz", + ) + + http_archive( + name = "com_google_absl", + sha256 = "e3812f256dd7347a33bf9d93a950cf356c61c0596842ff07d8154cd415145d83", + strip_prefix = "abseil-cpp-5d8fc9192245f0ea67094af57399d7931d6bd53f", + urls = ["https://github.com/abseil/abseil-cpp/archive/5d8fc9192245f0ea67094af57399d7931d6bd53f.tar.gz"], + ) + + http_archive( + name = "io_bazel_rules_rust", + sha256 = "7401878bf966325bbec5224eeb4ff7e8762681070b401acaa168da68d383563a", + strip_prefix = "rules_rust-9741a32e50a8c50c504c0931111bb6048d6d6888", + url = "https://github.com/bazelbuild/rules_rust/archive/9741a32e50a8c50c504c0931111bb6048d6d6888.tar.gz", + ) + + http_archive( + name = "bazel_skylib", + sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", + ], + ) + + http_archive( + name = "com_google_protobuf", + sha256 = "465fd9367992a9b9c4fba34a549773735da200903678b81b25f367982e8df376", + strip_prefix = "protobuf-3.13.0", + url = "https://github.com/protocolbuffers/protobuf/releases/download/v3.13.0/protobuf-all-3.13.0.tar.gz", + patches = ["@envoy//bazel:protobuf.patch"], + patch_args = ["-p1"], + ) + +def _envoy_deps(): + native.new_local_repository( + name = "envoy_build_config", + path = "bazel/external/envoy", + build_file_content = "", + ) + + http_archive( + name = "envoy", + sha256 = "910ef0c163a0b9ff34506a6c787de7239d8f57c558ef8db92b3c71d15fc3a281", + strip_prefix = "envoy-0f7952d1850be92620f2add304c8d95fce028f93", + url = "https://github.com/envoyproxy/envoy/archive/0f7952d1850be92620f2add304c8d95fce028f93.tar.gz", + ) diff --git a/bazel/dependencies_extra.bzl b/bazel/dependencies_extra.bzl new file mode 100644 index 00000000..2653c1fb --- /dev/null +++ b/bazel/dependencies_extra.bzl @@ -0,0 +1,24 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("@io_bazel_rules_rust//:workspace.bzl", "rust_workspace") +load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories") +load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") +load("@proxy_wasm_cpp_host//bazel/cargo:crates.bzl", "proxy_wasm_cpp_host_raze__fetch_remote_crates") + +def dependencies_extra(): + bazel_skylib_workspace() + rust_repositories() + rust_workspace() + proxy_wasm_cpp_host_raze__fetch_remote_crates() diff --git a/bazel/external/envoy/extensions_build_config.bzl b/bazel/external/envoy/extensions_build_config.bzl new file mode 100644 index 00000000..ad5497be --- /dev/null +++ b/bazel/external/envoy/extensions_build_config.bzl @@ -0,0 +1,31 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +EXTENSIONS = { + "envoy.access_loggers.wasm": "//source/extensions/access_loggers/wasm:config", + "envoy.bootstrap.wasm": "//source/extensions/bootstrap/wasm:config", + "envoy.filters.http.router": "//source/extensions/filters/http/router:config", + "envoy.filters.http.wasm": "//source/extensions/filters/http/wasm:config", + "envoy.filters.network.http_connection_manager": "//source/extensions/filters/network/http_connection_manager:config", + "envoy.filters.network.tcp_proxy": "//source/extensions/filters/network/tcp_proxy:config", + "envoy.filters.network.wasm": "//source/extensions/filters/network/wasm:config", + "envoy.stat_sinks.wasm": "//source/extensions/stat_sinks/wasm:config", + "envoy.wasm.runtime.null": "//source/extensions/wasm_runtime/null:config", + "envoy.wasm.runtime.wasmtime": "//source/extensions/wasm_runtime/wasmtime:config", +} + +# These can be changed to ["//visibility:public"], for downstream builds which +# need to directly reference Envoy extensions. +EXTENSION_CONFIG_VISIBILITY = ["//:extension_config"] +EXTENSION_PACKAGE_VISIBILITY = ["//:extension_library"] diff --git a/test/test_data/wasm.bzl b/bazel/wasm.bzl similarity index 100% rename from test/test_data/wasm.bzl rename to bazel/wasm.bzl diff --git a/integration_test/envoy/BUILD b/integration_test/envoy/BUILD new file mode 100644 index 00000000..929e91f9 --- /dev/null +++ b/integration_test/envoy/BUILD @@ -0,0 +1,23 @@ +load("@rules_cc//cc:defs.bzl", "cc_test") +load( + "@envoy//bazel:envoy_build_system.bzl", + "envoy_cc_binary", +) + +envoy_cc_binary( + name = "envoy", + repository = "@envoy", + deps = [ + "@envoy//source/exe:envoy_main_entry_lib", + ], +) + +cc_test( + name = "tmp_test", + srcs = ["tmp.cc"], + deps = [ + ":envoy", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/integration_test/envoy/tmp.cc b/integration_test/envoy/tmp.cc new file mode 100644 index 00000000..e4571cd5 --- /dev/null +++ b/integration_test/envoy/tmp.cc @@ -0,0 +1,14 @@ +// Copyright 2016-2019 Envoy Project Authors +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. diff --git a/test/BUILD b/test/BUILD index 803e59e9..82daf715 100644 --- a/test/BUILD +++ b/test/BUILD @@ -1,5 +1,5 @@ load("@rules_cc//cc:defs.bzl", "cc_test") -load("//:bazel/variables.bzl", "COPTS", "LINKOPTS") +load("@proxy_wasm_cpp_host//bazel:variables.bzl", "COPTS", "LINKOPTS") cc_test( name = "null_vm_test", diff --git a/test/test_data/BUILD b/test/test_data/BUILD index d6797368..051f051c 100644 --- a/test/test_data/BUILD +++ b/test/test_data/BUILD @@ -1,4 +1,4 @@ -load("//test/test_data:wasm.bzl", "wasm_rust_binary") +load("@proxy_wasm_cpp_host//bazel:wasm.bzl", "wasm_rust_binary") package(default_visibility = ["//visibility:public"])