os/build.py
Mathieu Strypsteen d9860e89a7
All checks were successful
Build / build (push) Successful in 2m48s
Add first syscall and migrate build script to python
2024-12-24 09:27:51 +01:00

40 lines
1.2 KiB
Python
Executable file

#!/usr/bin/env python3
import os
import shutil
import subprocess
def run_command(cmd, cwd=None):
subprocess.run(cmd, shell=True, check=True, cwd=cwd)
def main():
target = os.environ.get("OS_TARGET", "release")
if os.path.exists("img"):
shutil.rmtree("img")
os.makedirs("img/boot/efi/boot")
run_command("make -j4", cwd="lib/acpica-build")
components = ["init", "kernel", "loader"]
for component in components:
cargo_cmd = f'cargo build {"--release" if target == "release" else ""}'
run_command(cargo_cmd, cwd=component)
loader_path = f"target/x86_64-unknown-uefi/{target}/loader.efi"
shutil.copy(loader_path, "img/boot/efi/boot/bootx64.efi")
os.chdir("img")
run_command("dd if=/dev/zero of=boot.img bs=1M count=16 status=none")
run_command("mformat -i boot.img")
run_command("mcopy -si boot.img boot/* ::")
run_command("dd if=/dev/zero of=os.img bs=1M count=32 status=none")
run_command("parted -s os.img mklabel gpt")
run_command("parted -s os.img mkpart primary fat32 2048s 100%")
run_command("parted -s os.img set 1 esp on")
run_command("dd if=boot.img of=os.img bs=1M seek=1 conv=notrunc status=none")
if __name__ == "__main__":
main()