Skip to content

Commit

Permalink
Add probe_sysroot_crate and emit_sysroot_crate
Browse files Browse the repository at this point in the history
Review

Review (pt. 2)
  • Loading branch information
leo60228 committed Aug 17, 2019
1 parent 81ea9f3 commit 6561d2f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,25 @@ impl AutoCfg {
Ok(status.success())
}

/// Tests whether the given sysroot crate can be used.
///
/// The test code is subject to change, but currently looks like:
///
/// ```ignore
/// extern crate CRATE as probe;
/// ```
pub fn probe_sysroot_crate(&self, name: &str) -> bool {
self.probe(format!("extern crate {} as probe;", name)) // `as _` wasn't stabilized until Rust 1.33
.unwrap_or(false)
}

/// Emits a config value `has_CRATE` if `probe_sysroot_crate` returns true.
pub fn emit_sysroot_crate(&self, name: &str) {
if self.probe_sysroot_crate(name) {
emit(&format!("has_{}", mangle(name)));
}
}

/// Tests whether the given path can be used.
///
/// The test code is subject to change, but currently looks like:
Expand Down
19 changes: 19 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ fn probe_sum() {
assert!(missing ^ ac.probe_type("std::iter::Sum<i32>"));
}

#[test]
fn probe_std() {
let ac = AutoCfg::with_dir("target").unwrap();
assert_eq!(ac.probe_sysroot_crate("std"), !ac.no_std);
}

#[test]
fn probe_alloc() {
let ac = AutoCfg::with_dir("target").unwrap();
let missing = !ac.probe_rustc_version(1, 36);
assert!(missing ^ ac.probe_sysroot_crate("alloc"));
}

#[test]
fn probe_bad_sysroot_crate() {
let ac = AutoCfg::with_dir("target").unwrap();
assert!(!ac.probe_sysroot_crate("doesnt_exist"));
}

#[test]
fn probe_no_std() {
let ac = AutoCfg::with_dir("target").unwrap();
Expand Down

0 comments on commit 6561d2f

Please sign in to comment.