From 51355478f42c398e41a9b78bfcf93b00a93c7f1e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 25 Jul 2014 07:55:25 -0700 Subject: [PATCH] rustdoc: Add a --target flag Closes #13893 --- src/librustdoc/core.rs | 9 ++++++--- src/librustdoc/lib.rs | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 7f021510f4a..032189dca48 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -80,7 +80,8 @@ pub struct CrateAnalysis { pub type Externs = HashMap>; /// Parses, resolves, and typechecks the given crate -fn get_ast_and_resolve(cpath: &Path, libs: HashSet, cfgs: Vec, externs: Externs) +fn get_ast_and_resolve(cpath: &Path, libs: HashSet, cfgs: Vec, + externs: Externs, triple: Option) -> (DocContext, CrateAnalysis) { use syntax::codemap::dummy_spanned; use rustc::driver::driver::{FileInput, @@ -99,6 +100,7 @@ fn get_ast_and_resolve(cpath: &Path, libs: HashSet, cfgs: Vec, ext crate_types: vec!(driver::config::CrateTypeRlib), lint_opts: vec!((warning_lint, lint::Allow)), externs: externs, + target_triple: triple.unwrap_or(driver::driver::host_triple().to_string()), ..rustc::driver::config::basic_options().clone() }; @@ -151,9 +153,10 @@ fn get_ast_and_resolve(cpath: &Path, libs: HashSet, cfgs: Vec, ext }) } -pub fn run_core(libs: HashSet, cfgs: Vec, externs: Externs, path: &Path) +pub fn run_core(libs: HashSet, cfgs: Vec, externs: Externs, + path: &Path, triple: Option) -> (clean::Crate, CrateAnalysis) { - let (ctxt, analysis) = get_ast_and_resolve(path, libs, cfgs, externs); + let (ctxt, analysis) = get_ast_and_resolve(path, libs, cfgs, externs, triple); let ctxt = box(GC) ctxt; super::ctxtkey.replace(Some(ctxt)); diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 39b2511fde4..a89b7657287 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -117,6 +117,7 @@ pub fn opts() -> Vec { optflag("", "test", "run code examples as tests"), optmulti("", "test-args", "arguments to pass to the test runner", "ARGS"), + optopt("", "target", "target triple to document", "TRIPLE"), optmulti("", "markdown-css", "CSS files to include via in a rendered Markdown file", "FILES"), optmulti("", "html-in-header", @@ -321,6 +322,7 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche .map(|s| Path::new(s.as_slice())) .collect(); let cfgs = matches.opt_strs("cfg"); + let triple = matches.opt_str("target"); let cr = Path::new(cratefile); info!("starting to run rustc"); @@ -329,7 +331,8 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche core::run_core(libs.move_iter().collect(), cfgs, externs, - &cr) + &cr, + triple) }).map_err(|boxed_any|format!("{:?}", boxed_any)).unwrap(); info!("finished with rustc"); analysiskey.replace(Some(analysis));