Skip to content

Commit

Permalink
rustdoc: Add a --target flag
Browse files Browse the repository at this point in the history
Closes #13893
  • Loading branch information
alexcrichton committed Jul 25, 2014
1 parent 44019c7 commit 5135547
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/librustdoc/core.rs
Expand Up @@ -80,7 +80,8 @@ pub struct CrateAnalysis {
pub type Externs = HashMap<String, Vec<String>>;

/// 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) {
use syntax::codemap::dummy_spanned;
use rustc::driver::driver::{FileInput,
Expand All @@ -99,6 +100,7 @@ fn get_ast_and_resolve(cpath: &Path, libs: HashSet<Path>, cfgs: Vec<String>, 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()
};

Expand Down Expand Up @@ -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) {
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));

Expand Down
5 changes: 4 additions & 1 deletion src/librustdoc/lib.rs
Expand Up @@ -117,6 +117,7 @@ pub fn opts() -> Vec<getopts::OptGroup> {
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 <link> in a rendered Markdown file",
"FILES"),
optmulti("", "html-in-header",
Expand Down Expand Up @@ -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");
Expand All @@ -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));
Expand Down

0 comments on commit 5135547

Please sign in to comment.