feat: re-enable std in uv-trampoline (#4722)

## Summary

Partially closes #1917

This PR picks up on some of the great work from #1864 and opted to keep
`panic_immediate_abort` (for size reasons). I split the PR in different
isolated commits in case we want to separate/cherry-pick them out.

1. The first commit ports mostly all std changes from that PR into this
PR. Binary sizes stayed the same ~16kb.
2. The second commit migrates our existing usage of windows-sys to
windows for a safer ffi calls with Results!. It also changes all large
unsafe blocks to be isolated to the actual unsafe calls, and switches
some areas to use std such as getenv port ( which seemed buggy! ) from
launcher.c. In addition, this also adds more error checking in order to
match some missing assertions from distlib's launcher.c. Note, due to
the additional .text data, the binary sizes increased to ~20.5kb, but we
can cut back on some of the added error msgs as needed.
3. The third commit switches to using xwin for building on all 3
supported trampoline targets for sanity, and adds a CI bloat check for
core::fmt and panic as a precaution. Sadly, this will invalidate the
xwin cache on the first run.

## Test Plan

Most changes were tested on a couple of local GUI apps and console apps,
also tested some of the error states manually by using SetLastError at
different points in the code and/or passing in invalid handles.

I'm not sure how far we can get with migrating some of the other calls
without increasing binary size substantially. An initial attempt at
using std::path didn't seem so bad size wise when I tried it (~1k). On
other cases, such as std::process::exit added ~10k to the total binary
size.

---------

Co-authored-by: konstin <konstin@mailbox.org>
This commit is contained in:
samypr100
2024-07-06 16:38:45 -04:00
committed by GitHub
parent 6c8ce1d013
commit eee90a340c
14 changed files with 482 additions and 494 deletions
+44 -36
View File
@@ -88,7 +88,7 @@ jobs:
uses: actions/cache@v4
with:
path: "${{ github.workspace}}/.xwin"
key: cargo-xwin
key: cargo-xwin-x86_64
- name: Load rust cache
uses: Swatinem/rust-cache@v2
with:
@@ -274,57 +274,65 @@ jobs:
windows-trampoline:
needs: determine_changes
if: ${{ github.repository == 'astral-sh/uv' && (needs.determine_changes.outputs.code == 'true' || github.ref == 'refs/heads/main') }}
runs-on: windows-latest
name: "check windows trampoline"
runs-on: ubuntu-latest
name: "check windows trampoline | ${{ matrix.target-arch }}"
strategy:
fail-fast: false
matrix:
target-arch: ["x86_64", "i686", "aarch64"]
steps:
- name: Create Dev Drive using ReFS
run: |
$Volume = New-VHD -Path C:/uv_dev_drive.vhdx -SizeBytes 10GB |
Mount-VHD -Passthru |
Initialize-Disk -Passthru |
New-Partition -AssignDriveLetter -UseMaximumSize |
Format-Volume -FileSystem ReFS -Confirm:$false -Force
Write-Output $Volume
Write-Output "DEV_DRIVE=$($Volume.DriveLetter):" >> $env:GITHUB_ENV
- uses: actions/checkout@v4
# actions/checkout does not let us clone into anywhere outside ${{ github.workspace }}, so we have to copy the clone...
- name: Copy Git Repo to Dev Drive
run: |
Copy-Item -Path "${{ github.workspace }}" -Destination "${{ env.DEV_DRIVE }}/uv" -Recurse
- name: "Install Rust toolchain"
working-directory: ${{ env.DEV_DRIVE }}/uv/crates/uv-trampoline
env:
CARGO_HOME: ${{ env.DEV_DRIVE }}/.cargo
RUSTUP_HOME: ${{ env.DEV_DRIVE }}/.rustup
working-directory: ${{ github.workspace }}/crates/uv-trampoline
run: |
rustup target add x86_64-pc-windows-msvc
rustup component add clippy rust-src --toolchain nightly-2024-05-27-x86_64-pc-windows-msvc
rustup target add ${{ matrix.target-arch }}-pc-windows-msvc
rustup component add rust-src --target ${{ matrix.target-arch }}-pc-windows-msvc
- name: Load xwin cache
uses: actions/cache@v4
with:
path: "${{ github.workspace }}/.xwin"
key: cargo-xwin-${{ matrix.target-arch }}
- uses: rui314/setup-mold@v1
- uses: Swatinem/rust-cache@v2
with:
workspaces: ${{ env.DEV_DRIVE }}/uv/crates/uv-trampoline
env:
CARGO_HOME: ${{ env.DEV_DRIVE }}/.cargo
RUSTUP_HOME: ${{ env.DEV_DRIVE }}/.rustup
workspaces: ${{ github.workspace }}/crates/uv-trampoline
- name: "Install cargo-xwin and cargo-bloat"
uses: taiki-e/install-action@v2
with:
tool: cargo-xwin,cargo-bloat
- name: "Install xwin dependencies"
run: sudo apt-get install --no-install-recommends -y lld llvm clang cmake ninja-build
- name: "Clippy"
working-directory: ${{ env.DEV_DRIVE }}/uv/crates/uv-trampoline
working-directory: ${{ github.workspace }}/crates/uv-trampoline
if: matrix.target-arch == 'x86_64'
run: cargo xwin clippy --all-features --locked --target x86_64-pc-windows-msvc -- -D warnings
env:
CARGO_HOME: ${{ env.DEV_DRIVE }}/.cargo
RUSTUP_HOME: ${{ env.DEV_DRIVE }}/.rustup
run: cargo clippy --all-features --locked --target x86_64-pc-windows-msvc -- -D warnings
XWIN_ARCH: "x86_64"
XWIN_CACHE_DIR: "${{ github.workspace }}/.xwin"
- name: "Bloat Check"
working-directory: ${{ github.workspace }}/crates/uv-trampoline
if: matrix.target-arch == 'x86_64'
run: |
cargo xwin bloat --release --target x86_64-pc-windows-msvc | \
grep -q -E 'core::fmt|std::panicking|std::backtrace_rs' && exit 1 || exit 0
env:
XWIN_ARCH: "x86_64"
XWIN_CACHE_DIR: "${{ github.workspace }}/.xwin"
- name: "Build"
working-directory: ${{ env.DEV_DRIVE }}/uv/crates/uv-trampoline
working-directory: ${{ github.workspace }}/crates/uv-trampoline
run: cargo xwin build --release --target ${{ matrix.target-arch }}-pc-windows-msvc
env:
CARGO_HOME: ${{ env.DEV_DRIVE }}/.cargo
RUSTUP_HOME: ${{ env.DEV_DRIVE }}/.rustup
run: cargo build --release --target x86_64-pc-windows-msvc
XWIN_ARCH: "${{ matrix.target-arch == 'i686' && 'x86' || matrix.target-arch }}"
XWIN_CACHE_DIR: "${{ github.workspace }}/.xwin"
typos:
runs-on: ubuntu-latest