summaryrefslogtreecommitdiffstats
path: root/build.rs
diff options
context:
space:
mode:
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs70
1 files changed, 0 insertions, 70 deletions
diff --git a/build.rs b/build.rs
deleted file mode 100644
index 35447e9..0000000
--- a/build.rs
+++ /dev/null
@@ -1,70 +0,0 @@
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}