Tests library Issue

I have src/lib.rs, src/smth.rs and want to run tests in smth.rs(not in lib as cargo test). Also I want to create dynamic library, so I want to know how on Linux/Windows do it:

I need some commands to create .a and .so.. mylonestar

How then link this library to another crate and so on, thanks in advance!(I didn't work with dynamic library, curious how to).

For Cargo there's no smaller unit than a crate, which means lib.rs and all files (modules) that it uses. Generating .so/.a files always starts at lib.rs and includes all of it.

Tests can be filtered by name cargo test name_of_a_test. This still compiles all tests starting from lib.rs, but runs only the tests matching the name.

If you want to create a library from a subset of code smaller than what you have in lib.rs and all modules it has, then you need to split your project into two or more libraries, each having its own lib.rs.

In Cargo this is done with multiple crates that belong to the same workspace.

https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html

1 Like

Thanks for the information that you provide.

1 Like