-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a trampoline variant that just executes python
#8637
Conversation
4084c76
to
868c15a
Compare
7cf64ed
to
5529ab6
Compare
/// | ||
/// <https://github.com/pypa/pip/blob/fd0ea6bc5e8cb95e518c23d901c26ca14db17f89/src/pip/_vendor/distlib/scripts.py#L248-L262> | ||
#[allow(unused_variables)] | ||
pub(crate) fn windows_script_launcher( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This moved ~unchanged into uv-trampoline-builder
@@ -1075,54 +969,6 @@ mod test { | |||
Ok(()) | |||
} | |||
|
|||
#[test] | |||
#[cfg(all(windows, target_arch = "x86"))] | |||
fn test_launchers_are_small() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This moved into uv-trampoline-builder
, size limit bumped
|
||
#[cfg(all(test, windows))] | ||
#[allow(clippy::print_stdout)] | ||
mod test { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests pulled from uv-trampoline::tests::harness
and uv-install-wheel
/// | ||
/// Sort of equivalent to a `python` symlink on Unix. | ||
#[allow(unused_variables)] | ||
pub fn windows_python_launcher( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is new
/// | ||
/// <https://github.com/pypa/pip/blob/fd0ea6bc5e8cb95e518c23d901c26ca14db17f89/src/pip/_vendor/distlib/scripts.py#L248-L262> | ||
#[allow(unused_variables)] | ||
pub fn windows_script_launcher( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was copied ~unchanged
@@ -1,269 +0,0 @@ | |||
use std::io::{Cursor, Write}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This moved ~unchanged into uv-trampoline-builder
3157eb4
to
c29b9d9
Compare
python
python
Ohhh I see what's happening here. I was also surprised they increased in size. Thanks for pointing that out. That's... annoying to fix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. How did you resolve the test failures from yesterday?
Self::Script => &[b'U', b'V', b'S', b'C'], | ||
Self::Python => &[b'U', b'V', b'P', b'Y'], | ||
Self::Script => b"UVSC", | ||
Self::Python => b"UVPY", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah whoops, you already did this. :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry; this is one of those things that wasn't worth moving in the rebase since it was a mess
assert!( | ||
super::LAUNCHER_I686_GUI.len() < 45 * 1024, | ||
super::LAUNCHER_I686_GUI.len() < 80 * 1024, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would using cfg(not(debug_assertions))
as a proxy for "compiling with optimizations" help here? Otherwise, you can't cfg
on opt-level
at present. So probably the only alternative is a Cargo feature. (Assuming I'm understanding the problem correctly.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That'd be interesting. I can also just.. run these tests separately from the ones we run to test changes to the trampolines. In CI, we replace the production trampolines with a debug build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the threshold bump still relevant? In the git diff it looks like the binaries even shrank a little
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since I moved the tests, they run against the debug builds we create for testing.
I can fix that somehow, or we can just assert on the size of the debug builds (80kb is still very reasonable).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BurntSushi I resolved the test failures by moving the tests from |
Thanks for the reviews! |
Currently, our trampoline is used to convert `<command> [args]` to `python <command> [args]` for script entrypoints installed into virtual environments. For #8458, it'd be nice to convert a shim `python3.12 [args]` to `python [args]`. Here, we modify the trampolines to support this use-case. The only change we really need here is to avoid injecting `<command>` into the child process. We change the "magic number" at the end of the trampoline executables from `UVUV` to `UVSC` and `UVPY` which define "script" and "python" variants to the trampoline. We then omit the `<command>` injection in the latter case. We also omit writing the zip script payload. To support construction of the new variant, a new `uv-trampoline-builder` crate is introduced — this avoids requirements on `uv-install-wheel` in future work. I also use `uv-trampoline-builder` to consolidate some of the test setup for `uv-trampoline`. There should be no backwards compatibility concerns, since trampolines are fully self-referential. I rebased to fix the commits at the end, as this took many iterations to get working via CI. This should roughly be reviewable by commit if you prefer.
Currently, our trampoline is used to convert
<command> [args]
topython <command> [args]
for script entrypoints installed into virtual environments. For #8458, it'd be nice to convert a shimpython3.12 [args]
topython [args]
. Here, we modify the trampolines to support this use-case.The only change we really need here is to avoid injecting
<command>
into the child process. We change the "magic number" at the end of the trampoline executables fromUVUV
toUVSC
andUVPY
which define "script" and "python" variants to the trampoline. We then omit the<command>
injection in the latter case. We also omit writing the zip script payload when constructing the trampoline.To support construction of the new variant, a new
uv-trampoline-builder
crate is introduced — this avoids requirements onuv-install-wheel
in future work. I also useuv-trampoline-builder
to consolidate some of the test setup foruv-trampoline
.There should be no backwards compatibility concerns, since trampolines are fully self-referential.
I rebased to fix the commits at the end, as this took many iterations to get working via CI. This should roughly be reviewable by commit if you prefer.