diff --git a/crates/cargo-test-support/src/lib.rs b/crates/cargo-test-support/src/lib.rs index 4ce0162bfbd2..c151dc48d446 100644 --- a/crates/cargo-test-support/src/lib.rs +++ b/crates/cargo-test-support/src/lib.rs @@ -831,12 +831,17 @@ impl Execs { self } + pub fn enable_split_debuginfo_packed(&mut self) -> &mut Self { + self.env("CARGO_PROFILE_DEV_SPLIT_DEBUGINFO", "packed") + .env("CARGO_PROFILE_TEST_SPLIT_DEBUGINFO", "packed") + .env("CARGO_PROFILE_RELEASE_SPLIT_DEBUGINFO", "packed") + .env("CARGO_PROFILE_BENCH_SPLIT_DEBUGINFO", "packed"); + self + } + pub fn enable_mac_dsym(&mut self) -> &mut Self { if cfg!(target_os = "macos") { - self.env("CARGO_PROFILE_DEV_SPLIT_DEBUGINFO", "packed") - .env("CARGO_PROFILE_TEST_SPLIT_DEBUGINFO", "packed") - .env("CARGO_PROFILE_RELEASE_SPLIT_DEBUGINFO", "packed") - .env("CARGO_PROFILE_BENCH_SPLIT_DEBUGINFO", "packed"); + return self.enable_split_debuginfo_packed(); } self } diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index 61398a7d66e6..4a346ed829a2 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -333,6 +333,7 @@ impl TargetInfo { crate_type: &CrateType, flavor: FileFlavor, target_triple: &str, + split_debuginfo: Option<&str>, ) -> CargoResult>> { let crate_type = if *crate_type == CrateType::Lib { CrateType::Rlib @@ -462,6 +463,14 @@ impl TargetInfo { // preserved. should_replace_hyphens: true, }) + } else if split_debuginfo == Some("packed") { + ret.push(FileType { + suffix: format!("{}.dwp", suffix), + prefix: prefix.clone(), + flavor: FileFlavor::DebugInfo, + crate_type: Some(crate_type), + should_replace_hyphens: false, + }) } } @@ -494,11 +503,19 @@ impl TargetInfo { mode: CompileMode, target_kind: &TargetKind, target_triple: &str, + split_debuginfo: Option<&str>, ) -> CargoResult<(Vec, Vec)> { match mode { - CompileMode::Build => self.calc_rustc_outputs(target_kind, target_triple), + CompileMode::Build => { + self.calc_rustc_outputs(target_kind, target_triple, split_debuginfo) + } CompileMode::Test | CompileMode::Bench => { - match self.file_types(&CrateType::Bin, FileFlavor::Normal, target_triple)? { + match self.file_types( + &CrateType::Bin, + FileFlavor::Normal, + target_triple, + split_debuginfo, + )? { Some(fts) => Ok((fts, Vec::new())), None => Ok((Vec::new(), vec![CrateType::Bin])), } @@ -517,6 +534,7 @@ impl TargetInfo { &self, target_kind: &TargetKind, target_triple: &str, + split_debuginfo: Option<&str>, ) -> CargoResult<(Vec, Vec)> { let mut unsupported = Vec::new(); let mut result = Vec::new(); @@ -527,7 +545,7 @@ impl TargetInfo { } else { FileFlavor::Normal }; - let file_types = self.file_types(crate_type, flavor, target_triple)?; + let file_types = self.file_types(crate_type, flavor, target_triple, split_debuginfo)?; match file_types { Some(types) => { result.extend(types); diff --git a/src/cargo/core/compiler/context/compilation_files.rs b/src/cargo/core/compiler/context/compilation_files.rs index dcfaabf327a1..5a3d51bd619f 100644 --- a/src/cargo/core/compiler/context/compilation_files.rs +++ b/src/cargo/core/compiler/context/compilation_files.rs @@ -346,6 +346,7 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> { CompileMode::Build, &TargetKind::Bin, bcx.target_data.short_name(&kind), + None, ) .expect("target must support `bin`"); @@ -486,8 +487,12 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> { let info = bcx.target_data.info(unit.kind); let triple = bcx.target_data.short_name(&unit.kind); - let (file_types, unsupported) = - info.rustc_outputs(unit.mode, unit.target.kind(), triple)?; + let (file_types, unsupported) = info.rustc_outputs( + unit.mode, + unit.target.kind(), + triple, + unit.profile.split_debuginfo.as_deref(), + )?; if file_types.is_empty() { if !unsupported.is_empty() { let unsupported_strs: Vec<_> = unsupported.iter().map(|ct| ct.as_str()).collect(); diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index 507c2d89b1ce..83a607eee370 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -174,7 +174,7 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> { let (file_types, _unsupported) = target_data .info(*compile_kind) - .rustc_outputs(mode, target.kind(), triple)?; + .rustc_outputs(mode, target.kind(), triple, None)?; let (dir, uplift_dir) = match target.kind() { TargetKind::ExampleBin | TargetKind::ExampleLib(..) => { (layout.examples(), Some(layout.examples())) @@ -203,6 +203,8 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> { rm_rf_glob(&split_debuginfo_obj, config, &mut progress)?; let split_debuginfo_dwo = dir_glob.join(format!("{}.*.dwo", crate_name)); rm_rf_glob(&split_debuginfo_dwo, config, &mut progress)?; + let split_debuginfo_dwp = dir_glob.join(format!("{}.*.dwp", crate_name)); + rm_rf_glob(&split_debuginfo_dwp, config, &mut progress)?; // Remove the uplifted copy. if let Some(uplift_dir) = uplift_dir { diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 58c3f6baf014..8ad9f70ac526 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -5216,6 +5216,29 @@ fn uplift_pdb_of_bin_on_windows() { assert!(!p.target_debug_dir().join("d.pdb").exists()); } +#[cargo_test] +#[cfg(target_os = "linux")] +fn uplift_dwp_of_bin_on_linux() { + let p = project() + .file("src/main.rs", "fn main() { panic!(); }") + .file("src/bin/b.rs", "fn main() { panic!(); }") + .file("src/bin/foo-bar.rs", "fn main() { panic!(); }") + .file("examples/c.rs", "fn main() { panic!(); }") + .file("tests/d.rs", "fn main() { panic!(); }") + .build(); + + p.cargo("build --bins --examples --tests") + .enable_split_debuginfo_packed() + .run(); + assert!(p.target_debug_dir().join("foo.dwp").is_file()); + assert!(p.target_debug_dir().join("b.dwp").is_file()); + assert!(p.target_debug_dir().join("examples/c.dwp").exists()); + assert!(p.target_debug_dir().join("foo-bar").is_file()); + assert!(p.target_debug_dir().join("foo-bar.dwp").is_file()); + assert!(!p.target_debug_dir().join("c.dwp").exists()); + assert!(!p.target_debug_dir().join("d.dwp").exists()); +} + // Ensure that `cargo build` chooses the correct profile for building // targets based on filters (assuming `--profile` is not specified). #[cargo_test]