rust-lang/cargo · error · anyhow::Error

` ` is not supported in build script overrides

Error message

`{}` is not supported in build script overrides

What it means

Thrown while parsing build script overrides in [target.<triple>.links.<lib>] config tables when the key is one of 'warning', 'rerun-if-changed', or 'rerun-if-env-changed'. These directives are only meaningful when emitted by actual build scripts at runtime, not when configured as static overrides.

Solutions

  1. Remove the 'warning', 'rerun-if-changed', or 'rerun-if-env-changed' key from the links override table
  2. Control build script warnings via RUSTC_FLAGS or the actual build script code instead
  3. Use the supported override keys: rustc-flags, rustc-link-lib, rustc-link-search, rustc-cfg, rustc-check-cfg, rustc-env

Example fix

# before (config.toml)
[target.x86_64-unknown-linux-gnu.links.foo]
rerun-if-changed = "src/foo.c"

# after — remove unsupported key; handle in build.rs instead
# (delete from config.toml; add `println!("cargo:rerun-if-changed=src/foo.c");` in build.rs)
Defensive patterns

Strategy: validation

Validate before calling

// Validate links override keys before writing config
const SUPPORTED_LINK_KEYS: &[&str] = &[
    "rustc-flags", "rustc-link-lib", "rustc-link-search",
    "rustc-cfg", "rustc-check-cfg", "rustc-env",
];
const UNSUPPORTED_LINK_KEYS: &[&str] = &["warning", "rerun-if-changed", "rerun-if-env-changed"];
fn validate_links_override(table: &toml::Table) -> Result<(), String> {
    for key in table.keys() {
        if UNSUPPORTED_LINK_KEYS.contains(&key.as_str()) {
            return Err(format!("`{key}` is not supported in build script overrides"));
        }
    }
    Ok(())
}

Prevention

When it happens

Trigger: Adding a `warning`, `rerun-if-changed`, or `rerun-if-env-changed` key inside a `[target.x86_64-unknown-linux-gnu.links.foo]` table in config.toml.

Common situations: Attempting to suppress or control build script behavior via config overrides without understanding that these are runtime directives. Copying build script directives into config expecting them to work as overrides.

Related errors


AI-assisted analysis of rust-lang/cargo@98a09e7e7d (2026-08-11). Data as JSON: /api/errors/e1909922589d78bb. Report an issue: GitHub.

Appendix: source

Thrown at src/context/target.rs:232

                    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 98a09e7e7d)