Inline creation of TargetInfos in Context::new()
authorDirkjan Ochtman <dirkjan@ochtman.nl>
Fri, 13 Apr 2018 18:09:50 +0000 (20:09 +0200)
committerDirkjan Ochtman <dirkjan@ochtman.nl>
Fri, 13 Apr 2018 18:09:50 +0000 (20:09 +0200)
src/cargo/core/compiler/context/mod.rs
src/cargo/core/compiler/context/target_info.rs

index 77ca4cc5f11cf6d8f5d9eaf09ce0eb7ef9de29d2..e6fab8ed0d6efd1c289c2bd5bb40a634e6036855 100644 (file)
@@ -125,13 +125,31 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
             None => Client::new(build_config.jobs as usize - 1)
                 .chain_err(|| "failed to create jobserver")?,
         };
+
+        let (host_info, target_info) = {
+            let _p = profile::start("Context::probe_target_info");
+            debug!("probe_target_info");
+            let host_target_same = match build_config.requested_target {
+                Some(ref s) if s != &config.rustc()?.host => false,
+                _ => true,
+            };
+
+            let host_info = TargetInfo::new(config, &build_config, Kind::Host)?;
+            let target_info = if host_target_same {
+                host_info.clone()
+            } else {
+                TargetInfo::new(config, &build_config, Kind::Target)?
+            };
+            (host_info, target_info)
+        };
+
         let mut cx = Context {
             ws,
             resolve,
             packages,
             config,
-            target_info: TargetInfo::default(),
-            host_info: TargetInfo::default(),
+            target_info,
+            host_info,
             compilation: Compilation::new(config),
             build_state: Arc::new(BuildState::new(&build_config)),
             build_config,
@@ -150,7 +168,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
             files: None,
         };
 
-        cx.probe_target_info()?;
+        cx.compilation.host_dylib_path = cx.host_info.sysroot_libdir.clone();
+        cx.compilation.target_dylib_path = cx.target_info.sysroot_libdir.clone();
         Ok(cx)
     }
 
@@ -341,27 +360,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
         Ok(())
     }
 
-    /// Ensure that we've collected all target-specific information to compile
-    /// all the units mentioned in `units`.
-    fn probe_target_info(&mut self) -> CargoResult<()> {
-        let _p = profile::start("Context::probe_target_info");
-        debug!("probe_target_info");
-        let host_target_same = match self.build_config.requested_target {
-            Some(ref s) if s != &self.config.rustc()?.host => false,
-            _ => true,
-        };
-
-        self.host_info = TargetInfo::new(self.config, &self.build_config, Kind::Host)?;
-        self.target_info = if host_target_same {
-            self.host_info.clone()
-        } else {
-            TargetInfo::new(self.config, &self.build_config, Kind::Target)?
-        };
-        self.compilation.host_dylib_path = self.host_info.sysroot_libdir.clone();
-        self.compilation.target_dylib_path = self.target_info.sysroot_libdir.clone();
-        Ok(())
-    }
-
     /// Builds up the `used_in_plugin` internal to this context from the list of
     /// top-level units.
     ///
index 1d1061259b9e9b54d0b68d394682c85c0a559c03..40a840103757a22326713caffd827682992a570b 100644 (file)
@@ -8,7 +8,7 @@ use util::{CargoResult, CargoResultExt, Cfg, Config, ProcessBuilder};
 use core::TargetKind;
 use super::Kind;
 
-#[derive(Clone, Default)]
+#[derive(Clone)]
 pub struct TargetInfo {
     crate_type_process: Option<ProcessBuilder>,
     crate_types: RefCell<HashMap<String, Option<(String, String)>>>,