Add a flag to enable or disable dbg for release builds.
Jackojc opened this issue · comments
Not sure if there's currently a way to set a flag to enable or disable dbg depending on whether or not it's a debug build. If there is a flag, it should probably be documented, if not, maybe some kind of #define to effectively make the dbg macro do nothing.
Not sure if there's currently a way to set a flag to enable or disable dbg depending on whether or not it's a debug build
There is no flag or mechanism to do this.
I'm trying to follow a similar philosophy as the Rust team did with their dbg!(…)
macro.
Quoting from https://doc.rust-lang.org/std/macro.dbg.html
The dbg! macro works exactly the same in release builds. This is useful when debugging issues that only occur in release builds or when debugging in release mode is significantly faster.
Note that the macro is intended as a debugging tool and therefore you should avoid having uses of it in version control for longer periods.
This is why the dbg(…)
macro does not disable itself in non-DEBUG
builds.
That being said, I think I would be okay with adding a compile flag to disable the macro completely.
I have hadded a DBG_MACRO_DISABLE
compile time flag that can be used to disable the macro.
If disabled, the macro can still be used in expressions since we define it to be dbg(x) = x
.
That's okay. Anyway, you should add something to the the macro when it is disabled, because a lot of "-Wunused-value" warnings appear in g++ and clang++, but that's different issue
@fgallegosalido I have prepared CI for AppleClang, GCC and MSVC. We will see about those warnings.
Anyway, you should add something to the the macro when it is disabled, because a lot of "-Wunused-value" warnings appear in g++ and clang++
Good point. Would you like to open a new issue for that?
Okay, I'm opening it now
i tried to run a mini project that has dbg!(), but it doesnt work
command is:
DBG_MACRO_DISABLE=1 cargo run -q -p ldebug
# also tried this
DBG_MACRO_DISABLE=true cargo run -q -p ldebug
program is:
fn main() {
let x = 123;
dbg!(x);
}
output
❱ DBG_MACRO_DISABLE=1 cargo run -q -p ldebug
[crates/ldebug/src/main.rs:25] x = 123
How am I supposed to run cargo run with this flag DBG_MACRO_DISABLE
?
I think you're mixing this project up with the Rust macro of the same name (I believe this project was inspired by it). https://doc.rust-lang.org/std/macro.dbg.html
woooow. ups. sorry. didnt know i was commenting on cpp repo.
i had this problem in rust and google sugested this repo and i clicked fast without looking.