Skip to content

Commit 367e5dd

Browse files
committed
Rather disgusting hack to build without log dependencies
- 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 ;-)
1 parent 624c32c commit 367e5dd

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

Cargo.toml

+10-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@ cfg-if = "0.1.0"
2626
clang-sys = "0.8.0"
2727
lazy_static = "0.1.*"
2828
libc = "0.2"
29-
log = "0.3"
30-
env_logger = "0.3"
3129
rustc-serialize = "0.3.19"
3230
syntex_syntax = "0.44"
3331
regex = "0.1"
3432

33+
[dependencies.log]
34+
version = "0.3"
35+
optional = true
36+
37+
[dependencies.env_logger]
38+
version = "0.3"
39+
optional = true
40+
3541
[dependencies.aster]
3642
features = ["with-syntex"]
3743
version = "0.28"
@@ -45,6 +51,8 @@ features = ["with-syntex"]
4551
version = "0.20"
4652

4753
[features]
54+
default = ["logging"]
55+
logging = ["log", "env_logger"]
4856
llvm_stable = []
4957
static = []
5058
# This feature only exists for CI -- don't use it!

src/lib.rs

+38-2
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,46 @@ extern crate clang_sys;
3131
extern crate libc;
3232
extern crate regex;
3333
#[macro_use]
34-
extern crate log;
35-
#[macro_use]
3634
extern crate lazy_static;
3735

36+
cfg_if! {
37+
if #[cfg(feature = "logging")] {
38+
#[macro_use]
39+
extern crate log;
40+
} else {
41+
macro_rules! log {
42+
(target: $target:expr, $($arg:tt)+) => (
43+
let _ = format_args!($($arg)+);
44+
);
45+
($($arg:tt)+) => (log!(target: module_path!(), $($arg)+))
46+
}
47+
macro_rules! debug {
48+
(target: $target:expr, $($arg:tt)*) => (
49+
log!(target: $target, $($arg)*);
50+
);
51+
($($arg:tt)*) => (
52+
log!($($arg)*);
53+
)
54+
}
55+
macro_rules! warn {
56+
(target: $target:expr, $($arg:tt)*) => (
57+
log!(target: $target, $($arg)*);
58+
);
59+
($($arg:tt)*) => (
60+
log!($($arg)*);
61+
)
62+
}
63+
macro_rules! error {
64+
(target: $target:expr, $($arg:tt)*) => (
65+
log!(target: $target, $($arg)*);
66+
);
67+
($($arg:tt)*) => (
68+
log!($($arg)*);
69+
)
70+
}
71+
}
72+
}
73+
3874
// A macro to declare an internal module for which we *must* provide
3975
// documentation for. If we are building with the "_docs" feature, then the
4076
// module is declared public, and our `#![deny(missing_docs)]` pragma applies to

0 commit comments

Comments
 (0)