summaryrefslogtreecommitdiffstats
path: root/rsnix/build.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-07-31 02:58:31 +0200
committersalmonik <salmonik@tuta.io>2026-07-31 02:58:31 +0200
commit6a5c32fa6ae8ec34e3e5b44d7e5a78ded8fe729b (patch)
treeed59a5bd59a94b3a731b28c68c507f18afc44b0b /rsnix/build.rs
parentauto-version all strings from Cargo.toml via env!("CARGO_PKG_VERSION") (diff)
downloadrs-dos-6a5c32fa6ae8ec34e3e5b44d7e5a78ded8fe729b.tar.gz
rs-dos-6a5c32fa6ae8ec34e3e5b44d7e5a78ded8fe729b.zip
restructure: rsnix kernel + shell crate + rsdos entry point
Architecture: rs-dos/ (workspace root, was raisernics/) ├── rsnix/ — kernel lib crate (uefi, serial, gop, ps2, interrupts, memory) ├── shell/ — shell lib crate (prompt, commands, line input) ├── rsdos/ — binary crate (efi_main, init, panic handler) └── rsboot/ — future git submodule No functional changes — boots to shell prompt identically. Version auto-pulled from Cargo.toml via env!("CARGO_PKG_VERSION").
Diffstat (limited to 'rsnix/build.rs')
-rw-r--r--rsnix/build.rs70
1 files changed, 70 insertions, 0 deletions
diff --git a/rsnix/build.rs b/rsnix/build.rs
new file mode 100644
index 0000000..35447e9
--- /dev/null
+++ b/rsnix/build.rs
@@ -0,0 +1,70 @@
1/// Build script — extracts glyph data from a PSF2 font file.
2/// Uses zcat (system gzip) to decompress — zero dependencies.
3use std::env;
4use std::fs;
5use std::path::Path;
6use std::process::{Command, Output};
7
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9 let font_path = "/usr/share/kbd/consolefonts/lat1-16.psfu.gz";
10 println!("cargo::rerun-if-changed={}", font_path);
11
12 // Decompress via zcat (available on any Linux system)
13 let Output { stdout, status, .. } = Command::new("zcat").arg(font_path).output()?;
14 if !status.success() {
15 return Err(format!("zcat exited with {status:?}").into());
16 }
17 let raw = stdout;
18
19 if raw.len() < 32 {
20 return Err("PSF font too small".into());
21 }
22
23 // PSF2 magic: 0x864ab572 (little-endian)
24 let magic = u32::from_le_bytes(raw[..4].try_into()?);
25 if magic != 0x864ab572 {
26 return Err("not a PSF2 font".into());
27 }
28
29 let hdr_size = u32::from_le_bytes(raw[8..12].try_into()?) as usize;
30 let num_glyphs = u32::from_le_bytes(raw[16..20].try_into()?) as usize;
31 let bytes_per_glyph = u32::from_le_bytes(raw[20..24].try_into()?) as usize;
32
33 if num_glyphs != 256 {
34 return Err(format!("expected 256 glyphs, got {num_glyphs}").into());
35 }
36 if bytes_per_glyph != 16 {
37 return Err(format!("expected 16 bytes/glyph, got {bytes_per_glyph}").into());
38 }
39
40 let glyph_data = &raw[hdr_size..hdr_size + num_glyphs * bytes_per_glyph];
41
42 // Write generated Rust source into OUT_DIR
43 let out_dir = env::var("OUT_DIR")?;
44 let dest = Path::new(&out_dir).join("font_data.rs");
45
46 let mut code = String::from(
47 "/// 8×16 bitmap font glyph data (256 glyphs, 16 bytes each).
48#[rustfmt::skip]
49#[allow(clippy::unreadable_literal)]
50pub const GLYPH_8X16: [[u8; 16]; 256] = [",
51 );
52
53 for g in 0..256 {
54 let offset = g * 16;
55 code.push_str("\n [");
56 for row in 0..16 {
57 if row % 4 == 0 {
58 code.push('\n');
59 }
60 let byte = glyph_data[offset + row];
61 code.push_str(&format!(" 0x{byte:02X},"));
62 }
63 code.push_str("\n ],");
64 }
65
66 code.push_str("\n];\n");
67
68 fs::write(&dest, code)?;
69 Ok(())
70}