Skip to content

Commit

Permalink
feat: add support for Windows aarch64 (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangl-cc authored Dec 24, 2024
1 parent 5493d16 commit 3d60e41
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 33 deletions.
5 changes: 5 additions & 0 deletions maa-cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ fn main() {
} else {
println!("cargo:rustc-env=MAA_VERSION={}", env!("CARGO_PKG_VERSION"));
}

println!(
"cargo:rustc-env=TARGET={}",
std::env::var("TARGET").unwrap()
);
}
1 change: 1 addition & 0 deletions maa-cli/docs/en-US/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ If package managers are not available on your system or you prefer not to use th
- [Linux x86_64 (x64, amd64)](https://github.com/MaaAssistantArknights/maa-cli/releases/latest/download/maa_cli-x86_64-unknown-linux-gnu.tar.gz)
- [Linux aarch64 (arm64)](https://github.com/MaaAssistantArknights/maa-cli/releases/latest/download/maa_cli-aarch64-unknown-linux-gnu.tar.gz)
- [Windows x86_64 (x64, amd64)](https://github.com/MaaAssistantArknights/maa-cli/releases/latest/download/maa_cli-x86_64-pc-windows-msvc.zip)
- [Windows aarch64 (arm64)](https://github.com/MaaAssistantArknights/maa-cli/releases/latest/download/maa_cli-aarch64-pc-windows-msvc.zip)

If your platform is not listed above, you can try to compile and install it yourself (see below).

Expand Down
1 change: 1 addition & 0 deletions maa-cli/docs/ja-JP/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Homebrew 用户可以通过非官方的 [tap](https://github.com/MaaAssistantArk
- [Linux x86_64 (x64, amd64)](https://github.com/MaaAssistantArknights/maa-cli/releases/latest/download/maa_cli-x86_64-unknown-linux-gnu.tar.gz)
- [Linux aarch64 (arm64)](https://github.com/MaaAssistantArknights/maa-cli/releases/latest/download/maa_cli-aarch64-unknown-linux-gnu.tar.gz)
- [Windows x86_64 (x64, amd64)](https://github.com/MaaAssistantArknights/maa-cli/releases/latest/download/maa_cli-x86_64-pc-windows-msvc.zip)
- [Windows aarch64 (arm64)](https://github.com/MaaAssistantArknights/maa-cli/releases/latest/download/maa_cli-aarch64-pc-windows-msvc.zip)

如果你的平台不在上述列表中,可以尝试自行编译安装(参见下文)。

Expand Down
1 change: 1 addition & 0 deletions maa-cli/docs/ko-KR/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Homebrew 사용자는 비공식 [tap](https://github.com/MaaAssistantArknights/h
- [Linux x86_64 (x64, amd64)](https://github.com/MaaAssistantArknights/maa-cli/releases/latest/download/maa_cli-x86_64-unknown-linux-gnu.tar.gz)
- [Linux aarch64 (arm64)](https://github.com/MaaAssistantArknights/maa-cli/releases/latest/download/maa_cli-aarch64-unknown-linux-gnu.tar.gz)
- [Windows x86_64 (x64, amd64)](https://github.com/MaaAssistantArknights/maa-cli/releases/latest/download/maa_cli-x86_64-pc-windows-msvc.zip)
- [Windows aarch64 (arm64)](https://github.com/MaaAssistantArknights/maa-cli/releases/latest/download/maa_cli-aarch64-pc-windows-msvc.zip)

위의 목록에 없는 플랫폼의 경우, 직접 컴파일하여 설치할 수 있습니다(아래 참조).

Expand Down
1 change: 1 addition & 0 deletions maa-cli/docs/zh-CN/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Homebrew 用户可以通过非官方的 [tap](https://github.com/MaaAssistantArk
- [Linux x86_64 (x64, amd64)](https://github.com/MaaAssistantArknights/maa-cli/releases/latest/download/maa_cli-x86_64-unknown-linux-gnu.tar.gz)
- [Linux aarch64 (arm64)](https://github.com/MaaAssistantArknights/maa-cli/releases/latest/download/maa_cli-aarch64-unknown-linux-gnu.tar.gz)
- [Windows x86_64 (x64, amd64)](https://github.com/MaaAssistantArknights/maa-cli/releases/latest/download/maa_cli-x86_64-pc-windows-msvc.zip)
- [Windows aarch64 (arm64)](https://github.com/MaaAssistantArknights/maa-cli/releases/latest/download/maa_cli-aarch64-pc-windows-msvc.zip)

如果你的平台不在上述列表中,可以尝试自行编译安装(参见下文)。

Expand Down
1 change: 1 addition & 0 deletions maa-cli/docs/zh-TW/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Homebrew 用户可以通过非官方的 [tap](https://github.com/MaaAssistantArk
- [Linux x86_64 (x64, amd64)](https://github.com/MaaAssistantArknights/maa-cli/releases/latest/download/maa_cli-x86_64-unknown-linux-gnu.tar.gz)
- [Linux aarch64 (arm64)](https://github.com/MaaAssistantArknights/maa-cli/releases/latest/download/maa_cli-aarch64-unknown-linux-gnu.tar.gz)
- [Windows x86_64 (x64, amd64)](https://github.com/MaaAssistantArknights/maa-cli/releases/latest/download/maa_cli-x86_64-pc-windows-msvc.zip)
- [Windows aarch64 (arm64)](https://github.com/MaaAssistantArknights/maa-cli/releases/latest/download/maa_cli-aarch64-pc-windows-msvc.zip)

如果你的平台不在上述列表中,可以尝试自行编译安装(参见下文)。

Expand Down
51 changes: 18 additions & 33 deletions maa-cli/src/installer/maa_cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
collections::BTreeMap,
env::{consts, current_exe},
time::Duration,
};
Expand Down Expand Up @@ -89,36 +90,15 @@ impl Details {
}

#[derive(Deserialize)]
struct Assets {
#[serde(rename = "x86_64-apple-darwin")]
x86_64_apple_darwin: Asset,
#[serde(rename = "aarch64-apple-darwin")]
aarch64_apple_darwin: Asset,
#[serde(rename = "x86_64-unknown-linux-gnu")]
x86_64_unknown_linux_gnu: Asset,
#[serde(rename = "aarch64-unknown-linux-gnu")]
aarch64_unknown_linux_gnu: Asset,
#[serde(rename = "x86_64-pc-windows-msvc")]
x86_64_pc_windows_msvc: Asset,
}
struct Assets(BTreeMap<String, Asset>);

const PLATFORM: &str = env!("TARGET");

impl Assets {
fn asset(&self) -> Result<&Asset> {
use consts::{ARCH, OS};
match OS {
"macos" => match ARCH {
"x86_64" => Ok(&self.x86_64_apple_darwin),
"aarch64" => Ok(&self.aarch64_apple_darwin),
_ => Err(anyhow!("Unsupported architecture: {ARCH}")),
},
"linux" => match consts::ARCH {
"x86_64" => Ok(&self.x86_64_unknown_linux_gnu),
"aarch64" => Ok(&self.aarch64_unknown_linux_gnu),
_ => Err(anyhow!("Unsupported architecture: {ARCH}")),
},
"windows" if consts::ARCH == "x86_64" => Ok(&self.x86_64_pc_windows_msvc),
_ => Err(anyhow!("Unsupported platform: {OS} {ARCH}")),
}
self.0
.get(PLATFORM)
.ok_or_else(|| anyhow!("No asset for platform: {}", PLATFORM))
}
}

Expand Down Expand Up @@ -158,27 +138,32 @@ mod tests {
"tag": "v0.1.0",
"assets": {
"x86_64-apple-darwin": {
"name": "maa-cli.zip",
"name": "maa_cli-0.1.0-x86_64-apple-darwin.zip",
"size": 123456,
"sha256sum": "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
},
"aarch64-apple-darwin": {
"name": "maa-cli.zip",
"name": "maa_cli-0.1.0-aarch64-apple-darwin.zip",
"size": 123456,
"sha256sum": "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
},
"x86_64-unknown-linux-gnu": {
"name": "maa-cli.zip",
"name": "maa_cli-0.1.0-x86_64-unknown-linux-gnu.zip",
"size": 123456,
"sha256sum": "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
},
"aarch64-unknown-linux-gnu": {
"name": "maa-cli.zip",
"name": "maa_cli-0.1.0-aarch64-unknown-linux-gnu.zip",
"size": 123456,
"sha256sum": "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
},
"x86_64-pc-windows-msvc": {
"name": "maa-cli.zip",
"name": "maa_cli-0.1.0-x86_64-pc-windows-msvc.zip",
"size": 123456,
"sha256sum": "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
},
"aarch64-pc-windows-msvc": {
"name": "maa_cli-0.1.0-aarch64-pc-windows-msvc.zip",
"size": 123456,
"sha256sum": "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
}
Expand All @@ -190,7 +175,7 @@ mod tests {
let version_json: VersionJSON<Details> = serde_json::from_str(json).unwrap();
let asset = version_json.details().asset().unwrap();

assert_eq!(asset.name(), "maa-cli.zip");
assert_eq!(asset.name(), format!("maa_cli-0.1.0-{}.zip", PLATFORM));
assert_eq!(asset.size(), 123456);
assert_eq!(
asset.checksum(),
Expand Down

0 comments on commit 3d60e41

Please sign in to comment.