diff --git a/maa-cli/build.rs b/maa-cli/build.rs index 736fd6ab..041809d9 100644 --- a/maa-cli/build.rs +++ b/maa-cli/build.rs @@ -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() + ); } diff --git a/maa-cli/docs/en-US/install.md b/maa-cli/docs/en-US/install.md index 9411dfde..60813e0f 100644 --- a/maa-cli/docs/en-US/install.md +++ b/maa-cli/docs/en-US/install.md @@ -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). diff --git a/maa-cli/docs/ja-JP/install.md b/maa-cli/docs/ja-JP/install.md index 7976dc01..23a80ec0 100644 --- a/maa-cli/docs/ja-JP/install.md +++ b/maa-cli/docs/ja-JP/install.md @@ -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) 如果你的平台不在上述列表中,可以尝试自行编译安装(参见下文)。 diff --git a/maa-cli/docs/ko-KR/install.md b/maa-cli/docs/ko-KR/install.md index 4b963179..42f664b1 100644 --- a/maa-cli/docs/ko-KR/install.md +++ b/maa-cli/docs/ko-KR/install.md @@ -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) 위의 목록에 없는 플랫폼의 경우, 직접 컴파일하여 설치할 수 있습니다(아래 참조). diff --git a/maa-cli/docs/zh-CN/install.md b/maa-cli/docs/zh-CN/install.md index 6013c785..08d4255b 100644 --- a/maa-cli/docs/zh-CN/install.md +++ b/maa-cli/docs/zh-CN/install.md @@ -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) 如果你的平台不在上述列表中,可以尝试自行编译安装(参见下文)。 diff --git a/maa-cli/docs/zh-TW/install.md b/maa-cli/docs/zh-TW/install.md index 7976dc01..23a80ec0 100644 --- a/maa-cli/docs/zh-TW/install.md +++ b/maa-cli/docs/zh-TW/install.md @@ -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) 如果你的平台不在上述列表中,可以尝试自行编译安装(参见下文)。 diff --git a/maa-cli/src/installer/maa_cli.rs b/maa-cli/src/installer/maa_cli.rs index 9793ede3..e853741f 100644 --- a/maa-cli/src/installer/maa_cli.rs +++ b/maa-cli/src/installer/maa_cli.rs @@ -1,4 +1,5 @@ use std::{ + collections::BTreeMap, env::{consts, current_exe}, time::Duration, }; @@ -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); + +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)) } } @@ -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" } @@ -190,7 +175,7 @@ mod tests { let version_json: VersionJSON
= 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(),