Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
154 lines (133 loc) · 6.07 KB
/
Copy pathMakefile
File metadata and controls
154 lines (133 loc) · 6.07 KB
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
ARCH ?= x64
TIMEOUT ?= 30
KERNEL ?= HelloWorld
OUTPUT := ./output-$(ARCH)
ifeq ($(ARCH),arm64)
RID := linux-arm64
DEFINE := ARCH_ARM64
COSMOS_ARCH := arm64
QEMU := qemu-system-aarch64 -M virt,gic-version=3 -cpu cortex-a72 -m 512M \
-bios ~/.cosmos/tools/qemu/share/qemu/edk2-aarch64-code.fd
DEV_QEMU := qemu-system-aarch64 -M virt,highmem=off,gic-version=3 -cpu cortex-a53 -m 1G \
-bios ~/.cosmos/tools/qemu/share/qemu/edk2-aarch64-code.fd
DEV_ISO_FLAGS := -drive if=none,id=cd,file=$(OUTPUT)/DevKernel.iso \
-device virtio-scsi-pci -device scsi-cd,drive=cd,bootindex=0 \
-device virtio-keyboard-device -device virtio-mouse-device \
-device ramfb -serial stdio
DEV_READY := QEMU-DEVKERNEL-ARM64-DEBUG-READY
else
RID := linux-x64
DEFINE := ARCH_X64
COSMOS_ARCH := x64
# KVM when the host exposes it (TCG is ~10x slower and tanks guest FPS);
# -cpu host needs KVM, so the TCG fallback keeps -cpu max (CI, containers).
KVM_FLAGS := $(shell test -w /dev/kvm && echo "-enable-kvm -cpu host" || echo "-cpu max")
QEMU := qemu-system-x86_64 $(KVM_FLAGS)
DEV_QEMU := qemu-system-x86_64 -M q35 $(KVM_FLAGS) -m 512M
DEV_ISO_FLAGS := -drive file=$(OUTPUT)/DevKernel.iso,if=none,id=cosmoscd,format=raw,readonly=on \
-device ide-cd,drive=cosmoscd,bootindex=0 \
-vga std -device i8042 -serial stdio
DEV_READY := QEMU-DEVKERNEL-DEBUG-READY
endif
DEVKERNEL := ./examples/DevKernel/DevKernel.csproj
TEST_ENGINE := ./tests/Cosmos.TestRunner.Engine/Cosmos.TestRunner.Engine.csproj
DOCS_DIR := ./docs
DOCS_PORT ?= 8080
# The translated sites, one docfx project each under docs/<lang>/.
DOCS_LANGS := $(patsubst $(DOCS_DIR)/%/docfx.json,%,$(wildcard $(DOCS_DIR)/*/docfx.json))
# Same pinned version as .github/workflows/build-docs.yml.
DOCFX_VERSION := 2.81.0
# Cosmos.Kernel transitively project-references every project DocFX reads, so
# restoring it alone covers the metadata step. Restoring the slnx instead pulls
# in examples/DevKernel, whose NuGet.Config needs artifacts/package/release.
DOCS_RESTORE := ./src/Cosmos.Kernel/Cosmos.Kernel.csproj
AHCI_IMG := disk-ahci.img
NVME_IMG := disk-nvme.img
DEV_DISK_FLAGS := -drive file=$(AHCI_IMG),if=none,id=ahcidisk,format=raw \
-device ich9-ahci,id=ahci0 \
-device ide-hd,drive=ahcidisk,bus=ahci0.0 \
-drive file=$(NVME_IMG),if=none,id=nvmedisk,format=raw \
-device nvme,drive=nvmedisk,serial=cosmos-nvme
.PHONY: setup build clean distclean run run-dev debug-dev disks test test-cache api \
docs docs-serve docs-clean
setup:
./.devcontainer/postCreateCommand.sh
# Reseed the PublicAPI.*.txt files of the API-tracked projects: builds the
# project, then applies the RS0016/RS0017 code fixes (declare new public
# symbols, drop deleted ones). Run after any deliberate public surface change.
api:
dotnet format analyzers src/Cosmos.Kernel.System/Cosmos.Kernel.System.csproj \
--diagnostics RS0016 RS0017 --severity info
dotnet format analyzers src/Cosmos.Kernel.Core/Cosmos.Kernel.Core.csproj \
--diagnostics RS0016 RS0017 --severity info
dotnet format analyzers src/Cosmos.Kernel.HAL/Cosmos.Kernel.HAL.csproj \
--diagnostics RS0016 RS0017 --severity info
dotnet format analyzers src/Cosmos.Kernel.Drivers/Cosmos.Kernel.Drivers.csproj \
--diagnostics RS0016 RS0017 --severity info
build:
dotnet publish -c Debug -r $(RID) \
-p:DefineConstants="$(DEFINE)" -p:CosmosArch=$(COSMOS_ARCH) \
$(DEVKERNEL) -o $(OUTPUT)
clean:
rm -rf ./output-x64 ./output-arm64 uart.log
distclean: clean
rm -rf ./artifacts
dotnet nuget remove source local-packages 2>/dev/null || true
rm -rf ~/.nuget/packages/cosmos.* 2>/dev/null || true
run: build
@echo "Starting QEMU ($(ARCH))... Press Ctrl+A X to exit."
@QEMU_PID=""; \
trap 'test -n "$$QEMU_PID" && kill $$QEMU_PID 2>/dev/null || true' EXIT; \
$(QEMU) \
-cdrom $(OUTPUT)/DevKernel.iso \
-boot d \
-m 512M \
-serial file:uart.log \
-nographic \
-no-reboot \
-no-shutdown & \
QEMU_PID=$$!; \
sleep $(TIMEOUT); \
echo "Stopping QEMU..."; \
kill $$QEMU_PID 2>/dev/null || true
$(AHCI_IMG) $(NVME_IMG):
truncate -s 256M $@
disks: $(AHCI_IMG) $(NVME_IMG)
run-dev: build disks
$(DEV_QEMU) $(DEV_ISO_FLAGS) $(DEV_DISK_FLAGS) -no-reboot -no-shutdown
debug-dev: build disks
# @ so make does NOT echo the recipe text: the VSCode background
# matcher's endsPattern would fire on the echoed $(DEV_READY) before
# QEMU listens on :1234, bypassing the sleep gate and handing gdb a
# connection-refused. The deliberate post-sleep echo below must be the
# only READY occurrence in the output.
@$(DEV_QEMU) $(DEV_ISO_FLAGS) $(DEV_DISK_FLAGS) -s -S -no-reboot -no-shutdown & \
sleep 1; \
echo "$(DEV_READY)"; \
wait
test:
dotnet build $(TEST_ENGINE) -c Debug
dotnet run --project $(TEST_ENGINE) --no-build \
-- tests/Kernels/Cosmos.Kernel.Tests.$(KERNEL) $(ARCH) $(TIMEOUT) \
test-results-$(KERNEL)-$(ARCH).xml ci
test-cache:
dotnet test tests/Cosmos.Tests.BuildCache/ -c Debug
# Generate the API metadata and render the static site into docs/_site, then
# each translation into docs/_site/<lang> (after the English site, whose
# metadata pass writes the API pages they reuse), then report the translations
# that fell behind the English pages.
docs:
@command -v docfx >/dev/null 2>&1 || dotnet tool update -g docfx --version $(DOCFX_VERSION)
dotnet restore $(DOCS_RESTORE)
cd $(DOCS_DIR) && docfx docfx.json
for lang in $(DOCS_LANGS); do (cd $(DOCS_DIR) && docfx $$lang/docfx.json) || exit 1; done
python3 .github/scripts/docs-i18n.py check
# Serve the built site on http://localhost:$(DOCS_PORT) (Ctrl+C to stop).
docs-serve: docs
@echo "Serving docs on http://localhost:$(DOCS_PORT) - Ctrl+C to stop."
docfx serve $(DOCS_DIR)/_site --port $(DOCS_PORT)
# Drop the generated site and the generated api/*.yml (both gitignored).
docs-clean:
rm -rf $(DOCS_DIR)/_site
find $(DOCS_DIR)/api -name '*.yml' -delete
rm -f $(DOCS_DIR)/api/.manifest