uv icon indicating copy to clipboard operation
uv copied to clipboard

Use `std` for `uv-trampoline`

Open MichaReiser opened this issue 1 year ago • 0 comments

The uv-trampoline is used by uv to generate exe binaries for python entrypoint scripts (launcher scripts).

Our current implementation is a fork of posy's trampoline and one of the author's primary goal is to generate binaries with a minimal size. They achieve that by not using Rust's std and only use win32 APIs. Our current launcher has a size of a little less than 20KB.

We agree that it's important that the launcher is small because we include it twice into the uv binary and append it to every launcher script. However, not using std means that we must use unsafe win32 API almost exclusively, which requires extra care and comes at the risk of UB and potential security vulnerabilities.

Only using non_std is also no guarantee for a small binary. It requires extra care that no implicit panics "bloat" the binary size.

That's why we think it's worth exploring using std for the trampoline. I created https://github.com/astral-sh/uv/pull/1864 and documented my initial findings. It seems that using std with panic=abort increases the binary size to roughly 90KB, which seems acceptable. It's also possible that the size can be reduced further. I haven't spent a lot of time trying.

The goal is to explore using std for uv-trampoline while keeping the binary size minimal (by e.g. avoiding calling into panic handlers etc).

MichaReiser avatar Feb 23 '24 15:02 MichaReiser