Skip to content

Commit fd663da

Browse files
authored
Allow use on x86_64 systems (#46)
This PR uses the system architecture to decide which QEMU binary to run. Allows for use on x86_64 machines.
1 parent 0d3d73c commit fd663da

3 files changed

Lines changed: 36 additions & 8 deletions

File tree

.changeset/red-vms-sneeze.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"pi-enclave": patch
3+
---
4+
5+
Pass the architecture-specific QEMU binary through to Gondolin when starting the VM.

packages/enclave/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ VM-isolated enclave for [pi](https://pi.dev). Runs all tools inside a [Gondolin]
88
pi install npm:pi-enclave
99
```
1010

11-
Requires QEMU: `brew install qemu` (macOS) or `sudo apt install qemu-system-aarch64` (Linux).
11+
Requires QEMU: `brew install qemu` (macOS) or `sudo apt install qemu-system-x86` / `sudo apt install qemu-system-aarch64` (Linux, matching your host architecture).
1212

1313
## How it works
1414

15-
pi-enclave starts an Alpine Linux micro-VM (QEMU/aarch64) and redirects all tool execution into it. Your workspace is mounted read-write at the same path inside the VM, so tools see identical paths on host and guest. File changes are bidirectional.
15+
pi-enclave starts an Alpine Linux micro-VM (QEMU, matching your host architecture) and redirects all tool execution into it. Your workspace is mounted read-write at the same path inside the VM, so tools see identical paths on host and guest. File changes are bidirectional.
1616

1717
The core security property: **secrets never enter the VM**. Secrets configured in your TOML config (like `gh auth token`) are resolved on the host, and their values are replaced with random placeholders inside the VM. Gondolin's HTTP proxy substitutes real values on the wire, only for requests to configured hosts.
1818

packages/enclave/src/vm.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,18 @@ export class EnclaveVM {
232232
}
233233
}
234234

235-
// Create and start VM
235+
// Create and start VM. Pass qemuPath explicitly so the preflight
236+
// check and Gondolin launch use the same architecture-specific binary.
237+
const qemuPath = qemuBinaryForHost();
238+
if (!qemuPath) {
239+
throw new Error(`pi-enclave does not support host architecture: ${process.arch}`);
240+
}
241+
236242
this.vm = await VM.create({
237-
sandbox: this.options.image ? { imagePath: this.options.image } : undefined,
243+
sandbox: {
244+
...(this.options.image ? { imagePath: this.options.image } : {}),
245+
qemuPath,
246+
},
238247
httpHooks,
239248
env: {
240249
...env,
@@ -319,28 +328,42 @@ function shellEscape(s: string): string {
319328
return `'${s.replace(/'/g, "'\\''")}'`;
320329
}
321330

331+
function qemuBinaryForHost(): string | undefined {
332+
if (process.arch === "arm64") return "qemu-system-aarch64";
333+
if (process.arch === "x64") return "qemu-system-x86_64";
334+
return undefined;
335+
}
336+
322337
/**
323338
* Check if QEMU is available on the host.
324339
*/
325340
export function checkQemuAvailable(): { available: boolean; message?: string } {
341+
const qemuBinary = qemuBinaryForHost();
342+
if (!qemuBinary) {
343+
return {
344+
available: false,
345+
message: `pi-enclave does not support host architecture: ${process.arch}`,
346+
};
347+
}
348+
326349
try {
327-
execSync("which qemu-system-aarch64", { stdio: "ignore" });
350+
execSync(`which ${qemuBinary}`, { stdio: "ignore" });
328351
return { available: true };
329352
} catch {
330353
const platform = process.platform;
331354
let installHint: string;
332355
if (platform === "darwin") {
333356
installHint = "Install with: brew install qemu";
334357
} else if (platform === "linux") {
335-
installHint =
336-
"Install with: sudo apt install qemu-system-aarch64 (Debian/Ubuntu) or sudo pacman -S qemu-full (Arch)";
358+
const debianPackage = process.arch === "arm64" ? "qemu-system-aarch64" : "qemu-system-x86";
359+
installHint = `Install with: sudo apt install ${debianPackage} (Debian/Ubuntu) or sudo pacman -S qemu-full (Arch)`;
337360
} else {
338361
installHint = "QEMU is required but your platform may not be supported.";
339362
}
340363

341364
return {
342365
available: false,
343-
message: `pi-enclave requires QEMU but qemu-system-aarch64 was not found.\n${installHint}`,
366+
message: `pi-enclave requires QEMU but ${qemuBinary} was not found.\n${installHint}`,
344367
};
345368
}
346369
}

0 commit comments

Comments
 (0)