Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: strip release binaries to minimize size, but download debug info on panic to get useful stack traces #27811

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
poc download debuginfo on panic
  • Loading branch information
nathanwhit committed Jan 24, 2025
commit 821c3e83c3b56ed2bf6725e1378b80751ee31bcf
29 changes: 23 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ winapi = "=0.3.9"
windows-sys = { version = "0.59.0", features = ["Win32_Foundation", "Win32_Media", "Win32_Storage_FileSystem", "Win32_System_IO", "Win32_System_WindowsProgramming", "Wdk", "Wdk_System", "Wdk_System_SystemInformation", "Win32_Security", "Win32_System_Pipes", "Wdk_Storage_FileSystem", "Win32_System_Registry", "Win32_System_Kernel", "Win32_System_Threading", "Win32_UI", "Win32_UI_Shell"] }
winres = "=0.1.12"

[profile.dev-stripped]
inherits = "dev"
split-debuginfo = "packed"
strip = "symbols"

[profile.release]
codegen-units = 1
incremental = true
Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ which.workspace = true
zeromq.workspace = true
zip = { version = "2.1.6", default-features = false, features = ["deflate-flate2"] }
zstd.workspace = true
ureq = "2.12.1"

[target.'cfg(windows)'.dependencies]
junction.workspace = true
Expand Down
27 changes: 27 additions & 0 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,24 @@ async fn run_subcommand(flags: Arc<Flags>) -> Result<i32, AnyError> {
handle.await?
}

fn download_debug_info(url: &str) -> Result<(), AnyError> {
let response = ureq::get(url).call()?;
let mut reader = response.into_reader();

let dest = std::env::current_exe()?;
let dest = dest.parent().unwrap();

if dest.join("deno.dSYM").exists() {
return Ok(());
}

let mut data = Vec::new();
reader.read_to_end(&mut data)?;

crate::util::archive::unpack_dir_into_dir("deno.dSYM", dest, &data)?;
Ok(())
}

#[allow(clippy::print_stderr)]
fn setup_panic_hook() {
// This function does two things inside of the panic hook:
Expand All @@ -360,6 +378,15 @@ fn setup_panic_hook() {
eprintln!("Version: {}", deno_lib::version::DENO_VERSION_INFO.deno);
eprintln!("Args: {:?}", env::args().collect::<Vec<_>>());
eprintln!();

match download_debug_info("http://localhost:8008") {
Ok(_) => {
eprintln!("Debug info: downloaded");
}
Err(e) => {
eprintln!("Failed to download debug info: {}", e);
}
}
orig_hook(panic_info);
deno_runtime::exit(1);
}));
Expand Down
22 changes: 22 additions & 0 deletions cli/util/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub fn unpack_into_dir(args: UnpackArgs) -> Result<PathBuf, AnyError> {
let exe_ext = if is_windows { "exe" } else { "" };
let archive_path = dest_path.join(exe_name).with_extension("zip");
let exe_path = dest_path.join(exe_name).with_extension(exe_ext);
dbg!(&exe_path);
assert!(!exe_path.exists());

let archive_ext = Path::new(archive_name)
Expand All @@ -116,3 +117,24 @@ pub fn unpack_into_dir(args: UnpackArgs) -> Result<PathBuf, AnyError> {
assert!(exe_path.exists());
Ok(exe_path)
}

pub fn unpack_dir_into_dir(
out_name: &str,
dest_path: &Path,
archive_data: &[u8],
) -> Result<(), AnyError> {
let ext = out_name.rsplit_once('.').map(|(_, ext)| ext);
let archive_path = dest_path.join(out_name).with_extension(
ext
.map(|s| format!("{s}.zip"))
.unwrap_or_else(|| "zip".to_string()),
);

unzip(
archive_path.file_name().unwrap().to_str().unwrap(),
archive_data,
dest_path,
)?;

Ok(())
}