os-build.sleela
lib/operating-system/os-build.sleela · 211 line(s) · sleela
#sleela 2.5
material;
< os-build.sleela -- the self-contained, runnable demonstrator of the SLeeLa >
< OS-construction family (lib/operating-system/SL*OS*, SL*Spec, SL*Emitter, SLISOBuilder, >
< SLInstallerGenerator). The SLeeLa compiler's `run` compiles one file as a >
< single unit, so this aggregate inlines a compact slice of the model + the >
< emitters and a `main` that: >
< 1. designs a Linux-shaped OS by OOD (name, arch, kernel, rootfs, services), >
< 2. emits the C config header and the C++ OsImage, >
< 3. emits the ISO build recipe and the matching installer, >
< then prints every generated artifact. The split per-class files in this >
< package are the full discovery surface; this file is the executable >
< counterpart, mirroring the website.sleela / data_structures.sleela convention. >
< >
< The point it demonstrates: an operating system is described ONCE as SLeeLa >
< objects, and compiling + running that description yields the C/C++ sources, >
< the ISO recipe, and the installer for the target OS. Changing one call >
< (shape "Linux" -> "Windows"/"macOS") re-shapes every emitted artifact. >
< --- A compact OS model (the OOD aggregate) ------------------------------ >
struct OsModel {
< ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
<< Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
or catalog can read and (where appropriate) override this record.
Values are faithful to the subject's real origin where publicly known. >>
String metaVersion = "1.0.0";
int metaId = 10861;
String metaAuthor = "Kiro Agent";
String metaDate = "2026-10-16";
String metaCopyright = "SLeeLa project";
String metaTrademark = "none";
String metaCorporation = "none";
< metaOrigin: National | <nation> | International | Galactic >
String metaOrigin = "International";
String metaBirthDate = "2026-10-10";
< metaScienceRating: maturity/robustness on a 1..10 scale >
int metaScienceRating = 9;
< metaNationalSchedule: a real, citable instrument or "none" >
String metaNationalSchedule = "none";
String getMetaVersion() { return metaVersion; }
void setMetaVersion(String v) { metaVersion = v; }
int getMetaId() { return metaId; }
void setMetaId(int v) { metaId = v; }
String getAuthor() { return metaAuthor; }
void setAuthor(String v) { metaAuthor = v; }
String getDate() { return metaDate; }
void setDate(String v) { metaDate = v; }
String getCopyright() { return metaCopyright; }
void setCopyright(String v) { metaCopyright = v; }
String getTrademark() { return metaTrademark; }
void setTrademark(String v) { metaTrademark = v; }
String getCorporation() { return metaCorporation; }
void setCorporation(String v) { metaCorporation = v; }
String getOrigin() { return metaOrigin; }
void setOrigin(String v) { metaOrigin = v; }
String getBirthDate() { return metaBirthDate; }
void setBirthDate(String v) { metaBirthDate = v; }
int getScienceRating() { return metaScienceRating; }
void setScienceRating(int v) { metaScienceRating = v; }
String getNationalSchedule() { return metaNationalSchedule; }
void setNationalSchedule(String v) { metaNationalSchedule = v; }
String name; String version; String shape; String arch; String triple;
String loader; String kernel; String cmdline; String rootfs; String init;
String desktop; String packages; String dirs;
}
class OsBuilder {
String intToStr(int v) { return "" + v; }
< OOD extrapolation: fill an OsModel with a shape's defaults, then refine. >
OsModel shape(String name, String version, String family) {
OsModel m = new OsModel();
m.name = name; m.version = version; m.shape = family;
if (family == "Windows") {
m.arch = "amd64"; m.triple = "x86_64-pc-windows-msvc";
m.loader = "BOOTMGR"; m.kernel = "NT"; m.cmdline = "ro quiet";
m.rootfs = "NTFS"; m.init = "ServiceControlManager"; m.desktop = "Explorer";
m.packages = "ntoskrnl 10.0\nwin32-base 10.0\nexplorer 10.0";
m.dirs = "C:/Windows\nC:/Program Files\nC:/Users";
return m;
}
if (family == "macOS") {
m.arch = "arm64"; m.triple = "aarch64-apple-darwin";
m.loader = "boot.efi"; m.kernel = "XNU"; m.cmdline = "ro quiet";
m.rootfs = "APFS"; m.init = "launchd"; m.desktop = "Aqua";
m.packages = "xnu-base 24.0\nlibSystem 24.0\nFinder 24.0";
m.dirs = "/System\n/Library\n/Applications\n/Users";
return m;
}
< Linux shape (default). >
m.arch = "amd64"; m.triple = "x86_64-unknown-linux-gnu";
m.loader = "GRUB"; m.kernel = "Linux"; m.cmdline = "ro quiet splash";
m.rootfs = "ext4"; m.init = "systemd"; m.desktop = "GNOME Shell";
m.packages = "libc 2.39\ncoreutils 9.5\nsystemd 255\ngnome-shell 46";
m.dirs = "/boot\n/etc\n/usr\n/var\n/home\n/proc\n/sys\n/tmp";
return m;
}
String identity(OsModel m) {
return m.name + " " + m.version + " (" + m.shape + ", " + m.arch + ")";
}
< --- C backend: the generated configuration header ------------------- >
String emitConfigHeader(OsModel m) {
String h = "/* os_config.h - generated by SLeeLa lib/os from " + identity(m) + " */\n";
h = h + "#ifndef OS_CONFIG_H\n#define OS_CONFIG_H\n\n";
h = h + "#define OS_NAME \"" + m.name + "\"\n";
h = h + "#define OS_VERSION \"" + m.version + "\"\n";
h = h + "#define OS_SHAPE \"" + m.shape + "\"\n";
h = h + "#define OS_ARCH \"" + m.arch + "\"\n";
h = h + "#define OS_TRIPLE \"" + m.triple + "\"\n";
h = h + "#define OS_LOADER \"" + m.loader + "\"\n";
h = h + "#define OS_KERNEL \"" + m.kernel + "\"\n";
h = h + "#define OS_CMDLINE \"" + m.cmdline + "\"\n";
h = h + "#define OS_ROOTFS \"" + m.rootfs + "\"\n";
h = h + "#define OS_INIT \"" + m.init + "\"\n";
h = h + "#define OS_DESKTOP \"" + m.desktop + "\"\n";
h = h + "\n#endif /* OS_CONFIG_H */\n";
return h;
}
< --- C++ backend: the OsImage that composes the boot chain ----------- >
String emitOsImage(OsModel m) {
String s = "// os_image.cpp - generated by SLeeLa lib/os from " + identity(m) + "\n";
s = s + "#include <string>\nnamespace sleela_os {\n";
s = s + "class OsImage {\npublic:\n";
s = s + " std::string name = \"" + m.name + "\";\n";
s = s + " std::string loader = \"" + m.loader + "\";\n";
s = s + " std::string kernel = \"" + m.kernel + "\";\n";
s = s + " std::string rootfs = \"" + m.rootfs + "\";\n";
s = s + " std::string init = \"" + m.init + "\";\n";
s = s + " int assemble() {\n";
s = s + " if (!firmwareHandoff(loader)) return 1;\n";
s = s + " if (!kernelStart()) return 2;\n";
s = s + " if (!mountRootfs(rootfs)) return 3;\n";
s = s + " startInit(init);\n return 0;\n }\n";
s = s + "private:\n";
s = s + " bool firmwareHandoff(const std::string&);\n";
s = s + " bool kernelStart();\n";
s = s + " bool mountRootfs(const std::string&);\n";
s = s + " void startInit(const std::string&);\n";
s = s + "};\n} // namespace sleela_os\n";
return s;
}
< --- ISO backend: the xorriso build recipe --------------------------- >
String emitIsoRecipe(OsModel m) {
String iso = m.name + "-" + m.version + "-" + m.arch + ".iso";
String r = "#!/bin/sh\n# gen-iso recipe for " + identity(m) + "\nset -eu\n";
r = r + "STAGE=staging/rootfs\nOUT=" + iso + "\n";
r = r + "cc -c gen/os_boot.c -o \"$STAGE/boot/os_boot.o\"\n";
r = r + "c++ -c gen/os_image.cpp -o \"$STAGE/boot/os_image.o\"\n";
r = r + "install-loader --loader " + m.loader + " --esp \"$STAGE/boot/efi\"\n";
r = r + "xorriso -as mkisofs -V " + m.name + "-" + m.version
+ " -o \"$OUT\" -e boot/efi/EFI/BOOT/BOOTX64.EFI -no-emul-boot -J -R \"$STAGE\"\n";
return r;
}
< --- Installer backend: the per-shape installer ---------------------- >
String emitInstaller(OsModel m) {
String iso = m.name + "-" + m.version + "-" + m.arch + ".iso";
if (m.shape == "Windows") {
String s = "#requires -RunAsAdministrator\n# install-windows.ps1 for " + m.name + "\n";
s = s + "param([int]$Target,[switch]$Vm)\n$Iso=\"" + iso + "\"\n";
s = s + "if ($Vm) { qemu-system-x86_64 -m 4096 -cdrom $Iso -boot d -bios OVMF.fd; exit 0 }\n";
s = s + "Clear-Disk -Number $Target -RemoveData -Confirm:$false\n";
s = s + "# ...format " + m.rootfs + ", apply image, bcdboot /f UEFI\n";
return s;
}
String s = "#!/bin/sh\n# install-" + lower(m.shape) + ".sh for " + m.name + "\nset -eu\n";
s = s + "ISO=" + iso + "\nTARGET=\"${1:-}\"\n";
s = s + "if [ \"$TARGET\" = \"--vm\" ]; then qemu-system-x86_64 -m 4096 -cdrom \"$ISO\" -boot d -bios OVMF.fd; exit 0; fi\n";
s = s + "mkfs." + m.rootfs + " \"${TARGET}1\" && mount \"${TARGET}1\" /mnt\n";
s = s + "unpack-rootfs \"$ISO\" /mnt\n";
s = s + "install-loader --loader " + m.loader + " --root /mnt\n";
return s;
}
String lower(String shape) {
if (shape == "macOS") { return "macos"; }
if (shape == "Windows") { return "windows"; }
return "linux";
}
void banner(String title) {
print("================================================================");
print(" " + title);
print("================================================================");
}
void main() {
< 1. Design a Linux-shaped OS by OOD, then refine one field. >
OsModel os = shape("Determinant", "1.0", "Linux");
< product name stays; shape supplies the rest >
os.name = "Determinant";
banner("SLeeLa OS build: " + identity(os));
print("");
banner("C -> gen/os_config.h");
print(emitConfigHeader(os));
banner("C++ -> gen/os_image.cpp");
print(emitOsImage(os));
banner("ISO -> gen-iso recipe");
print(emitIsoRecipe(os));
banner("Installer -> install-linux.sh");
print(emitInstaller(os));
}
}