Support x86 windows (#3873)

Add trampolines for x86 windows.

Closes https://github.com/astral-sh/uv/issues/3660.
This commit is contained in:
konsti 2024-05-28 18:07:39 +02:00 committed by GitHub
parent cedd18e4c6
commit f92447772e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 32 additions and 7 deletions

View file

@ -266,7 +266,7 @@ jobs:
RUSTUP_HOME: ${{ env.DEV_DRIVE }}/.rustup
run: |
rustup target add x86_64-pc-windows-msvc
rustup component add clippy rust-src --toolchain nightly-2024-03-19-x86_64-pc-windows-msvc
rustup component add clippy rust-src --toolchain nightly-2024-05-27-x86_64-pc-windows-msvc
- uses: rui314/setup-mold@v1

View file

@ -70,7 +70,9 @@ pub enum Error {
RecordCsv(#[from] csv::Error),
#[error("Broken virtualenv: {0}")]
BrokenVenv(String),
#[error("Unable to create Windows launcher for {0} (only x64_64 is supported)")]
#[error(
"Unable to create Windows launcher for: {0} (only x86_64, x86, and arm64 are supported)"
)]
UnsupportedWindowsArch(&'static str),
#[error("Unable to create Windows launcher on non-Windows platform")]
NotWindows,

View file

@ -23,6 +23,14 @@ use crate::{Error, Layout};
const LAUNCHER_MAGIC_NUMBER: [u8; 4] = [b'U', b'V', b'U', b'V'];
#[cfg(all(windows, target_arch = "x86"))]
const LAUNCHER_I686_GUI: &[u8] =
include_bytes!("../../uv-trampoline/trampolines/uv-trampoline-i686-gui.exe");
#[cfg(all(windows, target_arch = "x86"))]
const LAUNCHER_I686_CONSOLE: &[u8] =
include_bytes!("../../uv-trampoline/trampolines/uv-trampoline-i686-console.exe");
#[cfg(all(windows, target_arch = "x86_64"))]
const LAUNCHER_X86_64_GUI: &[u8] =
include_bytes!("../../uv-trampoline/trampolines/uv-trampoline-x86_64-gui.exe");
@ -161,6 +169,14 @@ pub(crate) fn windows_script_launcher(
}
let launcher_bin: &[u8] = match env::consts::ARCH {
#[cfg(all(windows, target_arch = "x86"))]
"x86" => {
if is_gui {
LAUNCHER_I686_GUI
} else {
LAUNCHER_I686_CONSOLE
}
}
#[cfg(all(windows, target_arch = "x86_64"))]
"x86_64" => {
if is_gui {

View file

@ -11,6 +11,7 @@ package manager to install LLD and add the `rustup` targets:
```shell
sudo apt install llvm clang lld
rustup target add i686-pc-windows-msvc
rustup target add x86_64-pc-windows-msvc
rustup target add aarch64-pc-windows-msvc
```
@ -18,8 +19,9 @@ rustup target add aarch64-pc-windows-msvc
Then, build the trampolines for both supported architectures:
```shell
cargo +nightly-2024-03-19 xwin build --release --target x86_64-pc-windows-msvc
cargo +nightly-2024-03-19 xwin build --release --target aarch64-pc-windows-msvc
cargo +nightly-2024-05-27 xwin build --xwin-arch x86 --release --target i686-pc-windows-msvc
cargo +nightly-2024-05-27 xwin build --release --target x86_64-pc-windows-msvc
cargo +nightly-2024-05-27 xwin build --release --target aarch64-pc-windows-msvc
```
### Cross-compiling from macOS
@ -29,6 +31,7 @@ package manager to install LLVM and add the `rustup` targets:
```shell
brew install llvm
rustup target add i686-pc-windows-msvc
rustup target add x86_64-pc-windows-msvc
rustup target add aarch64-pc-windows-msvc
```
@ -36,8 +39,9 @@ rustup target add aarch64-pc-windows-msvc
Then, build the trampolines for both supported architectures:
```shell
cargo +nightly-2024-03-19 xwin build --release --target x86_64-pc-windows-msvc
cargo +nightly-2024-03-19 xwin build --release --target aarch64-pc-windows-msvc
cargo +nightly-2024-05-27 xwin build --release --target i686-pc-windows-msvc
cargo +nightly-2024-05-27 xwin build --release --target x86_64-pc-windows-msvc
cargo +nightly-2024-05-27 xwin build --release --target aarch64-pc-windows-msvc
```
### Updating the prebuilt executables
@ -49,6 +53,8 @@ cp target/aarch64-pc-windows-msvc/release/uv-trampoline-console.exe trampolines/
cp target/aarch64-pc-windows-msvc/release/uv-trampoline-gui.exe trampolines/uv-trampoline-aarch64-gui.exe
cp target/x86_64-pc-windows-msvc/release/uv-trampoline-console.exe trampolines/uv-trampoline-x86_64-console.exe
cp target/x86_64-pc-windows-msvc/release/uv-trampoline-gui.exe trampolines/uv-trampoline-x86_64-gui.exe
cp target/i686-pc-windows-msvc/release/uv-trampoline-console.exe trampolines/uv-trampoline-i686-console.exe
cp target/i686-pc-windows-msvc/release/uv-trampoline-gui.exe trampolines/uv-trampoline-i686-gui.exe
```
### Testing the trampolines
@ -167,6 +173,7 @@ might not realize that, and still emit references to the unwinding helper
exist.
```
cargo build --release --target i686-pc-windows-msvc
cargo build --release --target x86_64-pc-windows-msvc
cargo build --release --target aarch64-pc-windows-msvc
```

View file

@ -1,2 +1,2 @@
[toolchain]
channel = "nightly-2024-03-19"
channel = "nightly-2024-05-27"

Binary file not shown.