From 195350863a31dbdf2eb8f920d07db94597bcf617 Mon Sep 17 00:00:00 2001 From: edef Date: Thu, 16 Apr 2015 03:21:40 -0400 Subject: [PATCH] make Valgrind optional --- Cargo.toml | 3 ++- build.rs | 5 ++++- src/debug/valgrind/mod.rs | 14 ++++++++++++++ src/debug/{valgrind.c => valgrind/native.c} | 0 src/debug/{valgrind.rs => valgrind/native.rs} | 0 5 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/debug/valgrind/mod.rs rename src/debug/{valgrind.c => valgrind/native.c} (100%) rename src/debug/{valgrind.rs => valgrind/native.rs} (100%) diff --git a/Cargo.toml b/Cargo.toml index f4683f5..6f0c389 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,5 +8,6 @@ build = "build.rs" gcc = "0.3.3" [features] -default = ["os"] +default = ["os", "valgrind"] os = [] +valgrind = [] diff --git a/build.rs b/build.rs index 7fb9751..03f6187 100644 --- a/build.rs +++ b/build.rs @@ -1,5 +1,8 @@ extern crate gcc; +use std::env::var_os; fn main() { - gcc::compile_library("libvalgrind.a", &["src/debug/valgrind.c"]); + if var_os("CARGO_FEATURE_VALGRIND").is_some() { + gcc::compile_library("libvalgrind.a", &["src/debug/valgrind/native.c"]); + } } diff --git a/src/debug/valgrind/mod.rs b/src/debug/valgrind/mod.rs new file mode 100644 index 0000000..4e0ebe3 --- /dev/null +++ b/src/debug/valgrind/mod.rs @@ -0,0 +1,14 @@ +pub use self::imp::*; + +#[cfg(feature = "valgrind")] +#[path = "native.rs"] +mod imp; + +#[cfg(not(feature = "valgrind"))] +mod imp { + //! Stub for the Valgrind functions + #![allow(non_camel_case_types)] + pub type stack_id_t = (); + pub unsafe fn stack_register(_start: *const u8, _end: *const u8) -> stack_id_t {} + pub unsafe fn stack_deregister(_id: stack_id_t) {} +} diff --git a/src/debug/valgrind.c b/src/debug/valgrind/native.c similarity index 100% rename from src/debug/valgrind.c rename to src/debug/valgrind/native.c diff --git a/src/debug/valgrind.rs b/src/debug/valgrind/native.rs similarity index 100% rename from src/debug/valgrind.rs rename to src/debug/valgrind/native.rs