File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -212,6 +212,27 @@ impl AutoCfg {
212
212
Ok ( status. success ( ) )
213
213
}
214
214
215
+ /// Tests whether the given sysroot crate can be used.
216
+ ///
217
+ /// The test code is subject to change, but currently looks like:
218
+ ///
219
+ /// ```ignore
220
+ /// extern crate CRATE as dummy; // `as _` wasn't stabilized until Rust 1.33
221
+ /// ```
222
+ pub fn probe_sysroot_crate ( & self , name : & str ) -> bool {
223
+ self . probe ( format ! ( "extern crate {} as dummy;" , name) ) . unwrap_or ( false )
224
+ }
225
+
226
+ /// Emits a config value `has_PATH` if `probe_sysroot_crate` returns true.
227
+ ///
228
+ /// Any non-identifier characters in the `path` will be replaced with
229
+ /// `_` in the generated config value.
230
+ pub fn emit_sysroot_crate ( & self , name : & str ) {
231
+ if self . probe_sysroot_crate ( name) {
232
+ emit ( & format ! ( "has_{}" , mangle( name) ) ) ;
233
+ }
234
+ }
235
+
215
236
/// Tests whether the given path can be used.
216
237
///
217
238
/// The test code is subject to change, but currently looks like:
Original file line number Diff line number Diff line change @@ -56,6 +56,25 @@ fn probe_sum() {
56
56
assert ! ( missing ^ ac. probe_type( "std::iter::Sum<i32>" ) ) ;
57
57
}
58
58
59
+ #[ test]
60
+ fn probe_std ( ) {
61
+ let ac = AutoCfg :: with_dir ( "target" ) . unwrap ( ) ;
62
+ assert_eq ! ( ac. probe_sysroot_crate( "std" ) , !ac. no_std) ;
63
+ }
64
+
65
+ #[ test]
66
+ fn probe_alloc ( ) {
67
+ let ac = AutoCfg :: with_dir ( "target" ) . unwrap ( ) ;
68
+ let missing = !ac. probe_rustc_version ( 1 , 36 ) ;
69
+ assert ! ( missing ^ ac. probe_sysroot_crate( "alloc" ) ) ;
70
+ }
71
+
72
+ #[ test]
73
+ fn probe_bad_sysroot_crate ( ) {
74
+ let ac = AutoCfg :: with_dir ( "target" ) . unwrap ( ) ;
75
+ assert ! ( !ac. probe_sysroot_crate( "doesnt_exist" ) ) ;
76
+ }
77
+
59
78
#[ test]
60
79
fn probe_no_std ( ) {
61
80
let ac = AutoCfg :: with_dir ( "target" ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments