better logs, don't run codesign if no assets are found (#4464)

This commit is contained in:
Jonathan Kelley authored and GitHub committed 2025-07-23 17:41:04 -07:00
1 parent f9f30263d3
commit 66c2dac38f
5 files changed
+119 -54

No files matched your search

+4 -2
View File
@@ -337,19 +337,21 @@ pub(crate) fn extract_assets_from_file(path: impl AsRef<Path>) -> Result<AssetMa
// Write the modified binary data back to the file
file.write_all(new_data.as_ref())?;
}
// Ensure the file is flushed to disk
file.sync_all()
.context("Failed to sync file after writing assets")?;
// If the file is a macos binary, we need to re-sign the modified binary
if object_file.format() == object::BinaryFormat::MachO {
if object_file.format() == object::BinaryFormat::MachO && !assets.is_empty() {
// Spawn the codesign command to re-sign the binary
let output = std::process::Command::new("codesign")
.arg("--force")
.arg("--sign")
.arg("-") // Sign with an empty identity
.arg(path)
.output()?;
.output()
.context("Failed to run codesign - is `codesign` in your path?")?;
if !output.status.success() {
bail!(
+2 -2
View File
@@ -1086,7 +1086,7 @@ We checked the folders:
.args(["find-identity", "-v", "-p", "codesigning"])
.output()
.await
.context("Failed to run `security find-identity -v -p codesigning`")
.context("Failed to run `security find-identity -v -p codesigning` - is `security` in your path?")
.map(|e| {
String::from_utf8(e.stdout)
.context("Failed to parse `security find-identity -v -p codesigning`")
@@ -1191,7 +1191,7 @@ We checked the folders:
.arg(self.build.root_dir())
.output()
.await
.context("Failed to codesign the app")?;
.context("Failed to codesign the app - is `codesign` in your path?")?;
if !output.status.success() {
bail!(
+1 -8
View File
@@ -1874,7 +1874,7 @@ impl BuildRequest {
// but is necessary for some linkers to work properly.
// We ignore its error in case it doesn't recognize the architecture
if self.linker_flavor() == LinkerFlavor::Darwin {
if let Some(ranlib) = self.select_ranlib() {
if let Some(ranlib) = Workspace::select_ranlib() {
_ = Command::new(ranlib).arg(&out_ar_path).output().await;
}
}
@@ -4607,13 +4607,6 @@ __wbg_init({{module_or_path: "/{}/{wasm_path}"}}).then((wasm) => {{
Ok(())
}
fn select_ranlib(&self) -> Option<PathBuf> {
// 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
+71 -22
View File
@@ -9,13 +9,16 @@ pub(crate) struct Doctor {}
impl Doctor {
pub async fn doctor(self) -> Result<StructuredOutput> {
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<PathBuf> {
@@ -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:#}
+41 -20
View File
@@ -21,7 +21,6 @@ pub struct Workspace {
pub(crate) ignore: Gitignore,
pub(crate) cargo_toml: cargo_toml::Manifest,
pub(crate) android_tools: Option<Arc<AndroidTools>>,
pub(crate) xcode: Option<PathBuf>,
}
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<PathBuf> {
// 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<String> {
self.krates
@@ -484,6 +475,36 @@ impl Workspace {
.context("Failed to find directory containing Cargo.toml")
}
pub async fn get_xcode_path() -> Option<PathBuf> {
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<String, anyhow::Error> {
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<String> {
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<PathBuf> {
dunce::canonicalize(std::env::current_exe().context("Failed to find dx")?)