|
22 | 22 | //! everything.
|
23 | 23 |
|
24 | 24 | use std::collections::HashSet;
|
25 |
| -use std::iter; |
26 | 25 | use std::path::{Path, PathBuf};
|
| 26 | +use std::{env, iter}; |
27 | 27 |
|
28 | 28 | use crate::core::config::TargetSelection;
|
29 | 29 | use crate::utils::exec::{BootstrapCommand, command};
|
@@ -56,6 +56,36 @@ fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build {
|
56 | 56 | cfg
|
57 | 57 | }
|
58 | 58 |
|
| 59 | +/// Finds archiver tool for the given target if possible. |
| 60 | +/// FIXME(onur-ozkan): This logic should be replaced by calling into the `cc` crate. |
| 61 | +fn cc2ar(cc: &Path, target: TargetSelection, default_ar: PathBuf) -> Option<PathBuf> { |
| 62 | + if let Some(ar) = env::var_os(format!("AR_{}", target.triple.replace('-', "_"))) { |
| 63 | + Some(PathBuf::from(ar)) |
| 64 | + } else if let Some(ar) = env::var_os("AR") { |
| 65 | + Some(PathBuf::from(ar)) |
| 66 | + } else if target.is_msvc() { |
| 67 | + None |
| 68 | + } else if target.contains("musl") || target.contains("openbsd") { |
| 69 | + Some(PathBuf::from("ar")) |
| 70 | + } else if target.contains("vxworks") { |
| 71 | + Some(PathBuf::from("wr-ar")) |
| 72 | + } else if target.contains("-nto-") { |
| 73 | + if target.starts_with("i586") { |
| 74 | + Some(PathBuf::from("ntox86-ar")) |
| 75 | + } else if target.starts_with("aarch64") { |
| 76 | + Some(PathBuf::from("ntoaarch64-ar")) |
| 77 | + } else if target.starts_with("x86_64") { |
| 78 | + Some(PathBuf::from("ntox86_64-ar")) |
| 79 | + } else { |
| 80 | + panic!("Unknown architecture, cannot determine archiver for Neutrino QNX"); |
| 81 | + } |
| 82 | + } else if target.contains("android") || target.contains("-wasi") { |
| 83 | + Some(cc.parent().unwrap().join(PathBuf::from("llvm-ar"))) |
| 84 | + } else { |
| 85 | + Some(default_ar) |
| 86 | + } |
| 87 | +} |
| 88 | + |
59 | 89 | /// Probes for C and C++ compilers and configures the corresponding entries in the [`Build`]
|
60 | 90 | /// structure.
|
61 | 91 | ///
|
@@ -110,7 +140,13 @@ pub fn find_target(build: &Build, target: TargetSelection) {
|
110 | 140 | let ar = if let ar @ Some(..) = config.and_then(|c| c.ar.clone()) {
|
111 | 141 | ar
|
112 | 142 | } else {
|
113 |
| - cfg.try_get_archiver().map(|c| PathBuf::from(c.get_program())).ok() |
| 143 | + dbg!(compiler.path()); |
| 144 | + let old = cc2ar(compiler.path(), target, PathBuf::from(cfg.get_archiver().get_program())); |
| 145 | + dbg!(old); |
| 146 | + let new = cfg.try_get_archiver().map(|c| PathBuf::from(c.get_program())).ok(); |
| 147 | + dbg!(&new); |
| 148 | + |
| 149 | + new |
114 | 150 | };
|
115 | 151 |
|
116 | 152 | build.cc.borrow_mut().insert(target, compiler.clone());
|
|
0 commit comments