I am trying to write a few tests for a Rust - Java cross-platform program where Rust serves as a library for the backend. I want to call the tests from a new main.rs.
While the library (lib.rs) works fine when called from the Java code, I have trouble linking the main.rs to the lib.rs.
This works but has errors when cross-compiling:
Cargo.toml:
[package]
name = "rust_backend"
version = "0.1.0"
edition = "2018"
crate-type = ["cdylib"]
[dependencies]
jni = { version = "0.10.2", default-features = false }
[profile.release]
lto = true
lib.rs
pub const ĆALLING: &'static str = "Rust library called";
pub fn foo() -> bool {
return true;
}
main.rs
use rust_backend::CALLING;
use rust_backend::foo;
fn main() {
println!("{}", CALLING);
if foo() == true { {
println!("foo");
}
}
I want my Cargo.toml to look like this so that cross-compiling works:
[package]
name = "rust_backend"
version = "0.1.0"
edition = "2018"
[dependencies]
jni = { version = "0.10.2", default-features = false }
[profile.release]
lto = true
[lib]
name = "rust_backend"
crate-type = ["cdylib"]
This results in an error when building:
error[E0432]: unresolved import `rust_backend`
--> src/main.rs:1:5
|
1 | use rust_backend::CALLING;
| ^^^^^^^^^^^^ use of undeclared type or module `rust_backend`
error[E0432]: unresolved import `rust_backend`
--> src/main.rs:2:5
|
2 | use rust_backend::foo;
| ^^^^^^^^^^^^ use of undeclared type or module `rust_backend`
I'm probably missing something super-simple here, but neither the documentation nor other code examples where able to help me out with this basic problem.