Skip to content

Commit 8a0255f

Browse files
committed
Only pass '--crate-type' if supported by rustdoc
1 parent 752112c commit 8a0255f

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +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::{CargoResult, CargoResultExt, Cfg, Config, ProcessBuilder, Rustc};
10+
use crate::util::{CargoResult, CargoResultExt, Cfg, Config, ProcessBuilder, Rustc, process as process_};
1111

1212
/// Information about the platform target gleaned from querying rustc.
1313
///
@@ -35,6 +35,7 @@ pub struct TargetInfo {
3535
/// Extra flags to pass to `rustdoc`, see `env_args`.
3636
pub rustdocflags: Vec<String>,
3737
pub supports_pipelining: Option<bool>,
38+
pub supports_rustdoc_crate_type: bool
3839
}
3940

4041
/// Kind of each file generated by a Unit, part of `FileType`.
@@ -114,6 +115,13 @@ impl TargetInfo {
114115
Kind::Target => None,
115116
};
116117

118+
// NOTE: set this unconditionally to 'true' once support for '--crate-type'
119+
// on rustdoc rides to stable.
120+
let mut crate_type_test = process_(config.rustdoc()?);
121+
crate_type_test.args(&["--crate-type", "proc-macro", "--help"]);
122+
let supports_rustdoc_crate_type = crate_type_test.exec_with_output()
123+
.is_ok();
124+
117125
let target_triple = requested_target
118126
.as_ref()
119127
.map(|s| s.as_str())
@@ -204,6 +212,7 @@ impl TargetInfo {
204212
)?,
205213
cfg,
206214
supports_pipelining,
215+
supports_rustdoc_crate_type
207216
})
208217
}
209218

src/cargo/core/compiler/compilation.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub struct Compilation<'cfg> {
7373
primary_unit_rustc_process: Option<ProcessBuilder>,
7474

7575
target_runner: Option<(PathBuf, Vec<String>)>,
76+
supports_rustdoc_crate_type: bool
7677
}
7778

7879
impl<'cfg> Compilation<'cfg> {
@@ -109,6 +110,7 @@ impl<'cfg> Compilation<'cfg> {
109110
host: bcx.host_triple().to_string(),
110111
target: bcx.target_triple().to_string(),
111112
target_runner: target_runner(bcx)?,
113+
supports_rustdoc_crate_type: bcx.target_info.supports_rustdoc_crate_type
112114
})
113115
}
114116

@@ -140,8 +142,11 @@ impl<'cfg> Compilation<'cfg> {
140142
if target.edition() != Edition::Edition2015 {
141143
p.arg(format!("--edition={}", target.edition()));
142144
}
143-
for crate_type in target.rustc_crate_types() {
144-
p.arg("--crate-type").arg(crate_type);
145+
146+
if self.supports_rustdoc_crate_type {
147+
for crate_type in target.rustc_crate_types() {
148+
p.arg("--crate-type").arg(crate_type);
149+
}
145150
}
146151

147152
Ok(p)

0 commit comments

Comments
 (0)