Skip to content

Commit 05c7218

Browse files
dmitriplotnikovcopybara-github
authored andcommitted
Support Python 3.12, 3.13, and 3.14 on Windows.
PiperOrigin-RevId: 919746546
1 parent 2939a0b commit 05c7218

3 files changed

Lines changed: 77 additions & 22 deletions

File tree

release/kokoro/build_windows.bat

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,25 @@
1717
:: Core Bazel Build script for CEL Python on Windows.
1818

1919
echo === Loading Environment Configuration ===
20-
call "%~dp0set_env_windows.bat"
20+
call "%~dp0set_env_windows.bat" %1
2121
if !ERRORLEVEL! NEQ 0 (
2222
echo Failed to configure build environment!
2323
exit /b 1
2424
)
2525

26+
set "BUILD_STATUS=0"
27+
28+
echo --- Backing up MODULE.bazel ---
29+
copy MODULE.bazel MODULE.bazel.bak >nul
30+
31+
echo --- Dynamically Adjusting Python Version in MODULE.bazel ---
32+
!PYTHON_EXE! -c "import sys; path='MODULE.bazel'; content=open(path).read(); open(path,'w').write(content.replace('python_version = \"3.11\"', 'python_version = \"!PYTHON_VERSION!\"'))"
33+
if !ERRORLEVEL! NEQ 0 (
34+
echo Failed to modify MODULE.bazel!
35+
set "BUILD_STATUS=1"
36+
goto cleanup
37+
)
38+
2639
:: Fetch dependencies. We perform multiple attempts to absorb transient flaky network connections.
2740
echo --- Fetching Dependencies ---
2841
set ATTEMPTS=0
@@ -42,8 +55,8 @@ if !FETCH_STATUS! NEQ 0 (
4255
)
4356
)
4457
echo Fetch failed permanently or max attempts reached.
45-
if exist fetch.log del fetch.log
46-
exit /b 1
58+
set "BUILD_STATUS=1"
59+
goto cleanup
4760
)
4861
if exist fetch.log del fetch.log
4962

@@ -53,7 +66,7 @@ set "OUTPUT_BASE=!OUTPUT_BASE:/=\!"
5366
echo Output Base: !OUTPUT_BASE!
5467

5568
echo --- Resolving Hermetic Python Toolchain ---
56-
for /f "tokens=*" %%A in ('dir /b /ad "!OUTPUT_BASE!\external\*python_3_11_host" 2^>nul') do set "PY_HOST_DIR=%%A"
69+
for /f "tokens=*" %%A in ('dir /b /ad "!OUTPUT_BASE!\external\*python_!PY_VER_UNDERSCORE!_host" 2^>nul') do set "PY_HOST_DIR=%%A"
5770
echo Hermetic Python Directory: !PY_HOST_DIR!
5871

5972
if not "!PY_HOST_DIR!" == "" (
@@ -87,7 +100,18 @@ echo --- Bazel Build ---
87100
bazel %STARTUP_FLAGS% build %LINK_FLAGS% //...
88101
if !ERRORLEVEL! NEQ 0 (
89102
echo Build failed!
90-
exit /b 1
103+
set "BUILD_STATUS=1"
104+
goto cleanup
91105
)
92106

93107
echo --- Build Success ---
108+
109+
:cleanup
110+
if exist fetch.log del fetch.log
111+
if exist MODULE.bazel.bak (
112+
echo --- Restoring MODULE.bazel ---
113+
move /y MODULE.bazel.bak MODULE.bazel >nul
114+
)
115+
if "%BUILD_STATUS%" NEQ "0" (
116+
exit /b %BUILD_STATUS%
117+
)

release/kokoro/presubmit_windows.bat

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,43 @@ setlocal enabledelayedexpansion
1717
:: presubmit_windows.bat
1818
:: Kokoro entrypoint for Windows Presubmit builds.
1919

20-
echo === Launching Windows Build Workflow ===
21-
call "%~dp0build_windows.bat"
22-
if !ERRORLEVEL! NEQ 0 (
23-
echo Windows Presubmit Build FAILED!
24-
exit /b 1
20+
set "IN_PRESUBMIT=1"
21+
set "PRESUBMIT_STATUS=0"
22+
if "%PYTHON_VERSIONS%" == "" (
23+
set "PYTHON_VERSIONS=3.11"
2524
)
2625

27-
echo --- Bazel Test ---
28-
bazel %STARTUP_FLAGS% test %LINK_FLAGS% --test_output=errors //...
29-
if !ERRORLEVEL! NEQ 0 (
30-
echo Tests failed!
31-
exit /b 1
26+
echo === Launching Windows Build Workflow ===
27+
for %%V in (%PYTHON_VERSIONS%) do (
28+
echo --- Building Python %%V ---
29+
call "%~dp0build_windows.bat" %%V
30+
if !ERRORLEVEL! NEQ 0 (
31+
echo Windows Presubmit Build FAILED for Python %%V!
32+
set "PRESUBMIT_STATUS=1"
33+
goto cleanup
34+
)
35+
36+
echo --- Bazel Test Python %%V ---
37+
bazel %STARTUP_FLAGS% test %LINK_FLAGS% --test_output=errors //...
38+
if !ERRORLEVEL! NEQ 0 (
39+
echo Tests failed for Python %%V!
40+
set "PRESUBMIT_STATUS=1"
41+
goto cleanup
42+
)
43+
44+
if exist MODULE.bazel.bak (
45+
echo --- Restoring MODULE.bazel ---
46+
move /y MODULE.bazel.bak MODULE.bazel >nul
47+
)
3248
)
3349

3450
echo Windows Presubmit Build and Tests PASSED!
51+
52+
:cleanup
53+
if exist MODULE.bazel.bak (
54+
echo --- Restoring MODULE.bazel ---
55+
move /y MODULE.bazel.bak MODULE.bazel >nul
56+
)
57+
if "%PRESUBMIT_STATUS%" NEQ "0" (
58+
exit /b %PRESUBMIT_STATUS%
59+
)

release/kokoro/set_env_windows.bat

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,21 @@ echo STARTUP_FLAGS set to %STARTUP_FLAGS%
5252
echo --- Bazel Version ---
5353
bazel %STARTUP_FLAGS% version
5454

55+
set "PYTHON_VERSION=%~1"
56+
if "%PYTHON_VERSION%" == "" (
57+
set "PYTHON_VERSION=3.11"
58+
)
59+
set "PY_VER_UNDERSCORE=%PYTHON_VERSION:.=_%"
60+
set "PY_VER_NO_DOT=%PYTHON_VERSION:.=%"
61+
62+
echo Python Version Selected: %PYTHON_VERSION%
63+
5564
:: Detect Python executable first (needed for downloading BCR assets dynamically)
5665
set PYTHON_EXE=python
57-
where python3.11 >nul 2>&1
66+
where python%PYTHON_VERSION% >nul 2>&1
5867
if !ERRORLEVEL! EQU 0 (
59-
set PYTHON_EXE=python3.11
60-
) else if exist C:\Python311\python.exe (
61-
set PYTHON_EXE=C:\Python311\python.exe
68+
set PYTHON_EXE=python%PYTHON_VERSION%
69+
) else if exist C:\Python%PY_VER_NO_DOT%\python.exe (
70+
set PYTHON_EXE=C:\Python%PY_VER_NO_DOT%\python.exe
6271
)
6372
echo Python set to %PYTHON_EXE%
64-
65-
echo --- Python Version ---
66-
!PYTHON_EXE! --version

0 commit comments

Comments
 (0)