From ed19a2b13c3f1e1c5f362e7f419de3c5f87ee6d2 Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Thu, 19 Dec 2024 09:58:47 -0500 Subject: [PATCH] build: Make backtraces useable in release builds Having `strip = "symbols"` and omitting `-C force-unwind-tables` makes backtraces generated with `RUST_BACKTRACE=1` completely useless in release builds. By adding the `-C force-unwind-tables` flag and setting `strip = "debuginfo"`, we make backtraces usable in release builds. This will help us debug issues we are unable to reproduce, since we can ask users to set `RUST_BACKTRACE=1` and provide the logs with this option. --- .cargo/config.toml | 3 +++ Cargo.toml | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 35c67ad3d2..293cd4611c 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,5 @@ +[build] +rustflags = ["-C", "force-unwind-tables"] # Make backtraces work. + [target.'cfg(all(windows, target_env = "msvc"))'] rustflags = ["-C", "target-feature=+crt-static"] diff --git a/Cargo.toml b/Cargo.toml index 7d5ac40a90..6e0b0595f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -113,7 +113,7 @@ winapi = "0.3.9" [profile.release] opt-level = "z" panic = "abort" -strip = true # Strip symbols from the binary. -codegen-units = 1 # Parallel compilation prevents some optimizations. +strip = "debuginfo" # Only strip debuginfo (not symbols) to keep backtraces useful. +codegen-units = 1 # Parallel compilation prevents some optimizations. # We do not enable link-time optimizations (lto) because they cause the # CLI to timeout when run in Xcode Cloud.