-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJustfile
186 lines (164 loc) · 6.29 KB
/
Justfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# Configuration variables
test-crates := "utils"
rust-profile := "debug"
# Directory and file paths
kernel-dir := "kernel"
iso-root := "iso_root"
ovmf-dir := "ovmf"
limine-dir := "limine"
iso-file := "funderberker.iso"
kernel-bin := "funderberker"
# File paths
ovmf-code := ovmf-dir + "/ovmf-code-x86_64.fd"
ovmf-vars := ovmf-dir + "/ovmf-vars-x86_64.fd"
limine-binary := limine-dir + "/limine"
# Rust flags
rustflags := "-C relocation-model=static"
features := "default"
# Default recipe (runs when just is called without arguments)
default: build
# Help message
help:
@echo "Funderberker OS Build System"
@echo ""
@echo "Available recipes:"
@echo " default - Build the kernel and create bootable ISO"
@echo " build - Same as 'default'"
@echo " run - Build and run in QEMU"
@echo " debug - Build and run in QEMU with debug output"
@echo " test - Build and run kernel tests in QEMU"
@echo " crates-test - Run other crates' unit tests"
@echo " clean - Remove all build artifacts"
@echo " media - Write the compiled ISO to a USB device"
@echo " media-test - Write the test compiled ISO to a USB device"
@echo ""
@echo "Configuration:"
@echo " rust-profile=debug|release (current: {{rust-profile}})"
@echo " test-crates='{{test-crates}}'"
# Build the kernel based on profile
build-kernel:
#!/usr/bin/env bash
if [ "{{rust-profile}}" = "debug" ]; then
RUSTFLAGS="{{rustflags}} -g" cargo +nightly build --manifest-path="kernel/Cargo.toml" --features {{features}} --target x86_64-unknown-none
elif [ "{{rust-profile}}" = "release" ]; then
RUSTFLAGS="{{rustflags}}" cargo +nightly build --manifest-path="kernel/Cargo.toml" --release --features {{features}} --target x86_64-unknown-none
else
echo "Error: Invalid rust-profile '{{rust-profile}}'. Must be 'debug' or 'release'."
exit 1
fi
BIN=`find kernel/target/x86_64-unknown-none -type f -executable -name "kernel" | head -n 1`
cp $BIN {{kernel-bin}}
# Build the kernel tests
build-kernel-test: clean
#!/usr/bin/env bash
pwd
if [ "{{rust-profile}}" = "debug" ]; then
RUSTFLAGS="{{rustflags}}" cargo +nightly test --manifest-path="kernel/Cargo.toml" --features {{features}} --no-run --target x86_64-unknown-none
elif [ "{{rust-profile}}" = "release" ]; then
RUSTFLAGS="{{rustflags}}" cargo +nightly test --manifest-path="kernel/Cargo.toml" --features {{features}} --no-run --release --target x86_64-unknown-none
else
echo "Error: Invalid rust-profile '{{rust-profile}}'. Must be 'debug' or 'release'."
exit 1
fi
BIN=`find kernel/target/x86_64-unknown-none -type f -executable -name "kernel-*" | head -n 1`
cp $BIN {{kernel-bin}}
# Run crate tests
crates-test:
#!/usr/bin/env bash
for crate in {{test-crates}}; do
cargo test --manifest-path="$crate/Cargo.toml"
done
build-test: build-kernel-test _create-iso-common
# Build everything
build: build-kernel _create-iso-common
# Run kernel tests and launch in QEMU
test: build-test
@just _run-qemu
# Run in QEMU
run: build
@just _run-qemu
# Run with debugging enabled
debug: build
@just _run-qemu-debug
# Write a test compiled ISO to a USB device
media-test: build-test _media
# Write the compiled ISO to a USB device
media: build _media
# Helper recipe for writing ISO to USB device
_media:
#!/usr/bin/env bash
lsblk
read -p "Enter device (in the format /dev/<...>):" DEVICE
while true; do
read -p "WARNING - everything on '$DEVICE' WILL be deleted. Are you OK with that? (y/n)" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo "Exiting..."; exit;;
* ) echo "Please answer yes or no.";;
esac
done
sudo dd if={{iso-file}} of=$DEVICE bs=4M status=progress oflag=sync
# Helper recipe for running QEMU
_run-qemu: _download-firmware
qemu-system-x86_64 \
-vga virtio \
-nodefaults \
-serial stdio \
-no-reboot \
-drive if=pflash,unit=0,format=raw,file={{ovmf-code}},readonly=on \
-drive if=pflash,unit=1,format=raw,file={{ovmf-vars}} \
-cdrom {{iso-file}}
# Helper recipe for running QEMU with debug
_run-qemu-debug: _download-firmware
qemu-system-x86_64 \
-vga virtio \
-nodefaults \
-serial stdio \
-no-reboot \
-drive if=pflash,unit=0,format=raw,file={{ovmf-code}},readonly=on \
-drive if=pflash,unit=1,format=raw,file={{ovmf-vars}} \
-cdrom {{iso-file}} \
-d in_asm,int -D qemu.log -s -S\
# Common ISO creation steps
_create-iso-common: _setup-limine
rm -rf {{iso-root}}
mkdir -p {{iso-root}}/boot
cp -v {{kernel-bin}} {{iso-root}}/boot/
# rm {{kernel-bin}}
mkdir -p {{iso-root}}/boot/limine
cp -v limine.conf {{iso-root}}/boot/limine/
mkdir -p {{iso-root}}/EFI/BOOT
cp -v {{limine-dir}}/limine-bios.sys {{limine-dir}}/limine-bios-cd.bin {{limine-dir}}/limine-uefi-cd.bin {{iso-root}}/boot/limine/
cp -v {{limine-dir}}/BOOTX64.EFI {{iso-root}}/EFI/BOOT/
cp -v {{limine-dir}}/BOOTIA32.EFI {{iso-root}}/EFI/BOOT/
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 \
{{iso-root}} -o {{iso-file}}
./{{limine-dir}}/limine bios-install {{iso-file}}
# Clean build artifacts
clean:
-rm -f {{kernel-bin}}
-rm -f {{iso-file}}
-rm -rf {{iso-root}}
cargo clean --manifest-path=kernel/Cargo.toml
# Download UEFI firmware files
_download-firmware:
#!/usr/bin/env bash
if [ ! -f "{{ovmf-code}}" ]; then
mkdir -p {{ovmf-dir}}
curl -Lo {{ovmf-code}} https://github.com/osdev0/edk2-ovmf-nightly/releases/latest/download/ovmf-code-x86_64.fd
fi
if [ ! -f "{{ovmf-vars}}" ]; then
mkdir -p {{ovmf-dir}}
curl -Lo {{ovmf-vars}} https://github.com/osdev0/edk2-ovmf-nightly/releases/latest/download/ovmf-vars-x86_64.fd
fi
# Clone and build Limine bootloader
_setup-limine:
#!/usr/bin/env bash
if [ ! -f "{{limine-binary}}" ]; then
rm -rf {{limine-dir}}
git clone https://github.com/limine-bootloader/limine.git --branch=v8.x-binary --depth=1 {{limine-dir}}
make -C {{limine-dir}}
fi