rust-lang/cargo · error

the -Zhost-config flag requires the -Ztarget-applies-to-host

Error message

the -Zhost-config flag requires the -Ztarget-applies-to-host flag to be set

What it means

get_target_applies_to_host (target.rs:83-97) gates the `-Zhost-config` feature: it may only be used together with `-Ztarget-applies-to-host`. If host_config is enabled but target_applies_to_host is not (and the `target-applies-to-host` config key is unset), Cargo bails 'the -Zhost-config flag requires the -Ztarget-applies-to-host flag to be set'. The two flags jointly decide whether `[host]` config tables also apply to host targets.

Source

Thrown at src/context/target.rs:91

                    other_key, key
                ))?;
            }
            result.push((key, cfg));
        }
    }
    Ok(result)
}

/// Returns true if the `[target]` table should be applied to host targets.
pub(super) fn get_target_applies_to_host(gctx: &GlobalContext) -> CargoResult<bool> {
    if gctx.cli_unstable().target_applies_to_host {
        if let Ok(target_applies_to_host) = gctx.get::<bool>("target-applies-to-host") {
            Ok(target_applies_to_host)
        } else {
            Ok(!gctx.cli_unstable().host_config)
        }
    } else if gctx.cli_unstable().host_config {
        anyhow::bail!(
            "the -Zhost-config flag requires the -Ztarget-applies-to-host flag to be set"
        );
    } else {
        Ok(true)
    }
}

/// Loads a single `[host]` table for the given triple.
pub(super) fn load_host_triple(gctx: &GlobalContext, triple: &str) -> CargoResult<TargetConfig> {
    if gctx.cli_unstable().host_config {
        let host_triple_prefix = format!("host.{}", triple);
        let host_triple_key = ConfigKey::from_str(&host_triple_prefix);
        let host_prefix = match gctx.get_cv(&host_triple_key)? {
            Some(_) => host_triple_prefix,
            None => "host".to_string(),
        };
        load_config_table(gctx, &host_prefix)
    } else {

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Pass both flags: `cargo +nightly build -Zhost-config -Ztarget-applies-to-host`.
  2. Alternatively set `target-applies-to-host = true|false` in config.toml so the second unstable flag is implied.
  3. Drop `-Zhost-config` if you do not need `[host]` tables.

Example fix

# before
cargo +nightly build -Zhost-config
# after
cargo +nightly build -Zhost-config -Ztarget-applies-to-host
Defensive patterns

Strategy: validation

Validate before calling

# Require the companion flag whenever -Zhost-config is used:
if printf '%s\n' "$@" | grep -q -- '-Zhost-config'; then
  set -- "$@" -Ztarget-applies-to-host
fi
cargo +nightly "$@"

Prevention

When it happens

Trigger: Invoking cargo with `-Zhost-config` but without `-Ztarget-applies-to-host` on the CLI, and with no `target-applies-to-host` config value set.

Common situations: Experimenting with the host-config nightly feature and forgetting the companion flag; following a partial example; config that sets `[host.*]` without enabling target-applies-to-host.

Related errors


AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06). Data as JSON: /data/errors/a356f02b04838aef.json. Report an issue: GitHub.