Skip to content

Commit 983efdc

Browse files
Merge pull request #43 from xvanc/master
build on darwin :^) (at least without `--sysroot`)
2 parents 7e26b6a + 83d9bbe commit 983efdc

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

aero.py

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,18 @@ def cp(src, dest):
404404

405405
if platform.system() == 'Windows':
406406
limine_install = 'limine-install-win32.exe'
407-
elif platform.system() == 'Linux' or platform.system() == 'Darwin':
407+
elif platform.system() == 'Linux':
408408
limine_install = 'limine-install-linux-x86_64'
409+
elif platform.system() == 'Darwin':
410+
limine_install = 'limine-install'
411+
# Limine doesn't provide pre-built binaries, so we have to build from source
412+
code, _, limine_build_stderr = run_command(['make', '-C', limine_path],
413+
stdout=subprocess.PIPE,
414+
stderr=subprocess.PIPE)
415+
if code != 0:
416+
print('Failed to build `limine-install`')
417+
print(limine_build_stderr.decode('utf8'))
418+
exit(1)
409419

410420
limine_install = os.path.join(limine_path, limine_install)
411421

@@ -445,23 +455,54 @@ def run_in_emulator(args, iso_path):
445455
if is_kvm_available and not args.disable_kvm:
446456
print("Running with KVM acceleration enabled")
447457

448-
qemu_args += ['-enable-kvm', '-cpu',
449-
'host,+la57' if args.la57 else 'host']
458+
if platform.system() == 'Darwin':
459+
qemu_args += ['-accel', 'hvf']
460+
else:
461+
qemu_args += ['-enable-kvm']
462+
qemu_args += ['-cpu', 'host,+la57' if args.la57 else 'host']
450463
else:
451464
qemu_args += ["-cpu", "qemu64,+la57" if args.la57 else "qemu64"]
452465

453466
run_command(['qemu-system-x86_64', *qemu_args])
454467

455468

469+
def get_sysctl(name: str) -> str:
470+
"""
471+
Shell out to sysctl(1)
472+
473+
Returns the value as a string.
474+
Non-leaf nodes will return the value for each sub-node separated by newline characters.
475+
"""
476+
status, stdout, stderr = run_command(["sysctl", "-n", name],
477+
stdout=subprocess.PIPE,
478+
stderr=subprocess.PIPE)
479+
if status != 0:
480+
print("`sysctl` failed: ", end="")
481+
print(stderr.decode())
482+
483+
return stdout.strip().decode()
484+
485+
456486
def is_kvm_supported() -> bool:
457487
"""
458488
Returns True if KVM is supported on this machine
459489
"""
460490

461-
kvm_path = "/dev/kvm"
462491
platform = sys.platform
463492

493+
if platform == "darwin":
494+
# Check for VMX support
495+
cpu_features = get_sysctl("machdep.cpu.features")
496+
vmx_support = "VMX" in cpu_features.split(' ')
497+
498+
# Check for HVF support
499+
hv_support = get_sysctl("kern.hv_support") == "1"
500+
501+
return hv_support and vmx_support
502+
464503
if platform == "linux":
504+
kvm_path = "/dev/kvm"
505+
465506
# Check if the `/dev/kvm` device exists.
466507
if not os.path.exists(kvm_path):
467508
return False

0 commit comments

Comments
 (0)