fix: select native ARM64 tools before Windows x64 fallback

Цей коміт міститься в:
l0ng-ai committed 2026-10-31 10:07:46 +08:00
1 джерело d91f851eeb
коміт 76f87ada84
4 files changed
+59 -7

No files matched your search

+18
Переглянути файл
@@ -211,6 +211,12 @@ fn choose<'a>(entry: &'a Entry, platform: Platform, on_path: &dyn Fn(&str) -> bo
if let Some(b) = d.binary.get(&platform_key(platform)) {
return Some(Choice::Binary(b));
}
if platform.os == Os::Windows
&& platform.arch == Arch::Arm64
&& let Some(b) = d.binary.get("windows-x86_64")
{
return Some(Choice::Binary(b));
}
if let Some(p) = &d.npx
&& on_path("npm")
&& on_path("node")
@@ -689,6 +695,18 @@ mod tests {
const LINUX: Platform = Platform { os: Os::Linux, arch: Arch::X64 };
const WINDOWS: Platform = Platform { os: Os::Windows, arch: Arch::X64 };
#[test]
fn windows_arm_binary_prefers_native_then_x64() {
let mut entry = parse(INDEX).unwrap().remove(0);
let arm = Platform { os: Os::Windows, arch: Arch::Arm64 };
assert!(matches!(choose(&entry, arm, &|_| false), Some(Choice::Binary(_))));
assert!(choose(&entry, Platform { os: Os::Linux, arch: Arch::Arm64 }, &|_| false).is_none());
let mut native = entry.distribution.binary["windows-x86_64"].clone();
native.cmd = "native.exe".into();
entry.distribution.binary.insert("windows-aarch64".into(), native);
assert!(matches!(choose(&entry, arm, &|_| false), Some(Choice::Binary(b)) if b.cmd == "native.exe"));
}
const INDEX: &str = r#"{"version":"1.0.0","agents":[
{"id":"amp-acp","name":"Amp","version":"0.10.0","description":"Amp over ACP",
"repository":"https://github.com/x/amp-acp","authors":["x"],"license":"Apache-2.0",
+3 -3
Переглянути файл
@@ -323,9 +323,9 @@ impl Tools {
picked =
adoptium_pick(&http.get_text(&adoptium_assets_url(feature, self.platform), cancel)?, self.platform)?;
}
if picked.is_none() && self.platform.os == Os::Mac && self.platform.arch == Arch::Arm64 {
// Java 8 has no Apple Silicon build: the Intel one runs under Rosetta.
let intel = Platform { os: Os::Mac, arch: Arch::X64 };
if picked.is_none() && matches!(self.platform.os, Os::Mac | Os::Windows) && self.platform.arch == Arch::Arm64 {
// Older JDKs may need the OS-provided x64 emulation.
let intel = Platform { os: self.platform.os, arch: Arch::X64 };
picked = adoptium_pick(&http.get_text(&adoptium_assets_url(feature, intel), cancel)?, intel)?;
}
let (dl, major) = picked.ok_or_else(|| {
+36 -4
Переглянути файл
@@ -61,8 +61,8 @@ pub const fn any_arch(os: Os, pattern: &'static str) -> AssetRule {
}
/// Picks the asset for `platform`: rules are tried in order and the first
/// rule matching any asset name wins. Apple Silicon falls back to x64 assets
/// (Rosetta) when no native build exists.
/// rule matching any asset name wins. ARM64 macOS and Windows fall back to x64 assets
/// under OS emulation when no native build exists.
pub fn select_asset<'a>(names: &[&'a str], rules: &[AssetRule], platform: Platform) -> Option<&'a str> {
let pick = |arch: Arch| {
rules
@@ -70,8 +70,11 @@ pub fn select_asset<'a>(names: &[&'a str], rules: &[AssetRule], platform: Platfo
.filter(|r| r.os == platform.os && r.arch.is_none_or(|a| a == arch))
.find_map(|r| names.iter().copied().find(|n| glob_match(r.pattern, n)))
};
pick(platform.arch)
.or_else(|| (platform.os == Os::Mac && platform.arch == Arch::Arm64).then(|| pick(Arch::X64)).flatten())
pick(platform.arch).or_else(|| {
(matches!(platform.os, Os::Mac | Os::Windows) && platform.arch == Arch::Arm64)
.then(|| pick(Arch::X64))
.flatten()
})
}
/// Case-insensitive glob with `*` wildcards only.
@@ -175,6 +178,35 @@ mod tests {
assert_eq!(select_asset(&old, rules, LINUX_X64), Some("codelldb-x86_64-linux.vsix"));
}
#[test]
fn arm64_native_then_emulated_assets() {
for os in [Os::Mac, Os::Windows, Os::Linux] {
let rules = [rule(os, Arch::X64, "tool-x64"), rule(os, Arch::Arm64, "tool-arm64")];
let platform = Platform { os, arch: Arch::Arm64 };
assert_eq!(select_asset(&["tool-x64", "tool-arm64"], &rules, platform), Some("tool-arm64"));
let fallback = if os == Os::Linux { None } else { Some("tool-x64") };
assert_eq!(select_asset(&["tool-x64"], &rules, platform), fallback);
assert_eq!(select_asset(&[], &rules, platform), None);
}
}
#[test]
fn native_windows_release_rules() {
let platform = Platform { os: Os::Windows, arch: Arch::Arm64 };
for (tool, asset) in [
("zls", "zls-aarch64-windows.zip"),
("taplo", "taplo-windows-aarch64.zip"),
("buf", "buf-Windows-arm64.zip"),
("texlab", "texlab-aarch64-windows.zip"),
("neocmakelsp", "neocmakelsp-aarch64-pc-windows-msvc.zip"),
] {
assert_eq!(
select_asset(&[asset], crate::registry::find(tool).unwrap().asset_rules(), platform),
Some(asset)
);
}
}
#[test]
fn exe_suffix() {
assert_eq!(WIN.exe("clangd"), "clangd.exe");
+2
Переглянути файл
@@ -398,6 +398,7 @@ pub static TOOLS: &[ToolSpec] = &[
rule(Linux, X64, "taplo-linux-x86_64.gz"),
rule(Linux, Arm64, "taplo-linux-aarch64.gz"),
rule(Windows, X64, "taplo-windows-x86_64.zip"),
rule(Windows, Arm64, "taplo-windows-aarch64.zip"),
],
locate: &["taplo"],
},
@@ -418,6 +419,7 @@ pub static TOOLS: &[ToolSpec] = &[
rule(Linux, X64, "zls-x86_64-linux.tar.xz"),
rule(Linux, Arm64, "zls-aarch64-linux.tar.xz"),
rule(Windows, X64, "zls-x86_64-windows.zip"),
rule(Windows, Arm64, "zls-aarch64-windows.zip"),
],
locate: &["zls"],
},