135 lines
4.4 KiB
Zig
135 lines
4.4 KiB
Zig
// SPDX-License-Identifier: LCL-1.0
|
|
// Copyright (c) 2026 Markus Maiwald
|
|
// Stewardship: Self Sovereign Society Foundation
|
|
//
|
|
// This file is part of the Nexus Commonwealth.
|
|
// See legal/LICENSE_COMMONWEALTH.md for license terms.
|
|
|
|
//! Rumpk Build System
|
|
//!
|
|
//! Orchestrates L0 (Zig) and L1 (Nim) compilation.
|
|
//! Builds the Hardware Abstraction Layer as a static library.
|
|
|
|
const std = @import("std");
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
const target = b.standardTargetOptions(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
// =========================================================
|
|
// L0: Hardware Abstraction Layer (Zig)
|
|
// =========================================================
|
|
|
|
// NOTE(Build): Zig 0.15.x API - using addLibrary with static linkage
|
|
const hal_mod = b.createModule(.{
|
|
.root_source_file = b.path("hal/abi.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
// Freestanding kernel - no libc, no red zone, no stack checks
|
|
hal_mod.red_zone = false;
|
|
hal_mod.stack_check = false;
|
|
hal_mod.code_model = .medany;
|
|
|
|
const hal = b.addLibrary(.{
|
|
.name = "rumpk_hal",
|
|
.root_module = hal_mod,
|
|
.linkage = .static,
|
|
});
|
|
|
|
b.installArtifact(hal);
|
|
|
|
// TODO(Build): Microui needs stdio.h stubs for freestanding.
|
|
// Re-enable after creating libs/microui/stdio_stub.h
|
|
// Microui Integration (Phase 3.5b)
|
|
// hal_mod.addIncludePath(b.path("libs/microui"));
|
|
// hal_mod.addCSourceFile(.{
|
|
// .file = b.path("libs/microui/microui.c"),
|
|
// .flags = &.{"-std=c99"},
|
|
// });
|
|
|
|
// =========================================================
|
|
// Boot: Entry Point (Assembly + Zig)
|
|
// =========================================================
|
|
|
|
const boot_mod = b.createModule(.{
|
|
.root_source_file = b.path("boot/header.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
boot_mod.red_zone = false;
|
|
boot_mod.stack_check = false;
|
|
boot_mod.code_model = .medany;
|
|
|
|
const boot = b.addObject(.{
|
|
.name = "boot",
|
|
.root_module = boot_mod,
|
|
});
|
|
|
|
// =========================================================
|
|
// Final Link: rumpk.elf
|
|
// =========================================================
|
|
|
|
const kernel_mod = b.createModule(.{
|
|
.root_source_file = b.path("hal/abi.zig"), // Fake root, we add objects later
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
kernel_mod.red_zone = false;
|
|
kernel_mod.stack_check = false;
|
|
kernel_mod.code_model = .medany;
|
|
|
|
const kernel = b.addExecutable(.{
|
|
.name = "rumpk.elf",
|
|
.root_module = kernel_mod,
|
|
});
|
|
|
|
kernel.setLinkerScript(b.path("boot/linker.ld"));
|
|
kernel.addObject(boot);
|
|
// kernel.linkLibrary(hal); // Redundant, already in kernel_mod
|
|
|
|
// Add Nim-generated objects
|
|
{
|
|
var nimcache_dir = std.fs.cwd().openDir("build/nimcache", .{ .iterate = true }) catch |err| {
|
|
std.debug.print("Warning: Could not open nimcache dir: {}\n", .{err});
|
|
return;
|
|
};
|
|
defer nimcache_dir.close();
|
|
var it = nimcache_dir.iterate();
|
|
while (it.next() catch null) |entry| {
|
|
if (entry.kind == .file and std.mem.endsWith(u8, entry.name, ".o")) {
|
|
const path = b.fmt("build/nimcache/{s}", .{entry.name});
|
|
kernel.addObjectFile(b.path(path));
|
|
}
|
|
}
|
|
}
|
|
|
|
// Add external pre-built dependencies (Order matters: Libs after users)
|
|
kernel.addObjectFile(b.path("build/switch.o")); // cpu_switch_to
|
|
kernel.addObjectFile(b.path("build/sys_arch.o")); // sys_now, nexus_lwip_panic
|
|
kernel.addObjectFile(b.path("build/libc_shim.o"));
|
|
kernel.addObjectFile(b.path("build/clib.o"));
|
|
kernel.addObjectFile(b.path("build/liblwip.a"));
|
|
kernel.addObjectFile(b.path("build/initrd.o"));
|
|
|
|
b.installArtifact(kernel);
|
|
|
|
// =========================================================
|
|
// Tests
|
|
// =========================================================
|
|
|
|
const test_mod = b.createModule(.{
|
|
.root_source_file = b.path("hal/abi.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
|
|
const hal_tests = b.addTest(.{
|
|
.root_module = test_mod,
|
|
});
|
|
|
|
const run_tests = b.addRunArtifact(hal_tests);
|
|
const test_step = b.step("test", "Run Rumpk HAL tests");
|
|
test_step.dependOn(&run_tests.step);
|
|
}
|