]> git.lizzy.rs Git - rust.git/blobdiff - src/bootstrap/cc_detect.rs
Rollup merge of #68279 - GuillaumeGomez:clean-up-e0198, r=Dylan-DPC
[rust.git] / src / bootstrap / cc_detect.rs
index a4cb81d3d1b1b02716417c3c26752f7284b3a2f5..a236edf971fcca2702e0e111688ad217f4d371a8 100644 (file)
 //! everything.
 
 use std::collections::HashSet;
-use std::{env, iter};
 use std::path::{Path, PathBuf};
 use std::process::Command;
+use std::{env, iter};
 
 use build_helper::output;
 
-use crate::{Build, GitRepo};
-use crate::config::Target;
 use crate::cache::Interned;
+use crate::config::Target;
+use crate::{Build, GitRepo};
 
 // The `cc` crate doesn't provide a way to obtain a path to the detected archiver,
 // so use some simplified logic here. First we respect the environment variable `AR`, then
@@ -64,14 +64,25 @@ fn cc2ar(cc: &Path, target: &str) -> Option<PathBuf> {
 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.
-    let targets = build.targets.iter().chain(&build.hosts).cloned().chain(iter::once(build.build))
-                               .collect::<HashSet<_>>();
+    let targets = build
+        .targets
+        .iter()
+        .chain(&build.hosts)
+        .cloned()
+        .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).host(&build.build);
+        cfg.cargo_metadata(false)
+            .opt_level(2)
+            .warnings(false)
+            .debug(false)
+            .target(&target)
+            .host(&build.build);
         match build.crt_static(target) {
-            Some(a) => { cfg.static_crt(a); }
+            Some(a) => {
+                cfg.static_crt(a);
+            }
             None => {
                 if target.contains("msvc") {
                     cfg.static_crt(true);
@@ -102,8 +113,13 @@ 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).host(&build.build);
+        cfg.cargo_metadata(false)
+            .opt_level(2)
+            .warnings(false)
+            .debug(false)
+            .cpp(true)
+            .target(&target)
+            .host(&build.build);
 
         let cxx_configured = if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) {
             cfg.compiler(cxx);
@@ -133,21 +149,24 @@ pub fn find(build: &mut Build) {
     }
 }
 
-fn set_compiler(cfg: &mut cc::Build,
-                compiler: Language,
-                target: Interned<String>,
-                config: Option<&Target>,
-                build: &Build) {
+fn set_compiler(
+    cfg: &mut cc::Build,
+    compiler: Language,
+    target: Interned<String>,
+    config: Option<&Target>,
+    build: &Build,
+) {
     match &*target {
         // When compiling for android we may have the NDK configured in the
         // config.toml in which case we look there. Otherwise the default
         // compiler already takes into account the triple in question.
         t if t.contains("android") => {
             if let Some(ndk) = config.and_then(|c| c.ndk.as_ref()) {
-                let target = target.replace("armv7neon", "arm")
-                                   .replace("armv7", "arm")
-                                   .replace("thumbv7neon", "arm")
-                                   .replace("thumbv7", "arm");
+                let target = target
+                    .replace("armv7neon", "arm")
+                    .replace("armv7", "arm")
+                    .replace("thumbv7neon", "arm")
+                    .replace("thumbv7", "arm");
                 let compiler = format!("{}-{}", target, compiler.clang());
                 cfg.compiler(ndk.join("bin").join(compiler));
             }
@@ -159,7 +178,7 @@ fn set_compiler(cfg: &mut cc::Build,
             let c = cfg.get_compiler();
             let gnu_compiler = compiler.gcc();
             if !c.path().ends_with(gnu_compiler) {
-                return
+                return;
             }
 
             let output = output(c.to_command().arg("--version"));
@@ -168,7 +187,7 @@ fn set_compiler(cfg: &mut cc::Build,
                 None => return,
             };
             match output[i + 3..].chars().next().unwrap() {
-                '0' ..= '6' => {}
+                '0'..='6' => {}
                 _ => return,
             }
             let alternative = format!("e{}", gnu_compiler);