From d5e9476a41eaf0fb40ed6eefe18a0374a3bb80a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Wed, 18 Mar 2026 11:08:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=20QEMU=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E6=9F=A5=E6=89=BE=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E6=9E=B6=E6=9E=84=E4=BC=98=E5=85=88?= =?UTF-8?q?=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ostool/src/run/qemu.rs | 44 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/ostool/src/run/qemu.rs b/ostool/src/run/qemu.rs index f54fa59..d20e260 100644 --- a/ostool/src/run/qemu.rs +++ b/ostool/src/run/qemu.rs @@ -92,10 +92,9 @@ pub struct RunQemuArgs { /// /// Returns an error if QEMU fails to start or exits with an error. pub async fn run_qemu(ctx: AppContext, args: RunQemuArgs) -> anyhow::Result<()> { - // Build logic will be implemented here let config_path = match args.qemu_config.clone() { Some(path) => path, - None => ctx.paths.manifest.join(".qemu.toml"), + None => find_qemu_config(&ctx)?, }; info!("Using QEMU config file: {}", config_path.display()); @@ -510,3 +509,44 @@ impl QemuRunner { Ok(()) } } + +/// Find QEMU configuration file with architecture-specific priority. +/// +/// Search order: +/// 1. qemu-.toml +/// 2. .qemu-.toml +/// 3. qemu.toml +/// 4. .qemu.toml +fn find_qemu_config(ctx: &AppContext) -> anyhow::Result { + let manifest_dir = &ctx.paths.manifest; + + // Get architecture string if available + let arch_str = ctx.arch.map(|arch| format!("{arch:?}").to_lowercase()); + + // Try architecture-specific config files first + if let Some(ref arch) = arch_str { + let candidates = [ + manifest_dir.join(format!("qemu-{}.toml", arch)), + manifest_dir.join(format!(".qemu-{}.toml", arch)), + ]; + for path in &candidates { + if path.exists() { + return Ok(path.clone()); + } + } + } + + // Fall back to generic config files + let fallback_candidates = [ + manifest_dir.join("qemu.toml"), + manifest_dir.join(".qemu.toml"), + ]; + for path in &fallback_candidates { + if path.exists() { + return Ok(path.clone()); + } + } + + // Return default path if none exists + Ok(manifest_dir.join(".qemu.toml")) +}