From 807861acfedf50e31086db62e56d296a62638194 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Wed, 28 Dec 2022 14:42:30 -0300 Subject: [PATCH] feat: validate library artifact existence --- .changes/missing-lib-error-message.md | 5 +++++ Cargo.lock | 2 +- src/android/target.rs | 6 ++++++ src/apple/cli.rs | 26 ++++++++++++++++---------- 4 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 .changes/missing-lib-error-message.md diff --git a/.changes/missing-lib-error-message.md b/.changes/missing-lib-error-message.md new file mode 100644 index 00000000..505b2146 --- /dev/null +++ b/.changes/missing-lib-error-message.md @@ -0,0 +1,5 @@ +--- +"tauri-mobile": patch +--- + +Improve error message for missing library artifact. diff --git a/Cargo.lock b/Cargo.lock index acb86454..fb130e82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1085,7 +1085,7 @@ dependencies = [ [[package]] name = "tauri-mobile" -version = "0.1.2" +version = "0.1.3" dependencies = [ "cocoa", "colored", diff --git a/src/android/target.rs b/src/android/target.rs index 427dd9e4..9901c506 100644 --- a/src/android/target.rs +++ b/src/android/target.rs @@ -72,6 +72,8 @@ pub enum SymlinkLibsError { RequiredLibsFailed(ndk::RequiredLibsError), #[error("Failed to locate \"libc++_shared.so\": {0}")] LibcxxSharedPathFailed(ndk::MissingToolError), + #[error("Library artifact not found at {path}. Make sure your Cargo.toml file has a [lib] block with `crate-type = [\"staticlib\", \"cdylib\", \"rlib\"]`")] + LibNotFound { path: PathBuf }, } impl Reportable for SymlinkLibsError { @@ -311,6 +313,10 @@ impl<'a> Target<'a> { .target_dir(&self.triple, profile) .join(config.so_name()); + if !src.exists() { + return Err(SymlinkLibsError::LibNotFound { path: src }); + } + jnilibs .symlink_lib(&src) .map_err(SymlinkLibsError::SymlinkFailed)?; diff --git a/src/apple/cli.rs b/src/apple/cli.rs index 09bbd89a..21cc59f0 100644 --- a/src/apple/cli.rs +++ b/src/apple/cli.rs @@ -176,6 +176,7 @@ pub enum Error { CompileLibFailed(CompileLibError), PodCommandFailed(bossy::Error), CopyLibraryFailed(std::io::Error), + LibNotFound { path: PathBuf }, } impl Reportable for Error { @@ -220,6 +221,7 @@ impl Reportable for Error { Self::CompileLibFailed(err) => err.report(), Self::PodCommandFailed(err) => Report::error("pod command failed", err), Self::CopyLibraryFailed(err) => Report::error("Failed to copy static library to Xcode Project", err), + Self::LibNotFound { path } => Report::error("Library artifact not found", format!("Library not found at {}. Make sure your Cargo.toml file has a [lib] block with `crate-type = [\"staticlib\", \"cdylib\", \"rlib\"]`", path.display())), } } } @@ -479,6 +481,17 @@ impl Exec for Input { ) .map_err(Error::CompileLibFailed)?; + let lib_location = format!( + "{rust_triple}/{}/lib{}.a", + profile.as_str(), + AsSnakeCase(config.app().name()) + ); + let lib_path = PathBuf::from(format!("../../target/{lib_location}")); + + if !lib_path.exists() { + return Err(Error::LibNotFound { path: lib_path }); + } + // Copy static lib .a to Xcode Project if rust_triple == "aarch64-apple-ios" { std::fs::create_dir_all(format!( @@ -486,16 +499,9 @@ impl Exec for Input { profile.as_str() )) .map_err(Error::CopyLibraryFailed)?; - let lib_location = format!( - "{rust_triple}/{}/lib{}.a", - profile.as_str(), - AsSnakeCase(config.app().name()) - ); - std::fs::copy( - format!("../../target/{lib_location}"), - format!("Sources/{lib_location}"), - ) - .map_err(Error::CopyLibraryFailed)?; + + std::fs::copy(lib_path, format!("Sources/{lib_location}")) + .map_err(Error::CopyLibraryFailed)?; } } Ok(())