allow mutating the c compilers detected by bootstrap
This will be needed to create synthetic targets in future commits.
This commit is contained in:
parent
1b5143ae13
commit
68d458bb40
7 changed files with 46 additions and 41 deletions
|
@ -1650,7 +1650,7 @@ impl<'a> Builder<'a> {
|
|||
}
|
||||
};
|
||||
cargo.env(profile_var("DEBUG"), debuginfo_level.to_string());
|
||||
if self.cc[&target].args().iter().any(|arg| arg == "-gz") {
|
||||
if self.cc.borrow()[&target].args().iter().any(|arg| arg == "-gz") {
|
||||
rustflags.arg("-Clink-arg=-gz");
|
||||
}
|
||||
cargo.env(
|
||||
|
|
|
@ -89,7 +89,7 @@ fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build {
|
|||
cfg
|
||||
}
|
||||
|
||||
pub fn find(build: &mut Build) {
|
||||
pub fn find(build: &Build) {
|
||||
// For all targets we're going to need a C compiler for building some shims
|
||||
// and such as well as for being a linker for Rust code.
|
||||
let targets = build
|
||||
|
@ -115,7 +115,7 @@ pub fn find(build: &mut Build) {
|
|||
cc2ar(compiler.path(), target)
|
||||
};
|
||||
|
||||
build.cc.insert(target, compiler.clone());
|
||||
build.cc.borrow_mut().insert(target, compiler.clone());
|
||||
let cflags = build.cflags(target, GitRepo::Rustc, CLang::C);
|
||||
|
||||
// If we use llvm-libunwind, we will need a C++ compiler as well for all targets
|
||||
|
@ -136,7 +136,7 @@ pub fn find(build: &mut Build) {
|
|||
// for VxWorks, record CXX compiler which will be used in lib.rs:linker()
|
||||
if cxx_configured || target.contains("vxworks") {
|
||||
let compiler = cfg.get_compiler();
|
||||
build.cxx.insert(target, compiler);
|
||||
build.cxx.borrow_mut().insert(target, compiler);
|
||||
}
|
||||
|
||||
build.verbose(&format!("CC_{} = {:?}", &target.triple, build.cc(target)));
|
||||
|
@ -148,11 +148,11 @@ pub fn find(build: &mut Build) {
|
|||
}
|
||||
if let Some(ar) = ar {
|
||||
build.verbose(&format!("AR_{} = {:?}", &target.triple, ar));
|
||||
build.ar.insert(target, ar);
|
||||
build.ar.borrow_mut().insert(target, ar);
|
||||
}
|
||||
|
||||
if let Some(ranlib) = config.and_then(|c| c.ranlib.clone()) {
|
||||
build.ranlib.insert(target, ranlib);
|
||||
build.ranlib.borrow_mut().insert(target, ranlib);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -314,7 +314,7 @@ fn copy_self_contained_objects(
|
|||
}
|
||||
} else if target.ends_with("windows-gnu") {
|
||||
for obj in ["crt2.o", "dllcrt2.o"].iter() {
|
||||
let src = compiler_file(builder, builder.cc(target), target, CLang::C, obj);
|
||||
let src = compiler_file(builder, &builder.cc(target), target, CLang::C, obj);
|
||||
let target = libdir_self_contained.join(obj);
|
||||
builder.copy(&src, &target);
|
||||
target_deps.push((target, DependencyType::TargetSelfContained));
|
||||
|
@ -995,8 +995,13 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
|
|||
&& !target.contains("apple")
|
||||
&& !target.contains("solaris")
|
||||
{
|
||||
let file =
|
||||
compiler_file(builder, builder.cxx(target).unwrap(), target, CLang::Cxx, "libstdc++.a");
|
||||
let file = compiler_file(
|
||||
builder,
|
||||
&builder.cxx(target).unwrap(),
|
||||
target,
|
||||
CLang::Cxx,
|
||||
"libstdc++.a",
|
||||
);
|
||||
cargo.env("LLVM_STATIC_STDCPP", file);
|
||||
}
|
||||
if builder.llvm_link_shared() {
|
||||
|
|
|
@ -226,10 +226,10 @@ pub struct Build {
|
|||
|
||||
// Runtime state filled in later on
|
||||
// C/C++ compilers and archiver for all targets
|
||||
cc: HashMap<TargetSelection, cc::Tool>,
|
||||
cxx: HashMap<TargetSelection, cc::Tool>,
|
||||
ar: HashMap<TargetSelection, PathBuf>,
|
||||
ranlib: HashMap<TargetSelection, PathBuf>,
|
||||
cc: RefCell<HashMap<TargetSelection, cc::Tool>>,
|
||||
cxx: RefCell<HashMap<TargetSelection, cc::Tool>>,
|
||||
ar: RefCell<HashMap<TargetSelection, PathBuf>>,
|
||||
ranlib: RefCell<HashMap<TargetSelection, PathBuf>>,
|
||||
// Miscellaneous
|
||||
// allow bidirectional lookups: both name -> path and path -> name
|
||||
crates: HashMap<Interned<String>, Crate>,
|
||||
|
@ -451,10 +451,10 @@ impl Build {
|
|||
miri_info,
|
||||
rustfmt_info,
|
||||
in_tree_llvm_info,
|
||||
cc: HashMap::new(),
|
||||
cxx: HashMap::new(),
|
||||
ar: HashMap::new(),
|
||||
ranlib: HashMap::new(),
|
||||
cc: RefCell::new(HashMap::new()),
|
||||
cxx: RefCell::new(HashMap::new()),
|
||||
ar: RefCell::new(HashMap::new()),
|
||||
ranlib: RefCell::new(HashMap::new()),
|
||||
crates: HashMap::new(),
|
||||
crate_paths: HashMap::new(),
|
||||
is_sudo,
|
||||
|
@ -482,7 +482,7 @@ impl Build {
|
|||
}
|
||||
|
||||
build.verbose("finding compilers");
|
||||
cc_detect::find(&mut build);
|
||||
cc_detect::find(&build);
|
||||
// When running `setup`, the profile is about to change, so any requirements we have now may
|
||||
// be different on the next invocation. Don't check for them until the next time x.py is
|
||||
// run. This is ok because `setup` never runs any build commands, so it won't fail if commands are missing.
|
||||
|
@ -1103,16 +1103,16 @@ impl Build {
|
|||
}
|
||||
|
||||
/// Returns the path to the C compiler for the target specified.
|
||||
fn cc(&self, target: TargetSelection) -> &Path {
|
||||
self.cc[&target].path()
|
||||
fn cc(&self, target: TargetSelection) -> PathBuf {
|
||||
self.cc.borrow()[&target].path().into()
|
||||
}
|
||||
|
||||
/// Returns a list of flags to pass to the C compiler for the target
|
||||
/// specified.
|
||||
fn cflags(&self, target: TargetSelection, which: GitRepo, c: CLang) -> Vec<String> {
|
||||
let base = match c {
|
||||
CLang::C => &self.cc[&target],
|
||||
CLang::Cxx => &self.cxx[&target],
|
||||
CLang::C => self.cc.borrow()[&target].clone(),
|
||||
CLang::Cxx => self.cxx.borrow()[&target].clone(),
|
||||
};
|
||||
|
||||
// Filter out -O and /O (the optimization flags) that we picked up from
|
||||
|
@ -1153,19 +1153,19 @@ impl Build {
|
|||
}
|
||||
|
||||
/// Returns the path to the `ar` archive utility for the target specified.
|
||||
fn ar(&self, target: TargetSelection) -> Option<&Path> {
|
||||
self.ar.get(&target).map(|p| &**p)
|
||||
fn ar(&self, target: TargetSelection) -> Option<PathBuf> {
|
||||
self.ar.borrow().get(&target).cloned()
|
||||
}
|
||||
|
||||
/// Returns the path to the `ranlib` utility for the target specified.
|
||||
fn ranlib(&self, target: TargetSelection) -> Option<&Path> {
|
||||
self.ranlib.get(&target).map(|p| &**p)
|
||||
fn ranlib(&self, target: TargetSelection) -> Option<PathBuf> {
|
||||
self.ranlib.borrow().get(&target).cloned()
|
||||
}
|
||||
|
||||
/// Returns the path to the C++ compiler for the target specified.
|
||||
fn cxx(&self, target: TargetSelection) -> Result<&Path, String> {
|
||||
match self.cxx.get(&target) {
|
||||
Some(p) => Ok(p.path()),
|
||||
fn cxx(&self, target: TargetSelection) -> Result<PathBuf, String> {
|
||||
match self.cxx.borrow().get(&target) {
|
||||
Some(p) => Ok(p.path().into()),
|
||||
None => {
|
||||
Err(format!("target `{}` is not configured as a host, only as a target", target))
|
||||
}
|
||||
|
@ -1173,21 +1173,21 @@ impl Build {
|
|||
}
|
||||
|
||||
/// Returns the path to the linker for the given target if it needs to be overridden.
|
||||
fn linker(&self, target: TargetSelection) -> Option<&Path> {
|
||||
if let Some(linker) = self.config.target_config.get(&target).and_then(|c| c.linker.as_ref())
|
||||
fn linker(&self, target: TargetSelection) -> Option<PathBuf> {
|
||||
if let Some(linker) = self.config.target_config.get(&target).and_then(|c| c.linker.clone())
|
||||
{
|
||||
Some(linker)
|
||||
} else if target.contains("vxworks") {
|
||||
// need to use CXX compiler as linker to resolve the exception functions
|
||||
// that are only existed in CXX libraries
|
||||
Some(self.cxx[&target].path())
|
||||
Some(self.cxx.borrow()[&target].path().into())
|
||||
} else if target != self.config.build
|
||||
&& util::use_host_linker(target)
|
||||
&& !target.contains("msvc")
|
||||
{
|
||||
Some(self.cc(target))
|
||||
} else if self.config.use_lld && !self.is_fuse_ld_lld(target) && self.build == target {
|
||||
Some(&self.initial_lld)
|
||||
Some(self.initial_lld.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
@ -605,7 +605,7 @@ fn configure_cmake(
|
|||
}
|
||||
|
||||
let (cc, cxx) = match builder.config.llvm_clang_cl {
|
||||
Some(ref cl) => (cl.as_ref(), cl.as_ref()),
|
||||
Some(ref cl) => (cl.into(), cl.into()),
|
||||
None => (builder.cc(target), builder.cxx(target).unwrap()),
|
||||
};
|
||||
|
||||
|
@ -656,9 +656,9 @@ fn configure_cmake(
|
|||
.define("CMAKE_CXX_COMPILER_LAUNCHER", ccache);
|
||||
}
|
||||
}
|
||||
cfg.define("CMAKE_C_COMPILER", sanitize_cc(cc))
|
||||
.define("CMAKE_CXX_COMPILER", sanitize_cc(cxx))
|
||||
.define("CMAKE_ASM_COMPILER", sanitize_cc(cc));
|
||||
cfg.define("CMAKE_C_COMPILER", sanitize_cc(&cc))
|
||||
.define("CMAKE_CXX_COMPILER", sanitize_cc(&cxx))
|
||||
.define("CMAKE_ASM_COMPILER", sanitize_cc(&cc));
|
||||
}
|
||||
|
||||
cfg.build_arg("-j").build_arg(builder.jobs().to_string());
|
||||
|
@ -698,7 +698,7 @@ fn configure_cmake(
|
|||
if ar.is_absolute() {
|
||||
// LLVM build breaks if `CMAKE_AR` is a relative path, for some reason it
|
||||
// tries to resolve this path in the LLVM build directory.
|
||||
cfg.define("CMAKE_AR", sanitize_cc(ar));
|
||||
cfg.define("CMAKE_AR", sanitize_cc(&ar));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -706,7 +706,7 @@ fn configure_cmake(
|
|||
if ranlib.is_absolute() {
|
||||
// LLVM build breaks if `CMAKE_RANLIB` is a relative path, for some reason it
|
||||
// tries to resolve this path in the LLVM build directory.
|
||||
cfg.define("CMAKE_RANLIB", sanitize_cc(ranlib));
|
||||
cfg.define("CMAKE_RANLIB", sanitize_cc(&ranlib));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1698,7 +1698,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the
|
|||
// Note that if we encounter `PATH` we make sure to append to our own `PATH`
|
||||
// rather than stomp over it.
|
||||
if target.contains("msvc") {
|
||||
for &(ref k, ref v) in builder.cc[&target].env() {
|
||||
for &(ref k, ref v) in builder.cc.borrow()[&target].env() {
|
||||
if k != "PATH" {
|
||||
cmd.env(k, v);
|
||||
}
|
||||
|
|
|
@ -855,7 +855,7 @@ impl<'a> Builder<'a> {
|
|||
if compiler.host.contains("msvc") {
|
||||
let curpaths = env::var_os("PATH").unwrap_or_default();
|
||||
let curpaths = env::split_paths(&curpaths).collect::<Vec<_>>();
|
||||
for &(ref k, ref v) in self.cc[&compiler.host].env() {
|
||||
for &(ref k, ref v) in self.cc.borrow()[&compiler.host].env() {
|
||||
if k != "PATH" {
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue