From 752112ce78fce1669fc9b9246ba88600d5c048fa Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Sat, 20 Jul 2019 22:59:55 -0400 Subject: [PATCH 1/7] Pass --crate-type to rustdoc This supports the corresponding rustc PR. To enable rustdoc to properly document macros, we mirror the '--crate-type' flag used by rustc. Currently, all crate types other than 'proc-macro' are ignored by rustdoc. --- src/cargo/core/compiler/compilation.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index ec5374d04be..861eac0456a 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -140,6 +140,10 @@ impl<'cfg> Compilation<'cfg> { if target.edition() != Edition::Edition2015 { p.arg(format!("--edition={}", target.edition())); } + for crate_type in target.rustc_crate_types() { + p.arg("--crate-type").arg(crate_type); + } + Ok(p) } From 8a0255f9ac35c64af4926bdfd1f2f037642a1e7e Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Sat, 24 Aug 2019 20:25:58 -0400 Subject: [PATCH 2/7] Only pass '--crate-type' if supported by rustdoc --- src/cargo/core/compiler/build_context/target_info.rs | 11 ++++++++++- src/cargo/core/compiler/compilation.rs | 9 +++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index b5b74fd9024..9c9363bc352 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -7,7 +7,7 @@ use std::str::{self, FromStr}; use crate::core::compiler::Kind; use crate::core::TargetKind; use crate::util::CfgExpr; -use crate::util::{CargoResult, CargoResultExt, Cfg, Config, ProcessBuilder, Rustc}; +use crate::util::{CargoResult, CargoResultExt, Cfg, Config, ProcessBuilder, Rustc, process as process_}; /// Information about the platform target gleaned from querying rustc. /// @@ -35,6 +35,7 @@ pub struct TargetInfo { /// Extra flags to pass to `rustdoc`, see `env_args`. pub rustdocflags: Vec, pub supports_pipelining: Option, + pub supports_rustdoc_crate_type: bool } /// Kind of each file generated by a Unit, part of `FileType`. @@ -114,6 +115,13 @@ impl TargetInfo { Kind::Target => None, }; + // NOTE: set this unconditionally to 'true' once support for '--crate-type' + // on rustdoc rides to stable. + let mut crate_type_test = process_(config.rustdoc()?); + crate_type_test.args(&["--crate-type", "proc-macro", "--help"]); + let supports_rustdoc_crate_type = crate_type_test.exec_with_output() + .is_ok(); + let target_triple = requested_target .as_ref() .map(|s| s.as_str()) @@ -204,6 +212,7 @@ impl TargetInfo { )?, cfg, supports_pipelining, + supports_rustdoc_crate_type }) } diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index 861eac0456a..4380b9244f5 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -73,6 +73,7 @@ pub struct Compilation<'cfg> { primary_unit_rustc_process: Option, target_runner: Option<(PathBuf, Vec)>, + supports_rustdoc_crate_type: bool } impl<'cfg> Compilation<'cfg> { @@ -109,6 +110,7 @@ impl<'cfg> Compilation<'cfg> { host: bcx.host_triple().to_string(), target: bcx.target_triple().to_string(), target_runner: target_runner(bcx)?, + supports_rustdoc_crate_type: bcx.target_info.supports_rustdoc_crate_type }) } @@ -140,8 +142,11 @@ impl<'cfg> Compilation<'cfg> { if target.edition() != Edition::Edition2015 { p.arg(format!("--edition={}", target.edition())); } - for crate_type in target.rustc_crate_types() { - p.arg("--crate-type").arg(crate_type); + + if self.supports_rustdoc_crate_type { + for crate_type in target.rustc_crate_types() { + p.arg("--crate-type").arg(crate_type); + } } Ok(p) From 511050baefa2ec21c2be8c3eaee2aade1da2c06b Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Sat, 24 Aug 2019 20:40:52 -0400 Subject: [PATCH 3/7] Run 'cargo fmt' --- src/cargo/core/compiler/build_context/target_info.rs | 11 ++++++----- src/cargo/core/compiler/compilation.rs | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index 9c9363bc352..7fedc7fc24b 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -7,7 +7,9 @@ use std::str::{self, FromStr}; use crate::core::compiler::Kind; use crate::core::TargetKind; use crate::util::CfgExpr; -use crate::util::{CargoResult, CargoResultExt, Cfg, Config, ProcessBuilder, Rustc, process as process_}; +use crate::util::{ + process as process_, CargoResult, CargoResultExt, Cfg, Config, ProcessBuilder, Rustc, +}; /// Information about the platform target gleaned from querying rustc. /// @@ -35,7 +37,7 @@ pub struct TargetInfo { /// Extra flags to pass to `rustdoc`, see `env_args`. pub rustdocflags: Vec, pub supports_pipelining: Option, - pub supports_rustdoc_crate_type: bool + pub supports_rustdoc_crate_type: bool, } /// Kind of each file generated by a Unit, part of `FileType`. @@ -119,8 +121,7 @@ impl TargetInfo { // on rustdoc rides to stable. let mut crate_type_test = process_(config.rustdoc()?); crate_type_test.args(&["--crate-type", "proc-macro", "--help"]); - let supports_rustdoc_crate_type = crate_type_test.exec_with_output() - .is_ok(); + let supports_rustdoc_crate_type = crate_type_test.exec_with_output().is_ok(); let target_triple = requested_target .as_ref() @@ -212,7 +213,7 @@ impl TargetInfo { )?, cfg, supports_pipelining, - supports_rustdoc_crate_type + supports_rustdoc_crate_type, }) } diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index 4380b9244f5..b3b257163fc 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -73,7 +73,7 @@ pub struct Compilation<'cfg> { primary_unit_rustc_process: Option, target_runner: Option<(PathBuf, Vec)>, - supports_rustdoc_crate_type: bool + supports_rustdoc_crate_type: bool, } impl<'cfg> Compilation<'cfg> { @@ -110,7 +110,7 @@ impl<'cfg> Compilation<'cfg> { host: bcx.host_triple().to_string(), target: bcx.target_triple().to_string(), target_runner: target_runner(bcx)?, - supports_rustdoc_crate_type: bcx.target_info.supports_rustdoc_crate_type + supports_rustdoc_crate_type: bcx.target_info.supports_rustdoc_crate_type, }) } From 5d302e5a72aababa7d121fea7170092fff0bee43 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Mon, 26 Aug 2019 16:55:29 -0400 Subject: [PATCH 4/7] Cache outout of 'rustdoc --crate-type proc-macro --help' --- src/cargo/core/compiler/build_context/mod.rs | 5 +++-- .../compiler/build_context/target_info.rs | 12 +---------- src/cargo/core/compiler/compilation.rs | 20 +++++++++++++++---- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/cargo/core/compiler/build_context/mod.rs b/src/cargo/core/compiler/build_context/mod.rs index 9cb34e3390e..071f02c40ac 100644 --- a/src/cargo/core/compiler/build_context/mod.rs +++ b/src/cargo/core/compiler/build_context/mod.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use std::path::{Path, PathBuf}; use std::str; +use std::rc::Rc; use log::debug; @@ -33,7 +34,7 @@ pub struct BuildContext<'a, 'cfg> { pub packages: &'a PackageSet<'cfg>, /// Information about the compiler. - pub rustc: Rustc, + pub rustc: Rc, /// Build information for the host arch. pub host_config: TargetConfig, /// Build information for the target. @@ -53,7 +54,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> { units: &'a UnitInterner<'a>, extra_compiler_args: HashMap, Vec>, ) -> CargoResult> { - let rustc = config.load_global_rustc(Some(ws))?; + let rustc = Rc::new(config.load_global_rustc(Some(ws))?); let host_config = TargetConfig::new(config, &rustc.host)?; let target_config = match build_config.requested_target.as_ref() { diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index 7fedc7fc24b..b5b74fd9024 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -7,9 +7,7 @@ use std::str::{self, FromStr}; use crate::core::compiler::Kind; use crate::core::TargetKind; use crate::util::CfgExpr; -use crate::util::{ - process as process_, CargoResult, CargoResultExt, Cfg, Config, ProcessBuilder, Rustc, -}; +use crate::util::{CargoResult, CargoResultExt, Cfg, Config, ProcessBuilder, Rustc}; /// Information about the platform target gleaned from querying rustc. /// @@ -37,7 +35,6 @@ pub struct TargetInfo { /// Extra flags to pass to `rustdoc`, see `env_args`. pub rustdocflags: Vec, pub supports_pipelining: Option, - pub supports_rustdoc_crate_type: bool, } /// Kind of each file generated by a Unit, part of `FileType`. @@ -117,12 +114,6 @@ impl TargetInfo { Kind::Target => None, }; - // NOTE: set this unconditionally to 'true' once support for '--crate-type' - // on rustdoc rides to stable. - let mut crate_type_test = process_(config.rustdoc()?); - crate_type_test.args(&["--crate-type", "proc-macro", "--help"]); - let supports_rustdoc_crate_type = crate_type_test.exec_with_output().is_ok(); - let target_triple = requested_target .as_ref() .map(|s| s.as_str()) @@ -213,7 +204,6 @@ impl TargetInfo { )?, cfg, supports_pipelining, - supports_rustdoc_crate_type, }) } diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index b3b257163fc..0cab6cbf47f 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -2,12 +2,13 @@ use std::collections::{BTreeSet, HashMap, HashSet}; use std::env; use std::ffi::OsStr; use std::path::PathBuf; +use std::rc::Rc; use semver::Version; use super::BuildContext; use crate::core::{Edition, InternedString, Package, PackageId, Target}; -use crate::util::{self, join_paths, process, CargoResult, CfgExpr, Config, ProcessBuilder}; +use crate::util::{self, join_paths, process, CargoResult, CfgExpr, Config, ProcessBuilder, rustc::Rustc}; pub struct Doctest { /// The package being doc-tested. @@ -73,7 +74,7 @@ pub struct Compilation<'cfg> { primary_unit_rustc_process: Option, target_runner: Option<(PathBuf, Vec)>, - supports_rustdoc_crate_type: bool, + rustc: Rc } impl<'cfg> Compilation<'cfg> { @@ -110,7 +111,7 @@ impl<'cfg> Compilation<'cfg> { host: bcx.host_triple().to_string(), target: bcx.target_triple().to_string(), target_runner: target_runner(bcx)?, - supports_rustdoc_crate_type: bcx.target_info.supports_rustdoc_crate_type, + rustc: bcx.rustc.clone() }) } @@ -136,6 +137,17 @@ impl<'cfg> Compilation<'cfg> { Ok(p) } + fn supports_rustdoc_crate_type(&self) -> CargoResult { + // NOTE: Unconditionally return 'true' once support for + // rustdoc '--crate-type' rides to stable + let mut crate_type_test = process(self.config.rustdoc()?); + // If '--crate-type' is not supported by rustcoc, this command + // will exit with an error. Otherwise, it will print a help message, + // and exit successfully + crate_type_test.args(&["--crate-type", "proc-macro", "--help"]); + Ok(self.rustc.cached_output(&crate_type_test).is_ok()) + } + /// See `process`. pub fn rustdoc_process(&self, pkg: &Package, target: &Target) -> CargoResult { let mut p = self.fill_env(process(&*self.config.rustdoc()?), pkg, false)?; @@ -143,7 +155,7 @@ impl<'cfg> Compilation<'cfg> { p.arg(format!("--edition={}", target.edition())); } - if self.supports_rustdoc_crate_type { + if self.supports_rustdoc_crate_type()? { for crate_type in target.rustc_crate_types() { p.arg("--crate-type").arg(crate_type); } From 5bc05b40f01ab58b86dd0a6e08d3692ffbb17531 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Thu, 12 Sep 2019 13:38:10 -0400 Subject: [PATCH 5/7] Add tests --- tests/testsuite/build_script.rs | 4 +-- tests/testsuite/profile_targets.rs | 12 ++++---- tests/testsuite/rename_deps.rs | 2 +- tests/testsuite/rustdoc.rs | 47 +++++++++++++++++++++++++----- tests/testsuite/test.rs | 6 ++-- 5 files changed, 52 insertions(+), 19 deletions(-) diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index 04db56f9054..c4f39f3ff7a 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -813,7 +813,7 @@ fn testing_and_such() { [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] [RUNNING] `[..]/foo-[..][EXE]` [DOCTEST] foo -[RUNNING] `rustdoc --test [..]`", +[RUNNING] `rustdoc [..]--test [..]`", ) .with_stdout_contains_n("running 0 tests", 2) .run(); @@ -2747,7 +2747,7 @@ fn doctest_receives_build_link_args() { p.cargo("test -v") .with_stderr_contains( - "[RUNNING] `rustdoc --test [..] --crate-name foo [..]-L native=bar[..]`", + "[RUNNING] `rustdoc [..]--test [..] --crate-name foo [..]-L native=bar[..]`", ) .run(); } diff --git a/tests/testsuite/profile_targets.rs b/tests/testsuite/profile_targets.rs index 7a85f481401..718ec2fb211 100644 --- a/tests/testsuite/profile_targets.rs +++ b/tests/testsuite/profile_targets.rs @@ -306,7 +306,7 @@ fn profile_selection_test() { [RUNNING] `[..]/deps/foo-[..]` [RUNNING] `[..]/deps/test1-[..]` [DOCTEST] foo -[RUNNING] `rustdoc --test [..] +[RUNNING] `rustdoc [..]--test [..] ").run(); p.cargo("test -vv") .with_stderr_unordered( @@ -319,7 +319,7 @@ fn profile_selection_test() { [RUNNING] `[..]/deps/foo-[..]` [RUNNING] `[..]/deps/test1-[..]` [DOCTEST] foo -[RUNNING] `rustdoc --test [..] +[RUNNING] `rustdoc [..]--test [..] ", ) .run(); @@ -371,7 +371,7 @@ fn profile_selection_test_release() { [RUNNING] `[..]/deps/foo-[..]` [RUNNING] `[..]/deps/test1-[..]` [DOCTEST] foo -[RUNNING] `rustdoc --test [..]` +[RUNNING] `rustdoc [..]--test [..]` ").run(); p.cargo("test --release -vv") .with_stderr_unordered( @@ -384,7 +384,7 @@ fn profile_selection_test_release() { [RUNNING] `[..]/deps/foo-[..]` [RUNNING] `[..]/deps/test1-[..]` [DOCTEST] foo -[RUNNING] `rustdoc --test [..] +[RUNNING] `rustdoc [..]--test [..] ", ) .run(); @@ -633,7 +633,7 @@ fn profile_selection_doc() { [COMPILING] bar [..] [DOCUMENTING] bar [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=1 -C debuginfo=2 [..] -[RUNNING] `rustdoc --crate-name bar bar/src/lib.rs [..] +[RUNNING] `rustdoc [..]--crate-name bar bar/src/lib.rs [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]metadata -C panic=abort -C codegen-units=1 -C debuginfo=2 [..] [COMPILING] bdep [..] [RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=1 -C debuginfo=2 [..] @@ -642,7 +642,7 @@ fn profile_selection_doc() { [RUNNING] `[..]target/debug/build/foo-[..]/build-script-build` [foo 0.0.1] foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 [DOCUMENTING] foo [..] -[RUNNING] `rustdoc --crate-name foo src/lib.rs [..] +[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..] [FINISHED] dev [unoptimized + debuginfo] [..] ").run(); } diff --git a/tests/testsuite/rename_deps.rs b/tests/testsuite/rename_deps.rs index fc4858163f2..e94ac67eec7 100644 --- a/tests/testsuite/rename_deps.rs +++ b/tests/testsuite/rename_deps.rs @@ -263,7 +263,7 @@ fn can_run_doc_tests() { .with_stderr_contains( "\ [DOCTEST] foo -[RUNNING] `rustdoc --test [CWD]/src/lib.rs \ +[RUNNING] `rustdoc [..]--test [CWD]/src/lib.rs \ [..] \ --extern bar=[CWD]/target/debug/deps/libbar-[..].rlib \ --extern baz=[CWD]/target/debug/deps/libbar-[..].rlib \ diff --git a/tests/testsuite/rustdoc.rs b/tests/testsuite/rustdoc.rs index 195b47c0342..50e613eeb0b 100644 --- a/tests/testsuite/rustdoc.rs +++ b/tests/testsuite/rustdoc.rs @@ -1,4 +1,4 @@ -use crate::support::{basic_manifest, project}; +use crate::support::{basic_manifest, is_nightly, project}; #[cargo_test] fn rustdoc_simple() { @@ -8,7 +8,7 @@ fn rustdoc_simple() { .with_stderr( "\ [DOCUMENTING] foo v0.0.1 ([CWD]) -[RUNNING] `rustdoc --crate-name foo src/lib.rs [..]\ +[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..]\ -o [CWD]/target/doc \ [..] \ -L dependency=[CWD]/target/debug/deps` @@ -26,7 +26,7 @@ fn rustdoc_args() { .with_stderr( "\ [DOCUMENTING] foo v0.0.1 ([CWD]) -[RUNNING] `rustdoc --crate-name foo src/lib.rs [..]\ +[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..]\ -o [CWD]/target/doc \ [..] \ --cfg=foo \ @@ -66,7 +66,7 @@ fn rustdoc_foo_with_bar_dependency() { [CHECKING] bar v0.0.1 ([..]) [RUNNING] `rustc [..]bar/src/lib.rs [..]` [DOCUMENTING] foo v0.0.1 ([CWD]) -[RUNNING] `rustdoc --crate-name foo src/lib.rs [..]\ +[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..]\ -o [CWD]/target/doc \ [..] \ --cfg=foo \ @@ -105,7 +105,7 @@ fn rustdoc_only_bar_dependency() { .with_stderr( "\ [DOCUMENTING] bar v0.0.1 ([..]) -[RUNNING] `rustdoc --crate-name bar [..]bar/src/lib.rs [..]\ +[RUNNING] `rustdoc [..]--crate-name bar [..]bar/src/lib.rs [..]\ -o [CWD]/target/doc \ [..] \ --cfg=foo \ @@ -127,7 +127,7 @@ fn rustdoc_same_name_documents_lib() { .with_stderr( "\ [DOCUMENTING] foo v0.0.1 ([..]) -[RUNNING] `rustdoc --crate-name foo src/lib.rs [..]\ +[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..]\ -o [CWD]/target/doc \ [..] \ --cfg=foo \ @@ -161,6 +161,39 @@ fn features() { .run(); } +#[cargo_test] +fn proc_macro_crate_type() { + // NOTE - Remove this once 'rustdoc --crate-type' + // rides to stable + if !is_nightly() { + return; + } + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [lib] + proc-macro = true + + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("rustdoc --verbose") + .with_stderr_contains( + "\ +[RUNNING] `rustdoc --crate-type proc-macro [..]` +", + ) + .run(); +} + #[cargo_test] #[cfg(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))] fn rustdoc_target() { @@ -170,7 +203,7 @@ fn rustdoc_target() { .with_stderr( "\ [DOCUMENTING] foo v0.0.1 ([..]) -[RUNNING] `rustdoc --crate-name foo src/lib.rs [..]\ +[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..]\ --target x86_64-unknown-linux-gnu \ -o [CWD]/target/x86_64-unknown-linux-gnu/doc \ [..] \ diff --git a/tests/testsuite/test.rs b/tests/testsuite/test.rs index d9e73f8b0a4..bfb6e0e11c5 100644 --- a/tests/testsuite/test.rs +++ b/tests/testsuite/test.rs @@ -97,7 +97,7 @@ fn cargo_test_release() { [RUNNING] `[..]target/release/deps/foo-[..][EXE]` [RUNNING] `[..]target/release/deps/test-[..][EXE]` [DOCTEST] foo -[RUNNING] `rustdoc --test [..]lib.rs[..]`", +[RUNNING] `rustdoc [..]--test [..]lib.rs[..]`", ) .with_stdout_contains_n("test test ... ok", 2) .with_stdout_contains("running 0 tests") @@ -2702,7 +2702,7 @@ fn pass_correct_cfgs_flags_to_rustdoc() { .with_stderr_contains( "\ [DOCTEST] feature_a -[RUNNING] `rustdoc --test [..]mock_serde_codegen[..]`", +[RUNNING] `rustdoc [..]--test [..]mock_serde_codegen[..]`", ) .run(); @@ -2710,7 +2710,7 @@ fn pass_correct_cfgs_flags_to_rustdoc() { .with_stderr_contains( "\ [DOCTEST] foo -[RUNNING] `rustdoc --test [..]feature_a[..]`", +[RUNNING] `rustdoc [..]--test [..]feature_a[..]`", ) .run(); } From 60afaa77335ab464a5b6c913883ad145ae97d750 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Thu, 12 Sep 2019 13:47:13 -0400 Subject: [PATCH 6/7] Run 'cargo fmt' --- src/cargo/core/compiler/build_context/mod.rs | 2 +- src/cargo/core/compiler/compilation.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cargo/core/compiler/build_context/mod.rs b/src/cargo/core/compiler/build_context/mod.rs index 071f02c40ac..04dc112157f 100644 --- a/src/cargo/core/compiler/build_context/mod.rs +++ b/src/cargo/core/compiler/build_context/mod.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use std::path::{Path, PathBuf}; -use std::str; use std::rc::Rc; +use std::str; use log::debug; diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index 0cab6cbf47f..3613aad2fe6 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -8,7 +8,9 @@ use semver::Version; use super::BuildContext; use crate::core::{Edition, InternedString, Package, PackageId, Target}; -use crate::util::{self, join_paths, process, CargoResult, CfgExpr, Config, ProcessBuilder, rustc::Rustc}; +use crate::util::{ + self, join_paths, process, rustc::Rustc, CargoResult, CfgExpr, Config, ProcessBuilder, +}; pub struct Doctest { /// The package being doc-tested. @@ -74,7 +76,7 @@ pub struct Compilation<'cfg> { primary_unit_rustc_process: Option, target_runner: Option<(PathBuf, Vec)>, - rustc: Rc + rustc: Rc, } impl<'cfg> Compilation<'cfg> { @@ -111,7 +113,7 @@ impl<'cfg> Compilation<'cfg> { host: bcx.host_triple().to_string(), target: bcx.target_triple().to_string(), target_runner: target_runner(bcx)?, - rustc: bcx.rustc.clone() + rustc: bcx.rustc.clone(), }) } From b68e8542856a4a4d46a7fd74d9455ad62fe20a78 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Mon, 16 Sep 2019 14:08:14 -0400 Subject: [PATCH 7/7] Compute 'rustdoc --crate-type' support when Compilation is created --- src/cargo/core/compiler/build_context/mod.rs | 5 ++-- src/cargo/core/compiler/compilation.rs | 29 ++++++++++---------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/cargo/core/compiler/build_context/mod.rs b/src/cargo/core/compiler/build_context/mod.rs index 04dc112157f..9cb34e3390e 100644 --- a/src/cargo/core/compiler/build_context/mod.rs +++ b/src/cargo/core/compiler/build_context/mod.rs @@ -1,6 +1,5 @@ use std::collections::HashMap; use std::path::{Path, PathBuf}; -use std::rc::Rc; use std::str; use log::debug; @@ -34,7 +33,7 @@ pub struct BuildContext<'a, 'cfg> { pub packages: &'a PackageSet<'cfg>, /// Information about the compiler. - pub rustc: Rc, + pub rustc: Rustc, /// Build information for the host arch. pub host_config: TargetConfig, /// Build information for the target. @@ -54,7 +53,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> { units: &'a UnitInterner<'a>, extra_compiler_args: HashMap, Vec>, ) -> CargoResult> { - let rustc = Rc::new(config.load_global_rustc(Some(ws))?); + let rustc = config.load_global_rustc(Some(ws))?; let host_config = TargetConfig::new(config, &rustc.host)?; let target_config = match build_config.requested_target.as_ref() { diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index 3613aad2fe6..dcd2e1923bf 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -2,7 +2,6 @@ use std::collections::{BTreeSet, HashMap, HashSet}; use std::env; use std::ffi::OsStr; use std::path::PathBuf; -use std::rc::Rc; use semver::Version; @@ -76,7 +75,7 @@ pub struct Compilation<'cfg> { primary_unit_rustc_process: Option, target_runner: Option<(PathBuf, Vec)>, - rustc: Rc, + supports_rustdoc_crate_type: bool, } impl<'cfg> Compilation<'cfg> { @@ -113,7 +112,7 @@ impl<'cfg> Compilation<'cfg> { host: bcx.host_triple().to_string(), target: bcx.target_triple().to_string(), target_runner: target_runner(bcx)?, - rustc: bcx.rustc.clone(), + supports_rustdoc_crate_type: supports_rustdoc_crate_type(bcx.config, &bcx.rustc)?, }) } @@ -139,17 +138,6 @@ impl<'cfg> Compilation<'cfg> { Ok(p) } - fn supports_rustdoc_crate_type(&self) -> CargoResult { - // NOTE: Unconditionally return 'true' once support for - // rustdoc '--crate-type' rides to stable - let mut crate_type_test = process(self.config.rustdoc()?); - // If '--crate-type' is not supported by rustcoc, this command - // will exit with an error. Otherwise, it will print a help message, - // and exit successfully - crate_type_test.args(&["--crate-type", "proc-macro", "--help"]); - Ok(self.rustc.cached_output(&crate_type_test).is_ok()) - } - /// See `process`. pub fn rustdoc_process(&self, pkg: &Package, target: &Target) -> CargoResult { let mut p = self.fill_env(process(&*self.config.rustdoc()?), pkg, false)?; @@ -157,7 +145,7 @@ impl<'cfg> Compilation<'cfg> { p.arg(format!("--edition={}", target.edition())); } - if self.supports_rustdoc_crate_type()? { + if self.supports_rustdoc_crate_type { for crate_type in target.rustc_crate_types() { p.arg("--crate-type").arg(crate_type); } @@ -331,3 +319,14 @@ fn target_runner(bcx: &BuildContext<'_, '_>) -> CargoResult CargoResult { + // NOTE: Unconditionally return 'true' once support for + // rustdoc '--crate-type' rides to stable + let mut crate_type_test = process(config.rustdoc()?); + // If '--crate-type' is not supported by rustcoc, this command + // will exit with an error. Otherwise, it will print a help message, + // and exit successfully + crate_type_test.args(&["--crate-type", "proc-macro", "--help"]); + Ok(rustc.cached_output(&crate_type_test).is_ok()) +}