1+ //! # Profiles: built-in and customizable compiler flag presets
2+ //!
3+ //! [`Profiles`] is a collections of profiles from built-in profiles, and those
4+ //! defined in the root manifest and configurations.
5+ //! To start using a profile, most of the time you start from [`Profiles::new`],
6+ //! which does the followings:
7+ //!
8+ //! - Create a `Profiles` by merging profiles from configs onto the profile
9+ //! from root mainfest (see [`merge_config_profiles`]).
10+ //! - Add built-in profiles onto it (see [`Profiles::add_root_profiles`]).
11+ //! - Process profile inheritance for each profiles. (see [`Profiles::add_maker`]).
12+ //!
13+ //! Then you can query a [`Profile`] via [`Profiles::get_profile`], which respects
14+ //! the profile overriden hierarchy described in below. The [`Profile`] you get
15+ //! is basically an immutable struct containing the compiler flag presets.
16+ //!
17+ //! ## Profile overridden hierarchy
18+ //!
19+ //! Profile settings can be overridden for specific packages and build-time crates.
20+ //! The precedence is explained in [`ProfileMaker`].
21+ //! The algorithm happens within [`ProfileMaker::get_profile`].
22+
123use crate :: core:: compiler:: { CompileKind , CompileTarget , Unit } ;
224use crate :: core:: dependency:: Artifact ;
325use crate :: core:: resolver:: features:: FeaturesFor ;
@@ -11,6 +33,10 @@ use std::hash::Hash;
1133use std:: { cmp, env, fmt, hash} ;
1234
1335/// Collection of all profiles.
36+ ///
37+ /// To get a specific [`Profile`], you usually create this and call [`get_profile`] then.
38+ ///
39+ /// [`get_profile`]: Profiles::get_profile
1440#[ derive( Clone , Debug ) ]
1541pub struct Profiles {
1642 /// Incremental compilation can be overridden globally via:
@@ -355,12 +381,13 @@ impl Profiles {
355381/// An object used for handling the profile hierarchy.
356382///
357383/// The precedence of profiles are (first one wins):
384+ ///
358385/// - 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
386+ /// - ` [profile.dev.package.name]` -- a named package.
387+ /// - ` [profile.dev.package."*"]` -- this cannot apply to workspace members.
388+ /// - ` [profile.dev.build-override]` -- this can only apply to `build.rs` scripts
362389/// and their dependencies.
363- /// - [profile.dev]
390+ /// - ` [profile.dev]`
364391/// - Default (hard-coded) values.
365392#[ derive( Debug , Clone ) ]
366393struct ProfileMaker {
@@ -636,6 +663,7 @@ impl cmp::PartialEq for Profile {
636663}
637664
638665impl Profile {
666+ /// Returns a built-in `dev` profile.
639667 fn default_dev ( ) -> Profile {
640668 Profile {
641669 name : InternedString :: new ( "dev" ) ,
@@ -648,6 +676,7 @@ impl Profile {
648676 }
649677 }
650678
679+ /// Returns a built-in `release` profile.
651680 fn default_release ( ) -> Profile {
652681 Profile {
653682 name : InternedString :: new ( "release" ) ,
@@ -797,9 +826,7 @@ pub struct UnitFor {
797826 /// build.rs` is HOST=true, HOST_FEATURES=false for the same reasons that
798827 /// foo's build script is set that way.
799828 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.
829+ /// How Cargo processes the `panic` setting or profiles.
803830 panic_setting : PanicSetting ,
804831
805832 /// The compile kind of the root unit for which artifact dependencies are built.
@@ -821,6 +848,13 @@ pub struct UnitFor {
821848 artifact_target_for_features : Option < CompileTarget > ,
822849}
823850
851+ /// How Cargo processes the `panic` setting or profiles.
852+ ///
853+ /// This is done to handle test/benches inheriting from dev/release,
854+ /// as well as forcing `for_host` units to always unwind.
855+ /// It also interacts with [`-Z panic-abort-tests`].
856+ ///
857+ /// [`-Z panic-abort-tests`]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#panic-abort-tests
824858#[ derive( Copy , Clone , Debug , Eq , PartialEq , Hash , Ord , PartialOrd ) ]
825859enum PanicSetting {
826860 /// Used to force a unit to always be compiled with the `panic=unwind`
0 commit comments