Skip to content

Commit d39e010

Browse files
committed
examples: Add http-filter-cc using bzlmod
Signed-off-by: Ryan Northey <ryan@synca.io>
1 parent 2d56886 commit d39e010

31 files changed

+1140
-1
lines changed

.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.github
2+
http-filter-cc
23
node_modules
34
wasm-cc
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Verify/Filters
2+
3+
permissions:
4+
contents: read
5+
on:
6+
workflow_call:
7+
concurrency:
8+
group: >-
9+
${{ github.event.inputs.head_ref || github.run_id }}-verify_filters
10+
11+
12+
jobs:
13+
http-filter-cc:
14+
permissions:
15+
packages: read
16+
contents: read
17+
runs-on: ubuntu-24.04
18+
steps:
19+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
20+
- run: |
21+
docker pull envoyproxy/envoy:dev
22+
DEV_CONTAINER_ID=$(docker inspect --format='{{.Id}}' envoyproxy/envoy:dev)
23+
echo "DEV_CONTAINER_ID=${DEV_CONTAINER_ID}" >> $GITHUB_ENV
24+
- run: |
25+
echo "build --config=rbe" > repo.bazelrc
26+
echo "build --config=ci" >> repo.bazelrc
27+
./verify.sh
28+
working-directory: http-filter-cc
29+
env:
30+
GITHUB_TOKEN: ${{ github.token }}

.github/workflows/verify.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ jobs:
1919
uses: ./.github/workflows/_verify_examples.yml
2020
wasm:
2121
uses: ./.github/workflows/_verify_wasm.yml
22+
filters:
23+
uses: ./.github/workflows/_verify_filters.yml
24+
permissions:
25+
packages: read
26+
contents: read

http-filter-cc/.bazelrc

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#############################################################################
2+
# startup
3+
#############################################################################
4+
5+
startup --host_jvm_args=-Xmx3g
6+
7+
8+
#############################################################################
9+
# global
10+
#############################################################################
11+
12+
build --color=yes
13+
fetch --color=yes
14+
run --color=yes
15+
16+
common --enable_bzlmod
17+
common --noenable_workspace
18+
common --@envoy//bazel:enable_bzlmod=True
19+
20+
# build --workspace_status_command="bash get_workspace_status"
21+
build --incompatible_strict_action_env
22+
# Global C++ standard and common warning suppressions
23+
build --cxxopt=-std=c++20 --host_cxxopt=-std=c++20
24+
build --copt=-Wno-deprecated-declarations
25+
build --define envoy_mobile_listener=enabled
26+
build --experimental_repository_downloader_retries=2
27+
build --experimental_cc_static_library
28+
build --enable_platform_specific_config
29+
build --incompatible_merge_fixed_and_default_shell_env
30+
build --jobs=HOST_CPUS*.8
31+
build --verbose_failures
32+
33+
common --@rules_python//python/config_settings:bootstrap_impl=script
34+
build --incompatible_default_to_explicit_init_py
35+
36+
# proxy-wasm-cpp-host
37+
common --@proxy-wasm-cpp-host//bazel:crypto_lib=@envoy//bazel:crypto
38+
39+
build --@googleurl//build_config:system_icu=0
40+
41+
#############################################################################
42+
# ci
43+
#############################################################################
44+
45+
common:ci --noshow_progress
46+
common:ci --noshow_loading_progress
47+
common:ci --test_output=errors
48+
49+
build:remote-ci --config=ci
50+
build:remote-ci --remote_download_minimal
51+
52+
53+
#############################################################################
54+
# compiler
55+
#############################################################################
56+
57+
# Common flags for Clang (shared between all clang variants)
58+
common:clang-common --linkopt=-fuse-ld=lld
59+
common:clang-common --@toolchains_llvm//toolchain/config:compiler-rt=false
60+
common:clang-common --@toolchains_llvm//toolchain/config:libunwind=false
61+
62+
# Clang with libc++ (default)
63+
common:clang --config=clang-common
64+
common:clang --config=libc++
65+
common:clang --host_platform=@clang_platform
66+
common:clang --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
67+
68+
# Clang installed to non-standard location (ie not /opt/llvm/)
69+
common:clang-local --config=clang-common
70+
common:clang-local --config=libc++
71+
72+
# libc++ - default for clang
73+
common:libc++ --action_env=CXXFLAGS=-stdlib=libc++
74+
common:libc++ --action_env=LDFLAGS="-stdlib=libc++ -fuse-ld=lld"
75+
common:libc++ --action_env=BAZEL_CXXOPTS=-stdlib=libc++
76+
common:libc++ --action_env=BAZEL_LINKLIBS=-l%:libc++.a:-l%:libc++abi.a
77+
common:libc++ --action_env=BAZEL_LINKOPTS=-lm:-pthread
78+
common:libc++ --define force_libcpp=enabled
79+
common:libc++ --@envoy//bazel:libc++=true
80+
81+
82+
#############################################################################
83+
# remote
84+
#############################################################################
85+
86+
build:remote --spawn_strategy=remote,sandboxed,local
87+
build:remote --strategy=Javac=remote,sandboxed,local
88+
build:remote --strategy=Closure=remote,sandboxed,local
89+
build:remote --strategy=Genrule=remote,sandboxed,local
90+
build:remote --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
91+
92+
## RBE (Engflow Envoy)
93+
94+
# this is not included in the `--config=rbe` target - set it to publish to engflow ui
95+
common:bes --bes_backend=grpcs://mordenite.cluster.engflow.com/
96+
common:bes --bes_results_url=https://mordenite.cluster.engflow.com/invocation/
97+
common:bes --bes_timeout=3600s
98+
common:bes --bes_upload_mode=fully_async
99+
common:bes --nolegacy_important_outputs
100+
101+
common:engflow-common --google_default_credentials=false
102+
common:engflow-common --credential_helper=*.engflow.com=%workspace%/engflow-bazel-credential-helper.sh
103+
common:engflow-common --grpc_keepalive_time=60s
104+
common:engflow-common --grpc_keepalive_timeout=30s
105+
common:engflow-common --remote_cache_compression
106+
107+
# this provides access to RBE+cache
108+
common:rbe --config=remote-cache
109+
common:rbe --config=remote-exec
110+
111+
# this provides access to just cache
112+
common:remote-cache --config=engflow-common
113+
common:remote-cache --remote_cache=grpcs://mordenite.cluster.engflow.com
114+
common:remote-cache --remote_timeout=3600s
115+
116+
common:remote-exec --remote_executor=grpcs://mordenite.cluster.engflow.com
117+
common:remote-exec --jobs=200
118+
common:remote-exec --define=engflow_rbe=true
119+
120+
try-import %workspace%/registry.bazelrc
121+
try-import %workspace%/repo.bazelrc

http-filter-cc/.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.6.2

http-filter-cc/BUILD

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
load("@envoy//bazel:envoy_build_system.bzl", "envoy_cc_binary", "envoy_cc_library")
2+
load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")
3+
load("@rules_pkg//pkg:pkg.bzl", "pkg_tar")
4+
5+
licenses(["notice"]) # Apache 2
6+
7+
package(default_visibility = ["//visibility:public"])
8+
9+
api_proto_package()
10+
11+
envoy_cc_library(
12+
name = "http_filter_lib",
13+
srcs = ["http_filter.cc"],
14+
hdrs = ["http_filter.h"],
15+
repository = "@envoy",
16+
deps = [
17+
":pkg_cc_proto",
18+
"@envoy//source/extensions/filters/http/common:pass_through_filter_lib",
19+
],
20+
)
21+
22+
envoy_cc_library(
23+
name = "http_filter_config",
24+
srcs = ["http_filter_config.cc"],
25+
repository = "@envoy",
26+
deps = [
27+
":http_filter_lib",
28+
"@envoy//envoy/server:filter_config_interface",
29+
],
30+
)
31+
32+
envoy_cc_binary(
33+
name = "envoy",
34+
repository = "@envoy",
35+
deps = [
36+
":http_filter_config",
37+
"@envoy//source/exe:envoy_main_entry_lib",
38+
],
39+
)
40+
41+
filegroup(
42+
name = "files",
43+
srcs = glob(
44+
["**/*"],
45+
exclude = [
46+
"**/*~",
47+
"**/.*",
48+
".*/**/*",
49+
"BUILD",
50+
"README.md",
51+
"WORKSPACE",
52+
],
53+
),
54+
)
55+
56+
pkg_tar(
57+
name = "includes",
58+
srcs = [":files"],
59+
package_dir = "_include/http-filter-cc",
60+
visibility = ["//visibility:public"],
61+
)

http-filter-cc/BUILD.bazel

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
load("@envoy//bazel:envoy_build_system.bzl", "envoy_cc_binary")
2+
load("@rules_pkg//pkg:pkg.bzl", "pkg_tar")
3+
4+
licenses(["notice"]) # Apache 2
5+
6+
package(default_visibility = ["//visibility:public"])
7+
8+
# Custom Envoy binary with the sample filter statically linked
9+
envoy_cc_binary(
10+
name = "envoy",
11+
repository = "@envoy",
12+
deps = [
13+
"//factory:factory_lib",
14+
"@envoy//source/exe:envoy_main_entry_lib",
15+
],
16+
)
17+
18+
filegroup(
19+
name = "files",
20+
srcs = glob(
21+
["**/*"],
22+
exclude = [
23+
"**/*~",
24+
"**/.*",
25+
".*/**/*",
26+
"BUILD.bazel",
27+
"README.md",
28+
],
29+
),
30+
)
31+
32+
pkg_tar(
33+
name = "includes",
34+
srcs = [":files"],
35+
package_dir = "_include/http-filter-cc",
36+
visibility = ["//visibility:public"],
37+
)

http-filter-cc/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM envoyproxy/envoy-build:ci-cdfbb76bc18c115270127132c6f7c67000cd2e74@sha256:48a8b1bc24ed771560126642dcbba33c50c6b837722ba9c75270b858ef7ab3a6 AS builder
2+
ARG USER_ID
3+
ENV USER_ID="${USER_ID:-1000}"
4+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
5+
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
6+
apt-get -qq update \
7+
&& apt-get -qq install --no-install-recommends -y gettext-base \
8+
&& usermod -u "$USER_ID" envoybuild \
9+
&& mkdir -p /home/envoybuild/.cache/bazel
10+
WORKDIR /build
11+
COPY --chmod=755 --chown=envoybuild . /build
12+
RUN chown envoybuild /build && chown -R envoybuild:envoybuild /home/envoybuild/.cache
13+
USER envoybuild
14+
ARG GITHUB_TOKEN
15+
ENV GITHUB_TOKEN="${GITHUB_TOKEN:-}"
16+
ARG ENVOY_BZLMOD_COMMIT
17+
ENV ENVOY_BZLMOD_COMMIT="${ENVOY_BZLMOD_COMMIT:-}"
18+
ARG ENVOY_BZLMOD_REGISTRY
19+
ENV ENVOY_BZLMOD_REGISTRY="${ENVOY_BZLMOD_REGISTRY:-}"
20+
RUN --mount=type=cache,target=/home/envoybuild/.cache/bazel,sharing=locked,uid="${USER_ID}" \
21+
envsubst '${ENVOY_BZLMOD_COMMIT}' < MODULE.bazel.tpl > MODULE.bazel \
22+
&& envsubst '${ENVOY_BZLMOD_REGISTRY}' < registry.bazelrc.tpl > registry.bazelrc \
23+
&& bazel --version \
24+
&& bazel build --config=clang //:envoy \
25+
&& mkdir out \
26+
&& cp -a bazel-bin/envoy out/
27+
28+
29+
FROM envoyproxy/envoy:dev
30+
COPY --from=builder /build/out/envoy /usr/local/bin/envoy
31+
COPY envoy.yaml /etc/envoy/envoy.yaml
32+
CMD ["/usr/local/bin/envoy", "-c", "/etc/envoy/envoy.yaml"]

http-filter-cc/MODULE.bazel.tpl

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
module(
2+
name = "envoy_http_filter",
3+
version = "0.1.0-dev",
4+
)
5+
6+
bazel_dep(name = "bazel_skylib", version = "1.8.2")
7+
bazel_dep(name = "envoy", version = "1.36.4-dev")
8+
bazel_dep(name = "envoy_api", version = "1.36.4-dev")
9+
bazel_dep(name = "googleapis", version = "0.0.0-20251003-2193a2bf")
10+
bazel_dep(name = "googleurl", version = "0.0.0-221103-dd4080f.envoy")
11+
bazel_dep(name = "platforms", version = "1.0.0")
12+
bazel_dep(name = "protobuf", version = "33.4.envoy", repo_name = "com_google_protobuf")
13+
bazel_dep(name = "protoc-gen-validate", version = "1.3.0.envoy", repo_name = "com_envoyproxy_protoc_gen_validate")
14+
bazel_dep(name = "proxy-wasm-cpp-host", version = "0.0.0-260115-beb8a4e.envoy")
15+
bazel_dep(name = "re2", version = "2024-07-02.bcr.1")
16+
bazel_dep(name = "rules_go", version = "0.59.0", repo_name = "io_bazel_rules_go")
17+
bazel_dep(name = "rules_pkg", version = "1.1.0")
18+
bazel_dep(name = "rules_python", version = "1.7.0")
19+
bazel_dep(name = "toolchains_llvm", version = "1.6.0.envoy", dev_dependency = True)
20+
bazel_dep(name = "zipkin-api", version = "1.0.0.envoy")
21+
22+
git_override(
23+
module_name = "envoy",
24+
commit = "${ENVOY_BZLMOD_COMMIT}",
25+
remote = "https://github.com/envoyproxy/envoy",
26+
)
27+
28+
git_override(
29+
module_name = "envoy_api",
30+
commit = "${ENVOY_BZLMOD_COMMIT}",
31+
remote = "https://github.com/envoyproxy/envoy",
32+
strip_prefix = "api",
33+
)
34+
35+
# needed to resolve conflict grpc <> flatbuffers
36+
single_version_override(
37+
module_name = "rules_swift",
38+
version = "2.4.0",
39+
)
40+
41+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
42+
python.toolchain(
43+
is_default = True,
44+
python_version = "3.12",
45+
)
46+
use_repo(
47+
python,
48+
"python_3_12",
49+
python = "python_versions",
50+
)
51+
52+
go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")
53+
go_sdk.download(
54+
name = "go_sdk",
55+
version = "1.24.6",
56+
)
57+
use_repo(
58+
go_sdk,
59+
"go_toolchains",
60+
"io_bazel_rules_nogo",
61+
)
62+
register_toolchains("@go_toolchains//:all")
63+
64+
envoy_toolchains_ext = use_extension("@envoy//bazel:extensions.bzl", "envoy_toolchains_extension")
65+
use_repo(envoy_toolchains_ext, "clang_platform")

http-filter-cc/api/BUILD.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")
2+
3+
licenses(["notice"]) # Apache 2
4+
5+
api_proto_package()

0 commit comments

Comments
 (0)