Skip to content

Commit b68e854

Browse files
committed
Compute 'rustdoc --crate-type' support when Compilation is created
1 parent 60afaa7 commit b68e854

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

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

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

65
use log::debug;
@@ -34,7 +33,7 @@ pub struct BuildContext<'a, 'cfg> {
3433
pub packages: &'a PackageSet<'cfg>,
3534

3635
/// Information about the compiler.
37-
pub rustc: Rc<Rustc>,
36+
pub rustc: Rustc,
3837
/// Build information for the host arch.
3938
pub host_config: TargetConfig,
4039
/// Build information for the target.
@@ -54,7 +53,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
5453
units: &'a UnitInterner<'a>,
5554
extra_compiler_args: HashMap<Unit<'a>, Vec<String>>,
5655
) -> CargoResult<BuildContext<'a, 'cfg>> {
57-
let rustc = Rc::new(config.load_global_rustc(Some(ws))?);
56+
let rustc = config.load_global_rustc(Some(ws))?;
5857

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

src/cargo/core/compiler/compilation.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ 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;
65

76
use semver::Version;
87

@@ -76,7 +75,7 @@ pub struct Compilation<'cfg> {
7675
primary_unit_rustc_process: Option<ProcessBuilder>,
7776

7877
target_runner: Option<(PathBuf, Vec<String>)>,
79-
rustc: Rc<Rustc>,
78+
supports_rustdoc_crate_type: bool,
8079
}
8180

8281
impl<'cfg> Compilation<'cfg> {
@@ -113,7 +112,7 @@ impl<'cfg> Compilation<'cfg> {
113112
host: bcx.host_triple().to_string(),
114113
target: bcx.target_triple().to_string(),
115114
target_runner: target_runner(bcx)?,
116-
rustc: bcx.rustc.clone(),
115+
supports_rustdoc_crate_type: supports_rustdoc_crate_type(bcx.config, &bcx.rustc)?,
117116
})
118117
}
119118

@@ -139,25 +138,14 @@ impl<'cfg> Compilation<'cfg> {
139138
Ok(p)
140139
}
141140

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

160-
if self.supports_rustdoc_crate_type()? {
148+
if self.supports_rustdoc_crate_type {
161149
for crate_type in target.rustc_crate_types() {
162150
p.arg("--crate-type").arg(crate_type);
163151
}
@@ -331,3 +319,14 @@ fn target_runner(bcx: &BuildContext<'_, '_>) -> CargoResult<Option<(PathBuf, Vec
331319

332320
Ok(None)
333321
}
322+
323+
fn supports_rustdoc_crate_type(config: &Config, rustc: &Rustc) -> CargoResult<bool> {
324+
// NOTE: Unconditionally return 'true' once support for
325+
// rustdoc '--crate-type' rides to stable
326+
let mut crate_type_test = process(config.rustdoc()?);
327+
// If '--crate-type' is not supported by rustcoc, this command
328+
// will exit with an error. Otherwise, it will print a help message,
329+
// and exit successfully
330+
crate_type_test.args(&["--crate-type", "proc-macro", "--help"]);
331+
Ok(rustc.cached_output(&crate_type_test).is_ok())
332+
}

0 commit comments

Comments
 (0)