Skip to content

Commit f16bfc2

Browse files
committed
Auto merge of #9298 - alexcrichton:mac-split-debuginfo-default, r=ehuss
Default macOS targets to `unpacked` debuginfo This commit continues the work from #9112 to enable `unpacked` split debuginfo on macOS targets by default. This has been discussed on [internals] for awhile now and no breakage has emerged while significant speedups have. This is expected to be a compile-time and `target`-directory size win for almost all macOS Rust projects. While breakage is possible it's possible to mitigate this with project-local or global cargo configuration of the `dev` and `test` profiles. [internals]: https://internals.rust-lang.org/t/help-test-faster-incremental-debug-macos-builds-on-nightly/14016/9
2 parents 8e24bb0 + a4f0988 commit f16bfc2

File tree

7 files changed

+47
-31
lines changed

7 files changed

+47
-31
lines changed

crates/cargo-test-support/src/lib.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,14 +1614,6 @@ fn _process(t: &OsStr) -> ProcessBuilder {
16141614
p.env("PATH", new_path);
16151615
}
16161616

1617-
if cfg!(target_os = "macos") {
1618-
// This makes the test suite run substantially faster.
1619-
p.env("CARGO_PROFILE_DEV_SPLIT_DEBUGINFO", "unpacked")
1620-
.env("CARGO_PROFILE_TEST_SPLIT_DEBUGINFO", "unpacked")
1621-
.env("CARGO_PROFILE_RELEASE_SPLIT_DEBUGINFO", "unpacked")
1622-
.env("CARGO_PROFILE_BENCH_SPLIT_DEBUGINFO", "unpacked");
1623-
}
1624-
16251617
p.cwd(&paths::root())
16261618
.env("HOME", paths::home())
16271619
.env("CARGO_HOME", paths::home().join(".cargo"))

src/cargo/core/compiler/standard_lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,18 @@ pub fn generate_std_roots(
158158
// in time is minimal, and the difference in caching is
159159
// significant.
160160
let mode = CompileMode::Build;
161-
let profile = profiles.get_profile(
162-
pkg.package_id(),
163-
/*is_member*/ false,
164-
/*is_local*/ false,
165-
unit_for,
166-
mode,
167-
);
168161
let features = std_features.activated_features(pkg.package_id(), FeaturesFor::NormalOrDev);
169162

170163
for kind in kinds {
171164
let list = ret.entry(*kind).or_insert_with(Vec::new);
165+
let profile = profiles.get_profile(
166+
pkg.package_id(),
167+
/*is_member*/ false,
168+
/*is_local*/ false,
169+
unit_for,
170+
mode,
171+
*kind,
172+
);
172173
list.push(interner.intern(
173174
pkg,
174175
lib,

src/cargo/core/compiler/unit_dependencies.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ fn new_unit_dep(
585585
is_local,
586586
unit_for,
587587
mode,
588+
kind,
588589
);
589590
new_unit_dep_with_profile(state, parent, pkg, target, unit_for, kind, mode, profile)
590591
}

src/cargo/core/profiles.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::core::compiler::{CompileMode, Unit};
1+
use crate::core::compiler::{CompileKind, CompileMode, Unit};
22
use crate::core::resolver::features::FeaturesFor;
33
use crate::core::{Feature, PackageId, PackageIdSpec, Resolve, Shell, Target, Workspace};
44
use crate::util::errors::CargoResultExt;
@@ -291,6 +291,7 @@ impl Profiles {
291291
is_local: bool,
292292
unit_for: UnitFor,
293293
mode: CompileMode,
294+
kind: CompileKind,
294295
) -> Profile {
295296
let (profile_name, inherits) = if !self.named_profiles_enabled {
296297
// With the feature disabled, we degrade `--profile` back to the
@@ -346,6 +347,23 @@ impl Profiles {
346347
}
347348
}
348349

350+
// Default macOS debug information to being stored in the "unpacked"
351+
// split-debuginfo format. At the time of this writing that's the only
352+
// platform which has a stable `-Csplit-debuginfo` option for rustc,
353+
// and it's typically much faster than running `dsymutil` on all builds
354+
// in incremental cases.
355+
if let Some(debug) = profile.debuginfo {
356+
if profile.split_debuginfo.is_none() && debug > 0 {
357+
let target = match &kind {
358+
CompileKind::Host => self.rustc_host.as_str(),
359+
CompileKind::Target(target) => target.short_name(),
360+
};
361+
if target.contains("-apple-") {
362+
profile.split_debuginfo = Some(InternedString::new("unpacked"));
363+
}
364+
}
365+
}
366+
349367
// Incremental can be globally overridden.
350368
if let Some(v) = self.incremental {
351369
profile.incremental = v;

src/cargo/ops/cargo_compile.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -909,19 +909,20 @@ fn generate_targets(
909909
};
910910

911911
let is_local = pkg.package_id().source_id().is_path();
912-
let profile = profiles.get_profile(
913-
pkg.package_id(),
914-
ws.is_member(pkg),
915-
is_local,
916-
unit_for,
917-
target_mode,
918-
);
919912

920913
// No need to worry about build-dependencies, roots are never build dependencies.
921914
let features_for = FeaturesFor::from_for_host(target.proc_macro());
922915
let features = resolved_features.activated_features(pkg.package_id(), features_for);
923916

924917
for kind in requested_kinds {
918+
let profile = profiles.get_profile(
919+
pkg.package_id(),
920+
ws.is_member(pkg),
921+
is_local,
922+
unit_for,
923+
target_mode,
924+
*kind,
925+
);
925926
let unit = interner.intern(
926927
pkg,
927928
target,

src/doc/src/reference/profiles.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@ controls whether debug information, if generated, is either placed in the
8383
executable itself or adjacent to it.
8484

8585
This option is a string and acceptable values are the same as those the
86-
[compiler accepts][`-C split-debuginfo` flag]. See that documentation for the
87-
default behavior, which is platform-specific. Some options are only available
88-
on the [nightly channel]. The default may change in the future once more
89-
testing has been performed, and support for DWARF is stabilized.
86+
[compiler accepts][`-C split-debuginfo` flag]. The default value for this option
87+
is `unpacked` on macOS for profiles that have debug information otherwise
88+
enabled. Otherwise the default for this option is [documented with rustc][`-C
89+
split-debuginfo` flag] and is platform-specific. Some options are only
90+
available on the [nightly channel]. The Cargo default may change in the future
91+
once more testing has been performed, and support for DWARF is stabilized.
9092

9193
[nightly channel]: ../../book/appendix-07-nightly-rust.html
9294
[`-C split-debuginfo` flag]: ../../rustc/codegen-options/index.html#split-debuginfo

tests/testsuite/profile_config.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ fn named_config_profile() {
342342
// foo -> middle -> bar -> dev
343343
// middle exists in Cargo.toml, the others in .cargo/config
344344
use super::config::ConfigBuilder;
345-
use cargo::core::compiler::CompileMode;
345+
use cargo::core::compiler::{CompileKind, CompileMode};
346346
use cargo::core::profiles::{Profiles, UnitFor};
347347
use cargo::core::{PackageId, Workspace};
348348
use cargo::util::interning::InternedString;
@@ -403,7 +403,8 @@ fn named_config_profile() {
403403

404404
// normal package
405405
let mode = CompileMode::Build;
406-
let p = profiles.get_profile(a_pkg, true, true, UnitFor::new_normal(), mode);
406+
let kind = CompileKind::Host;
407+
let p = profiles.get_profile(a_pkg, true, true, UnitFor::new_normal(), mode, kind);
407408
assert_eq!(p.name, "foo");
408409
assert_eq!(p.codegen_units, Some(2)); // "foo" from config
409410
assert_eq!(p.opt_level, "1"); // "middle" from manifest
@@ -412,7 +413,7 @@ fn named_config_profile() {
412413
assert_eq!(p.overflow_checks, true); // "dev" built-in (ignore package override)
413414

414415
// build-override
415-
let bo = profiles.get_profile(a_pkg, true, true, UnitFor::new_host(false), mode);
416+
let bo = profiles.get_profile(a_pkg, true, true, UnitFor::new_host(false), mode, kind);
416417
assert_eq!(bo.name, "foo");
417418
assert_eq!(bo.codegen_units, Some(6)); // "foo" build override from config
418419
assert_eq!(bo.opt_level, "0"); // default to zero
@@ -421,7 +422,7 @@ fn named_config_profile() {
421422
assert_eq!(bo.overflow_checks, true); // SAME as normal
422423

423424
// package overrides
424-
let po = profiles.get_profile(dep_pkg, false, true, UnitFor::new_normal(), mode);
425+
let po = profiles.get_profile(dep_pkg, false, true, UnitFor::new_normal(), mode, kind);
425426
assert_eq!(po.name, "foo");
426427
assert_eq!(po.codegen_units, Some(7)); // "foo" package override from config
427428
assert_eq!(po.opt_level, "1"); // SAME as normal

0 commit comments

Comments
 (0)