Skip to content

Commit d55e3a6

Browse files
xtask: Add default QEMU executable directory on Windows
The QEMU installer for Windows does not automatically add the directory containing the QEMU executables to the PATH. Add the default directory to the PATH to make it more likely that QEMU will be found on Windows. The directory is appended, so if a different directory on the PATH already has the QEMU binary this change won't affect anything.
1 parent 9d273d4 commit d55e3a6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

xtask/src/qemu.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::ffi::OsString;
1111
use std::io::{BufRead, BufReader, Read, Write};
1212
use std::path::{Path, PathBuf};
1313
use std::process::{Child, Command, Stdio};
14-
use std::thread;
14+
use std::{env, thread};
1515
use tempfile::TempDir;
1616

1717
struct OvmfPaths {
@@ -265,6 +265,18 @@ pub fn run_qemu(arch: UefiArch, opt: &QemuOpt) -> Result<()> {
265265
};
266266
let mut cmd = Command::new(qemu_exe);
267267

268+
if platform::is_windows() {
269+
// The QEMU installer for Windows does not automatically add the
270+
// directory containing the QEMU executables to the PATH. Add
271+
// the default directory to the PATH to make it more likely that
272+
// QEMU will be found on Windows. (The directory is appended, so
273+
// if a different directory on the PATH already has the QEMU
274+
// binary this change won't affect anything.)
275+
let mut path = env::var_os("PATH").unwrap_or_default();
276+
path.push(r";C:\Program Files\qemu");
277+
cmd.env("PATH", path);
278+
}
279+
268280
// Disable default devices.
269281
// QEMU by defaults enables a ton of devices which slow down boot.
270282
cmd.arg("-nodefaults");

0 commit comments

Comments
 (0)