-
Notifications
You must be signed in to change notification settings - Fork 23
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
Test if a dependency contains a path or symbol #60
Comments
I think it would be a useful extension here, but I don't know a good way to accomplish it. The crude way would be to add The clean way to add dependency crates would be with |
Tried to mess a bit with autocfg but got blocked by the extern crate autocfg;
use std::process::Command;
use std::process::Output;
fn main() {
// TODO how to get around rustc_private with autocfg
// FIXME temporary solution: rust-script compiles for and runs in the local system? I want to test-compile for the target system or similar
// does rust-script work? (warning: outputs to stdout/stderr)
let status = Command::new("rust-script").arg("--version").status().expect("rust-script is required, running 'cargo install rust-script' in the console should fix this error\n");
if !status.success() {
panic!("rust-script: {}", status);
}
// sanity check: libc::size_t should always exist
assert!(Command::new("rust-script").args(["--dep", "libc", "--expr", "{ let _: libc::size_t = 0; }"]).output().unwrap().status.success());
fn probe_dep_path(dep: &str, path: &str) -> Output {
let expr = format!("{{ use {}; }}", path);
Command::new("rust-script").args(["--dep", dep, "--expr", &expr]).output().unwrap()
}
fn emit_dep_path_cfg(dep: &str, path: &str, cfg: &str) {
if probe_dep_path(dep, path).status.success() {
autocfg::emit(cfg);
}
}
emit_dep_path_cfg("libc", "libc::B76800", "has_libc_B76800");
// ...
} |
Sorry if this is the wrong crate. This crate is the closest that I could find to the functionality that I need.
I'm porting code from C to rust that has
#if defined(...)
code.The crate
libc
has the symbols I need but I can't find a way to automatically test if they actually exist (within cargo/rust) and do conditional compilation with that. Using '#[cfg(target_os = "...")]' combinations would be very error prone and a huge maintenance burden that I'm not gonna introduce.What I need is something like this for
build.rs
:Is it possible to use or adapt this crate for this use case?
If not, can you point me to any other crate that I can look into?
The text was updated successfully, but these errors were encountered: