summaryrefslogtreecommitdiff
path: root/build.rs
diff options
context:
space:
mode:
authorIsaac Woods <isaacwoods.home@gmail.com>2018-09-17 19:33:52 +0100
committerIsaac Woods <isaacwoods.home@gmail.com>2018-09-18 19:50:36 +0100
commit79c80c4ec44a470e3b9cb194da19a23a2ddb2f0a (patch)
treee78b3d081d52562641f106f0ee1d9d37d7a1340a /build.rs
parent1844a772b60771d0124a157019f627d60fea4e73 (diff)
downloadrust-libc-79c80c4ec44a470e3b9cb194da19a23a2ddb2f0a.tar.gz
Re-export core::ffi::c_void if supported
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/build.rs b/build.rs
new file mode 100644
index 0000000000..aa56ea0545
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,35 @@
+use std::env;
+use std::process::Command;
+use std::str;
+
+fn main() {
+ /*
+ * If `core::ffi::c_void` exists, libc can just re-export it. Otherwise, it
+ * must define an incompatible type to retain backwards-compatibility.
+ */
+ if rustc_minor_version().expect("Failed to get rustc version") >= 31 {
+ println!("cargo:rustc-cfg=core_cvoid");
+ }
+}
+
+fn rustc_minor_version() -> Option<u32> {
+ macro_rules! otry {
+ ($e:expr) => {
+ match $e {
+ Some(e) => e,
+ None => return None,
+ }
+ };
+ }
+
+ let rustc = otry!(env::var_os("RUSTC"));
+ let output = otry!(Command::new(rustc).arg("--version").output().ok());
+ let version = otry!(str::from_utf8(&output.stdout).ok());
+ let mut pieces = version.split('.');
+
+ if pieces.next() != Some("rustc 1") {
+ return None;
+ }
+
+ otry!(pieces.next()).parse().ok()
+}