I'm struggling with the imports for the integration test.
I have the following structure:
file/
│
├── src/
│ ├── bindings.rs
│ └── lib.rs
│
├── tests/
│ └── calc_test.rs
│
└── Cargo.toml
My lib.rs looks like this
mod bindings;
pub use bindings::Guest;
pub struct Calculator;
impl Guest for Calculator {
fn add(a: f64, b: f64) -> f64 {
a + b
}
}
bindings::export!(Calculator with_types_in bindings);
In my integration test calc_test.rs
I try declare the import with use calc::Calculator
and get rustc: unresolved import calc
use of undeclared crate or module calc
. Using just use calc;
doesn't return any error. How should I declare the import?
use calc::Calculator;
#[test]
fn test_calc() {
assert_eq!(2.0, Calculator::add(2, 2));
}
Other files in the project.
.wit file
package test:ext;
world calculator {
export add: func(a: float64, b: float64) -> float64;
}
Cargo.toml
[package]
name = "calc"
version = "0.1.0"
edition = "2021"
[dependencies]
wit-bindgen = { version = "0.24.0", default-features = false, features = [
"realloc",
] }
wit-bindgen-rt = "0.24.0"
wit-cli = "0.0.0"
[lib]
crate-type = ["cdylib"]
[package.metadata.component]
package = "test:ext"
[package.metadata.component.dependencies]
Have you tried changing the crate-type = ["cdylib"]
line in your Cargo.toml to crate-type = ["cdylib", "rlib"]
?
Last updated: Dec 23 2024 at 12:05 UTC