rust-lang/cargo · error
`{}` is not supported in build script overrides
Error message
`{}` is not supported in build script overrides What it means
When parsing `[host]`/`[target.*]` build-script override config (target.rs:130-237), Cargo accepts keys like rustc-link-lib, rustc-link-search, rustc-link-arg*, rustc-cfg, rustc-check-cfg, rustc-env. The keys `warning`, `rerun-if-changed`, and `rerun-if-env-changed` are explicitly rejected because they are runtime directives only a build.rs can emit, not static config. Cargo bails '`<key>` is not supported in build script overrides'.
Source
Thrown at src/context/target.rs:230
let args = extra_link_args(LinkArgTarget::Example, key, value)?;
output.linker_args.extend(args);
}
"rustc-cfg" => {
let list = value.string_list(key)?;
output.cfgs.extend(list.iter().map(|v| v.0.clone()));
}
"rustc-check-cfg" => {
let list = value.string_list(key)?;
output.check_cfgs.extend(list.iter().map(|v| v.0.clone()));
}
"rustc-env" => {
for (name, val) in value.table(key)?.0 {
let val = val.string(name)?.0;
output.env.push((name.clone(), val.to_string()));
}
}
"warning" | "rerun-if-changed" | "rerun-if-env-changed" => {
anyhow::bail!("`{}` is not supported in build script overrides", key);
}
_ => {
let val = value.string(key)?.0;
output.metadata.push((key.clone(), val.to_string()));
}
}
}
links_overrides.insert(lib_name, output);
}
Ok(links_overrides)
}
fn extra_link_args(
link_type: LinkArgTarget,
key: &str,
value: &CV,
) -> CargoResult<Vec<(LinkArgTarget, String)>> {
let args = value.string_list(key)?;View on GitHub (pinned to 0e07a15537)
Solutions
- Remove the `warning`/`rerun-if-changed`/`rerun-if-env-changed` keys from the [target.*]/[host.*] override table.
- Implement those behaviors in the package's build.rs instead (they are runtime directives).
- Use only the supported override keys (rustc-link-lib, rustc-link-search, rustc-link-arg*, rustc-cfg, rustc-check-cfg, rustc-env, and metadata).
Example fix
# before (.cargo/config.toml)
[target.x86_64-unknown-linux-gnu]
rustc-link-lib = ["foo"]
rerun-if-changed = ["src/wrapper.rs"] # not supported -> error
# after
[target.x86_64-unknown-linux-gnu]
rustc-link-lib = ["foo"]
# move 'rerun-if-changed' into build.rs:
# println!("cargo::rerun-if-changed=src/wrapper.rs"); Defensive patterns
Strategy: validation
Validate before calling
# Reject unsupported override keys before building:
python3 - <<'EOF'
import tomllib
try: d = tomllib.load(open('.cargo/config.toml','rb'))
except FileNotFoundError: raise SystemExit(0)
bad = {'warning','rerun-if-changed','rerun-if-env-changed'}
for section in ('target','host'):
for triple, tbl in (d.get(section) or {}).items():
if isinstance(tbl, dict):
hit = bad & set(tbl)
assert not hit, f'{section}.{triple}: unsupported keys {hit}'
EOF Prevention
- Only use supported build-script override keys in [target.*]/[host.*].
- Implement warning/rerun-if-changed/rerun-if-env-changed inside build.rs, not config.
- Keep a reference of allowed override keys when authoring target config.
When it happens
Trigger: Placing `warning = [...]`, `rerun-if-changed = [...]`, or `rerun-if-env-changed = [...]` under a `[target.<triple>]` (or `[host.<triple>]`) table in config.toml that is being parsed as a build-script override via links_overrides.
Common situations: Copying build.rs cargo: directives verbatim into config expecting them to work declaratively; misunderstanding the limited set of override keys.
Related errors
- several matching instances of `target.'cfg(..)'.runner` in c
- several matching instances of `target.'cfg(..)'.linker` in c
- the -Zhost-config flag requires the -Ztarget-applies-to-host
- subcommand is required, add a subcommand to the command alia
- alias {} has unresolvable recursive definition: {} -> {}
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/e1909922589d78bb.json.
Report an issue: GitHub.