Skip to content

Commit

Permalink
Pass rustdocflags like rustflags
Browse files Browse the repository at this point in the history
  • Loading branch information
gmorenz committed May 11, 2024
1 parent 7475f8a commit 5550429
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 18 deletions.
13 changes: 0 additions & 13 deletions src/cargo/core/compiler/build_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,6 @@ impl<'a, 'gctx> BuildContext<'a, 'gctx> {
self.build_config.jobs
}

/// Extra compiler flags to pass to `rustdoc` for a given unit.
///
/// Although it depends on the caller, in the current Cargo implementation,
/// these flags take precedence over those from [`BuildContext::extra_args_for`].
///
/// As of now, these flags come from environment variables and configurations.
/// See [`TargetInfo.rustdocflags`] for more on how Cargo collects them.
///
/// [`TargetInfo.rustdocflags`]: TargetInfo::rustdocflags
pub fn rustdocflags_args(&self, unit: &Unit) -> &[String] {
&self.target_data.info(unit.kind).rustdocflags
}

/// Extra compiler args for either `rustc` or `rustdoc`.
///
/// As of now, these flags come from the trailing args of either
Expand Down
5 changes: 3 additions & 2 deletions src/cargo/core/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub struct TargetInfo {
/// Extra flags to pass to `rustc`, see [`extra_args`].
pub rustflags: Arc<[String]>,
/// Extra flags to pass to `rustdoc`, see [`extra_args`].
pub rustdocflags: Vec<String>,
pub rustdocflags: Arc<[String]>,
/// Whether or not rustc (stably) supports the `--check-cfg` flag.
///
/// Can be removed once the minimum supported rustc version of Cargo is
Expand Down Expand Up @@ -320,7 +320,8 @@ impl TargetInfo {
Some(&cfg),
kind,
Flags::Rustdoc,
)?,
)?
.into(),
cfg,
support_split_debuginfo,
support_check_cfg,
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/build_runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
}
}
}
args.extend(self.bcx.rustdocflags_args(unit).iter().map(Into::into));
args.extend(unit.rustdocflags.iter().map(Into::into));

use super::MessageFormat;
let format = match self.bcx.build_config.message_format {
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/fingerprint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ fn calculate_normal(
// hashed to take up less space on disk as we just need to know when things
// change.
let extra_flags = if unit.mode.is_doc() || unit.mode.is_doc_scrape() {
build_runner.bcx.rustdocflags_args(unit)
&unit.rustdocflags
} else {
&unit.rustflags
}
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ fn prepare_rustdoc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResu

rustdoc::add_output_format(build_runner, unit, &mut rustdoc)?;

rustdoc.args(bcx.rustdocflags_args(unit));
rustdoc.args(&unit.rustdocflags);

if !crate_version_flag_already_present(&rustdoc) {
append_crate_version_flag(unit, &mut rustdoc);
Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/compiler/standard_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ pub fn generate_std_roots(
mode,
features.clone(),
target_data.info(*kind).rustflags.clone(),
target_data.info(*kind).rustdocflags.clone(),
/*is_std*/ true,
/*dep_hash*/ 0,
IsArtifact::No,
Expand Down
12 changes: 12 additions & 0 deletions src/cargo/core/compiler/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ pub struct UnitInner {
///
/// [`TargetInfo.rustflags`]: TargetInfo::rustflags
pub rustflags: Arc<[String]>,
/// Extra compiler flags to pass to `rustdoc` for a given unit.
///
/// Although it depends on the caller, in the current Cargo implementation,
/// these flags take precedence over those from [`BuildContext::extra_args_for`].
///
/// As of now, these flags come from environment variables and configurations.
/// See [`TargetInfo.rustdocflags`] for more on how Cargo collects them.
///
/// [`TargetInfo.rustdocflags`]: TargetInfo::rustdocflags
pub rustdocflags: Arc<[String]>,
// if `true`, the dependency is an artifact dependency, requiring special handling when
// calculating output directories, linkage and environment variables provided to builds.
pub artifact: IsArtifact,
Expand Down Expand Up @@ -211,6 +221,7 @@ impl UnitInterner {
mode: CompileMode,
features: Vec<InternedString>,
rustflags: Arc<[String]>,
rustdocflags: Arc<[String]>,
is_std: bool,
dep_hash: u64,
artifact: IsArtifact,
Expand Down Expand Up @@ -245,6 +256,7 @@ impl UnitInterner {
mode,
features,
rustflags,
rustdocflags,
is_std,
dep_hash,
artifact,
Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/compiler/unit_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ fn new_unit_dep_with_profile(
mode,
features,
state.target_data.info(kind).rustflags.clone(),
state.target_data.info(kind).rustdocflags.clone(),
state.is_std,
/*dep_hash*/ 0,
artifact.map_or(IsArtifact::No, |_| IsArtifact::Yes),
Expand Down
3 changes: 3 additions & 0 deletions src/cargo/ops/cargo_compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ fn traverse_and_share(
unit.mode,
unit.features.clone(),
unit.rustflags.clone(),
unit.rustdocflags.clone(),
unit.is_std,
unit.dep_hash,
unit.artifact,
Expand All @@ -732,6 +733,7 @@ fn traverse_and_share(
unit.mode,
unit.features.clone(),
unit.rustflags.clone(),
unit.rustdocflags.clone(),
unit.is_std,
new_dep_hash,
unit.artifact,
Expand Down Expand Up @@ -894,6 +896,7 @@ fn override_rustc_crate_types(
unit.mode,
unit.features.clone(),
unit.rustflags.clone(),
unit.rustdocflags.clone(),
unit.is_std,
unit.dep_hash,
unit.artifact,
Expand Down
1 change: 1 addition & 0 deletions src/cargo/ops/cargo_compile/unit_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ impl<'a> UnitGenerator<'a, '_> {
target_mode,
features.clone(),
self.target_data.info(kind).rustflags.clone(),
self.target_data.info(kind).rustdocflags.clone(),
/*is_std*/ false,
/*dep_hash*/ 0,
IsArtifact::No,
Expand Down

0 comments on commit 5550429

Please sign in to comment.