Replace Makefile

This commit is contained in:
River 2025-05-07 19:01:21 -04:00
parent a2de95687f
commit 6521d41aa5
Signed by: shibedrill
GPG Key ID: 5FE0CB25945EFAA2
8 changed files with 111 additions and 136 deletions

1
.envrc
View File

@ -1 +0,0 @@
use nix

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/target
/build
.idea

View File

@ -1,5 +1,4 @@
{
"rust-analyzer.cargo.target": "x86_64-unknown-none",
"rust-analyzer.check.allTargets": false,
"makefile.configureOnOpen": false
}

View File

@ -1,91 +0,0 @@
# Default target is x86_64-unknown-none
TARGET ?= "x86_64-unknown-none"
# Limine BIOS file directory
LIMINEDIR ?= "/usr/share/limine"
# QEMU system is set accordingly and automatically
qemu = "qemu-system-x86_64"
# List of required BIOS files
limine-files = limine-bios.sys limine-bios-cd.bin limine-bios-uefi-cd.bin BOOTX64.EFI BOOTIA32.EFI BOOTAA64.EFI BOOTLOONGARCH64.EFI BOOTRISCV64.EFI
# Properly set QEMU command
ifeq ($(TARGET),x86_64-unknown-none)
qemu = "qemu-system-x86_64"
else ifeq ($(TARGET),riscv64gc-unknown-none-elf)
qemu = "qemu-system-riscv64"
else ifeq ($(TARGET),aarch64-unknown-none)
qemu = "qemu-system-aarch64"
qemu += "-machine"
qemu += "orangepi-pc"
else ifeq ($(TARGET),loongarch64-unknown-none)
qemu = "qemu-system-loongarch64"
endif
executables = rustup xorriso limine tree $(qemu)
all: kernel iso run
checkenv:
$(info "Limine directory: $(LIMINEDIR)")
$(foreach file,$(limine-files),\
$(if $(shell test -f $(LIMINEDIR)/$(file) | echo "it exists"),$(info "Found $(file)"),$(error "No $(file) in $(LIMINEDIR)")))
$(foreach exec,$(executables),\
$(if $(shell which $(exec)),$(info "Found $(exec)"),$(error "No $(exec) in PATH")))
# Prepare toolchain
prepare: checkenv
rustup install nightly
rustup target add $(TARGET)
# Run the ISO in an emulator.
run: iso
$(qemu) -drive file=build/gila.iso,format=raw,index=0,media=disk
# Build the bootable kernel image.
.PHONY: build/kernel
kernel: prepare $(shell find src/kernel/ -type f -name *.rs) $(shell find src/kernel/ -type f -name linker.ld)
cargo build --bin kernel --release -Zunstable-options --artifact-dir=build
# Build a bootable ISO and install Limine.
.PHONY: build/gila.iso
iso: kernel limine.conf
mkdir -p build/iso/boot/limine
mkdir -p build/iso/EFI/BOOT
# Copy Limine files
cp ./limine.conf build/iso/
cp $(LIMINEDIR)/limine-bios.sys build/iso/boot/limine/
cp $(LIMINEDIR)/limine-bios-cd.bin build/iso/boot/limine/
cp $(LIMINEDIR)/limine-uefi-cd.bin build/iso/boot/limine/
cp $(LIMINEDIR)/BOOTX64.EFI build/iso/EFI/BOOT/
cp $(LIMINEDIR)/BOOTIA32.EFI build/iso/EFI/BOOT/
cp $(LIMINEDIR)/BOOTAA64.EFI build/iso/EFI/BOOT/
cp $(LIMINEDIR)/BOOTLOONGARCH64.EFI build/iso/EFI/BOOT
cp $(LIMINEDIR)/BOOTRISCV64.EFI build/iso/EFI/BOOT
# Copy kernel
mv build/kernel build/iso/boot/
# Build filesystem tree
mkdir -p build/iso/system/bin
mkdir -p build/iso/system/tmp
mkdir -p build/iso/system/cfg
xorriso -as mkisofs -b boot/limine/limine-bios-cd.bin -no-emul-boot \
-boot-load-size 4 -boot-info-table --efi-boot \
boot/limine/limine-uefi-cd.bin -efi-boot-part --efi-boot-image \
--protective-msdos-label build/iso -o build/gila.iso
limine bios-install build/gila.iso
tree build/iso/
clean:
rm -rf build
cargo clean

97
Makefile.toml Normal file
View File

@ -0,0 +1,97 @@
env_scripts = [
'''
#!@duckscript
if eq ${TARGET} "x86_64-unknown-none"
set_env QEMUCOMMAND "qemu-system-x86_64"
set_env LIMINEBIN "BOOTX64.EFI"
else if eq ${TARGET} "aarch64-unknown-none"
set_env QEMUCOMMAND "qemu-system-aarch64"
set_env LIMINEBIN "BOOTAA64.EFI"
else if eq ${TARGET} "riscv64gc-unknown-none-elf"
set_env QEMUCOMMAND "qemu-system-riscv64"
set_env LIMINEBIN "BOOTRISCV64.EFI"
else if eq ${TARGET} "loongarch64-unknown-none"
set_env QEMUCOMMAND "qemu-system-loongarch64"
set_env LIMINEBIN "BOOTLOONGARCH64.EFI"
end
'''
]
[env]
LIMINEDIR = "/usr/share/limine"
TARGET = "x86_64-unknown-none"
[env.development]
PROFILE = "dev"
TARGETDIR = "debug"
[env.release]
PROFILE = "release"
TARGETDIR = "release"
[tasks.default]
alias = "run"
[tasks.clean]
dependencies = ["cleaniso"]
command = "cargo"
args = ["clean"]
[tasks.prepare]
script = "rustup install nightly; rustup target add ${TARGET}"
[tasks.cleaniso]
command = "rm"
args = ["-rf", "build"]
[tasks.kernel]
condition = { files_modified = { input = ["./src/**/*.rs", "./src/**/*.ld"], output = ["./target/${TARGET}/${TARGETDIR}/kernel"] }, fail_message = "(inputs unchanged)"}
dependencies = ["prepare"]
command = "cargo"
args = ["build", "--profile", "${PROFILE}", "--bin", "kernel"]
[tasks.iso]
condition = { files_modified = { input = [
"./target/${TARGET}/${TARGETDIR}/kernel",
"./limine.conf",
"${LIMINEDIR}/limine-bios.sys",
"${LIMINEDIR}/limine-bios-cd.bin",
"${LIMINEDIR}/limine-uefi-cd.bin",
"${LIMINEDIR}/${LIMINEBIN}"
], output = ["./build/gila.iso"] }, fail_message = "(inputs unchanged)" }
dependencies = ["kernel"]
script = '''
#!@shell
mkdir -p build/iso/boot/limine
mkdir -p build/iso/EFI/BOOT
cp ./limine.conf build/iso/
cp ${LIMINEDIR}/limine-bios.sys build/iso/boot/limine/
cp ${LIMINEDIR}/limine-bios-cd.bin build/iso/boot/limine/
cp ${LIMINEDIR}/limine-uefi-cd.bin build/iso/boot/limine/
cp ${LIMINEDIR}/${LIMINEBIN} build/iso/EFI/BOOT
cp target/${TARGET}/${TARGETDIR}/kernel build/iso/boot/
mkdir -p build/iso/system/bin
mkdir -p build/iso/system/tmp
mkdir -p build/iso/system/cfg
xorriso -as mkisofs \
-b boot/limine/limine-bios-cd.bin \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
--efi-boot boot/limine/limine-uefi-cd.bin \
-efi-boot-part \
--efi-boot-image \
--protective-msdos-label build/iso \
-o build/gila.iso
limine bios-install build/gila.iso
'''
[tasks.run]
dependencies = ["iso"]
command = "${QEMUCOMMAND}"
args = ["-drive", "file=build/gila.iso,format=raw,index=0,media=disk"]

View File

@ -65,26 +65,23 @@ To build an ISO image that you can boot, there are several prerequisites:
- `rustup` command installed
- `limine` command installed
- `xorriso` command installed
- `make` command installed
- `cargo-make` command installed (`cargo install cargo-make`)
- `qemu-system-{your target architecture}` command installed (for running)
Then run `make` to invoke the [Makefile](Makefile).
Then run `cargo make` to invoke the [Makefile.toml](Makefile.toml).
- `make checkenv`: Asserts all needed commands and resources are accessible.
- `make prepare`: Installs needed Rust toolchain.
- `make clean`: Cleans all built binaries, libraries, and ISOs.
- `make kernel`: Builds the kernel ELF file.
- `make iso`: Builds the bootable ISO with Limine installed.
- `make run`: Builds the ISO and boots it in QEMU.
- `cargo make prepare`: Installs needed Rust toolchain.
- `cargo make clean`: Cleans all built binaries, libraries, and ISOs.
- `cargo make cleaniso`: Clean only files involved in building the ISO.
- `cargo make kernel`: Builds the kernel ELF file.
- `cargo make iso`: Builds the bootable ISO with Limine installed.
- `cargo make run`: Builds the ISO and boots it in QEMU.
To change the target gila will be compiled or run for, supply `TARGET={valid-rustc-targettriple}` either as an argument to `make` or as an environment variable. The default is `x86_64-unknown-none`.
To change the target gila will be compiled or run for, supply `TARGET={valid-rustc-targettriple}` as an environment variable to `cargo make`. The default is `x86_64-unknown-none`.
To change the search path for limine's binaries, supply `LIMINEDIR=/some/valid/path/no/trailing/slash` either as an argument to `make` or as an environment variable. The default is `/usr/share/limine`.
To change the search path for limine's binaries, supply `LIMINEDIR={/abs/path/no/trailing/slash}` as an environment variable to `cargo make`. The default is `/usr/share/limine`.
If you use Nix, you can install all these dependencies automatically by running `nix-shell`. This will also automatically set the correct directory for the limine BIOS files.
> [!IMPORTANT]
> **I do not, and cannot, currently recommend using `nix` for dependency management.** `nixpkgs` does not ship all of the necessary files in its packaging of limine.
To change the development profile from `dev` to `release`, supply `-p {profile}` as an argument to `cargo make` **BEFORE** the task name.
## Kernel Parameters

View File

@ -1,27 +0,0 @@
let
nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz";
pkgs = import nixpkgs { config = {}; overlays = []; };
in
pkgs.mkShell {
packages = with pkgs; [
bash
limine.dev
xorriso
rustup
qemu
gnumake
];
buildInputs = with pkgs; [
limine.dev
];
shellHook = ''
rustup default nightly;
rustup target add x86_64-unknown-none
export LIMINEDIR="${pkgs.limine}/share/limine"
'';
}