| 214 | } |
| 215 | |
| 216 | fn find_llvm_tool(name: &str) -> PathBuf { |
| 217 | let output = Command::new("rustc") |
| 218 | .arg("--print") |
| 219 | .arg("sysroot") |
| 220 | .output() |
| 221 | .expect("failed to run rustc --print sysroot"); |
| 222 | let sysroot = String::from_utf8(output.stdout) |
| 223 | .expect("non-utf8 sysroot") |
| 224 | .trim() |
| 225 | .to_string(); |
| 226 | |
| 227 | let rustlib = Path::new(&sysroot).join("lib").join("rustlib"); |
| 228 | if let Ok(entries) = fs::read_dir(&rustlib) { |
| 229 | for entry in entries.flatten() { |
| 230 | let candidate = entry.path().join("bin").join(name); |
| 231 | if candidate.exists() { |
| 232 | return candidate; |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | eprintln!("warning: {name} not found in rustup sysroot, trying PATH"); |
| 238 | PathBuf::from(name) |
| 239 | } |
| 240 | |
| 241 | fn has_command(name: &str) -> bool { |
| 242 | Command::new(name) |