From 60b6ec7a6e0b99b5698462219254a10f0ff6ea27 Mon Sep 17 00:00:00 2001 From: Demetrius Kanios Date: Tue, 8 Sep 2026 11:38:22 -0700 Subject: [PATCH] Fix large component type embeddings --- crates/d/src/lib.rs | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/crates/d/src/lib.rs b/crates/d/src/lib.rs index 0a3873653..ea9cdd2aa 100644 --- a/crates/d/src/lib.rs +++ b/crates/d/src/lib.rs @@ -903,6 +903,38 @@ impl WorldGenerator for D { ) .unwrap(); + world_src.push_str(&format!( + "private enum componentTypeBytes = x\"{}\n\";\n", + &component_type + .iter() + .map(|b| format!("{b:02X}")) + .enumerate() + .fold(String::default(), |a, (i, b)| { + if (i % 39) == 0 { a + "\n" + &b } else { a + &b } + }) + )); + + world_src.push_str( + " + private enum componentTypeStr = (() { + immutable input = componentTypeBytes; + auto result = new char[input.length*3]; + + foreach (i, b; input) { + result[(i*3)+0] = '\\\\'; + + ubyte n1 = (b >> 4) & 0xF; + result[(i*3)+1] = n1 < 0xA ? cast(char)('0'+n1) : cast(char)('A'+(n1-0xA)); + + ubyte n2 = b & 0xF; + result[(i*3)+2] = n2 < 0xA ? cast(char)('0'+n2) : cast(char)('A'+(n2-0xA)); + } + + return cast(string)result; + })(); + ", + ); + world_src.push_str(&format!( " pragma(inline, false) @@ -914,19 +946,12 @@ impl WorldGenerator for D { \"\", \"\", `!wasm.custom_sections = !{{!0}} - !0 = !{{!\"component-type:wit-bindgen:{version}:{pkg}:{world_name}:{opts_suffix}\", !\"{}\"}}`, + !0 = !{{!\"component-type:wit-bindgen:{version}:{pkg}:{world_name}:{opts_suffix}\", !\"`~componentTypeStr~`\"}}`, void ); }} ", - self.root_pkg, - &component_type - .iter() - .map(|b| format!("\\{b:02X}")) - .enumerate() - .fold(String::default(), |a, (i, b)| { - if (i % 24) == 0 { a + "`\n~`" + &b } else { a + &b } - }) + self.root_pkg )); }