@@ -470,8 +470,31 @@ impl ProfileMaker {
470
470
unit_for : UnitFor ,
471
471
) -> Profile {
472
472
let mut profile = self . default ;
473
+
474
+ // First apply profile-specific settings, things like
475
+ // `[profile.release]`
473
476
if let Some ( toml) = & self . toml {
474
477
merge_profile ( & mut profile, toml) ;
478
+ }
479
+
480
+ // Next start overriding those settings. First comes build dependencies
481
+ // which default to opt-level 0...
482
+ if unit_for. is_for_host ( ) {
483
+ // For-host units are things like procedural macros, build scripts, and
484
+ // their dependencies. For these units most projects simply want them
485
+ // to compile quickly and the runtime doesn't matter too much since
486
+ // they tend to process very little data. For this reason we default
487
+ // them to a "compile as quickly as possible" mode which for now means
488
+ // basically turning down the optimization level and avoid limiting
489
+ // codegen units. This ensures that we spend little time optimizing as
490
+ // well as enabling parallelism by not constraining codegen units.
491
+ profile. opt_level = InternedString :: new ( "0" ) ;
492
+ profile. codegen_units = None ;
493
+ }
494
+ // ... and next comes any other sorts of overrides specified in
495
+ // profiles, such as `[profile.release.build-override]` or
496
+ // `[profile.release.package.foo]`
497
+ if let Some ( toml) = & self . toml {
475
498
merge_toml_overrides ( pkg_id, is_member, unit_for, & mut profile, toml) ;
476
499
}
477
500
profile
@@ -487,17 +510,6 @@ fn merge_toml_overrides(
487
510
toml : & TomlProfile ,
488
511
) {
489
512
if unit_for. is_for_host ( ) {
490
- // For-host units are things like procedural macros, build scripts, and
491
- // their dependencies. For these units most projects simply want them
492
- // to compile quickly and the runtime doesn't matter too much since
493
- // they tend to process very little data. For this reason we default
494
- // them to a "compile as quickly as possible" mode which for now means
495
- // basically turning down the optimization level and avoid limiting
496
- // codegen units. This ensures that we spend little time optimizing as
497
- // well as enabling parallelism by not constraining codegen units.
498
- profile. opt_level = InternedString :: new ( "0" ) ;
499
- profile. codegen_units = None ;
500
-
501
513
if let Some ( build_override) = & toml. build_override {
502
514
merge_profile ( profile, build_override) ;
503
515
}
0 commit comments