@@ -470,8 +470,31 @@ impl ProfileMaker {
470470 unit_for : UnitFor ,
471471 ) -> Profile {
472472 let mut profile = self . default ;
473+
474+ // First apply profile-specific settings, things like
475+ // `[profile.release]`
473476 if let Some ( toml) = & self . toml {
474477 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 {
475498 merge_toml_overrides ( pkg_id, is_member, unit_for, & mut profile, toml) ;
476499 }
477500 profile
@@ -487,17 +510,6 @@ fn merge_toml_overrides(
487510 toml : & TomlProfile ,
488511) {
489512 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-
501513 if let Some ( build_override) = & toml. build_override {
502514 merge_profile ( profile, build_override) ;
503515 }
0 commit comments