Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cargo publish path does not point to folder with .so files #3

Open
NumesSanguis opened this issue May 25, 2024 · 2 comments
Open

Cargo publish path does not point to folder with .so files #3

NumesSanguis opened this issue May 25, 2024 · 2 comments

Comments

@NumesSanguis
Copy link

NumesSanguis commented May 25, 2024

Issue

Following your blog post at: Rust cross-platform... The Android part..., I run into the issue that cargo run --bin publish gives the error Error copying library file. The full output that that command gives:

warning: `/home/{user}/github/Rust-Cross-Platform-Development/rust-library/cryptor_jni/.cargo/config` is deprecated in favor of `config.toml`
note: if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
   Compiling cryptor_jni v0.1.0 (/home/{user}/github/Rust-Cross-Platform-Development/rust-library/cryptor_jni)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.33s
     Running `target/debug/publish`
Message: Error copying library file

This error message comes from line 150 in publish.rs.

Probable cause

It seems that cryptor_jni is missing from the path used in publish.

The output paths:

  • cargo run --bin release path: Rust-Cross-Platform-Development/rust-library/cryptor_jni/target/armv7-linux-androideabi/release/libcryptor_jni.so
  • cargo run --bin publish path: Rust-Cross-Platform-Development/rust-library/target/armv7-linux-androideabi/release/libcryptor_jni.so

I executed the release and publish commands from: Rust-Cross-Platform-Development/rust-library/cryptor_jni

Release from rust-library

If I run the command rust-library$ cargo run --bin release (instead of in rust-library/cryptor_jni), it throws the error:

error: multiple workspace roots found in the same workspace:
  /home/{user}/github/Rust-Cross-Platform-Development/rust-library/cryptor_jni
  /home/{user}/github/Rust-Cross-Platform-Development/rust-library

Debugging

I modified that Err line to output crate_lib_file_path and android_lib_file_path:

return Err(format!("Error copying library file {} |\n{}", crate_lib_file_path, android_lib_file_path).into())

Which gives me:

Message: Error copying library file /home/{user}/github/Rust-Cross-Platform-Development/rust-library/target/armv7-linux-androideabi/release/libcryptor_jni.so |
/home/{user}/github/Rust-Cross-Platform-Development/android-sample/app/src/main/jniLibs/armeabi-v7a/libcryptor_jni.so

Comparing this to the output from cargo run --bin release:

warning: `/home/{user}/github/Rust-Cross-Platform-Development/rust-library/cryptor_jni/.cargo/config` is deprecated in favor of `config.toml`
note: if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.02s
     Running `target/debug/release`
Message: Releasing Android Targets...Be patient... :)
Message: Building Android Target --> armv7-linux-androideabi
warning: `/home/{user}/github/Rust-Cross-Platform-Development/rust-library/cryptor_jni/.cargo/config` is deprecated in favor of `config.toml`
note: if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
   Compiling cryptor_jni v0.1.0 (/home/{user}/github/Rust-Cross-Platform-Development/rust-library/cryptor_jni)
    Finished `release` profile [optimized] target(s) in 0.49s
...
@NumesSanguis
Copy link
Author

NumesSanguis commented May 25, 2024

Adding the following 2 lines to Rust-Cross-Platform-Development/rust-library/cryptor_jni/src/bin/publish.rs:

    crate_lib_file_path.push_str(MAIN_SEPARATOR_STR);
    crate_lib_file_path.push_str("cryptor_jni");

To the function:

/// `$ rust-library/target/x86_64-linux-android/release/JNI_LIB_FILE_NAME`
/// 
fn crate_file_path_for_target(project_dir_path: &str, android_target: &str) -> String {
    let mut crate_lib_file_path = project_dir_path.to_owned();

    crate_lib_file_path.push_str(MAIN_SEPARATOR_STR);
    crate_lib_file_path.push_str("cryptor_jni");
    crate_lib_file_path.push_str(MAIN_SEPARATOR_STR);
    crate_lib_file_path.push_str("target");
    crate_lib_file_path.push_str(MAIN_SEPARATOR_STR);
    crate_lib_file_path.push_str(&android_target);
    crate_lib_file_path.push_str(MAIN_SEPARATOR_STR);
    crate_lib_file_path.push_str("release");
    crate_lib_file_path.push_str(MAIN_SEPARATOR_STR);
    crate_lib_file_path.push_str(JNI_LIB_FILE_NAME);

    crate_lib_file_path
}

Solved the issue for me and it was able to execute successfully.

Hardcoding "cryptor_jni" might not be the correct approach to solve it properly though?

@NumesSanguis
Copy link
Author

It might have been a problem on my side. I added the following lines (to have Rust stop complaining):

[workspace]
resolver = "2"

to Cargo.toml located in rust-library/cryptor_jni, instead of the Cargo.toml located in the top folder rust-library.

I think changing this resulted in the correct rust-library/target folder having the binaries instead of rust-library/cryptor_jni/target

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant