{"id":"e1909922589d78bb","repo":"rust-lang/cargo","slug":"is-not-supported-in-build-script-overrides","errorCode":null,"errorMessage":"`{}` is not supported in build script overrides","messagePattern":"`(.+?)` is not supported in build script overrides","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/context/target.rs","lineNumber":230,"sourceCode":"                    let args = extra_link_args(LinkArgTarget::Example, key, value)?;\n                    output.linker_args.extend(args);\n                }\n                \"rustc-cfg\" => {\n                    let list = value.string_list(key)?;\n                    output.cfgs.extend(list.iter().map(|v| v.0.clone()));\n                }\n                \"rustc-check-cfg\" => {\n                    let list = value.string_list(key)?;\n                    output.check_cfgs.extend(list.iter().map(|v| v.0.clone()));\n                }\n                \"rustc-env\" => {\n                    for (name, val) in value.table(key)?.0 {\n                        let val = val.string(name)?.0;\n                        output.env.push((name.clone(), val.to_string()));\n                    }\n                }\n                \"warning\" | \"rerun-if-changed\" | \"rerun-if-env-changed\" => {\n                    anyhow::bail!(\"`{}` is not supported in build script overrides\", key);\n                }\n                _ => {\n                    let val = value.string(key)?.0;\n                    output.metadata.push((key.clone(), val.to_string()));\n                }\n            }\n        }\n        links_overrides.insert(lib_name, output);\n    }\n    Ok(links_overrides)\n}\n\nfn extra_link_args(\n    link_type: LinkArgTarget,\n    key: &str,\n    value: &CV,\n) -> CargoResult<Vec<(LinkArgTarget, String)>> {\n    let args = value.string_list(key)?;","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/context/target.rs#L212-L248","documentation":"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'.","triggerScenarios":"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.","commonSituations":"Copying build.rs cargo: directives verbatim into config expecting them to work declaratively; misunderstanding the limited set of override keys.","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)."],"exampleFix":"# before (.cargo/config.toml)\n[target.x86_64-unknown-linux-gnu]\nrustc-link-lib = [\"foo\"]\nrerun-if-changed = [\"src/wrapper.rs\"]   # not supported -> error\n# after\n[target.x86_64-unknown-linux-gnu]\nrustc-link-lib = [\"foo\"]\n# move 'rerun-if-changed' into build.rs:\n#   println!(\"cargo::rerun-if-changed=src/wrapper.rs\");","handlingStrategy":"validation","validationCode":"# Reject unsupported override keys before building:\npython3 - <<'EOF'\nimport tomllib\ntry: d = tomllib.load(open('.cargo/config.toml','rb'))\nexcept FileNotFoundError: raise SystemExit(0)\nbad = {'warning','rerun-if-changed','rerun-if-env-changed'}\nfor section in ('target','host'):\n    for triple, tbl in (d.get(section) or {}).items():\n        if isinstance(tbl, dict):\n            hit = bad & set(tbl)\n            assert not hit, f'{section}.{triple}: unsupported keys {hit}'\nEOF","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["config","target","build-script","links-overrides","unsupported-key"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}