Skip to content

Commit d7e5ef7

Browse files
committed
feat: run on aarch64 with the native ARM64 WoW client
1 parent 300cc86 commit d7e5ef7

11 files changed

Lines changed: 160 additions & 17 deletions

File tree

‎crates/core/src/doctor.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ fn icd_dirs(data_home: Option<&str>, home: Option<&Path>, data_dirs: Option<&str
184184
}
185185

186186
fn loader() -> Check {
187+
if !runtime::needs_32bit_libraries() {
188+
return check("32-bit runtime", Status::Ok, "not needed on this processor", None);
189+
}
187190
if runtime::has_32bit_loader() {
188191
return check("32-bit runtime", Status::Ok, "present", None);
189192
}
@@ -197,6 +200,9 @@ fn loader() -> Check {
197200
}
198201

199202
fn gnutls() -> Check {
203+
if !runtime::needs_32bit_libraries() {
204+
return check("32-bit gnutls", Status::Ok, "not needed on this processor", None);
205+
}
200206
match runtime::has_32bit_tls() {
201207
Some(true) => check("32-bit gnutls", Status::Ok, "present", None),
202208
Some(false) => check(

‎crates/core/src/prefix.rs‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,20 @@ impl ProtonRunner {
201201
cmd
202202
}
203203

204-
/// Proton's runtime directory, `files` or `dist`, holding `bin/wineserver`.
204+
/// The `wineserver` the `proton` script runs. An ARM build keeps its
205+
/// binaries in `bin-arm64` (GE-Proton11-7-aarch64 has no `bin`), and the
206+
/// script takes it on aarch64 unless `PROTON_USE_ARM64` is not `1`.
207+
pub fn wineserver(&self) -> PathBuf {
208+
let arm = self.dist.join("bin-arm64");
209+
let wants_arm = cfg!(target_arch = "aarch64")
210+
&& std::env::var_os("PROTON_USE_ARM64").is_none_or(|v| v == "1");
211+
match wants_arm && arm.is_dir() {
212+
true => arm.join("wineserver"),
213+
false => self.dist.join("bin").join("wineserver"),
214+
}
215+
}
216+
217+
/// Proton's runtime directory, `files` or `dist`.
205218
pub fn dist(&self) -> &Path {
206219
&self.dist
207220
}
@@ -267,7 +280,7 @@ impl ProtonRunner {
267280
/// Proton's runtime directly: the `proton` script has no verb for it. A
268281
/// live wineserver holds the registry, so every mutation waits for this.
269282
pub fn wineserver_kill(&self) -> Result<(), PrefixError> {
270-
let wineserver = self.dist.join("bin").join("wineserver");
283+
let wineserver = self.wineserver();
271284
if !wineserver.is_file() {
272285
return Err(PrefixError::MissingRuntime(wineserver));
273286
}

‎crates/core/src/preflight/gate.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl Preflight {
180180
/// Whether the prefix's live `wineserver`, if any, is this runner's. Two Wine
181181
/// builds cannot share one server. One whose binary cannot be read is let be.
182182
pub(super) fn served_by(runner: &ProtonRunner, layout: &Layout) -> bool {
183-
let ours = runner.dist().join("bin").join("wineserver");
183+
let ours = runner.wineserver();
184184
let ours = ours.canonicalize().unwrap_or(ours);
185185
scan(layout)
186186
.into_iter()

‎crates/core/src/runtime.rs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub enum RuntimeError {
9292
/// Cheap enough to call before any download. Passes off x86-64, where it
9393
/// means nothing.
9494
pub fn check_loader() -> Result<(), RuntimeError> {
95-
if !cfg!(target_arch = "x86_64") {
95+
if !needs_32bit_libraries() {
9696
return Ok(());
9797
}
9898
if LOADER_CANDIDATES.iter().any(|p| Path::new(p).exists()) {
@@ -131,6 +131,12 @@ pub fn check_wine(dist: &Path) -> Result<(), RuntimeError> {
131131
})
132132
}
133133

134+
/// Whether 32-bit Windows programs need the host's 32-bit libraries. Not on
135+
/// ARM: there Wine runs them through FEX with the native aarch64 ones.
136+
pub fn needs_32bit_libraries() -> bool {
137+
cfg!(target_arch = "x86_64")
138+
}
139+
134140
/// Whether a 32-bit runtime is present, for a debug bundle or a settings
135141
/// panel that wants to state a fact, not fail.
136142
pub fn has_32bit_loader() -> bool {
@@ -654,7 +660,7 @@ pub fn tls_container(
654660
proton_root: &Path,
655661
steam: Option<&crate::steam::SteamRoot>,
656662
) -> Result<Option<PathBuf>, RuntimeError> {
657-
if has_32bit_tls() != Some(false) {
663+
if !needs_32bit_libraries() || has_32bit_tls() != Some(false) {
658664
return Ok(None);
659665
}
660666
let appid = required_runtime(proton_root);

‎crates/core/src/tact/install/mod.rs‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ use locale::*;
3333
#[derive(Debug, Clone)]
3434
pub struct Options {
3535
pub region: Region,
36+
/// Which of Blizzard's client builds to install; the host's by default.
37+
pub cpu: Cpu,
3638
/// Client locale, e.g. `enUS`. Selects which of a build's files are wanted.
3739
pub locale: String,
3840
/// Optional content to opt in to, by tag name, e.g. `HighRes`. See
@@ -78,6 +80,7 @@ impl Default for Options {
7880
fn default() -> Self {
7981
Self {
8082
region: Region::default(),
83+
cpu: Cpu::host(),
8184
locale: "enUS".to_owned(),
8285
optional_tags: Vec::new(),
8386
flavor: String::new(),
@@ -110,7 +113,8 @@ impl Options {
110113
/// see [`shipped_locale`].
111114
fn tag_column_for(&self, locale: &str) -> String {
112115
let r = self.region.as_str().to_uppercase();
113-
format!("Windows x86_64 {r} {locale} speech:Windows x86_64 {r} {locale} text")
116+
let cpu = self.cpu.tag();
117+
format!("Windows {cpu} {r} {locale} speech:Windows {cpu} {r} {locale} text")
114118
}
115119

116120
/// True when any option truncates the plan.
@@ -119,6 +123,31 @@ impl Options {
119123
}
120124
}
121125

126+
/// The processor a client build is for. WoW's product config names both
127+
/// (`tags_64bit`, `tags_arm64`) and an ARM binary, `Wow-ARM64.exe`.
128+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
129+
pub enum Cpu {
130+
X86_64,
131+
Arm64,
132+
}
133+
134+
impl Cpu {
135+
pub fn host() -> Self {
136+
match cfg!(target_arch = "aarch64") {
137+
true => Self::Arm64,
138+
false => Self::X86_64,
139+
}
140+
}
141+
142+
/// The install and download manifests' architecture tag.
143+
pub fn tag(self) -> &'static str {
144+
match self {
145+
Self::X86_64 => "x86_64",
146+
Self::Arm64 => "arm64",
147+
}
148+
}
149+
}
150+
122151
/// What the run is doing, as it happens.
123152
#[derive(Debug, Clone)]
124153
pub enum Event {
@@ -271,6 +300,9 @@ pub enum InstallError {
271300
#[error("the build config has no {0} manifest")]
272301
MissingManifest(&'static str),
273302

303+
#[error("{code} has no {cpu} client")]
304+
NoClientFor { code: String, cpu: &'static str },
305+
274306
/// Downloaded and extracted; only the bookkeeping failed. Its own variant,
275307
/// so the message says which file in the install root it was.
276308
#[error("{dir} will not accept new files, so this install cannot be finished")]

‎crates/core/src/tact/install/prepare.rs‎

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ use std::collections::HashSet;
55
use std::path::Path;
66

77
use super::locale::shipped_locale;
8-
use super::{io, Event, InstallError, Options};
8+
use super::{io, Cpu, Event, InstallError, Options};
99
use crate::net::Http;
1010
use crate::product::ProductCode;
1111
use crate::tact::archive::FileIndex;
1212
use crate::tact::cdn::Client;
1313
use crate::tact::config::{BuildConfig, CdnConfig, KeyPair};
1414
use crate::tact::encoding::Encoding;
1515
use crate::tact::indices::{IndexCache, Locations};
16-
use crate::tact::manifest::{DownloadEntry, DownloadManifest, InstallManifest, TagSet};
16+
use crate::tact::manifest::{DownloadEntry, DownloadManifest, InstallManifest, Tag, TagSet};
1717
use crate::tact::plan::{reverse_encoding, Options as PlanOptions, Plan};
1818
use crate::tact::storage::{EKey, Storage};
1919
use crate::tact::version;
@@ -147,6 +147,7 @@ pub async fn offerings(
147147
let ekey = pair.ekey.ok_or(InstallError::MissingManifest("download"))?;
148148
let manifest =
149149
DownloadManifest::parse(&client.fetch_loose(http, &ekey, &pair.ckey).await?)?;
150+
require_cpu(options.cpu, code, manifest.tags())?;
150151

151152
let locale = shipped_locale(&options.locale, manifest.tags());
152153
let base_tags = TagSet::parse(&options.tag_column_for(&locale));
@@ -192,7 +193,14 @@ pub async fn prepare(
192193
.inspect_err(|e| tracing::warn!("product config {}: {e}", remote.product_config))
193194
.ok(),
194195
};
195-
let executable = product.as_ref().and_then(|p| p.executable.clone());
196+
let executable = product.as_ref().and_then(|p| match options.cpu {
197+
Cpu::X86_64 => p.executable.clone(),
198+
Cpu::Arm64 => p.executable_arm64.clone(),
199+
});
200+
// The fallback name is the x86 binary, which an ARM install leaves out.
201+
if options.cpu == Cpu::Arm64 && executable.is_none() {
202+
return Err(no_client(options.cpu, code));
203+
}
196204
let flavor = match (options.flavor.is_empty(), product.and_then(|p| p.install_dir)) {
197205
(false, _) => options.flavor.clone(),
198206
(true, Some(dir)) => dir,
@@ -239,6 +247,7 @@ pub async fn prepare(
239247
let download_manifest =
240248
DownloadManifest::parse(&fetch_manifest(build.download, "download").await?)?;
241249
let install = InstallManifest::parse(&fetch_manifest(build.install, "install").await?)?;
250+
require_cpu(options.cpu, code, download_manifest.tags())?;
242251
let locale = shipped_locale(&options.locale, download_manifest.tags());
243252
let tag_column = options.tag_column_for(&locale);
244253
let tags = TagSet::parse(&tag_column).with_optional(options.optional_tags.clone());
@@ -355,3 +364,39 @@ pub async fn prepare(
355364
executable,
356365
})
357366
}
367+
368+
/// An ARM build has to be on offer: without its tag the selection drops
369+
/// every architecture's binaries and the install could never start. x86_64
370+
/// is not checked, so a build that predates the tag still installs.
371+
fn require_cpu(cpu: Cpu, code: &ProductCode, tags: &[Tag]) -> Result<(), InstallError> {
372+
match cpu == Cpu::X86_64 || tags.iter().any(|tag| tag.name == cpu.tag()) {
373+
true => Ok(()),
374+
false => Err(no_client(cpu, code)),
375+
}
376+
}
377+
378+
fn no_client(cpu: Cpu, code: &ProductCode) -> InstallError {
379+
InstallError::NoClientFor { code: code.as_str().to_owned(), cpu: cpu.tag() }
380+
}
381+
382+
#[cfg(test)]
383+
mod cpu_tests {
384+
use super::*;
385+
386+
const ARCH: u16 = 2;
387+
388+
#[test]
389+
fn an_arm_install_needs_a_build_that_offers_arm() {
390+
let retail = ProductCode::Retail;
391+
let x86_only = [Tag::named("Windows", 1), Tag::named("x86_64", ARCH)];
392+
let both = [Tag::named("Windows", 1), Tag::named("x86_64", ARCH), Tag::named("arm64", ARCH)];
393+
394+
assert!(matches!(require_cpu(Cpu::Arm64, &retail, &x86_only), Err(InstallError::NoClientFor { .. })));
395+
assert!(require_cpu(Cpu::Arm64, &retail, &both).is_ok());
396+
}
397+
398+
#[test]
399+
fn an_x86_install_is_never_refused_for_a_missing_tag() {
400+
assert!(require_cpu(Cpu::X86_64, &ProductCode::Retail, &[Tag::named("Windows", 1)]).is_ok());
401+
}
402+
}

‎crates/core/src/tact/install/tests.rs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ use crate::tact::manifest::Tag;
33

44
#[test]
55
fn the_tag_column_matches_what_a_real_build_info_carries() {
6-
let options = Options { region: Region::Eu, locale: "enUS".into(), ..Options::default() };
6+
let options = Options { region: Region::Eu, cpu: Cpu::X86_64, locale: "enUS".into(), ..Options::default() };
77
assert_eq!(
88
options.tag_column(),
99
"Windows x86_64 EU enUS speech:Windows x86_64 EU enUS text"
1010
);
1111
}
1212

13+
#[test]
14+
fn an_arm_machine_asks_for_the_arm_client() {
15+
let options = Options { region: Region::Eu, cpu: Cpu::Arm64, locale: "enUS".into(), ..Options::default() };
16+
assert_eq!(options.tag_column(), "Windows arm64 EU enUS speech:Windows arm64 EU enUS text");
17+
}
18+
1319
fn locale_tag(name: &str) -> Tag {
1420
Tag::named(name, LOCALE_TAG)
1521
}

‎crates/core/src/tact/product_config.rs‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ pub struct ProductConfig {
1616
pub install_dir: Option<String>,
1717
/// The Windows game binary's file name, e.g. `WoW.exe`.
1818
pub executable: Option<String>,
19+
/// The Windows-on-ARM binary's, e.g. `Wow-ARM64.exe`.
20+
pub executable_arm64: Option<String>,
1921
}
2022

2123
#[derive(Debug, thiserror::Error)]
@@ -33,15 +35,19 @@ pub enum ProductConfigError {
3335
pub fn parse(json: &str) -> Result<ProductConfig, serde_json::Error> {
3436
let value: serde_json::Value = serde_json::from_str(json)?;
3537
let text = |pointer: &str| value.pointer(pointer).and_then(serde_json::Value::as_str);
38+
let binary = |pointer: &str| {
39+
text(pointer)
40+
.and_then(|path| path.rsplit(['/', '\\']).next())
41+
.filter(|name| !name.is_empty())
42+
.map(str::to_owned)
43+
};
3644
Ok(ProductConfig {
3745
// Joined onto the install root: a single plain folder name or nothing.
3846
install_dir: text("/all/config/shared_container_default_subfolder")
3947
.filter(|dir| !dir.is_empty() && *dir != ".." && !dir.contains(['/', '\\']))
4048
.map(str::to_owned),
41-
executable: text("/platform/win/config/binaries/game/relative_path")
42-
.and_then(|path| path.rsplit(['/', '\\']).next())
43-
.filter(|name| !name.is_empty())
44-
.map(str::to_owned),
49+
executable: binary("/platform/win/config/binaries/game/relative_path"),
50+
executable_arm64: binary("/platform/win/config/binaries/game/relative_path_arm64"),
4551
})
4652
}
4753

@@ -74,6 +80,12 @@ mod tests {
7480
assert_eq!(config.executable.as_deref(), Some("WoW.exe"));
7581
}
7682

83+
#[test]
84+
fn retail_and_forever_name_an_arm_binary() {
85+
assert_eq!(parse(WOW).unwrap().executable_arm64.as_deref(), Some("Wow-ARM64.exe"));
86+
assert_eq!(parse(WOWF).unwrap().executable_arm64.as_deref(), Some("Wow-arm64.exe"));
87+
}
88+
7789
#[test]
7890
fn a_folder_that_would_leave_the_install_is_ignored() {
7991
let json = r#"{"all":{"config":{"shared_container_default_subfolder":"../elsewhere"}}}"#;

‎crates/launcher-cli/src/cli.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ pub(crate) enum Command {
256256
locale: String,
257257
#[arg(long)]
258258
flavor: Option<String>,
259+
/// Plan another machine's client: `x86_64` or `arm64`. This one's by
260+
/// default.
261+
#[arg(long)]
262+
cpu: Option<String>,
259263
/// Break the difference down by priority, bucket and source, and
260264
/// cross-examine the store probe that produced it.
261265
#[arg(long)]

‎crates/launcher-cli/src/commands/download.rs‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,18 +333,25 @@ pub(crate) async fn cdn_fetch(code: ProductCode, region: String, hash: Option<St
333333

334334
// One parameter per command-line flag.
335335
#[allow(clippy::too_many_arguments)]
336-
pub(crate) async fn plan(dest: PathBuf, code: ProductCode, region: String, locale: String, flavor: String, explain: bool, optional: Vec<String>, limit_archives: Option<usize>, concurrency: usize) -> Result<()> {
336+
pub(crate) async fn plan(dest: PathBuf, code: ProductCode, region: String, locale: String, flavor: String, cpu: Option<String>, explain: bool, optional: Vec<String>, limit_archives: Option<usize>, concurrency: usize) -> Result<()> {
337337
use lightforge_core::net::Http;
338338
use lightforge_core::tact::explain as tact_explain;
339339
use lightforge_core::tact::storage::Storage;
340-
use lightforge_core::tact::install::{self, Event, Options as InstallOptions};
340+
use lightforge_core::tact::install::{self, Cpu, Event, Options as InstallOptions};
341341
use lightforge_core::tact::version::Region;
342342

343343
let region: Region = region.parse().context("parsing --region")?;
344+
let cpu = match cpu.as_deref() {
345+
None => Cpu::host(),
346+
Some("x86_64") => Cpu::X86_64,
347+
Some("arm64" | "aarch64") => Cpu::Arm64,
348+
Some(other) => anyhow::bail!("unknown --cpu `{other}` (x86_64 or arm64)"),
349+
};
344350
let gib = |b: u64| b as f64 / 1024f64.powi(3);
345351

346352
let options = InstallOptions {
347353
region,
354+
cpu,
348355
locale,
349356
flavor,
350357
concurrency,
@@ -373,6 +380,17 @@ pub(crate) async fn plan(dest: PathBuf, code: ProductCode, region: String, local
373380
let prepared =
374381
install::prepare(&http, &dest, &code, &options, &mut on_event).await?;
375382

383+
match prepared.executable.as_deref() {
384+
// The selected install files are what lands in the flavor folder.
385+
Some(name) => {
386+
let selected = prepared.install.select(&prepared.tags).iter().any(|e| e.path.eq_ignore_ascii_case(name));
387+
println!("executable {name} ({})", match selected {
388+
true => "in the install files",
389+
false => "NOT in the install files",
390+
});
391+
}
392+
None => println!("executable not named by the product config"),
393+
}
376394
println!(
377395
"optional {}",
378396
match prepared.optional.is_empty() {

0 commit comments

Comments
 (0)