1
+ //! # Profiles: built-in and customizable compiler flag presets
2
+ //!
3
+ //! [`Profiles`] is a collections of built-in profiles, and profiles defined
4
+ //! in the root manifest and configurations.
5
+ //!
6
+ //! To start using a profile, most of the time you start from [`Profiles::new`],
7
+ //! which does the followings:
8
+ //!
9
+ //! - Create a `Profiles` by merging profiles from configs onto the profile
10
+ //! from root mainfest (see [`merge_config_profiles`]).
11
+ //! - Add built-in profiles onto it (see [`Profiles::add_root_profiles`]).
12
+ //! - Process profile inheritance for each profiles. (see [`Profiles::add_maker`]).
13
+ //!
14
+ //! Then you can query a [`Profile`] via [`Profiles::get_profile`], which respects
15
+ //! the profile overriden hierarchy described in below. The [`Profile`] you get
16
+ //! is basically an immutable struct containing the compiler flag presets.
17
+ //!
18
+ //! ## Profile overridden hierarchy
19
+ //!
20
+ //! Profile settings can be overridden for specific packages and build-time crates.
21
+ //! The precedence is explained in [`ProfileMaker`].
22
+ //! The algorithm happens within [`ProfileMaker::get_profile`].
23
+
1
24
use crate :: core:: compiler:: { CompileKind , CompileTarget , Unit } ;
2
25
use crate :: core:: dependency:: Artifact ;
3
26
use crate :: core:: resolver:: features:: FeaturesFor ;
@@ -11,6 +34,10 @@ use std::hash::Hash;
11
34
use std:: { cmp, env, fmt, hash} ;
12
35
13
36
/// Collection of all profiles.
37
+ ///
38
+ /// To get a specific [`Profile`], you usually create this and call [`get_profile`] then.
39
+ ///
40
+ /// [`get_profile`]: Profiles::get_profile
14
41
#[ derive( Clone , Debug ) ]
15
42
pub struct Profiles {
16
43
/// Incremental compilation can be overridden globally via:
@@ -355,12 +382,13 @@ impl Profiles {
355
382
/// An object used for handling the profile hierarchy.
356
383
///
357
384
/// The precedence of profiles are (first one wins):
385
+ ///
358
386
/// - Profiles in `.cargo/config` files (using same order as below).
359
- /// - [profile.dev.package.name] -- a named package.
360
- /// - [profile.dev.package."*"] -- this cannot apply to workspace members.
361
- /// - [profile.dev.build-override] -- this can only apply to `build.rs` scripts
387
+ /// - ` [profile.dev.package.name]` -- a named package.
388
+ /// - ` [profile.dev.package."*"]` -- this cannot apply to workspace members.
389
+ /// - ` [profile.dev.build-override]` -- this can only apply to `build.rs` scripts
362
390
/// and their dependencies.
363
- /// - [profile.dev]
391
+ /// - ` [profile.dev]`
364
392
/// - Default (hard-coded) values.
365
393
#[ derive( Debug , Clone ) ]
366
394
struct ProfileMaker {
@@ -636,6 +664,7 @@ impl cmp::PartialEq for Profile {
636
664
}
637
665
638
666
impl Profile {
667
+ /// Returns a built-in `dev` profile.
639
668
fn default_dev ( ) -> Profile {
640
669
Profile {
641
670
name : InternedString :: new ( "dev" ) ,
@@ -648,6 +677,7 @@ impl Profile {
648
677
}
649
678
}
650
679
680
+ /// Returns a built-in `release` profile.
651
681
fn default_release ( ) -> Profile {
652
682
Profile {
653
683
name : InternedString :: new ( "release" ) ,
@@ -797,9 +827,7 @@ pub struct UnitFor {
797
827
/// build.rs` is HOST=true, HOST_FEATURES=false for the same reasons that
798
828
/// foo's build script is set that way.
799
829
host_features : bool ,
800
- /// How Cargo processes the `panic` setting or profiles. This is done to
801
- /// handle test/benches inheriting from dev/release, as well as forcing
802
- /// `for_host` units to always unwind.
830
+ /// How Cargo processes the `panic` setting or profiles.
803
831
panic_setting : PanicSetting ,
804
832
805
833
/// The compile kind of the root unit for which artifact dependencies are built.
@@ -821,6 +849,13 @@ pub struct UnitFor {
821
849
artifact_target_for_features : Option < CompileTarget > ,
822
850
}
823
851
852
+ /// How Cargo processes the `panic` setting or profiles.
853
+ ///
854
+ /// This is done to handle test/benches inheriting from dev/release,
855
+ /// as well as forcing `for_host` units to always unwind.
856
+ /// It also interacts with [`-Z panic-abort-tests`].
857
+ ///
858
+ /// [`-Z panic-abort-tests`]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#panic-abort-tests
824
859
#[ derive( Copy , Clone , Debug , Eq , PartialEq , Hash , Ord , PartialOrd ) ]
825
860
enum PanicSetting {
826
861
/// Used to force a unit to always be compiled with the `panic=unwind`
0 commit comments