2013-02-28 07:15:32 -06:00
|
|
|
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
2012-12-03 18:48:01 -06:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-01-07 23:17:52 -06:00
|
|
|
/*!
|
|
|
|
|
|
|
|
The Rust compiler.
|
|
|
|
|
|
|
|
# Note
|
|
|
|
|
|
|
|
This API is completely unstable and subject to change.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2014-01-10 00:47:26 -06:00
|
|
|
#[crate_id = "rustc#0.10-pre"];
|
2012-01-23 18:25:15 -06:00
|
|
|
#[comment = "The Rust compiler"];
|
2013-03-01 10:41:31 -06:00
|
|
|
#[license = "MIT/ASL2"];
|
Add generation of static libraries to rustc
This commit implements the support necessary for generating both intermediate
and result static rust libraries. This is an implementation of my thoughts in
https://mail.mozilla.org/pipermail/rust-dev/2013-November/006686.html.
When compiling a library, we still retain the "lib" option, although now there
are "rlib", "staticlib", and "dylib" as options for crate_type (and these are
stackable). The idea of "lib" is to generate the "compiler default" instead of
having too choose (although all are interchangeable). For now I have left the
"complier default" to be a dynamic library for size reasons.
Of the rust libraries, lib{std,extra,rustuv} will bootstrap with an
rlib/dylib pair, but lib{rustc,syntax,rustdoc,rustpkg} will only be built as a
dynamic object. I chose this for size reasons, but also because you're probably
not going to be embedding the rustc compiler anywhere any time soon.
Other than the options outlined above, there are a few defaults/preferences that
are now opinionated in the compiler:
* If both a .dylib and .rlib are found for a rust library, the compiler will
prefer the .rlib variant. This is overridable via the -Z prefer-dynamic option
* If generating a "lib", the compiler will generate a dynamic library. This is
overridable by explicitly saying what flavor you'd like (rlib, staticlib,
dylib).
* If no options are passed to the command line, and no crate_type is found in
the destination crate, then an executable is generated
With this change, you can successfully build a rust program with 0 dynamic
dependencies on rust libraries. There is still a dynamic dependency on
librustrt, but I plan on removing that in a subsequent commit.
This change includes no tests just yet. Our current testing
infrastructure/harnesses aren't very amenable to doing flavorful things with
linking, so I'm planning on adding a new mode of testing which I believe belongs
as a separate commit.
Closes #552
2013-11-15 16:03:29 -06:00
|
|
|
#[crate_type = "dylib"];
|
2013-11-30 22:52:21 -06:00
|
|
|
#[crate_type = "rlib"];
|
2014-01-07 23:17:52 -06:00
|
|
|
#[doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
|
|
|
|
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
|
|
|
html_root_url = "http://static.rust-lang.org/doc/master")];
|
2011-05-05 21:44:00 -05:00
|
|
|
|
2013-10-23 03:49:18 -05:00
|
|
|
#[feature(macro_rules, globs, struct_variant, managed_boxes)];
|
2013-08-14 20:41:40 -05:00
|
|
|
|
2013-06-28 17:32:26 -05:00
|
|
|
extern mod extra;
|
2013-05-18 23:21:41 -05:00
|
|
|
extern mod syntax;
|
2013-03-26 21:53:33 -05:00
|
|
|
|
2013-12-19 14:23:39 -06:00
|
|
|
use back::link;
|
2013-03-26 21:53:33 -05:00
|
|
|
use driver::session;
|
|
|
|
use middle::lint;
|
|
|
|
|
2013-12-19 14:23:39 -06:00
|
|
|
use d = driver::driver;
|
|
|
|
|
2013-12-05 20:19:06 -06:00
|
|
|
use std::cast;
|
2013-08-29 20:34:09 -05:00
|
|
|
use std::comm;
|
2013-11-11 00:46:32 -06:00
|
|
|
use std::io;
|
|
|
|
use std::io::Reader;
|
Replaces the free-standing functions in f32, &c.
The free-standing functions in f32, f64, i8, i16, i32, i64, u8, u16,
u32, u64, float, int, and uint are replaced with generic functions in
num instead.
If you were previously using any of those functions, just replace them
with the corresponding function with the same name in num.
Note: If you were using a function that corresponds to an operator, use
the operator instead.
2013-07-08 11:05:17 -05:00
|
|
|
use std::num;
|
2013-06-28 17:32:26 -05:00
|
|
|
use std::os;
|
|
|
|
use std::result;
|
|
|
|
use std::str;
|
|
|
|
use std::task;
|
|
|
|
use std::vec;
|
2013-09-17 20:42:23 -05:00
|
|
|
use extra::getopts::groups;
|
2013-05-18 14:39:17 -05:00
|
|
|
use extra::getopts;
|
2013-12-19 14:23:39 -06:00
|
|
|
use syntax::ast;
|
|
|
|
use syntax::attr;
|
2013-03-26 21:53:33 -05:00
|
|
|
use syntax::codemap;
|
2013-08-29 20:34:09 -05:00
|
|
|
use syntax::diagnostic::Emitter;
|
2013-03-26 21:53:33 -05:00
|
|
|
use syntax::diagnostic;
|
2013-12-19 14:23:39 -06:00
|
|
|
use syntax::parse;
|
2013-03-26 21:53:33 -05:00
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod middle {
|
2013-06-12 18:18:58 -05:00
|
|
|
pub mod trans;
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod ty;
|
2013-10-29 05:03:32 -05:00
|
|
|
pub mod ty_fold;
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
pub mod subst;
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod resolve;
|
2013-10-29 05:03:32 -05:00
|
|
|
pub mod resolve_lifetime;
|
2012-11-28 14:33:00 -06:00
|
|
|
pub mod typeck;
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod check_loop;
|
|
|
|
pub mod check_match;
|
|
|
|
pub mod check_const;
|
|
|
|
pub mod lint;
|
2012-12-13 15:05:22 -06:00
|
|
|
pub mod borrowck;
|
2013-04-17 17:05:17 -05:00
|
|
|
pub mod dataflow;
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod mem_categorization;
|
|
|
|
pub mod liveness;
|
|
|
|
pub mod kind;
|
|
|
|
pub mod freevars;
|
|
|
|
pub mod pat_util;
|
|
|
|
pub mod region;
|
|
|
|
pub mod const_eval;
|
|
|
|
pub mod astencode;
|
|
|
|
pub mod lang_items;
|
|
|
|
pub mod privacy;
|
2013-01-10 12:59:58 -06:00
|
|
|
pub mod moves;
|
2013-04-29 16:56:05 -05:00
|
|
|
pub mod entry;
|
2013-05-23 21:12:16 -05:00
|
|
|
pub mod effect;
|
2013-06-14 20:21:47 -05:00
|
|
|
pub mod reachable;
|
2013-05-09 10:29:17 -05:00
|
|
|
pub mod graph;
|
2013-05-10 12:10:35 -05:00
|
|
|
pub mod cfg;
|
2013-12-08 01:55:27 -06:00
|
|
|
pub mod dead;
|
2011-04-19 18:40:46 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod front {
|
|
|
|
pub mod config;
|
|
|
|
pub mod test;
|
2013-05-17 15:12:42 -05:00
|
|
|
pub mod std_inject;
|
2014-01-06 06:00:46 -06:00
|
|
|
pub mod assign_node_ids_and_map;
|
2013-10-02 20:10:16 -05:00
|
|
|
pub mod feature_gate;
|
2010-06-23 23:03:09 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod back {
|
Add generation of static libraries to rustc
This commit implements the support necessary for generating both intermediate
and result static rust libraries. This is an implementation of my thoughts in
https://mail.mozilla.org/pipermail/rust-dev/2013-November/006686.html.
When compiling a library, we still retain the "lib" option, although now there
are "rlib", "staticlib", and "dylib" as options for crate_type (and these are
stackable). The idea of "lib" is to generate the "compiler default" instead of
having too choose (although all are interchangeable). For now I have left the
"complier default" to be a dynamic library for size reasons.
Of the rust libraries, lib{std,extra,rustuv} will bootstrap with an
rlib/dylib pair, but lib{rustc,syntax,rustdoc,rustpkg} will only be built as a
dynamic object. I chose this for size reasons, but also because you're probably
not going to be embedding the rustc compiler anywhere any time soon.
Other than the options outlined above, there are a few defaults/preferences that
are now opinionated in the compiler:
* If both a .dylib and .rlib are found for a rust library, the compiler will
prefer the .rlib variant. This is overridable via the -Z prefer-dynamic option
* If generating a "lib", the compiler will generate a dynamic library. This is
overridable by explicitly saying what flavor you'd like (rlib, staticlib,
dylib).
* If no options are passed to the command line, and no crate_type is found in
the destination crate, then an executable is generated
With this change, you can successfully build a rust program with 0 dynamic
dependencies on rust libraries. There is still a dynamic dependency on
librustrt, but I plan on removing that in a subsequent commit.
This change includes no tests just yet. Our current testing
infrastructure/harnesses aren't very amenable to doing flavorful things with
linking, so I'm planning on adding a new mode of testing which I believe belongs
as a separate commit.
Closes #552
2013-11-15 16:03:29 -06:00
|
|
|
pub mod archive;
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod link;
|
|
|
|
pub mod abi;
|
|
|
|
pub mod arm;
|
2013-01-29 08:28:08 -06:00
|
|
|
pub mod mips;
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod x86;
|
|
|
|
pub mod x86_64;
|
|
|
|
pub mod rpath;
|
|
|
|
pub mod target_strs;
|
Implement LTO
This commit implements LTO for rust leveraging LLVM's passes. What this means
is:
* When compiling an rlib, in addition to insdering foo.o into the archive, also
insert foo.bc (the LLVM bytecode) of the optimized module.
* When the compiler detects the -Z lto option, it will attempt to perform LTO on
a staticlib or binary output. The compiler will emit an error if a dylib or
rlib output is being generated.
* The actual act of performing LTO is as follows:
1. Force all upstream libraries to have an rlib version available.
2. Load the bytecode of each upstream library from the rlib.
3. Link all this bytecode into the current LLVM module (just using llvm
apis)
4. Run an internalization pass which internalizes all symbols except those
found reachable for the local crate of compilation.
5. Run the LLVM LTO pass manager over this entire module
6a. If assembling an archive, then add all upstream rlibs into the output
archive. This ignores all of the object/bitcode/metadata files rust
generated and placed inside the rlibs.
6b. If linking a binary, create copies of all upstream rlibs, remove the
rust-generated object-file, and then link everything as usual.
As I have explained in #10741, this process is excruciatingly slow, so this is
*not* turned on by default, and it is also why I have decided to hide it behind
a -Z flag for now. The good news is that the binary sizes are about as small as
they can be as a result of LTO, so it's definitely working.
Closes #10741
Closes #10740
2013-12-03 01:19:29 -06:00
|
|
|
pub mod lto;
|
2010-09-23 17:46:31 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod metadata;
|
2011-06-27 18:38:57 -05:00
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod driver;
|
2010-06-23 23:03:09 -05:00
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod util {
|
|
|
|
pub mod common;
|
|
|
|
pub mod ppaux;
|
2013-12-09 15:56:53 -06:00
|
|
|
pub mod sha2;
|
2010-08-18 13:34:47 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod lib {
|
|
|
|
pub mod llvm;
|
2013-11-30 22:52:21 -06:00
|
|
|
pub mod llvmdeps;
|
2010-07-12 19:47:40 -05:00
|
|
|
}
|
|
|
|
|
2013-05-24 21:35:29 -05:00
|
|
|
// A curious inner module that allows ::std::foo to be available in here for
|
|
|
|
// macros.
|
2013-06-28 17:32:26 -05:00
|
|
|
/*
|
2013-05-24 21:35:29 -05:00
|
|
|
mod std {
|
2013-07-02 14:47:32 -05:00
|
|
|
pub use std::clone;
|
2013-06-28 17:32:26 -05:00
|
|
|
pub use std::cmp;
|
|
|
|
pub use std::os;
|
|
|
|
pub use std::str;
|
|
|
|
pub use std::sys;
|
|
|
|
pub use std::to_bytes;
|
|
|
|
pub use std::unstable;
|
2013-05-24 21:35:29 -05:00
|
|
|
pub use extra::serialize;
|
|
|
|
}
|
2013-06-28 17:32:26 -05:00
|
|
|
*/
|
2013-05-24 21:35:29 -05:00
|
|
|
|
2013-08-06 23:50:23 -05:00
|
|
|
pub fn version(argv0: &str) {
|
|
|
|
let vers = match option_env!("CFG_VERSION") {
|
|
|
|
Some(vers) => vers,
|
|
|
|
None => "unknown version"
|
|
|
|
};
|
2013-09-25 00:16:43 -05:00
|
|
|
println!("{} {}", argv0, vers);
|
2013-12-19 14:23:39 -06:00
|
|
|
println!("host: {}", d::host_triple());
|
2013-08-06 23:50:23 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub fn usage(argv0: &str) {
|
2013-09-28 00:38:08 -05:00
|
|
|
let message = format!("Usage: {} [OPTIONS] INPUT", argv0);
|
2013-09-25 00:16:43 -05:00
|
|
|
println!("{}\n\
|
2013-06-21 18:08:37 -05:00
|
|
|
Additional help:
|
|
|
|
-W help Print 'lint' options and default settings
|
|
|
|
-Z help Print internal options for debugging rustc\n",
|
2013-12-19 14:23:39 -06:00
|
|
|
groups::usage(message, d::optgroups()));
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub fn describe_warnings() {
|
2014-01-09 04:06:55 -06:00
|
|
|
println!("
|
2012-11-28 14:33:00 -06:00
|
|
|
Available lint options:
|
|
|
|
-W <foo> Warn about <foo>
|
|
|
|
-A <foo> Allow <foo>
|
|
|
|
-D <foo> Deny <foo>
|
|
|
|
-F <foo> Forbid <foo> (deny, and deny all overrides)
|
2013-07-22 11:03:39 -05:00
|
|
|
");
|
2012-11-28 14:33:00 -06:00
|
|
|
|
|
|
|
let lint_dict = lint::get_lint_dict();
|
2013-08-07 21:21:36 -05:00
|
|
|
let mut lint_dict = lint_dict.move_iter()
|
2013-08-09 22:09:47 -05:00
|
|
|
.map(|(k, v)| (v, k))
|
2013-07-16 23:12:16 -05:00
|
|
|
.collect::<~[(lint::LintSpec, &'static str)]>();
|
2013-12-19 06:03:11 -06:00
|
|
|
lint_dict.sort();
|
2013-07-16 23:12:16 -05:00
|
|
|
|
2012-11-28 14:33:00 -06:00
|
|
|
let mut max_key = 0;
|
2013-08-03 11:45:23 -05:00
|
|
|
for &(_, name) in lint_dict.iter() {
|
2013-07-16 23:12:16 -05:00
|
|
|
max_key = num::max(name.len(), max_key);
|
|
|
|
}
|
2012-11-28 14:33:00 -06:00
|
|
|
fn padded(max: uint, s: &str) -> ~str {
|
2013-11-28 06:52:11 -06:00
|
|
|
" ".repeat(max - s.len()) + s
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
2014-01-09 04:06:55 -06:00
|
|
|
println!("{}", "\nAvailable lint checks:\n"); // FIXME: #9970
|
2013-09-25 00:16:43 -05:00
|
|
|
println!(" {} {:7.7s} {}",
|
|
|
|
padded(max_key, "name"), "default", "meaning");
|
|
|
|
println!(" {} {:7.7s} {}\n",
|
|
|
|
padded(max_key, "----"), "-------", "-------");
|
2013-08-07 21:21:36 -05:00
|
|
|
for (spec, name) in lint_dict.move_iter() {
|
2013-07-16 23:12:16 -05:00
|
|
|
let name = name.replace("_", "-");
|
2013-09-25 00:16:43 -05:00
|
|
|
println!(" {} {:7.7s} {}",
|
|
|
|
padded(max_key, name),
|
|
|
|
lint::level_to_str(spec.default),
|
|
|
|
spec.desc);
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
2014-01-09 04:06:55 -06:00
|
|
|
println!("");
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub fn describe_debug_flags() {
|
2014-01-09 04:06:55 -06:00
|
|
|
println!("{}", "\nAvailable debug options:\n"); // FIXME: #9970
|
2013-06-21 07:29:53 -05:00
|
|
|
let r = session::debugging_opts_map();
|
2013-08-03 11:45:23 -05:00
|
|
|
for tuple in r.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
match *tuple {
|
|
|
|
(ref name, ref desc, _) => {
|
2013-09-25 00:16:43 -05:00
|
|
|
println!(" -Z {:>20s} -- {}", *name, *desc);
|
2013-07-02 14:47:32 -05:00
|
|
|
}
|
|
|
|
}
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-29 20:34:09 -05:00
|
|
|
pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
|
2013-08-22 04:41:33 -05:00
|
|
|
let mut args = args.to_owned();
|
2013-12-26 23:48:35 -06:00
|
|
|
let binary = args.shift();
|
2012-11-28 14:33:00 -06:00
|
|
|
|
2013-06-12 12:02:55 -05:00
|
|
|
if args.is_empty() { usage(binary); return; }
|
2012-11-28 14:33:00 -06:00
|
|
|
|
|
|
|
let matches =
|
2013-12-19 14:23:39 -06:00
|
|
|
&match getopts::groups::getopts(args, d::optgroups()) {
|
2013-01-10 12:59:58 -06:00
|
|
|
Ok(m) => m,
|
|
|
|
Err(f) => {
|
2013-12-19 14:23:39 -06:00
|
|
|
d::early_error(demitter, f.to_err_msg());
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-17 20:42:23 -05:00
|
|
|
if matches.opt_present("h") || matches.opt_present("help") {
|
2013-06-12 12:02:55 -05:00
|
|
|
usage(binary);
|
2012-11-28 14:33:00 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-17 20:42:23 -05:00
|
|
|
let lint_flags = vec::append(matches.opt_strs("W"),
|
|
|
|
matches.opt_strs("warn"));
|
2014-01-15 11:31:48 -06:00
|
|
|
if lint_flags.iter().any(|x| x == &~"help") {
|
2012-11-28 14:33:00 -06:00
|
|
|
describe_warnings();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-17 20:42:23 -05:00
|
|
|
let r = matches.opt_strs("Z");
|
2013-07-04 21:13:26 -05:00
|
|
|
if r.iter().any(|x| x == &~"help") {
|
2012-11-28 14:33:00 -06:00
|
|
|
describe_debug_flags();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-17 20:42:23 -05:00
|
|
|
if matches.opt_str("passes") == Some(~"list") {
|
2013-08-22 22:58:42 -05:00
|
|
|
unsafe { lib::llvm::llvm::LLVMRustPrintPasses(); }
|
2013-05-29 03:08:20 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-17 20:42:23 -05:00
|
|
|
if matches.opt_present("v") || matches.opt_present("version") {
|
2013-06-12 12:02:55 -05:00
|
|
|
version(binary);
|
2012-11-28 14:33:00 -06:00
|
|
|
return;
|
|
|
|
}
|
2013-06-08 20:38:47 -05:00
|
|
|
let input = match matches.free.len() {
|
2013-12-19 14:23:39 -06:00
|
|
|
0u => d::early_error(demitter, "no input filename given"),
|
2012-11-28 14:33:00 -06:00
|
|
|
1u => {
|
2013-06-12 12:02:55 -05:00
|
|
|
let ifile = matches.free[0].as_slice();
|
|
|
|
if "-" == ifile {
|
2013-11-28 06:52:11 -06:00
|
|
|
let src = str::from_utf8_owned(io::stdin().read_to_end());
|
2014-01-13 10:31:05 -06:00
|
|
|
d::StrInput(src.to_managed())
|
2012-11-28 14:33:00 -06:00
|
|
|
} else {
|
2014-01-13 10:31:05 -06:00
|
|
|
d::FileInput(Path::new(ifile))
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
|
|
|
}
|
2013-12-19 14:23:39 -06:00
|
|
|
_ => d::early_error(demitter, "multiple input filenames provided")
|
2012-11-28 14:33:00 -06:00
|
|
|
};
|
|
|
|
|
2013-12-19 14:23:39 -06:00
|
|
|
let sopts = d::build_session_options(binary, matches, demitter);
|
|
|
|
let sess = d::build_session(sopts, demitter);
|
2013-12-03 21:15:12 -06:00
|
|
|
let odir = matches.opt_str("out-dir").map(|o| Path::new(o));
|
|
|
|
let ofile = matches.opt_str("o").map(|o| Path::new(o));
|
2013-12-19 14:23:39 -06:00
|
|
|
let cfg = d::build_configuration(sess);
|
2013-11-21 17:42:55 -06:00
|
|
|
let pretty = matches.opt_default("pretty", "normal").map(|a| {
|
2013-12-19 14:23:39 -06:00
|
|
|
d::parse_pretty(sess, a)
|
2013-11-21 17:42:55 -06:00
|
|
|
});
|
2012-11-28 14:33:00 -06:00
|
|
|
match pretty {
|
2013-12-19 14:23:39 -06:00
|
|
|
Some::<d::PpMode>(ppm) => {
|
|
|
|
d::pretty_print_input(sess, cfg, &input, ppm);
|
2012-11-28 14:33:00 -06:00
|
|
|
return;
|
|
|
|
}
|
2013-12-19 14:23:39 -06:00
|
|
|
None::<d::PpMode> => {/* continue */ }
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
2013-09-17 20:42:23 -05:00
|
|
|
let ls = matches.opt_present("ls");
|
2012-11-28 14:33:00 -06:00
|
|
|
if ls {
|
|
|
|
match input {
|
2014-01-13 10:31:05 -06:00
|
|
|
d::FileInput(ref ifile) => {
|
2013-12-21 17:24:10 -06:00
|
|
|
let mut stdout = io::stdout();
|
2013-12-19 14:23:39 -06:00
|
|
|
d::list_metadata(sess, &(*ifile),
|
2013-12-21 17:24:10 -06:00
|
|
|
&mut stdout as &mut io::Writer);
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
2014-01-13 10:31:05 -06:00
|
|
|
d::StrInput(_) => {
|
2013-12-19 14:23:39 -06:00
|
|
|
d::early_error(demitter, "can not list metadata for stdin");
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2013-12-19 14:23:39 -06:00
|
|
|
let (crate_id, crate_name, crate_file_name) = sopts.print_metas;
|
|
|
|
// these nasty nested conditions are to avoid doing extra work
|
|
|
|
if crate_id || crate_name || crate_file_name {
|
|
|
|
let attrs = parse_crate_attrs(sess, &input);
|
|
|
|
let t_outputs = d::build_output_filenames(&input, &odir, &ofile,
|
|
|
|
attrs, sess);
|
|
|
|
if crate_id || crate_name {
|
2013-12-27 18:14:01 -06:00
|
|
|
let crateid = match attr::find_crateid(attrs) {
|
|
|
|
Some(crateid) => crateid,
|
2013-12-19 14:23:39 -06:00
|
|
|
None => {
|
|
|
|
sess.fatal("No crate_id and --crate-id or \
|
|
|
|
--crate-name requested")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if crate_id {
|
2014-01-09 04:06:55 -06:00
|
|
|
println!("{}", crateid.to_str());
|
2013-12-19 14:23:39 -06:00
|
|
|
}
|
|
|
|
if crate_name {
|
2014-01-09 04:06:55 -06:00
|
|
|
println!("{}", crateid.name);
|
2013-12-19 14:23:39 -06:00
|
|
|
}
|
|
|
|
}
|
2012-11-28 14:33:00 -06:00
|
|
|
|
2013-12-19 14:23:39 -06:00
|
|
|
if crate_file_name {
|
|
|
|
let lm = link::build_link_meta(sess, attrs, &t_outputs.obj_filename,
|
|
|
|
&mut ::util::sha2::Sha256::new());
|
2014-01-01 15:26:07 -06:00
|
|
|
let outputs = session::collect_outputs(&sess, attrs);
|
2013-12-19 14:23:39 -06:00
|
|
|
for &style in outputs.iter() {
|
|
|
|
let fname = link::filename_for_input(&sess, style, &lm,
|
|
|
|
&t_outputs.out_filename);
|
|
|
|
println!("{}", fname.filename_display());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d::compile_input(sess, cfg, &input, &odir, &ofile);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parse_crate_attrs(sess: session::Session,
|
2014-01-13 10:31:05 -06:00
|
|
|
input: &d::Input) -> ~[ast::Attribute] {
|
2013-12-19 14:23:39 -06:00
|
|
|
match *input {
|
2014-01-13 10:31:05 -06:00
|
|
|
d::FileInput(ref ifile) => {
|
2013-12-19 14:23:39 -06:00
|
|
|
parse::parse_crate_attrs_from_file(ifile, ~[], sess.parse_sess)
|
|
|
|
}
|
2014-01-13 10:31:05 -06:00
|
|
|
d::StrInput(src) => {
|
2013-12-19 14:23:39 -06:00
|
|
|
parse::parse_crate_attrs_from_source_str(
|
|
|
|
d::anon_src(), src, ~[], sess.parse_sess)
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
|
|
|
|
2013-03-20 10:40:02 -05:00
|
|
|
#[deriving(Eq)]
|
2013-01-29 17:16:07 -06:00
|
|
|
pub enum monitor_msg {
|
2012-11-28 14:33:00 -06:00
|
|
|
fatal,
|
|
|
|
done,
|
|
|
|
}
|
|
|
|
|
2013-08-29 20:34:09 -05:00
|
|
|
struct RustcEmitter {
|
|
|
|
ch_capture: comm::SharedChan<monitor_msg>
|
|
|
|
}
|
|
|
|
|
|
|
|
impl diagnostic::Emitter for RustcEmitter {
|
|
|
|
fn emit(&self,
|
2014-01-01 00:23:41 -06:00
|
|
|
cmsp: Option<(&codemap::CodeMap, codemap::Span)>,
|
2013-08-29 20:34:09 -05:00
|
|
|
msg: &str,
|
2014-01-09 07:05:33 -06:00
|
|
|
lvl: diagnostic::Level) {
|
|
|
|
if lvl == diagnostic::Fatal {
|
2013-12-05 20:19:06 -06:00
|
|
|
let this = unsafe { cast::transmute_mut(self) };
|
|
|
|
this.ch_capture.send(fatal)
|
2013-08-29 20:34:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
diagnostic::DefaultEmitter.emit(cmsp, msg, lvl)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 14:33:00 -06:00
|
|
|
/*
|
|
|
|
This is a sanity check that any failure of the compiler is performed
|
|
|
|
through the diagnostic module and reported properly - we shouldn't be calling
|
|
|
|
plain-old-fail on any execution path that might be taken. Since we have
|
|
|
|
console logging off by default, hitting a plain fail statement would make the
|
|
|
|
compiler silently exit, which would be terrible.
|
|
|
|
|
|
|
|
This method wraps the compiler in a subtask and injects a function into the
|
|
|
|
diagnostic emitter which records when we hit a fatal error. If the task
|
|
|
|
fails without recording a fatal error then we've encountered a compiler
|
|
|
|
bug and need to present an error.
|
|
|
|
*/
|
2013-11-18 17:40:29 -06:00
|
|
|
pub fn monitor(f: proc(@diagnostic::Emitter)) {
|
2013-06-28 17:32:26 -05:00
|
|
|
use std::comm::*;
|
2013-08-05 15:10:34 -05:00
|
|
|
|
|
|
|
// XXX: This is a hack for newsched since it doesn't support split stacks.
|
2013-10-17 03:40:33 -05:00
|
|
|
// rustc needs a lot of stack! When optimizations are disabled, it needs
|
|
|
|
// even *more* stack than usual as well.
|
|
|
|
#[cfg(rtopt)]
|
|
|
|
static STACK_SIZE: uint = 6000000; // 6MB
|
|
|
|
#[cfg(not(rtopt))]
|
|
|
|
static STACK_SIZE: uint = 20000000; // 20MB
|
2013-08-05 15:10:34 -05:00
|
|
|
|
2013-12-05 20:19:06 -06:00
|
|
|
let (p, ch) = SharedChan::new();
|
2013-01-30 03:52:01 -06:00
|
|
|
let ch_capture = ch.clone();
|
2013-08-05 15:10:34 -05:00
|
|
|
let mut task_builder = task::task();
|
2013-10-31 22:08:17 -05:00
|
|
|
task_builder.name("rustc");
|
2013-08-09 19:28:27 -05:00
|
|
|
|
|
|
|
// XXX: Hacks on hacks. If the env is trying to override the stack size
|
|
|
|
// then *don't* set it explicitly.
|
|
|
|
if os::getenv("RUST_MIN_STACK").is_none() {
|
|
|
|
task_builder.opts.stack_size = Some(STACK_SIZE);
|
|
|
|
}
|
|
|
|
|
2013-11-22 01:36:52 -06:00
|
|
|
match task_builder.try(proc() {
|
2013-01-30 03:52:01 -06:00
|
|
|
let ch = ch_capture.clone();
|
2012-11-28 14:33:00 -06:00
|
|
|
// The 'diagnostics emitter'. Every error, warning, etc. should
|
|
|
|
// go through this function.
|
2013-08-29 20:34:09 -05:00
|
|
|
let demitter = @RustcEmitter {
|
|
|
|
ch_capture: ch.clone(),
|
|
|
|
} as @diagnostic::Emitter;
|
2012-11-28 14:33:00 -06:00
|
|
|
|
|
|
|
struct finally {
|
2013-01-30 03:52:01 -06:00
|
|
|
ch: SharedChan<monitor_msg>,
|
2013-02-27 18:13:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for finally {
|
2013-09-16 20:18:07 -05:00
|
|
|
fn drop(&mut self) { self.ch.send(done); }
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
let _finally = finally { ch: ch };
|
|
|
|
|
2013-07-13 01:26:23 -05:00
|
|
|
f(demitter);
|
2013-11-21 17:42:55 -06:00
|
|
|
}) {
|
2012-11-28 14:33:00 -06:00
|
|
|
result::Ok(_) => { /* fallthrough */ }
|
|
|
|
result::Err(_) => {
|
|
|
|
// Task failed without emitting a fatal diagnostic
|
2013-01-30 03:52:01 -06:00
|
|
|
if p.recv() == done {
|
2013-08-29 20:34:09 -05:00
|
|
|
diagnostic::DefaultEmitter.emit(
|
2012-11-28 14:33:00 -06:00
|
|
|
None,
|
2013-05-19 00:07:44 -05:00
|
|
|
diagnostic::ice_msg("unexpected failure"),
|
2014-01-09 07:05:33 -06:00
|
|
|
diagnostic::Error);
|
2012-11-28 14:33:00 -06:00
|
|
|
|
2013-06-21 07:29:53 -05:00
|
|
|
let xs = [
|
2012-11-28 14:33:00 -06:00
|
|
|
~"the compiler hit an unexpected failure path. \
|
|
|
|
this is a bug",
|
2013-08-15 00:27:03 -05:00
|
|
|
~"try running with RUST_LOG=rustc=1 \
|
2012-11-28 14:33:00 -06:00
|
|
|
to get further details and report the results \
|
|
|
|
to github.com/mozilla/rust/issues"
|
2013-06-21 07:29:53 -05:00
|
|
|
];
|
2013-08-03 11:45:23 -05:00
|
|
|
for note in xs.iter() {
|
2013-08-29 20:34:09 -05:00
|
|
|
diagnostic::DefaultEmitter.emit(None,
|
|
|
|
*note,
|
2014-01-09 07:05:33 -06:00
|
|
|
diagnostic::Note)
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Fail so the process returns a failure code
|
2013-10-21 15:08:31 -05:00
|
|
|
fail!();
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub fn main() {
|
2013-09-24 18:34:23 -05:00
|
|
|
std::os::set_exit_status(main_args(std::os::args()));
|
2013-08-22 04:41:33 -05:00
|
|
|
}
|
|
|
|
|
2013-09-24 18:34:23 -05:00
|
|
|
pub fn main_args(args: &[~str]) -> int {
|
2013-08-22 04:41:33 -05:00
|
|
|
let owned_args = args.to_owned();
|
2013-11-22 01:36:52 -06:00
|
|
|
monitor(proc(demitter) run_compiler(owned_args, demitter));
|
2013-11-21 17:42:55 -06:00
|
|
|
0
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|