Skip to content

Commit

Permalink
feat: validate library artifact existence
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Dec 28, 2022
1 parent d3f446d commit 807861a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changes/missing-lib-error-message.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-mobile": patch
---

Improve error message for missing library artifact.
2 changes: 1 addition & 1 deletion 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 src/android/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)?;
Expand Down
26 changes: 16 additions & 10 deletions src/apple/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ pub enum Error {
CompileLibFailed(CompileLibError),
PodCommandFailed(bossy::Error),
CopyLibraryFailed(std::io::Error),
LibNotFound { path: PathBuf },
}

impl Reportable for Error {
Expand Down Expand Up @@ -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())),
}
}
}
Expand Down Expand Up @@ -479,23 +481,27 @@ 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!(
"Sources/{rust_triple}/{}",
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(())
Expand Down

0 comments on commit 807861a

Please sign in to comment.