diff --git a/crates/install-wheel-rs/src/wheel.rs b/crates/install-wheel-rs/src/wheel.rs index db2670694..3aa462fa7 100644 --- a/crates/install-wheel-rs/src/wheel.rs +++ b/crates/install-wheel-rs/src/wheel.rs @@ -33,19 +33,21 @@ use crate::{find_dist_info, Error}; /// `#!/usr/bin/env python` pub const SHEBANG_PYTHON: &str = "#!/usr/bin/env python"; -#[cfg(windows)] +#[cfg(all(windows, target_arch = "x86_64"))] const LAUNCHER_X86_64_GUI: &[u8] = - include_bytes!("../../puffin-trampoline/trampolines/puffin-trampoline-gui.exe"); + include_bytes!("../../puffin-trampoline/trampolines/puffin-trampoline-x86_64-gui.exe"); -#[cfg(windows)] +#[cfg(all(windows, target_arch = "x86_64"))] const LAUNCHER_X86_64_CONSOLE: &[u8] = - include_bytes!("../../puffin-trampoline/trampolines/puffin-trampoline-console.exe"); + include_bytes!("../../puffin-trampoline/trampolines/puffin-trampoline-x86_64-console.exe"); -#[cfg(not(windows))] -const LAUNCHER_X86_64_GUI: &[u8] = &[]; +#[cfg(all(windows, target_arch = "aarch64"))] +const LAUNCHER_AARCH64_GUI: &[u8] = + include_bytes!("../../puffin-trampoline/trampolines/puffin-trampoline-aarch64-gui.exe"); -#[cfg(not(windows))] -const LAUNCHER_X86_64_CONSOLE: &[u8] = &[]; +#[cfg(all(windows, target_arch = "aarch64"))] +const LAUNCHER_AARCH64_CONSOLE: &[u8] = + include_bytes!("../../puffin-trampoline/trampolines/puffin-trampoline-aarch64-console.exe"); /// Wrapper script template function /// @@ -293,6 +295,7 @@ fn get_shebang(location: &InstallLocation>) -> String { /// to start the embedded script. /// /// +#[allow(unused_variables)] pub(crate) fn windows_script_launcher( launcher_python_script: &str, is_gui: bool, @@ -303,7 +306,8 @@ pub(crate) fn windows_script_launcher( return Err(Error::NotWindows); } - let launcher_bin = match env::consts::ARCH { + let launcher_bin: &[u8] = match env::consts::ARCH { + #[cfg(all(windows, target_arch = "x86_64"))] "x86_64" => { if is_gui { LAUNCHER_X86_64_GUI @@ -311,9 +315,20 @@ pub(crate) fn windows_script_launcher( LAUNCHER_X86_64_CONSOLE } } + #[cfg(all(windows, target_arch = "aarch64"))] + "aarch64" => { + if is_gui { + LAUNCHER_AARCH64_GUI + } else { + LAUNCHER_AARCH64_CONSOLE + } + } + #[cfg(windows)] arch => { return Err(Error::UnsupportedWindowsArch(arch)); } + #[cfg(not(windows))] + arch => &[], }; let mut payload: Vec = Vec::new(); @@ -1163,10 +1178,7 @@ mod test { use indoc::{formatdoc, indoc}; - use super::{ - parse_key_value_file, parse_wheel_version, read_record_file, relative_to, Script, - LAUNCHER_X86_64_CONSOLE, LAUNCHER_X86_64_GUI, - }; + use super::{parse_key_value_file, parse_wheel_version, read_record_file, relative_to, Script}; #[test] fn test_parse_key_value_file() { @@ -1294,17 +1306,34 @@ mod test { } #[test] + #[cfg(all(windows, target_arch = "x86_64"))] fn test_launchers_are_small() { // At time of writing, they are 15872 bytes. assert!( - LAUNCHER_X86_64_GUI.len() < 20 * 1024, + super::LAUNCHER_X86_64_GUI.len() < 20 * 1024, "GUI launcher: {}", - LAUNCHER_X86_64_GUI.len() + super::LAUNCHER_X86_64_GUI.len() ); assert!( - LAUNCHER_X86_64_CONSOLE.len() < 20 * 1024, + super::LAUNCHER_X86_64_CONSOLE.len() < 20 * 1024, "CLI launcher: {}", - LAUNCHER_X86_64_CONSOLE.len() + super::LAUNCHER_X86_64_CONSOLE.len() + ); + } + + #[test] + #[cfg(all(windows, target_arch = "aarch64"))] + fn test_launchers_are_small() { + // At time of writing, they are 14848 and 14336 bytes. + assert!( + super::LAUNCHER_AArch64_GUI.len() < 20 * 1024, + "GUI launcher: {}", + super::LAUNCHER_AArch64_GUI.len() + ); + assert!( + super::LAUNCHER_AArch64_CONSOLE.len() < 20 * 1024, + "CLI launcher: {}", + super::LAUNCHER_AArch64_CONSOLE.len() ); } } diff --git a/crates/puffin-trampoline/README.md b/crates/puffin-trampoline/README.md index 523924357..1abaac693 100644 --- a/crates/puffin-trampoline/README.md +++ b/crates/puffin-trampoline/README.md @@ -112,3 +112,19 @@ Two approaches that are reasonably likely to work: Hopefully in the future as `#![no_std]` develops, this will get smoother. Also, sometimes it helps to fiddle with optimization levels. + +# Cross compiling from linux + +Install [cargo xwin](https://github.com/rust-cross/cargo-xwin). Use your +package manager to install LLD and add the rustup targets: + +```shell +sudo apt install llvm clang lld +rustup target add x86_64-pc-windows-msvc +rustup target add aarch64-pc-windows-msvc +``` + +```shell +cargo +nightly xwin build --release -Z build-std=core,panic_abort,alloc -Z build-std-features=compiler-builtins-mem --target x86_64-pc-windows-msvc +cargo +nightly xwin build --release -Z build-std=core,panic_abort,alloc -Z build-std-features=compiler-builtins-mem --target aarch64-pc-windows-msvc +``` diff --git a/crates/puffin-trampoline/trampolines/puffin-trampoline-aarch64-console.exe b/crates/puffin-trampoline/trampolines/puffin-trampoline-aarch64-console.exe new file mode 100755 index 000000000..9f1d81b6e Binary files /dev/null and b/crates/puffin-trampoline/trampolines/puffin-trampoline-aarch64-console.exe differ diff --git a/crates/puffin-trampoline/trampolines/puffin-trampoline-aarch64-gui.exe b/crates/puffin-trampoline/trampolines/puffin-trampoline-aarch64-gui.exe new file mode 100755 index 000000000..05fb2d40e Binary files /dev/null and b/crates/puffin-trampoline/trampolines/puffin-trampoline-aarch64-gui.exe differ diff --git a/crates/puffin-trampoline/trampolines/puffin-trampoline-console.exe b/crates/puffin-trampoline/trampolines/puffin-trampoline-x86_64-console.exe similarity index 100% rename from crates/puffin-trampoline/trampolines/puffin-trampoline-console.exe rename to crates/puffin-trampoline/trampolines/puffin-trampoline-x86_64-console.exe diff --git a/crates/puffin-trampoline/trampolines/puffin-trampoline-gui.exe b/crates/puffin-trampoline/trampolines/puffin-trampoline-x86_64-gui.exe similarity index 100% rename from crates/puffin-trampoline/trampolines/puffin-trampoline-gui.exe rename to crates/puffin-trampoline/trampolines/puffin-trampoline-x86_64-gui.exe