Skip to content

Commit

Permalink
feat: more rust in trampoline (astral-sh#5750)
Browse files Browse the repository at this point in the history
## Summary

This is an experimental PR to replace more unsafe calls with more rust
while still trying to keep the binary size small enough. These changes
roughly increase the size of the trampolines to about 40kb~. This is a
alternate PR to astral-sh#5751.

The primary changes here include
* Switch to use rust path components for ease of path management
* Leverage `std::process::exit` for process exit and cleanup
* Use `std::io::Error::last_os_error` for IO Errors to remove
`FormatMessage` complexity
* Use `std::env::current_exe` to get the current executable instead of
`GetModuleFileNameA`

## Test Plan

Added one more existing test case to trampoline tests.
Still need to verify dunce::canonicalize is desired or not on
find_python_exe.

---------

Co-authored-by: konstin <[email protected]>
  • Loading branch information
samypr100 and konstin authored Aug 7, 2024
1 parent d0b16f9 commit 2cd63f0
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 210 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ jobs:
if: matrix.target-arch == 'x86_64'
run: |
cargo xwin bloat --release --target x86_64-pc-windows-msvc | \
grep -v -i -E 'core::fmt::write|core::fmt::getcount' | \
grep -q -E 'core::fmt|std::panicking|std::backtrace_rs' && exit 1 || exit 0
env:
XWIN_ARCH: "x86_64"
Expand Down
18 changes: 9 additions & 9 deletions crates/install-wheel-rs/src/wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,14 +1018,14 @@ mod test {
#[test]
#[cfg(all(windows, target_arch = "x86"))]
fn test_launchers_are_small() {
// At time of writing, they are 17408 bytes.
// At time of writing, they are 45kb~ bytes.
assert!(
super::LAUNCHER_I686_GUI.len() < 25 * 1024,
super::LAUNCHER_I686_GUI.len() < 45 * 1024,
"GUI launcher: {}",
super::LAUNCHER_I686_GUI.len()
);
assert!(
super::LAUNCHER_I686_CONSOLE.len() < 25 * 1024,
super::LAUNCHER_I686_CONSOLE.len() < 45 * 1024,
"CLI launcher: {}",
super::LAUNCHER_I686_CONSOLE.len()
);
Expand All @@ -1034,14 +1034,14 @@ mod test {
#[test]
#[cfg(all(windows, target_arch = "x86_64"))]
fn test_launchers_are_small() {
// At time of writing, they are 21504 and 20480 bytes.
// At time of writing, they are 45kb~ bytes.
assert!(
super::LAUNCHER_X86_64_GUI.len() < 25 * 1024,
super::LAUNCHER_X86_64_GUI.len() < 45 * 1024,
"GUI launcher: {}",
super::LAUNCHER_X86_64_GUI.len()
);
assert!(
super::LAUNCHER_X86_64_CONSOLE.len() < 25 * 1024,
super::LAUNCHER_X86_64_CONSOLE.len() < 45 * 1024,
"CLI launcher: {}",
super::LAUNCHER_X86_64_CONSOLE.len()
);
Expand All @@ -1050,14 +1050,14 @@ mod test {
#[test]
#[cfg(all(windows, target_arch = "aarch64"))]
fn test_launchers_are_small() {
// At time of writing, they are 20480 and 19456 bytes.
// At time of writing, they are 45kb~ bytes.
assert!(
super::LAUNCHER_AARCH64_GUI.len() < 25 * 1024,
super::LAUNCHER_AARCH64_GUI.len() < 45 * 1024,
"GUI launcher: {}",
super::LAUNCHER_AARCH64_GUI.len()
);
assert!(
super::LAUNCHER_AARCH64_CONSOLE.len() < 25 * 1024,
super::LAUNCHER_AARCH64_CONSOLE.len() < 45 * 1024,
"CLI launcher: {}",
super::LAUNCHER_AARCH64_CONSOLE.len()
);
Expand Down
1 change: 1 addition & 0 deletions crates/uv-trampoline/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions crates/uv-trampoline/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,15 @@ windows = { version = "0.58.0", features = [
"std",
"Win32_Foundation",
"Win32_Security",
"Win32_Storage_FileSystem",
"Win32_System_Console",
"Win32_System_Diagnostics_Debug",
"Win32_System_Environment",
"Win32_System_IO",
"Win32_System_JobObjects",
"Win32_System_JobObjects",
"Win32_System_LibraryLoader",
"Win32_System_Memory",
"Win32_System_Threading",
"Win32_System_WindowsProgramming",
"Win32_UI_WindowsAndMessaging",
] }
ufmt-write = "0.1.0"
ufmt = { version = "0.2.0", features = ["std"] }
dunce = { version = "1.0.4" }

[build-dependencies]
embed-manifest = "1.4.0"
Expand Down
Loading

0 comments on commit 2cd63f0

Please sign in to comment.