From c7e9cb2d88a97c705f11bcafb3a7001323c54c03 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 13 Jun 2025 14:33:43 +0700 Subject: [PATCH] Use Windows ARM64 cargo/node binaries during build We can't provide ARM64 wheels to users yet due to #4079, but we can at least speed up the build. The rustls -> native-tls change on Windows is because ring requires clang to compile for ARM64, and I figured it's best to keep our Windows deps consistent. We already built the wheels with native-tls. --- build/configure/src/platform.rs | 12 +++++++----- build/configure/src/pylib.rs | 2 +- build/configure/src/python.rs | 1 + build/ninja_gen/Cargo.toml | 7 ++++++- build/ninja_gen/src/archives.rs | 24 ++++++++++++------------ build/ninja_gen/src/bin/update_uv.rs | 3 ++- build/ninja_gen/src/node.rs | 4 ++++ build/ninja_gen/src/protobuf.rs | 4 ++-- build/ninja_gen/src/python.rs | 6 ++++++ build/runner/Cargo.toml | 7 ++++++- docs/windows.md | 7 ++++++- 11 files changed, 53 insertions(+), 24 deletions(-) diff --git a/build/configure/src/platform.rs b/build/configure/src/platform.rs index 4aec36e65..6afc4aac7 100644 --- a/build/configure/src/platform.rs +++ b/build/configure/src/platform.rs @@ -5,16 +5,18 @@ use std::env; use ninja_gen::archives::Platform; -/// Usually None to use the host architecture; can be overriden by setting -/// MAC_X86 to build for x86_64 on Apple Silicon +/// Please see [`overriden_python_target_platform()`] for details. pub fn overriden_rust_target_triple() -> Option<&'static str> { overriden_python_target_platform().map(|p| p.as_rust_triple()) } -/// Usually None to use the host architecture; can be overriden by setting -/// MAC_X86 to build for x86_64 on Apple Silicon +/// Usually None to use the host architecture, except on Windows which +/// always uses x86_64. +/// On a Mac, set MAC_X86 to build for x86_64 on Apple Silicon. pub fn overriden_python_target_platform() -> Option { - if env::var("MAC_X86").is_ok() { + if cfg!(target_os = "windows") { + Some(Platform::WindowsX64) + } else if env::var("MAC_X86").is_ok() { Some(Platform::MacX64) } else { None diff --git a/build/configure/src/pylib.rs b/build/configure/src/pylib.rs index d8a75d3b8..8301f4bba 100644 --- a/build/configure/src/pylib.rs +++ b/build/configure/src/pylib.rs @@ -50,7 +50,7 @@ pub fn build_pylib(build: &mut Build) -> Result<()> { output: &format!( "pylib/anki/_rsbridge.{}", match build.host_platform { - Platform::WindowsX64 => "pyd", + Platform::WindowsX64 | Platform::WindowsArm => "pyd", _ => "so", } ), diff --git a/build/configure/src/python.rs b/build/configure/src/python.rs index 45f9e8967..e69304807 100644 --- a/build/configure/src/python.rs +++ b/build/configure/src/python.rs @@ -118,6 +118,7 @@ impl BuildAction for BuildWheel { Platform::MacX64 => "macosx_12_0_x86_64", Platform::MacArm => "macosx_12_0_arm64", Platform::WindowsX64 => "win_amd64", + Platform::WindowsArm => "win_arm64", }; format!("cp39-abi3-{platform_tag}") } else { diff --git a/build/ninja_gen/Cargo.toml b/build/ninja_gen/Cargo.toml index 65a0c8926..5b050b4b7 100644 --- a/build/ninja_gen/Cargo.toml +++ b/build/ninja_gen/Cargo.toml @@ -17,11 +17,16 @@ itertools.workspace = true maplit.workspace = true num_cpus.workspace = true regex.workspace = true -reqwest = { workspace = true, features = ["blocking", "json", "rustls-tls"] } serde_json.workspace = true walkdir.workspace = true which.workspace = true +[target.'cfg(windows)'.dependencies] +reqwest = { workspace = true, features = ["blocking", "json", "native-tls"] } + +[target.'cfg(not(windows))'.dependencies] +reqwest = { workspace = true, features = ["blocking", "json", "rustls-tls"] } + [[bin]] name = "update_uv" path = "src/bin/update_uv.rs" diff --git a/build/ninja_gen/src/archives.rs b/build/ninja_gen/src/archives.rs index 9dd784bdd..3f87d3ff5 100644 --- a/build/ninja_gen/src/archives.rs +++ b/build/ninja_gen/src/archives.rs @@ -26,22 +26,21 @@ pub enum Platform { MacX64, MacArm, WindowsX64, + WindowsArm, } impl Platform { pub fn current() -> Self { - if cfg!(windows) { - Self::WindowsX64 - } else { - let os = std::env::consts::OS; - let arch = std::env::consts::ARCH; - match (os, arch) { - ("linux", "x86_64") => Self::LinuxX64, - ("linux", "aarch64") => Self::LinuxArm, - ("macos", "x86_64") => Self::MacX64, - ("macos", "aarch64") => Self::MacArm, - _ => panic!("unsupported os/arch {os} {arch} - PR welcome!"), - } + let os = std::env::consts::OS; + let arch = std::env::consts::ARCH; + match (os, arch) { + ("linux", "x86_64") => Self::LinuxX64, + ("linux", "aarch64") => Self::LinuxArm, + ("macos", "x86_64") => Self::MacX64, + ("macos", "aarch64") => Self::MacArm, + ("windows", "x86_64") => Self::WindowsX64, + ("windows", "aarch64") => Self::WindowsArm, + _ => panic!("unsupported os/arch {os} {arch} - PR welcome!"), } } @@ -62,6 +61,7 @@ impl Platform { Platform::MacX64 => "x86_64-apple-darwin", Platform::MacArm => "aarch64-apple-darwin", Platform::WindowsX64 => "x86_64-pc-windows-msvc", + Platform::WindowsArm => "aarch64-pc-windows-msvc", } } } diff --git a/build/ninja_gen/src/bin/update_uv.rs b/build/ninja_gen/src/bin/update_uv.rs index 4954e4653..39cf87668 100644 --- a/build/ninja_gen/src/bin/update_uv.rs +++ b/build/ninja_gen/src/bin/update_uv.rs @@ -31,6 +31,7 @@ fn fetch_uv_release_info() -> Result> { ("MacX64", "x86_64-apple-darwin"), ("MacArm", "aarch64-apple-darwin"), ("WindowsX64", "x86_64-pc-windows-msvc"), + ("WindowsArm", "aarch64-pc-windows-msvc"), ]; let mut match_blocks = Vec::new(); @@ -126,7 +127,7 @@ mod tests { let content = fs::read_to_string("src/python.rs").unwrap(); let original_lines = content.lines().count(); - const EXPECTED_LINES_REMOVED: usize = 32; + const EXPECTED_LINES_REMOVED: usize = 38; let updated = update_uv_text(&content, "").unwrap(); let updated_lines = updated.lines().count(); diff --git a/build/ninja_gen/src/node.rs b/build/ninja_gen/src/node.rs index dac056c10..10b3e6184 100644 --- a/build/ninja_gen/src/node.rs +++ b/build/ninja_gen/src/node.rs @@ -38,6 +38,10 @@ pub fn node_archive(platform: Platform) -> OnlineArchive { url: "https://nodejs.org/dist/v20.11.0/node-v20.11.0-win-x64.zip", sha256: "893115cd92ad27bf178802f15247115e93c0ef0c753b93dca96439240d64feb5", }, + Platform::WindowsArm => OnlineArchive { + url: "https://nodejs.org/dist/v20.11.0/node-v20.11.0-win-arm64.zip", + sha256: "89c1f7034dcd6ff5c17f2af61232a96162a1902f862078347dcf274a938b6142", + }, } } diff --git a/build/ninja_gen/src/protobuf.rs b/build/ninja_gen/src/protobuf.rs index 2643c2ab1..f07087579 100644 --- a/build/ninja_gen/src/protobuf.rs +++ b/build/ninja_gen/src/protobuf.rs @@ -37,7 +37,7 @@ pub fn protoc_archive(platform: Platform) -> OnlineArchive { sha256: "e3324d3bc2e9bc967a0bec2472e0ec73b26f952c7c87f2403197414f780c3c6c", } } - Platform::WindowsX64 => { + Platform::WindowsX64 | Platform::WindowsArm => { OnlineArchive { url: "https://github.com/protocolbuffers/protobuf/releases/download/v21.8/protoc-21.8-win64.zip", sha256: "3657053024faa439ff5f8c1dd2ee06bac0f9b9a3d660e99944f015a7451e87ec", @@ -67,7 +67,7 @@ fn clang_format_archive(platform: Platform) -> OnlineArchive { sha256: "238be68d9478163a945754f06a213483473044f5a004c4125d3d9d8d3556466e", } } - Platform::WindowsX64 => { + Platform::WindowsX64 | Platform::WindowsArm=> { OnlineArchive { url: "https://github.com/ankitects/clang-format-binaries/releases/download/anki-2021-01-09/clang-format_windows_x86_64.zip", sha256: "7d9f6915e3f0fb72407830f0fc37141308d2e6915daba72987a52f309fbeaccc", diff --git a/build/ninja_gen/src/python.rs b/build/ninja_gen/src/python.rs index f42c3112f..aea77a22c 100644 --- a/build/ninja_gen/src/python.rs +++ b/build/ninja_gen/src/python.rs @@ -54,6 +54,12 @@ pub fn uv_archive(platform: Platform) -> OnlineArchive { url: "https://github.com/astral-sh/uv/releases/download/0.7.13/uv-x86_64-pc-windows-msvc.zip", sha256: "e199b10bef1a7cc540014483e7f60f825a174988f41020e9d2a6b01bd60f0669", } + }, + Platform::WindowsArm => { + OnlineArchive { + url: "https://github.com/astral-sh/uv/releases/download/0.7.13/uv-aarch64-pc-windows-msvc.zip", + sha256: "bb40708ad549ad6a12209cb139dd751bf0ede41deb679ce7513ce197bd9ef234", + } } } } diff --git a/build/runner/Cargo.toml b/build/runner/Cargo.toml index 54722f01d..1fffe7050 100644 --- a/build/runner/Cargo.toml +++ b/build/runner/Cargo.toml @@ -15,7 +15,6 @@ camino.workspace = true clap.workspace = true flate2.workspace = true junction.workspace = true -reqwest = { workspace = true, features = ["rustls-tls", "rustls-tls-native-roots"] } sha2.workspace = true tar.workspace = true termcolor.workspace = true @@ -24,3 +23,9 @@ which.workspace = true xz2.workspace = true zip.workspace = true zstd.workspace = true + +[target.'cfg(windows)'.dependencies] +reqwest = { workspace = true, features = ["native-tls"] } + +[target.'cfg(not(windows))'.dependencies] +reqwest = { workspace = true, features = ["rustls-tls", "rustls-tls-native-roots"] } diff --git a/docs/windows.md b/docs/windows.md index aae9f6869..12f4e7c39 100644 --- a/docs/windows.md +++ b/docs/windows.md @@ -9,7 +9,12 @@ You must be running 64 bit Windows 10, version 1703 or newer. **Rustup**: As mentioned in development.md, rustup must be installed. If you're on -ARM Windows, you must set the default target to x86_64-pc-windows-msvc. +ARM Windows and install the ARM64 version of rust-up, from this project folder, +run + +``` +rustup target add x86_64-pc-windows-msvc +``` **Visual Studio**: