Skip to content

Commit

Permalink
feat: move debug logging behind an environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Feb 25, 2024
1 parent 35d96f0 commit 66b9fa1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/command_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ use crate::{Error, ErrorKind, Object};
pub(crate) struct CargoOutput {
pub(crate) metadata: bool,
pub(crate) warnings: bool,
pub(crate) debug: bool,
}

impl CargoOutput {
pub(crate) const fn new() -> Self {
pub(crate) fn new() -> Self {
println!("cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT");
Self {
metadata: true,
warnings: true,
debug: std::env::var("CC_ENABLE_DEBUG_OUTPUT").is_ok(),
}
}

Expand All @@ -40,6 +43,10 @@ impl CargoOutput {
}
}

pub(crate) fn print_debug(&self, arg: &dyn Display) {
println!("{}", arg);
}

fn stdio_for_warnings(&self) -> Stdio {
if self.warnings {
Stdio::piped()
Expand Down Expand Up @@ -217,7 +224,7 @@ fn wait_on_child(
}
};

cargo_output.print_warning(&status);
cargo_output.print_debug(&status);

if status.success() {
Ok(())
Expand Down Expand Up @@ -326,7 +333,7 @@ pub(crate) fn spawn(
}
}

cargo_output.print_warning(&format_args!("running: {:?}", cmd));
cargo_output.print_debug(&format_args!("running: {:?}", cmd));

let cmd = ResetStderr(cmd);
let child = cmd.0.stderr(cargo_output.stdio_for_warnings()).spawn();
Expand Down
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,16 @@ impl Build {
self
}

/// Define whether compile debug information should be emitted for cargo. Defaults to
/// `false`.
///
/// If enabled, the compiler will emit debug information when generating object files,
/// such as the command invoked and the exit status.
pub fn cargo_debug(&mut self, cargo_debug: bool) -> &mut Build {
self.cargo_output.debug = cargo_debug;
self
}

/// Adds a native library modifier that will be added to the
/// `rustc-link-lib=static:MODIFIERS=LIBRARY_NAME` metadata line
/// emitted for cargo if `cargo_metadata` is enabled.
Expand Down

0 comments on commit 66b9fa1

Please sign in to comment.