Skip to content

Commit 51b20bc

Browse files
authored
Rollup merge of #34302 - retep998:🐇-sanity-is-overrated-🐇, r=alexcrichton
Fix issue where rustbuild expected msvc to have ar I made `cc2ar` return an `Option`. r? @alexcrichton
2 parents 986bb53 + e0992df commit 51b20bc

File tree

6 files changed

+21
-13
lines changed

6 files changed

+21
-13
lines changed

src/bootstrap/build/cc.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ pub fn find(build: &mut Build) {
5757
let compiler = cfg.get_compiler();
5858
let ar = cc2ar(compiler.path(), target);
5959
build.verbose(&format!("CC_{} = {:?}", target, compiler.path()));
60-
build.verbose(&format!("AR_{} = {:?}", target, ar));
60+
if let Some(ref ar) = ar {
61+
build.verbose(&format!("AR_{} = {:?}", target, ar));
62+
}
6163
build.cc.insert(target.to_string(), (compiler, ar));
6264
}
6365

src/bootstrap/build/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub struct Build {
119119
lldb_python_dir: Option<String>,
120120

121121
// Runtime state filled in later on
122-
cc: HashMap<String, (gcc::Tool, PathBuf)>,
122+
cc: HashMap<String, (gcc::Tool, Option<PathBuf>)>,
123123
cxx: HashMap<String, gcc::Tool>,
124124
compiler_rt_built: RefCell<HashMap<String, PathBuf>>,
125125
}
@@ -549,7 +549,7 @@ impl Build {
549549
// FIXME: the guard against msvc shouldn't need to be here
550550
if !target.contains("msvc") {
551551
cargo.env(format!("CC_{}", target), self.cc(target))
552-
.env(format!("AR_{}", target), self.ar(target))
552+
.env(format!("AR_{}", target), self.ar(target).unwrap()) // only msvc is None
553553
.env(format!("CFLAGS_{}", target), self.cflags(target).join(" "));
554554
}
555555

@@ -825,8 +825,8 @@ impl Build {
825825
}
826826

827827
/// Returns the path to the `ar` archive utility for the target specified.
828-
fn ar(&self, target: &str) -> &Path {
829-
&self.cc[target].1
828+
fn ar(&self, target: &str) -> Option<&Path> {
829+
self.cc[target].1.as_ref().map(|p| &**p)
830830
}
831831

832832
/// Returns the path to the C++ compiler for the target specified, may panic

src/bootstrap/build/sanity.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ pub fn check(build: &mut Build) {
7070
// also build some C++ shims for LLVM so we need a C++ compiler.
7171
for target in build.config.target.iter() {
7272
need_cmd(build.cc(target).as_ref());
73-
need_cmd(build.ar(target).as_ref());
73+
if let Some(ar) = build.ar(target) {
74+
need_cmd(ar.as_ref());
75+
}
7476
}
7577
for host in build.config.host.iter() {
7678
need_cmd(build.cxx(host).as_ref());

src/build_helper/lib.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,22 @@ pub fn gnu_target(target: &str) -> String {
3939
}
4040
}
4141

42-
pub fn cc2ar(cc: &Path, target: &str) -> PathBuf {
43-
if target.contains("musl") || target.contains("msvc") {
44-
PathBuf::from("ar")
42+
pub fn cc2ar(cc: &Path, target: &str) -> Option<PathBuf> {
43+
if target.contains("msvc") {
44+
None
45+
} else if target.contains("musl") {
46+
Some(PathBuf::from("ar"))
4547
} else {
4648
let parent = cc.parent().unwrap();
4749
let file = cc.file_name().unwrap().to_str().unwrap();
4850
for suffix in &["gcc", "cc", "clang"] {
4951
if let Some(idx) = file.rfind(suffix) {
5052
let mut file = file[..idx].to_owned();
5153
file.push_str("ar");
52-
return parent.join(&file);
54+
return Some(parent.join(&file));
5355
}
5456
}
55-
parent.join(file)
57+
Some(parent.join(file))
5658
}
5759
}
5860

src/liballoc_jemalloc/build.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ fn main() {
4343
}
4444

4545
let compiler = gcc::Config::new().get_compiler();
46-
let ar = build_helper::cc2ar(compiler.path(), &target);
46+
// only msvc returns None for ar so unwrap is okay
47+
let ar = build_helper::cc2ar(compiler.path(), &target).unwrap();
4748
let cflags = compiler.args()
4849
.iter()
4950
.map(|s| s.to_str().unwrap())

src/libstd/build.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ fn build_libbacktrace(host: &str, target: &str) {
8080
}
8181

8282
let compiler = gcc::Config::new().get_compiler();
83-
let ar = build_helper::cc2ar(compiler.path(), target);
83+
// only msvc returns None for ar so unwrap is okay
84+
let ar = build_helper::cc2ar(compiler.path(), target).unwrap();
8485
let cflags = compiler.args().iter().map(|s| s.to_str().unwrap())
8586
.collect::<Vec<_>>().join(" ");
8687
run(Command::new("sh")

0 commit comments

Comments
 (0)