Skip to content

Commit fda782b

Browse files
Internal change
PiperOrigin-RevId: 917337474
1 parent b60b825 commit fda782b

9 files changed

Lines changed: 367 additions & 14 deletions

File tree

MODULE.bazel

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@ module(
33
)
44

55
# https://registry.bazel.build/modules/abseil-cpp
6-
bazel_dep(name = "abseil-cpp", version = "20250814.1", repo_name = "com_google_absl")
6+
bazel_dep(name = "abseil-cpp", version = "20260107.0", repo_name = "com_google_absl")
77

88
# https://registry.bazel.build/modules/abseil-py
9-
bazel_dep(name = "abseil-py", version = "2.1.0", repo_name = "com_google_absl_py")
9+
bazel_dep(name = "abseil-py", version = "2.4.0", repo_name = "com_google_absl_py")
1010

1111
# https://github.com/bazelbuild/bazel-skylib
12-
bazel_dep(name = "bazel_skylib", version = "1.8.2")
12+
bazel_dep(name = "bazel_skylib", version = "1.9.0")
1313

1414
# https://registry.bazel.build/modules/cel-cpp
1515
bazel_dep(name = "cel-cpp", version = "0.15.0", repo_name = "com_google_cel_cpp")
16-
single_version_override(
16+
git_override(
1717
module_name = "cel-cpp",
18+
commit = "2e6e9ff4493bfbe0baf883107f3fb7ce6f675d88",
1819
patch_cmds = [
1920
# ABSL_CONST_INIT is incompatible with MSVC-CL with the /std:c++20 option
2021
"sed -i 's/ABSL_CONST_INIT //g' common/values/optional_value.cc",
2122
],
22-
version = "0.15.0",
23+
patch_cmds_win = [
24+
"python -c \"import sys; path='common/values/optional_value.cc'; content=open(path).read(); open(path,'w').write(content.replace('ABSL_CONST_INIT ',''))\"",
25+
],
26+
remote = "https://github.com/google/cel-cpp",
2327
)
2428

2529
# https://registry.bazel.build/modules/cel-spec
@@ -32,7 +36,7 @@ bazel_dep(name = "googletest", version = "1.17.0.bcr.2", repo_name = "com_google
3236
bazel_dep(name = "platforms", version = "1.0.0")
3337

3438
# https://registry.bazel.build/modules/protobuf
35-
bazel_dep(name = "protobuf", version = "33.1", repo_name = "com_google_protobuf")
39+
bazel_dep(name = "protobuf", version = "33.4", repo_name = "com_google_protobuf")
3640

3741
# https://registry.bazel.build/modules/pybind11_abseil
3842
bazel_dep(name = "pybind11_abseil", version = "202402.0")
@@ -41,25 +45,34 @@ bazel_dep(name = "pybind11_abseil", version = "202402.0")
4145
bazel_dep(name = "pybind11_bazel", version = "3.0.0")
4246

4347
# https://registry.bazel.build/modules/rules_cc
44-
bazel_dep(name = "rules_cc", version = "0.2.14")
48+
bazel_dep(name = "rules_cc", version = "0.2.16")
4549

4650
# https://registry.bazel.build/modules/rules_proto
4751
bazel_dep(name = "rules_proto", version = "7.1.0")
4852

4953
# https://registry.bazel.build/modules/rules_python
50-
bazel_dep(name = "rules_python", version = "1.7.0")
54+
bazel_dep(name = "rules_python", version = "1.9.0")
5155

5256
# On Windows the file system is case-insensitive, which creates a collision between
5357
# antlr4-cpp-runtime/VERSION and the system `#include <version>`
5458
single_version_override(
5559
module_name = "antlr4-cpp-runtime",
5660
patch_cmds = [
57-
"mv VERSION VERSION.txt",
61+
"python -c \"import os; os.rename('VERSION', 'VERSION.txt') if os.path.exists('VERSION') else None\"",
62+
"python -c \"import os; os.rename('version', 'version.txt') if os.path.exists('version') else None\"",
5863
],
5964
)
6065

61-
python_rules = use_extension("@rules_python//python/extensions:python.bzl", "python")
62-
python_rules.toolchain(
63-
is_default = True,
64-
python_version = "3.11",
66+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
67+
python.defaults(python_version = "3.11")
68+
python.toolchain(python_version = "3.11")
69+
use_repo(python, "pythons_hub")
70+
71+
pybind11_internal_configure = use_extension(
72+
"@pybind11_bazel//:internal_configure.bzl",
73+
"internal_configure_extension",
6574
)
75+
use_repo(pybind11_internal_configure, "pybind11")
76+
77+
local_repo_ext = use_extension("//cel_expr_python:local_repo_extension.bzl", "local_repo_ext")
78+
use_repo(local_repo_ext, "python_headers_custom")

cel_expr_python/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ pybind_library(
125125
"@com_google_cel_cpp//compiler",
126126
"@com_google_cel_cpp//runtime:runtime_builder",
127127
"@com_google_cel_cpp//runtime:runtime_options",
128+
"@python_headers_custom//:headers",
128129
],
129130
)
130131

cel_expr_python/ext/BUILD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pybind_extension(
1616
"//cel_expr_python:cel_extension",
1717
"@com_google_cel_cpp//compiler",
1818
"@com_google_cel_cpp//extensions:bindings_ext",
19+
"@python_headers_custom//:headers",
1920
],
2021
)
2122

@@ -36,6 +37,7 @@ pybind_extension(
3637
"@com_google_cel_cpp//extensions:encoders",
3738
"@com_google_cel_cpp//runtime:runtime_builder",
3839
"@com_google_cel_cpp//runtime:runtime_options",
40+
"@python_headers_custom//:headers",
3941
],
4042
)
4143

@@ -58,6 +60,7 @@ pybind_extension(
5860
"@com_google_cel_cpp//extensions:math_ext_decls",
5961
"@com_google_cel_cpp//runtime:runtime_builder",
6062
"@com_google_cel_cpp//runtime:runtime_options",
63+
"@python_headers_custom//:headers",
6164
],
6265
)
6366

@@ -81,6 +84,7 @@ pybind_extension(
8184
"@com_google_cel_cpp//runtime:optional_types",
8285
"@com_google_cel_cpp//runtime:runtime_builder",
8386
"@com_google_cel_cpp//runtime:runtime_options",
87+
"@python_headers_custom//:headers",
8488
],
8589
)
8690

@@ -98,6 +102,7 @@ pybind_extension(
98102
"//cel_expr_python:cel_extension",
99103
"@com_google_cel_cpp//compiler",
100104
"@com_google_cel_cpp//extensions:proto_ext",
105+
"@python_headers_custom//:headers",
101106
],
102107
)
103108

@@ -119,5 +124,6 @@ pybind_extension(
119124
"@com_google_cel_cpp//extensions:strings",
120125
"@com_google_cel_cpp//runtime:runtime_builder",
121126
"@com_google_cel_cpp//runtime:runtime_options",
127+
"@python_headers_custom//:headers",
122128
],
123129
)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""Module extension to create a local repository for custom headers."""
2+
3+
def _custom_headers_repo_impl(ctx):
4+
# Resolve label to path
5+
build_file_path = ctx.path(ctx.attr.build_file_label)
6+
repo_dir = build_file_path.dirname
7+
8+
# Symlink the include directory
9+
ctx.symlink(repo_dir.get_child("include"), "include")
10+
11+
# Check if include/python3.11 exists (dynamic pathing for POSIX vs Windows)
12+
if ctx.path("include/python3.11").exists:
13+
include_path = "include/python3.11"
14+
else:
15+
include_path = "include"
16+
17+
# Create BUILD file with dynamic includes
18+
ctx.file("BUILD.bazel", """
19+
cc_library(
20+
name = "headers",
21+
hdrs = glob(["{include_path}/**"]),
22+
includes = ["{include_path}"],
23+
visibility = ["//visibility:public"],
24+
)
25+
""".format(include_path = include_path))
26+
27+
custom_headers_repo = repository_rule(
28+
implementation = _custom_headers_repo_impl,
29+
attrs = {
30+
"build_file_label": attr.label(mandatory = True),
31+
},
32+
)
33+
34+
def _local_repo_extension_impl(_ctx):
35+
custom_headers_repo(
36+
name = "python_headers_custom",
37+
# Use the platform-independent host repository alias!
38+
build_file_label = "@@rules_python++python+python_3_11_host//:BUILD.bazel",
39+
)
40+
41+
local_repo_ext = module_extension(
42+
implementation = _local_repo_extension_impl,
43+
)

release/kokoro/build_windows.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# proto-message: BuildConfig
33

44
build_file: "cel-python/release/kokoro/presubmit_windows.bat"
5-
timeout_mins: 30
5+
timeout_mins: 120
66

77
container_properties {
88
docker_image: "us-central1-docker.pkg.dev/kokoro-container-bakery/kokoro/windows/windows2019/full@sha256:c9995cdda2206803409164f9682f47e0027b8836076591a960373e3cdb1847e1"

release/kokoro/download_patches.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import json
2+
import os
3+
import sys
4+
import time
5+
import urllib.error
6+
import urllib.request
7+
8+
def find_modules(node, modules=None):
9+
if modules is None:
10+
modules = set()
11+
12+
if isinstance(node, dict):
13+
name = node.get("name")
14+
version = node.get("version")
15+
if name and version and name != "cel-python" and name != "cel-cpp":
16+
modules.add((name, version))
17+
18+
for val in node.values():
19+
find_modules(val, modules)
20+
elif isinstance(node, list):
21+
for item in node:
22+
find_modules(item, modules)
23+
24+
return modules
25+
26+
def urlopen_with_retry(url, headers=None, timeout=30, max_retries=5, backoff_factor=2):
27+
if headers is None:
28+
headers = {"User-Agent": "Mozilla/5.0"}
29+
30+
req = urllib.request.Request(url, headers=headers)
31+
32+
retries = 0
33+
delay = 1
34+
while True:
35+
try:
36+
# Use standard urlopen (respects proxy settings)
37+
return urllib.request.urlopen(req, timeout=timeout)
38+
except (urllib.error.URLError, ConnectionError, TimeoutError, Exception) as e:
39+
retries += 1
40+
if retries > max_retries:
41+
print(f"Failed to fetch {url} after {max_retries} attempts.", file=sys.stderr)
42+
raise e
43+
print(f"Error fetching {url} (attempt {retries}/{max_retries}): {e}. Retrying in {delay}s...", file=sys.stderr)
44+
time.sleep(delay)
45+
delay *= backoff_factor
46+
47+
def main():
48+
if len(sys.argv) < 3:
49+
print("Usage: python download_patches.py <graph.json> <distdir_base_path>", file=sys.stderr)
50+
sys.exit(1)
51+
52+
graph_path = sys.argv[1]
53+
distdir_base = sys.argv[2]
54+
55+
if not os.path.exists(graph_path):
56+
print(f"Error: {graph_path} not found.", file=sys.stderr)
57+
sys.exit(1)
58+
59+
with open(graph_path, "r") as f:
60+
graph = json.load(f)
61+
62+
modules = find_modules(graph)
63+
print(f"Found {len(modules)} unique transitive modules.", file=sys.stderr)
64+
65+
patches_found = []
66+
67+
for name, version in sorted(modules):
68+
url = f"https://bcr.bazel.build/modules/{name}/{version}/source.json"
69+
try:
70+
with urlopen_with_retry(url, timeout=30) as response:
71+
source_data = json.loads(response.read().decode())
72+
patches = source_data.get("patches")
73+
if patches:
74+
print(f"Module {name}@{version} has patches: {list(patches.keys())}", file=sys.stderr)
75+
for patch_name in patches.keys():
76+
patch_url = f"https://bcr.bazel.build/modules/{name}/{version}/patches/{patch_name}"
77+
patches_found.append({
78+
"module": name,
79+
"version": version,
80+
"patch_name": patch_name,
81+
"url": patch_url
82+
})
83+
except urllib.error.HTTPError as e:
84+
if e.code != 404:
85+
print(f"HTTP Error for {name}@{version}: {e.code}", file=sys.stderr)
86+
except Exception as e:
87+
print(f"Error fetching {name}@{version}: {e}", file=sys.stderr)
88+
89+
print(f"Found {len(patches_found)} patches to download.", file=sys.stderr)
90+
91+
distdir_dirs = set()
92+
93+
for patch in patches_found:
94+
module_clean = patch["module"].replace("-", "_")
95+
dir_name = os.path.join(distdir_base, module_clean)
96+
distdir_dirs.add(dir_name)
97+
98+
os.makedirs(dir_name, exist_ok=True)
99+
dest_file = os.path.join(dir_name, patch["patch_name"])
100+
101+
print(f"Downloading {patch['url']} to {dest_file}...", file=sys.stderr)
102+
try:
103+
with urlopen_with_retry(patch["url"], timeout=30) as response, open(dest_file, "wb") as out:
104+
out.write(response.read())
105+
except Exception as e:
106+
print(f"Failed to download {patch['url']}: {e}", file=sys.stderr)
107+
sys.exit(1)
108+
109+
# Generate the env setting command for batch
110+
distdir_flags = []
111+
for d in sorted(distdir_dirs):
112+
d_win = d.replace("/", "\\")
113+
distdir_flags.append(f"--distdir={d_win}")
114+
115+
flags_str = " ".join(distdir_flags)
116+
print(f'@set "DISTDIR_FLAGS={flags_str}"')
117+
118+
if __name__ == "__main__":
119+
main()

0 commit comments

Comments
 (0)