summaryrefslogtreecommitdiffstats
path: root/build.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-07-31 02:18:30 +0200
committersalmonik <salmonik@tuta.io>2026-07-31 02:18:30 +0200
commit76103215711d268b4b02f62e900f2be3032cf295 (patch)
treedcd86b5b02ae99c99ca833668055f4f53211be6b /build.rs
downloadrs-dos-76103215711d268b4b02f62e900f2be3032cf295.tar.gz
rs-dos-76103215711d268b4b02f62e900f2be3032cf295.zip
Initial commit: raisernics toy kernel
- Bare-metal x86_64 UEFI kernel (PE32+, no libc) - GOP framebuffer + 8x16 bitmap font - PS/2 keyboard (polling, scancode set 1) - UART 16550 serial driver (COM1, 115200 8N1) - Bump allocator as #[global_allocator] (alloc::String, Vec, format!) - UEFI memory map capture (static buffer, ADR 0001) - Shell with 7 commands (help, echo, clear, hello, info, mem, halt) - Dual output: GOP framebuffer + serial console - Makefile: run, run-gui, debug, release, image targets - tools/: qemu.sh, boot-image.sh, debug-kernel.py
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs70
1 files changed, 70 insertions, 0 deletions
diff --git a/build.rs b/build.rs
new file mode 100644
index 0000000..44e6344
--- /dev/null
+++ b/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}