Skip to content

Commit 1b0270f

Browse files
Enforced kernel and userland version sync (#65)
Summary: This change makes the ThunderOS userland build use the kernel's recorded version metadata and fail fast when the generated userland header drifts from the kernel VERSION. Changes: - Generated `external/userland/build/generated/thunderos_version.h` from the ThunderOS `VERSION` file during `make userland` - Added a clean fallback when `VERSION_CODENAME` is absent - Added `make check-abi-version` and ran it automatically after the userland build - Kept the userland banner/version header aligned with the kernel version that ships with it Testing: - `bash -n build_userland.sh` - `git diff --check` - `make userland` - `make check-abi-version`
2 parents c6f8183 + 518dc84 commit 1b0270f

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ DOCKER_USER ?= $(shell id -u):$(shell id -g)
118118
FS_IMG := $(BUILD_DIR)/fs.img
119119
FS_SIZE := 10M
120120

121-
.PHONY: all clean run debug fs userland test test-quick help docker-build-env docker-verify docker-shell
121+
.PHONY: all clean run debug fs userland check-abi-version test test-quick help docker-build-env docker-verify docker-shell
122122

123123
# Default target - must be first
124124
all: $(KERNEL_ELF) $(KERNEL_BIN)
@@ -292,9 +292,22 @@ userland:
292292
@echo "$(BOLD)$(BLUE)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━$(RESET)"
293293
@chmod +x build_userland.sh
294294
@./build_userland.sh
295+
@$(MAKE) --no-print-directory check-abi-version
295296
@echo "$(BOLD)$(BLUE)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━$(RESET)"
296297
@echo ""
297298

299+
check-abi-version:
300+
@kernel_ver=$$(tr -d '\n' < VERSION); \
301+
userland_ver=$$(sed -n 's/^#define THUNDEROS_VERSION_STRING "\(.*\)"/\1/p' external/userland/build/generated/thunderos_version.h 2>/dev/null || echo 'MISSING'); \
302+
if [ "$$kernel_ver" != "$$userland_ver" ]; then \
303+
echo "$(RED)✗ ABI version mismatch:$(RESET) kernel=$$kernel_ver userland=$$userland_ver"; \
304+
echo " The userland was built against a different kernel version."; \
305+
echo " Run 'make userland' to rebuild with the current kernel version."; \
306+
exit 1; \
307+
else \
308+
echo "$(GREEN)✓ ABI version match:$(RESET) kernel=$$kernel_ver userland=$$userland_ver"; \
309+
fi
310+
298311
test:
299312
@cd tests/scripts && bash test_runner.sh
300313

build_userland.sh

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ readonly OBJCOPY="${CROSS_COMPILE}objcopy"
1010

1111
readonly USERLAND_DIR="$(cd "$(dirname "$0")" && pwd)/external/userland"
1212
readonly BUILD_DIR="${USERLAND_DIR}/build"
13+
readonly REPO_ROOT="$(cd "$(dirname "$0")" && pwd)"
14+
readonly GENERATED_DIR="${USERLAND_DIR}/build/generated"
1315

14-
readonly CFLAGS="-march=rv64gc -mabi=lp64d -nostdlib -nostartfiles -ffreestanding -fno-common -O0 -g -Wall"
16+
readonly CFLAGS="-march=rv64gc -mabi=lp64d -nostdlib -nostartfiles -ffreestanding -fno-common -O0 -g -Wall -I${GENERATED_DIR}"
1517
readonly LDFLAGS="-nostdlib -static"
1618
readonly LDSCRIPT="${USERLAND_DIR}/lib/user.ld"
1719

@@ -83,6 +85,28 @@ build_program() {
8385

8486
# Create build directory
8587
mkdir -p "${BUILD_DIR}"
88+
mkdir -p "${GENERATED_DIR}"
89+
90+
# Generate version header from the kernel VERSION file so userland
91+
# binaries always report the same version as the kernel they ship with.
92+
kernel_version="$(tr -d '\n' < "${REPO_ROOT}/VERSION")"
93+
if [[ -f "${REPO_ROOT}/VERSION_CODENAME" ]]; then
94+
kernel_codename="$(tr -d '\n' < "${REPO_ROOT}/VERSION_CODENAME")"
95+
else
96+
kernel_codename="ThunderOS"
97+
fi
98+
cat > "${GENERATED_DIR}/thunderos_version.h" <<VEOF
99+
#ifndef THUNDEROS_VERSION_METADATA_H
100+
#define THUNDEROS_VERSION_METADATA_H
101+
102+
#define THUNDEROS_VERSION_STRING "${kernel_version}"
103+
#define THUNDEROS_VERSION_TAG "v${kernel_version}"
104+
#define THUNDEROS_VERSION_CODENAME "${kernel_codename}"
105+
#define THUNDEROS_RELEASE_LABEL "v${kernel_version} ${kernel_codename}"
106+
107+
#endif
108+
VEOF
109+
echo -e "${GREEN}${NC} Version header: v${kernel_version} (${kernel_codename})"
86110

87111
print_header
88112

0 commit comments

Comments
 (0)