Reputation: 782
I am trying to build a test app using cassandra-rs which uses the DataStax CPP driver. I am using cargo 0.6.0 (ec9398e 2015-09-29) (built from git)
.
My DataStax driver is not located in the standard directories Cargo looks in.
I added a build script specifying the path to the DataStax driver:
fn main() {
println!("cargo:rustc-link-search={}", "/path/to/dir/");
}
Here is my Cargo.toml:
[package]
name = "castest"
version = "0.1.0"
build = "build.rs"
[dependencies]
cassandra="*"
But cargo build --verbose
shows that the additional search directory is not included when building.
The package that the build is actually failing on is cql_bindgen which is a dependency of cassandra-rs. In that project there is this build.rs:
fn main() {
println!("cargo:rustc-flags=-l dylib=crypto");
println!("cargo:rustc-flags=-l dylib=ssl");
println!("cargo:rustc-flags=-l dylib=stdc++");
println!("cargo:rustc-flags=-l dylib=uv");
println!("cargo:rustc-link-search={}", "/usr/lib/");
println!("cargo:rustc-link-search={}", "/usr/local/lib64");
println!("cargo:rustc-link-lib=static=cassandra_static");
}
How can I add additional libraries or otherwise override configuration in my project that is set in dependent projects?
Upvotes: 4
Views: 3763
Reputation: 431789
A downstream user of a crate cannot make changes to how that crate is compiled, other than by features that the crate exposes.
When linking to existing native libraries, the Cargo build script is used to help find the appropriate libraries to link to.
The correct solution here is to fix the upstream crate (cql_bindgen) build.rs to allow end users to specify alternate paths to search within. One way of doing this is to use the option_env!
macro, something like:
if let Some(datastax_dir) = option_env!("CQL_BINDGEN_DATASTAX_LIB_PATH") {
println!("cargo:rustc-link-search={}", datastax_dir);
}
Of course, you can override the dependency with a local version as you iterate to get a solution that works locally.
In the mean time, you can try installing your library in one of the hard-coded directories that are already searched.
Upvotes: 2