From aa57f2ac9431202690a9b79300410bb64ddd1e85 Mon Sep 17 00:00:00 2001 From: Boni Garcia Date: Wed, 4 Oct 2023 14:08:46 +0200 Subject: [PATCH] [rust] Include debug info in release artifact and enable backtrace by default --- rust/Cargo.Bazel.lock | 2 +- rust/Cargo.toml | 2 +- rust/src/main.rs | 23 ++++++++--------------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/rust/Cargo.Bazel.lock b/rust/Cargo.Bazel.lock index 35fe4dff4e6a7..9863913546078 100644 --- a/rust/Cargo.Bazel.lock +++ b/rust/Cargo.Bazel.lock @@ -1,5 +1,5 @@ { - "checksum": "4745128072794bf6ed7da8d621ea818d5d0e11d98386c45fd55852bd6ca41af8", + "checksum": "ac879e4513ac137fb555c16e74c747e59a78e2847d2a1121f432e73c4c37ad81", "crates": { "addr2line 0.19.0": { "name": "addr2line", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 5814bdf97763d..eec5cb88051ea 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -43,4 +43,4 @@ opt-level = 'z' # Optimize for size lto = true # Enable Link Time Optimization codegen-units = 1 # Reduce number of codegen units to increase optimizations panic = 'abort' # Abort on panic -strip = true # Strip symbols from binary* +debug = true # Full debug info \ No newline at end of file diff --git a/rust/src/main.rs b/rust/src/main.rs index 15a7b6e970247..43e68a6b2c140 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -use std::backtrace::{Backtrace, BacktraceStatus}; +use std::env; use std::path::Path; use std::process::exit; @@ -129,6 +129,8 @@ struct Cli { } fn main() { + env::set_var("RUST_BACKTRACE", "1"); // Enable capture backtrace by default + let mut cli = Cli::parse(); let cache_path = StringKey(vec![CACHE_PATH_KEY], &cli.cache_path.unwrap_or_default()).get_value(); @@ -203,11 +205,7 @@ fn main() { .and_then(|_| selenium_manager.setup()) .map(|driver_path| { let log = selenium_manager.get_logger(); - log_driver_and_browser_path( - log, - &driver_path, - selenium_manager.get_browser_path(), - ); + log_driver_and_browser_path(log, &driver_path, selenium_manager.get_browser_path()); flush_and_exit(OK, log, None); }) .unwrap_or_else(|err| { @@ -236,11 +234,7 @@ fn main() { }); } -fn log_driver_and_browser_path( - log: &Logger, - driver_path: &Path, - browser_path: &str, -) { +fn log_driver_and_browser_path(log: &Logger, driver_path: &Path, browser_path: &str) { if driver_path.exists() { log.info(format!("{}{}", DRIVER_PATH, driver_path.display())); } else { @@ -254,10 +248,9 @@ fn log_driver_and_browser_path( fn flush_and_exit(code: i32, log: &Logger, err: Option) -> ! { if let Some(error) = err { - let backtrace = Backtrace::capture(); - let backtrace_status = backtrace.status(); - if backtrace_status == BacktraceStatus::Captured { - log.debug(format!("Backtrace:\n{}", error.backtrace())); + let backtrace = error.backtrace(); + if !backtrace.to_string().ends_with("backtrace") { + log.debug(format!("Backtrace:\n{}", backtrace)); } } log.set_code(code);