Skip to content

Commit e80ccfe

Browse files
committed
feat(matting): support arm64 on Windows and Linux
Runtime download only keyed on OS before, always fetching the x64 package, so it failed on Windows/Linux arm64. Select by target_arch too and return a clear error on platforms without an official prebuilt package. macOS already used universal2 (Intel + Apple Silicon).
1 parent 63e8331 commit e80ccfe

1 file changed

Lines changed: 30 additions & 9 deletions

File tree

crates/app-core/src/matting_plugin.rs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,34 @@ fn dylib_name() -> &'static str {
3232
}
3333
}
3434

35-
/// 当前平台的 ONNX Runtime 官方发布包 URL + 解压时匹配库文件的关键片段。
36-
fn runtime_archive() -> (String, bool) {
37-
// 返回 (url, is_zip)。
35+
/// 当前平台 + 架构的 ONNX Runtime 官方发布包 URL,以及是否 zip(否则 tgz)。
36+
/// 覆盖:Windows x64/arm64、macOS(universal2,含 Intel 与 Apple Silicon)、Linux x64/arm64。
37+
/// 返回 `None` 表示该平台 / 架构没有官方预编译包(如 32 位),插件不可用。
38+
fn runtime_archive() -> Option<(String, bool)> {
3839
let v = ORT_VERSION;
39-
if cfg!(target_os = "windows") {
40-
(format!("https://github.com/microsoft/onnxruntime/releases/download/v{v}/onnxruntime-win-x64-{v}.zip"), true)
40+
let base = "https://github.com/microsoft/onnxruntime/releases/download";
41+
let (slug, is_zip) = if cfg!(target_os = "windows") {
42+
match () {
43+
_ if cfg!(target_arch = "x86_64") => (format!("onnxruntime-win-x64-{v}"), true),
44+
_ if cfg!(target_arch = "aarch64") => (format!("onnxruntime-win-arm64-{v}"), true),
45+
_ => return None,
46+
}
4147
} else if cfg!(target_os = "macos") {
42-
(format!("https://github.com/microsoft/onnxruntime/releases/download/v{v}/onnxruntime-osx-universal2-{v}.tgz"), false)
48+
// universal2 同时含 x86_64 与 arm64。
49+
(format!("onnxruntime-osx-universal2-{v}"), false)
50+
} else if cfg!(target_os = "linux") {
51+
match () {
52+
_ if cfg!(target_arch = "x86_64") => (format!("onnxruntime-linux-x64-{v}"), false),
53+
_ if cfg!(target_arch = "aarch64") => (format!("onnxruntime-linux-aarch64-{v}"), false),
54+
_ => return None,
55+
}
4356
} else {
44-
(format!("https://github.com/microsoft/onnxruntime/releases/download/v{v}/onnxruntime-linux-x64-{v}.tgz"), false)
45-
}
57+
return None;
58+
};
59+
Some((
60+
format!("{base}/v{v}/{slug}.{}", if is_zip { "zip" } else { "tgz" }),
61+
is_zip,
62+
))
4663
}
4764

4865
/// 解压后成功提取的库最小合理体积(真实库都 > 10 MB;软链 / 坏文件会远小于此)。
@@ -133,7 +150,11 @@ impl App {
133150
.ok_or_else(|| AppError::InvalidInput("plugin dir not set".into()))?;
134151
std::fs::create_dir_all(&dir)?;
135152

136-
let (rt_url, is_zip) = runtime_archive();
153+
let (rt_url, is_zip) = runtime_archive().ok_or_else(|| {
154+
AppError::InvalidInput(
155+
"AI matting is not available on this platform / architecture".into(),
156+
)
157+
})?;
137158

138159
// 先探两个下载的总大小,合并成一个进度。
139160
let model_total = content_length(MODEL_URL).await.unwrap_or(0);

0 commit comments

Comments
 (0)