Skip to content

Commit 5cb5c85

Browse files
committed
rustbuild+configure: improve bin/exe joining
1 parent dce4600 commit 5cb5c85

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/bootstrap/config.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use std::process;
2323
use num_cpus;
2424
use rustc_serialize::Decodable;
2525
use toml::{Parser, Decoder, Value};
26+
use util::push_exe_path;
2627

2728
/// Global configuration for the entire build and/or bootstrap.
2829
///
@@ -417,7 +418,7 @@ impl Config {
417418
let target = self.target_config.entry(self.build.clone())
418419
.or_insert(Target::default());
419420
let root = PathBuf::from(value);
420-
target.llvm_config = Some(root.join("bin/llvm-config"));
421+
target.llvm_config = Some(push_exe_path(root, &["bin", "llvm-config"]));
421422
}
422423
"CFG_JEMALLOC_ROOT" if value.len() > 0 => {
423424
let target = self.target_config.entry(self.build.clone())
@@ -449,8 +450,9 @@ impl Config {
449450
target.ndk = Some(PathBuf::from(value));
450451
}
451452
"CFG_LOCAL_RUST_ROOT" if value.len() > 0 => {
452-
self.rustc = Some(PathBuf::from(value).join("bin/rustc"));
453-
self.cargo = Some(PathBuf::from(value).join("bin/cargo"));
453+
let path = PathBuf::from(value);
454+
self.rustc = Some(push_exe_path(path.clone(), &["bin", "rustc"]));
455+
self.cargo = Some(push_exe_path(path, &["bin", "cargo"]));
454456
}
455457
_ => {}
456458
}

src/bootstrap/util.rs

+18
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,21 @@ pub fn dylib_path() -> Vec<PathBuf> {
172172
env::split_paths(&env::var_os(dylib_path_var()).unwrap_or(OsString::new()))
173173
.collect()
174174
}
175+
176+
/// `push` all components to `buf`. On windows, append `.exe` to the last component.
177+
pub fn push_exe_path(mut buf: PathBuf, components: &[&str]) -> PathBuf {
178+
let (&file, components) = components.split_last().expect("at least one component required");
179+
let mut file = file.to_owned();
180+
181+
if cfg!(windows) {
182+
file.push_str(".exe");
183+
}
184+
185+
for c in components {
186+
buf.push(c);
187+
}
188+
189+
buf.push(file);
190+
191+
buf
192+
}

0 commit comments

Comments
 (0)