feat(slice-4): v0.0.48 — runtime exporta WASM_BINARY (Paso 4a)

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) <noreply@anthropic.com>
This commit is contained in:
davidherranandClaude Opus 4.8 committed 2026-05-30 11:13:33 -05:00
1 parent 28408cdf73
commit 05b6c70fca
1 file changed
+35
+35
View File
@@ -49,6 +49,41 @@ pub mod configs;
pub mod genesis_config_presets; pub mod genesis_config_presets;
pub mod opaque; 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) // WASM binary canonical (Slice 2b investigation registered, Slice 2c deferred)
// ============================================================ // ============================================================