File tree 4 files changed +68
-21
lines changed
4 files changed +68
-21
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ description = """
12
12
A library for types and bindings to native C functions often found in libc or
13
13
other common platform libraries.
14
14
"""
15
+ build = " build.rs"
15
16
16
17
[badges ]
17
18
travis-ci = { repository = " rust-lang/libc" }
Original file line number Diff line number Diff line change
1
+ use std:: env;
2
+ use std:: process:: Command ;
3
+ use std:: str;
4
+
5
+ fn main ( ) {
6
+ /*
7
+ * If `core::ffi::c_void` exists, libc can just re-export it. Otherwise, it must define an
8
+ * incompatible type to retain backwards-compatibility.
9
+ */
10
+ if rustc_minor_version ( ) . expect ( "Failed to get rustc version" ) >= 31 {
11
+ println ! ( "cargo:rustc-cfg=core_cvoid" ) ;
12
+ }
13
+ }
14
+
15
+ fn rustc_minor_version ( ) -> Option < u32 > {
16
+ macro_rules! otry {
17
+ ( $e: expr) => {
18
+ match $e {
19
+ Some ( e) => e,
20
+ None => return None ,
21
+ }
22
+ } ;
23
+ }
24
+
25
+ let rustc = otry ! ( env:: var_os( "RUSTC" ) ) ;
26
+ let output = otry ! ( Command :: new( rustc) . arg( "--version" ) . output( ) . ok( ) ) ;
27
+ let version = otry ! ( str :: from_utf8( & output. stdout) . ok( ) ) ;
28
+ let mut pieces = version. split ( '.' ) ;
29
+
30
+ if pieces. next ( ) != Some ( "rustc 1" ) {
31
+ return None ;
32
+ }
33
+
34
+ otry ! ( pieces. next( ) ) . parse ( ) . ok ( )
35
+ }
Original file line number Diff line number Diff line change @@ -108,17 +108,22 @@ cfg_if! {
108
108
// On the Switch, we only define some useful universal types for
109
109
// convenience. Those can be found in the switch.rs file.
110
110
} else {
111
-
112
- // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
113
- // more optimization opportunities around it recognizing things like
114
- // malloc/free.
115
- #[ repr( u8 ) ]
116
- pub enum c_void {
117
- // Two dummy variants so the #[repr] attribute can be used.
118
- #[ doc( hidden) ]
119
- __variant1,
120
- #[ doc( hidden) ]
121
- __variant2,
111
+ cfg_if! {
112
+ if #[ cfg( core_cvoid) ] {
113
+ pub use core:: ffi:: c_void;
114
+ } else {
115
+ // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
116
+ // more optimization opportunities around it recognizing things like
117
+ // malloc/free.
118
+ #[ repr( u8 ) ]
119
+ pub enum c_void {
120
+ // Two dummy variants so the #[repr] attribute can be used.
121
+ #[ doc( hidden) ]
122
+ __variant1,
123
+ #[ doc( hidden) ]
124
+ __variant2,
125
+ }
126
+ }
122
127
}
123
128
124
129
pub type int8_t = i8 ;
Original file line number Diff line number Diff line change 1
1
//! Switch C type definitions
2
2
3
- // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
4
- // more optimization opportunities around it recognizing things like
5
- // malloc/free.
6
- #[ repr( u8 ) ]
7
- pub enum c_void {
8
- // Two dummy variants so the #[repr] attribute can be used.
9
- #[ doc( hidden) ]
10
- __variant1,
11
- #[ doc( hidden) ]
12
- __variant2,
3
+ cfg_if ! {
4
+ if #[ cfg( core_cvoid) ] {
5
+ pub use core:: ffi:: c_void;
6
+ } else {
7
+ // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
8
+ // more optimization opportunities around it recognizing things like
9
+ // malloc/free.
10
+ #[ repr( u8 ) ]
11
+ pub enum c_void {
12
+ // Two dummy variants so the #[repr] attribute can be used.
13
+ #[ doc( hidden) ]
14
+ __variant1,
15
+ #[ doc( hidden) ]
16
+ __variant2,
17
+ }
18
+ }
13
19
}
14
20
15
21
pub type int8_t = i8 ;
You can’t perform that action at this time.
0 commit comments