Skip to content

Commit 9bdc926

Browse files
committed
Auto merge of #11219 - weihanglo:doc/profiles, r=ehuss
doc(profiles): add module level doc
2 parents 823d917 + 74d7fe3 commit 9bdc926

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

src/cargo/core/profiles.rs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
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+
124
use crate::core::compiler::{CompileKind, CompileTarget, Unit};
225
use crate::core::dependency::Artifact;
326
use crate::core::resolver::features::FeaturesFor;
@@ -11,6 +34,10 @@ use std::hash::Hash;
1134
use std::{cmp, env, fmt, hash};
1235

1336
/// 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
1441
#[derive(Clone, Debug)]
1542
pub struct Profiles {
1643
/// Incremental compilation can be overridden globally via:
@@ -355,12 +382,13 @@ impl Profiles {
355382
/// An object used for handling the profile hierarchy.
356383
///
357384
/// The precedence of profiles are (first one wins):
385+
///
358386
/// - 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
362390
/// and their dependencies.
363-
/// - [profile.dev]
391+
/// - `[profile.dev]`
364392
/// - Default (hard-coded) values.
365393
#[derive(Debug, Clone)]
366394
struct ProfileMaker {
@@ -636,6 +664,7 @@ impl cmp::PartialEq for Profile {
636664
}
637665

638666
impl Profile {
667+
/// Returns a built-in `dev` profile.
639668
fn default_dev() -> Profile {
640669
Profile {
641670
name: InternedString::new("dev"),
@@ -648,6 +677,7 @@ impl Profile {
648677
}
649678
}
650679

680+
/// Returns a built-in `release` profile.
651681
fn default_release() -> Profile {
652682
Profile {
653683
name: InternedString::new("release"),
@@ -797,9 +827,7 @@ pub struct UnitFor {
797827
/// build.rs` is HOST=true, HOST_FEATURES=false for the same reasons that
798828
/// foo's build script is set that way.
799829
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.
803831
panic_setting: PanicSetting,
804832

805833
/// The compile kind of the root unit for which artifact dependencies are built.
@@ -821,6 +849,13 @@ pub struct UnitFor {
821849
artifact_target_for_features: Option<CompileTarget>,
822850
}
823851

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
824859
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
825860
enum PanicSetting {
826861
/// Used to force a unit to always be compiled with the `panic=unwind`

0 commit comments

Comments
 (0)