{"id":"6580d0bae007aeb3","repo":"rust-lang/cargo","slug":"several-matching-instances-of-target-cfg-ru","errorCode":null,"errorMessage":"several matching instances of `target.'cfg(..)'.runner` in configurations\nfirst match `{}` located in {}\nsecond match `{}` located in {}","messagePattern":"several matching instances of `target\\.'cfg\\(\\.\\.\\)'\\.runner` in configurations\nfirst match `(.+?)` located in (.+?)\nsecond match `(.+?)` located in (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/compilation.rs","lineNumber":543,"sourceCode":"\n    // With `target-applies-to-host = true`,\n    // host artifacts must fall through to pick up from [target]\n    // since this is the stable behavior\n    if kind.is_host() && !bcx.gctx.target_applies_to_host()? {\n        return Ok(None);\n    }\n\n    // try target.'cfg(...)'.runner\n    let target_cfg = bcx.target_data.info(kind).cfg();\n    let mut cfgs = bcx\n        .gctx\n        .target_cfgs()?\n        .iter()\n        .filter_map(|(key, cfg)| cfg.runner.as_ref().map(|runner| (key, runner)))\n        .filter(|(key, _runner)| CfgExpr::matches_key(key, target_cfg));\n    let matching_runner = cfgs.next();\n    if let Some((key, runner)) = cfgs.next() {\n        anyhow::bail!(\n            \"several matching instances of `target.'cfg(..)'.runner` in configurations\\n\\\n             first match `{}` located in {}\\n\\\n             second match `{}` located in {}\",\n            matching_runner.unwrap().0,\n            matching_runner.unwrap().1.definition,\n            key,\n            runner.definition\n        );\n    }\n    Ok(matching_runner.map(|(_k, runner)| {\n        (\n            runner.val.path.clone().resolve_program(bcx.gctx),\n            runner.val.args.clone(),\n        )\n    }))\n}\n\n/// Gets the user-specified linker for a particular host or target from the configuration.","sourceCodeStart":525,"sourceCodeEnd":561,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/compiler/compilation.rs#L525-L561","documentation":"In target_runner (compilation.rs:533-552), Cargo selects a `target.'cfg(...)'.runner` by filtering all configured cfg-runner entries whose cfg key matches the current target's cfg. If MORE THAN ONE entry matches, the choice is ambiguous and Cargo bails, printing the first and second matching keys along with the config files (definition locations) that defined them.","triggerScenarios":"Defining multiple `[target.'cfg(...)'.runner]` entries in `.cargo/config.toml` (or across layered config files) whose cfg expressions both match the build target — e.g. `[target.'cfg(unix)'.runner]` and `[target.'cfg(linux)'.runner]` both matching a Linux target.","commonSituations":"Overlapping cfg-based runner config across global and project config files; broadening a cfg expression that now collides with a more specific one; merging config from multiple team members; `[target.<triple>.runner]` plus a matching `[target.'cfg(...)'.runner]`.","solutions":["Disambiguate by keeping only ONE matching cfg-runner entry; remove or narrow the broader cfg expression.","Use the most specific key (e.g. an exact triple `[target.x86_64-unknown-linux-gnu].runner`) instead of overlapping cfgs.","Audit layered config files (`~/.cargo/config.toml`, `.cargo/config.toml`, `--config` flags) for duplicate runner definitions.","If two different runners are legitimately needed, differentiate their cfg conditions so they never both match."],"exampleFix":"// before (.cargo/config.toml)\n[target.'cfg(unix)'.runner]\nrunner = \"qemu-unix\"\n[target.'cfg(linux)'.runner]\nrunner = \"qemu-linux\"\n// both match a linux build -> error\n\n// after\n[target.'cfg(target_os = \"macos\")'.runner]\nrunner = \"qemu-macos\"\n[target.'cfg(target_os = \"linux\")'.runner]\nrunner = \"qemu-linux\"","handlingStrategy":"validation","validationCode":"// Detect overlapping cfg-runner keys for a given target cfg\nlet matching: Vec<_> = target_cfgs.iter()\n    .filter(|(_, c)| c.runner.is_some())\n    .filter(|(k, _)| CfgExpr::matches_key(k, &target_cfg))\n    .collect();\nif matching.len() > 1 {\n    return Err(format!(\"{} target.'cfg(..)'.runner match; disambiguate\", matching.len()));\n}","typeGuard":"fn single_runner_match(entries: &[(&str, &Config)]) -> bool {\n    entries.iter().filter(|(_, c)| c.runner.is_some()).count() <= 1\n}\n","tryCatchPattern":null,"preventionTips":["Audit layered cargo config files for runner duplicates.","Prefer exact-triple runner keys over broad cfg expressions.","Lint config in CI for overlapping cfg keys."],"tags":["cargo","config","target","runner","cfg"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}