astral-sh/uv
uv-trampoline-builder
crates/uv-trampoline-builder/ produces the small Windows executables that act as console
shims for venv-installed scripts. It embeds prebuilt binaries from crates/uv-trampoline/ (a
nightly-only no_std crate) and stamps them with the right paths at install time.
Purpose
On Windows, putting a Python script directly into Scripts/ doesn't work the way it does on
Unix — there's no #! honoring. The standard approach is a tiny .exe that re-launches the
venv's Python and invokes the actual entry point. uv adopts that approach with its own
trampoline implementation derived from
Posy's posy-trampoline.
Directory layout
crates/uv-trampoline-builder/src/
├── lib.rs # 27k chars: build APIs + payload embedding
└── bin/ # Embedded prebuilt trampoline binariesKey abstractions
| Type | Role |
|---|---|
Trampoline enum / kind |
The trampoline flavor: GUI script vs. console script vs. Python-loader. |
prepend_to_trampoline |
Append the script payload (the actual script bytes plus a target descriptor) to a stamped trampoline binary. |
windows_script_launchers |
Helpers for writing the .exe shim into a venv's Scripts/ directory. |
How it works
Each trampoline is a small Win32 PE binary that:
- Locates the venv's
python.exe(relative path computed at install). - Reads its own appended payload (a frozen Python script + entry-point descriptor).
- Spawns Python with that script and the real arguments.
- Forwards exit status.
The build pipeline:
- The actual trampoline source lives in
crates/uv-trampoline/(a separate, nightly-only,no_stdcrate excluded from the main workspace). scripts/build-trampolines.shbuilds those binaries on a Windows host (or via Wine / podman) and copies them intocrates/uv-trampoline-builder/src/bin/.crates/uv-trampoline-builderinclude_bytes!s those binaries and exposes them to the rest of uv.- At install time,
uv-virtualenvanduv-install-wheelcall into this crate to produce.exeshims with the right script appended.
The CI workflow .github/workflows/test-windows-trampolines.yml runs the trampoline tests
across multiple Windows configurations, including QEMU and Wine for non-native runners.
Integration points
uv-virtualenvuses these for the venv'spython.exeshim.uv-install-wheeluses these for installed console scripts.uv-toolreuses them for tool-environment shims.
Entry points for modification
- Adding a launcher kind — extend the
Trampolineenum and add a corresponding payload format. Updatecrates/uv-trampoline/if a new binary is needed and rebuild viascripts/build-trampolines.sh. - Resigning / re-stamping —
lib.rshas the helpers for rewriting an existing trampoline's appended payload (used when a venv is moved).
Key source files
| File | Purpose |
|---|---|
crates/uv-trampoline-builder/src/lib.rs |
The 27k-character build API. |
crates/uv-trampoline-builder/src/bin/ |
The prebuilt PE binaries. |
crates/uv-trampoline/ |
The actual trampoline source (separate workspace, nightly only). |
See also
uv-trampoline— the source that produces the embedded binaries.uv-virtualenv— the Windows venv consumer.uv-install-wheel— the console-script consumer.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.