Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that static_crt is set in the bootstrapper whenever using cc-rs to get a compiler command line. #98434

Merged
merged 1 commit into from
Jun 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 27 additions & 30 deletions src/bootstrap/cc_detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,30 @@ fn cc2ar(cc: &Path, target: TargetSelection) -> Option<PathBuf> {
}
}

fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build {
let mut cfg = cc::Build::new();
cfg.cargo_metadata(false)
.opt_level(2)
.warnings(false)
.debug(false)
.target(&target.triple)
.host(&build.build.triple);
match build.crt_static(target) {
Some(a) => {
cfg.static_crt(a);
}
None => {
if target.contains("msvc") {
cfg.static_crt(true);
}
if target.contains("musl") {
cfg.static_flag(true);
}
}
}
cfg
}

pub fn find(build: &mut 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.
Expand All @@ -72,27 +96,7 @@ pub fn find(build: &mut Build) {
.chain(iter::once(build.build))
.collect::<HashSet<_>>();
for target in targets.into_iter() {
let mut cfg = cc::Build::new();
cfg.cargo_metadata(false)
.opt_level(2)
.warnings(false)
.debug(false)
.target(&target.triple)
.host(&build.build.triple);
match build.crt_static(target) {
Some(a) => {
cfg.static_crt(a);
}
None => {
if target.contains("msvc") {
cfg.static_crt(true);
}
if target.contains("musl") {
cfg.static_flag(true);
}
}
}

let mut cfg = new_cc_build(build, target);
let config = build.config.target_config.get(&target);
if let Some(cc) = config.and_then(|c| c.cc.as_ref()) {
cfg.compiler(cc);
Expand All @@ -112,15 +116,8 @@ pub fn find(build: &mut Build) {

// If we use llvm-libunwind, we will need a C++ compiler as well for all targets
// We'll need one anyways if the target triple is also a host triple
let mut cfg = cc::Build::new();
cfg.cargo_metadata(false)
.opt_level(2)
.warnings(false)
.debug(false)
.cpp(true)
.target(&target.triple)
.host(&build.build.triple);

let mut cfg = new_cc_build(build, target);
dpaoliello marked this conversation as resolved.
Show resolved Hide resolved
cfg.cpp(true);
let cxx_configured = if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) {
cfg.compiler(cxx);
true
Expand Down