{"record":{"id":"b3f70d371c0fa688","repo":"astrid-runtime/astrid","slug":"no-cargo-build-target-selected-set-build-targe","errorCode":null,"errorMessage":"No Cargo build target selected. Set `[build] target = \"wasm32-unknown-unknown\"` (Astrid-canonical) or `wasm32-wasip2` in `.cargo/config.toml`, or set CARGO_BUILD_TARGET.","messagePattern":"No Cargo build target selected\\. Set `\\[build\\] target = \"wasm32-unknown-unknown\"` \\(Astrid-canonical\\) or `wasm32-wasip2` in `\\.cargo/config\\.toml`, or set CARGO_BUILD_TARGET\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-build/src/rust.rs","lineNumber":548,"sourceCode":"    }\n\n    let mut value = config_flags.join(RUSTFLAGS_SEP);\n    if !value.is_empty() {\n        value.push_str(RUSTFLAGS_SEP);\n    }\n    value.push_str(GETRANDOM_CUSTOM_CFG);\n    Some((\"CARGO_ENCODED_RUSTFLAGS\".to_owned(), value))\n}\n\nfn resolve_build_target(\n    config_target: Option<String>,\n    env_target: Option<String>,\n) -> Result<String> {\n    env_target\n        .or(config_target)\n        .filter(|target| !target.trim().is_empty())\n        .ok_or_else(|| {\n        anyhow::anyhow!(\n            \"No Cargo build target selected. Set `[build] target = \\\"wasm32-unknown-unknown\\\"` (Astrid-canonical) or `wasm32-wasip2` in `.cargo/config.toml`, or set CARGO_BUILD_TARGET.\"\n        )\n    })\n}\n\n/// Wrap a core wasm module into a Component Model component if it isn't\n/// one already. `wasm32-unknown-unknown` (Astrid-canonical) produces a\n/// core module with `wit-bindgen`'s component-type custom section\n/// embedded; `wit_component::ComponentEncoder` consumes that section and\n/// emits a real component. `wasm32-wasip2` builds skip this — cargo\n/// already produces a component there.\nfn ensure_component(wasm_path: &Path) -> Result<PathBuf> {\n    let bytes =\n        std::fs::read(wasm_path).context(\"Failed to read compiled WASM for component check\")?;\n    // Component magic: \\0asm version=0x0d layer=0x01. Core magic:\n    // \\0asm version=0x01. The 4-byte version field at offset 4\n    // distinguishes them.\n    let is_component = bytes.len() >= 8 && &bytes[..4] == b\"\\0asm\" && bytes[6] == 0x01;","sourceCodeStart":530,"sourceCodeEnd":566,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-build/src/rust.rs#L530-L566","documentation":"Astrid's WASM build refuses to guess a compilation target. rustc without an explicit --target builds a host binary, which would silently produce a native cdylib instead of a wasm module, so resolve_build_target requires either `[build] target` in .cargo/config.toml or the CARGO_BUILD_TARGET env var, and it must be a wasm triple.","triggerScenarios":"Calling compile_wasm (via environment_target_overrides_capsule_config_target or directly) when neither `.cargo/config.toml` has `[build] target` nor the CARGO_BUILD_TARGET environment variable is set, or when the value present is empty/whitespace.","commonSituations":"Fresh clone of an Astrid capsule workspace without the .cargo/config.toml checked in; CI runner that doesn't inherit CARGO_BUILD_TARGET; developer removed the config file or relies on a shell alias that didn't export the var.","solutions":["Add `[build]\\ntarget = \"wasm32-unknown-unknown\"` to `.cargo/config.toml` (Astrid-canonical)","Or set `target = \"wasm32-wasip2\"` if your capsule targets WASI","Export CARGO_BUILD_TARGET=wasm32-unknown-unknown in your shell/CI environment","Verify the value is not empty or whitespace-only"],"exampleFix":"// before (missing .cargo/config.toml)\n// after\n// .cargo/config.toml\n[build]\ntarget = \"wasm32-unknown-unknown\"","handlingStrategy":"validation","validationCode":"fn ensure_wasm_target() -> Result<(), String> {\n    let t = std::env::var(\"CARGO_BUILD_TARGET\").ok()\n        .or_else(|| parse_cargo_config_build_target(\".cargo/config.toml\"));\n    match t {\n        Some(v) if !v.trim().is_empty() && v.starts_with(\"wasm32-\") => Ok(()),\n        _ => Err(\"set [build] target = \\\"wasm32-unknown-unknown\\\" in .cargo/config.toml\".into()),\n    }\n}","typeGuard":"fn has_wasm_target(v: &Option<String>) -> bool {\n    v.as_deref().map_or(false, |t| !t.trim().is_empty() && t.starts_with(\"wasm32-\"))\n}","tryCatchPattern":"match compile_wasm(...) {\n    Err(e) if e.to_string().contains(\"No Cargo build target selected\") => {\n        eprintln!(\"configure [build] target in .cargo/config.toml or CARGO_BUILD_TARGET\");\n    }\n    other => other?,\n}","preventionTips":["Commit .cargo/config.toml with [build] target = \"wasm32-unknown-unknown\" to the repo","Set CARGO_BUILD_TARGET in CI before cargo/astrid build steps","Check the file exists after a fresh clone before building"],"tags":["build","cargo","wasm","config"],"backgroundTag":"missing-required-config-field","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}