2014-05-06 11:38:01 +00:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
//! Contains infrastructure for configuring the compiler, including parsing
|
|
|
|
//! command line options.
|
|
|
|
|
2014-11-06 08:05:53 +00:00
|
|
|
pub use self::EntryFnType::*;
|
|
|
|
pub use self::CrateType::*;
|
|
|
|
pub use self::Passes::*;
|
|
|
|
pub use self::DebugInfoLevel::*;
|
|
|
|
|
2015-01-02 07:53:35 +00:00
|
|
|
use session::{early_error, early_warn, Session};
|
2014-12-16 22:32:02 +00:00
|
|
|
use session::search_paths::SearchPaths;
|
2014-05-06 11:38:01 +00:00
|
|
|
|
2014-07-23 18:56:36 +00:00
|
|
|
use rustc_back::target::Target;
|
2014-06-01 22:58:06 +00:00
|
|
|
use lint;
|
2015-11-24 22:00:26 +00:00
|
|
|
use middle::cstore;
|
2014-05-06 11:38:01 +00:00
|
|
|
|
2015-09-14 09:58:20 +00:00
|
|
|
use syntax::ast::{self, IntTy, UintTy};
|
2014-05-06 11:38:01 +00:00
|
|
|
use syntax::attr;
|
|
|
|
use syntax::attr::AttrMetaMethods;
|
|
|
|
use syntax::parse;
|
|
|
|
use syntax::parse::token::InternedString;
|
2015-06-18 00:48:16 +00:00
|
|
|
use syntax::feature_gate::UnstableFeatures;
|
2014-05-06 11:38:01 +00:00
|
|
|
|
2016-07-30 11:06:49 +00:00
|
|
|
use errors::{ColorConfig, FatalError, Handler};
|
2016-06-21 22:08:13 +00:00
|
|
|
|
2015-01-30 08:44:27 +00:00
|
|
|
use getopts;
|
2014-08-31 17:07:27 +00:00
|
|
|
use std::collections::HashMap;
|
2015-02-03 00:40:52 +00:00
|
|
|
use std::env;
|
2014-06-11 07:48:17 +00:00
|
|
|
use std::fmt;
|
2015-02-27 05:00:43 +00:00
|
|
|
use std::path::PathBuf;
|
2014-05-06 11:38:01 +00:00
|
|
|
|
|
|
|
pub struct Config {
|
2014-07-23 18:56:36 +00:00
|
|
|
pub target: Target,
|
2014-05-06 11:38:01 +00:00
|
|
|
pub int_type: IntTy,
|
|
|
|
pub uint_type: UintTy,
|
|
|
|
}
|
|
|
|
|
2015-01-04 03:54:18 +00:00
|
|
|
#[derive(Clone, Copy, PartialEq)]
|
2014-05-06 11:38:01 +00:00
|
|
|
pub enum OptLevel {
|
|
|
|
No, // -O0
|
|
|
|
Less, // -O1
|
|
|
|
Default, // -O2
|
2016-03-27 19:42:47 +00:00
|
|
|
Aggressive, // -O3
|
|
|
|
Size, // -Os
|
|
|
|
SizeMin, // -Oz
|
2014-05-06 11:38:01 +00:00
|
|
|
}
|
|
|
|
|
2015-01-04 03:54:18 +00:00
|
|
|
#[derive(Clone, Copy, PartialEq)]
|
2014-05-06 11:38:01 +00:00
|
|
|
pub enum DebugInfoLevel {
|
|
|
|
NoDebugInfo,
|
|
|
|
LimitedDebugInfo,
|
|
|
|
FullDebugInfo,
|
|
|
|
}
|
|
|
|
|
2016-07-25 14:51:14 +00:00
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
|
2014-11-16 01:30:33 +00:00
|
|
|
pub enum OutputType {
|
2015-09-30 17:08:37 +00:00
|
|
|
Bitcode,
|
|
|
|
Assembly,
|
|
|
|
LlvmAssembly,
|
|
|
|
Object,
|
|
|
|
Exe,
|
|
|
|
DepInfo,
|
2014-11-16 01:30:33 +00:00
|
|
|
}
|
|
|
|
|
2015-12-31 03:50:06 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
|
|
pub enum ErrorOutputType {
|
2016-01-06 20:23:01 +00:00
|
|
|
HumanReadable(ColorConfig),
|
2015-12-31 03:50:06 +00:00
|
|
|
Json,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for ErrorOutputType {
|
|
|
|
fn default() -> ErrorOutputType {
|
2016-01-06 20:23:01 +00:00
|
|
|
ErrorOutputType::HumanReadable(ColorConfig::Auto)
|
2015-12-31 03:50:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-04 18:35:16 +00:00
|
|
|
impl OutputType {
|
|
|
|
fn is_compatible_with_codegen_units_and_single_output_file(&self) -> bool {
|
|
|
|
match *self {
|
|
|
|
OutputType::Exe |
|
|
|
|
OutputType::DepInfo => true,
|
|
|
|
OutputType::Bitcode |
|
|
|
|
OutputType::Assembly |
|
|
|
|
OutputType::LlvmAssembly |
|
|
|
|
OutputType::Object => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn shorthand(&self) -> &'static str {
|
|
|
|
match *self {
|
|
|
|
OutputType::Bitcode => "llvm-bc",
|
|
|
|
OutputType::Assembly => "asm",
|
|
|
|
OutputType::LlvmAssembly => "llvm-ir",
|
|
|
|
OutputType::Object => "obj",
|
|
|
|
OutputType::Exe => "link",
|
|
|
|
OutputType::DepInfo => "dep-info",
|
|
|
|
}
|
|
|
|
}
|
2016-07-25 14:51:14 +00:00
|
|
|
|
|
|
|
pub fn extension(&self) -> &'static str {
|
|
|
|
match *self {
|
|
|
|
OutputType::Bitcode => "bc",
|
|
|
|
OutputType::Assembly => "s",
|
|
|
|
OutputType::LlvmAssembly => "ll",
|
|
|
|
OutputType::Object => "o",
|
|
|
|
OutputType::DepInfo => "d",
|
|
|
|
OutputType::Exe => "",
|
|
|
|
}
|
|
|
|
}
|
2015-12-04 18:35:16 +00:00
|
|
|
}
|
|
|
|
|
2015-01-04 03:54:18 +00:00
|
|
|
#[derive(Clone)]
|
2014-05-06 11:38:01 +00:00
|
|
|
pub struct Options {
|
|
|
|
// The crate config requested for the session, which may be combined
|
|
|
|
// with additional crate configurations during the compile process
|
|
|
|
pub crate_types: Vec<CrateType>,
|
|
|
|
|
|
|
|
pub optimize: OptLevel,
|
2015-03-02 22:51:24 +00:00
|
|
|
pub debug_assertions: bool,
|
2014-05-06 11:38:01 +00:00
|
|
|
pub debuginfo: DebugInfoLevel,
|
2014-06-04 21:35:58 +00:00
|
|
|
pub lint_opts: Vec<(String, lint::Level)>,
|
2015-07-24 05:19:12 +00:00
|
|
|
pub lint_cap: Option<lint::Level>,
|
2014-06-04 21:35:58 +00:00
|
|
|
pub describe_lints: bool,
|
2015-09-30 17:08:37 +00:00
|
|
|
pub output_types: HashMap<OutputType, Option<PathBuf>>,
|
2014-05-06 11:38:01 +00:00
|
|
|
// This was mutable for rustpkg, which updates search paths based on the
|
|
|
|
// parsed code. It remains mutable in case its replacements wants to use
|
|
|
|
// this.
|
2014-12-16 22:32:02 +00:00
|
|
|
pub search_paths: SearchPaths,
|
librustc: Make `Copy` opt-in.
This change makes the compiler no longer infer whether types (structures
and enumerations) implement the `Copy` trait (and thus are implicitly
copyable). Rather, you must implement `Copy` yourself via `impl Copy for
MyType {}`.
A new warning has been added, `missing_copy_implementations`, to warn
you if a non-generic public type has been added that could have
implemented `Copy` but didn't.
For convenience, you may *temporarily* opt out of this behavior by using
`#![feature(opt_out_copy)]`. Note though that this feature gate will never be
accepted and will be removed by the time that 1.0 is released, so you should
transition your code away from using it.
This breaks code like:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
Change this code to:
#[deriving(Show)]
struct Point2D {
x: int,
y: int,
}
impl Copy for Point2D {}
fn main() {
let mypoint = Point2D {
x: 1,
y: 1,
};
let otherpoint = mypoint;
println!("{}{}", mypoint, otherpoint);
}
This is the backwards-incompatible part of #13231.
Part of RFC #3.
[breaking-change]
2014-12-06 01:01:33 +00:00
|
|
|
pub libs: Vec<(String, cstore::NativeLibraryKind)>,
|
2015-02-27 05:00:43 +00:00
|
|
|
pub maybe_sysroot: Option<PathBuf>,
|
2014-05-22 23:57:53 +00:00
|
|
|
pub target_triple: String,
|
2014-05-06 11:38:01 +00:00
|
|
|
// User-specified cfg meta items. The compiler itself will add additional
|
|
|
|
// items to the crate config, and during parsing the entire crate config
|
|
|
|
// will be added to the crate AST node. This should not be used for
|
|
|
|
// anything except building the full crate config prior to parsing.
|
|
|
|
pub cfg: ast::CrateConfig,
|
|
|
|
pub test: bool,
|
|
|
|
pub parse_only: bool,
|
|
|
|
pub no_trans: bool,
|
2016-01-06 20:23:01 +00:00
|
|
|
pub error_format: ErrorOutputType,
|
2015-02-18 16:02:06 +00:00
|
|
|
pub treat_err_as_bug: bool,
|
2016-03-25 17:17:04 +00:00
|
|
|
pub continue_parse_after_error: bool,
|
2016-02-07 20:46:39 +00:00
|
|
|
pub mir_opt_level: usize,
|
2016-01-29 20:07:04 +00:00
|
|
|
|
2016-03-28 21:43:36 +00:00
|
|
|
/// if Some, enable incremental compilation, using the given
|
|
|
|
/// directory to store intermediate results
|
|
|
|
pub incremental: Option<PathBuf>,
|
2016-01-29 20:07:04 +00:00
|
|
|
|
2014-05-06 11:38:01 +00:00
|
|
|
pub no_analysis: bool,
|
2014-12-09 09:55:49 +00:00
|
|
|
pub debugging_opts: DebuggingOptions,
|
2014-12-16 00:03:39 +00:00
|
|
|
pub prints: Vec<PrintRequest>,
|
2014-05-06 11:38:01 +00:00
|
|
|
pub cg: CodegenOptions,
|
2014-07-01 15:37:54 +00:00
|
|
|
pub externs: HashMap<String, Vec<String>>,
|
2014-07-02 00:07:06 +00:00
|
|
|
pub crate_name: Option<String>,
|
2014-07-20 23:32:46 +00:00
|
|
|
/// An optional name to use as the crate for std during std injection,
|
|
|
|
/// written `extern crate std = "name"`. Default to "std". Used by
|
|
|
|
/// out-of-tree drivers.
|
Preliminary feature staging
This partially implements the feature staging described in the
[release channel RFC][rc]. It does not yet fully conform to the RFC as
written, but does accomplish its goals sufficiently for the 1.0 alpha
release.
It has three primary user-visible effects:
* On the nightly channel, use of unstable APIs generates a warning.
* On the beta channel, use of unstable APIs generates a warning.
* On the beta channel, use of feature gates generates a warning.
Code that does not trigger these warnings is considered 'stable',
modulo pre-1.0 bugs.
Disabling the warnings for unstable APIs continues to be done in the
existing (i.e. old) style, via `#[allow(...)]`, not that specified in
the RFC. I deem this marginally acceptable since any code that must do
this is not using the stable dialect of Rust.
Use of feature gates is itself gated with the new 'unstable_features'
lint, on nightly set to 'allow', and on beta 'warn'.
The attribute scheme used here corresponds to an older version of the
RFC, with the `#[staged_api]` crate attribute toggling the staging
behavior of the stability attributes, but the user impact is only
in-tree so I'm not concerned about having to make design changes later
(and I may ultimately prefer the scheme here after all, with the
`#[staged_api]` crate attribute).
Since the Rust codebase itself makes use of unstable features the
compiler and build system to a midly elaborate dance to allow it to
bootstrap while disobeying these lints (which would otherwise be
errors because Rust builds with `-D warnings`).
This patch includes one significant hack that causes a
regression. Because the `format_args!` macro emits calls to unstable
APIs it would trigger the lint. I added a hack to the lint to make it
not trigger, but this in turn causes arguments to `println!` not to be
checked for feature gates. I don't presently understand macro
expansion well enough to fix. This is bug #20661.
Closes #16678
[rc]: https://github.com/rust-lang/rfcs/blob/master/text/0507-release-channels.md
2015-01-06 14:26:08 +00:00
|
|
|
pub alt_std_name: Option<String>,
|
|
|
|
/// Indicates how the compiler should treat unstable features
|
|
|
|
pub unstable_features: UnstableFeatures
|
|
|
|
}
|
|
|
|
|
2015-01-04 03:54:18 +00:00
|
|
|
#[derive(Clone, PartialEq, Eq)]
|
2014-12-16 00:03:39 +00:00
|
|
|
pub enum PrintRequest {
|
|
|
|
FileNames,
|
|
|
|
Sysroot,
|
|
|
|
CrateName,
|
2016-01-25 19:36:18 +00:00
|
|
|
Cfg,
|
2016-02-12 15:11:58 +00:00
|
|
|
TargetList,
|
2014-12-16 00:03:39 +00:00
|
|
|
}
|
|
|
|
|
2014-11-27 12:21:26 +00:00
|
|
|
pub enum Input {
|
|
|
|
/// Load source from file
|
2015-02-27 05:00:43 +00:00
|
|
|
File(PathBuf),
|
2016-03-10 03:49:40 +00:00
|
|
|
Str {
|
|
|
|
/// String that is shown in place of a filename
|
|
|
|
name: String,
|
|
|
|
/// Anonymous source string
|
|
|
|
input: String,
|
|
|
|
},
|
2014-11-27 12:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Input {
|
|
|
|
pub fn filestem(&self) -> String {
|
|
|
|
match *self {
|
2015-02-27 05:00:43 +00:00
|
|
|
Input::File(ref ifile) => ifile.file_stem().unwrap()
|
|
|
|
.to_str().unwrap().to_string(),
|
2016-03-10 03:49:40 +00:00
|
|
|
Input::Str { .. } => "rust_out".to_string(),
|
2014-11-27 12:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-04 03:54:18 +00:00
|
|
|
#[derive(Clone)]
|
2014-11-27 12:21:26 +00:00
|
|
|
pub struct OutputFilenames {
|
2015-02-27 05:00:43 +00:00
|
|
|
pub out_directory: PathBuf,
|
2014-11-27 12:21:26 +00:00
|
|
|
pub out_filestem: String,
|
2015-02-27 05:00:43 +00:00
|
|
|
pub single_output_file: Option<PathBuf>,
|
2014-11-27 12:21:26 +00:00
|
|
|
pub extra: String,
|
2015-09-30 17:08:37 +00:00
|
|
|
pub outputs: HashMap<OutputType, Option<PathBuf>>,
|
2014-11-27 12:21:26 +00:00
|
|
|
}
|
|
|
|
|
2016-05-14 00:48:32 +00:00
|
|
|
/// Codegen unit names generated by the numbered naming scheme will contain this
|
|
|
|
/// marker right before the index of the codegen unit.
|
|
|
|
pub const NUMBERED_CODEGEN_UNIT_MARKER: &'static str = ".cgu-";
|
|
|
|
|
2014-11-27 12:21:26 +00:00
|
|
|
impl OutputFilenames {
|
2015-02-27 05:00:43 +00:00
|
|
|
pub fn path(&self, flavor: OutputType) -> PathBuf {
|
2015-09-30 17:08:37 +00:00
|
|
|
self.outputs.get(&flavor).and_then(|p| p.to_owned())
|
|
|
|
.or_else(|| self.single_output_file.clone())
|
2016-05-14 00:48:32 +00:00
|
|
|
.unwrap_or_else(|| self.temp_path(flavor, None))
|
2014-11-27 12:21:26 +00:00
|
|
|
}
|
|
|
|
|
2016-05-14 00:48:32 +00:00
|
|
|
/// Get the path where a compilation artifact of the given type for the
|
|
|
|
/// given codegen unit should be placed on disk. If codegen_unit_name is
|
|
|
|
/// None, a path distinct from those of any codegen unit will be generated.
|
|
|
|
pub fn temp_path(&self,
|
|
|
|
flavor: OutputType,
|
|
|
|
codegen_unit_name: Option<&str>)
|
|
|
|
-> PathBuf {
|
2016-07-25 14:51:14 +00:00
|
|
|
let extension = flavor.extension();
|
2016-05-14 00:48:32 +00:00
|
|
|
self.temp_path_ext(extension, codegen_unit_name)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Like temp_path, but also supports things where there is no corresponding
|
|
|
|
/// OutputType, like no-opt-bitcode or lto-bitcode.
|
|
|
|
pub fn temp_path_ext(&self,
|
|
|
|
ext: &str,
|
|
|
|
codegen_unit_name: Option<&str>)
|
|
|
|
-> PathBuf {
|
2015-02-27 05:00:43 +00:00
|
|
|
let base = self.out_directory.join(&self.filestem());
|
2016-05-14 00:48:32 +00:00
|
|
|
|
|
|
|
let mut extension = String::new();
|
|
|
|
|
|
|
|
if let Some(codegen_unit_name) = codegen_unit_name {
|
|
|
|
if codegen_unit_name.contains(NUMBERED_CODEGEN_UNIT_MARKER) {
|
|
|
|
// If we use the numbered naming scheme for modules, we don't want
|
|
|
|
// the files to look like <crate-name><extra>.<crate-name>.<index>.<ext>
|
|
|
|
// but simply <crate-name><extra>.<index>.<ext>
|
|
|
|
let marker_offset = codegen_unit_name.rfind(NUMBERED_CODEGEN_UNIT_MARKER)
|
|
|
|
.unwrap();
|
|
|
|
let index_offset = marker_offset + NUMBERED_CODEGEN_UNIT_MARKER.len();
|
|
|
|
extension.push_str(&codegen_unit_name[index_offset .. ]);
|
|
|
|
} else {
|
|
|
|
extension.push_str(codegen_unit_name);
|
|
|
|
};
|
2014-11-27 12:21:26 +00:00
|
|
|
}
|
2016-05-14 00:48:32 +00:00
|
|
|
|
|
|
|
if !ext.is_empty() {
|
|
|
|
if !extension.is_empty() {
|
|
|
|
extension.push_str(".");
|
|
|
|
}
|
|
|
|
|
|
|
|
extension.push_str(ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
let path = base.with_extension(&extension[..]);
|
|
|
|
path
|
2014-11-27 12:21:26 +00:00
|
|
|
}
|
|
|
|
|
2015-02-27 05:00:43 +00:00
|
|
|
pub fn with_extension(&self, extension: &str) -> PathBuf {
|
|
|
|
self.out_directory.join(&self.filestem()).with_extension(extension)
|
2014-11-27 12:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn filestem(&self) -> String {
|
|
|
|
format!("{}{}", self.out_filestem, self.extra)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-16 01:30:33 +00:00
|
|
|
pub fn host_triple() -> &'static str {
|
|
|
|
// Get the host triple out of the build environment. This ensures that our
|
|
|
|
// idea of the host triple is the same as for the set of libraries we've
|
|
|
|
// actually built. We can't just take LLVM's host triple because they
|
|
|
|
// normalize all ix86 architectures to i386.
|
|
|
|
//
|
|
|
|
// Instead of grabbing the host triple (for the current host), we grab (at
|
|
|
|
// compile time) the target triple that this rustc is built with and
|
|
|
|
// calling that (at runtime) the host triple.
|
|
|
|
(option_env!("CFG_COMPILER_HOST_TRIPLE")).
|
|
|
|
expect("CFG_COMPILER_HOST_TRIPLE")
|
|
|
|
}
|
|
|
|
|
2014-05-06 11:38:01 +00:00
|
|
|
/// Some reasonable defaults
|
|
|
|
pub fn basic_options() -> Options {
|
|
|
|
Options {
|
|
|
|
crate_types: Vec::new(),
|
2015-12-31 03:50:06 +00:00
|
|
|
optimize: OptLevel::No,
|
2014-05-06 11:38:01 +00:00
|
|
|
debuginfo: NoDebugInfo,
|
|
|
|
lint_opts: Vec::new(),
|
2015-07-24 05:19:12 +00:00
|
|
|
lint_cap: None,
|
2014-06-04 21:35:58 +00:00
|
|
|
describe_lints: false,
|
2015-09-30 17:08:37 +00:00
|
|
|
output_types: HashMap::new(),
|
2014-12-16 22:32:02 +00:00
|
|
|
search_paths: SearchPaths::new(),
|
2014-05-06 11:38:01 +00:00
|
|
|
maybe_sysroot: None,
|
2014-11-16 01:30:33 +00:00
|
|
|
target_triple: host_triple().to_string(),
|
2014-05-06 11:38:01 +00:00
|
|
|
cfg: Vec::new(),
|
|
|
|
test: false,
|
|
|
|
parse_only: false,
|
|
|
|
no_trans: false,
|
2015-02-18 16:02:06 +00:00
|
|
|
treat_err_as_bug: false,
|
2016-03-25 17:17:04 +00:00
|
|
|
continue_parse_after_error: false,
|
2016-02-07 20:46:39 +00:00
|
|
|
mir_opt_level: 1,
|
2016-03-28 21:43:36 +00:00
|
|
|
incremental: None,
|
2014-05-06 11:38:01 +00:00
|
|
|
no_analysis: false,
|
2014-12-09 09:55:49 +00:00
|
|
|
debugging_opts: basic_debugging_options(),
|
2014-12-16 00:03:39 +00:00
|
|
|
prints: Vec::new(),
|
2014-05-06 11:38:01 +00:00
|
|
|
cg: basic_codegen_options(),
|
2016-01-06 20:23:01 +00:00
|
|
|
error_format: ErrorOutputType::default(),
|
2014-07-01 15:37:54 +00:00
|
|
|
externs: HashMap::new(),
|
2014-07-02 00:07:06 +00:00
|
|
|
crate_name: None,
|
2014-07-20 05:40:39 +00:00
|
|
|
alt_std_name: None,
|
2014-10-21 06:04:16 +00:00
|
|
|
libs: Vec::new(),
|
2015-03-02 22:51:24 +00:00
|
|
|
unstable_features: UnstableFeatures::Disallow,
|
|
|
|
debug_assertions: true,
|
2014-05-06 11:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-28 21:43:36 +00:00
|
|
|
impl Options {
|
|
|
|
/// True if there is a reason to build the dep graph.
|
|
|
|
pub fn build_dep_graph(&self) -> bool {
|
|
|
|
self.incremental.is_some() ||
|
|
|
|
self.debugging_opts.dump_dep_graph ||
|
|
|
|
self.debugging_opts.query_dep_graph
|
|
|
|
}
|
2016-07-13 21:03:02 +00:00
|
|
|
|
|
|
|
pub fn single_codegen_unit(&self) -> bool {
|
|
|
|
self.incremental.is_none() ||
|
|
|
|
self.cg.codegen_units == 1
|
|
|
|
}
|
2016-03-28 21:43:36 +00:00
|
|
|
}
|
|
|
|
|
2014-05-06 11:38:01 +00:00
|
|
|
// The type of entry function, so
|
|
|
|
// users can have their own entry
|
|
|
|
// functions that don't start a
|
|
|
|
// scheduler
|
2015-03-30 13:38:44 +00:00
|
|
|
#[derive(Copy, Clone, PartialEq)]
|
2014-05-06 11:38:01 +00:00
|
|
|
pub enum EntryFnType {
|
|
|
|
EntryMain,
|
|
|
|
EntryStart,
|
|
|
|
EntryNone,
|
|
|
|
}
|
|
|
|
|
2015-01-28 13:34:18 +00:00
|
|
|
#[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash, Debug)]
|
2014-05-06 11:38:01 +00:00
|
|
|
pub enum CrateType {
|
|
|
|
CrateTypeExecutable,
|
|
|
|
CrateTypeDylib,
|
|
|
|
CrateTypeRlib,
|
|
|
|
CrateTypeStaticlib,
|
2016-05-10 21:17:57 +00:00
|
|
|
CrateTypeCdylib,
|
2014-05-06 11:38:01 +00:00
|
|
|
}
|
|
|
|
|
2015-01-04 03:54:18 +00:00
|
|
|
#[derive(Clone)]
|
2014-09-12 15:17:58 +00:00
|
|
|
pub enum Passes {
|
2014-09-11 05:07:49 +00:00
|
|
|
SomePasses(Vec<String>),
|
2014-09-12 15:17:58 +00:00
|
|
|
AllPasses,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Passes {
|
|
|
|
pub fn is_empty(&self) -> bool {
|
|
|
|
match *self {
|
2014-09-11 05:07:49 +00:00
|
|
|
SomePasses(ref v) => v.is_empty(),
|
2014-09-12 15:17:58 +00:00
|
|
|
AllPasses => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-08 23:18:40 +00:00
|
|
|
#[derive(Clone, PartialEq)]
|
|
|
|
pub enum PanicStrategy {
|
|
|
|
Unwind,
|
|
|
|
Abort,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PanicStrategy {
|
|
|
|
pub fn desc(&self) -> &str {
|
|
|
|
match *self {
|
|
|
|
PanicStrategy::Unwind => "unwind",
|
|
|
|
PanicStrategy::Abort => "abort",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-09 09:44:01 +00:00
|
|
|
/// Declare a macro that will define all CodegenOptions/DebuggingOptions fields and parsers all
|
2014-05-06 11:38:01 +00:00
|
|
|
/// at once. The goal of this macro is to define an interface that can be
|
|
|
|
/// programmatically used by the option parser in order to initialize the struct
|
|
|
|
/// without hardcoding field names all over the place.
|
|
|
|
///
|
|
|
|
/// The goal is to invoke this macro once with the correct fields, and then this
|
|
|
|
/// macro generates all necessary code. The main gotcha of this macro is the
|
|
|
|
/// cgsetters module which is a bunch of generated code to parse an option into
|
|
|
|
/// its respective field in the struct. There are a few hand-written parsers for
|
|
|
|
/// parsing specific types of values in this module.
|
2014-12-09 09:44:01 +00:00
|
|
|
macro_rules! options {
|
|
|
|
($struct_name:ident, $setter_name:ident, $defaultfn:ident,
|
|
|
|
$buildfn:ident, $prefix:expr, $outputname:expr,
|
|
|
|
$stat:ident, $mod_desc:ident, $mod_set:ident,
|
|
|
|
$($opt:ident : $t:ty = ($init:expr, $parse:ident, $desc:expr)),* ,) =>
|
2014-05-06 11:38:01 +00:00
|
|
|
(
|
2015-01-04 03:54:18 +00:00
|
|
|
#[derive(Clone)]
|
2014-12-09 09:44:01 +00:00
|
|
|
pub struct $struct_name { $(pub $opt: $t),* }
|
2014-05-06 11:38:01 +00:00
|
|
|
|
2014-12-09 09:44:01 +00:00
|
|
|
pub fn $defaultfn() -> $struct_name {
|
|
|
|
$struct_name { $($opt: $init),* }
|
2014-05-06 11:38:01 +00:00
|
|
|
}
|
|
|
|
|
2016-01-06 20:23:01 +00:00
|
|
|
pub fn $buildfn(matches: &getopts::Matches, error_format: ErrorOutputType) -> $struct_name
|
2014-12-09 09:44:01 +00:00
|
|
|
{
|
|
|
|
let mut op = $defaultfn();
|
2015-02-01 01:03:04 +00:00
|
|
|
for option in matches.opt_strs($prefix) {
|
2015-04-01 18:28:34 +00:00
|
|
|
let mut iter = option.splitn(2, '=');
|
2014-12-09 09:44:01 +00:00
|
|
|
let key = iter.next().unwrap();
|
|
|
|
let value = iter.next();
|
|
|
|
let option_to_lookup = key.replace("-", "_");
|
|
|
|
let mut found = false;
|
2015-01-31 17:20:46 +00:00
|
|
|
for &(candidate, setter, opt_type_desc, _) in $stat {
|
2014-12-09 09:44:01 +00:00
|
|
|
if option_to_lookup != candidate { continue }
|
|
|
|
if !setter(&mut op, value) {
|
|
|
|
match (value, opt_type_desc) {
|
|
|
|
(Some(..), None) => {
|
2016-01-06 20:23:01 +00:00
|
|
|
early_error(error_format, &format!("{} option `{}` takes no \
|
|
|
|
value", $outputname, key))
|
2014-12-09 09:44:01 +00:00
|
|
|
}
|
|
|
|
(None, Some(type_desc)) => {
|
2016-01-06 20:23:01 +00:00
|
|
|
early_error(error_format, &format!("{0} option `{1}` requires \
|
|
|
|
{2} ({3} {1}=<value>)",
|
|
|
|
$outputname, key,
|
|
|
|
type_desc, $prefix))
|
2014-12-09 09:44:01 +00:00
|
|
|
}
|
|
|
|
(Some(value), Some(type_desc)) => {
|
2016-01-06 20:23:01 +00:00
|
|
|
early_error(error_format, &format!("incorrect value `{}` for {} \
|
|
|
|
option `{}` - {} was expected",
|
|
|
|
value, $outputname,
|
|
|
|
key, type_desc))
|
2014-12-09 09:44:01 +00:00
|
|
|
}
|
2016-03-25 17:46:11 +00:00
|
|
|
(None, None) => bug!()
|
2014-12-09 09:44:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if !found {
|
2016-01-06 20:23:01 +00:00
|
|
|
early_error(error_format, &format!("unknown {} option: `{}`",
|
|
|
|
$outputname, key));
|
2014-12-09 09:44:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return op;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type $setter_name = fn(&mut $struct_name, v: Option<&str>) -> bool;
|
|
|
|
pub const $stat: &'static [(&'static str, $setter_name,
|
2014-11-15 13:51:22 +00:00
|
|
|
Option<&'static str>, &'static str)] =
|
2014-12-09 09:44:01 +00:00
|
|
|
&[ $( (stringify!($opt), $mod_set::$opt, $mod_desc::$parse, $desc) ),* ];
|
2014-11-15 13:51:22 +00:00
|
|
|
|
2014-12-09 09:55:49 +00:00
|
|
|
#[allow(non_upper_case_globals, dead_code)]
|
2014-12-09 09:44:01 +00:00
|
|
|
mod $mod_desc {
|
2014-11-15 13:51:22 +00:00
|
|
|
pub const parse_bool: Option<&'static str> = None;
|
2015-01-09 05:06:45 +00:00
|
|
|
pub const parse_opt_bool: Option<&'static str> =
|
|
|
|
Some("one of: `y`, `yes`, `on`, `n`, `no`, or `off`");
|
2014-11-15 13:51:22 +00:00
|
|
|
pub const parse_string: Option<&'static str> = Some("a string");
|
|
|
|
pub const parse_opt_string: Option<&'static str> = Some("a string");
|
|
|
|
pub const parse_list: Option<&'static str> = Some("a space-separated list of strings");
|
|
|
|
pub const parse_opt_list: Option<&'static str> = Some("a space-separated list of strings");
|
|
|
|
pub const parse_uint: Option<&'static str> = Some("a number");
|
|
|
|
pub const parse_passes: Option<&'static str> =
|
|
|
|
Some("a space-separated list of passes, or `all`");
|
2014-12-16 00:03:39 +00:00
|
|
|
pub const parse_opt_uint: Option<&'static str> =
|
|
|
|
Some("a number");
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-08 23:18:40 +00:00
|
|
|
pub const parse_panic_strategy: Option<&'static str> =
|
|
|
|
Some("either `panic` or `abort`");
|
2014-11-15 13:51:22 +00:00
|
|
|
}
|
2014-05-06 11:38:01 +00:00
|
|
|
|
2014-12-09 09:55:49 +00:00
|
|
|
#[allow(dead_code)]
|
2014-12-09 09:44:01 +00:00
|
|
|
mod $mod_set {
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-08 23:18:40 +00:00
|
|
|
use super::{$struct_name, Passes, SomePasses, AllPasses, PanicStrategy};
|
2014-05-06 11:38:01 +00:00
|
|
|
|
|
|
|
$(
|
2014-12-09 09:44:01 +00:00
|
|
|
pub fn $opt(cg: &mut $struct_name, v: Option<&str>) -> bool {
|
2014-05-06 11:38:01 +00:00
|
|
|
$parse(&mut cg.$opt, v)
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
|
|
|
|
fn parse_bool(slot: &mut bool, v: Option<&str>) -> bool {
|
|
|
|
match v {
|
|
|
|
Some(..) => false,
|
|
|
|
None => { *slot = true; true }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-23 18:56:36 +00:00
|
|
|
fn parse_opt_bool(slot: &mut Option<bool>, v: Option<&str>) -> bool {
|
|
|
|
match v {
|
2015-01-09 05:06:45 +00:00
|
|
|
Some(s) => {
|
|
|
|
match s {
|
|
|
|
"n" | "no" | "off" => {
|
|
|
|
*slot = Some(false);
|
|
|
|
}
|
|
|
|
"y" | "yes" | "on" => {
|
|
|
|
*slot = Some(true);
|
|
|
|
}
|
|
|
|
_ => { return false; }
|
|
|
|
}
|
|
|
|
|
|
|
|
true
|
|
|
|
},
|
2014-07-23 18:56:36 +00:00
|
|
|
None => { *slot = Some(true); true }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 23:57:53 +00:00
|
|
|
fn parse_opt_string(slot: &mut Option<String>, v: Option<&str>) -> bool {
|
2014-05-06 11:38:01 +00:00
|
|
|
match v {
|
2014-05-25 10:17:19 +00:00
|
|
|
Some(s) => { *slot = Some(s.to_string()); true },
|
2014-05-06 11:38:01 +00:00
|
|
|
None => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 23:57:53 +00:00
|
|
|
fn parse_string(slot: &mut String, v: Option<&str>) -> bool {
|
2014-05-06 11:38:01 +00:00
|
|
|
match v {
|
2014-05-25 10:17:19 +00:00
|
|
|
Some(s) => { *slot = s.to_string(); true },
|
2014-05-06 11:38:01 +00:00
|
|
|
None => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 23:57:53 +00:00
|
|
|
fn parse_list(slot: &mut Vec<String>, v: Option<&str>)
|
2014-05-06 11:38:01 +00:00
|
|
|
-> bool {
|
|
|
|
match v {
|
|
|
|
Some(s) => {
|
2015-04-18 17:49:51 +00:00
|
|
|
for s in s.split_whitespace() {
|
2014-05-25 10:17:19 +00:00
|
|
|
slot.push(s.to_string());
|
2014-05-06 11:38:01 +00:00
|
|
|
}
|
|
|
|
true
|
|
|
|
},
|
|
|
|
None => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-23 18:56:36 +00:00
|
|
|
fn parse_opt_list(slot: &mut Option<Vec<String>>, v: Option<&str>)
|
|
|
|
-> bool {
|
|
|
|
match v {
|
|
|
|
Some(s) => {
|
2015-04-18 17:49:51 +00:00
|
|
|
let v = s.split_whitespace().map(|s| s.to_string()).collect();
|
2014-07-23 18:56:36 +00:00
|
|
|
*slot = Some(v);
|
|
|
|
true
|
|
|
|
},
|
|
|
|
None => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn parse_uint(slot: &mut usize, v: Option<&str>) -> bool {
|
2015-01-28 06:52:32 +00:00
|
|
|
match v.and_then(|s| s.parse().ok()) {
|
run optimization and codegen on worker threads
Refactor the code in `llvm::back` that invokes LLVM optimization and codegen
passes so that it can be called from worker threads. (Previously, it used
`&Session` extensively, and `Session` is not `Share`.) The new code can handle
multiple compilation units, by compiling each unit to `crate.0.o`, `crate.1.o`,
etc., and linking together all the `crate.N.o` files into a single `crate.o`
using `ld -r`. The later linking steps can then be run unchanged.
The new code preserves the behavior of `--emit`/`-o` when building a single
compilation unit. With multiple compilation units, the `--emit=asm/ir/bc`
options produce multiple files, so combinations like `--emit=ir -o foo.ll` will
not actually produce `foo.ll` (they instead produce several `foo.N.ll` files).
The new code supports `-Z lto` only when using a single compilation unit.
Compiling with multiple compilation units and `-Z lto` will produce an error.
(I can't think of any good reason to do such a thing.) Linking with `-Z lto`
against a library that was built as multiple compilation units will also fail,
because the rlib does not contain a `crate.bytecode.deflate` file. This could
be supported in the future by linking together the `crate.N.bc` files produced
when compiling the library into a single `crate.bc`, or by making the LTO code
support multiple `crate.N.bytecode.deflate` files.
2014-07-17 17:52:52 +00:00
|
|
|
Some(i) => { *slot = i; true },
|
|
|
|
None => false
|
|
|
|
}
|
|
|
|
}
|
2014-09-12 15:17:58 +00:00
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn parse_opt_uint(slot: &mut Option<usize>, v: Option<&str>) -> bool {
|
2014-12-16 00:03:39 +00:00
|
|
|
match v {
|
2015-01-28 06:52:32 +00:00
|
|
|
Some(s) => { *slot = s.parse().ok(); slot.is_some() }
|
2014-12-16 00:03:39 +00:00
|
|
|
None => { *slot = None; true }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-12 15:17:58 +00:00
|
|
|
fn parse_passes(slot: &mut Passes, v: Option<&str>) -> bool {
|
|
|
|
match v {
|
|
|
|
Some("all") => {
|
|
|
|
*slot = AllPasses;
|
|
|
|
true
|
|
|
|
}
|
|
|
|
v => {
|
|
|
|
let mut passes = vec!();
|
|
|
|
if parse_list(&mut passes, v) {
|
2014-09-11 05:07:49 +00:00
|
|
|
*slot = SomePasses(passes);
|
2014-09-12 15:17:58 +00:00
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-08 23:18:40 +00:00
|
|
|
|
|
|
|
fn parse_panic_strategy(slot: &mut PanicStrategy, v: Option<&str>) -> bool {
|
|
|
|
match v {
|
|
|
|
Some("unwind") => *slot = PanicStrategy::Unwind,
|
|
|
|
Some("abort") => *slot = PanicStrategy::Abort,
|
|
|
|
_ => return false
|
|
|
|
}
|
|
|
|
true
|
|
|
|
}
|
2014-05-06 11:38:01 +00:00
|
|
|
}
|
2014-11-14 17:18:10 +00:00
|
|
|
) }
|
2014-05-06 11:38:01 +00:00
|
|
|
|
2014-12-09 09:44:01 +00:00
|
|
|
options! {CodegenOptions, CodegenSetter, basic_codegen_options,
|
|
|
|
build_codegen_options, "C", "codegen",
|
|
|
|
CG_OPTIONS, cg_type_desc, cgsetters,
|
2014-05-22 23:57:53 +00:00
|
|
|
ar: Option<String> = (None, parse_opt_string,
|
2014-05-06 11:38:01 +00:00
|
|
|
"tool to assemble archives with"),
|
2014-05-22 23:57:53 +00:00
|
|
|
linker: Option<String> = (None, parse_opt_string,
|
2014-05-06 11:38:01 +00:00
|
|
|
"system linker to link outputs with"),
|
2014-07-23 18:56:36 +00:00
|
|
|
link_args: Option<Vec<String>> = (None, parse_opt_list,
|
2014-05-06 11:38:01 +00:00
|
|
|
"extra arguments to pass to the linker (space separated)"),
|
2016-02-02 17:56:59 +00:00
|
|
|
link_dead_code: bool = (false, parse_bool,
|
2016-02-15 16:44:06 +00:00
|
|
|
"don't let linker strip dead code (turning it on can be used for code coverage)"),
|
2014-09-21 04:36:17 +00:00
|
|
|
lto: bool = (false, parse_bool,
|
|
|
|
"perform LLVM link-time optimizations"),
|
2014-07-23 18:56:36 +00:00
|
|
|
target_cpu: Option<String> = (None, parse_opt_string,
|
2014-05-06 11:38:01 +00:00
|
|
|
"select target processor (llc -mcpu=help for details)"),
|
2014-05-25 10:17:19 +00:00
|
|
|
target_feature: String = ("".to_string(), parse_string,
|
2014-05-06 11:38:01 +00:00
|
|
|
"target specific attributes (llc -mattr=help for details)"),
|
2014-05-22 23:57:53 +00:00
|
|
|
passes: Vec<String> = (Vec::new(), parse_list,
|
2014-05-06 11:38:01 +00:00
|
|
|
"a list of extra LLVM passes to run (space separated)"),
|
2014-05-22 23:57:53 +00:00
|
|
|
llvm_args: Vec<String> = (Vec::new(), parse_list,
|
2014-05-06 11:38:01 +00:00
|
|
|
"a list of arguments to pass to llvm (space separated)"),
|
|
|
|
save_temps: bool = (false, parse_bool,
|
|
|
|
"save all temporary output files during compilation"),
|
2014-06-11 21:52:38 +00:00
|
|
|
rpath: bool = (false, parse_bool,
|
|
|
|
"set rpath values in libs/exes"),
|
2014-05-06 11:38:01 +00:00
|
|
|
no_prepopulate_passes: bool = (false, parse_bool,
|
|
|
|
"don't pre-populate the pass manager with a list of passes"),
|
|
|
|
no_vectorize_loops: bool = (false, parse_bool,
|
|
|
|
"don't run the loop vectorization optimization passes"),
|
|
|
|
no_vectorize_slp: bool = (false, parse_bool,
|
|
|
|
"don't run LLVM's SLP vectorization pass"),
|
|
|
|
soft_float: bool = (false, parse_bool,
|
|
|
|
"generate software floating point library calls"),
|
|
|
|
prefer_dynamic: bool = (false, parse_bool,
|
|
|
|
"prefer dynamic linking to static linking"),
|
|
|
|
no_integrated_as: bool = (false, parse_bool,
|
|
|
|
"use an external assembler rather than LLVM's integrated one"),
|
2014-07-23 18:56:36 +00:00
|
|
|
no_redzone: Option<bool> = (None, parse_opt_bool,
|
2014-07-16 11:35:50 +00:00
|
|
|
"disable the use of the redzone"),
|
2014-07-23 18:56:36 +00:00
|
|
|
relocation_model: Option<String> = (None, parse_opt_string,
|
2014-05-06 11:38:01 +00:00
|
|
|
"choose the relocation model to use (llc -relocation-model for details)"),
|
2014-07-23 18:56:36 +00:00
|
|
|
code_model: Option<String> = (None, parse_opt_string,
|
2014-07-15 23:14:02 +00:00
|
|
|
"choose the code model to use (llc -code-model for details)"),
|
2014-07-01 05:52:48 +00:00
|
|
|
metadata: Vec<String> = (Vec::new(), parse_list,
|
|
|
|
"metadata to mangle symbol names with"),
|
2014-07-01 14:57:07 +00:00
|
|
|
extra_filename: String = ("".to_string(), parse_string,
|
|
|
|
"extra data to put in each output filename"),
|
2015-03-26 00:06:52 +00:00
|
|
|
codegen_units: usize = (1, parse_uint,
|
run optimization and codegen on worker threads
Refactor the code in `llvm::back` that invokes LLVM optimization and codegen
passes so that it can be called from worker threads. (Previously, it used
`&Session` extensively, and `Session` is not `Share`.) The new code can handle
multiple compilation units, by compiling each unit to `crate.0.o`, `crate.1.o`,
etc., and linking together all the `crate.N.o` files into a single `crate.o`
using `ld -r`. The later linking steps can then be run unchanged.
The new code preserves the behavior of `--emit`/`-o` when building a single
compilation unit. With multiple compilation units, the `--emit=asm/ir/bc`
options produce multiple files, so combinations like `--emit=ir -o foo.ll` will
not actually produce `foo.ll` (they instead produce several `foo.N.ll` files).
The new code supports `-Z lto` only when using a single compilation unit.
Compiling with multiple compilation units and `-Z lto` will produce an error.
(I can't think of any good reason to do such a thing.) Linking with `-Z lto`
against a library that was built as multiple compilation units will also fail,
because the rlib does not contain a `crate.bytecode.deflate` file. This could
be supported in the future by linking together the `crate.N.bc` files produced
when compiling the library into a single `crate.bc`, or by making the LTO code
support multiple `crate.N.bytecode.deflate` files.
2014-07-17 17:52:52 +00:00
|
|
|
"divide crate into N units to optimize in parallel"),
|
2014-09-11 05:07:49 +00:00
|
|
|
remark: Passes = (SomePasses(Vec::new()), parse_passes,
|
2014-09-12 15:17:58 +00:00
|
|
|
"print remarks for these optimization passes (space separated, or \"all\")"),
|
2014-09-06 00:56:59 +00:00
|
|
|
no_stack_check: bool = (false, parse_bool,
|
|
|
|
"disable checks for stack exhaustion (a memory-safety hazard!)"),
|
2015-03-26 00:06:52 +00:00
|
|
|
debuginfo: Option<usize> = (None, parse_opt_uint,
|
2014-12-16 00:03:39 +00:00
|
|
|
"debug info emission level, 0 = no debug info, 1 = line tables only, \
|
|
|
|
2 = full debug info with variable and type information"),
|
2016-03-27 19:42:47 +00:00
|
|
|
opt_level: Option<String> = (None, parse_opt_string,
|
|
|
|
"optimize with possible levels 0-3, s, or z"),
|
2015-03-02 22:51:24 +00:00
|
|
|
debug_assertions: Option<bool> = (None, parse_opt_bool,
|
|
|
|
"explicitly enable the cfg(debug_assertions) directive"),
|
2015-11-20 00:07:09 +00:00
|
|
|
inline_threshold: Option<usize> = (None, parse_opt_uint,
|
|
|
|
"set the inlining threshold for"),
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-08 23:18:40 +00:00
|
|
|
panic: PanicStrategy = (PanicStrategy::Unwind, parse_panic_strategy,
|
|
|
|
"panic strategy to compile crate with"),
|
2014-11-14 17:18:10 +00:00
|
|
|
}
|
2014-05-06 11:38:01 +00:00
|
|
|
|
2014-12-09 09:55:49 +00:00
|
|
|
options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
|
|
|
|
build_debugging_options, "Z", "debugging",
|
|
|
|
DB_OPTIONS, db_type_desc, dbsetters,
|
|
|
|
verbose: bool = (false, parse_bool,
|
|
|
|
"in general, enable more debug printouts"),
|
|
|
|
time_passes: bool = (false, parse_bool,
|
|
|
|
"measure time of each rustc pass"),
|
|
|
|
count_llvm_insns: bool = (false, parse_bool,
|
|
|
|
"count where LLVM instrs originate"),
|
|
|
|
time_llvm_passes: bool = (false, parse_bool,
|
|
|
|
"measure time of each LLVM pass"),
|
2015-11-11 05:26:14 +00:00
|
|
|
input_stats: bool = (false, parse_bool,
|
|
|
|
"gather statistics about the input"),
|
2014-12-09 09:55:49 +00:00
|
|
|
trans_stats: bool = (false, parse_bool,
|
|
|
|
"gather trans statistics"),
|
|
|
|
asm_comments: bool = (false, parse_bool,
|
|
|
|
"generate comments into the assembly (may change behavior)"),
|
|
|
|
no_verify: bool = (false, parse_bool,
|
|
|
|
"skip LLVM verification"),
|
|
|
|
borrowck_stats: bool = (false, parse_bool,
|
|
|
|
"gather borrowck statistics"),
|
|
|
|
no_landing_pads: bool = (false, parse_bool,
|
|
|
|
"omit landing pads for unwinding"),
|
|
|
|
debug_llvm: bool = (false, parse_bool,
|
|
|
|
"enable debug output from LLVM"),
|
|
|
|
meta_stats: bool = (false, parse_bool,
|
|
|
|
"gather metadata statistics"),
|
|
|
|
print_link_args: bool = (false, parse_bool,
|
2015-11-11 05:26:14 +00:00
|
|
|
"print the arguments passed to the linker"),
|
2014-12-09 09:55:49 +00:00
|
|
|
print_llvm_passes: bool = (false, parse_bool,
|
2015-11-11 05:26:14 +00:00
|
|
|
"prints the llvm optimization passes being run"),
|
2014-12-09 09:55:49 +00:00
|
|
|
ast_json: bool = (false, parse_bool,
|
2015-11-11 05:26:14 +00:00
|
|
|
"print the AST as JSON and halt"),
|
2014-12-09 09:55:49 +00:00
|
|
|
ast_json_noexpand: bool = (false, parse_bool,
|
2015-11-11 05:26:14 +00:00
|
|
|
"print the pre-expansion AST as JSON and halt"),
|
2014-12-09 09:55:49 +00:00
|
|
|
ls: bool = (false, parse_bool,
|
2015-11-11 05:26:14 +00:00
|
|
|
"list the symbols defined by a library crate"),
|
2014-12-09 09:55:49 +00:00
|
|
|
save_analysis: bool = (false, parse_bool,
|
2016-04-25 22:14:44 +00:00
|
|
|
"write syntax and type analysis (in JSON format) information in addition to normal output"),
|
|
|
|
save_analysis_csv: bool = (false, parse_bool,
|
|
|
|
"write syntax and type analysis (in CSV format) information in addition to normal output"),
|
2014-12-09 09:55:49 +00:00
|
|
|
print_move_fragments: bool = (false, parse_bool,
|
2015-11-11 05:26:14 +00:00
|
|
|
"print out move-fragment data for every fn"),
|
2014-12-09 09:55:49 +00:00
|
|
|
flowgraph_print_loans: bool = (false, parse_bool,
|
2015-11-11 05:26:14 +00:00
|
|
|
"include loan analysis data in --unpretty flowgraph output"),
|
2014-12-09 09:55:49 +00:00
|
|
|
flowgraph_print_moves: bool = (false, parse_bool,
|
2015-11-11 05:26:14 +00:00
|
|
|
"include move analysis data in --unpretty flowgraph output"),
|
2014-12-09 09:55:49 +00:00
|
|
|
flowgraph_print_assigns: bool = (false, parse_bool,
|
2015-11-11 05:26:14 +00:00
|
|
|
"include assignment analysis data in --unpretty flowgraph output"),
|
2014-12-09 09:55:49 +00:00
|
|
|
flowgraph_print_all: bool = (false, parse_bool,
|
2015-11-11 05:26:14 +00:00
|
|
|
"include all dataflow analysis data in --unpretty flowgraph output"),
|
2014-12-09 09:55:49 +00:00
|
|
|
print_region_graph: bool = (false, parse_bool,
|
2015-11-11 05:26:14 +00:00
|
|
|
"prints region inference graph. \
|
2014-12-09 09:55:49 +00:00
|
|
|
Use with RUST_REGION_GRAPH=help for more info"),
|
|
|
|
parse_only: bool = (false, parse_bool,
|
2015-11-11 05:26:14 +00:00
|
|
|
"parse only; do not compile, assemble, or link"),
|
2014-12-09 09:55:49 +00:00
|
|
|
no_trans: bool = (false, parse_bool,
|
2015-11-11 05:26:14 +00:00
|
|
|
"run all passes except translation; no output"),
|
2015-02-18 16:02:06 +00:00
|
|
|
treat_err_as_bug: bool = (false, parse_bool,
|
2015-11-11 05:26:14 +00:00
|
|
|
"treat all errors that occur as bugs"),
|
2016-03-25 17:17:04 +00:00
|
|
|
continue_parse_after_error: bool = (false, parse_bool,
|
|
|
|
"attempt to recover from parse errors (experimental)"),
|
2016-03-28 21:43:36 +00:00
|
|
|
incremental: Option<String> = (None, parse_opt_string,
|
2015-12-22 21:35:02 +00:00
|
|
|
"enable incremental compilation (experimental)"),
|
|
|
|
dump_dep_graph: bool = (false, parse_bool,
|
|
|
|
"dump the dependency graph to $RUST_DEP_GRAPH (default: /tmp/dep_graph.gv)"),
|
2016-03-28 21:43:36 +00:00
|
|
|
query_dep_graph: bool = (false, parse_bool,
|
|
|
|
"enable queries of the dependency graph for regression testing"),
|
2014-12-09 09:55:49 +00:00
|
|
|
no_analysis: bool = (false, parse_bool,
|
2015-11-11 05:26:14 +00:00
|
|
|
"parse and expand the source, but run no analysis"),
|
2014-12-09 17:25:37 +00:00
|
|
|
extra_plugins: Vec<String> = (Vec::new(), parse_list,
|
|
|
|
"load extra plugins"),
|
2014-12-09 09:55:49 +00:00
|
|
|
unstable_options: bool = (false, parse_bool,
|
2015-11-11 05:26:14 +00:00
|
|
|
"adds unstable command line options to rustc interface"),
|
2015-01-06 05:56:30 +00:00
|
|
|
force_overflow_checks: Option<bool> = (None, parse_opt_bool,
|
2015-11-11 05:26:14 +00:00
|
|
|
"force overflow checks on or off"),
|
2015-03-25 10:57:55 +00:00
|
|
|
force_dropflag_checks: Option<bool> = (None, parse_opt_bool,
|
2015-11-11 05:26:14 +00:00
|
|
|
"force drop flag checks on or off"),
|
2015-04-14 13:36:38 +00:00
|
|
|
trace_macros: bool = (false, parse_bool,
|
2015-11-11 05:26:14 +00:00
|
|
|
"for every macro invocation, print its name and arguments"),
|
2015-08-07 13:51:25 +00:00
|
|
|
enable_nonzeroing_move_hints: bool = (false, parse_bool,
|
2015-11-11 05:26:14 +00:00
|
|
|
"force nonzeroing move optimization on"),
|
2016-07-16 19:11:28 +00:00
|
|
|
keep_hygiene_data: bool = (false, parse_bool,
|
|
|
|
"don't clear the hygiene data after analysis"),
|
2015-12-25 16:17:45 +00:00
|
|
|
keep_ast: bool = (false, parse_bool,
|
|
|
|
"keep the AST after lowering it to HIR"),
|
2016-01-12 04:44:24 +00:00
|
|
|
show_span: Option<String> = (None, parse_opt_string,
|
|
|
|
"show spans for compiler debugging (expr|pat|ty)"),
|
2015-11-02 13:46:39 +00:00
|
|
|
print_trans_items: Option<String> = (None, parse_opt_string,
|
|
|
|
"print the result of the translation item collection pass"),
|
2016-02-07 20:46:39 +00:00
|
|
|
mir_opt_level: Option<usize> = (None, parse_opt_uint,
|
|
|
|
"set the MIR optimization level (0-3)"),
|
2016-03-22 20:05:28 +00:00
|
|
|
dump_mir: Option<String> = (None, parse_opt_string,
|
|
|
|
"dump MIR state at various points in translation"),
|
2016-07-07 23:40:01 +00:00
|
|
|
dump_mir_dir: Option<String> = (None, parse_opt_string,
|
|
|
|
"the directory the MIR is dumped into"),
|
2016-03-09 20:46:00 +00:00
|
|
|
orbit: bool = (false, parse_bool,
|
|
|
|
"get MIR where it belongs - everywhere; most importantly, in orbit"),
|
2014-12-09 09:55:49 +00:00
|
|
|
}
|
|
|
|
|
2014-05-06 11:38:01 +00:00
|
|
|
pub fn default_lib_output() -> CrateType {
|
|
|
|
CrateTypeRlib
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
|
2014-07-23 18:56:36 +00:00
|
|
|
use syntax::parse::token::intern_and_get_ident as intern;
|
2014-05-06 11:38:01 +00:00
|
|
|
|
2015-02-20 19:08:14 +00:00
|
|
|
let end = &sess.target.target.target_endian;
|
|
|
|
let arch = &sess.target.target.arch;
|
|
|
|
let wordsz = &sess.target.target.target_pointer_width;
|
|
|
|
let os = &sess.target.target.target_os;
|
2015-04-21 22:53:32 +00:00
|
|
|
let env = &sess.target.target.target_env;
|
2015-09-23 23:20:43 +00:00
|
|
|
let vendor = &sess.target.target.target_vendor;
|
2016-04-15 19:16:19 +00:00
|
|
|
let max_atomic_width = sess.target.target.options.max_atomic_width;
|
2014-05-06 11:38:01 +00:00
|
|
|
|
2015-10-09 02:08:07 +00:00
|
|
|
let fam = if let Some(ref fam) = sess.target.target.options.target_family {
|
|
|
|
intern(fam)
|
|
|
|
} else if sess.target.target.options.is_like_windows {
|
|
|
|
InternedString::new("windows")
|
|
|
|
} else {
|
|
|
|
InternedString::new("unix")
|
2014-05-06 11:38:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let mk = attr::mk_name_value_item_str;
|
2015-03-02 22:51:24 +00:00
|
|
|
let mut ret = vec![ // Target bindings.
|
2015-10-09 02:08:07 +00:00
|
|
|
mk(InternedString::new("target_os"), intern(os)),
|
|
|
|
mk(InternedString::new("target_family"), fam.clone()),
|
|
|
|
mk(InternedString::new("target_arch"), intern(arch)),
|
|
|
|
mk(InternedString::new("target_endian"), intern(end)),
|
|
|
|
mk(InternedString::new("target_pointer_width"), intern(wordsz)),
|
|
|
|
mk(InternedString::new("target_env"), intern(env)),
|
|
|
|
mk(InternedString::new("target_vendor"), intern(vendor)),
|
2015-03-02 22:51:24 +00:00
|
|
|
];
|
2015-10-09 02:08:07 +00:00
|
|
|
match &fam[..] {
|
|
|
|
"windows" | "unix" => ret.push(attr::mk_word_item(fam)),
|
|
|
|
_ => (),
|
|
|
|
}
|
2015-12-10 20:21:55 +00:00
|
|
|
if sess.target.target.options.has_elf_tls {
|
|
|
|
ret.push(attr::mk_word_item(InternedString::new("target_thread_local")));
|
|
|
|
}
|
2016-04-15 19:16:19 +00:00
|
|
|
for &i in &[8, 16, 32, 64, 128] {
|
|
|
|
if i <= max_atomic_width {
|
|
|
|
let s = i.to_string();
|
|
|
|
ret.push(mk(InternedString::new("target_has_atomic"), intern(&s)));
|
|
|
|
if &s == wordsz {
|
|
|
|
ret.push(mk(InternedString::new("target_has_atomic"), intern("ptr")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-02 22:51:24 +00:00
|
|
|
if sess.opts.debug_assertions {
|
|
|
|
ret.push(attr::mk_word_item(InternedString::new("debug_assertions")));
|
|
|
|
}
|
|
|
|
return ret;
|
2014-05-06 11:38:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn append_configuration(cfg: &mut ast::CrateConfig,
|
|
|
|
name: InternedString) {
|
|
|
|
if !cfg.iter().any(|mi| mi.name() == name) {
|
|
|
|
cfg.push(attr::mk_word_item(name))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn build_configuration(sess: &Session) -> ast::CrateConfig {
|
|
|
|
// Combine the configuration requested by the session (command line) with
|
|
|
|
// some default and generated configuration items
|
|
|
|
let default_cfg = default_configuration(sess);
|
|
|
|
let mut user_cfg = sess.opts.cfg.clone();
|
|
|
|
// If the user wants a test runner, then add the test cfg
|
|
|
|
if sess.opts.test {
|
|
|
|
append_configuration(&mut user_cfg, InternedString::new("test"))
|
|
|
|
}
|
2014-10-15 06:05:01 +00:00
|
|
|
let mut v = user_cfg.into_iter().collect::<Vec<_>>();
|
2015-12-03 01:31:49 +00:00
|
|
|
v.extend_from_slice(&default_cfg[..]);
|
2014-10-15 06:05:01 +00:00
|
|
|
v
|
2014-05-06 11:38:01 +00:00
|
|
|
}
|
|
|
|
|
2015-12-13 22:17:55 +00:00
|
|
|
pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
|
2015-02-20 19:08:14 +00:00
|
|
|
let target = match Target::search(&opts.target_triple) {
|
2014-07-23 18:56:36 +00:00
|
|
|
Ok(t) => t,
|
|
|
|
Err(e) => {
|
2016-07-30 11:06:49 +00:00
|
|
|
sp.struct_fatal(&format!("Error loading target specification: {}", e))
|
|
|
|
.help("Use `--print target-list` for a list of built-in targets")
|
|
|
|
.emit();
|
|
|
|
panic!(FatalError);
|
2015-04-14 13:36:38 +00:00
|
|
|
}
|
2014-05-06 11:38:01 +00:00
|
|
|
};
|
2014-07-23 18:56:36 +00:00
|
|
|
|
2015-02-20 19:08:14 +00:00
|
|
|
let (int_type, uint_type) = match &target.target_pointer_width[..] {
|
2016-05-06 13:31:11 +00:00
|
|
|
"16" => (ast::IntTy::I16, ast::UintTy::U16),
|
2016-02-08 15:20:57 +00:00
|
|
|
"32" => (ast::IntTy::I32, ast::UintTy::U32),
|
|
|
|
"64" => (ast::IntTy::I64, ast::UintTy::U64),
|
2015-12-13 22:17:55 +00:00
|
|
|
w => panic!(sp.fatal(&format!("target specification was invalid: \
|
|
|
|
unrecognized target-pointer-width {}", w))),
|
2014-05-06 11:38:01 +00:00
|
|
|
};
|
2014-07-23 18:56:36 +00:00
|
|
|
|
2014-05-06 11:38:01 +00:00
|
|
|
Config {
|
2014-07-23 18:56:36 +00:00
|
|
|
target: target,
|
2014-05-06 11:38:01 +00:00
|
|
|
int_type: int_type,
|
|
|
|
uint_type: uint_type,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 13:34:18 +00:00
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
2016-02-20 06:03:54 +00:00
|
|
|
pub enum OptionStability {
|
|
|
|
Stable,
|
|
|
|
|
|
|
|
// FIXME: historically there were some options which were either `-Z` or
|
|
|
|
// required the `-Z unstable-options` flag, which were all intended
|
|
|
|
// to be unstable. Unfortunately we didn't actually gate usage of
|
|
|
|
// these options on the stable compiler, so we still allow them there
|
|
|
|
// today. There are some warnings printed out about this in the
|
|
|
|
// driver.
|
|
|
|
UnstableButNotReally,
|
|
|
|
|
|
|
|
Unstable,
|
|
|
|
}
|
2014-12-17 13:42:50 +00:00
|
|
|
|
2015-01-04 03:54:18 +00:00
|
|
|
#[derive(Clone, PartialEq, Eq)]
|
2014-12-17 13:42:50 +00:00
|
|
|
pub struct RustcOptGroup {
|
|
|
|
pub opt_group: getopts::OptGroup,
|
|
|
|
pub stability: OptionStability,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RustcOptGroup {
|
|
|
|
pub fn is_stable(&self) -> bool {
|
|
|
|
self.stability == OptionStability::Stable
|
|
|
|
}
|
|
|
|
|
2016-03-15 08:09:29 +00:00
|
|
|
pub fn stable(g: getopts::OptGroup) -> RustcOptGroup {
|
2014-12-17 13:42:50 +00:00
|
|
|
RustcOptGroup { opt_group: g, stability: OptionStability::Stable }
|
|
|
|
}
|
|
|
|
|
2016-02-20 06:03:54 +00:00
|
|
|
#[allow(dead_code)] // currently we have no "truly unstable" options
|
2016-03-15 08:09:29 +00:00
|
|
|
pub fn unstable(g: getopts::OptGroup) -> RustcOptGroup {
|
2014-12-17 13:42:50 +00:00
|
|
|
RustcOptGroup { opt_group: g, stability: OptionStability::Unstable }
|
|
|
|
}
|
2016-02-20 06:03:54 +00:00
|
|
|
|
|
|
|
fn unstable_bnr(g: getopts::OptGroup) -> RustcOptGroup {
|
|
|
|
RustcOptGroup {
|
|
|
|
opt_group: g,
|
|
|
|
stability: OptionStability::UnstableButNotReally,
|
|
|
|
}
|
|
|
|
}
|
2014-12-17 13:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The `opt` local module holds wrappers around the `getopts` API that
|
|
|
|
// adds extra rustc-specific metadata to each option; such metadata
|
|
|
|
// is exposed by . The public
|
|
|
|
// functions below ending with `_u` are the functions that return
|
|
|
|
// *unstable* options, i.e. options that are only enabled when the
|
|
|
|
// user also passes the `-Z unstable-options` debugging flag.
|
|
|
|
mod opt {
|
|
|
|
// The `fn opt_u` etc below are written so that we can use them
|
|
|
|
// in the future; do not warn about them not being used right now.
|
|
|
|
#![allow(dead_code)]
|
|
|
|
|
|
|
|
use getopts;
|
|
|
|
use super::RustcOptGroup;
|
|
|
|
|
2015-03-11 21:44:56 +00:00
|
|
|
pub type R = RustcOptGroup;
|
|
|
|
pub type S<'a> = &'a str;
|
2014-12-17 13:42:50 +00:00
|
|
|
|
|
|
|
fn stable(g: getopts::OptGroup) -> R { RustcOptGroup::stable(g) }
|
|
|
|
fn unstable(g: getopts::OptGroup) -> R { RustcOptGroup::unstable(g) }
|
2016-02-20 06:03:54 +00:00
|
|
|
fn unstable_bnr(g: getopts::OptGroup) -> R { RustcOptGroup::unstable_bnr(g) }
|
2014-12-17 13:42:50 +00:00
|
|
|
|
2016-02-20 06:03:54 +00:00
|
|
|
pub fn opt_s(a: S, b: S, c: S, d: S) -> R {
|
|
|
|
stable(getopts::optopt(a, b, c, d))
|
|
|
|
}
|
|
|
|
pub fn multi_s(a: S, b: S, c: S, d: S) -> R {
|
|
|
|
stable(getopts::optmulti(a, b, c, d))
|
|
|
|
}
|
|
|
|
pub fn flag_s(a: S, b: S, c: S) -> R {
|
|
|
|
stable(getopts::optflag(a, b, c))
|
|
|
|
}
|
|
|
|
pub fn flagopt_s(a: S, b: S, c: S, d: S) -> R {
|
|
|
|
stable(getopts::optflagopt(a, b, c, d))
|
|
|
|
}
|
|
|
|
pub fn flagmulti_s(a: S, b: S, c: S) -> R {
|
|
|
|
stable(getopts::optflagmulti(a, b, c))
|
|
|
|
}
|
2015-04-29 15:20:36 +00:00
|
|
|
|
2016-02-20 06:03:54 +00:00
|
|
|
pub fn opt(a: S, b: S, c: S, d: S) -> R {
|
|
|
|
unstable(getopts::optopt(a, b, c, d))
|
|
|
|
}
|
|
|
|
pub fn multi(a: S, b: S, c: S, d: S) -> R {
|
|
|
|
unstable(getopts::optmulti(a, b, c, d))
|
|
|
|
}
|
|
|
|
pub fn flag(a: S, b: S, c: S) -> R {
|
|
|
|
unstable(getopts::optflag(a, b, c))
|
|
|
|
}
|
|
|
|
pub fn flagopt(a: S, b: S, c: S, d: S) -> R {
|
|
|
|
unstable(getopts::optflagopt(a, b, c, d))
|
|
|
|
}
|
|
|
|
pub fn flagmulti(a: S, b: S, c: S) -> R {
|
|
|
|
unstable(getopts::optflagmulti(a, b, c))
|
|
|
|
}
|
2014-12-17 13:42:50 +00:00
|
|
|
|
2016-02-20 06:03:54 +00:00
|
|
|
// Do not use these functions for any new options added to the compiler, all
|
|
|
|
// new options should use the `*_u` variants above to be truly unstable.
|
|
|
|
pub fn opt_ubnr(a: S, b: S, c: S, d: S) -> R {
|
|
|
|
unstable_bnr(getopts::optopt(a, b, c, d))
|
|
|
|
}
|
|
|
|
pub fn multi_ubnr(a: S, b: S, c: S, d: S) -> R {
|
|
|
|
unstable_bnr(getopts::optmulti(a, b, c, d))
|
|
|
|
}
|
|
|
|
pub fn flag_ubnr(a: S, b: S, c: S) -> R {
|
|
|
|
unstable_bnr(getopts::optflag(a, b, c))
|
|
|
|
}
|
|
|
|
pub fn flagopt_ubnr(a: S, b: S, c: S, d: S) -> R {
|
|
|
|
unstable_bnr(getopts::optflagopt(a, b, c, d))
|
|
|
|
}
|
|
|
|
pub fn flagmulti_ubnr(a: S, b: S, c: S) -> R {
|
|
|
|
unstable_bnr(getopts::optflagmulti(a, b, c))
|
|
|
|
}
|
2014-12-17 13:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the "short" subset of the rustc command line options,
|
|
|
|
/// including metadata for each option, such as whether the option is
|
|
|
|
/// part of the stable long-term interface for rustc.
|
|
|
|
pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
|
2014-12-16 00:03:39 +00:00
|
|
|
vec![
|
2016-02-20 06:03:54 +00:00
|
|
|
opt::flag_s("h", "help", "Display this message"),
|
|
|
|
opt::multi_s("", "cfg", "Configure the compilation environment", "SPEC"),
|
2016-04-15 20:55:42 +00:00
|
|
|
opt::multi_s("L", "", "Add a directory to the library search path. The
|
|
|
|
optional KIND can be one of dependency, crate, native,
|
|
|
|
framework or all (the default).", "[KIND=]PATH"),
|
2016-02-20 06:03:54 +00:00
|
|
|
opt::multi_s("l", "", "Link the generated crate(s) to the specified native
|
2016-04-10 13:59:19 +00:00
|
|
|
library NAME. The optional KIND can be one of
|
2014-10-21 06:04:16 +00:00
|
|
|
static, dylib, or framework. If omitted, dylib is
|
2014-12-31 23:10:45 +00:00
|
|
|
assumed.", "[KIND=]NAME"),
|
2016-02-20 06:03:54 +00:00
|
|
|
opt::multi_s("", "crate-type", "Comma separated list of types of crates
|
2014-05-06 11:38:01 +00:00
|
|
|
for the compiler to emit",
|
2016-07-12 16:56:11 +00:00
|
|
|
"[bin|lib|rlib|dylib|cdylib|staticlib]"),
|
2016-02-20 06:03:54 +00:00
|
|
|
opt::opt_s("", "crate-name", "Specify the name of the crate being built",
|
2014-07-02 00:07:06 +00:00
|
|
|
"NAME"),
|
2016-02-20 06:03:54 +00:00
|
|
|
opt::multi_s("", "emit", "Comma separated list of types of output for \
|
2014-12-16 00:03:39 +00:00
|
|
|
the compiler to emit",
|
2014-12-22 10:32:29 +00:00
|
|
|
"[asm|llvm-bc|llvm-ir|obj|link|dep-info]"),
|
2016-02-20 06:03:54 +00:00
|
|
|
opt::multi_s("", "print", "Comma separated list of compiler information to \
|
2014-12-16 00:03:39 +00:00
|
|
|
print on stdout",
|
2016-02-14 22:09:44 +00:00
|
|
|
"[crate-name|file-names|sysroot|cfg|target-list]"),
|
2016-02-20 06:03:54 +00:00
|
|
|
opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"),
|
|
|
|
opt::flagmulti_s("O", "", "Equivalent to -C opt-level=2"),
|
|
|
|
opt::opt_s("o", "", "Write output to <filename>", "FILENAME"),
|
|
|
|
opt::opt_s("", "out-dir", "Write output to compiler-chosen filename \
|
2014-12-16 00:03:39 +00:00
|
|
|
in <dir>", "DIR"),
|
2016-02-20 06:03:54 +00:00
|
|
|
opt::opt_s("", "explain", "Provide a detailed explanation of an error \
|
2014-12-16 00:03:39 +00:00
|
|
|
message", "OPT"),
|
2016-02-20 06:03:54 +00:00
|
|
|
opt::flag_s("", "test", "Build a test harness"),
|
|
|
|
opt::opt_s("", "target", "Target triple for which the code is compiled", "TARGET"),
|
|
|
|
opt::multi_s("W", "warn", "Set lint warnings", "OPT"),
|
|
|
|
opt::multi_s("A", "allow", "Set lint allowed", "OPT"),
|
|
|
|
opt::multi_s("D", "deny", "Set lint denied", "OPT"),
|
|
|
|
opt::multi_s("F", "forbid", "Set lint forbidden", "OPT"),
|
|
|
|
opt::multi_s("", "cap-lints", "Set the most restrictive lint level. \
|
2015-07-24 05:19:12 +00:00
|
|
|
More restrictive lints are capped at this \
|
|
|
|
level", "LEVEL"),
|
2016-02-20 06:03:54 +00:00
|
|
|
opt::multi_s("C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
|
|
|
|
opt::flag_s("V", "version", "Print version info and exit"),
|
|
|
|
opt::flag_s("v", "verbose", "Use verbose output"),
|
2014-12-16 00:03:39 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2014-12-17 13:42:50 +00:00
|
|
|
/// Returns all rustc command line options, including metadata for
|
|
|
|
/// each option, such as whether the option is part of the stable
|
|
|
|
/// long-term interface for rustc.
|
|
|
|
pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
|
|
|
|
let mut opts = rustc_short_optgroups();
|
2015-12-03 01:31:49 +00:00
|
|
|
opts.extend_from_slice(&[
|
2016-03-15 08:09:29 +00:00
|
|
|
opt::multi_s("", "extern", "Specify where an external rust library is located",
|
|
|
|
"NAME=PATH"),
|
2016-02-20 06:03:54 +00:00
|
|
|
opt::opt_s("", "sysroot", "Override the system root", "PATH"),
|
|
|
|
opt::multi_ubnr("Z", "", "Set internal debugging options", "FLAG"),
|
|
|
|
opt::opt_ubnr("", "error-format",
|
|
|
|
"How errors and other messages are produced",
|
|
|
|
"human|json"),
|
|
|
|
opt::opt_s("", "color", "Configure coloring of output:
|
2016-03-15 08:09:29 +00:00
|
|
|
auto = colorize, if output goes to a tty (default);
|
|
|
|
always = always colorize output;
|
|
|
|
never = never colorize output", "auto|always|never"),
|
2014-12-16 00:03:39 +00:00
|
|
|
|
2016-02-20 06:03:54 +00:00
|
|
|
opt::flagopt_ubnr("", "pretty",
|
2016-03-15 08:09:29 +00:00
|
|
|
"Pretty-print the input instead of compiling;
|
|
|
|
valid types are: `normal` (un-annotated source),
|
|
|
|
`expanded` (crates expanded), or
|
|
|
|
`expanded,identified` (fully parenthesized, AST nodes with IDs).",
|
|
|
|
"TYPE"),
|
2016-02-20 06:03:54 +00:00
|
|
|
opt::flagopt_ubnr("", "unpretty",
|
2016-03-15 08:09:29 +00:00
|
|
|
"Present the input source, unstable (and less-pretty) variants;
|
|
|
|
valid types are any of the types for `--pretty`, as well as:
|
|
|
|
`flowgraph=<nodeid>` (graphviz formatted flowgraph for node),
|
|
|
|
`everybody_loops` (all function bodies replaced with `loop {}`),
|
|
|
|
`hir` (the HIR), `hir,identified`, or
|
|
|
|
`hir,typed` (HIR with types for each node).",
|
|
|
|
"TYPE"),
|
2016-02-20 06:03:54 +00:00
|
|
|
|
|
|
|
// new options here should **not** use the `_ubnr` functions, all new
|
|
|
|
// unstable options should use the short variants to indicate that they
|
|
|
|
// are truly unstable. All `_ubnr` flags are just that way because they
|
|
|
|
// were so historically.
|
|
|
|
//
|
|
|
|
// You may also wish to keep this comment at the bottom of this list to
|
|
|
|
// ensure that others see it.
|
2014-12-16 00:03:39 +00:00
|
|
|
]);
|
|
|
|
opts
|
2014-05-06 11:38:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert strings provided as --cfg [cfgspec] into a crate_cfg
|
2014-10-07 02:39:01 +00:00
|
|
|
pub fn parse_cfgspecs(cfgspecs: Vec<String> ) -> ast::CrateConfig {
|
2014-09-15 03:27:36 +00:00
|
|
|
cfgspecs.into_iter().map(|s| {
|
2016-02-10 06:48:47 +00:00
|
|
|
let sess = parse::ParseSess::new();
|
|
|
|
let mut parser = parse::new_parser_from_source_str(&sess,
|
|
|
|
Vec::new(),
|
|
|
|
"cfgspec".to_string(),
|
|
|
|
s.to_string());
|
|
|
|
let meta_item = panictry!(parser.parse_meta_item());
|
|
|
|
|
|
|
|
if !parser.reader.is_eof() {
|
|
|
|
early_error(ErrorOutputType::default(), &format!("invalid --cfg argument: {}",
|
|
|
|
s))
|
|
|
|
}
|
|
|
|
|
|
|
|
meta_item
|
2014-05-06 11:38:01 +00:00
|
|
|
}).collect::<ast::CrateConfig>()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
2015-08-22 14:51:53 +00:00
|
|
|
let color = match matches.opt_str("color").as_ref().map(|s| &s[..]) {
|
2015-12-13 22:17:55 +00:00
|
|
|
Some("auto") => ColorConfig::Auto,
|
|
|
|
Some("always") => ColorConfig::Always,
|
|
|
|
Some("never") => ColorConfig::Never,
|
2015-08-22 14:51:53 +00:00
|
|
|
|
2015-12-13 22:17:55 +00:00
|
|
|
None => ColorConfig::Auto,
|
2015-08-22 14:51:53 +00:00
|
|
|
|
|
|
|
Some(arg) => {
|
2015-12-31 03:50:06 +00:00
|
|
|
early_error(ErrorOutputType::default(), &format!("argument for --color must be auto, \
|
|
|
|
always or never (instead was `{}`)",
|
|
|
|
arg))
|
2015-08-22 14:51:53 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-12-31 03:50:06 +00:00
|
|
|
// We need the opts_present check because the driver will send us Matches
|
2016-01-06 20:23:01 +00:00
|
|
|
// with only stable options if no unstable options are used. Since error-format
|
|
|
|
// is unstable, it will not be present. We have to use opts_present not
|
2015-12-31 03:50:06 +00:00
|
|
|
// opt_present because the latter will panic.
|
2016-01-06 20:23:01 +00:00
|
|
|
let error_format = if matches.opts_present(&["error-format".to_owned()]) {
|
|
|
|
match matches.opt_str("error-format").as_ref().map(|s| &s[..]) {
|
|
|
|
Some("human") => ErrorOutputType::HumanReadable(color),
|
2015-12-31 03:50:06 +00:00
|
|
|
Some("json") => ErrorOutputType::Json,
|
|
|
|
|
2016-02-11 01:02:20 +00:00
|
|
|
None => ErrorOutputType::HumanReadable(color),
|
2015-12-31 03:50:06 +00:00
|
|
|
|
|
|
|
Some(arg) => {
|
2016-02-11 01:02:20 +00:00
|
|
|
early_error(ErrorOutputType::HumanReadable(color),
|
|
|
|
&format!("argument for --error-format must be human or json (instead \
|
|
|
|
was `{}`)",
|
|
|
|
arg))
|
2015-12-31 03:50:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2016-02-11 01:02:20 +00:00
|
|
|
ErrorOutputType::HumanReadable(color)
|
2015-12-31 03:50:06 +00:00
|
|
|
};
|
|
|
|
|
2014-05-06 11:38:01 +00:00
|
|
|
let unparsed_crate_types = matches.opt_strs("crate-type");
|
2014-07-20 04:11:26 +00:00
|
|
|
let crate_types = parse_crate_types_from_list(unparsed_crate_types)
|
2016-01-06 20:23:01 +00:00
|
|
|
.unwrap_or_else(|e| early_error(error_format, &e[..]));
|
2014-05-06 11:38:01 +00:00
|
|
|
|
2014-06-04 21:35:58 +00:00
|
|
|
let mut lint_opts = vec!();
|
|
|
|
let mut describe_lints = false;
|
|
|
|
|
2015-01-31 17:20:46 +00:00
|
|
|
for &level in &[lint::Allow, lint::Warn, lint::Deny, lint::Forbid] {
|
2015-02-01 01:03:04 +00:00
|
|
|
for lint_name in matches.opt_strs(level.as_str()) {
|
2014-11-27 18:53:34 +00:00
|
|
|
if lint_name == "help" {
|
2014-06-04 21:35:58 +00:00
|
|
|
describe_lints = true;
|
|
|
|
} else {
|
2014-12-11 03:46:38 +00:00
|
|
|
lint_opts.push((lint_name.replace("-", "_"), level));
|
2014-05-06 11:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-24 05:19:12 +00:00
|
|
|
let lint_cap = matches.opt_str("cap-lints").map(|cap| {
|
|
|
|
lint::Level::from_str(&cap).unwrap_or_else(|| {
|
2016-01-06 20:23:01 +00:00
|
|
|
early_error(error_format, &format!("unknown lint level: `{}`", cap))
|
2015-07-24 05:19:12 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2016-01-06 20:23:01 +00:00
|
|
|
let debugging_opts = build_debugging_options(matches, error_format);
|
2014-05-06 11:38:01 +00:00
|
|
|
|
2015-01-20 18:57:10 +00:00
|
|
|
let parse_only = debugging_opts.parse_only;
|
|
|
|
let no_trans = debugging_opts.no_trans;
|
2015-02-18 16:02:06 +00:00
|
|
|
let treat_err_as_bug = debugging_opts.treat_err_as_bug;
|
2016-03-25 17:17:04 +00:00
|
|
|
let continue_parse_after_error = debugging_opts.continue_parse_after_error;
|
2016-02-07 20:46:39 +00:00
|
|
|
let mir_opt_level = debugging_opts.mir_opt_level.unwrap_or(1);
|
2015-01-20 18:57:10 +00:00
|
|
|
let no_analysis = debugging_opts.no_analysis;
|
2014-12-16 00:03:39 +00:00
|
|
|
|
2015-09-30 17:08:37 +00:00
|
|
|
let mut output_types = HashMap::new();
|
2016-05-25 05:46:36 +00:00
|
|
|
if !debugging_opts.parse_only {
|
2015-09-30 17:08:37 +00:00
|
|
|
for list in matches.opt_strs("emit") {
|
|
|
|
for output_type in list.split(',') {
|
|
|
|
let mut parts = output_type.splitn(2, '=');
|
|
|
|
let output_type = match parts.next().unwrap() {
|
|
|
|
"asm" => OutputType::Assembly,
|
|
|
|
"llvm-ir" => OutputType::LlvmAssembly,
|
|
|
|
"llvm-bc" => OutputType::Bitcode,
|
|
|
|
"obj" => OutputType::Object,
|
|
|
|
"link" => OutputType::Exe,
|
|
|
|
"dep-info" => OutputType::DepInfo,
|
|
|
|
part => {
|
2016-01-06 20:23:01 +00:00
|
|
|
early_error(error_format, &format!("unknown emission type: `{}`",
|
2015-08-22 14:51:53 +00:00
|
|
|
part))
|
2014-05-16 17:45:16 +00:00
|
|
|
}
|
2014-05-06 11:38:01 +00:00
|
|
|
};
|
2015-09-30 17:08:37 +00:00
|
|
|
let path = parts.next().map(PathBuf::from);
|
|
|
|
output_types.insert(output_type, path);
|
2014-05-06 11:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-03-24 23:53:34 +00:00
|
|
|
if output_types.is_empty() {
|
2015-09-30 17:08:37 +00:00
|
|
|
output_types.insert(OutputType::Exe, None);
|
2014-05-06 11:38:01 +00:00
|
|
|
}
|
|
|
|
|
2016-01-06 20:23:01 +00:00
|
|
|
let mut cg = build_codegen_options(matches, error_format);
|
2015-12-04 18:35:16 +00:00
|
|
|
|
|
|
|
// Issue #30063: if user requests llvm-related output to one
|
|
|
|
// particular path, disable codegen-units.
|
|
|
|
if matches.opt_present("o") && cg.codegen_units != 1 {
|
|
|
|
let incompatible: Vec<_> = output_types.iter()
|
|
|
|
.map(|ot_path| ot_path.0)
|
|
|
|
.filter(|ot| {
|
|
|
|
!ot.is_compatible_with_codegen_units_and_single_output_file()
|
|
|
|
}).collect();
|
|
|
|
if !incompatible.is_empty() {
|
|
|
|
for ot in &incompatible {
|
2016-01-06 20:23:01 +00:00
|
|
|
early_warn(error_format, &format!("--emit={} with -o incompatible with \
|
|
|
|
-C codegen-units=N for N > 1",
|
|
|
|
ot.shorthand()));
|
2015-12-04 18:35:16 +00:00
|
|
|
}
|
2016-01-06 20:23:01 +00:00
|
|
|
early_warn(error_format, "resetting to default -C codegen-units=1");
|
2015-12-04 18:35:16 +00:00
|
|
|
cg.codegen_units = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-12 10:31:34 +00:00
|
|
|
if cg.codegen_units < 1 {
|
|
|
|
early_error(error_format, "Value for codegen units must be a positive nonzero integer");
|
|
|
|
}
|
|
|
|
|
2015-12-04 18:35:16 +00:00
|
|
|
let cg = cg;
|
2014-12-16 00:03:39 +00:00
|
|
|
|
2015-03-18 16:14:54 +00:00
|
|
|
let sysroot_opt = matches.opt_str("sysroot").map(|m| PathBuf::from(&m));
|
2014-06-26 06:15:14 +00:00
|
|
|
let target = matches.opt_str("target").unwrap_or(
|
2014-11-16 01:30:33 +00:00
|
|
|
host_triple().to_string());
|
2014-05-06 11:38:01 +00:00
|
|
|
let opt_level = {
|
2014-09-21 04:08:00 +00:00
|
|
|
if matches.opt_present("O") {
|
2014-12-16 00:03:39 +00:00
|
|
|
if cg.opt_level.is_some() {
|
2016-01-06 20:23:01 +00:00
|
|
|
early_error(error_format, "-O and -C opt-level both provided");
|
2014-12-16 00:03:39 +00:00
|
|
|
}
|
2015-12-31 03:50:06 +00:00
|
|
|
OptLevel::Default
|
2014-05-06 11:38:01 +00:00
|
|
|
} else {
|
2016-04-29 06:04:45 +00:00
|
|
|
match (cg.opt_level.as_ref().map(String::as_ref),
|
|
|
|
nightly_options::is_nightly_build()) {
|
|
|
|
(None, _) => OptLevel::No,
|
|
|
|
(Some("0"), _) => OptLevel::No,
|
|
|
|
(Some("1"), _) => OptLevel::Less,
|
|
|
|
(Some("2"), _) => OptLevel::Default,
|
|
|
|
(Some("3"), _) => OptLevel::Aggressive,
|
|
|
|
(Some("s"), true) => OptLevel::Size,
|
|
|
|
(Some("z"), true) => OptLevel::SizeMin,
|
2016-04-30 05:45:24 +00:00
|
|
|
(Some("s"), false) | (Some("z"), false) => {
|
|
|
|
early_error(error_format, &format!("the optimizations s or z are only \
|
|
|
|
accepted on the nightly compiler"));
|
|
|
|
},
|
2016-04-29 06:04:45 +00:00
|
|
|
(Some(arg), _) => {
|
2016-01-06 20:23:01 +00:00
|
|
|
early_error(error_format, &format!("optimization level needs to be \
|
2016-04-29 06:04:45 +00:00
|
|
|
between 0-3 (instead was `{}`)",
|
2016-01-06 20:23:01 +00:00
|
|
|
arg));
|
2014-12-16 00:03:39 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-06 11:38:01 +00:00
|
|
|
}
|
|
|
|
};
|
2015-12-31 03:50:06 +00:00
|
|
|
let debug_assertions = cg.debug_assertions.unwrap_or(opt_level == OptLevel::No);
|
2014-05-06 11:38:01 +00:00
|
|
|
let debuginfo = if matches.opt_present("g") {
|
2014-12-16 00:03:39 +00:00
|
|
|
if cg.debuginfo.is_some() {
|
2016-01-06 20:23:01 +00:00
|
|
|
early_error(error_format, "-g and -C debuginfo both provided");
|
2014-12-16 00:03:39 +00:00
|
|
|
}
|
2014-05-06 11:38:01 +00:00
|
|
|
FullDebugInfo
|
|
|
|
} else {
|
2014-12-16 00:03:39 +00:00
|
|
|
match cg.debuginfo {
|
|
|
|
None | Some(0) => NoDebugInfo,
|
|
|
|
Some(1) => LimitedDebugInfo,
|
|
|
|
Some(2) => FullDebugInfo,
|
|
|
|
Some(arg) => {
|
2016-01-06 20:23:01 +00:00
|
|
|
early_error(error_format, &format!("debug info level needs to be between \
|
|
|
|
0-2 (instead was `{}`)",
|
|
|
|
arg));
|
2014-12-16 00:03:39 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-06 11:38:01 +00:00
|
|
|
};
|
|
|
|
|
2014-12-16 22:32:02 +00:00
|
|
|
let mut search_paths = SearchPaths::new();
|
2015-01-31 17:20:46 +00:00
|
|
|
for s in &matches.opt_strs("L") {
|
2016-01-06 20:23:01 +00:00
|
|
|
search_paths.add_path(&s[..], error_format);
|
2014-12-16 22:32:02 +00:00
|
|
|
}
|
2014-05-06 11:38:01 +00:00
|
|
|
|
2014-10-21 06:04:16 +00:00
|
|
|
let libs = matches.opt_strs("l").into_iter().map(|s| {
|
2015-04-01 18:28:34 +00:00
|
|
|
let mut parts = s.splitn(2, '=');
|
2014-12-31 23:10:45 +00:00
|
|
|
let kind = parts.next().unwrap();
|
2014-10-21 06:04:16 +00:00
|
|
|
let (name, kind) = match (parts.next(), kind) {
|
|
|
|
(None, name) |
|
|
|
|
(Some(name), "dylib") => (name, cstore::NativeUnknown),
|
|
|
|
(Some(name), "framework") => (name, cstore::NativeFramework),
|
|
|
|
(Some(name), "static") => (name, cstore::NativeStatic),
|
|
|
|
(_, s) => {
|
2016-01-06 20:23:01 +00:00
|
|
|
early_error(error_format, &format!("unknown library kind `{}`, expected \
|
|
|
|
one of dylib, framework, or static",
|
|
|
|
s));
|
2014-10-21 06:04:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
(name.to_string(), kind)
|
|
|
|
}).collect();
|
|
|
|
|
2014-06-26 06:15:14 +00:00
|
|
|
let cfg = parse_cfgspecs(matches.opt_strs("cfg"));
|
2014-05-06 11:38:01 +00:00
|
|
|
let test = matches.opt_present("test");
|
2014-12-16 00:03:39 +00:00
|
|
|
|
2015-01-20 18:57:10 +00:00
|
|
|
let prints = matches.opt_strs("print").into_iter().map(|s| {
|
2015-02-02 02:53:25 +00:00
|
|
|
match &*s {
|
2014-12-16 00:03:39 +00:00
|
|
|
"crate-name" => PrintRequest::CrateName,
|
|
|
|
"file-names" => PrintRequest::FileNames,
|
|
|
|
"sysroot" => PrintRequest::Sysroot,
|
2016-01-25 19:36:18 +00:00
|
|
|
"cfg" => PrintRequest::Cfg,
|
2016-02-12 15:11:58 +00:00
|
|
|
"target-list" => PrintRequest::TargetList,
|
2014-12-16 00:03:39 +00:00
|
|
|
req => {
|
2016-01-06 20:23:01 +00:00
|
|
|
early_error(error_format, &format!("unknown print request `{}`", req))
|
2014-12-16 00:03:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}).collect::<Vec<_>>();
|
2014-05-06 11:38:01 +00:00
|
|
|
|
2014-09-12 15:17:58 +00:00
|
|
|
if !cg.remark.is_empty() && debuginfo == NoDebugInfo {
|
2016-01-06 20:23:01 +00:00
|
|
|
early_warn(error_format, "-C remark will not show source locations without \
|
|
|
|
--debuginfo");
|
2014-09-12 15:17:58 +00:00
|
|
|
}
|
|
|
|
|
2014-07-01 15:37:54 +00:00
|
|
|
let mut externs = HashMap::new();
|
2015-01-31 17:20:46 +00:00
|
|
|
for arg in &matches.opt_strs("extern") {
|
2015-04-01 18:28:34 +00:00
|
|
|
let mut parts = arg.splitn(2, '=');
|
2014-07-01 15:37:54 +00:00
|
|
|
let name = match parts.next() {
|
|
|
|
Some(s) => s,
|
2016-01-06 20:23:01 +00:00
|
|
|
None => early_error(error_format, "--extern value must not be empty"),
|
2014-07-01 15:37:54 +00:00
|
|
|
};
|
|
|
|
let location = match parts.next() {
|
|
|
|
Some(s) => s,
|
2016-01-06 20:23:01 +00:00
|
|
|
None => early_error(error_format, "--extern value must be of the format `foo=bar`"),
|
2014-07-01 15:37:54 +00:00
|
|
|
};
|
2014-09-18 21:05:52 +00:00
|
|
|
|
2015-03-20 17:43:01 +00:00
|
|
|
externs.entry(name.to_string()).or_insert(vec![]).push(location.to_string());
|
2014-07-01 15:37:54 +00:00
|
|
|
}
|
|
|
|
|
2014-07-02 00:07:06 +00:00
|
|
|
let crate_name = matches.opt_str("crate-name");
|
|
|
|
|
2016-03-28 21:43:36 +00:00
|
|
|
let incremental = debugging_opts.incremental.as_ref().map(|m| PathBuf::from(m));
|
|
|
|
|
2014-05-06 11:38:01 +00:00
|
|
|
Options {
|
|
|
|
crate_types: crate_types,
|
|
|
|
optimize: opt_level,
|
|
|
|
debuginfo: debuginfo,
|
|
|
|
lint_opts: lint_opts,
|
2015-07-24 05:19:12 +00:00
|
|
|
lint_cap: lint_cap,
|
2014-06-04 21:35:58 +00:00
|
|
|
describe_lints: describe_lints,
|
2014-05-06 11:38:01 +00:00
|
|
|
output_types: output_types,
|
2014-12-16 22:32:02 +00:00
|
|
|
search_paths: search_paths,
|
2014-05-06 11:38:01 +00:00
|
|
|
maybe_sysroot: sysroot_opt,
|
|
|
|
target_triple: target,
|
|
|
|
cfg: cfg,
|
|
|
|
test: test,
|
|
|
|
parse_only: parse_only,
|
|
|
|
no_trans: no_trans,
|
2015-02-18 16:02:06 +00:00
|
|
|
treat_err_as_bug: treat_err_as_bug,
|
2016-03-25 17:17:04 +00:00
|
|
|
continue_parse_after_error: continue_parse_after_error,
|
2016-02-07 20:46:39 +00:00
|
|
|
mir_opt_level: mir_opt_level,
|
2016-03-28 21:43:36 +00:00
|
|
|
incremental: incremental,
|
2014-05-06 11:38:01 +00:00
|
|
|
no_analysis: no_analysis,
|
|
|
|
debugging_opts: debugging_opts,
|
2014-12-16 00:03:39 +00:00
|
|
|
prints: prints,
|
2014-05-06 11:38:01 +00:00
|
|
|
cg: cg,
|
2016-01-06 20:23:01 +00:00
|
|
|
error_format: error_format,
|
2014-07-01 15:37:54 +00:00
|
|
|
externs: externs,
|
2014-07-02 00:07:06 +00:00
|
|
|
crate_name: crate_name,
|
2014-10-21 06:04:16 +00:00
|
|
|
alt_std_name: None,
|
|
|
|
libs: libs,
|
2015-01-30 08:44:27 +00:00
|
|
|
unstable_features: get_unstable_features_setting(),
|
2015-03-02 22:51:24 +00:00
|
|
|
debug_assertions: debug_assertions,
|
2015-01-30 08:44:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_unstable_features_setting() -> UnstableFeatures {
|
|
|
|
// Whether this is a feature-staged build, i.e. on the beta or stable channel
|
|
|
|
let disable_unstable_features = option_env!("CFG_DISABLE_UNSTABLE_FEATURES").is_some();
|
|
|
|
// The secret key needed to get through the rustc build itself by
|
|
|
|
// subverting the unstable features lints
|
|
|
|
let bootstrap_secret_key = option_env!("CFG_BOOTSTRAP_KEY");
|
|
|
|
// The matching key to the above, only known by the build system
|
2015-02-11 19:47:53 +00:00
|
|
|
let bootstrap_provided_key = env::var("RUSTC_BOOTSTRAP_KEY").ok();
|
2015-01-30 08:44:27 +00:00
|
|
|
match (disable_unstable_features, bootstrap_secret_key, bootstrap_provided_key) {
|
|
|
|
(_, Some(ref s), Some(ref p)) if s == p => UnstableFeatures::Cheat,
|
|
|
|
(true, _, _) => UnstableFeatures::Disallow,
|
2015-06-18 00:48:16 +00:00
|
|
|
(false, _, _) => UnstableFeatures::Allow
|
2014-05-06 11:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-20 23:32:46 +00:00
|
|
|
pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateType>, String> {
|
2014-07-20 04:11:26 +00:00
|
|
|
let mut crate_types: Vec<CrateType> = Vec::new();
|
2015-01-31 17:20:46 +00:00
|
|
|
for unparsed_crate_type in &list_list {
|
2014-11-27 18:53:34 +00:00
|
|
|
for part in unparsed_crate_type.split(',') {
|
2014-07-20 04:11:26 +00:00
|
|
|
let new_part = match part {
|
|
|
|
"lib" => default_lib_output(),
|
|
|
|
"rlib" => CrateTypeRlib,
|
|
|
|
"staticlib" => CrateTypeStaticlib,
|
|
|
|
"dylib" => CrateTypeDylib,
|
2016-05-10 21:17:57 +00:00
|
|
|
"cdylib" => CrateTypeCdylib,
|
2014-07-20 04:11:26 +00:00
|
|
|
"bin" => CrateTypeExecutable,
|
|
|
|
_ => {
|
|
|
|
return Err(format!("unknown crate type: `{}`",
|
|
|
|
part));
|
|
|
|
}
|
|
|
|
};
|
2015-02-09 17:30:22 +00:00
|
|
|
if !crate_types.contains(&new_part) {
|
|
|
|
crate_types.push(new_part)
|
|
|
|
}
|
2014-07-20 04:11:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok(crate_types);
|
|
|
|
}
|
|
|
|
|
2016-03-15 08:09:29 +00:00
|
|
|
pub mod nightly_options {
|
|
|
|
use getopts;
|
|
|
|
use syntax::feature_gate::UnstableFeatures;
|
|
|
|
use super::{ErrorOutputType, OptionStability, RustcOptGroup, get_unstable_features_setting};
|
|
|
|
use session::{early_error, early_warn};
|
|
|
|
|
|
|
|
pub fn is_unstable_enabled(matches: &getopts::Matches) -> bool {
|
|
|
|
is_nightly_build() && matches.opt_strs("Z").iter().any(|x| *x == "unstable-options")
|
|
|
|
}
|
|
|
|
|
2016-04-29 06:04:45 +00:00
|
|
|
pub fn is_nightly_build() -> bool {
|
2016-03-15 08:09:29 +00:00
|
|
|
match get_unstable_features_setting() {
|
|
|
|
UnstableFeatures::Allow | UnstableFeatures::Cheat => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn check_nightly_options(matches: &getopts::Matches, flags: &[RustcOptGroup]) {
|
|
|
|
let has_z_unstable_option = matches.opt_strs("Z").iter().any(|x| *x == "unstable-options");
|
|
|
|
let really_allows_unstable_options = match get_unstable_features_setting() {
|
|
|
|
UnstableFeatures::Disallow => false,
|
|
|
|
_ => true,
|
|
|
|
};
|
|
|
|
|
|
|
|
for opt in flags.iter() {
|
|
|
|
if opt.stability == OptionStability::Stable {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
let opt_name = if opt.opt_group.long_name.is_empty() {
|
|
|
|
&opt.opt_group.short_name
|
|
|
|
} else {
|
|
|
|
&opt.opt_group.long_name
|
|
|
|
};
|
|
|
|
if !matches.opt_present(opt_name) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if opt_name != "Z" && !has_z_unstable_option {
|
|
|
|
early_error(ErrorOutputType::default(),
|
|
|
|
&format!("the `-Z unstable-options` flag must also be passed to enable \
|
|
|
|
the flag `{}`",
|
|
|
|
opt_name));
|
|
|
|
}
|
|
|
|
if really_allows_unstable_options {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
match opt.stability {
|
|
|
|
OptionStability::Unstable => {
|
|
|
|
let msg = format!("the option `{}` is only accepted on the \
|
|
|
|
nightly compiler", opt_name);
|
|
|
|
early_error(ErrorOutputType::default(), &msg);
|
|
|
|
}
|
|
|
|
OptionStability::UnstableButNotReally => {
|
2016-05-05 19:11:41 +00:00
|
|
|
let msg = format!("the option `{}` is unstable and should \
|
2016-03-15 08:09:29 +00:00
|
|
|
only be used on the nightly compiler, but \
|
|
|
|
it is currently accepted for backwards \
|
|
|
|
compatibility; this will soon change, \
|
|
|
|
see issue #31847 for more details",
|
|
|
|
opt_name);
|
|
|
|
early_warn(ErrorOutputType::default(), &msg);
|
|
|
|
}
|
|
|
|
OptionStability::Stable => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
impl fmt::Display for CrateType {
|
2014-06-11 07:48:17 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
|
|
|
CrateTypeExecutable => "bin".fmt(f),
|
|
|
|
CrateTypeDylib => "dylib".fmt(f),
|
|
|
|
CrateTypeRlib => "rlib".fmt(f),
|
2016-05-10 21:17:57 +00:00
|
|
|
CrateTypeStaticlib => "staticlib".fmt(f),
|
|
|
|
CrateTypeCdylib => "cdylib".fmt(f),
|
2014-06-11 07:48:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-06 11:38:01 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
2015-04-24 15:30:41 +00:00
|
|
|
mod tests {
|
2016-03-29 17:19:37 +00:00
|
|
|
use dep_graph::DepGraph;
|
2015-11-26 17:19:54 +00:00
|
|
|
use middle::cstore::DummyCrateStore;
|
2016-02-20 06:03:54 +00:00
|
|
|
use session::config::{build_configuration, build_session_options};
|
2014-11-16 01:30:33 +00:00
|
|
|
use session::build_session;
|
2016-06-22 22:39:43 +00:00
|
|
|
use errors;
|
2015-11-26 17:19:54 +00:00
|
|
|
use std::rc::Rc;
|
2016-02-20 06:03:54 +00:00
|
|
|
use getopts::{getopts, OptGroup};
|
2014-05-06 11:38:01 +00:00
|
|
|
use syntax::attr;
|
|
|
|
use syntax::attr::AttrMetaMethods;
|
|
|
|
|
2016-02-20 06:03:54 +00:00
|
|
|
fn optgroups() -> Vec<OptGroup> {
|
|
|
|
super::rustc_optgroups().into_iter()
|
|
|
|
.map(|a| a.opt_group)
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
|
2014-05-06 11:38:01 +00:00
|
|
|
// When the user supplies --test we should implicitly supply --cfg test
|
|
|
|
#[test]
|
|
|
|
fn test_switch_implies_cfg_test() {
|
2016-03-29 17:19:37 +00:00
|
|
|
let dep_graph = DepGraph::new(false);
|
2014-05-06 11:38:01 +00:00
|
|
|
let matches =
|
2015-02-20 19:08:14 +00:00
|
|
|
&match getopts(&["--test".to_string()], &optgroups()) {
|
2014-05-06 11:38:01 +00:00
|
|
|
Ok(m) => m,
|
2014-10-09 19:17:22 +00:00
|
|
|
Err(f) => panic!("test_switch_implies_cfg_test: {}", f)
|
2014-05-06 11:38:01 +00:00
|
|
|
};
|
2016-06-22 22:39:43 +00:00
|
|
|
let registry = errors::registry::Registry::new(&[]);
|
2014-05-06 11:38:01 +00:00
|
|
|
let sessopts = build_session_options(matches);
|
2016-03-29 17:19:37 +00:00
|
|
|
let sess = build_session(sessopts, &dep_graph, None, registry, Rc::new(DummyCrateStore));
|
2014-05-06 11:38:01 +00:00
|
|
|
let cfg = build_configuration(&sess);
|
2015-02-18 19:48:57 +00:00
|
|
|
assert!((attr::contains_name(&cfg[..], "test")));
|
2014-05-06 11:38:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// When the user supplies --test and --cfg test, don't implicitly add
|
|
|
|
// another --cfg test
|
|
|
|
#[test]
|
|
|
|
fn test_switch_implies_cfg_test_unless_cfg_test() {
|
2016-03-29 17:19:37 +00:00
|
|
|
let dep_graph = DepGraph::new(false);
|
2014-05-06 11:38:01 +00:00
|
|
|
let matches =
|
2014-11-17 08:39:01 +00:00
|
|
|
&match getopts(&["--test".to_string(), "--cfg=test".to_string()],
|
2015-02-20 19:08:14 +00:00
|
|
|
&optgroups()) {
|
2014-05-06 11:38:01 +00:00
|
|
|
Ok(m) => m,
|
|
|
|
Err(f) => {
|
2014-10-09 19:17:22 +00:00
|
|
|
panic!("test_switch_implies_cfg_test_unless_cfg_test: {}", f)
|
2014-05-06 11:38:01 +00:00
|
|
|
}
|
|
|
|
};
|
2016-06-22 22:39:43 +00:00
|
|
|
let registry = errors::registry::Registry::new(&[]);
|
2014-05-06 11:38:01 +00:00
|
|
|
let sessopts = build_session_options(matches);
|
2016-03-29 17:19:37 +00:00
|
|
|
let sess = build_session(sessopts, &dep_graph, None, registry,
|
2015-11-26 17:19:54 +00:00
|
|
|
Rc::new(DummyCrateStore));
|
2014-05-06 11:38:01 +00:00
|
|
|
let cfg = build_configuration(&sess);
|
2014-11-21 01:25:27 +00:00
|
|
|
let mut test_items = cfg.iter().filter(|m| m.name() == "test");
|
2014-05-06 11:38:01 +00:00
|
|
|
assert!(test_items.next().is_some());
|
|
|
|
assert!(test_items.next().is_none());
|
|
|
|
}
|
2014-11-24 19:53:12 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_can_print_warnings() {
|
2016-03-29 17:19:37 +00:00
|
|
|
let dep_graph = DepGraph::new(false);
|
2014-11-24 19:53:12 +00:00
|
|
|
{
|
|
|
|
let matches = getopts(&[
|
|
|
|
"-Awarnings".to_string()
|
2015-02-20 19:08:14 +00:00
|
|
|
], &optgroups()).unwrap();
|
2016-06-22 22:39:43 +00:00
|
|
|
let registry = errors::registry::Registry::new(&[]);
|
2014-11-24 19:53:12 +00:00
|
|
|
let sessopts = build_session_options(&matches);
|
2016-03-29 17:19:37 +00:00
|
|
|
let sess = build_session(sessopts, &dep_graph, None, registry,
|
2015-11-26 17:19:54 +00:00
|
|
|
Rc::new(DummyCrateStore));
|
2015-12-15 03:51:13 +00:00
|
|
|
assert!(!sess.diagnostic().can_emit_warnings);
|
2014-11-24 19:53:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
let matches = getopts(&[
|
|
|
|
"-Awarnings".to_string(),
|
|
|
|
"-Dwarnings".to_string()
|
2015-02-20 19:08:14 +00:00
|
|
|
], &optgroups()).unwrap();
|
2016-06-22 22:39:43 +00:00
|
|
|
let registry = errors::registry::Registry::new(&[]);
|
2014-11-24 19:53:12 +00:00
|
|
|
let sessopts = build_session_options(&matches);
|
2016-03-29 17:19:37 +00:00
|
|
|
let sess = build_session(sessopts, &dep_graph, None, registry,
|
2015-11-26 17:19:54 +00:00
|
|
|
Rc::new(DummyCrateStore));
|
2015-12-15 03:51:13 +00:00
|
|
|
assert!(sess.diagnostic().can_emit_warnings);
|
2014-11-24 19:53:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
let matches = getopts(&[
|
|
|
|
"-Adead_code".to_string()
|
2015-02-20 19:08:14 +00:00
|
|
|
], &optgroups()).unwrap();
|
2016-06-22 22:39:43 +00:00
|
|
|
let registry = errors::registry::Registry::new(&[]);
|
2014-11-24 19:53:12 +00:00
|
|
|
let sessopts = build_session_options(&matches);
|
2016-03-29 17:19:37 +00:00
|
|
|
let sess = build_session(sessopts, &dep_graph, None, registry,
|
2015-11-26 17:19:54 +00:00
|
|
|
Rc::new(DummyCrateStore));
|
2015-12-15 03:51:13 +00:00
|
|
|
assert!(sess.diagnostic().can_emit_warnings);
|
2014-11-24 19:53:12 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-06 11:38:01 +00:00
|
|
|
}
|