Skip to content

Commit

Permalink
Set LD_LIBRARY_PATH when calling limactl or qemu-img
Browse files Browse the repository at this point in the history
This is needed when running with the bundled QEMU on Linux to pick up
the additional QEMU dependency libraries that might not exist on the
local system (or might be incompatible).

LD_LIBRARY_PATH is ignored on macOS, and doesn't hurt on Linux when
QEMU isn't bundled.

Signed-off-by: Jan Dubois <[email protected]>
  • Loading branch information
jandubois committed Nov 9, 2024
1 parent 068b430 commit fb36a5c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pkg/rancher-desktop/backend/lima.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,15 +749,23 @@ export default class LimaBackend extends events.EventEmitter implements VMBacken

protected static get limaEnv() {
const binDir = path.join(paths.resources, os.platform(), 'lima', 'bin');
const libDir = path.join(paths.resources, os.platform(), 'lima', 'lib');
const VMNETDir = path.join(VMNET_DIR, 'bin');
const pathList = (process.env.PATH || '').split(path.delimiter);
const newPath = [binDir, VMNETDir].concat(...pathList).filter(x => x);

// LD_LIBRARY_PATH is set for running from an extracted Linux zip file, that includes QEMU,
// to make sure QEMU dependencies are loaded from the bundled lib directory,
// LD_LIBRARY_PATH is ignored on macOS.
return {
...process.env, LIMA_HOME: paths.lima, PATH: newPath.join(path.delimiter),
...process.env, LIMA_HOME: paths.lima, LD_LIBRARY_PATH: libDir, PATH: newPath.join(path.delimiter),
};
}

protected static get qemuImgEnv() {
return { ...process.env, LD_LIBRARY_PATH: path.join(paths.resources, os.platform(), 'lima', 'lib') };
}

/**
* Run `limactl` with the given arguments.
*/
Expand Down Expand Up @@ -925,7 +933,8 @@ export default class LimaBackend extends events.EventEmitter implements VMBacken

protected async imageInfo(fileName: string): Promise<QEMUImageInfo> {
try {
const { stdout } = await this.spawnWithCapture(LimaBackend.qemuImg, 'info', '--output=json', '--force-share', fileName);
const { stdout } = await this.spawnWithCapture(LimaBackend.qemuImg, { env: LimaBackend.qemuImgEnv },
'info', '--output=json', '--force-share', fileName);

return JSON.parse(stdout) as QEMUImageInfo;
} catch {
Expand All @@ -936,7 +945,8 @@ export default class LimaBackend extends events.EventEmitter implements VMBacken
protected async convertToRaw(fileName: string): Promise<void> {
const rawFileName = `${ fileName }.raw`;

await this.spawnWithCapture(LimaBackend.qemuImg, 'convert', fileName, rawFileName);
await this.spawnWithCapture(LimaBackend.qemuImg, { env: LimaBackend.qemuImgEnv },
'convert', fileName, rawFileName);
await fs.promises.unlink(fileName);
await fs.promises.rename(rawFileName, fileName);
}
Expand Down

0 comments on commit fb36a5c

Please sign in to comment.