From 05b6c70fca92097ec5689e28442dbe2012ce8239 Mon Sep 17 00:00:00 2001 From: DavidHerran Date: Sat, 30 May 2026 11:13:33 -0500 Subject: [PATCH] =?UTF-8?q?feat(slice-4):=20v0.0.48=20=E2=80=94=20runtime?= =?UTF-8?q?=20exporta=20WASM=5FBINARY=20(Paso=204a)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Slice 4 Ship 1 — prerequisito para el full sc-service. El runtime ahora exporta WASM_BINARY que el node consumirá para construir ChainSpecs reales (Paso 4b). build.rs ya generaba OUT_DIR/wasm_binary.rs vía substrate-wasm-builder (Slice 2e), pero lib.rs no lo incluía. Esta ship añade el include! gateado: - #[cfg(feature = wasm-build)] include!(OUT_DIR/wasm_binary.rs) → WASM_BINARY real - #[cfg(not(wasm-build))] pub const WASM_BINARY: Option<&[u8]> = None → host-only - wasm_binary_unwrap() helper con mensaje de error claro El gate evita: (1) error de compilación cuando wasm-build off (archivo no existe), (2) recursión en build.rs (el inner build wasm32 no hereda wasm-build, no es default). Verificación: - cargo check -p origin-chain-runtime (host, wasm-build off): clean, WASM_BINARY=None - cargo build --features wasm-build + CC=LLVM: clean 39s, include! compila → WASM_BINARY=Some (real binary 2.8 MB) - cargo test --workspace: 213 verde, 0 fail, sin regresiones Próximo Ship 2 (v0.0.49): Paso 4b chain_spec GenericChainSpec + Paso 4c service.rs + rpc.rs + node sc-* deps. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/origin-chain-runtime/src/lib.rs | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/crates/origin-chain-runtime/src/lib.rs b/crates/origin-chain-runtime/src/lib.rs index c0f45e4..75ae9d4 100644 --- a/crates/origin-chain-runtime/src/lib.rs +++ b/crates/origin-chain-runtime/src/lib.rs @@ -49,6 +49,41 @@ pub mod configs; pub mod genesis_config_presets; pub mod opaque; +// ============================================================ +// WASM binary (Slice 4 Paso 4a — WASM_BINARY export v0.0.48) +// ============================================================ +// +// `build.rs` genera `OUT_DIR/wasm_binary.rs` con `pub const WASM_BINARY: +// Option<&[u8]>` cuando el feature `wasm-build` está activo (vía +// substrate-wasm-builder). El node lo consume para construir el ChainSpec real +// (`sc_service::GenericChainSpec`) en Slice 4 Paso 4b. +// +// Gate: el `include!` solo corre con `wasm-build` on (si está off, el archivo +// generado no existe → error de compilación). El fallback `None` cubre los +// builds host-only (`cargo test`/`cargo check`). El inner build wasm32 que +// dispara substrate-wasm-builder NO hereda `wasm-build` (no es default feature), +// lo que evita recursión en build.rs. +#[cfg(feature = "wasm-build")] +include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); + +/// Fallback de `WASM_BINARY` para builds host-only (feature `wasm-build` off). +/// Para obtener el binary real: `cargo build --features wasm-build` + env vars +/// `CC=/opt/homebrew/opt/llvm/bin/clang` (ver SLICE_2E). El node activa +/// `origin-chain-runtime/wasm-build` para embeberlo en el ChainSpec. +#[cfg(not(feature = "wasm-build"))] +pub const WASM_BINARY: Option<&[u8]> = None; + +/// Devuelve el `WASM_BINARY` o falla con un mensaje claro si no está disponible. +/// Consumido por el node al construir ChainSpecs (Slice 4 Paso 4b). +#[cfg(feature = "std")] +pub fn wasm_binary_unwrap() -> &'static [u8] { + WASM_BINARY.expect( + "WASM binary no disponible: build con `--features wasm-build` + \ + CC=LLVM env vars (ver SLICE_2E). El node debe activar \ + origin-chain-runtime/wasm-build.", + ) +} + // ============================================================ // WASM binary canonical (Slice 2b investigation registered, Slice 2c deferred) // ============================================================