-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature request] Provide a way to bypass pkg-config's logic by providing minimal info via env #40
Comments
Hm I'm not sure I quite follow unfortunately? Is the idea that you want something like include paths from pkg-config but lib paths from a custom location? |
In first place I want to write
So fn main() {
let lib = pkg_config::Config::new()
.probe("smbclient")
.expect("libsmbclient not found");
// bindgen staff
let header = find_header(&lib).unwrap().to_str().unwrap().to_string();
let bindings = bindgen::Builer::default().header(header)
// bindgen config
.generate()
.expect("failed to generate bindings");
// write bindings to file
} instead of fn main() {
let inc_path_name = "SMBCLIENT_INCLUDE_PATH";
let lib_path_name = "SMBCLIENT_LIBRARY_PATH";
let header = match (env::var(inc_path_name), env::var(lib_path_name)) {
(Ok(inc_path), Ok(lib_path)) => {
println!("cargo:rustc-link-lib=smbclient");
println!("cargo:rustc-link-search=native={}", lib_path);
let mut path = PathBuf::from(inc_path);
path.push("libsmbclient.h");
path.to_str().unwrap().to_string()
}
(Ok(_), Err(_)) | (Err(_), Ok(_)) =>
panic!("Either both {} and {} should be set or none of them", inc_path_name, lib_path_name),
(Err(_), Err(_)) => {
let lib = pkg_config::Config::new()
.probe("smbclient")
.expect("libsmbclient not found");
find_header(&lib).unwrap().to_str().unwrap().to_string()
}
};
// bindgen staff
let bindings = bindgen::Builer::default().header(header)
// bindgen config
.generate()
.expect("failed to generate bindings");
// write bindings to file
} |
Ah ok I see, but I think that's beyond the scope of the pkg-config crate? That sounds like an external helper crate, though, which may internally use pkg-config. |
I thought it but it seems to me as duplication. It will still have something like Of course, if it seems out of scope for |
Sure yeah there may be some duplication, but not too much in theory, right? The wrapper like you're indicating may also not want to have all the fields that pkg-config returns. |
Primary idea behind this feature request is that currenty
build.rs
script has to duplicate some logic and data structure ifFOO_NO_PKG_CONFIG
is passed or nopkg-config
is available on target system.E.g. if I have
FOO_LIB_PATH
andFOO_INC_PATH
for override in mybuild.rs
I will have a struct which storesinclude_paths: Vec<PathBuf>
andlink_paths: Vec<PathBuf>
(at least) which is populated from something likeand have to emit
cargo:rustc-link-lib=...
andcargo:rustc-link-search=native=...
afterwards likepkg-config
crate does.If such feature is implemeted
build.rs
would be much simplier for such simple cases.Would you accept PR for this or my idea has some fatal flaws which could prevent this?
The text was updated successfully, but these errors were encountered: