Skip to content

Commit

Permalink
Rather disgusting hack to build without log dependencies
Browse files Browse the repository at this point in the history
- Unfortunately there's a dependency on log via syntex_errors, so we
don't get rid of it all
- I can't find a more sensible way to set dependencies based on whether
you're building the lib or bin
- So `--no-default-features` means you need to know what you're doing,
as only the lib will build without the logging crates for now
- The replacement log macros are pretty gross too, but they show a proof
of concept ;-)
  • Loading branch information
jdub committed Nov 4, 2016
1 parent f498903 commit 82bb363
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
12 changes: 10 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ cfg-if = "0.1.0"
clang-sys = "0.8.0"
lazy_static = "0.1.*"
libc = "0.2"
log = "0.3"
env_logger = "0.3"
rustc-serialize = "0.3.19"
syntex_syntax = "0.44"
regex = "0.1"

[dependencies.log]
version = "0.3"
optional = true

[dependencies.env_logger]
version = "0.3"
optional = true

[dependencies.aster]
features = ["with-syntex"]
version = "0.28"
Expand All @@ -45,6 +51,8 @@ features = ["with-syntex"]
version = "0.20"

[features]
default = ["logging"]
logging = ["log", "env_logger"]
llvm_stable = []
static = []
# This feature only exists for CI -- don't use it!
Expand Down
40 changes: 38 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,46 @@ extern crate clang_sys;
extern crate libc;
extern crate regex;
#[macro_use]
extern crate log;
#[macro_use]
extern crate lazy_static;

cfg_if! {
if #[cfg(feature = "logging")] {
#[macro_use]
extern crate log;
} else {
macro_rules! log {
(target: $target:expr, $($arg:tt)+) => (
let _ = format_args!($($arg)+);
);
($($arg:tt)+) => (log!(target: module_path!(), $($arg)+))
}
macro_rules! debug {
(target: $target:expr, $($arg:tt)*) => (
log!(target: $target, $($arg)*);
);
($($arg:tt)*) => (
log!($($arg)*);
)
}
macro_rules! warn {
(target: $target:expr, $($arg:tt)*) => (
log!(target: $target, $($arg)*);
);
($($arg:tt)*) => (
log!($($arg)*);
)
}
macro_rules! error {
(target: $target:expr, $($arg:tt)*) => (
log!(target: $target, $($arg)*);
);
($($arg:tt)*) => (
log!($($arg)*);
)
}
}
}

// A macro to declare an internal module for which we *must* provide
// documentation for. If we are building with the "_docs" feature, then the
// module is declared public, and our `#![deny(missing_docs)]` pragma applies to
Expand Down

0 comments on commit 82bb363

Please sign in to comment.