File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -212,6 +212,28 @@ 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) )
224
+ . unwrap_or ( false )
225
+ }
226
+
227
+ /// Emits a config value `has_PATH` if `probe_sysroot_crate` returns true.
228
+ ///
229
+ /// Any non-identifier characters in the `path` will be replaced with
230
+ /// `_` in the generated config value.
231
+ pub fn emit_sysroot_crate ( & self , name : & str ) {
232
+ if self . probe_sysroot_crate ( name) {
233
+ emit ( & format ! ( "has_{}" , mangle( name) ) ) ;
234
+ }
235
+ }
236
+
215
237
/// Tests whether the given path can be used.
216
238
///
217
239
/// 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