Skip to content

Commit

Permalink
feat(cli): always validate iOS lib (#10845)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Sep 2, 2024
1 parent b426835 commit 9c9644d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .changes/enhance-ios-lib-validation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'tauri-cli': 'patch:enhance'
'@tauri-apps/cli': 'patch:enhance'
---

Enhance iOS library validation, checking libs built with link time optimization.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions crates/tauri-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ libc = "0.2"
[target."cfg(target_os = \"macos\")".dependencies]
plist = "1"
tauri-macos-sign = { version = "0.1.1-rc.0", path = "../tauri-macos-sign" }
object = { version = "0.36", default-features = false, features = [
"macho",
"read_core",
"std",
] }
ar = "0.9"

[features]
default = ["rustls"]
Expand Down
39 changes: 25 additions & 14 deletions crates/tauri-cli/src/mobile/ios/xcode_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ use crate::{
use anyhow::Context;
use cargo_mobile2::{apple::target::Target, opts::Profile};
use clap::Parser;
use object::{Object, ObjectSymbol};

use std::{
collections::HashMap,
env::{current_dir, set_current_dir, var, var_os},
ffi::OsStr,
fs::read_to_string,
io::Read,
path::{Path, PathBuf},
process::Command,
};

#[derive(Debug, Parser)]
Expand Down Expand Up @@ -228,10 +229,7 @@ pub fn command(options: Options) -> Result<()> {
return Err(anyhow::anyhow!("Library not found at {}. Make sure your Cargo.toml file has a [lib] block with `crate-type = [\"staticlib\", \"cdylib\", \"lib\"]`", lib_path.display()));
}

// for some reason the app works on release, but `nm <path>` does not print the start_app symbol
if profile == Profile::Debug {
validate_lib(&lib_path)?;
}
validate_lib(&lib_path)?;

let project_dir = config.project_dir();
let externals_lib_dir = project_dir.join(format!("Externals/{arch}/{}", profile.as_str()));
Expand Down Expand Up @@ -261,15 +259,28 @@ pub fn command(options: Options) -> Result<()> {
}

fn validate_lib(path: &Path) -> Result<()> {
// we ignore `nm` errors
if let Ok(output) = Command::new("nm").arg(path).output() {
let symbols = String::from_utf8_lossy(&output.stdout);
if !symbols.contains("start_app") {
anyhow::bail!(
"Library from {} does not include required runtime symbols. This means you are likely missing the tauri::mobile_entry_point macro usage, see the documentation for more information: https://v2.tauri.app/start/migrate/from-tauri-1",
path.display()
);
let mut archive = ar::Archive::new(std::fs::File::open(path)?);
// Iterate over all entries in the archive:
while let Some(entry) = archive.next_entry() {
let Ok(mut entry) = entry else {
continue;
};
let mut obj_bytes = Vec::new();
entry.read_to_end(&mut obj_bytes)?;

let file = object::File::parse(&*obj_bytes)?;
for symbol in file.symbols() {
let Ok(name) = symbol.name() else {
continue;
};
if name.contains("start_app") {
return Ok(());
}
}
}
Ok(())

anyhow::bail!(
"Library from {} does not include required runtime symbols. This means you are likely missing the tauri::mobile_entry_point macro usage, see the documentation for more information: https://v2.tauri.app/start/migrate/from-tauri-1",
path.display()
)
}

0 comments on commit 9c9644d

Please sign in to comment.