Skip to content

Commit 78cff07

Browse files
authored
deps: apply necessary changes for envoy_api MODULE without MODULE.bazel file (#41835)
#### Description This PR apply necessary changes for envoy_api MODULE without MODULE.bazel file. cf. envoyproxy/data-plane-api#632 Signed-off-by: Matthieu MOREL <[email protected]>
1 parent c3c5bf2 commit 78cff07

File tree

9 files changed

+101
-13
lines changed

9 files changed

+101
-13
lines changed

api/bazel/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ load(":repository_locations_utils.bzl", "load_repository_locations_spec")
1212
licenses(["notice"]) # Apache 2
1313

1414
exports_files([
15+
"extensions.bzl",
1516
"repository_locations.bzl",
1617
"repository_locations_utils.bzl",
1718
"utils.bzl",

api/bazel/api_build_system.bzl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
load("@com_envoyproxy_protoc_gen_validate//bazel:pgv_proto_library.bzl", "pgv_cc_proto_library")
22
load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")
33
load("@com_github_grpc_grpc//bazel:python_rules.bzl", _py_proto_library = "py_proto_library")
4+
load("@com_google_protobuf//bazel:java_proto_library.bzl", "java_proto_library")
45
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
56
load("@io_bazel_rules_go//go:def.bzl", "go_test")
67
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
@@ -24,6 +25,7 @@ _CC_GRPC_SUFFIX = "_cc_grpc"
2425
_GO_PROTO_SUFFIX = "_go_proto"
2526
_GO_IMPORTPATH_PREFIX = "github.com/envoyproxy/go-control-plane/"
2627
_JAVA_PROTO_SUFFIX = "_java_proto"
28+
_IS_BZLMOD = str(Label("//:invalid")).startswith("@@")
2729

2830
_COMMON_PROTO_DEPS = [
2931
"@com_google_protobuf//:any_proto",
@@ -43,7 +45,8 @@ _COMMON_PROTO_DEPS = [
4345
def _proto_mapping(dep, proto_dep_map, proto_suffix):
4446
mapped = proto_dep_map.get(dep)
4547
if mapped == None:
46-
prefix = "@" + Label(dep).workspace_name if not dep.startswith("//") else ""
48+
prefix = "@@" if _IS_BZLMOD else "@"
49+
prefix = prefix + Label(dep).repo_name if not dep.startswith("//") else ""
4750
return prefix + "//" + Label(dep).package + ":" + Label(dep).name + proto_suffix
4851
return mapped
4952

@@ -113,7 +116,7 @@ def api_cc_py_proto_library(
113116
)
114117

115118
if java:
116-
native.java_proto_library(
119+
java_proto_library(
117120
name = name + _JAVA_PROTO_SUFFIX,
118121
visibility = ["//visibility:public"],
119122
deps = [relative_name],

api/bazel/cc_proto_descriptor_library/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ cc_library(
3737
"@com_google_absl//absl/strings:str_format",
3838
"@com_google_protobuf//:protobuf",
3939
"@com_google_protobuf//src/google/protobuf/compiler:code_generator",
40-
"@com_google_protobuf//src/google/protobuf/compiler:retention",
4140
],
4241
)
4342

api/bazel/cc_proto_descriptor_library/builddefs.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"""
44

55
load("@bazel_skylib//lib:paths.bzl", "paths")
6+
load("@com_google_protobuf//bazel/common:proto_info.bzl", "ProtoInfo")
7+
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
8+
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
69

710
# begin:google_only
811
# load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain")

api/bazel/extensions.bzl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""Non-BCR dependencies for Envoy Data Plane API.
2+
3+
This extension provides repositories that are not available in Bazel Central Registry (BCR).
4+
"""
5+
6+
load(":repositories.bzl", "api_dependencies")
7+
8+
def _non_module_deps_impl(module_ctx):
9+
"""Implementation for non_module_deps extension.
10+
11+
This extension calls api_dependencies(bzlmod=True) which creates repositories
12+
not in BCR. It safely coexists with BCR deps because envoy_http_archive
13+
checks native.existing_rules() before creating repositories.
14+
15+
Args:
16+
module_ctx: Module extension context
17+
"""
18+
api_dependencies(bzlmod = True)
19+
20+
non_module_deps = module_extension(
21+
implementation = _non_module_deps_impl,
22+
doc = """
23+
Extension for Envoy API dependencies not available in BCR.
24+
25+
This extension creates the following repositories:
26+
- prometheus_metrics_model: Prometheus client model
27+
- com_github_chrusty_protoc_gen_jsonschema: Proto to JSON schema compiler
28+
- envoy_toolshed: Tooling and libraries for Envoy development
29+
30+
For WORKSPACE mode, call api_dependencies() directly from WORKSPACE.
31+
This extension should only be used in MODULE.bazel files.
32+
""",
33+
)

api/bazel/repositories.bzl

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,23 @@ def external_http_archive(name, **kwargs):
1212
**kwargs
1313
)
1414

15-
def api_dependencies():
15+
def api_dependencies(bzlmod = False):
16+
# Dependencies needed for both WORKSPACE and bzlmod
17+
external_http_archive(
18+
name = "prometheus_metrics_model",
19+
build_file_content = PROMETHEUSMETRICS_BUILD_CONTENT,
20+
)
21+
external_http_archive(
22+
name = "com_github_chrusty_protoc_gen_jsonschema",
23+
)
24+
external_http_archive(
25+
name = "envoy_toolshed",
26+
)
27+
28+
# WORKSPACE-only dependencies (available in BCR for bzlmod or not needed)
29+
if bzlmod:
30+
return
31+
1632
external_http_archive(
1733
name = "bazel_skylib",
1834
)
@@ -30,10 +46,6 @@ def api_dependencies():
3046
external_http_archive(
3147
name = "com_github_cncf_xds",
3248
)
33-
external_http_archive(
34-
name = "prometheus_metrics_model",
35-
build_file_content = PROMETHEUSMETRICS_BUILD_CONTENT,
36-
)
3749
external_http_archive(
3850
name = "rules_buf",
3951
)
@@ -51,9 +63,6 @@ def api_dependencies():
5163
external_http_archive(
5264
name = "dev_cel",
5365
)
54-
external_http_archive(
55-
name = "com_github_chrusty_protoc_gen_jsonschema",
56-
)
5766

5867
PROMETHEUSMETRICS_BUILD_CONTENT = """
5968
load("@envoy_api//bazel:api_build_system.bzl", "api_cc_py_proto_library")

api/bazel/repository_locations.bzl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,22 @@ REPOSITORY_LOCATIONS_SPEC = dict(
166166
license = "Apache-2.0",
167167
license_url = "https://github.com/google/cel-spec/blob/v{version}/LICENSE",
168168
),
169+
envoy_toolshed = dict(
170+
project_name = "envoy_toolshed",
171+
project_desc = "Tooling, libraries, runners and checkers for Envoy proxy's CI",
172+
project_url = "https://github.com/envoyproxy/toolshed",
173+
version = "0.3.5",
174+
sha256 = "ec59fe6cf1432d33c0207e9f85bda3cbf653b54b3a16f3f94479b6cc8f3d1701",
175+
strip_prefix = "toolshed-bazel-v{version}/bazel",
176+
urls = ["https://github.com/envoyproxy/toolshed/archive/bazel-v{version}.tar.gz"],
177+
use_category = ["build", "controlplane", "dataplane_core"],
178+
implied_untracked_deps = [
179+
"tsan_libs",
180+
"msan_libs",
181+
],
182+
release_date = "2025-10-27",
183+
cpe = "N/A",
184+
license = "Apache-2.0",
185+
license_url = "https://github.com/envoyproxy/toolshed/blob/bazel-v{version}/LICENSE",
186+
),
169187
)

api/tools/generate_listeners_test.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,18 @@
99
import generate_listeners
1010

1111
if __name__ == "__main__":
12-
srcdir = os.path.join(os.getenv("TEST_SRCDIR"), 'envoy_api')
12+
test_srcdir = os.getenv("TEST_SRCDIR")
13+
# In bzlmod, the main repository is '_main', in WORKSPACE it's 'envoy_api'
14+
# Try both to support both build systems
15+
for workspace_name in ['_main', 'envoy_api']:
16+
candidate_dir = os.path.join(test_srcdir, workspace_name)
17+
if os.path.isdir(candidate_dir):
18+
srcdir = candidate_dir
19+
break
20+
else:
21+
# Fallback to _main if neither exists (shouldn't happen)
22+
srcdir = os.path.join(test_srcdir, '_main')
23+
1324
generate_listeners.generate_listeners(
1425
os.path.join(srcdir, "examples/service_envoy/listeners.pb"), "/dev/stdout", "/dev/stdout",
1526
iter([os.path.join(srcdir, "examples/service_envoy/http_connection_manager.pb")]))

api/tools/tap2pcap_test.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@
1414
# a golden output file for the tshark dump. Since we run tap2pcap in a
1515
# subshell with a limited environment, the inferred time zone should be UTC.
1616
if __name__ == '__main__':
17-
srcdir = os.path.join(os.getenv('TEST_SRCDIR'), 'envoy_api')
17+
test_srcdir = os.getenv('TEST_SRCDIR')
18+
# In bzlmod, the main repository is '_main', in WORKSPACE it's 'envoy_api'
19+
# Try both to support both build systems
20+
for workspace_name in ['_main', 'envoy_api']:
21+
candidate_dir = os.path.join(test_srcdir, workspace_name)
22+
if os.path.isdir(candidate_dir):
23+
srcdir = candidate_dir
24+
break
25+
else:
26+
# Fallback to _main if neither exists (shouldn't happen)
27+
srcdir = os.path.join(test_srcdir, '_main')
28+
1829
tap_path = os.path.join(srcdir, 'tools/data/tap2pcap_h2_ipv4.pb_text')
1930
expected_path = os.path.join(srcdir, 'tools/data/tap2pcap_h2_ipv4.txt')
2031
pcap_path = os.path.join(os.getenv('TEST_TMPDIR'), 'generated.pcap')

0 commit comments

Comments
 (0)