From 66c2dac38f132fea6311b56cc632d602d1a29eb8 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Wed, 23 Jul 2025 17:41:04 -0700 Subject: [PATCH] better logs, don't run codesign if no assets are found (#4464) --- packages/cli/src/build/assets.rs | 6 +- packages/cli/src/build/builder.rs | 4 +- packages/cli/src/build/request.rs | 9 +-- packages/cli/src/cli/doctor.rs | 93 +++++++++++++++++++++++-------- packages/cli/src/workspace.rs | 61 +++++++++++++------- 5 files changed, 119 insertions(+), 54 deletions(-) diff --git a/packages/cli/src/build/assets.rs b/packages/cli/src/build/assets.rs index 79f10bbaa..4e37b19c9 100644 --- a/packages/cli/src/build/assets.rs +++ b/packages/cli/src/build/assets.rs @@ -337,19 +337,21 @@ pub(crate) fn extract_assets_from_file(path: impl AsRef) -> Result {{ Ok(()) } - fn select_ranlib(&self) -> Option { - // prefer the modern llvm-ranlib if they have it - which::which("llvm-ranlib") - .or_else(|_| which::which("ranlib")) - .ok() - } - /// Assemble a series of `--config key=value` arguments for the build command. /// /// This adds adhoc profiles that dx uses to isolate builds from each other. Normally if you ran diff --git a/packages/cli/src/cli/doctor.rs b/packages/cli/src/cli/doctor.rs index 948f2b500..8008bbb52 100644 --- a/packages/cli/src/cli/doctor.rs +++ b/packages/cli/src/cli/doctor.rs @@ -9,13 +9,16 @@ pub(crate) struct Doctor {} impl Doctor { pub async fn doctor(self) -> Result { - let Ok(workspace) = Workspace::current().await else { - bail!("dx doctor must be run within a cargo workspace!") - }; - - let rustc_version = &workspace.rustc_version; - let rustc_sysroot = &workspace.sysroot.to_string_lossy(); - let rustlib = workspace.sysroot.join("lib").join("rustlib"); + let mut rustc_version = "not found".to_string(); + let mut rustc_sysroot = "not found".to_string(); + let mut rustlib = PathBuf::from("."); + if let Ok(r) = Workspace::get_rustc_sysroot().await { + rustlib = PathBuf::from(r.as_str()).join("lib").join("rustlib"); + rustc_sysroot = r; + } + if let Ok(r) = Workspace::get_rustc_version().await { + rustc_version = r; + } // wasm-opt let wasm_opt_location = crate::wasm_opt::installed_location(); @@ -25,18 +28,20 @@ impl Doctor { }; // wasm-bindgen - let wbg_version = workspace.wasm_bindgen_version(); - let wbg_version_msg = match wbg_version.clone() { - Some(msg) => msg, - None => "not required".to_string(), - }; - let wasm_bindgen_location = match wbg_version { - Some(vers) => match crate::wasm_bindgen::WasmBindgen::new(&vers).get_binary_path() { - Ok(path) => path.to_string_lossy().to_string(), - Err(err) => err.to_string().lines().join(""), - }, - None => "not required".to_string(), - }; + let mut wbg_version_msg = "automatically managed".to_string(); + let mut wasm_bindgen_location = "automatically managed".to_string(); + if let Ok(workspace) = Workspace::current().await { + let wbg_version = workspace.wasm_bindgen_version(); + if let Some(vers) = &wbg_version { + wbg_version_msg = vers.to_string(); + + wasm_bindgen_location = + match crate::wasm_bindgen::WasmBindgen::new(vers).get_binary_path() { + Ok(path) => path.to_string_lossy().to_string(), + Err(err) => err.to_string().lines().join(""), + }; + } + } // extensions fn has_dioxus_ext(editor_dir: &str) -> anyhow::Result { @@ -81,7 +86,7 @@ impl Doctor { let mut sdk = "not found".to_string(); let mut java_home = "not found".to_string(); let mut emulator = "not found".to_string(); - if let Some(rf) = workspace.android_tools.as_deref() { + if let Some(rf) = crate::build::get_android_tools() { if rf.adb.exists() { adb = rf.adb.display().to_string(); } @@ -104,7 +109,7 @@ impl Doctor { let mut simulator_location = "not found".to_string(); let mut xcode_install = "not found".to_string(); - if let Some(xcode) = workspace.xcode.as_ref() { + if let Some(xcode) = Workspace::get_xcode_path().await { let sim_location = xcode.join("Applications").join("Simulator.app"); if sim_location.exists() { simulator_location = sim_location.display().to_string(); @@ -114,6 +119,27 @@ impl Doctor { } } + let mut security_cli_path = "not found".to_string(); + let mut codesign_path = "not found".to_string(); + let mut xcode_select_path = "not found".to_string(); + let mut xcrun_path = "not found".to_string(); + let mut ranlib_path = "not found".to_string(); + if let Ok(path) = which::which("security") { + security_cli_path = path.display().to_string(); + } + if let Ok(path) = which::which("codesign") { + codesign_path = path.display().to_string(); + } + if let Ok(path) = which::which("xcode-select") { + xcode_select_path = path.display().to_string(); + } + if let Ok(path) = which::which("xcrun") { + xcrun_path = path.display().to_string(); + } + if let Some(path) = Workspace::select_ranlib() { + ranlib_path = path.display().to_string(); + } + // toolchains let mut has_wasm32_unknown_unknown = "❌"; let mut has_aarch64_android_linux = "❌"; @@ -152,6 +178,20 @@ impl Doctor { has_aarch64_apple_darwin = "✅"; } + // Rust tool paths + let mut rustc_path = "not found".to_string(); + let mut cargo_path = "not found".to_string(); + let mut cc_path = "not found".to_string(); + if let Ok(path) = which::which("rustc") { + rustc_path = path.display().to_string(); + } + if let Ok(path) = which::which("cargo") { + cargo_path = path.display().to_string(); + } + if let Ok(path) = which::which("cc") { + cc_path = path.display().to_string(); + } + // Things to know // - current rust version and rust-related things // - installed toolchains @@ -165,10 +205,14 @@ impl Doctor { {GLOW_STYLE}macOS{GLOW_STYLE:#}: all tools should be installed by default {GLOW_STYLE}Windows{GLOW_STYLE:#}: install the webview2 binary {GLOW_STYLE}Linux{GLOW_STYLE:#}: Install libwebkit2gtk-4.1-dev libgtk-3-dev libasound2-dev libudev-dev libayatana-appindicator3-dev libxdo-dev libglib2.0-dev + {GLOW_STYLE}nix{GLOW_STYLE:#}: Make sure all tools are in your path (codesign, ld, etc.) {LINK_STYLE}Rust{LINK_STYLE:#} Rustc version: {HINT_STYLE}{rustc_version}{HINT_STYLE:#} Rustc sysroot: {HINT_STYLE}{rustc_sysroot}{HINT_STYLE:#} + Rustc path: {HINT_STYLE}{rustc_path}{HINT_STYLE:#} + Cargo path: {HINT_STYLE}{cargo_path}{HINT_STYLE:#} + cc path: {HINT_STYLE}{cc_path}{HINT_STYLE:#} {LINK_STYLE}Devtools{LINK_STYLE:#} VSCode Extension: {HINT_STYLE}{vscode_ext_msg}{HINT_STYLE:#} @@ -180,9 +224,14 @@ impl Doctor { wasm-bindgen: {HINT_STYLE}{wasm_bindgen_location}{HINT_STYLE:#} wasm-bindgen version: {HINT_STYLE}{wbg_version_msg}{HINT_STYLE:#} -{LINK_STYLE}iOS{LINK_STYLE:#} +{LINK_STYLE}iOS/macOS{LINK_STYLE:#} XCode: {HINT_STYLE}{xcode_install}{HINT_STYLE:#} Simulator: {HINT_STYLE}{simulator_location}{HINT_STYLE:#} + Security CLI: {HINT_STYLE}{security_cli_path}{HINT_STYLE:#} + Codesign CII: {HINT_STYLE}{codesign_path}{HINT_STYLE:#} + xcode-select: {HINT_STYLE}{xcode_select_path}{HINT_STYLE:#} + xcrun: {HINT_STYLE}{xcrun_path}{HINT_STYLE:#} + ranlib: {HINT_STYLE}{ranlib_path}{HINT_STYLE:#} {LINK_STYLE}Android{LINK_STYLE:#} sdk: {HINT_STYLE}{sdk}{HINT_STYLE:#} diff --git a/packages/cli/src/workspace.rs b/packages/cli/src/workspace.rs index 31aa7a354..191819e65 100644 --- a/packages/cli/src/workspace.rs +++ b/packages/cli/src/workspace.rs @@ -21,7 +21,6 @@ pub struct Workspace { pub(crate) ignore: Gitignore, pub(crate) cargo_toml: cargo_toml::Manifest, pub(crate) android_tools: Option>, - pub(crate) xcode: Option, } impl Workspace { @@ -86,19 +85,12 @@ impl Workspace { }; let settings = CliSettings::global_or_default(); - let sysroot = Command::new("rustc") - .args(["--print", "sysroot"]) - .output() + let sysroot = Self::get_rustc_sysroot() .await - .map(|out| String::from_utf8(out.stdout))? - .context("Failed to extract rustc sysroot output")?; - - let rustc_version = Command::new("rustc") - .args(["--version"]) - .output() + .context("Failed to get rustc sysroot")?; + let rustc_version = Self::get_rustc_version() .await - .map(|out| String::from_utf8(out.stdout))? - .context("Failed to extract rustc version output")?; + .context("Failed to get rustc version")?; let wasm_opt = which::which("wasm-opt").ok(); @@ -110,13 +102,6 @@ impl Workspace { let android_tools = crate::build::get_android_tools(); - let xcode = Command::new("xcode-select") - .arg("-p") - .output() - .await - .ok() - .map(|s| String::from_utf8_lossy(&s.stdout).trim().to_string().into()); - let workspace = Arc::new(Self { krates, settings, @@ -126,7 +111,6 @@ impl Workspace { ignore, cargo_toml, android_tools, - xcode, }); tracing::debug!( @@ -263,6 +247,13 @@ impl Workspace { self.gcc_ld_dir().join("wasm-ld") } + pub fn select_ranlib() -> Option { + // prefer the modern llvm-ranlib if they have it + which::which("llvm-ranlib") + .or_else(|_| which::which("ranlib")) + .ok() + } + /// Return the version of the wasm-bindgen crate if it exists pub fn wasm_bindgen_version(&self) -> Option { self.krates @@ -484,6 +475,36 @@ impl Workspace { .context("Failed to find directory containing Cargo.toml") } + pub async fn get_xcode_path() -> Option { + let xcode = Command::new("xcode-select") + .arg("-p") + .output() + .await + .ok() + .map(|s| String::from_utf8_lossy(&s.stdout).trim().to_string().into()); + xcode + } + + pub async fn get_rustc_sysroot() -> Result { + let sysroot = Command::new("rustc") + .args(["--print", "sysroot"]) + .output() + .await + .map(|out| String::from_utf8(out.stdout).map(|s| s.trim().to_string()))? + .context("Failed to extract rustc sysroot output")?; + Ok(sysroot) + } + + pub async fn get_rustc_version() -> Result { + let rustc_version = Command::new("rustc") + .args(["--version"]) + .output() + .await + .map(|out| String::from_utf8(out.stdout))? + .context("Failed to extract rustc version output")?; + Ok(rustc_version) + } + /// Returns the properly canonicalized path to the dx executable, used for linking and wrapping rustc pub(crate) fn path_to_dx() -> Result { dunce::canonicalize(std::env::current_exe().context("Failed to find dx")?)