Skip to content

Commit e0fc704

Browse files
committed
Re-export core::ffi::c_void if supported
1 parent 1844a77 commit e0fc704

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

Cargo.lock

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ description = """
1212
A library for types and bindings to native C functions often found in libc or
1313
other common platform libraries.
1414
"""
15+
build = "build.rs"
1516

1617
[badges]
1718
travis-ci = { repository = "rust-lang/libc" }
@@ -24,3 +25,6 @@ align = []
2425

2526
[workspace]
2627
members = ["libc-test"]
28+
29+
[build-dependencies]
30+
rustc_version = "0.2"

build.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
extern crate rustc_version;
2+
3+
fn main() {
4+
/*
5+
* If `core::ffi::c_void` exists, libc can just re-export it. Otherwise, it must define an
6+
* incompatible type to retain backwards-compatibility.
7+
*/
8+
let core_has_cvoid = {
9+
let version = rustc_version::version().expect("Could not get rustc version");
10+
(version.major > 1) || (version.major == 1 && version.minor >= 31)
11+
};
12+
if core_has_cvoid {
13+
println!("cargo:rustc-cfg=core_cvoid");
14+
}
15+
}

src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ cfg_if! {
108108
// On the Switch, we only define some useful universal types for
109109
// convenience. Those can be found in the switch.rs file.
110110
} else {
111+
#[cfg(core_cvoid)]
112+
pub use core::ffi::c_void;
111113

114+
#[cfg(not(core_cvoid))]
112115
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
113116
// more optimization opportunities around it recognizing things like
114117
// malloc/free.

src/switch.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
//! Switch C type definitions
22
3+
#[cfg(core_cvoid)]
4+
pub use core::ffi::c_void;
5+
6+
#[cfg(not(core_cvoid))]
37
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
48
// more optimization opportunities around it recognizing things like
59
// malloc/free.

0 commit comments

Comments
 (0)