Skip to content

Commit 104f4fd

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

10 files changed

Lines changed: 626 additions & 14 deletions

File tree

.bazelrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,25 @@ build --incompatible_default_to_explicit_init_py
99

1010
# MSVC: Use the C++20 standard in order to support C++20 features that were introduced in clang and gcc
1111
build:windows --copt="/std:c++20" --cxxopt="/std:c++20"
12+
# MSVC: Corrects the __cplusplus macro to report the true standard
13+
build:windows --copt="/Zc:__cplusplus" --cxxopt="/Zc:__cplusplus"
1214
# MSVC: Enable modern standards-compatible preprocessor
1315
build:windows --cxxopt="/Zc:preprocessor" --host_cxxopt="/Zc:preprocessor"
1416
# MSVC: Link ANTLR statically to avoid Windows DLL linking errors
1517
build:windows --cxxopt="-DANTLR4CPP_STATIC" --host_cxxopt="-DANTLR4CPP_STATIC"
18+
19+
# Repo environment bypasses for corporate proxy (Windows-only)
20+
common:windows --repo_env=no_proxy=bcr.bazel.build,bazel.build,storage.googleapis.com,*.googleapis.com,metadata.google.internal,169.254.169.254
21+
common:windows --repo_env=NO_PROXY=bcr.bazel.build,bazel.build,storage.googleapis.com,*.googleapis.com,metadata.google.internal,169.254.169.254
22+
23+
# Downloader attempts and retries for BCR network stability (Windows-only)
24+
common:windows --http_connector_attempts=10
25+
common:windows --experimental_repository_downloader_retries=10
26+
27+
# Build verbosity and output options (Windows-only)
28+
build:windows --verbose_failures
29+
test:windows --test_output=errors
30+
31+
# GCS remote caching config (Windows-only, active by default on Windows!)
32+
build:windows --remote_cache=https://storage.googleapis.com/windows-cel-python-remote-cache
33+
build:windows --google_default_credentials=true

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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""Module extension to create a local repository for custom headers."""
2+
3+
# A repository rule that dynamically constructs a platform-independent
4+
# `python_headers_custom` repository.
5+
#
6+
# Why this is needed:
7+
# 1. In the Google internal repository, Python headers are implicitly provided by internal rules.
8+
# In the OSS export, `pybind_extension` and `pybind_library` require explicit access to C++ Python headers.
9+
# 2. Instead of hardcoding a platform-specific repository (like the Linux-only x86_64-unknown-linux-gnu),
10+
# we dynamically resolve the compiler headers from the host platform's registered toolchain alias
11+
# (`@@rules_python++python+python_3_11_host`).
12+
# 3. The directory layout of Python include headers varies by platform:
13+
# - POSIX (Linux/macOS) Python distributions nest headers under `include/python3.11/Python.h`.
14+
# - Windows MSVC Python distributions place headers directly under `include/Python.h`.
15+
# 4. This implementation symlinks the host's `include` directory, checks if the nested `python3.11`
16+
# folder exists, and dynamically configures the `cc_library` glob and `includes` path accordingly.
17+
# This guarantees a seamless, warning-free C++20 compilation on Windows, Linux, and macOS.
18+
def _custom_headers_repo_impl(ctx):
19+
# Resolve label to path
20+
build_file_path = ctx.path(ctx.attr.build_file_label)
21+
repo_dir = build_file_path.dirname
22+
23+
# Symlink the include directory
24+
ctx.symlink(repo_dir.get_child("include"), "include")
25+
26+
# Check if include/python3.11 exists (dynamic pathing for POSIX vs Windows)
27+
if ctx.path("include/python3.11").exists:
28+
include_path = "include/python3.11"
29+
else:
30+
include_path = "include"
31+
32+
# Create BUILD file with dynamic includes
33+
ctx.file("BUILD.bazel", """
34+
cc_library(
35+
name = "headers",
36+
hdrs = glob(["{include_path}/**"]),
37+
includes = ["{include_path}"],
38+
visibility = ["//visibility:public"],
39+
)
40+
""".format(include_path = include_path))
41+
42+
custom_headers_repo = repository_rule(
43+
implementation = _custom_headers_repo_impl,
44+
attrs = {
45+
"build_file_label": attr.label(mandatory = True),
46+
},
47+
)
48+
49+
def _local_repo_extension_impl(_ctx):
50+
custom_headers_repo(
51+
name = "python_headers_custom",
52+
# Use the platform-independent host repository alias!
53+
build_file_label = "@@rules_python++python+python_3_11_host//:BUILD.bazel",
54+
)
55+
56+
local_repo_ext = module_extension(
57+
implementation = _local_repo_extension_impl,
58+
)

release/kokoro/build_windows.bat

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@echo off
2+
:: build_windows.bat
3+
:: Core Bazel Build script for CEL Python on Windows.
4+
5+
echo === Loading Environment Configuration ===
6+
call "%~dp0set_env_windows.bat"
7+
if !ERRORLEVEL! NEQ 0 (
8+
echo Failed to configure build environment!
9+
exit /b 1
10+
)
11+
12+
echo --- Fetching Dependencies ---
13+
bazel %STARTUP_FLAGS% fetch %DISTDIR_FLAGS% //...
14+
if !ERRORLEVEL! NEQ 0 (
15+
echo Fetch failed!
16+
exit /b 1
17+
)
18+
19+
echo --- Getting Output Base ---
20+
for /f "tokens=*" %%i in ('bazel --output_user_root=C:/tmp info output_base') do set "OUTPUT_BASE=%%i"
21+
set "OUTPUT_BASE=!OUTPUT_BASE:/=\!"
22+
echo Output Base: !OUTPUT_BASE!
23+
24+
echo --- Applying VERSION Collision Fix ---
25+
set "ANTLR_DIR=!OUTPUT_BASE!\external\antlr4-cpp-runtime+"
26+
if exist "!ANTLR_DIR!\VERSION" (
27+
if not exist "!ANTLR_DIR!\VERSION.txt" (
28+
echo Renaming !ANTLR_DIR!\VERSION to VERSION.txt
29+
ren "!ANTLR_DIR!\VERSION" VERSION.txt
30+
)
31+
)
32+
if exist "!ANTLR_DIR!\version" (
33+
if not exist "!ANTLR_DIR!\version.txt" (
34+
echo Renaming !ANTLR_DIR!\version to version.txt
35+
ren "!ANTLR_DIR!\version" version.txt
36+
)
37+
)
38+
39+
echo --- Bazel Build ---
40+
bazel %STARTUP_FLAGS% build %DISTDIR_FLAGS% %LINK_FLAGS% //...
41+
if !ERRORLEVEL! NEQ 0 (
42+
echo Build failed!
43+
exit /b 1
44+
)
45+
46+
echo --- Build Success ---

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"

0 commit comments

Comments
 (0)