From 68d111f946972378489531f0632cec6bfd985de0 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Thu, 23 Jun 2022 14:47:59 +1000 Subject: [PATCH] Use `get_desired_targets` in `entry` instead of `detect_targets`, so that if `opts.targets` is `None`, the future returned by `detect_targets` can be run in parallel by using `tokio::spawn` with other async code in `entry`, such as `fetch_crate_cratesio`. Signed-off-by: Jiahao XU --- src/main.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0d8748cc..35804af7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -193,6 +193,8 @@ async fn entry() -> Result<()> { let mut uithread = UIThread::new(!opts.no_confirm); + let desired_targets = get_desired_targets(&opts.targets); + // Compute install directory let install_path = get_install_path(opts.install_path.as_deref()).ok_or_else(|| { error!("No viable install path found of specified, try `--install-path`"); @@ -242,22 +244,11 @@ async fn entry() -> Result<()> { manifest.bin, ); - let desired_targets = { - let from_opts = opts - .targets - .as_ref() - .map(|ts| ts.split(',').map(|t| t.to_string()).collect()); - - if let Some(ts) = from_opts { - ts - } else { - detect_targets().await - } - }; - let mut fetchers = MultiFetcher::default(); - for target in &desired_targets { + let desired_targets = desired_targets.get().await; + + for target in desired_targets { debug!("Building metadata for target: {target}"); let mut target_meta = meta.clone();