I’d like to build a binary executable linked with my own native library. I have:
[package] … build = "src/build.rs" [lib] name = "foo" [[bin]] name = "foo" path = "src/bin.rs"
libfoo.a and prints
cargo:rustc-link-lib=static=foo, etc. Everything builds and links fine for the library part (
cargo build --lib), but the build script doesn’t seem to be invoked for
cargo build --bin (linking fails with missing symbols and linker command doesn’t include directives from build.rs).
Is that expected? Can a built script be used for both lib and bin targets?
I’m developing a utility that could be used via a Rust API or via CLI, so I thought it’d be nice to have it as one project/crate. I know I could work around it by moving lib to a separate crate, but can I tell cargo to link the native library (or even the Rust library containing the native part), with the binary executable it produces?