@@ -314,7 +314,7 @@ impl Profiles {
314
314
mode : CompileMode ,
315
315
profile_kind : ProfileKind ,
316
316
) -> Profile {
317
- let profile_name = if !self . named_profiles_enabled {
317
+ let ( profile_name, inherits ) = if !self . named_profiles_enabled {
318
318
// With the feature disabled, we degrade `--profile` back to the
319
319
// `--release` and `--debug` predicates, and convert back from
320
320
// ProfileKind::Custom instantiation.
@@ -328,9 +328,9 @@ impl Profiles {
328
328
match mode {
329
329
CompileMode :: Test | CompileMode :: Bench => {
330
330
if release {
331
- "bench"
331
+ ( "bench" , Some ( "release" ) )
332
332
} else {
333
- "test"
333
+ ( "test" , Some ( "dev" ) )
334
334
}
335
335
}
336
336
CompileMode :: Build
@@ -342,26 +342,33 @@ impl Profiles {
342
342
// ancestor's profile. However, `cargo clean -p` can hit this
343
343
// path.
344
344
if release {
345
- "release"
345
+ ( "release" , None )
346
346
} else {
347
- "dev"
347
+ ( "dev" , None )
348
348
}
349
349
}
350
- CompileMode :: Doc { .. } => "doc" ,
350
+ CompileMode :: Doc { .. } => ( "doc" , None ) ,
351
351
}
352
352
} else {
353
- profile_kind. name ( )
353
+ ( profile_kind. name ( ) , None )
354
354
} ;
355
355
let maker = match self . by_name . get ( profile_name) {
356
356
None => panic ! ( "Profile {} undefined" , profile_name) ,
357
357
Some ( r) => r,
358
358
} ;
359
359
let mut profile = maker. get_profile ( Some ( pkg_id) , is_member, unit_for) ;
360
- // `panic` may not be set for tests/benches, or any of their
361
- // dependencies, so handle that here if that's what `UnitFor` tells us
362
- // to do.
363
- if !unit_for. is_panic_abort_ok ( ) {
364
- profile. panic = PanicStrategy :: Unwind ;
360
+
361
+ // Dealing with `panic=abort` and `panic=unwind` requires some special
362
+ // treatment. Be sure to process all the various options here.
363
+ match unit_for. panic_setting ( ) {
364
+ PanicSetting :: AlwaysUnwind => profile. panic = PanicStrategy :: Unwind ,
365
+ PanicSetting :: ReadProfile => { }
366
+ PanicSetting :: Inherit => {
367
+ if let Some ( inherits) = inherits {
368
+ let maker = self . by_name . get ( inherits) . unwrap ( ) ;
369
+ profile. panic = maker. get_profile ( Some ( pkg_id) , is_member, unit_for) . panic ;
370
+ }
371
+ }
365
372
}
366
373
367
374
// Incremental can be globally overridden.
@@ -881,11 +888,25 @@ pub struct UnitFor {
881
888
/// any of its dependencies. This enables `build-override` profiles for
882
889
/// these targets.
883
890
build : bool ,
884
- /// This is true if it is *allowed* to set the `panic=abort` flag. Currently
885
- /// this is false for test/bench targets and all their dependencies, and
886
- /// "for_host" units such as proc macro and custom build scripts and their
887
- /// dependencies.
888
- panic_abort_ok : bool ,
891
+ /// How Cargo processes the `panic` setting or profiles. This is done to
892
+ /// handle test/benches inheriting from dev/release, as well as forcing
893
+ /// `for_host` units to always unwind.
894
+ panic_setting : PanicSetting ,
895
+ }
896
+
897
+ #[ derive( Copy , Clone , Debug , Eq , PartialEq , Hash , Ord , PartialOrd ) ]
898
+ enum PanicSetting {
899
+ /// Used to force a unit to always be compiled with the `panic=unwind`
900
+ /// strategy, notably for build scripts, proc macros, etc.
901
+ AlwaysUnwind ,
902
+
903
+ /// Indicates that this unit will read its `profile` setting and use
904
+ /// whatever is configured there.
905
+ ReadProfile ,
906
+
907
+ /// This unit will ignore its `panic` setting in its profile and will
908
+ /// instead inherit it from the `dev` or `release` profile, as appropriate.
909
+ Inherit ,
889
910
}
890
911
891
912
impl UnitFor {
@@ -894,7 +915,7 @@ impl UnitFor {
894
915
pub fn new_normal ( ) -> UnitFor {
895
916
UnitFor {
896
917
build : false ,
897
- panic_abort_ok : true ,
918
+ panic_setting : PanicSetting :: ReadProfile ,
898
919
}
899
920
}
900
921
@@ -904,7 +925,7 @@ impl UnitFor {
904
925
build : true ,
905
926
// Force build scripts to always use `panic=unwind` for now to
906
927
// maximally share dependencies with procedural macros.
907
- panic_abort_ok : false ,
928
+ panic_setting : PanicSetting :: AlwaysUnwind ,
908
929
}
909
930
}
910
931
@@ -915,7 +936,7 @@ impl UnitFor {
915
936
// Force plugins to use `panic=abort` so panics in the compiler do
916
937
// not abort the process but instead end with a reasonable error
917
938
// message that involves catching the panic in the compiler.
918
- panic_abort_ok : false ,
939
+ panic_setting : PanicSetting :: AlwaysUnwind ,
919
940
}
920
941
}
921
942
@@ -928,7 +949,15 @@ impl UnitFor {
928
949
pub fn new_test ( config : & Config ) -> UnitFor {
929
950
UnitFor {
930
951
build : false ,
931
- panic_abort_ok : config. cli_unstable ( ) . panic_abort_tests ,
952
+ // We're testing out an unstable feature (`-Zpanic-abort-tests`)
953
+ // which inherits the panic setting from the dev/release profile
954
+ // (basically avoid recompiles) but historical defaults required
955
+ // that we always unwound.
956
+ panic_setting : if config. cli_unstable ( ) . panic_abort_tests {
957
+ PanicSetting :: Inherit
958
+ } else {
959
+ PanicSetting :: AlwaysUnwind
960
+ } ,
932
961
}
933
962
}
934
963
@@ -942,7 +971,11 @@ impl UnitFor {
942
971
pub fn with_for_host ( self , for_host : bool ) -> UnitFor {
943
972
UnitFor {
944
973
build : self . build || for_host,
945
- panic_abort_ok : self . panic_abort_ok && !for_host,
974
+ panic_setting : if for_host {
975
+ PanicSetting :: AlwaysUnwind
976
+ } else {
977
+ self . panic_setting
978
+ } ,
946
979
}
947
980
}
948
981
@@ -952,29 +985,32 @@ impl UnitFor {
952
985
self . build
953
986
}
954
987
955
- /// Returns `true` if this unit is allowed to set the `panic=abort`
956
- /// compiler flag.
957
- pub fn is_panic_abort_ok ( self ) -> bool {
958
- self . panic_abort_ok
988
+ /// Returns how `panic` settings should be handled for this profile
989
+ fn panic_setting ( self ) -> PanicSetting {
990
+ self . panic_setting
959
991
}
960
992
961
993
/// All possible values, used by `clean`.
962
994
pub fn all_values ( ) -> & ' static [ UnitFor ] {
963
- static ALL : [ UnitFor ; 3 ] = [
995
+ static ALL : & [ UnitFor ] = & [
964
996
UnitFor {
965
997
build : false ,
966
- panic_abort_ok : true ,
998
+ panic_setting : PanicSetting :: ReadProfile ,
967
999
} ,
968
1000
UnitFor {
969
1001
build : true ,
970
- panic_abort_ok : false ,
1002
+ panic_setting : PanicSetting :: AlwaysUnwind ,
1003
+ } ,
1004
+ UnitFor {
1005
+ build : false ,
1006
+ panic_setting : PanicSetting :: AlwaysUnwind ,
971
1007
} ,
972
1008
UnitFor {
973
1009
build : false ,
974
- panic_abort_ok : false ,
1010
+ panic_setting : PanicSetting :: Inherit ,
975
1011
} ,
976
1012
] ;
977
- & ALL
1013
+ ALL
978
1014
}
979
1015
}
980
1016
0 commit comments