Skip to content

Commit e0e000e

Browse files
committed
Fix debuginfo strip when using --target
1 parent c3ad639 commit e0e000e

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

src/cargo/ops/cargo_compile/mod.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -427,23 +427,16 @@ pub fn create_bcx<'a, 'gctx>(
427427
.requested_kinds
428428
.iter()
429429
.any(CompileKind::is_host);
430-
let should_share_deps = host_kind_requested
431-
|| gctx.cli_unstable().bindeps
432-
&& unit_graph
433-
.iter()
434-
.any(|(unit, _)| unit.artifact_target_for_features.is_some());
435-
if should_share_deps {
436-
// Rebuild the unit graph, replacing the explicit host targets with
437-
// CompileKind::Host, removing `artifact_target_for_features` and merging any dependencies
438-
// shared with build and artifact dependencies.
439-
(units, scrape_units, unit_graph) = rebuild_unit_graph_shared(
440-
interner,
441-
unit_graph,
442-
&units,
443-
&scrape_units,
444-
host_kind_requested.then_some(explicit_host_kind),
445-
);
446-
}
430+
// Rebuild the unit graph, replacing the explicit host targets with
431+
// CompileKind::Host, removing `artifact_target_for_features` and merging any dependencies
432+
// shared with build and artifact dependencies.
433+
(units, scrape_units, unit_graph) = rebuild_unit_graph_shared(
434+
interner,
435+
unit_graph,
436+
&units,
437+
&scrape_units,
438+
host_kind_requested.then_some(explicit_host_kind),
439+
);
447440

448441
let mut extra_compiler_args = HashMap::new();
449442
if let Some(args) = extra_args {
@@ -545,7 +538,8 @@ where `<compatible-ver>` is the latest version supporting rustc {rustc_version}"
545538
Ok(bcx)
546539
}
547540

548-
/// This is used to rebuild the unit graph, sharing host dependencies if possible.
541+
/// This is used to rebuild the unit graph, sharing host dependencies if possible,
542+
/// and applying other unit adjustments based on the whole graph.
549543
///
550544
/// This will translate any unit's `CompileKind::Target(host)` to
551545
/// `CompileKind::Host` if `to_host` is not `None` and the kind is equal to `to_host`.
@@ -567,6 +561,14 @@ where `<compatible-ver>` is the latest version supporting rustc {rustc_version}"
567561
/// to the `Unit`, this allows the `CompileKind` to be changed back to `Host`
568562
/// and `artifact_target_for_features` to be removed without fear of an unwanted
569563
/// collision for build or artifact dependencies.
564+
///
565+
/// This is also responsible for adjusting the `strip` profile option to
566+
/// opportunistically strip if debug is 0 for all dependencies. This helps
567+
/// remove debuginfo added by the standard library.
568+
///
569+
/// This is also responsible for adjusting the `debug` setting for host
570+
/// dependencies, turning off debug if the user has not explicitly enabled it,
571+
/// and the unit is not shared with a target unit.
570572
fn rebuild_unit_graph_shared(
571573
interner: &UnitInterner,
572574
unit_graph: UnitGraph,

tests/testsuite/profiles.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Tests for profiles.
22
3-
use cargo_test_support::project;
43
use cargo_test_support::registry::Package;
4+
use cargo_test_support::{project, rustc_host};
55
use std::env;
66

77
#[cargo_test]
@@ -650,6 +650,10 @@ fn strip_debuginfo_in_release() {
650650
p.cargo("build --release -v")
651651
.with_stderr_contains("[RUNNING] `rustc [..] -C strip=debuginfo[..]`")
652652
.run();
653+
p.cargo("build --release -v --target")
654+
.arg(rustc_host())
655+
.with_stderr_contains("[RUNNING] `rustc [..] -C strip=debuginfo[..]`")
656+
.run();
653657
}
654658

655659
#[cargo_test]

0 commit comments

Comments
 (0)