astrid-runtime/astrid · error
No Cargo build target selected. Set `[build] target = "wasm3
Error message
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.
What it means
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.
Source
Thrown at crates/astrid-build/src/rust.rs:548
}
let mut value = config_flags.join(RUSTFLAGS_SEP);
if !value.is_empty() {
value.push_str(RUSTFLAGS_SEP);
}
value.push_str(GETRANDOM_CUSTOM_CFG);
Some(("CARGO_ENCODED_RUSTFLAGS".to_owned(), value))
}
fn resolve_build_target(
config_target: Option<String>,
env_target: Option<String>,
) -> Result<String> {
env_target
.or(config_target)
.filter(|target| !target.trim().is_empty())
.ok_or_else(|| {
anyhow::anyhow!(
"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."
)
})
}
/// Wrap a core wasm module into a Component Model component if it isn't
/// one already. `wasm32-unknown-unknown` (Astrid-canonical) produces a
/// core module with `wit-bindgen`'s component-type custom section
/// embedded; `wit_component::ComponentEncoder` consumes that section and
/// emits a real component. `wasm32-wasip2` builds skip this — cargo
/// already produces a component there.
fn ensure_component(wasm_path: &Path) -> Result<PathBuf> {
let bytes =
std::fs::read(wasm_path).context("Failed to read compiled WASM for component check")?;
// Component magic: \0asm version=0x0d layer=0x01. Core magic:
// \0asm version=0x01. The 4-byte version field at offset 4
// distinguishes them.
let is_component = bytes.len() >= 8 && &bytes[..4] == b"\0asm" && bytes[6] == 0x01;View on GitHub (pinned to affd8760f4)
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
Example fix
// before (missing .cargo/config.toml) // after // .cargo/config.toml [build] target = "wasm32-unknown-unknown"
Defensive patterns
Strategy: validation
Validate before calling
fn ensure_wasm_target() -> Result<(), String> {
let t = std::env::var("CARGO_BUILD_TARGET").ok()
.or_else(|| parse_cargo_config_build_target(".cargo/config.toml"));
match t {
Some(v) if !v.trim().is_empty() && v.starts_with("wasm32-") => Ok(()),
_ => Err("set [build] target = \"wasm32-unknown-unknown\" in .cargo/config.toml".into()),
}
} Type guard
fn has_wasm_target(v: &Option<String>) -> bool {
v.as_deref().map_or(false, |t| !t.trim().is_empty() && t.starts_with("wasm32-"))
} Try / catch
match compile_wasm(...) {
Err(e) if e.to_string().contains("No Cargo build target selected") => {
eprintln!("configure [build] target in .cargo/config.toml or CARGO_BUILD_TARGET");
}
other => other?,
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- Cargo include table must contain a string path in {}
- Cargo include optional must be a boolean in {}
- failed to create wasmtime engine for hooks
- build_host_state
- installed WASM executable differs from its authority receipt
AI-assisted analysis of astrid-runtime/astrid@affd8760f4 (2026-09-09).
Data as JSON: /api/errors/b3f70d371c0fa688.
Report an issue: GitHub.