rustdoc: Add a --target flag

Closes #13893
This commit is contained in:
Alex Crichton 2014-07-25 07:55:25 -07:00
parent 44019c79e0
commit 51355478f4
2 changed files with 10 additions and 4 deletions

View File

@ -80,7 +80,8 @@ pub struct CrateAnalysis {
pub type Externs = HashMap<String, Vec<String>>; pub type Externs = HashMap<String, Vec<String>>;
/// Parses, resolves, and typechecks the given crate /// Parses, resolves, and typechecks the given crate
fn get_ast_and_resolve(cpath: &Path, libs: HashSet<Path>, cfgs: Vec<String>, externs: Externs) fn get_ast_and_resolve(cpath: &Path, libs: HashSet<Path>, cfgs: Vec<String>,
externs: Externs, triple: Option<String>)
-> (DocContext, CrateAnalysis) { -> (DocContext, CrateAnalysis) {
use syntax::codemap::dummy_spanned; use syntax::codemap::dummy_spanned;
use rustc::driver::driver::{FileInput, use rustc::driver::driver::{FileInput,
@ -99,6 +100,7 @@ fn get_ast_and_resolve(cpath: &Path, libs: HashSet<Path>, cfgs: Vec<String>, ext
crate_types: vec!(driver::config::CrateTypeRlib), crate_types: vec!(driver::config::CrateTypeRlib),
lint_opts: vec!((warning_lint, lint::Allow)), lint_opts: vec!((warning_lint, lint::Allow)),
externs: externs, externs: externs,
target_triple: triple.unwrap_or(driver::driver::host_triple().to_string()),
..rustc::driver::config::basic_options().clone() ..rustc::driver::config::basic_options().clone()
}; };
@ -151,9 +153,10 @@ fn get_ast_and_resolve(cpath: &Path, libs: HashSet<Path>, cfgs: Vec<String>, ext
}) })
} }
pub fn run_core(libs: HashSet<Path>, cfgs: Vec<String>, externs: Externs, path: &Path) pub fn run_core(libs: HashSet<Path>, cfgs: Vec<String>, externs: Externs,
path: &Path, triple: Option<String>)
-> (clean::Crate, CrateAnalysis) { -> (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; let ctxt = box(GC) ctxt;
super::ctxtkey.replace(Some(ctxt)); super::ctxtkey.replace(Some(ctxt));

View File

@ -117,6 +117,7 @@ pub fn opts() -> Vec<getopts::OptGroup> {
optflag("", "test", "run code examples as tests"), optflag("", "test", "run code examples as tests"),
optmulti("", "test-args", "arguments to pass to the test runner", optmulti("", "test-args", "arguments to pass to the test runner",
"ARGS"), "ARGS"),
optopt("", "target", "target triple to document", "TRIPLE"),
optmulti("", "markdown-css", "CSS files to include via <link> in a rendered Markdown file", optmulti("", "markdown-css", "CSS files to include via <link> in a rendered Markdown file",
"FILES"), "FILES"),
optmulti("", "html-in-header", 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())) .map(|s| Path::new(s.as_slice()))
.collect(); .collect();
let cfgs = matches.opt_strs("cfg"); let cfgs = matches.opt_strs("cfg");
let triple = matches.opt_str("target");
let cr = Path::new(cratefile); let cr = Path::new(cratefile);
info!("starting to run rustc"); 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(), core::run_core(libs.move_iter().collect(),
cfgs, cfgs,
externs, externs,
&cr) &cr,
triple)
}).map_err(|boxed_any|format!("{:?}", boxed_any)).unwrap(); }).map_err(|boxed_any|format!("{:?}", boxed_any)).unwrap();
info!("finished with rustc"); info!("finished with rustc");
analysiskey.replace(Some(analysis)); analysiskey.replace(Some(analysis));