From 28fec5d869bee96250d833c9ef692e48c423c15b Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Wed, 18 Sep 2024 08:47:37 +1000 Subject: [PATCH] Put backtrace behind a feature --- soroban-env-host/Cargo.toml | 1 + soroban-env-host/src/host/error.rs | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/soroban-env-host/Cargo.toml b/soroban-env-host/Cargo.toml index 66c3a6167..ba220cef3 100644 --- a/soroban-env-host/Cargo.toml +++ b/soroban-env-host/Cargo.toml @@ -106,6 +106,7 @@ features = ["arbitrary"] [features] testutils = ["soroban-env-common/testutils", "recording_mode", "dep:backtrace"] +backtrace = ["dep:backtrace"] next = ["soroban-env-common/next", "stellar-xdr/next"] tracy = ["dep:tracy-client", "soroban-env-common/tracy"] recording_mode = [] diff --git a/soroban-env-host/src/host/error.rs b/soroban-env-host/src/host/error.rs index d2bfcfca4..069cd8e48 100644 --- a/soroban-env-host/src/host/error.rs +++ b/soroban-env-host/src/host/error.rs @@ -5,7 +5,7 @@ use crate::{ ConversionError, EnvBase, Error, Host, TryFromVal, U32Val, Val, }; -#[cfg(any(test, feature = "testutils"))] +#[cfg(any(test, all(feature = "testutils", feature = "backtrace")))] use backtrace::{Backtrace, BacktraceFrame}; use core::fmt::Debug; use std::{ @@ -18,7 +18,7 @@ use super::metered_clone::MeteredClone; #[derive(Clone)] pub(crate) struct DebugInfo { events: Events, - #[cfg(any(test, feature = "testutils"))] + #[cfg(any(test, all(feature = "testutils", feature = "backtrace")))] backtrace: Backtrace, } @@ -67,12 +67,12 @@ impl DebugInfo { Ok(()) } - #[cfg(not(any(test, feature = "testutils")))] + #[cfg(not(any(test, all(feature = "testutils", feature = "backtrace"))))] fn write_backtrace(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { Ok(()) } - #[cfg(any(test, feature = "testutils"))] + #[cfg(any(test, all(feature = "testutils", feature = "backtrace")))] fn write_backtrace(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { // We do a little trimming here, skipping the first two frames (which // are always into, from, and one or more Host::err_foo calls) and all @@ -296,8 +296,11 @@ impl Host { self.with_debug_mode(|| { if let Ok(events_ref) = self.0.events.try_borrow() { let events = events_ref.externalize(self)?; - let backtrace = Backtrace::new_unresolved(); - res = Some(Box::new(DebugInfo { backtrace, events })); + res = Some(Box::new(DebugInfo { + #[cfg(any(test, all(feature = "testutils", feature = "backtrace")))] + backtrace: Backtrace::new_unresolved(), + events, + })); } Ok(()) });