Skip to content

feat!: make windows use venvs#3680

Merged
rickeylev merged 66 commits intobazel-contrib:mainfrom
rickeylev:sys.py.win.venv
Apr 9, 2026
Merged

feat!: make windows use venvs#3680
rickeylev merged 66 commits intobazel-contrib:mainfrom
rickeylev:sys.py.win.venv

Conversation

@rickeylev
Copy link
Copy Markdown
Collaborator

@rickeylev rickeylev commented Apr 4, 2026

This makes Windows use a lite venv to better align it with the unixy
implementations. A lite venv is one that has the interpreter and
pyvenv.cfg file, but site-packages isn't populated.

Unfortunately, it has to recreate the venv at runtime because Bazel
incorrectly canonicalizes relative symlinks on Windows. This isn't
ideal, however, Windows builds were already going through a zip-unzip
process, so creating a handful of symlinks seems like an improvement
overall.

A particularity of venvs on Windows is that various supporting .dll
files must be in the same directory as python.exe. A new
attribute (and associated provider plumbing) is added to py_runtime
to capture these extra files.

Note that this requires symlink support be enabled in Bazel and
Windows. If both aren't enabled, then weird errors will occur because
junctions (instead of symlinks) are created that point to files
(junctions can only point to directories).

Zipapp support for these venvs is also added. This required adding
PyExecutableInfo.venv_interpreter_symlinks to keep track of relative
symlinks that need to be created. Tracking them separately is needed
because Bazel has a bug where relative symlinks are made absolute
on Windows.

The internal plumbing for these symlinks is kept relatively generic
to support using such symlinks in site-packages in a future change.

Along the way...

  • Hash-based extract support is added for zipapps passed to Python.
  • Fixed manually passing a zipapp to Python to bootstrap it. This was
    previously broken because the launcher doesn't know how to look
    inside the zip file.
  • Added RULES_PYTHON_EXTRACT_ROOT support when manually passing
    a zipapp to Python.
  • Fix several issues with forward-slashes being used on Windows.
  • Cleanup and improve bootstrap scripts in various ways.
  • Cleanup some doc in local_runtime_repo.
  • Have repo_utils.which print nicely formatted path entries on
    failure.
  • Add --config=fast-tests to make it easier to run small/medium tests
  • And --config=testone to make it easier to run a specific test

@rickeylev rickeylev requested a review from aignas as a code owner April 4, 2026 04:22
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors Python virtual environment (venv) creation to support platform-specific requirements, particularly for Windows, including the addition of a venv_bin_files attribute to PyRuntimeInfo for including DLLs and PDBs. The changes also update the bootstrap templates to handle Windows-specific pathing, pyvenv.cfg generation, and zip-app execution. Feedback from the review points out a global hardcoding of build_zip_enabled that should be restricted to Windows, redundant logic in the Unix venv creation path, and a bug in the bootstrap template where a function was incorrectly evaluated as a variable. Additionally, minor issues regarding PEP 8 formatting and a placeholder version string in the documentation were noted.

@rickeylev
Copy link
Copy Markdown
Collaborator Author

Ok, i think this is finally ready. Changelog updated. I've been fiddling with it the last couple days, but don't see much left to poke.

The two main breaking changes are:

  1. Windows symlinks are required for this to work
  2. --build_python_zip is now ignored on Windows entirely

Switching to a venv is certainly going to break something, but I've no idea what. There weren't many test failures relating to using a venv itself.

@rickeylev rickeylev changed the title feat!: make windows use full venvs feat!: make windows use venvs Apr 9, 2026
@rickeylev rickeylev added this pull request to the merge queue Apr 9, 2026
Merged via the queue into bazel-contrib:main with commit bd7696a Apr 9, 2026
4 checks passed
@rickeylev rickeylev deleted the sys.py.win.venv branch April 9, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants