-
-
Save alexcrichton/108f3c3bb70d8e5d250a63f0ca986d58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/rust/tor_allocate/build.rs b/src/rust/tor_allocate/build.rs | |
new file mode 100644 | |
index 000000000..c97fd55ce | |
--- /dev/null | |
+++ b/src/rust/tor_allocate/build.rs | |
@@ -0,0 +1,34 @@ | |
+use std::env; | |
+use std::process::Command; | |
+use std::str; | |
+ | |
+fn main() { | |
+ if let Some(version) = rustc_minor_version() { | |
+ if version >= 28 { | |
+ println!("cargo:rustc-cfg=global_allocator"); | |
+ } | |
+ } | |
+} | |
+ | |
+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() | |
+} | |
+ | |
diff --git a/src/rust/tor_allocate/lib.rs b/src/rust/tor_allocate/lib.rs | |
index 1cfa0b517..0f3f00dd3 100644 | |
--- a/src/rust/tor_allocate/lib.rs | |
+++ b/src/rust/tor_allocate/lib.rs | |
@@ -11,10 +11,12 @@ | |
extern crate libc; | |
+#[cfg(global_allocator)] | |
use std::alloc::System; | |
mod tor_allocate; | |
pub use tor_allocate::*; | |
#[global_allocator] | |
+#[cfg(global_allocator)] | |
static A: System = System; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment