Skip to content

Commit 5d302e5

Browse files
committed
Cache outout of 'rustdoc --crate-type proc-macro --help'
1 parent 511050b commit 5d302e5

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

src/cargo/core/compiler/build_context/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::collections::HashMap;
22
use std::path::{Path, PathBuf};
33
use std::str;
4+
use std::rc::Rc;
45

56
use log::debug;
67

@@ -33,7 +34,7 @@ pub struct BuildContext<'a, 'cfg> {
3334
pub packages: &'a PackageSet<'cfg>,
3435

3536
/// Information about the compiler.
36-
pub rustc: Rustc,
37+
pub rustc: Rc<Rustc>,
3738
/// Build information for the host arch.
3839
pub host_config: TargetConfig,
3940
/// Build information for the target.
@@ -53,7 +54,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
5354
units: &'a UnitInterner<'a>,
5455
extra_compiler_args: HashMap<Unit<'a>, Vec<String>>,
5556
) -> CargoResult<BuildContext<'a, 'cfg>> {
56-
let rustc = config.load_global_rustc(Some(ws))?;
57+
let rustc = Rc::new(config.load_global_rustc(Some(ws))?);
5758

5859
let host_config = TargetConfig::new(config, &rustc.host)?;
5960
let target_config = match build_config.requested_target.as_ref() {

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use std::str::{self, FromStr};
77
use crate::core::compiler::Kind;
88
use crate::core::TargetKind;
99
use crate::util::CfgExpr;
10-
use crate::util::{
11-
process as process_, CargoResult, CargoResultExt, Cfg, Config, ProcessBuilder, Rustc,
12-
};
10+
use crate::util::{CargoResult, CargoResultExt, Cfg, Config, ProcessBuilder, Rustc};
1311

1412
/// Information about the platform target gleaned from querying rustc.
1513
///
@@ -37,7 +35,6 @@ pub struct TargetInfo {
3735
/// Extra flags to pass to `rustdoc`, see `env_args`.
3836
pub rustdocflags: Vec<String>,
3937
pub supports_pipelining: Option<bool>,
40-
pub supports_rustdoc_crate_type: bool,
4138
}
4239

4340
/// Kind of each file generated by a Unit, part of `FileType`.
@@ -117,12 +114,6 @@ impl TargetInfo {
117114
Kind::Target => None,
118115
};
119116

120-
// NOTE: set this unconditionally to 'true' once support for '--crate-type'
121-
// on rustdoc rides to stable.
122-
let mut crate_type_test = process_(config.rustdoc()?);
123-
crate_type_test.args(&["--crate-type", "proc-macro", "--help"]);
124-
let supports_rustdoc_crate_type = crate_type_test.exec_with_output().is_ok();
125-
126117
let target_triple = requested_target
127118
.as_ref()
128119
.map(|s| s.as_str())
@@ -213,7 +204,6 @@ impl TargetInfo {
213204
)?,
214205
cfg,
215206
supports_pipelining,
216-
supports_rustdoc_crate_type,
217207
})
218208
}
219209

src/cargo/core/compiler/compilation.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ use std::collections::{BTreeSet, HashMap, HashSet};
22
use std::env;
33
use std::ffi::OsStr;
44
use std::path::PathBuf;
5+
use std::rc::Rc;
56

67
use semver::Version;
78

89
use super::BuildContext;
910
use crate::core::{Edition, InternedString, Package, PackageId, Target};
10-
use crate::util::{self, join_paths, process, CargoResult, CfgExpr, Config, ProcessBuilder};
11+
use crate::util::{self, join_paths, process, CargoResult, CfgExpr, Config, ProcessBuilder, rustc::Rustc};
1112

1213
pub struct Doctest {
1314
/// The package being doc-tested.
@@ -73,7 +74,7 @@ pub struct Compilation<'cfg> {
7374
primary_unit_rustc_process: Option<ProcessBuilder>,
7475

7576
target_runner: Option<(PathBuf, Vec<String>)>,
76-
supports_rustdoc_crate_type: bool,
77+
rustc: Rc<Rustc>
7778
}
7879

7980
impl<'cfg> Compilation<'cfg> {
@@ -110,7 +111,7 @@ impl<'cfg> Compilation<'cfg> {
110111
host: bcx.host_triple().to_string(),
111112
target: bcx.target_triple().to_string(),
112113
target_runner: target_runner(bcx)?,
113-
supports_rustdoc_crate_type: bcx.target_info.supports_rustdoc_crate_type,
114+
rustc: bcx.rustc.clone()
114115
})
115116
}
116117

@@ -136,14 +137,25 @@ impl<'cfg> Compilation<'cfg> {
136137
Ok(p)
137138
}
138139

140+
fn supports_rustdoc_crate_type(&self) -> CargoResult<bool> {
141+
// NOTE: Unconditionally return 'true' once support for
142+
// rustdoc '--crate-type' rides to stable
143+
let mut crate_type_test = process(self.config.rustdoc()?);
144+
// If '--crate-type' is not supported by rustcoc, this command
145+
// will exit with an error. Otherwise, it will print a help message,
146+
// and exit successfully
147+
crate_type_test.args(&["--crate-type", "proc-macro", "--help"]);
148+
Ok(self.rustc.cached_output(&crate_type_test).is_ok())
149+
}
150+
139151
/// See `process`.
140152
pub fn rustdoc_process(&self, pkg: &Package, target: &Target) -> CargoResult<ProcessBuilder> {
141153
let mut p = self.fill_env(process(&*self.config.rustdoc()?), pkg, false)?;
142154
if target.edition() != Edition::Edition2015 {
143155
p.arg(format!("--edition={}", target.edition()));
144156
}
145157

146-
if self.supports_rustdoc_crate_type {
158+
if self.supports_rustdoc_crate_type()? {
147159
for crate_type in target.rustc_crate_types() {
148160
p.arg("--crate-type").arg(crate_type);
149161
}

0 commit comments

Comments
 (0)