Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1 | //! Contains infrastructure for configuring the compiler, including parsing |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 2 | //! command-line options. |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 3 | |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 4 | use crate::lint; |
| 5 | use crate::middle::cstore; |
Mark Mansi | e957ed9 | 2019-02-05 17:20:45 | [diff] [blame] | 6 | use crate::session::{early_error, early_warn, Session}; |
| 7 | use crate::session::search_paths::SearchPath; |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 8 | |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 9 | use rustc_data_structures::fx::FxHashSet; |
| 10 | |
Peter Jin | b91d211 | 2018-12-31 18:58:13 | [diff] [blame] | 11 | use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, RelroLevel}; |
Irina Popa | 38e9640 | 2017-12-08 19:18:21 | [diff] [blame] | 12 | use rustc_target::spec::{Target, TargetTriple}; |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 13 | |
John Kåre Alsaker | 51938c6 | 2018-12-08 19:30:23 | [diff] [blame] | 14 | use syntax; |
Mazdak Farrokhzad | d945f98 | 2019-10-11 21:48:16 | [diff] [blame] | 15 | use syntax::ast::{self, IntTy, UintTy}; |
Donato Sciarra | 82607d2 | 2018-08-18 10:14:03 | [diff] [blame] | 16 | use syntax::source_map::{FileName, FilePathMapping}; |
Kurtis Nusbaum | 320fdaa | 2018-04-20 04:03:21 | [diff] [blame] | 17 | use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION}; |
Nicholas Nethercote | 26451ef | 2019-05-22 02:42:23 | [diff] [blame] | 18 | use syntax::symbol::{sym, Symbol}; |
Brian Anderson | f14a0e2 | 2015-06-18 00:48:16 | [diff] [blame] | 19 | use syntax::feature_gate::UnstableFeatures; |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 20 | |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 21 | use errors::emitter::HumanReadableErrorType; |
Mazdak Farrokhzad | d945f98 | 2019-10-11 21:48:16 | [diff] [blame] | 22 | use errors::{ColorConfig, FatalError, Handler}; |
Jonathan Turner | 6ae35021 | 2016-06-21 22:08:13 | [diff] [blame] | 23 | |
Nick Cameron | cacd6b6 | 2015-01-30 08:44:27 | [diff] [blame] | 24 | use getopts; |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 25 | |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 26 | use std::collections::{BTreeMap, BTreeSet}; |
| 27 | use std::collections::btree_map::{ |
| 28 | Iter as BTreeMapIter, Keys as BTreeMapKeysIter, Values as BTreeMapValuesIter, |
| 29 | }; |
| 30 | use std::fmt; |
| 31 | use std::str::{self, FromStr}; |
Alex Crichton | 10c3134 | 2016-09-29 00:23:36 | [diff] [blame] | 32 | use std::hash::Hasher; |
| 33 | use std::collections::hash_map::DefaultHasher; |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 34 | use std::iter::FromIterator; |
Philipp Oppermann | 7b49190 | 2018-03-24 19:14:59 | [diff] [blame] | 35 | use std::path::{Path, PathBuf}; |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 36 | |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 37 | pub struct Config { |
Corey Richardson | 6b130e3 | 2014-07-23 18:56:36 | [diff] [blame] | 38 | pub target: Target, |
Eduard-Mihai Burtescu | 3ce31eb | 2017-08-05 09:27:28 | [diff] [blame] | 39 | pub isize_ty: IntTy, |
| 40 | pub usize_ty: UintTy, |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 41 | } |
| 42 | |
kennytm | 00dff0a | 2017-04-17 20:22:16 | [diff] [blame] | 43 | #[derive(Clone, Hash, Debug)] |
Jorge Aparicio | 9af6aa3 | 2016-12-30 04:28:11 | [diff] [blame] | 44 | pub enum Sanitizer { |
| 45 | Address, |
| 46 | Leak, |
| 47 | Memory, |
| 48 | Thread, |
| 49 | } |
| 50 | |
Wesley Wiser | 45482c6 | 2018-05-19 17:50:58 | [diff] [blame] | 51 | #[derive(Clone, Copy, Debug, PartialEq, Hash)] |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 52 | pub enum OptLevel { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 53 | No, // -O0 |
| 54 | Less, // -O1 |
| 55 | Default, // -O2 |
Brandon Edens | b1337d3 | 2016-03-27 19:42:47 | [diff] [blame] | 56 | Aggressive, // -O3 |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 57 | Size, // -Os |
| 58 | SizeMin, // -Oz |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 59 | } |
| 60 | |
Simonas Kazlauskas | f38d0da | 2018-10-27 12:29:06 | [diff] [blame] | 61 | impl_stable_hash_via_hash!(OptLevel); |
| 62 | |
Michael Woerister | 24093a6 | 2018-09-04 15:57:17 | [diff] [blame] | 63 | /// This is what the `LtoCli` values get mapped to after resolving defaults and |
| 64 | /// and taking other command line options into account. |
Nicholas Nethercote | ac6daed | 2019-10-20 04:54:53 | [diff] [blame] | 65 | #[derive(Clone, PartialEq)] |
Alex Crichton | 8bde2ac | 2018-01-16 23:02:31 | [diff] [blame] | 66 | pub enum Lto { |
| 67 | /// Don't do any LTO whatsoever |
| 68 | No, |
| 69 | |
Alex Crichton | 8bde2ac | 2018-01-16 23:02:31 | [diff] [blame] | 70 | /// Do a full crate graph LTO with ThinLTO |
| 71 | Thin, |
| 72 | |
| 73 | /// Do a local graph LTO with ThinLTO (only relevant for multiple codegen |
| 74 | /// units). |
| 75 | ThinLocal, |
| 76 | |
| 77 | /// Do a full crate graph LTO with "fat" LTO |
| 78 | Fat, |
| 79 | } |
| 80 | |
Michael Woerister | 24093a6 | 2018-09-04 15:57:17 | [diff] [blame] | 81 | /// The different settings that the `-C lto` flag can have. |
| 82 | #[derive(Clone, Copy, PartialEq, Hash, Debug)] |
| 83 | pub enum LtoCli { |
| 84 | /// `-C lto=no` |
| 85 | No, |
| 86 | /// `-C lto=yes` |
| 87 | Yes, |
| 88 | /// `-C lto` |
| 89 | NoParam, |
| 90 | /// `-C lto=thin` |
| 91 | Thin, |
| 92 | /// `-C lto=fat` |
| 93 | Fat, |
| 94 | /// No `-C lto` flag passed |
| 95 | Unspecified, |
| 96 | } |
| 97 | |
Michael Woerister | a981089 | 2018-04-25 13:45:04 | [diff] [blame] | 98 | #[derive(Clone, PartialEq, Hash)] |
Michael Woerister | 04f425d | 2019-02-01 14:15:43 | [diff] [blame] | 99 | pub enum LinkerPluginLto { |
Michael Woerister | a981089 | 2018-04-25 13:45:04 | [diff] [blame] | 100 | LinkerPlugin(PathBuf), |
Michael Woerister | 65ff414 | 2018-07-03 14:33:11 | [diff] [blame] | 101 | LinkerPluginAuto, |
Michael Woerister | a981089 | 2018-04-25 13:45:04 | [diff] [blame] | 102 | Disabled |
| 103 | } |
| 104 | |
Michael Woerister | 04f425d | 2019-02-01 14:15:43 | [diff] [blame] | 105 | impl LinkerPluginLto { |
Michael Woerister | 72df804 | 2018-07-06 11:58:25 | [diff] [blame] | 106 | pub fn enabled(&self) -> bool { |
Michael Woerister | a981089 | 2018-04-25 13:45:04 | [diff] [blame] | 107 | match *self { |
Michael Woerister | 04f425d | 2019-02-01 14:15:43 | [diff] [blame] | 108 | LinkerPluginLto::LinkerPlugin(_) | |
| 109 | LinkerPluginLto::LinkerPluginAuto => true, |
| 110 | LinkerPluginLto::Disabled => false, |
Michael Woerister | a981089 | 2018-04-25 13:45:04 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | } |
| 114 | |
Michael Woerister | 7b1df42 | 2019-04-10 11:46:37 | [diff] [blame] | 115 | #[derive(Clone, PartialEq, Hash)] |
Michael Woerister | 64ee32e | 2019-05-28 14:13:59 | [diff] [blame] | 116 | pub enum SwitchWithOptPath { |
Michael Woerister | 7b1df42 | 2019-04-10 11:46:37 | [diff] [blame] | 117 | Enabled(Option<PathBuf>), |
| 118 | Disabled, |
| 119 | } |
| 120 | |
Michael Woerister | 64ee32e | 2019-05-28 14:13:59 | [diff] [blame] | 121 | impl SwitchWithOptPath { |
Michael Woerister | 7b1df42 | 2019-04-10 11:46:37 | [diff] [blame] | 122 | pub fn enabled(&self) -> bool { |
| 123 | match *self { |
Michael Woerister | 64ee32e | 2019-05-28 14:13:59 | [diff] [blame] | 124 | SwitchWithOptPath::Enabled(_) => true, |
| 125 | SwitchWithOptPath::Disabled => false, |
Michael Woerister | 7b1df42 | 2019-04-10 11:46:37 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
Eduard-Mihai Burtescu | 2092963 | 2019-01-29 05:24:32 | [diff] [blame] | 130 | #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] |
| 131 | pub enum SymbolManglingVersion { |
| 132 | Legacy, |
| 133 | V0, |
| 134 | } |
| 135 | |
| 136 | impl_stable_hash_via_hash!(SymbolManglingVersion); |
| 137 | |
Alex Crichton | 8bde2ac | 2018-01-16 23:02:31 | [diff] [blame] | 138 | #[derive(Clone, Copy, PartialEq, Hash)] |
Mark Rousskov | 2bc7197 | 2018-07-26 17:41:10 | [diff] [blame] | 139 | pub enum DebugInfo { |
| 140 | None, |
| 141 | Limited, |
| 142 | Full, |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 143 | } |
| 144 | |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 145 | #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord, RustcEncodable, RustcDecodable)] |
Niko Matsakis | dc6e414 | 2014-11-16 01:30:33 | [diff] [blame] | 146 | pub enum OutputType { |
Alex Crichton | 8c963c0 | 2015-09-30 17:08:37 | [diff] [blame] | 147 | Bitcode, |
| 148 | Assembly, |
| 149 | LlvmAssembly, |
Jake Goulding | 9218f97 | 2017-02-16 21:59:09 | [diff] [blame] | 150 | Mir, |
Nick Cameron | 7720cf0 | 2016-12-23 06:39:20 | [diff] [blame] | 151 | Metadata, |
Alex Crichton | 8c963c0 | 2015-09-30 17:08:37 | [diff] [blame] | 152 | Object, |
| 153 | Exe, |
| 154 | DepInfo, |
Niko Matsakis | dc6e414 | 2014-11-16 01:30:33 | [diff] [blame] | 155 | } |
| 156 | |
Mark Rousskov | ac4439c | 2018-08-03 22:41:30 | [diff] [blame] | 157 | impl_stable_hash_via_hash!(OutputType); |
Michael Woerister | 74d6b85 | 2017-09-18 10:14:52 | [diff] [blame] | 158 | |
Felix S. Klock II | f90c21a | 2015-12-04 18:35:16 | [diff] [blame] | 159 | impl OutputType { |
| 160 | fn is_compatible_with_codegen_units_and_single_output_file(&self) -> bool { |
| 161 | match *self { |
Alex Crichton | 955f283 | 2019-04-25 16:06:38 | [diff] [blame] | 162 | OutputType::Exe | OutputType::DepInfo | OutputType::Metadata => true, |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 163 | OutputType::Bitcode |
| 164 | | OutputType::Assembly |
| 165 | | OutputType::LlvmAssembly |
| 166 | | OutputType::Mir |
Alex Crichton | 955f283 | 2019-04-25 16:06:38 | [diff] [blame] | 167 | | OutputType::Object => false, |
Felix S. Klock II | f90c21a | 2015-12-04 18:35:16 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | |
| 171 | fn shorthand(&self) -> &'static str { |
| 172 | match *self { |
| 173 | OutputType::Bitcode => "llvm-bc", |
| 174 | OutputType::Assembly => "asm", |
| 175 | OutputType::LlvmAssembly => "llvm-ir", |
Jake Goulding | 9218f97 | 2017-02-16 21:59:09 | [diff] [blame] | 176 | OutputType::Mir => "mir", |
Felix S. Klock II | f90c21a | 2015-12-04 18:35:16 | [diff] [blame] | 177 | OutputType::Object => "obj", |
Nick Cameron | 7720cf0 | 2016-12-23 06:39:20 | [diff] [blame] | 178 | OutputType::Metadata => "metadata", |
Felix S. Klock II | f90c21a | 2015-12-04 18:35:16 | [diff] [blame] | 179 | OutputType::Exe => "link", |
| 180 | OutputType::DepInfo => "dep-info", |
| 181 | } |
| 182 | } |
Niko Matsakis | 2f9fff21 | 2016-07-25 14:51:14 | [diff] [blame] | 183 | |
Corey Farwell | c3ea358 | 2017-11-05 14:20:59 | [diff] [blame] | 184 | fn from_shorthand(shorthand: &str) -> Option<Self> { |
| 185 | Some(match shorthand { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 186 | "asm" => OutputType::Assembly, |
| 187 | "llvm-ir" => OutputType::LlvmAssembly, |
| 188 | "mir" => OutputType::Mir, |
| 189 | "llvm-bc" => OutputType::Bitcode, |
| 190 | "obj" => OutputType::Object, |
| 191 | "metadata" => OutputType::Metadata, |
| 192 | "link" => OutputType::Exe, |
| 193 | "dep-info" => OutputType::DepInfo, |
Corey Farwell | c3ea358 | 2017-11-05 14:20:59 | [diff] [blame] | 194 | _ => return None, |
| 195 | }) |
| 196 | } |
| 197 | |
| 198 | fn shorthands_display() -> String { |
| 199 | format!( |
| 200 | "`{}`, `{}`, `{}`, `{}`, `{}`, `{}`, `{}`, `{}`", |
| 201 | OutputType::Bitcode.shorthand(), |
| 202 | OutputType::Assembly.shorthand(), |
| 203 | OutputType::LlvmAssembly.shorthand(), |
| 204 | OutputType::Mir.shorthand(), |
| 205 | OutputType::Object.shorthand(), |
| 206 | OutputType::Metadata.shorthand(), |
| 207 | OutputType::Exe.shorthand(), |
| 208 | OutputType::DepInfo.shorthand(), |
| 209 | ) |
| 210 | } |
| 211 | |
Niko Matsakis | 2f9fff21 | 2016-07-25 14:51:14 | [diff] [blame] | 212 | pub fn extension(&self) -> &'static str { |
| 213 | match *self { |
| 214 | OutputType::Bitcode => "bc", |
| 215 | OutputType::Assembly => "s", |
| 216 | OutputType::LlvmAssembly => "ll", |
Jake Goulding | 9218f97 | 2017-02-16 21:59:09 | [diff] [blame] | 217 | OutputType::Mir => "mir", |
Niko Matsakis | 2f9fff21 | 2016-07-25 14:51:14 | [diff] [blame] | 218 | OutputType::Object => "o", |
Nick Cameron | 7720cf0 | 2016-12-23 06:39:20 | [diff] [blame] | 219 | OutputType::Metadata => "rmeta", |
Niko Matsakis | 2f9fff21 | 2016-07-25 14:51:14 | [diff] [blame] | 220 | OutputType::DepInfo => "d", |
| 221 | OutputType::Exe => "", |
| 222 | } |
| 223 | } |
Felix S. Klock II | f90c21a | 2015-12-04 18:35:16 | [diff] [blame] | 224 | } |
| 225 | |
Philipp Hansch | 33137ff | 2019-06-10 08:59:03 | [diff] [blame] | 226 | /// The type of diagnostics output to generate. |
Nick Cameron | b286a2f | 2016-10-25 22:14:02 | [diff] [blame] | 227 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 228 | pub enum ErrorOutputType { |
Philipp Hansch | e3516a1 | 2019-06-09 10:04:40 | [diff] [blame] | 229 | /// Output meant for the consumption of humans. |
Oliver Scherer | 39b2137 | 2019-03-25 10:16:58 | [diff] [blame] | 230 | HumanReadable(HumanReadableErrorType), |
Philipp Hansch | e3516a1 | 2019-06-09 10:04:40 | [diff] [blame] | 231 | /// Output that's consumed by other tools such as `rustfix` or the `RLS`. |
Oliver Scherer | 96404ee | 2019-03-12 12:06:43 | [diff] [blame] | 232 | Json { |
Philipp Hansch | 33137ff | 2019-06-10 08:59:03 | [diff] [blame] | 233 | /// Render the JSON in a human readable way (with indents and newlines). |
Oliver Scherer | 96404ee | 2019-03-12 12:06:43 | [diff] [blame] | 234 | pretty: bool, |
Philipp Hansch | e3516a1 | 2019-06-09 10:04:40 | [diff] [blame] | 235 | /// The JSON output includes a `rendered` field that includes the rendered |
| 236 | /// human output. |
Oliver Scherer | 39b2137 | 2019-03-25 10:16:58 | [diff] [blame] | 237 | json_rendered: HumanReadableErrorType, |
Oliver Scherer | 96404ee | 2019-03-12 12:06:43 | [diff] [blame] | 238 | }, |
Nick Cameron | b286a2f | 2016-10-25 22:14:02 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | impl Default for ErrorOutputType { |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 242 | fn default() -> Self { |
| 243 | Self::HumanReadable(HumanReadableErrorType::Default(ColorConfig::Auto)) |
Nick Cameron | b286a2f | 2016-10-25 22:14:02 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 247 | /// Use tree-based collections to cheaply get a deterministic `Hash` implementation. |
| 248 | /// *Do not* switch `BTreeMap` out for an unsorted container type! That would break |
| 249 | /// dependency tracking for command-line arguments. |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 250 | #[derive(Clone, Hash)] |
| 251 | pub struct OutputTypes(BTreeMap<OutputType, Option<PathBuf>>); |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 252 | |
Mark Rousskov | ac4439c | 2018-08-03 22:41:30 | [diff] [blame] | 253 | impl_stable_hash_via_hash!(OutputTypes); |
Michael Woerister | 74d6b85 | 2017-09-18 10:14:52 | [diff] [blame] | 254 | |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 255 | impl OutputTypes { |
| 256 | pub fn new(entries: &[(OutputType, Option<PathBuf>)]) -> OutputTypes { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 257 | OutputTypes(BTreeMap::from_iter( |
| 258 | entries.iter().map(|&(k, ref v)| (k, v.clone())), |
| 259 | )) |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 260 | } |
Niko Matsakis | d09fd1a | 2016-01-29 20:07:04 | [diff] [blame] | 261 | |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 262 | pub fn get(&self, key: &OutputType) -> Option<&Option<PathBuf>> { |
| 263 | self.0.get(key) |
| 264 | } |
Niko Matsakis | d09fd1a | 2016-01-29 20:07:04 | [diff] [blame] | 265 | |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 266 | pub fn contains_key(&self, key: &OutputType) -> bool { |
| 267 | self.0.contains_key(key) |
| 268 | } |
| 269 | |
Jeremy Stucki | d28832d | 2019-06-21 21:49:03 | [diff] [blame] | 270 | pub fn keys(&self) -> BTreeMapKeysIter<'_, OutputType, Option<PathBuf>> { |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 271 | self.0.keys() |
| 272 | } |
| 273 | |
Jeremy Stucki | d28832d | 2019-06-21 21:49:03 | [diff] [blame] | 274 | pub fn values(&self) -> BTreeMapValuesIter<'_, OutputType, Option<PathBuf>> { |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 275 | self.0.values() |
| 276 | } |
Nick Cameron | b059a80 | 2016-12-29 00:23:38 | [diff] [blame] | 277 | |
varkor | 8414520 | 2018-03-27 23:13:34 | [diff] [blame] | 278 | pub fn len(&self) -> usize { |
| 279 | self.0.len() |
| 280 | } |
| 281 | |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 282 | // Returns `true` if any of the output types require codegen or linking. |
Irina Popa | b63d7e2 | 2018-05-08 13:10:16 | [diff] [blame] | 283 | pub fn should_codegen(&self) -> bool { |
Nick Cameron | b059a80 | 2016-12-29 00:23:38 | [diff] [blame] | 284 | self.0.keys().any(|k| match *k { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 285 | OutputType::Bitcode |
| 286 | | OutputType::Assembly |
| 287 | | OutputType::LlvmAssembly |
| 288 | | OutputType::Mir |
| 289 | | OutputType::Object |
| 290 | | OutputType::Exe => true, |
| 291 | OutputType::Metadata | OutputType::DepInfo => false, |
Nick Cameron | b059a80 | 2016-12-29 00:23:38 | [diff] [blame] | 292 | }) |
| 293 | } |
Brian Anderson | c27133e | 2015-01-06 14:26:08 | [diff] [blame] | 294 | } |
| 295 | |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 296 | /// Use tree-based collections to cheaply get a deterministic `Hash` implementation. |
| 297 | /// *Do not* switch `BTreeMap` or `BTreeSet` out for an unsorted container type! That |
| 298 | /// would break dependency tracking for command-line arguments. |
Nicholas Nethercote | ac6daed | 2019-10-20 04:54:53 | [diff] [blame] | 299 | #[derive(Clone)] |
Aaron Hill | 482b77a | 2019-04-07 22:48:40 | [diff] [blame] | 300 | pub struct Externs(BTreeMap<String, ExternEntry>); |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 301 | |
Nicholas Nethercote | ac6daed | 2019-10-20 04:54:53 | [diff] [blame] | 302 | #[derive(Clone, Debug, Default)] |
Aaron Hill | 7cc3ce3 | 2019-03-25 03:06:32 | [diff] [blame] | 303 | pub struct ExternEntry { |
Aaron Hill | 482b77a | 2019-04-07 22:48:40 | [diff] [blame] | 304 | pub locations: BTreeSet<Option<String>>, |
| 305 | pub is_private_dep: bool |
Aaron Hill | 7cc3ce3 | 2019-03-25 03:06:32 | [diff] [blame] | 306 | } |
Aaron Hill | 21491dc | 2019-03-21 03:27:08 | [diff] [blame] | 307 | |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 308 | impl Externs { |
Aaron Hill | 482b77a | 2019-04-07 22:48:40 | [diff] [blame] | 309 | pub fn new(data: BTreeMap<String, ExternEntry>) -> Externs { |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 310 | Externs(data) |
| 311 | } |
| 312 | |
Aaron Hill | 482b77a | 2019-04-07 22:48:40 | [diff] [blame] | 313 | pub fn get(&self, key: &str) -> Option<&ExternEntry> { |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 314 | self.0.get(key) |
| 315 | } |
| 316 | |
Jeremy Stucki | d28832d | 2019-06-21 21:49:03 | [diff] [blame] | 317 | pub fn iter(&self) -> BTreeMapIter<'_, String, ExternEntry> { |
Aaron Hill | 21491dc | 2019-03-21 03:27:08 | [diff] [blame] | 318 | self.0.iter() |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 323 | macro_rules! hash_option { |
| 324 | ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, [UNTRACKED]) => ({}); |
| 325 | ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, [TRACKED]) => ({ |
| 326 | if $sub_hashes.insert(stringify!($opt_name), |
Manish Goregaokar | f3cb962 | 2018-02-23 18:02:10 | [diff] [blame] | 327 | $opt_expr as &dyn dep_tracking::DepTrackingHash).is_some() { |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 328 | bug!("duplicate key in CLI DepTrackingHash: {}", stringify!($opt_name)) |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 329 | } |
| 330 | }); |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | macro_rules! top_level_options { |
| 334 | (pub struct Options { $( |
| 335 | $opt:ident : $t:ty [$dep_tracking_marker:ident $($warn_val:expr, $warn_text:expr)*], |
| 336 | )* } ) => ( |
| 337 | #[derive(Clone)] |
| 338 | pub struct Options { |
| 339 | $(pub $opt: $t),* |
| 340 | } |
| 341 | |
| 342 | impl Options { |
| 343 | pub fn dep_tracking_hash(&self) -> u64 { |
| 344 | let mut sub_hashes = BTreeMap::new(); |
| 345 | $({ |
| 346 | hash_option!($opt, |
| 347 | &self.$opt, |
| 348 | &mut sub_hashes, |
| 349 | [$dep_tracking_marker $($warn_val, |
| 350 | $warn_text, |
| 351 | self.error_format)*]); |
| 352 | })* |
Alex Crichton | 10c3134 | 2016-09-29 00:23:36 | [diff] [blame] | 353 | let mut hasher = DefaultHasher::new(); |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 354 | dep_tracking::stable_hash(sub_hashes, |
| 355 | &mut hasher, |
| 356 | self.error_format); |
| 357 | hasher.finish() |
| 358 | } |
| 359 | } |
| 360 | ); |
| 361 | } |
| 362 | |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 363 | // The top-level command-line options struct. |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 364 | // |
| 365 | // For each option, one has to specify how it behaves with regard to the |
| 366 | // dependency tracking system of incremental compilation. This is done via the |
| 367 | // square-bracketed directive after the field type. The options are: |
| 368 | // |
| 369 | // [TRACKED] |
| 370 | // A change in the given field will cause the compiler to completely clear the |
| 371 | // incremental compilation cache before proceeding. |
| 372 | // |
| 373 | // [UNTRACKED] |
| 374 | // Incremental compilation is not influenced by this option. |
| 375 | // |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 376 | // If you add a new option to this struct or one of the sub-structs like |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 377 | // `CodegenOptions`, think about how it influences incremental compilation. If in |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 378 | // doubt, specify [TRACKED], which is always "correct" but might lead to |
| 379 | // unnecessary re-compilation. |
| 380 | top_level_options!( |
| 381 | pub struct Options { |
| 382 | // The crate config requested for the session, which may be combined |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 383 | // with additional crate configurations during the compile process. |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 384 | crate_types: Vec<CrateType> [TRACKED], |
| 385 | optimize: OptLevel [TRACKED], |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 386 | // Include the `debug_assertions` flag in dependency tracking, since it |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 387 | // can influence whether overflow checks are done or not. |
| 388 | debug_assertions: bool [TRACKED], |
Mark Rousskov | 2bc7197 | 2018-07-26 17:41:10 | [diff] [blame] | 389 | debuginfo: DebugInfo [TRACKED], |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 390 | lint_opts: Vec<(String, lint::Level)> [TRACKED], |
| 391 | lint_cap: Option<lint::Level> [TRACKED], |
| 392 | describe_lints: bool [UNTRACKED], |
| 393 | output_types: OutputTypes [TRACKED], |
Nicholas Nethercote | f130061 | 2018-11-22 05:33:07 | [diff] [blame] | 394 | search_paths: Vec<SearchPath> [UNTRACKED], |
Peter Wagenet | ae32b6e | 2017-02-21 21:18:58 | [diff] [blame] | 395 | libs: Vec<(String, Option<String>, Option<cstore::NativeLibraryKind>)> [TRACKED], |
Joel Galenson | e9e45c5 | 2019-08-12 16:34:41 | [diff] [blame] | 396 | maybe_sysroot: Option<PathBuf> [UNTRACKED], |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 397 | |
Philipp Oppermann | 3908b2e | 2018-03-14 14:27:06 | [diff] [blame] | 398 | target_triple: TargetTriple [TRACKED], |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 399 | |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 400 | test: bool [TRACKED], |
| 401 | error_format: ErrorOutputType [UNTRACKED], |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 402 | |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 403 | // If `Some`, enable incremental compilation, using the given |
| 404 | // directory to store intermediate results. |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 405 | incremental: Option<PathBuf> [UNTRACKED], |
| 406 | |
| 407 | debugging_opts: DebuggingOptions [TRACKED], |
| 408 | prints: Vec<PrintRequest> [UNTRACKED], |
est31 | c9af68e | 2017-11-19 22:35:53 | [diff] [blame] | 409 | // Determines which borrow checker(s) to run. This is the parsed, sanitized |
| 410 | // version of `debugging_opts.borrowck`, which is just a plain string. |
| 411 | borrowck_mode: BorrowckMode [UNTRACKED], |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 412 | cg: CodegenOptions [TRACKED], |
Alex Crichton | 2e9d9d4 | 2018-03-01 15:51:00 | [diff] [blame] | 413 | externs: Externs [UNTRACKED], |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 414 | crate_name: Option<String> [TRACKED], |
| 415 | // An optional name to use as the crate for std during std injection, |
Vadim Petrochenkov | c6c6cf9 | 2018-03-09 15:51:48 | [diff] [blame] | 416 | // written `extern crate name as std`. Defaults to `std`. Used by |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 417 | // out-of-tree drivers. |
| 418 | alt_std_name: Option<String> [TRACKED], |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 419 | // Indicates how the compiler should treat unstable features. |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 420 | unstable_features: UnstableFeatures [TRACKED], |
Alex Crichton | 7724a04 | 2016-09-30 02:10:29 | [diff] [blame] | 421 | |
| 422 | // Indicates whether this run of the compiler is actually rustdoc. This |
| 423 | // is currently just a hack and will be removed eventually, so please |
| 424 | // try to not rely on this too much. |
| 425 | actually_rustdoc: bool [TRACKED], |
Alex Crichton | 9e35b79 | 2017-09-25 19:26:25 | [diff] [blame] | 426 | |
Alex Crichton | 855f6d1 | 2017-11-25 19:13:58 | [diff] [blame] | 427 | // Specifications of codegen units / ThinLTO which are forced as a |
| 428 | // result of parsing command line options. These are not necessarily |
| 429 | // what rustc was invoked with, but massaged a bit to agree with |
| 430 | // commands like `--emit llvm-ir` which they're often incompatible with |
| 431 | // if we otherwise use the defaults of rustc. |
Alex Crichton | 5187763 | 2017-10-04 21:38:52 | [diff] [blame] | 432 | cli_forced_codegen_units: Option<usize> [UNTRACKED], |
Alex Crichton | 8bde2ac | 2018-01-16 23:02:31 | [diff] [blame] | 433 | cli_forced_thinlto_off: bool [UNTRACKED], |
Jeremy Fitzhardinge | 56a6828 | 2018-02-18 23:05:24 | [diff] [blame] | 434 | |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 435 | // Remap source path prefixes in all output (messages, object files, debug, etc.). |
Jeremy Fitzhardinge | 56a6828 | 2018-02-18 23:05:24 | [diff] [blame] | 436 | remap_path_prefix: Vec<(PathBuf, PathBuf)> [UNTRACKED], |
Michael Woerister | a981089 | 2018-04-25 13:45:04 | [diff] [blame] | 437 | |
Kurtis Nusbaum | 320fdaa | 2018-04-20 04:03:21 | [diff] [blame] | 438 | edition: Edition [TRACKED], |
Alex Crichton | 1731233 | 2019-07-17 19:52:56 | [diff] [blame] | 439 | |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 440 | // `true` if we're emitting JSON blobs about each artifact produced |
Alex Crichton | 1731233 | 2019-07-17 19:52:56 | [diff] [blame] | 441 | // by the compiler. |
| 442 | json_artifact_notifications: bool [TRACKED], |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 443 | } |
| 444 | ); |
| 445 | |
Robin Kruppe | e3f6e68 | 2017-04-30 18:33:25 | [diff] [blame] | 446 | #[derive(Copy, Clone, PartialEq, Eq, Debug)] |
Alex Crichton | 117984b | 2014-12-16 00:03:39 | [diff] [blame] | 447 | pub enum PrintRequest { |
| 448 | FileNames, |
| 449 | Sysroot, |
| 450 | CrateName, |
Alex Crichton | a1ffe6b | 2016-01-25 19:36:18 | [diff] [blame] | 451 | Cfg, |
Jorge Aparicio | 0bb4209 | 2016-02-12 15:11:58 | [diff] [blame] | 452 | TargetList, |
Cameron Hart | e1efa32 | 2016-07-10 14:22:13 | [diff] [blame] | 453 | TargetCPUs, |
| 454 | TargetFeatures, |
| 455 | RelocationModels, |
| 456 | CodeModels, |
Amanieu d'Antras | b233a6e | 2017-10-31 18:24:04 | [diff] [blame] | 457 | TlsModels, |
Doug Goldstein | ff11264 | 2016-04-07 21:36:35 | [diff] [blame] | 458 | TargetSpec, |
Kornel | 2920658 | 2017-08-22 20:20:42 | [diff] [blame] | 459 | NativeStaticLibs, |
Alex Crichton | 117984b | 2014-12-16 00:03:39 | [diff] [blame] | 460 | } |
| 461 | |
Nicholas Nethercote | ac6daed | 2019-10-20 04:54:53 | [diff] [blame] | 462 | #[derive(Copy, Clone)] |
est31 | c9af68e | 2017-11-19 22:35:53 | [diff] [blame] | 463 | pub enum BorrowckMode { |
est31 | c9af68e | 2017-11-19 22:35:53 | [diff] [blame] | 464 | Mir, |
Felix S. Klock II | a23e8a7 | 2018-07-20 15:29:29 | [diff] [blame] | 465 | Migrate, |
est31 | c9af68e | 2017-11-19 22:35:53 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | impl BorrowckMode { |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 469 | /// Returns whether we should run the MIR-based borrow check, but also fall back |
Felix S. Klock II | a23e8a7 | 2018-07-20 15:29:29 | [diff] [blame] | 470 | /// on the AST borrow check if the MIR-based one errors. |
| 471 | pub fn migrate(self) -> bool { |
| 472 | match self { |
Felix S. Klock II | a23e8a7 | 2018-07-20 15:29:29 | [diff] [blame] | 473 | BorrowckMode::Mir => false, |
| 474 | BorrowckMode::Migrate => true, |
| 475 | } |
| 476 | } |
est31 | c9af68e | 2017-11-19 22:35:53 | [diff] [blame] | 477 | } |
| 478 | |
Niko Matsakis | e135fa5 | 2014-11-27 12:21:26 | [diff] [blame] | 479 | pub enum Input { |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 480 | /// Load source code from a file. |
Alex Crichton | 95d9046 | 2015-02-27 05:00:43 | [diff] [blame] | 481 | File(PathBuf), |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 482 | /// Load source code from a string. |
mitaa | ea7cf90 | 2016-03-10 03:49:40 | [diff] [blame] | 483 | Str { |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 484 | /// A string that is shown in place of a filename. |
Oliver Schneider | d732da8 | 2017-12-14 07:09:19 | [diff] [blame] | 485 | name: FileName, |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 486 | /// An anonymous string containing the source code. |
mitaa | ea7cf90 | 2016-03-10 03:49:40 | [diff] [blame] | 487 | input: String, |
| 488 | }, |
Niko Matsakis | e135fa5 | 2014-11-27 12:21:26 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | impl Input { |
ljedrz | 675f00b | 2018-10-10 13:30:53 | [diff] [blame] | 492 | pub fn filestem(&self) -> &str { |
Niko Matsakis | e135fa5 | 2014-11-27 12:21:26 | [diff] [blame] | 493 | match *self { |
ljedrz | 675f00b | 2018-10-10 13:30:53 | [diff] [blame] | 494 | Input::File(ref ifile) => ifile.file_stem().unwrap().to_str().unwrap(), |
| 495 | Input::Str { .. } => "rust_out", |
Niko Matsakis | e135fa5 | 2014-11-27 12:21:26 | [diff] [blame] | 496 | } |
| 497 | } |
Guillaume Gomez | dadfa13 | 2018-05-10 18:13:25 | [diff] [blame] | 498 | |
| 499 | pub fn get_input(&mut self) -> Option<&mut String> { |
| 500 | match *self { |
| 501 | Input::File(_) => None, |
| 502 | Input::Str { ref mut input, .. } => Some(input), |
| 503 | } |
| 504 | } |
John Kåre Alsaker | 23a51f9 | 2018-12-08 19:30:23 | [diff] [blame] | 505 | |
| 506 | pub fn source_name(&self) -> FileName { |
| 507 | match *self { |
| 508 | Input::File(ref ifile) => ifile.clone().into(), |
| 509 | Input::Str { ref name, .. } => name.clone(), |
| 510 | } |
| 511 | } |
Niko Matsakis | e135fa5 | 2014-11-27 12:21:26 | [diff] [blame] | 512 | } |
| 513 | |
Mark Rousskov | ac4439c | 2018-08-03 22:41:30 | [diff] [blame] | 514 | #[derive(Clone, Hash)] |
Niko Matsakis | e135fa5 | 2014-11-27 12:21:26 | [diff] [blame] | 515 | pub struct OutputFilenames { |
Alex Crichton | 95d9046 | 2015-02-27 05:00:43 | [diff] [blame] | 516 | pub out_directory: PathBuf, |
Niko Matsakis | e135fa5 | 2014-11-27 12:21:26 | [diff] [blame] | 517 | pub out_filestem: String, |
Alex Crichton | 95d9046 | 2015-02-27 05:00:43 | [diff] [blame] | 518 | pub single_output_file: Option<PathBuf>, |
Niko Matsakis | e135fa5 | 2014-11-27 12:21:26 | [diff] [blame] | 519 | pub extra: String, |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 520 | pub outputs: OutputTypes, |
Niko Matsakis | e135fa5 | 2014-11-27 12:21:26 | [diff] [blame] | 521 | } |
| 522 | |
Mark Rousskov | ac4439c | 2018-08-03 22:41:30 | [diff] [blame] | 523 | impl_stable_hash_via_hash!(OutputFilenames); |
Michael Woerister | 74d6b85 | 2017-09-18 10:14:52 | [diff] [blame] | 524 | |
Vadim Petrochenkov | d588f93 | 2017-11-03 19:41:15 | [diff] [blame] | 525 | pub const RUST_CGU_EXT: &str = "rcgu"; |
Michael Woerister | 65e8a13 | 2016-05-14 00:48:32 | [diff] [blame] | 526 | |
Niko Matsakis | e135fa5 | 2014-11-27 12:21:26 | [diff] [blame] | 527 | impl OutputFilenames { |
Alex Crichton | 95d9046 | 2015-02-27 05:00:43 | [diff] [blame] | 528 | pub fn path(&self, flavor: OutputType) -> PathBuf { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 529 | self.outputs |
| 530 | .get(&flavor) |
| 531 | .and_then(|p| p.to_owned()) |
Alex Crichton | 8c963c0 | 2015-09-30 17:08:37 | [diff] [blame] | 532 | .or_else(|| self.single_output_file.clone()) |
Michael Woerister | 65e8a13 | 2016-05-14 00:48:32 | [diff] [blame] | 533 | .unwrap_or_else(|| self.temp_path(flavor, None)) |
Niko Matsakis | e135fa5 | 2014-11-27 12:21:26 | [diff] [blame] | 534 | } |
| 535 | |
Alexander Regueiro | c3e182c | 2019-02-08 13:53:55 | [diff] [blame] | 536 | /// Gets the path where a compilation artifact of the given type for the |
Michael Woerister | 65e8a13 | 2016-05-14 00:48:32 | [diff] [blame] | 537 | /// given codegen unit should be placed on disk. If codegen_unit_name is |
| 538 | /// None, a path distinct from those of any codegen unit will be generated. |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 539 | pub fn temp_path(&self, flavor: OutputType, codegen_unit_name: Option<&str>) -> PathBuf { |
Niko Matsakis | 2f9fff21 | 2016-07-25 14:51:14 | [diff] [blame] | 540 | let extension = flavor.extension(); |
Michael Woerister | 65e8a13 | 2016-05-14 00:48:32 | [diff] [blame] | 541 | self.temp_path_ext(extension, codegen_unit_name) |
| 542 | } |
| 543 | |
| 544 | /// Like temp_path, but also supports things where there is no corresponding |
Alexander Regueiro | c3e182c | 2019-02-08 13:53:55 | [diff] [blame] | 545 | /// OutputType, like noopt-bitcode or lto-bitcode. |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 546 | pub fn temp_path_ext(&self, ext: &str, codegen_unit_name: Option<&str>) -> PathBuf { |
Alex Crichton | 95d9046 | 2015-02-27 05:00:43 | [diff] [blame] | 547 | let base = self.out_directory.join(&self.filestem()); |
Michael Woerister | 65e8a13 | 2016-05-14 00:48:32 | [diff] [blame] | 548 | |
| 549 | let mut extension = String::new(); |
| 550 | |
| 551 | if let Some(codegen_unit_name) = codegen_unit_name { |
Alex Crichton | 4ca1b19 | 2017-07-23 15:14:38 | [diff] [blame] | 552 | extension.push_str(codegen_unit_name); |
Niko Matsakis | e135fa5 | 2014-11-27 12:21:26 | [diff] [blame] | 553 | } |
Michael Woerister | 65e8a13 | 2016-05-14 00:48:32 | [diff] [blame] | 554 | |
| 555 | if !ext.is_empty() { |
| 556 | if !extension.is_empty() { |
| 557 | extension.push_str("."); |
Alex Crichton | 4ca1b19 | 2017-07-23 15:14:38 | [diff] [blame] | 558 | extension.push_str(RUST_CGU_EXT); |
| 559 | extension.push_str("."); |
Michael Woerister | 65e8a13 | 2016-05-14 00:48:32 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | extension.push_str(ext); |
| 563 | } |
| 564 | |
| 565 | let path = base.with_extension(&extension[..]); |
| 566 | path |
Niko Matsakis | e135fa5 | 2014-11-27 12:21:26 | [diff] [blame] | 567 | } |
| 568 | |
Alex Crichton | 95d9046 | 2015-02-27 05:00:43 | [diff] [blame] | 569 | pub fn with_extension(&self, extension: &str) -> PathBuf { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 570 | self.out_directory |
| 571 | .join(&self.filestem()) |
| 572 | .with_extension(extension) |
Niko Matsakis | e135fa5 | 2014-11-27 12:21:26 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | pub fn filestem(&self) -> String { |
| 576 | format!("{}{}", self.out_filestem, self.extra) |
| 577 | } |
| 578 | } |
| 579 | |
Niko Matsakis | dc6e414 | 2014-11-16 01:30:33 | [diff] [blame] | 580 | pub fn host_triple() -> &'static str { |
| 581 | // Get the host triple out of the build environment. This ensures that our |
| 582 | // idea of the host triple is the same as for the set of libraries we've |
| 583 | // actually built. We can't just take LLVM's host triple because they |
| 584 | // normalize all ix86 architectures to i386. |
| 585 | // |
| 586 | // Instead of grabbing the host triple (for the current host), we grab (at |
| 587 | // compile time) the target triple that this rustc is built with and |
| 588 | // calling that (at runtime) the host triple. |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 589 | (option_env!("CFG_COMPILER_HOST_TRIPLE")).expect("CFG_COMPILER_HOST_TRIPLE") |
Niko Matsakis | dc6e414 | 2014-11-16 01:30:33 | [diff] [blame] | 590 | } |
| 591 | |
Mark Rousskov | 5fcef25 | 2018-07-26 18:36:11 | [diff] [blame] | 592 | impl Default for Options { |
| 593 | fn default() -> Options { |
| 594 | Options { |
| 595 | crate_types: Vec::new(), |
| 596 | optimize: OptLevel::No, |
| 597 | debuginfo: DebugInfo::None, |
| 598 | lint_opts: Vec::new(), |
| 599 | lint_cap: None, |
| 600 | describe_lints: false, |
| 601 | output_types: OutputTypes(BTreeMap::new()), |
Nicholas Nethercote | f130061 | 2018-11-22 05:33:07 | [diff] [blame] | 602 | search_paths: vec![], |
Mark Rousskov | 5fcef25 | 2018-07-26 18:36:11 | [diff] [blame] | 603 | maybe_sysroot: None, |
| 604 | target_triple: TargetTriple::from_triple(host_triple()), |
| 605 | test: false, |
| 606 | incremental: None, |
| 607 | debugging_opts: basic_debugging_options(), |
| 608 | prints: Vec::new(), |
Matthew Jasper | aa6fb6c | 2019-01-26 17:25:37 | [diff] [blame] | 609 | borrowck_mode: BorrowckMode::Migrate, |
Mark Rousskov | 5fcef25 | 2018-07-26 18:36:11 | [diff] [blame] | 610 | cg: basic_codegen_options(), |
| 611 | error_format: ErrorOutputType::default(), |
| 612 | externs: Externs(BTreeMap::new()), |
| 613 | crate_name: None, |
| 614 | alt_std_name: None, |
| 615 | libs: Vec::new(), |
| 616 | unstable_features: UnstableFeatures::Disallow, |
| 617 | debug_assertions: true, |
| 618 | actually_rustdoc: false, |
| 619 | cli_forced_codegen_units: None, |
| 620 | cli_forced_thinlto_off: false, |
| 621 | remap_path_prefix: Vec::new(), |
| 622 | edition: DEFAULT_EDITION, |
Alex Crichton | 1731233 | 2019-07-17 19:52:56 | [diff] [blame] | 623 | json_artifact_notifications: false, |
Mark Rousskov | 5fcef25 | 2018-07-26 18:36:11 | [diff] [blame] | 624 | } |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 625 | } |
| 626 | } |
| 627 | |
Niko Matsakis | fe47ca0 | 2016-03-28 21:43:36 | [diff] [blame] | 628 | impl Options { |
Alexander Regueiro | c3e182c | 2019-02-08 13:53:55 | [diff] [blame] | 629 | /// Returns `true` if there is a reason to build the dep graph. |
Niko Matsakis | fe47ca0 | 2016-03-28 21:43:36 | [diff] [blame] | 630 | pub fn build_dep_graph(&self) -> bool { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 631 | self.incremental.is_some() || self.debugging_opts.dump_dep_graph |
| 632 | || self.debugging_opts.query_dep_graph |
Niko Matsakis | fe47ca0 | 2016-03-28 21:43:36 | [diff] [blame] | 633 | } |
Michael Woerister | 59cfe90 | 2016-07-13 21:03:02 | [diff] [blame] | 634 | |
Michael Woerister | ca0a403 | 2017-06-23 14:37:12 | [diff] [blame] | 635 | #[inline(always)] |
| 636 | pub fn enable_dep_node_debug_strs(&self) -> bool { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 637 | cfg!(debug_assertions) |
| 638 | && (self.debugging_opts.query_dep_graph || self.debugging_opts.incremental_info) |
Michael Woerister | ca0a403 | 2017-06-23 14:37:12 | [diff] [blame] | 639 | } |
| 640 | |
Michael Woerister | 39ffea3 | 2017-04-24 17:01:19 | [diff] [blame] | 641 | pub fn file_path_mapping(&self) -> FilePathMapping { |
Jeremy Fitzhardinge | 56a6828 | 2018-02-18 23:05:24 | [diff] [blame] | 642 | FilePathMapping::new(self.remap_path_prefix.clone()) |
Michael Woerister | 39ffea3 | 2017-04-24 17:01:19 | [diff] [blame] | 643 | } |
varkor | c76cdce | 2017-12-18 15:35:45 | [diff] [blame] | 644 | |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 645 | /// Returns `true` if there will be an output file generated. |
varkor | c76cdce | 2017-12-18 15:35:45 | [diff] [blame] | 646 | pub fn will_create_output_file(&self) -> bool { |
| 647 | !self.debugging_opts.parse_only && // The file is just being parsed |
| 648 | !self.debugging_opts.ls // The file is just being queried |
| 649 | } |
Mark Rousskov | a9093a4 | 2018-07-26 19:20:47 | [diff] [blame] | 650 | |
| 651 | #[inline] |
| 652 | pub fn share_generics(&self) -> bool { |
| 653 | match self.debugging_opts.share_generics { |
| 654 | Some(setting) => setting, |
| 655 | None => { |
Mark Rousskov | a9093a4 | 2018-07-26 19:20:47 | [diff] [blame] | 656 | match self.optimize { |
| 657 | OptLevel::No | |
| 658 | OptLevel::Less | |
| 659 | OptLevel::Size | |
| 660 | OptLevel::SizeMin => true, |
| 661 | OptLevel::Default | |
| 662 | OptLevel::Aggressive => false, |
| 663 | } |
| 664 | } |
| 665 | } |
| 666 | } |
Niko Matsakis | fe47ca0 | 2016-03-28 21:43:36 | [diff] [blame] | 667 | } |
| 668 | |
Igor Matuszewski | ff19a53 | 2019-01-13 12:06:26 | [diff] [blame] | 669 | // The type of entry function, so users can have their own entry functions |
| 670 | #[derive(Copy, Clone, PartialEq, Hash, Debug)] |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 671 | pub enum EntryFnType { |
Mark Rousskov | 442a474 | 2018-07-26 17:29:45 | [diff] [blame] | 672 | Main, |
| 673 | Start, |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 674 | } |
| 675 | |
Igor Matuszewski | ff19a53 | 2019-01-13 12:06:26 | [diff] [blame] | 676 | impl_stable_hash_via_hash!(EntryFnType); |
| 677 | |
Alex Crichton | 5d531ae | 2019-09-16 20:34:57 | [diff] [blame] | 678 | #[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash, Debug, HashStable)] |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 679 | pub enum CrateType { |
Mark Rousskov | 2a93442 | 2018-07-26 17:13:11 | [diff] [blame] | 680 | Executable, |
| 681 | Dylib, |
| 682 | Rlib, |
| 683 | Staticlib, |
| 684 | Cdylib, |
| 685 | ProcMacro, |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 686 | } |
| 687 | |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 688 | #[derive(Clone, Hash)] |
Keegan McAllister | ad9a1da | 2014-09-12 15:17:58 | [diff] [blame] | 689 | pub enum Passes { |
Mark Rousskov | b3267dc | 2018-07-26 17:22:14 | [diff] [blame] | 690 | Some(Vec<String>), |
| 691 | All, |
Keegan McAllister | ad9a1da | 2014-09-12 15:17:58 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | impl Passes { |
| 695 | pub fn is_empty(&self) -> bool { |
| 696 | match *self { |
Mark Rousskov | b3267dc | 2018-07-26 17:22:14 | [diff] [blame] | 697 | Passes::Some(ref v) => v.is_empty(), |
| 698 | Passes::All => false, |
Keegan McAllister | ad9a1da | 2014-09-12 15:17:58 | [diff] [blame] | 699 | } |
| 700 | } |
| 701 | } |
| 702 | |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 703 | /// Defines all `CodegenOptions`/`DebuggingOptions` fields and parsers all at once. The goal of this |
Alexander Regueiro | fd48ca2 | 2019-09-06 20:05:37 | [diff] [blame] | 704 | /// macro is to define an interface that can be programmatically used by the option parser |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 705 | /// to initialize the struct without hardcoding field names all over the place. |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 706 | /// |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 707 | /// The goal is to invoke this macro once with the correct fields, and then this macro generates all |
Alexander Regueiro | fd48ca2 | 2019-09-06 20:05:37 | [diff] [blame] | 708 | /// necessary code. The main gotcha of this macro is the `cgsetters` module which is a bunch of |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 709 | /// generated code to parse an option into its respective field in the struct. There are a few |
| 710 | /// hand-written parsers for parsing specific types of values in this module. |
Manish Goregaokar | 3248bc5 | 2014-12-09 09:44:01 | [diff] [blame] | 711 | macro_rules! options { |
| 712 | ($struct_name:ident, $setter_name:ident, $defaultfn:ident, |
| 713 | $buildfn:ident, $prefix:expr, $outputname:expr, |
| 714 | $stat:ident, $mod_desc:ident, $mod_set:ident, |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 715 | $($opt:ident : $t:ty = ( |
| 716 | $init:expr, |
| 717 | $parse:ident, |
| 718 | [$dep_tracking_marker:ident $(($dep_warn_val:expr, $dep_warn_text:expr))*], |
| 719 | $desc:expr) |
| 720 | ),* ,) => |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 721 | ( |
Jorge Aparicio | 351409a | 2015-01-04 03:54:18 | [diff] [blame] | 722 | #[derive(Clone)] |
Manish Goregaokar | 3248bc5 | 2014-12-09 09:44:01 | [diff] [blame] | 723 | pub struct $struct_name { $(pub $opt: $t),* } |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 724 | |
Manish Goregaokar | 3248bc5 | 2014-12-09 09:44:01 | [diff] [blame] | 725 | pub fn $defaultfn() -> $struct_name { |
| 726 | $struct_name { $($opt: $init),* } |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 727 | } |
| 728 | |
Nick Cameron | 82f8e5c | 2016-01-06 20:23:01 | [diff] [blame] | 729 | pub fn $buildfn(matches: &getopts::Matches, error_format: ErrorOutputType) -> $struct_name |
Manish Goregaokar | 3248bc5 | 2014-12-09 09:44:01 | [diff] [blame] | 730 | { |
| 731 | let mut op = $defaultfn(); |
Jorge Aparicio | fd70270 | 2015-02-01 01:03:04 | [diff] [blame] | 732 | for option in matches.opt_strs($prefix) { |
Alex Crichton | e98dce3 | 2015-04-01 18:28:34 | [diff] [blame] | 733 | let mut iter = option.splitn(2, '='); |
Manish Goregaokar | 3248bc5 | 2014-12-09 09:44:01 | [diff] [blame] | 734 | let key = iter.next().unwrap(); |
| 735 | let value = iter.next(); |
| 736 | let option_to_lookup = key.replace("-", "_"); |
| 737 | let mut found = false; |
Jorge Aparicio | d5d7e65 | 2015-01-31 17:20:46 | [diff] [blame] | 738 | for &(candidate, setter, opt_type_desc, _) in $stat { |
Manish Goregaokar | 3248bc5 | 2014-12-09 09:44:01 | [diff] [blame] | 739 | if option_to_lookup != candidate { continue } |
| 740 | if !setter(&mut op, value) { |
| 741 | match (value, opt_type_desc) { |
| 742 | (Some(..), None) => { |
Nick Cameron | 82f8e5c | 2016-01-06 20:23:01 | [diff] [blame] | 743 | early_error(error_format, &format!("{} option `{}` takes no \ |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 744 | value", $outputname, key)) |
Manish Goregaokar | 3248bc5 | 2014-12-09 09:44:01 | [diff] [blame] | 745 | } |
| 746 | (None, Some(type_desc)) => { |
Nick Cameron | 82f8e5c | 2016-01-06 20:23:01 | [diff] [blame] | 747 | early_error(error_format, &format!("{0} option `{1}` requires \ |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 748 | {2} ({3} {1}=<value>)", |
| 749 | $outputname, key, |
| 750 | type_desc, $prefix)) |
Manish Goregaokar | 3248bc5 | 2014-12-09 09:44:01 | [diff] [blame] | 751 | } |
| 752 | (Some(value), Some(type_desc)) => { |
Nick Cameron | 82f8e5c | 2016-01-06 20:23:01 | [diff] [blame] | 753 | early_error(error_format, &format!("incorrect value `{}` for {} \ |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 754 | option `{}` - {} was expected", |
| 755 | value, $outputname, |
| 756 | key, type_desc)) |
Manish Goregaokar | 3248bc5 | 2014-12-09 09:44:01 | [diff] [blame] | 757 | } |
Benjamin Herr | dfd0e93 | 2016-03-25 17:46:11 | [diff] [blame] | 758 | (None, None) => bug!() |
Manish Goregaokar | 3248bc5 | 2014-12-09 09:44:01 | [diff] [blame] | 759 | } |
| 760 | } |
| 761 | found = true; |
| 762 | break; |
| 763 | } |
| 764 | if !found { |
Nick Cameron | 82f8e5c | 2016-01-06 20:23:01 | [diff] [blame] | 765 | early_error(error_format, &format!("unknown {} option: `{}`", |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 766 | $outputname, key)); |
Manish Goregaokar | 3248bc5 | 2014-12-09 09:44:01 | [diff] [blame] | 767 | } |
| 768 | } |
| 769 | return op; |
| 770 | } |
| 771 | |
Eduard-Mihai Burtescu | 774724b | 2019-06-11 09:21:38 | [diff] [blame] | 772 | impl dep_tracking::DepTrackingHash for $struct_name { |
Alex Crichton | 10c3134 | 2016-09-29 00:23:36 | [diff] [blame] | 773 | fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) { |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 774 | let mut sub_hashes = BTreeMap::new(); |
| 775 | $({ |
| 776 | hash_option!($opt, |
| 777 | &self.$opt, |
| 778 | &mut sub_hashes, |
| 779 | [$dep_tracking_marker $($dep_warn_val, |
| 780 | $dep_warn_text, |
| 781 | error_format)*]); |
| 782 | })* |
| 783 | dep_tracking::stable_hash(sub_hashes, hasher, error_format); |
| 784 | } |
| 785 | } |
| 786 | |
Manish Goregaokar | 3248bc5 | 2014-12-09 09:44:01 | [diff] [blame] | 787 | pub type $setter_name = fn(&mut $struct_name, v: Option<&str>) -> bool; |
ljedrz | d0c64bb | 2018-12-04 11:46:10 | [diff] [blame] | 788 | pub const $stat: &[(&str, $setter_name, Option<&str>, &str)] = |
Manish Goregaokar | 3248bc5 | 2014-12-09 09:44:01 | [diff] [blame] | 789 | &[ $( (stringify!($opt), $mod_set::$opt, $mod_desc::$parse, $desc) ),* ]; |
inrustwetrust | 3391ddd | 2014-11-15 13:51:22 | [diff] [blame] | 790 | |
Manish Goregaokar | 7e87ea9 | 2014-12-09 09:55:49 | [diff] [blame] | 791 | #[allow(non_upper_case_globals, dead_code)] |
Manish Goregaokar | 3248bc5 | 2014-12-09 09:44:01 | [diff] [blame] | 792 | mod $mod_desc { |
ljedrz | d0c64bb | 2018-12-04 11:46:10 | [diff] [blame] | 793 | pub const parse_bool: Option<&str> = None; |
| 794 | pub const parse_opt_bool: Option<&str> = |
James Miller | 280dea7 | 2015-01-09 05:06:45 | [diff] [blame] | 795 | Some("one of: `y`, `yes`, `on`, `n`, `no`, or `off`"); |
ljedrz | d0c64bb | 2018-12-04 11:46:10 | [diff] [blame] | 796 | pub const parse_string: Option<&str> = Some("a string"); |
| 797 | pub const parse_string_push: Option<&str> = Some("a string"); |
| 798 | pub const parse_pathbuf_push: Option<&str> = Some("a path"); |
| 799 | pub const parse_opt_string: Option<&str> = Some("a string"); |
| 800 | pub const parse_opt_pathbuf: Option<&str> = Some("a path"); |
| 801 | pub const parse_list: Option<&str> = Some("a space-separated list of strings"); |
| 802 | pub const parse_opt_list: Option<&str> = Some("a space-separated list of strings"); |
Tyler Mandry | fa8fd3d | 2019-03-14 22:05:49 | [diff] [blame] | 803 | pub const parse_opt_comma_list: Option<&str> = Some("a comma-separated list of strings"); |
Mark Rousskov | 1a1067d | 2019-09-30 20:27:28 | [diff] [blame] | 804 | pub const parse_threads: Option<&str> = Some("a number"); |
ljedrz | d0c64bb | 2018-12-04 11:46:10 | [diff] [blame] | 805 | pub const parse_uint: Option<&str> = Some("a number"); |
| 806 | pub const parse_passes: Option<&str> = |
inrustwetrust | 3391ddd | 2014-11-15 13:51:22 | [diff] [blame] | 807 | Some("a space-separated list of passes, or `all`"); |
ljedrz | d0c64bb | 2018-12-04 11:46:10 | [diff] [blame] | 808 | pub const parse_opt_uint: Option<&str> = |
Alex Crichton | 117984b | 2014-12-16 00:03:39 | [diff] [blame] | 809 | Some("a number"); |
ljedrz | d0c64bb | 2018-12-04 11:46:10 | [diff] [blame] | 810 | pub const parse_panic_strategy: Option<&str> = |
Eric Huss | b8da719 | 2018-11-19 21:29:35 | [diff] [blame] | 811 | Some("either `unwind` or `abort`"); |
ljedrz | d0c64bb | 2018-12-04 11:46:10 | [diff] [blame] | 812 | pub const parse_relro_level: Option<&str> = |
Johannes Löthberg | 94b9cc9 | 2017-07-14 20:01:37 | [diff] [blame] | 813 | Some("one of: `full`, `partial`, or `off`"); |
ljedrz | d0c64bb | 2018-12-04 11:46:10 | [diff] [blame] | 814 | pub const parse_sanitizer: Option<&str> = |
Jorge Aparicio | 9af6aa3 | 2016-12-30 04:28:11 | [diff] [blame] | 815 | Some("one of: `address`, `leak`, `memory` or `thread`"); |
ljedrz | d0c64bb | 2018-12-04 11:46:10 | [diff] [blame] | 816 | pub const parse_linker_flavor: Option<&str> = |
Irina Popa | 38e9640 | 2017-12-08 19:18:21 | [diff] [blame] | 817 | Some(::rustc_target::spec::LinkerFlavor::one_of()); |
ljedrz | d0c64bb | 2018-12-04 11:46:10 | [diff] [blame] | 818 | pub const parse_optimization_fuel: Option<&str> = |
Austin Hicks | 63ebf08 | 2017-03-08 21:28:47 | [diff] [blame] | 819 | Some("crate=integer"); |
ljedrz | d0c64bb | 2018-12-04 11:46:10 | [diff] [blame] | 820 | pub const parse_unpretty: Option<&str> = |
Mark Mansi | ebfa6c7 | 2018-01-15 03:11:40 | [diff] [blame] | 821 | Some("`string` or `string=string`"); |
Esteban Küber | c41ddf1 | 2019-03-07 09:54:53 | [diff] [blame] | 822 | pub const parse_treat_err_as_bug: Option<&str> = |
| 823 | Some("either no value or a number bigger than 0"); |
ljedrz | d0c64bb | 2018-12-04 11:46:10 | [diff] [blame] | 824 | pub const parse_lto: Option<&str> = |
Michael Woerister | 24093a6 | 2018-09-04 15:57:17 | [diff] [blame] | 825 | Some("either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, \ |
| 826 | `fat`, or omitted"); |
Michael Woerister | 04f425d | 2019-02-01 14:15:43 | [diff] [blame] | 827 | pub const parse_linker_plugin_lto: Option<&str> = |
Michael Woerister | d5f8edf | 2018-08-02 12:16:43 | [diff] [blame] | 828 | Some("either a boolean (`yes`, `no`, `on`, `off`, etc), \ |
Michael Woerister | a981089 | 2018-04-25 13:45:04 | [diff] [blame] | 829 | or the path to the linker plugin"); |
Michael Woerister | 64ee32e | 2019-05-28 14:13:59 | [diff] [blame] | 830 | pub const parse_switch_with_opt_path: Option<&str> = |
Michael Woerister | 7b1df42 | 2019-04-10 11:46:37 | [diff] [blame] | 831 | Some("an optional path to the profiling data output directory"); |
Peter Jin | b91d211 | 2018-12-31 18:58:13 | [diff] [blame] | 832 | pub const parse_merge_functions: Option<&str> = |
| 833 | Some("one of: `disabled`, `trampolines`, or `aliases`"); |
Eduard-Mihai Burtescu | 2092963 | 2019-01-29 05:24:32 | [diff] [blame] | 834 | pub const parse_symbol_mangling_version: Option<&str> = |
| 835 | Some("either `legacy` or `v0` (RFC 2603)"); |
inrustwetrust | 3391ddd | 2014-11-15 13:51:22 | [diff] [blame] | 836 | } |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 837 | |
Manish Goregaokar | 7e87ea9 | 2014-12-09 09:55:49 | [diff] [blame] | 838 | #[allow(dead_code)] |
Manish Goregaokar | 3248bc5 | 2014-12-09 09:44:01 | [diff] [blame] | 839 | mod $mod_set { |
Eduard-Mihai Burtescu | 2092963 | 2019-01-29 05:24:32 | [diff] [blame] | 840 | use super::{$struct_name, Passes, Sanitizer, LtoCli, LinkerPluginLto, SwitchWithOptPath, |
| 841 | SymbolManglingVersion}; |
Peter Jin | b91d211 | 2018-12-31 18:58:13 | [diff] [blame] | 842 | use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, RelroLevel}; |
Oliver Schneider | d732da8 | 2017-12-14 07:09:19 | [diff] [blame] | 843 | use std::path::PathBuf; |
Peter Jin | b91d211 | 2018-12-31 18:58:13 | [diff] [blame] | 844 | use std::str::FromStr; |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 845 | |
| 846 | $( |
Manish Goregaokar | 3248bc5 | 2014-12-09 09:44:01 | [diff] [blame] | 847 | pub fn $opt(cg: &mut $struct_name, v: Option<&str>) -> bool { |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 848 | $parse(&mut cg.$opt, v) |
| 849 | } |
| 850 | )* |
| 851 | |
| 852 | fn parse_bool(slot: &mut bool, v: Option<&str>) -> bool { |
| 853 | match v { |
| 854 | Some(..) => false, |
| 855 | None => { *slot = true; true } |
| 856 | } |
| 857 | } |
| 858 | |
Corey Richardson | 6b130e3 | 2014-07-23 18:56:36 | [diff] [blame] | 859 | fn parse_opt_bool(slot: &mut Option<bool>, v: Option<&str>) -> bool { |
| 860 | match v { |
James Miller | 280dea7 | 2015-01-09 05:06:45 | [diff] [blame] | 861 | Some(s) => { |
| 862 | match s { |
| 863 | "n" | "no" | "off" => { |
| 864 | *slot = Some(false); |
| 865 | } |
| 866 | "y" | "yes" | "on" => { |
| 867 | *slot = Some(true); |
| 868 | } |
| 869 | _ => { return false; } |
| 870 | } |
| 871 | |
| 872 | true |
| 873 | }, |
Corey Richardson | 6b130e3 | 2014-07-23 18:56:36 | [diff] [blame] | 874 | None => { *slot = Some(true); true } |
| 875 | } |
| 876 | } |
| 877 | |
Richo Healey | 5530745 | 2014-05-22 23:57:53 | [diff] [blame] | 878 | fn parse_opt_string(slot: &mut Option<String>, v: Option<&str>) -> bool { |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 879 | match v { |
Richo Healey | 1f1b2e4 | 2014-05-25 10:17:19 | [diff] [blame] | 880 | Some(s) => { *slot = Some(s.to_string()); true }, |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 881 | None => false, |
| 882 | } |
| 883 | } |
| 884 | |
Oliver Schneider | d732da8 | 2017-12-14 07:09:19 | [diff] [blame] | 885 | fn parse_opt_pathbuf(slot: &mut Option<PathBuf>, v: Option<&str>) -> bool { |
| 886 | match v { |
| 887 | Some(s) => { *slot = Some(PathBuf::from(s)); true }, |
| 888 | None => false, |
| 889 | } |
| 890 | } |
| 891 | |
Richo Healey | 5530745 | 2014-05-22 23:57:53 | [diff] [blame] | 892 | fn parse_string(slot: &mut String, v: Option<&str>) -> bool { |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 893 | match v { |
Richo Healey | 1f1b2e4 | 2014-05-25 10:17:19 | [diff] [blame] | 894 | Some(s) => { *slot = s.to_string(); true }, |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 895 | None => false, |
| 896 | } |
| 897 | } |
| 898 | |
Jorge Aparicio | 9631e9f | 2016-09-19 07:32:28 | [diff] [blame] | 899 | fn parse_string_push(slot: &mut Vec<String>, v: Option<&str>) -> bool { |
| 900 | match v { |
| 901 | Some(s) => { slot.push(s.to_string()); true }, |
| 902 | None => false, |
| 903 | } |
| 904 | } |
| 905 | |
Oliver Schneider | d732da8 | 2017-12-14 07:09:19 | [diff] [blame] | 906 | fn parse_pathbuf_push(slot: &mut Vec<PathBuf>, v: Option<&str>) -> bool { |
| 907 | match v { |
| 908 | Some(s) => { slot.push(PathBuf::from(s)); true }, |
| 909 | None => false, |
| 910 | } |
| 911 | } |
| 912 | |
Richo Healey | 5530745 | 2014-05-22 23:57:53 | [diff] [blame] | 913 | fn parse_list(slot: &mut Vec<String>, v: Option<&str>) |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 914 | -> bool { |
| 915 | match v { |
| 916 | Some(s) => { |
ljedrz | 59c8a27 | 2018-07-26 15:11:10 | [diff] [blame] | 917 | slot.extend(s.split_whitespace().map(|s| s.to_string())); |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 918 | true |
| 919 | }, |
| 920 | None => false, |
| 921 | } |
| 922 | } |
| 923 | |
Corey Richardson | 6b130e3 | 2014-07-23 18:56:36 | [diff] [blame] | 924 | fn parse_opt_list(slot: &mut Option<Vec<String>>, v: Option<&str>) |
| 925 | -> bool { |
| 926 | match v { |
| 927 | Some(s) => { |
kwantam | c361e13 | 2015-04-18 17:49:51 | [diff] [blame] | 928 | let v = s.split_whitespace().map(|s| s.to_string()).collect(); |
Corey Richardson | 6b130e3 | 2014-07-23 18:56:36 | [diff] [blame] | 929 | *slot = Some(v); |
| 930 | true |
| 931 | }, |
| 932 | None => false, |
| 933 | } |
| 934 | } |
| 935 | |
Tyler Mandry | fa8fd3d | 2019-03-14 22:05:49 | [diff] [blame] | 936 | fn parse_opt_comma_list(slot: &mut Option<Vec<String>>, v: Option<&str>) |
| 937 | -> bool { |
| 938 | match v { |
| 939 | Some(s) => { |
| 940 | let v = s.split(',').map(|s| s.to_string()).collect(); |
| 941 | *slot = Some(v); |
| 942 | true |
| 943 | }, |
| 944 | None => false, |
| 945 | } |
| 946 | } |
| 947 | |
Mark Rousskov | 1a1067d | 2019-09-30 20:27:28 | [diff] [blame] | 948 | fn parse_threads(slot: &mut usize, v: Option<&str>) -> bool { |
| 949 | match v.and_then(|s| s.parse().ok()) { |
| 950 | Some(0) => { *slot = ::num_cpus::get(); true }, |
| 951 | Some(i) => { *slot = i; true }, |
| 952 | None => false |
| 953 | } |
| 954 | } |
| 955 | |
Alex Crichton | 43bfaa4 | 2015-03-26 00:06:52 | [diff] [blame] | 956 | fn parse_uint(slot: &mut usize, v: Option<&str>) -> bool { |
Alex Crichton | 0cdde6e | 2015-01-28 06:52:32 | [diff] [blame] | 957 | match v.and_then(|s| s.parse().ok()) { |
Stuart Pernsteiner | cf67285 | 2014-07-17 17:52:52 | [diff] [blame] | 958 | Some(i) => { *slot = i; true }, |
| 959 | None => false |
| 960 | } |
| 961 | } |
Keegan McAllister | ad9a1da | 2014-09-12 15:17:58 | [diff] [blame] | 962 | |
Alex Crichton | 43bfaa4 | 2015-03-26 00:06:52 | [diff] [blame] | 963 | fn parse_opt_uint(slot: &mut Option<usize>, v: Option<&str>) -> bool { |
Alex Crichton | 117984b | 2014-12-16 00:03:39 | [diff] [blame] | 964 | match v { |
Alex Crichton | 0cdde6e | 2015-01-28 06:52:32 | [diff] [blame] | 965 | Some(s) => { *slot = s.parse().ok(); slot.is_some() } |
Alex Crichton | 9e35b79 | 2017-09-25 19:26:25 | [diff] [blame] | 966 | None => { *slot = None; false } |
Alex Crichton | 117984b | 2014-12-16 00:03:39 | [diff] [blame] | 967 | } |
| 968 | } |
| 969 | |
Keegan McAllister | ad9a1da | 2014-09-12 15:17:58 | [diff] [blame] | 970 | fn parse_passes(slot: &mut Passes, v: Option<&str>) -> bool { |
| 971 | match v { |
| 972 | Some("all") => { |
Mark Rousskov | b3267dc | 2018-07-26 17:22:14 | [diff] [blame] | 973 | *slot = Passes::All; |
Keegan McAllister | ad9a1da | 2014-09-12 15:17:58 | [diff] [blame] | 974 | true |
| 975 | } |
| 976 | v => { |
iirelu | e593c3b | 2016-10-29 21:54:04 | [diff] [blame] | 977 | let mut passes = vec![]; |
Keegan McAllister | ad9a1da | 2014-09-12 15:17:58 | [diff] [blame] | 978 | if parse_list(&mut passes, v) { |
Mark Rousskov | b3267dc | 2018-07-26 17:22:14 | [diff] [blame] | 979 | *slot = Passes::Some(passes); |
Keegan McAllister | ad9a1da | 2014-09-12 15:17:58 | [diff] [blame] | 980 | true |
| 981 | } else { |
| 982 | false |
| 983 | } |
| 984 | } |
| 985 | } |
| 986 | } |
Alex Crichton | 0ec321f | 2016-04-08 23:18:40 | [diff] [blame] | 987 | |
Jorge Aparicio | cbb967f | 2016-09-28 02:26:08 | [diff] [blame] | 988 | fn parse_panic_strategy(slot: &mut Option<PanicStrategy>, v: Option<&str>) -> bool { |
Alex Crichton | 0ec321f | 2016-04-08 23:18:40 | [diff] [blame] | 989 | match v { |
Jorge Aparicio | cbb967f | 2016-09-28 02:26:08 | [diff] [blame] | 990 | Some("unwind") => *slot = Some(PanicStrategy::Unwind), |
| 991 | Some("abort") => *slot = Some(PanicStrategy::Abort), |
Alex Crichton | 0ec321f | 2016-04-08 23:18:40 | [diff] [blame] | 992 | _ => return false |
| 993 | } |
| 994 | true |
| 995 | } |
Jorge Aparicio | 9af6aa3 | 2016-12-30 04:28:11 | [diff] [blame] | 996 | |
Johannes Löthberg | 94b9cc9 | 2017-07-14 20:01:37 | [diff] [blame] | 997 | fn parse_relro_level(slot: &mut Option<RelroLevel>, v: Option<&str>) -> bool { |
| 998 | match v { |
Johannes Löthberg | 2161fb2 | 2017-07-17 23:27:55 | [diff] [blame] | 999 | Some(s) => { |
| 1000 | match s.parse::<RelroLevel>() { |
| 1001 | Ok(level) => *slot = Some(level), |
| 1002 | _ => return false |
| 1003 | } |
| 1004 | }, |
Johannes Löthberg | 94b9cc9 | 2017-07-14 20:01:37 | [diff] [blame] | 1005 | _ => return false |
| 1006 | } |
| 1007 | true |
| 1008 | } |
| 1009 | |
Jorge Aparicio | 9af6aa3 | 2016-12-30 04:28:11 | [diff] [blame] | 1010 | fn parse_sanitizer(slote: &mut Option<Sanitizer>, v: Option<&str>) -> bool { |
| 1011 | match v { |
| 1012 | Some("address") => *slote = Some(Sanitizer::Address), |
| 1013 | Some("leak") => *slote = Some(Sanitizer::Leak), |
| 1014 | Some("memory") => *slote = Some(Sanitizer::Memory), |
| 1015 | Some("thread") => *slote = Some(Sanitizer::Thread), |
| 1016 | _ => return false, |
| 1017 | } |
| 1018 | true |
| 1019 | } |
Jorge Aparicio | 9d11b08 | 2017-02-21 19:47:15 | [diff] [blame] | 1020 | |
| 1021 | fn parse_linker_flavor(slote: &mut Option<LinkerFlavor>, v: Option<&str>) -> bool { |
| 1022 | match v.and_then(LinkerFlavor::from_str) { |
| 1023 | Some(lf) => *slote = Some(lf), |
| 1024 | _ => return false, |
| 1025 | } |
| 1026 | true |
| 1027 | } |
Austin Hicks | 63ebf08 | 2017-03-08 21:28:47 | [diff] [blame] | 1028 | |
| 1029 | fn parse_optimization_fuel(slot: &mut Option<(String, u64)>, v: Option<&str>) -> bool { |
| 1030 | match v { |
| 1031 | None => false, |
| 1032 | Some(s) => { |
| 1033 | let parts = s.split('=').collect::<Vec<_>>(); |
| 1034 | if parts.len() != 2 { return false; } |
| 1035 | let crate_name = parts[0].to_string(); |
| 1036 | let fuel = parts[1].parse::<u64>(); |
| 1037 | if fuel.is_err() { return false; } |
| 1038 | *slot = Some((crate_name, fuel.unwrap())); |
| 1039 | true |
| 1040 | } |
| 1041 | } |
| 1042 | } |
Mark Mansi | ebfa6c7 | 2018-01-15 03:11:40 | [diff] [blame] | 1043 | |
| 1044 | fn parse_unpretty(slot: &mut Option<String>, v: Option<&str>) -> bool { |
| 1045 | match v { |
| 1046 | None => false, |
| 1047 | Some(s) if s.split('=').count() <= 2 => { |
| 1048 | *slot = Some(s.to_string()); |
| 1049 | true |
| 1050 | } |
| 1051 | _ => false, |
| 1052 | } |
| 1053 | } |
Alex Crichton | 8bde2ac | 2018-01-16 23:02:31 | [diff] [blame] | 1054 | |
Esteban Küber | c41ddf1 | 2019-03-07 09:54:53 | [diff] [blame] | 1055 | fn parse_treat_err_as_bug(slot: &mut Option<usize>, v: Option<&str>) -> bool { |
| 1056 | match v { |
| 1057 | Some(s) => { *slot = s.parse().ok().filter(|&x| x != 0); slot.unwrap_or(0) != 0 } |
| 1058 | None => { *slot = Some(1); true } |
| 1059 | } |
| 1060 | } |
| 1061 | |
Michael Woerister | 24093a6 | 2018-09-04 15:57:17 | [diff] [blame] | 1062 | fn parse_lto(slot: &mut LtoCli, v: Option<&str>) -> bool { |
| 1063 | if v.is_some() { |
| 1064 | let mut bool_arg = None; |
| 1065 | if parse_opt_bool(&mut bool_arg, v) { |
| 1066 | *slot = if bool_arg.unwrap() { |
| 1067 | LtoCli::Yes |
| 1068 | } else { |
| 1069 | LtoCli::No |
| 1070 | }; |
| 1071 | return true |
| 1072 | } |
| 1073 | } |
| 1074 | |
Alex Crichton | 8bde2ac | 2018-01-16 23:02:31 | [diff] [blame] | 1075 | *slot = match v { |
Michael Woerister | 24093a6 | 2018-09-04 15:57:17 | [diff] [blame] | 1076 | None => LtoCli::NoParam, |
| 1077 | Some("thin") => LtoCli::Thin, |
| 1078 | Some("fat") => LtoCli::Fat, |
Alex Crichton | 8bde2ac | 2018-01-16 23:02:31 | [diff] [blame] | 1079 | Some(_) => return false, |
| 1080 | }; |
| 1081 | true |
| 1082 | } |
Manish Goregaokar | 2cff123 | 2018-02-04 16:52:26 | [diff] [blame] | 1083 | |
Michael Woerister | 04f425d | 2019-02-01 14:15:43 | [diff] [blame] | 1084 | fn parse_linker_plugin_lto(slot: &mut LinkerPluginLto, v: Option<&str>) -> bool { |
Michael Woerister | a981089 | 2018-04-25 13:45:04 | [diff] [blame] | 1085 | if v.is_some() { |
| 1086 | let mut bool_arg = None; |
| 1087 | if parse_opt_bool(&mut bool_arg, v) { |
| 1088 | *slot = if bool_arg.unwrap() { |
Michael Woerister | 04f425d | 2019-02-01 14:15:43 | [diff] [blame] | 1089 | LinkerPluginLto::LinkerPluginAuto |
Michael Woerister | a981089 | 2018-04-25 13:45:04 | [diff] [blame] | 1090 | } else { |
Michael Woerister | 04f425d | 2019-02-01 14:15:43 | [diff] [blame] | 1091 | LinkerPluginLto::Disabled |
Michael Woerister | a981089 | 2018-04-25 13:45:04 | [diff] [blame] | 1092 | }; |
| 1093 | return true |
| 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | *slot = match v { |
Michael Woerister | 04f425d | 2019-02-01 14:15:43 | [diff] [blame] | 1098 | None => LinkerPluginLto::LinkerPluginAuto, |
| 1099 | Some(path) => LinkerPluginLto::LinkerPlugin(PathBuf::from(path)), |
Michael Woerister | a981089 | 2018-04-25 13:45:04 | [diff] [blame] | 1100 | }; |
| 1101 | true |
| 1102 | } |
Peter Jin | b91d211 | 2018-12-31 18:58:13 | [diff] [blame] | 1103 | |
Michael Woerister | 64ee32e | 2019-05-28 14:13:59 | [diff] [blame] | 1104 | fn parse_switch_with_opt_path(slot: &mut SwitchWithOptPath, v: Option<&str>) -> bool { |
Michael Woerister | 7b1df42 | 2019-04-10 11:46:37 | [diff] [blame] | 1105 | *slot = match v { |
Michael Woerister | 64ee32e | 2019-05-28 14:13:59 | [diff] [blame] | 1106 | None => SwitchWithOptPath::Enabled(None), |
| 1107 | Some(path) => SwitchWithOptPath::Enabled(Some(PathBuf::from(path))), |
Michael Woerister | 7b1df42 | 2019-04-10 11:46:37 | [diff] [blame] | 1108 | }; |
| 1109 | true |
| 1110 | } |
| 1111 | |
Peter Jin | b91d211 | 2018-12-31 18:58:13 | [diff] [blame] | 1112 | fn parse_merge_functions(slot: &mut Option<MergeFunctions>, v: Option<&str>) -> bool { |
| 1113 | match v.and_then(|s| MergeFunctions::from_str(s).ok()) { |
| 1114 | Some(mergefunc) => *slot = Some(mergefunc), |
| 1115 | _ => return false, |
| 1116 | } |
| 1117 | true |
| 1118 | } |
Eduard-Mihai Burtescu | 2092963 | 2019-01-29 05:24:32 | [diff] [blame] | 1119 | |
| 1120 | fn parse_symbol_mangling_version( |
| 1121 | slot: &mut SymbolManglingVersion, |
| 1122 | v: Option<&str>, |
| 1123 | ) -> bool { |
| 1124 | *slot = match v { |
| 1125 | Some("legacy") => SymbolManglingVersion::Legacy, |
| 1126 | Some("v0") => SymbolManglingVersion::V0, |
| 1127 | _ => return false, |
| 1128 | }; |
| 1129 | true |
| 1130 | } |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1131 | } |
Patrick Walton | ddb2466 | 2014-11-14 17:18:10 | [diff] [blame] | 1132 | ) } |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1133 | |
Manish Goregaokar | 3248bc5 | 2014-12-09 09:44:01 | [diff] [blame] | 1134 | options! {CodegenOptions, CodegenSetter, basic_codegen_options, |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1135 | build_codegen_options, "C", "codegen", |
| 1136 | CG_OPTIONS, cg_type_desc, cgsetters, |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1137 | ar: Option<String> = (None, parse_opt_string, [UNTRACKED], |
Vadim Petrochenkov | b434c84 | 2017-10-08 08:41:12 | [diff] [blame] | 1138 | "this option is deprecated and does nothing"), |
Oliver Schneider | d732da8 | 2017-12-14 07:09:19 | [diff] [blame] | 1139 | linker: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED], |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1140 | "system linker to link outputs with"), |
Jorge Aparicio | 9631e9f | 2016-09-19 07:32:28 | [diff] [blame] | 1141 | link_arg: Vec<String> = (vec![], parse_string_push, [UNTRACKED], |
Jorge Aparicio | 94d2c43 | 2017-05-13 13:21:24 | [diff] [blame] | 1142 | "a single extra argument to append to the linker invocation (can be used several times)"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1143 | link_args: Option<Vec<String>> = (None, parse_opt_list, [UNTRACKED], |
Jorge Aparicio | 94d2c43 | 2017-05-13 13:21:24 | [diff] [blame] | 1144 | "extra arguments to append to the linker invocation (space separated)"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1145 | link_dead_code: bool = (false, parse_bool, [UNTRACKED], |
Johan Lorenzo | 39c2d85 | 2016-02-15 16:44:06 | [diff] [blame] | 1146 | "don't let linker strip dead code (turning it on can be used for code coverage)"), |
Michael Woerister | 24093a6 | 2018-09-04 15:57:17 | [diff] [blame] | 1147 | lto: LtoCli = (LtoCli::Unspecified, parse_lto, [TRACKED], |
Colin Davidson | a7a1bf8 | 2014-09-21 04:36:17 | [diff] [blame] | 1148 | "perform LLVM link-time optimizations"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1149 | target_cpu: Option<String> = (None, parse_opt_string, [TRACKED], |
Samy Kacimi | 66815c6 | 2019-07-23 19:26:01 | [diff] [blame] | 1150 | "select target processor (`rustc --print target-cpus` for details)"), |
Matthias Krüger | ede1f7d | 2018-08-23 08:14:52 | [diff] [blame] | 1151 | target_feature: String = (String::new(), parse_string, [TRACKED], |
togiberlin | de3fd02 | 2019-09-04 12:53:47 | [diff] [blame] | 1152 | "target specific attributes. (`rustc --print target-features` for details). \ |
| 1153 | This feature is unsafe."), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1154 | passes: Vec<String> = (Vec::new(), parse_list, [TRACKED], |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1155 | "a list of extra LLVM passes to run (space separated)"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1156 | llvm_args: Vec<String> = (Vec::new(), parse_list, [TRACKED], |
Brian Anderson | c03077b | 2019-08-07 21:51:49 | [diff] [blame] | 1157 | "a list of arguments to pass to LLVM (space separated)"), |
Michael Woerister | 0d67510 | 2019-05-28 15:27:46 | [diff] [blame] | 1158 | save_temps: bool = (false, parse_bool, [UNTRACKED], |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1159 | "save all temporary output files during compilation"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1160 | rpath: bool = (false, parse_bool, [UNTRACKED], |
Alex Crichton | a0546de | 2014-06-11 21:52:38 | [diff] [blame] | 1161 | "set rpath values in libs/exes"), |
Nathan Froyd | ffc6ddd | 2017-02-17 21:00:08 | [diff] [blame] | 1162 | overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED], |
| 1163 | "use overflow checks for integer arithmetic"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1164 | no_prepopulate_passes: bool = (false, parse_bool, [TRACKED], |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1165 | "don't pre-populate the pass manager with a list of passes"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1166 | no_vectorize_loops: bool = (false, parse_bool, [TRACKED], |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1167 | "don't run the loop vectorization optimization passes"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1168 | no_vectorize_slp: bool = (false, parse_bool, [TRACKED], |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1169 | "don't run LLVM's SLP vectorization pass"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1170 | soft_float: bool = (false, parse_bool, [TRACKED], |
James Duley | ffdd982 | 2016-09-04 12:47:25 | [diff] [blame] | 1171 | "use soft float ABI (*eabihf targets only)"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1172 | prefer_dynamic: bool = (false, parse_bool, [TRACKED], |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1173 | "prefer dynamic linking to static linking"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1174 | no_integrated_as: bool = (false, parse_bool, [TRACKED], |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1175 | "use an external assembler rather than LLVM's integrated one"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1176 | no_redzone: Option<bool> = (None, parse_opt_bool, [TRACKED], |
John Kåre Alsaker | 036b9e8 | 2014-07-16 11:35:50 | [diff] [blame] | 1177 | "disable the use of the redzone"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1178 | relocation_model: Option<String> = (None, parse_opt_string, [TRACKED], |
Samy Kacimi | 66815c6 | 2019-07-23 19:26:01 | [diff] [blame] | 1179 | "choose the relocation model to use (`rustc --print relocation-models` for details)"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1180 | code_model: Option<String> = (None, parse_opt_string, [TRACKED], |
Samy Kacimi | 66815c6 | 2019-07-23 19:26:01 | [diff] [blame] | 1181 | "choose the code model to use (`rustc --print code-models` for details)"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1182 | metadata: Vec<String> = (Vec::new(), parse_list, [TRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1183 | "metadata to mangle symbol names with"), |
Matthias Krüger | ede1f7d | 2018-08-23 08:14:52 | [diff] [blame] | 1184 | extra_filename: String = (String::new(), parse_string, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1185 | "extra data to put in each output filename"), |
Alex Crichton | 9e35b79 | 2017-09-25 19:26:25 | [diff] [blame] | 1186 | codegen_units: Option<usize> = (None, parse_opt_uint, [UNTRACKED], |
Stuart Pernsteiner | cf67285 | 2014-07-17 17:52:52 | [diff] [blame] | 1187 | "divide crate into N units to optimize in parallel"), |
Mark Rousskov | b3267dc | 2018-07-26 17:22:14 | [diff] [blame] | 1188 | remark: Passes = (Passes::Some(Vec::new()), parse_passes, [UNTRACKED], |
Keegan McAllister | ad9a1da | 2014-09-12 15:17:58 | [diff] [blame] | 1189 | "print remarks for these optimization passes (space separated, or \"all\")"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1190 | no_stack_check: bool = (false, parse_bool, [UNTRACKED], |
Samy Kacimi | 66815c6 | 2019-07-23 19:26:01 | [diff] [blame] | 1191 | "the `--no-stack-check` flag is deprecated and does nothing"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1192 | debuginfo: Option<usize> = (None, parse_opt_uint, [TRACKED], |
Alex Crichton | 117984b | 2014-12-16 00:03:39 | [diff] [blame] | 1193 | "debug info emission level, 0 = no debug info, 1 = line tables only, \ |
| 1194 | 2 = full debug info with variable and type information"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1195 | opt_level: Option<String> = (None, parse_opt_string, [TRACKED], |
Brandon Edens | b1337d3 | 2016-03-27 19:42:47 | [diff] [blame] | 1196 | "optimize with possible levels 0-3, s, or z"), |
Simonas Kazlauskas | 09d2db4 | 2018-03-06 18:27:19 | [diff] [blame] | 1197 | force_frame_pointers: Option<bool> = (None, parse_opt_bool, [TRACKED], |
| 1198 | "force use of the frame pointers"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1199 | debug_assertions: Option<bool> = (None, parse_opt_bool, [TRACKED], |
Alex Crichton | d5d8345 | 2015-03-02 22:51:24 | [diff] [blame] | 1200 | "explicitly enable the cfg(debug_assertions) directive"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1201 | inline_threshold: Option<usize> = (None, parse_opt_uint, [TRACKED], |
oyvindln | edf1622 | 2017-09-13 18:11:02 | [diff] [blame] | 1202 | "set the threshold for inlining a function (default: 225)"), |
Jorge Aparicio | cbb967f | 2016-09-28 02:26:08 | [diff] [blame] | 1203 | panic: Option<PanicStrategy> = (None, parse_panic_strategy, |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1204 | [TRACKED], "panic strategy to compile crate with"), |
Michael Woerister | 796264b | 2017-12-15 20:03:48 | [diff] [blame] | 1205 | incremental: Option<String> = (None, parse_opt_string, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1206 | "enable incremental compilation"), |
Alex Crichton | 6f4b378 | 2018-09-29 18:03:59 | [diff] [blame] | 1207 | default_linker_libraries: Option<bool> = (None, parse_opt_bool, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1208 | "allow the linker to link its default libraries"), |
David Wood | 9536d04 | 2018-11-29 21:00:09 | [diff] [blame] | 1209 | linker_flavor: Option<LinkerFlavor> = (None, parse_linker_flavor, [UNTRACKED], |
Brian Anderson | c03077b | 2019-08-07 21:51:49 | [diff] [blame] | 1210 | "linker flavor"), |
Michael Woerister | 04f425d | 2019-02-01 14:15:43 | [diff] [blame] | 1211 | linker_plugin_lto: LinkerPluginLto = (LinkerPluginLto::Disabled, |
| 1212 | parse_linker_plugin_lto, [TRACKED], |
| 1213 | "generate build artifacts that are compatible with linker-based LTO."), |
Michael Woerister | b7fe2ca | 2019-05-28 14:48:03 | [diff] [blame] | 1214 | profile_generate: SwitchWithOptPath = (SwitchWithOptPath::Disabled, |
| 1215 | parse_switch_with_opt_path, [TRACKED], |
| 1216 | "compile the program with profiling instrumentation"), |
| 1217 | profile_use: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED], |
| 1218 | "use the given `.profdata` file for profile-guided optimization"), |
Patrick Walton | ddb2466 | 2014-11-14 17:18:10 | [diff] [blame] | 1219 | } |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1220 | |
Manish Goregaokar | 7e87ea9 | 2014-12-09 09:55:49 | [diff] [blame] | 1221 | options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1222 | build_debugging_options, "Z", "debugging", |
| 1223 | DB_OPTIONS, db_type_desc, dbsetters, |
bjorn3 | 74c92c5 | 2017-10-30 17:42:21 | [diff] [blame] | 1224 | codegen_backend: Option<String> = (None, parse_opt_string, [TRACKED], |
| 1225 | "the backend to use"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1226 | verbose: bool = (false, parse_bool, [UNTRACKED], |
Manish Goregaokar | 7e87ea9 | 2014-12-09 09:55:49 | [diff] [blame] | 1227 | "in general, enable more debug printouts"), |
Felix S. Klock II | 20df0e9 | 2017-03-16 13:41:48 | [diff] [blame] | 1228 | span_free_formats: bool = (false, parse_bool, [UNTRACKED], |
| 1229 | "when debug-printing compiler state, do not include spans"), // o/w tests have closure@path |
Felix S. Klock II | 609813b | 2017-03-23 10:08:08 | [diff] [blame] | 1230 | identify_regions: bool = (false, parse_bool, [UNTRACKED], |
| 1231 | "make unnamed regions display as '# (where # is some non-ident unique id)"), |
est31 | c9af68e | 2017-11-19 22:35:53 | [diff] [blame] | 1232 | borrowck: Option<String> = (None, parse_opt_string, [UNTRACKED], |
Christopher Vittal | db6f7a9 | 2019-05-03 21:34:17 | [diff] [blame] | 1233 | "select which borrowck is used (`mir` or `migrate`)"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1234 | time_passes: bool = (false, parse_bool, [UNTRACKED], |
Manish Goregaokar | 7e87ea9 | 2014-12-09 09:55:49 | [diff] [blame] | 1235 | "measure time of each rustc pass"), |
John Kåre Alsaker | e842f57 | 2019-02-13 12:11:50 | [diff] [blame] | 1236 | time: bool = (false, parse_bool, [UNTRACKED], |
| 1237 | "measure time of rustc processes"), |
Michael Woerister | 0d67510 | 2019-05-28 15:27:46 | [diff] [blame] | 1238 | time_llvm_passes: bool = (false, parse_bool, [UNTRACKED], |
Manish Goregaokar | 7e87ea9 | 2014-12-09 09:55:49 | [diff] [blame] | 1239 | "measure time of each LLVM pass"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1240 | input_stats: bool = (false, parse_bool, [UNTRACKED], |
Nick Cameron | f7dc917 | 2015-11-11 05:26:14 | [diff] [blame] | 1241 | "gather statistics about the input"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1242 | asm_comments: bool = (false, parse_bool, [TRACKED], |
Manish Goregaokar | 7e87ea9 | 2014-12-09 09:55:49 | [diff] [blame] | 1243 | "generate comments into the assembly (may change behavior)"), |
Nikita Popov | 22cf833 | 2018-06-12 19:05:37 | [diff] [blame] | 1244 | verify_llvm_ir: bool = (false, parse_bool, [TRACKED], |
| 1245 | "verify LLVM IR"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1246 | borrowck_stats: bool = (false, parse_bool, [UNTRACKED], |
Manish Goregaokar | 7e87ea9 | 2014-12-09 09:55:49 | [diff] [blame] | 1247 | "gather borrowck statistics"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1248 | no_landing_pads: bool = (false, parse_bool, [TRACKED], |
Manish Goregaokar | 7e87ea9 | 2014-12-09 09:55:49 | [diff] [blame] | 1249 | "omit landing pads for unwinding"), |
Simonas Kazlauskas | b719578 | 2018-01-04 20:19:23 | [diff] [blame] | 1250 | fewer_names: bool = (false, parse_bool, [TRACKED], |
| 1251 | "reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR)"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1252 | meta_stats: bool = (false, parse_bool, [UNTRACKED], |
Manish Goregaokar | 7e87ea9 | 2014-12-09 09:55:49 | [diff] [blame] | 1253 | "gather metadata statistics"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1254 | print_link_args: bool = (false, parse_bool, [UNTRACKED], |
Nick Cameron | f7dc917 | 2015-11-11 05:26:14 | [diff] [blame] | 1255 | "print the arguments passed to the linker"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1256 | print_llvm_passes: bool = (false, parse_bool, [UNTRACKED], |
Brian Anderson | c03077b | 2019-08-07 21:51:49 | [diff] [blame] | 1257 | "prints the LLVM optimization passes being run"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1258 | ast_json: bool = (false, parse_bool, [UNTRACKED], |
Nick Cameron | f7dc917 | 2015-11-11 05:26:14 | [diff] [blame] | 1259 | "print the AST as JSON and halt"), |
Mark Rousskov | 1a1067d | 2019-09-30 20:27:28 | [diff] [blame] | 1260 | // We default to 1 here since we want to behave like |
| 1261 | // a sequential compiler for now. This'll likely be adjusted |
| 1262 | // in the future. Note that -Zthreads=0 is the way to get |
| 1263 | // the num_cpus behavior. |
| 1264 | threads: usize = (1, parse_threads, [UNTRACKED], |
John Kåre Alsaker | 975eb31 | 2019-01-28 14:51:47 | [diff] [blame] | 1265 | "use a thread pool with N threads"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1266 | ast_json_noexpand: bool = (false, parse_bool, [UNTRACKED], |
Nick Cameron | f7dc917 | 2015-11-11 05:26:14 | [diff] [blame] | 1267 | "print the pre-expansion AST as JSON and halt"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1268 | ls: bool = (false, parse_bool, [UNTRACKED], |
Nick Cameron | f7dc917 | 2015-11-11 05:26:14 | [diff] [blame] | 1269 | "list the symbols defined by a library crate"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1270 | save_analysis: bool = (false, parse_bool, [UNTRACKED], |
Nick Cameron | 377be7a | 2016-08-30 04:40:44 | [diff] [blame] | 1271 | "write syntax and type analysis (in JSON format) information, in \ |
Nick Cameron | cbafc57 | 2016-08-29 00:24:55 | [diff] [blame] | 1272 | addition to normal output"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1273 | print_region_graph: bool = (false, parse_bool, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1274 | "prints region inference graph. \ |
| 1275 | Use with RUST_REGION_GRAPH=help for more info"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1276 | parse_only: bool = (false, parse_bool, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1277 | "parse only; do not compile, assemble, or link"), |
John Kåre Alsaker | c3c1c8d | 2019-01-13 08:18:37 | [diff] [blame] | 1278 | dual_proc_macros: bool = (false, parse_bool, [TRACKED], |
| 1279 | "load proc macros for both target and host, but only link to the target"), |
Irina Popa | b63d7e2 | 2018-05-08 13:10:16 | [diff] [blame] | 1280 | no_codegen: bool = (false, parse_bool, [TRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1281 | "run all passes except codegen; no output"), |
Esteban Küber | c41ddf1 | 2019-03-07 09:54:53 | [diff] [blame] | 1282 | treat_err_as_bug: Option<usize> = (None, parse_treat_err_as_bug, [TRACKED], |
Esteban Küber | e3299f2 | 2019-03-07 19:18:05 | [diff] [blame] | 1283 | "treat error number `val` that occurs as bug"), |
Oliver Schneider | 56c9077 | 2018-07-19 15:53:44 | [diff] [blame] | 1284 | report_delayed_bugs: bool = (false, parse_bool, [TRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1285 | "immediately print bugs registered with `delay_span_bug`"), |
Alex Burka | b34a7ff | 2017-11-20 18:03:20 | [diff] [blame] | 1286 | external_macro_backtrace: bool = (false, parse_bool, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1287 | "show macro backtraces even for non-local macros"), |
Esteban Küber | 482f7f1 | 2018-01-23 19:34:57 | [diff] [blame] | 1288 | teach: bool = (false, parse_bool, [TRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1289 | "show extended diagnostic help"), |
Esteban Küber | 21f2e93 | 2019-08-15 00:57:28 | [diff] [blame] | 1290 | terminal_width: Option<usize> = (None, parse_opt_uint, [UNTRACKED], |
| 1291 | "set the current terminal width"), |
Tyler Mandry | 3f0254e | 2019-09-20 02:33:38 | [diff] [blame] | 1292 | panic_abort_tests: bool = (false, parse_bool, [TRACKED], |
| 1293 | "support compiling tests with panic=abort"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1294 | continue_parse_after_error: bool = (false, parse_bool, [TRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1295 | "attempt to recover from parse errors (experimental)"), |
John Kåre Alsaker | f0b15f6 | 2019-02-10 23:03:51 | [diff] [blame] | 1296 | dep_tasks: bool = (false, parse_bool, [UNTRACKED], |
| 1297 | "print tasks that execute and the color their dep node gets (requires debug build)"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1298 | incremental: Option<String> = (None, parse_opt_string, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1299 | "enable incremental compilation (experimental)"), |
Michael Woerister | cb1ff24 | 2017-11-16 16:13:39 | [diff] [blame] | 1300 | incremental_queries: bool = (true, parse_bool, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1301 | "enable incremental compilation support for queries (experimental)"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1302 | incremental_info: bool = (false, parse_bool, [UNTRACKED], |
Niko Matsakis | d4bd054 | 2016-08-06 00:12:02 | [diff] [blame] | 1303 | "print high-level information about incremental reuse (or the lack thereof)"), |
Niko Matsakis | 57ffda6 | 2016-12-01 17:29:28 | [diff] [blame] | 1304 | incremental_dump_hash: bool = (false, parse_bool, [UNTRACKED], |
| 1305 | "dump hash information in textual format to stdout"), |
Michael Woerister | 3c6f620 | 2017-11-07 14:22:29 | [diff] [blame] | 1306 | incremental_verify_ich: bool = (false, parse_bool, [UNTRACKED], |
| 1307 | "verify incr. comp. hashes of green query instances"), |
Michael Woerister | c5dd9f5 | 2017-12-04 11:47:16 | [diff] [blame] | 1308 | incremental_ignore_spans: bool = (false, parse_bool, [UNTRACKED], |
| 1309 | "ignore spans during ICH computation -- used for testing"), |
Jun Wu | 31a5066 | 2018-12-30 19:59:03 | [diff] [blame] | 1310 | instrument_mcount: bool = (false, parse_bool, [TRACKED], |
| 1311 | "insert function instrument code for mcount-based tracing"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1312 | dump_dep_graph: bool = (false, parse_bool, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1313 | "dump the dependency graph to $RUST_DEP_GRAPH (default: /tmp/dep_graph.gv)"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1314 | query_dep_graph: bool = (false, parse_bool, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1315 | "enable queries of the dependency graph for regression testing"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1316 | no_analysis: bool = (false, parse_bool, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1317 | "parse and expand the source, but run no analysis"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1318 | extra_plugins: Vec<String> = (Vec::new(), parse_list, [TRACKED], |
Manish Goregaokar | c41cafb | 2014-12-09 17:25:37 | [diff] [blame] | 1319 | "load extra plugins"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1320 | unstable_options: bool = (false, parse_bool, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1321 | "adds unstable command line options to rustc interface"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1322 | force_overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1323 | "force overflow checks on or off"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1324 | trace_macros: bool = (false, parse_bool, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1325 | "for every macro invocation, print its name and arguments"), |
Vadim Chugunov | cf64611 | 2016-08-25 02:34:31 | [diff] [blame] | 1326 | debug_macros: bool = (false, parse_bool, [TRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1327 | "emit line numbers debug info inside macros"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1328 | keep_hygiene_data: bool = (false, parse_bool, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1329 | "don't clear the hygiene data after analysis"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1330 | keep_ast: bool = (false, parse_bool, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1331 | "keep the AST after lowering it to HIR"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1332 | show_span: Option<String> = (None, parse_opt_string, [TRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1333 | "show spans for compiler debugging (expr|pat|ty)"), |
Felix S. Klock II | 9383fcf | 2016-11-14 16:46:20 | [diff] [blame] | 1334 | print_type_sizes: bool = (false, parse_bool, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1335 | "print layout information for each type encountered"), |
Irina Popa | b63d7e2 | 2018-05-08 13:10:16 | [diff] [blame] | 1336 | print_mono_items: Option<String> = (None, parse_opt_string, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1337 | "print the result of the monomorphization collection pass"), |
Ulrik Sverdrup | 6d46a21 | 2016-12-11 20:16:01 | [diff] [blame] | 1338 | mir_opt_level: usize = (1, parse_uint, [TRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1339 | "set the MIR optimization level (0-3, default: 1)"), |
Nikita Popov | 1230813 | 2018-05-14 13:20:51 | [diff] [blame] | 1340 | mutable_noalias: Option<bool> = (None, parse_opt_bool, [TRACKED], |
Josh Stone | 8bb5c12 | 2019-10-04 23:53:18 | [diff] [blame] | 1341 | "emit noalias metadata for mutable references (default: no)"), |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 1342 | dump_mir: Option<String> = (None, parse_opt_string, [UNTRACKED], |
Edd Barrett | 5f9f05d | 2018-12-07 14:48:16 | [diff] [blame] | 1343 | "dump MIR state to file. |
| 1344 | `val` is used to select which passes and functions to dump. For example: |
| 1345 | `all` matches all passes and functions, |
| 1346 | `foo` matches all passes for functions whose name contains 'foo', |
| 1347 | `foo & ConstProp` only the 'ConstProp' pass for function names containing 'foo', |
| 1348 | `foo | bar` all passes for function names containing 'foo' or 'bar'."), |
| 1349 | |
varkor | 2ccc82e | 2018-01-14 20:02:07 | [diff] [blame] | 1350 | dump_mir_dir: String = (String::from("mir_dump"), parse_string, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1351 | "the directory the MIR is dumped into"), |
Mikhail Modin | 08b1fe3 | 2017-10-24 11:48:39 | [diff] [blame] | 1352 | dump_mir_graphviz: bool = (false, parse_bool, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1353 | "in addition to `.mir` files, create graphviz `.dot` files"), |
Niko Matsakis | 46b342f | 2017-04-25 22:23:33 | [diff] [blame] | 1354 | dump_mir_exclude_pass_number: bool = (false, parse_bool, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1355 | "if set, exclude the pass number when dumping MIR (used in tests)"), |
Ralf Jung | aafcf2c | 2018-10-24 09:47:17 | [diff] [blame] | 1356 | mir_emit_retag: bool = (false, parse_bool, [TRACKED], |
Alexander Regueiro | ee89c08 | 2018-11-27 02:59:49 | [diff] [blame] | 1357 | "emit Retagging MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0"), |
Michael Woerister | dd65cb2 | 2016-08-23 17:23:58 | [diff] [blame] | 1358 | perf_stats: bool = (false, parse_bool, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1359 | "print some performance-related statistics"), |
John Kåre Alsaker | 0257c5a | 2018-12-24 05:18:39 | [diff] [blame] | 1360 | query_stats: bool = (false, parse_bool, [UNTRACKED], |
| 1361 | "print some statistics about the query system"), |
Michael Woerister | 94e655e | 2016-11-04 15:37:39 | [diff] [blame] | 1362 | hir_stats: bool = (false, parse_bool, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1363 | "print some statistics about AST and HIR"), |
Oliver Schneider | 87a9ae2 | 2016-12-07 12:22:21 | [diff] [blame] | 1364 | always_encode_mir: bool = (false, parse_bool, [TRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1365 | "encode MIR of all functions into the crate metadata"), |
Oliver Scherer | 39b2137 | 2019-03-25 10:16:58 | [diff] [blame] | 1366 | json_rendered: Option<String> = (None, parse_opt_string, [UNTRACKED], |
| 1367 | "describes how to render the `rendered` field of json diagnostics"), |
Oliver Scherer | d0129a6 | 2018-11-21 09:54:46 | [diff] [blame] | 1368 | unleash_the_miri_inside_of_you: bool = (false, parse_bool, [TRACKED], |
| 1369 | "take the breaks off const evaluation. NOTE: this is unsound"), |
Dylan MacKenzie | bc7928a | 2019-09-24 04:33:58 | [diff] [blame] | 1370 | suppress_const_validation_back_compat_ice: bool = (false, parse_bool, [TRACKED], |
| 1371 | "silence ICE triggered when the new const validator disagrees with the old"), |
Alex Crichton | 1b8e6c1 | 2016-12-17 22:11:02 | [diff] [blame] | 1372 | osx_rpath_install_name: bool = (false, parse_bool, [TRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1373 | "pass `-install_name @rpath/...` to the macOS linker"), |
Jorge Aparicio | 0b06db5 | 2017-02-21 03:34:42 | [diff] [blame] | 1374 | sanitizer: Option<Sanitizer> = (None, parse_sanitizer, [TRACKED], |
Brian Anderson | c03077b | 2019-08-07 21:51:49 | [diff] [blame] | 1375 | "use a sanitizer"), |
Austin Hicks | 63ebf08 | 2017-03-08 21:28:47 | [diff] [blame] | 1376 | fuel: Option<(String, u64)> = (None, parse_optimization_fuel, [TRACKED], |
oyvindln | e89748e | 2017-09-13 20:50:47 | [diff] [blame] | 1377 | "set the optimization fuel quota for a crate"), |
Austin Hicks | 63ebf08 | 2017-03-08 21:28:47 | [diff] [blame] | 1378 | print_fuel: Option<String> = (None, parse_opt_string, [TRACKED], |
Brian Anderson | c03077b | 2019-08-07 21:51:49 | [diff] [blame] | 1379 | "make rustc print the total optimization fuel used by a crate"), |
Alex Crichton | 99f629a | 2017-05-08 20:36:26 | [diff] [blame] | 1380 | force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED], |
| 1381 | "force all crates to be `rustc_private` unstable"), |
Jorge Aparicio | 94d2c43 | 2017-05-13 13:21:24 | [diff] [blame] | 1382 | pre_link_arg: Vec<String> = (vec![], parse_string_push, [UNTRACKED], |
| 1383 | "a single extra argument to prepend the linker invocation (can be used several times)"), |
| 1384 | pre_link_args: Option<Vec<String>> = (None, parse_opt_list, [UNTRACKED], |
| 1385 | "extra arguments to prepend to the linker invocation (space separated)"), |
whitequark | 42754ce | 2017-02-13 09:57:50 | [diff] [blame] | 1386 | profile: bool = (false, parse_bool, [TRACKED], |
| 1387 | "insert profiling code"), |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1388 | disable_instrumentation_preinliner: bool = (false, parse_bool, [TRACKED], |
| 1389 | "Disable the instrumentation pre-inliner, useful for profiling / PGO."), |
Johannes Löthberg | 6a8328c | 2017-07-17 22:18:00 | [diff] [blame] | 1390 | relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED], |
| 1391 | "choose which RELRO level to use"), |
Niko Matsakis | eaac10e | 2018-05-01 14:49:11 | [diff] [blame] | 1392 | nll_facts: bool = (false, parse_bool, [UNTRACKED], |
| 1393 | "dump facts from NLL analysis into side files"), |
Felix S. Klock II | 173315e | 2018-05-04 10:05:10 | [diff] [blame] | 1394 | nll_dont_emit_read_for_match: bool = (false, parse_bool, [UNTRACKED], |
Remy Rakic | f5e3105 | 2018-09-14 19:05:31 | [diff] [blame] | 1395 | "in match codegen, do not include FakeRead statements (used by mir-borrowck)"), |
Felix S. Klock II | 82e1750 | 2018-09-15 04:27:55 | [diff] [blame] | 1396 | dont_buffer_diagnostics: bool = (false, parse_bool, [UNTRACKED], |
| 1397 | "emit diagnostics rather than buffering (breaks NLL error downgrading, sorting)."), |
Douglas Campos | 4f88283 | 2018-05-25 22:17:04 | [diff] [blame] | 1398 | polonius: bool = (false, parse_bool, [UNTRACKED], |
| 1399 | "enable polonius-based borrow-checker"), |
Irina Popa | b63d7e2 | 2018-05-08 13:10:16 | [diff] [blame] | 1400 | codegen_time_graph: bool = (false, parse_bool, [UNTRACKED], |
| 1401 | "generate a graphical HTML report of time spent in codegen and LLVM"), |
Alex Crichton | 855f6d1 | 2017-11-25 19:13:58 | [diff] [blame] | 1402 | thinlto: Option<bool> = (None, parse_opt_bool, [TRACKED], |
Alex Crichton | 4ca1b19 | 2017-07-23 15:14:38 | [diff] [blame] | 1403 | "enable ThinLTO when possible"), |
Alex Crichton | 4b2bdf7 | 2017-10-06 21:59:33 | [diff] [blame] | 1404 | inline_in_all_cgus: Option<bool> = (None, parse_opt_bool, [TRACKED], |
Samy Kacimi | 66815c6 | 2019-07-23 19:26:01 | [diff] [blame] | 1405 | "control whether `#[inline]` functions are in all CGUs"), |
Amanieu d'Antras | fdf7ba2 | 2017-11-06 21:10:49 | [diff] [blame] | 1406 | tls_model: Option<String> = (None, parse_opt_string, [TRACKED], |
Samy Kacimi | 66815c6 | 2019-07-23 19:26:01 | [diff] [blame] | 1407 | "choose the TLS model to use (`rustc --print tls-models` for details)"), |
Robin Kruppe | 0d6b52c | 2017-10-09 00:14:00 | [diff] [blame] | 1408 | saturating_float_casts: bool = (false, parse_bool, [TRACKED], |
Robin Kruppe | 5952441 | 2017-11-09 23:24:05 | [diff] [blame] | 1409 | "make float->int casts UB-free: numbers outside the integer type's range are clipped to \ |
| 1410 | the max/min integer respectively, and NaN is mapped to 0"), |
Michael Woerister | 94f3037 | 2018-01-08 11:30:52 | [diff] [blame] | 1411 | human_readable_cgu_names: bool = (false, parse_bool, [TRACKED], |
| 1412 | "generate human-readable, predictable names for codegen units"), |
Adam C. Foltzer | 8c09d29 | 2018-01-15 21:08:27 | [diff] [blame] | 1413 | dep_info_omit_d_target: bool = (false, parse_bool, [TRACKED], |
| 1414 | "in dep-info output, omit targets for tracking dependencies of the dep-info files \ |
| 1415 | themselves"), |
Mark Mansi | ebfa6c7 | 2018-01-15 03:11:40 | [diff] [blame] | 1416 | unpretty: Option<String> = (None, parse_unpretty, [UNTRACKED], |
Brian Anderson | c03077b | 2019-08-07 21:51:49 | [diff] [blame] | 1417 | "present the input source, unstable (and less-pretty) variants; |
Mark Mansi | ebfa6c7 | 2018-01-15 03:11:40 | [diff] [blame] | 1418 | valid types are any of the types for `--pretty`, as well as: |
Hirokazu Hata | 260fb31 | 2019-01-14 15:09:21 | [diff] [blame] | 1419 | `expanded`, `expanded,identified`, |
| 1420 | `expanded,hygiene` (with internal representations), |
Mark Mansi | ebfa6c7 | 2018-01-15 03:11:40 | [diff] [blame] | 1421 | `everybody_loops` (all function bodies replaced with `loop {}`), |
Hirokazu Hata | 260fb31 | 2019-01-14 15:09:21 | [diff] [blame] | 1422 | `hir` (the HIR), `hir,identified`, |
| 1423 | `hir,typed` (HIR with types for each node), |
| 1424 | `hir-tree` (dump the raw HIR), |
| 1425 | `mir` (the MIR), or `mir-cfg` (graphviz formatted MIR)"), |
Alex Crichton | 0f16eee | 2018-01-26 05:21:02 | [diff] [blame] | 1426 | run_dsymutil: Option<bool> = (None, parse_opt_bool, [TRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1427 | "run `dsymutil` and delete intermediate object files"), |
Vadim Petrochenkov | cdbd8c2 | 2018-02-23 00:18:53 | [diff] [blame] | 1428 | ui_testing: bool = (false, parse_bool, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1429 | "format compiler diagnostics in a way that's better suitable for UI testing"), |
Alex Crichton | 0e0f74b | 2018-03-09 15:25:54 | [diff] [blame] | 1430 | embed_bitcode: bool = (false, parse_bool, [TRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1431 | "embed LLVM bitcode in object files"), |
Johannes Löthberg | 2f0dd4a | 2018-03-20 15:23:31 | [diff] [blame] | 1432 | strip_debuginfo_if_disabled: Option<bool> = (None, parse_opt_bool, [TRACKED], |
| 1433 | "tell the linker to strip debuginfo when building without debuginfo enabled."), |
Michael Woerister | 4f6d05d | 2018-03-06 09:33:42 | [diff] [blame] | 1434 | share_generics: Option<bool> = (None, parse_opt_bool, [TRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1435 | "make the current crate share its generic instantiations"), |
Niko Matsakis | 3aa1085 | 2018-03-22 09:19:25 | [diff] [blame] | 1436 | chalk: bool = (false, parse_bool, [TRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1437 | "enable the experimental Chalk-based trait solving engine"), |
Nikita Popov | 54f0668 | 2018-05-22 17:23:40 | [diff] [blame] | 1438 | no_parallel_llvm: bool = (false, parse_bool, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1439 | "don't run LLVM in parallel (while keeping codegen-units and ThinLTO)"), |
Niko Matsakis | d9afd2b | 2018-07-23 14:30:59 | [diff] [blame] | 1440 | no_leak_check: bool = (false, parse_bool, [UNTRACKED], |
| 1441 | "disables the 'leak check' for subtyping; unsound, but useful for tests"), |
John Kåre Alsaker | beb0c74 | 2019-01-18 06:40:55 | [diff] [blame] | 1442 | no_interleave_lints: bool = (false, parse_bool, [UNTRACKED], |
| 1443 | "don't interleave execution of lints; allows benchmarking individual lints"), |
Pietro Albini | 71276c6 | 2018-07-18 18:34:08 | [diff] [blame] | 1444 | crate_attr: Vec<String> = (Vec::new(), parse_string_push, [TRACKED], |
| 1445 | "inject the given attribute in the crate"), |
Michael Woerister | 64ee32e | 2019-05-28 14:13:59 | [diff] [blame] | 1446 | self_profile: SwitchWithOptPath = (SwitchWithOptPath::Disabled, |
| 1447 | parse_switch_with_opt_path, [UNTRACKED], |
Wesley Wiser | fccc841 | 2019-02-11 23:11:43 | [diff] [blame] | 1448 | "run the self profiler and output the raw event data"), |
Michael Woerister | 08efbac | 2019-04-12 12:48:41 | [diff] [blame] | 1449 | self_profile_events: Option<Vec<String>> = (None, parse_opt_comma_list, [UNTRACKED], |
| 1450 | "specifies which kinds of events get recorded by the self profiler"), |
Jorge Aparicio | 3c0907c | 2018-09-13 17:43:15 | [diff] [blame] | 1451 | emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED], |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 1452 | "emits a section containing stack size metadata"), |
Gabriel Majeri | 6009da0 | 2018-09-26 16:19:55 | [diff] [blame] | 1453 | plt: Option<bool> = (None, parse_opt_bool, [TRACKED], |
| 1454 | "whether to use the PLT when calling into shared libraries; |
| 1455 | only has effect for PIC code on systems with ELF binaries |
| 1456 | (default: PLT is disabled if full relro is enabled)"), |
Peter Jin | b91d211 | 2018-12-31 18:58:13 | [diff] [blame] | 1457 | merge_functions: Option<MergeFunctions> = (None, parse_merge_functions, [TRACKED], |
| 1458 | "control the operation of the MergeFunctions LLVM pass, taking |
| 1459 | the same values as the target option of the same name"), |
Tyler Mandry | 7c59ce9 | 2019-03-13 23:29:24 | [diff] [blame] | 1460 | allow_features: Option<Vec<String>> = (None, parse_opt_comma_list, [TRACKED], |
| 1461 | "only allow the listed language features to be enabled in code (space separated)"), |
Eduard-Mihai Burtescu | 2092963 | 2019-01-29 05:24:32 | [diff] [blame] | 1462 | symbol_mangling_version: SymbolManglingVersion = (SymbolManglingVersion::Legacy, |
| 1463 | parse_symbol_mangling_version, [TRACKED], |
| 1464 | "which mangling version to use for symbol names"), |
Mark Rousskov | d749b5e | 2019-07-24 15:00:09 | [diff] [blame] | 1465 | binary_dep_depinfo: bool = (false, parse_bool, [TRACKED], |
| 1466 | "include artifacts (sysroot, crate dependencies) used during compilation in dep-info"), |
Xiang Fan | 10c6681 | 2019-09-27 23:13:53 | [diff] [blame] | 1467 | insert_sideeffect: bool = (false, parse_bool, [TRACKED], |
| 1468 | "fix undefined behavior when a thread doesn't eventually make progress \ |
| 1469 | (such as entering an empty infinite loop) by inserting llvm.sideeffect"), |
Manish Goregaokar | 7e87ea9 | 2014-12-09 09:55:49 | [diff] [blame] | 1470 | } |
| 1471 | |
Mark Rousskov | c0fdddc | 2019-10-25 17:23:18 | [diff] [blame] | 1472 | pub const fn default_lib_output() -> CrateType { |
Mark Rousskov | 2a93442 | 2018-07-26 17:13:11 | [diff] [blame] | 1473 | CrateType::Rlib |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1474 | } |
| 1475 | |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1476 | pub fn default_configuration(sess: &Session) -> ast::CrateConfig { |
Niko Matsakis | 68e5bb3 | 2015-02-20 19:08:14 | [diff] [blame] | 1477 | let end = &sess.target.target.target_endian; |
| 1478 | let arch = &sess.target.target.arch; |
| 1479 | let wordsz = &sess.target.target.target_pointer_width; |
| 1480 | let os = &sess.target.target.target_os; |
Alex Crichton | ba2380d | 2015-04-21 22:53:32 | [diff] [blame] | 1481 | let env = &sess.target.target.target_env; |
Sebastian Wicki | af68cdf | 2015-09-23 23:20:43 | [diff] [blame] | 1482 | let vendor = &sess.target.target.target_vendor; |
whitequark | 5b0700e | 2016-08-15 09:46:44 | [diff] [blame] | 1483 | let min_atomic_width = sess.target.target.min_atomic_width(); |
Jorge Aparicio | 6136069 | 2016-10-04 04:45:40 | [diff] [blame] | 1484 | let max_atomic_width = sess.target.target.max_atomic_width(); |
Jorge Aparicio | bbf688a | 2018-06-30 19:56:08 | [diff] [blame] | 1485 | let atomic_cas = sess.target.target.options.atomic_cas; |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1486 | |
Eduard-Mihai Burtescu | 93f3f5b | 2018-08-18 10:55:43 | [diff] [blame] | 1487 | let mut ret = FxHashSet::default(); |
ljedrz | 675f00b | 2018-10-10 13:30:53 | [diff] [blame] | 1488 | ret.reserve(6); // the minimum number of insertions |
Jeffrey Seyfried | 4b9b0d3 | 2016-11-15 08:54:27 | [diff] [blame] | 1489 | // Target bindings. |
Jeffrey Seyfried | e85a0d7 | 2016-11-16 10:52:37 | [diff] [blame] | 1490 | ret.insert((Symbol::intern("target_os"), Some(Symbol::intern(os)))); |
Jeremy Soller | 4dcb867 | 2016-12-23 05:29:33 | [diff] [blame] | 1491 | if let Some(ref fam) = sess.target.target.options.target_family { |
| 1492 | ret.insert((Symbol::intern("target_family"), Some(Symbol::intern(fam)))); |
Jeremy Soller | c59bb49 | 2016-12-23 05:20:47 | [diff] [blame] | 1493 | if fam == "windows" || fam == "unix" { |
Jeremy Soller | 4dcb867 | 2016-12-23 05:29:33 | [diff] [blame] | 1494 | ret.insert((Symbol::intern(fam), None)); |
Jeremy Soller | c59bb49 | 2016-12-23 05:20:47 | [diff] [blame] | 1495 | } |
| 1496 | } |
Jeffrey Seyfried | e85a0d7 | 2016-11-16 10:52:37 | [diff] [blame] | 1497 | ret.insert((Symbol::intern("target_arch"), Some(Symbol::intern(arch)))); |
| 1498 | ret.insert((Symbol::intern("target_endian"), Some(Symbol::intern(end)))); |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1499 | ret.insert(( |
| 1500 | Symbol::intern("target_pointer_width"), |
| 1501 | Some(Symbol::intern(wordsz)), |
| 1502 | )); |
Jeffrey Seyfried | e85a0d7 | 2016-11-16 10:52:37 | [diff] [blame] | 1503 | ret.insert((Symbol::intern("target_env"), Some(Symbol::intern(env)))); |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1504 | ret.insert(( |
| 1505 | Symbol::intern("target_vendor"), |
| 1506 | Some(Symbol::intern(vendor)), |
| 1507 | )); |
Alex Crichton | b67b5a8 | 2015-12-10 20:21:55 | [diff] [blame] | 1508 | if sess.target.target.options.has_elf_tls { |
Nicholas Nethercote | 26451ef | 2019-05-22 02:42:23 | [diff] [blame] | 1509 | ret.insert((sym::target_thread_local, None)); |
Alex Crichton | b67b5a8 | 2015-12-10 20:21:55 | [diff] [blame] | 1510 | } |
Amanieu d'Antras | 04835ea | 2016-04-15 19:16:19 | [diff] [blame] | 1511 | for &i in &[8, 16, 32, 64, 128] { |
whitequark | 5b0700e | 2016-08-15 09:46:44 | [diff] [blame] | 1512 | if i >= min_atomic_width && i <= max_atomic_width { |
Amanieu d'Antras | dfe76a1 | 2019-10-08 16:09:23 | [diff] [blame] | 1513 | let mut insert_atomic = |s| { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1514 | ret.insert(( |
Amanieu d'Antras | dfe76a1 | 2019-10-08 16:09:23 | [diff] [blame] | 1515 | sym::target_has_atomic_load_store, |
| 1516 | Some(Symbol::intern(s)), |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1517 | )); |
Amanieu d'Antras | dfe76a1 | 2019-10-08 16:09:23 | [diff] [blame] | 1518 | if atomic_cas { |
| 1519 | ret.insert(( |
| 1520 | sym::target_has_atomic, |
| 1521 | Some(Symbol::intern(s)) |
| 1522 | )); |
| 1523 | } |
| 1524 | }; |
| 1525 | let s = i.to_string(); |
| 1526 | insert_atomic(&s); |
| 1527 | if &s == wordsz { |
| 1528 | insert_atomic("ptr"); |
Amanieu d'Antras | 04835ea | 2016-04-15 19:16:19 | [diff] [blame] | 1529 | } |
| 1530 | } |
| 1531 | } |
Alex Crichton | d5d8345 | 2015-03-02 22:51:24 | [diff] [blame] | 1532 | if sess.opts.debug_assertions { |
Jeffrey Seyfried | d2f8fb0 | 2016-11-16 08:21:52 | [diff] [blame] | 1533 | ret.insert((Symbol::intern("debug_assertions"), None)); |
Alex Crichton | d5d8345 | 2015-03-02 22:51:24 | [diff] [blame] | 1534 | } |
Mark Rousskov | 2a93442 | 2018-07-26 17:13:11 | [diff] [blame] | 1535 | if sess.opts.crate_types.contains(&CrateType::ProcMacro) { |
Nicholas Nethercote | 26451ef | 2019-05-22 02:42:23 | [diff] [blame] | 1536 | ret.insert((sym::proc_macro, None)); |
Alex Crichton | ecc6c39 | 2016-08-23 00:07:11 | [diff] [blame] | 1537 | } |
ljedrz | 0b2e9f7 | 2018-10-10 13:33:10 | [diff] [blame] | 1538 | ret |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1539 | } |
| 1540 | |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 1541 | /// Converts the crate `cfg!` configuration from `String` to `Symbol`. |
John Kåre Alsaker | 51938c6 | 2018-12-08 19:30:23 | [diff] [blame] | 1542 | /// `rustc_interface::interface::Config` accepts this in the compiler configuration, |
| 1543 | /// but the symbol interner is not yet set up then, so we must convert it later. |
| 1544 | pub fn to_crate_config(cfg: FxHashSet<(String, Option<String>)>) -> ast::CrateConfig { |
| 1545 | cfg.into_iter() |
| 1546 | .map(|(a, b)| (Symbol::intern(&a), b.map(|b| Symbol::intern(&b)))) |
| 1547 | .collect() |
| 1548 | } |
| 1549 | |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1550 | pub fn build_configuration(sess: &Session, mut user_cfg: ast::CrateConfig) -> ast::CrateConfig { |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1551 | // Combine the configuration requested by the session (command line) with |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 1552 | // some default and generated configuration items. |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1553 | let default_cfg = default_configuration(sess); |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 1554 | // If the user wants a test runner, then add the test cfg. |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1555 | if sess.opts.test { |
Nicholas Nethercote | 26451ef | 2019-05-22 02:42:23 | [diff] [blame] | 1556 | user_cfg.insert((sym::test, None)); |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1557 | } |
Jeffrey Seyfried | 4b9b0d3 | 2016-11-15 08:54:27 | [diff] [blame] | 1558 | user_cfg.extend(default_cfg.iter().cloned()); |
| 1559 | user_cfg |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1560 | } |
| 1561 | |
Nick Cameron | 6309b0f | 2015-12-13 22:17:55 | [diff] [blame] | 1562 | pub fn build_target_config(opts: &Options, sp: &Handler) -> Config { |
ljedrz | 0b2e9f7 | 2018-10-10 13:33:10 | [diff] [blame] | 1563 | let target = Target::search(&opts.target_triple).unwrap_or_else(|e| { |
| 1564 | sp.struct_fatal(&format!("Error loading target specification: {}", e)) |
| 1565 | .help("Use `--print target-list` for a list of built-in targets") |
| 1566 | .emit(); |
| 1567 | FatalError.raise(); |
| 1568 | }); |
Corey Richardson | 6b130e3 | 2014-07-23 18:56:36 | [diff] [blame] | 1569 | |
Eduard-Mihai Burtescu | 3ce31eb | 2017-08-05 09:27:28 | [diff] [blame] | 1570 | let (isize_ty, usize_ty) = match &target.target_pointer_width[..] { |
Jake Goulding | bc7595c | 2016-05-06 13:31:11 | [diff] [blame] | 1571 | "16" => (ast::IntTy::I16, ast::UintTy::U16), |
Oliver Schneider | 625e78b | 2016-02-08 15:20:57 | [diff] [blame] | 1572 | "32" => (ast::IntTy::I32, ast::UintTy::U32), |
| 1573 | "64" => (ast::IntTy::I64, ast::UintTy::U64), |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1574 | w => sp.fatal(&format!( |
| 1575 | "target specification was invalid: \ |
| 1576 | unrecognized target-pointer-width {}", |
| 1577 | w |
| 1578 | )).raise(), |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1579 | }; |
Corey Richardson | 6b130e3 | 2014-07-23 18:56:36 | [diff] [blame] | 1580 | |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1581 | Config { |
Zack M. Davis | f668999 | 2017-07-03 18:19:51 | [diff] [blame] | 1582 | target, |
Eduard-Mihai Burtescu | 3ce31eb | 2017-08-05 09:27:28 | [diff] [blame] | 1583 | isize_ty, |
| 1584 | usize_ty, |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1585 | } |
| 1586 | } |
| 1587 | |
Jorge Aparicio | 788181d | 2015-01-28 13:34:18 | [diff] [blame] | 1588 | #[derive(Copy, Clone, PartialEq, Eq, Debug)] |
Alex Crichton | 1282833 | 2016-02-20 06:03:54 | [diff] [blame] | 1589 | pub enum OptionStability { |
| 1590 | Stable, |
Alex Crichton | 1282833 | 2016-02-20 06:03:54 | [diff] [blame] | 1591 | Unstable, |
| 1592 | } |
Felix S. Klock II | e711e2d | 2014-12-17 13:42:50 | [diff] [blame] | 1593 | |
Felix S. Klock II | e711e2d | 2014-12-17 13:42:50 | [diff] [blame] | 1594 | pub struct RustcOptGroup { |
Manish Goregaokar | 69c53ac | 2018-02-23 17:53:00 | [diff] [blame] | 1595 | pub apply: Box<dyn Fn(&mut getopts::Options) -> &mut getopts::Options>, |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1596 | pub name: &'static str, |
Felix S. Klock II | e711e2d | 2014-12-17 13:42:50 | [diff] [blame] | 1597 | pub stability: OptionStability, |
| 1598 | } |
| 1599 | |
| 1600 | impl RustcOptGroup { |
| 1601 | pub fn is_stable(&self) -> bool { |
| 1602 | self.stability == OptionStability::Stable |
| 1603 | } |
| 1604 | |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1605 | pub fn stable<F>(name: &'static str, f: F) -> RustcOptGroup |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1606 | where |
| 1607 | F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static, |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1608 | { |
| 1609 | RustcOptGroup { |
Zack M. Davis | f668999 | 2017-07-03 18:19:51 | [diff] [blame] | 1610 | name, |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1611 | apply: Box::new(f), |
| 1612 | stability: OptionStability::Stable, |
| 1613 | } |
Felix S. Klock II | e711e2d | 2014-12-17 13:42:50 | [diff] [blame] | 1614 | } |
| 1615 | |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1616 | pub fn unstable<F>(name: &'static str, f: F) -> RustcOptGroup |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1617 | where |
| 1618 | F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static, |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1619 | { |
| 1620 | RustcOptGroup { |
Zack M. Davis | f668999 | 2017-07-03 18:19:51 | [diff] [blame] | 1621 | name, |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1622 | apply: Box::new(f), |
| 1623 | stability: OptionStability::Unstable, |
| 1624 | } |
Felix S. Klock II | e711e2d | 2014-12-17 13:42:50 | [diff] [blame] | 1625 | } |
| 1626 | } |
| 1627 | |
| 1628 | // The `opt` local module holds wrappers around the `getopts` API that |
| 1629 | // adds extra rustc-specific metadata to each option; such metadata |
| 1630 | // is exposed by . The public |
| 1631 | // functions below ending with `_u` are the functions that return |
Alexander Regueiro | ee89c08 | 2018-11-27 02:59:49 | [diff] [blame] | 1632 | // *unstable* options, i.e., options that are only enabled when the |
Felix S. Klock II | e711e2d | 2014-12-17 13:42:50 | [diff] [blame] | 1633 | // user also passes the `-Z unstable-options` debugging flag. |
| 1634 | mod opt { |
Vadim Petrochenkov | 4341521 | 2019-07-23 17:34:17 | [diff] [blame] | 1635 | // The `fn flag*` etc below are written so that we can use them |
Felix S. Klock II | e711e2d | 2014-12-17 13:42:50 | [diff] [blame] | 1636 | // in the future; do not warn about them not being used right now. |
| 1637 | #![allow(dead_code)] |
| 1638 | |
| 1639 | use getopts; |
| 1640 | use super::RustcOptGroup; |
| 1641 | |
Nick Cameron | 46aa621 | 2015-03-11 21:44:56 | [diff] [blame] | 1642 | pub type R = RustcOptGroup; |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1643 | pub type S = &'static str; |
Felix S. Klock II | e711e2d | 2014-12-17 13:42:50 | [diff] [blame] | 1644 | |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1645 | fn stable<F>(name: S, f: F) -> R |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1646 | where |
| 1647 | F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static, |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1648 | { |
| 1649 | RustcOptGroup::stable(name, f) |
| 1650 | } |
| 1651 | |
| 1652 | fn unstable<F>(name: S, f: F) -> R |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1653 | where |
| 1654 | F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static, |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1655 | { |
| 1656 | RustcOptGroup::unstable(name, f) |
| 1657 | } |
| 1658 | |
| 1659 | fn longer(a: S, b: S) -> S { |
| 1660 | if a.len() > b.len() { |
| 1661 | a |
| 1662 | } else { |
| 1663 | b |
| 1664 | } |
| 1665 | } |
Felix S. Klock II | e711e2d | 2014-12-17 13:42:50 | [diff] [blame] | 1666 | |
Alex Crichton | 1282833 | 2016-02-20 06:03:54 | [diff] [blame] | 1667 | pub fn opt_s(a: S, b: S, c: S, d: S) -> R { |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1668 | stable(longer(a, b), move |opts| opts.optopt(a, b, c, d)) |
Alex Crichton | 1282833 | 2016-02-20 06:03:54 | [diff] [blame] | 1669 | } |
| 1670 | pub fn multi_s(a: S, b: S, c: S, d: S) -> R { |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1671 | stable(longer(a, b), move |opts| opts.optmulti(a, b, c, d)) |
Alex Crichton | 1282833 | 2016-02-20 06:03:54 | [diff] [blame] | 1672 | } |
| 1673 | pub fn flag_s(a: S, b: S, c: S) -> R { |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1674 | stable(longer(a, b), move |opts| opts.optflag(a, b, c)) |
Alex Crichton | 1282833 | 2016-02-20 06:03:54 | [diff] [blame] | 1675 | } |
| 1676 | pub fn flagopt_s(a: S, b: S, c: S, d: S) -> R { |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1677 | stable(longer(a, b), move |opts| opts.optflagopt(a, b, c, d)) |
Alex Crichton | 1282833 | 2016-02-20 06:03:54 | [diff] [blame] | 1678 | } |
| 1679 | pub fn flagmulti_s(a: S, b: S, c: S) -> R { |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1680 | stable(longer(a, b), move |opts| opts.optflagmulti(a, b, c)) |
Alex Crichton | 1282833 | 2016-02-20 06:03:54 | [diff] [blame] | 1681 | } |
Felix S. Klock II | e711e2d | 2014-12-17 13:42:50 | [diff] [blame] | 1682 | |
Alex Crichton | 1282833 | 2016-02-20 06:03:54 | [diff] [blame] | 1683 | pub fn opt(a: S, b: S, c: S, d: S) -> R { |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1684 | unstable(longer(a, b), move |opts| opts.optopt(a, b, c, d)) |
Alex Crichton | 1282833 | 2016-02-20 06:03:54 | [diff] [blame] | 1685 | } |
| 1686 | pub fn multi(a: S, b: S, c: S, d: S) -> R { |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1687 | unstable(longer(a, b), move |opts| opts.optmulti(a, b, c, d)) |
Alex Crichton | 1282833 | 2016-02-20 06:03:54 | [diff] [blame] | 1688 | } |
| 1689 | pub fn flag(a: S, b: S, c: S) -> R { |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1690 | unstable(longer(a, b), move |opts| opts.optflag(a, b, c)) |
Alex Crichton | 1282833 | 2016-02-20 06:03:54 | [diff] [blame] | 1691 | } |
| 1692 | pub fn flagopt(a: S, b: S, c: S, d: S) -> R { |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1693 | unstable(longer(a, b), move |opts| opts.optflagopt(a, b, c, d)) |
Alex Crichton | 1282833 | 2016-02-20 06:03:54 | [diff] [blame] | 1694 | } |
| 1695 | pub fn flagmulti(a: S, b: S, c: S) -> R { |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1696 | unstable(longer(a, b), move |opts| opts.optflagmulti(a, b, c)) |
Alex Crichton | 1282833 | 2016-02-20 06:03:54 | [diff] [blame] | 1697 | } |
Felix S. Klock II | e711e2d | 2014-12-17 13:42:50 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | /// Returns the "short" subset of the rustc command line options, |
| 1701 | /// including metadata for each option, such as whether the option is |
| 1702 | /// part of the stable long-term interface for rustc. |
| 1703 | pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> { |
Alex Crichton | 117984b | 2014-12-16 00:03:39 | [diff] [blame] | 1704 | vec![ |
Alex Crichton | 1282833 | 2016-02-20 06:03:54 | [diff] [blame] | 1705 | opt::flag_s("h", "help", "Display this message"), |
| 1706 | opt::multi_s("", "cfg", "Configure the compilation environment", "SPEC"), |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1707 | opt::multi_s( |
| 1708 | "L", |
| 1709 | "", |
| 1710 | "Add a directory to the library search path. The |
pravic | 9da67da | 2016-04-15 20:55:42 | [diff] [blame] | 1711 | optional KIND can be one of dependency, crate, native, |
Tshepang Lekhonkhobe | 8353007 | 2019-07-06 03:30:15 | [diff] [blame] | 1712 | framework, or all (the default).", |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1713 | "[KIND=]PATH", |
| 1714 | ), |
| 1715 | opt::multi_s( |
| 1716 | "l", |
| 1717 | "", |
| 1718 | "Link the generated crate(s) to the specified native |
Matt Kraai | 43a0f41 | 2016-04-10 13:59:19 | [diff] [blame] | 1719 | library NAME. The optional KIND can be one of |
Tshepang Lekhonkhobe | 8353007 | 2019-07-06 03:30:15 | [diff] [blame] | 1720 | static, framework, or dylib (the default).", |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1721 | "[KIND=]NAME", |
| 1722 | ), |
Aaron Hill | 1498608 | 2019-07-20 20:34:41 | [diff] [blame] | 1723 | make_crate_type_option(), |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1724 | opt::opt_s( |
| 1725 | "", |
| 1726 | "crate-name", |
| 1727 | "Specify the name of the crate being built", |
| 1728 | "NAME", |
| 1729 | ), |
Peter Hall | 3eb4eae | 2019-03-22 11:51:37 | [diff] [blame] | 1730 | opt::opt_s( |
| 1731 | "", |
| 1732 | "edition", |
| 1733 | "Specify which edition of the compiler to use when compiling code.", |
| 1734 | EDITION_NAME_LIST, |
| 1735 | ), |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1736 | opt::multi_s( |
| 1737 | "", |
| 1738 | "emit", |
| 1739 | "Comma separated list of types of output for \ |
| 1740 | the compiler to emit", |
| 1741 | "[asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]", |
| 1742 | ), |
| 1743 | opt::multi_s( |
| 1744 | "", |
| 1745 | "print", |
Eric Huss | e392db6 | 2019-05-12 21:16:50 | [diff] [blame] | 1746 | "Compiler information to print on stdout", |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1747 | "[crate-name|file-names|sysroot|cfg|target-list|\ |
| 1748 | target-cpus|target-features|relocation-models|\ |
| 1749 | code-models|tls-models|target-spec-json|native-static-libs]", |
| 1750 | ), |
| 1751 | opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"), |
Alex Crichton | 1282833 | 2016-02-20 06:03:54 | [diff] [blame] | 1752 | opt::flagmulti_s("O", "", "Equivalent to -C opt-level=2"), |
| 1753 | opt::opt_s("o", "", "Write output to <filename>", "FILENAME"), |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1754 | opt::opt_s( |
| 1755 | "", |
| 1756 | "out-dir", |
| 1757 | "Write output to compiler-chosen filename \ |
| 1758 | in <dir>", |
| 1759 | "DIR", |
| 1760 | ), |
| 1761 | opt::opt_s( |
| 1762 | "", |
| 1763 | "explain", |
| 1764 | "Provide a detailed explanation of an error \ |
| 1765 | message", |
| 1766 | "OPT", |
| 1767 | ), |
Alex Crichton | 1282833 | 2016-02-20 06:03:54 | [diff] [blame] | 1768 | opt::flag_s("", "test", "Build a test harness"), |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1769 | opt::opt_s( |
| 1770 | "", |
| 1771 | "target", |
| 1772 | "Target triple for which the code is compiled", |
| 1773 | "TARGET", |
| 1774 | ), |
Alex Crichton | 1282833 | 2016-02-20 06:03:54 | [diff] [blame] | 1775 | opt::multi_s("W", "warn", "Set lint warnings", "OPT"), |
| 1776 | opt::multi_s("A", "allow", "Set lint allowed", "OPT"), |
| 1777 | opt::multi_s("D", "deny", "Set lint denied", "OPT"), |
| 1778 | opt::multi_s("F", "forbid", "Set lint forbidden", "OPT"), |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1779 | opt::multi_s( |
| 1780 | "", |
| 1781 | "cap-lints", |
| 1782 | "Set the most restrictive lint level. \ |
| 1783 | More restrictive lints are capped at this \ |
| 1784 | level", |
| 1785 | "LEVEL", |
| 1786 | ), |
Alex Crichton | 1282833 | 2016-02-20 06:03:54 | [diff] [blame] | 1787 | opt::multi_s("C", "codegen", "Set a codegen option", "OPT[=VALUE]"), |
| 1788 | opt::flag_s("V", "version", "Print version info and exit"), |
| 1789 | opt::flag_s("v", "verbose", "Use verbose output"), |
Alex Crichton | 117984b | 2014-12-16 00:03:39 | [diff] [blame] | 1790 | ] |
| 1791 | } |
| 1792 | |
Felix S. Klock II | e711e2d | 2014-12-17 13:42:50 | [diff] [blame] | 1793 | /// Returns all rustc command line options, including metadata for |
| 1794 | /// each option, such as whether the option is part of the stable |
| 1795 | /// long-term interface for rustc. |
| 1796 | pub fn rustc_optgroups() -> Vec<RustcOptGroup> { |
| 1797 | let mut opts = rustc_short_optgroups(); |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 1798 | opts.extend(vec![ |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1799 | opt::multi_s( |
| 1800 | "", |
| 1801 | "extern", |
| 1802 | "Specify where an external rust library is located", |
| 1803 | "NAME=PATH", |
| 1804 | ), |
Aaron Hill | 48ec29d | 2019-01-30 20:33:50 | [diff] [blame] | 1805 | opt::multi_s( |
| 1806 | "", |
| 1807 | "extern-private", |
| 1808 | "Specify where an extern rust library is located, marking it as a private dependency", |
| 1809 | "NAME=PATH", |
| 1810 | ), |
Alex Crichton | 1282833 | 2016-02-20 06:03:54 | [diff] [blame] | 1811 | opt::opt_s("", "sysroot", "Override the system root", "PATH"), |
Alex Crichton | ccbcc72 | 2017-05-04 16:34:44 | [diff] [blame] | 1812 | opt::multi("Z", "", "Set internal debugging options", "FLAG"), |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1813 | opt::opt_s( |
| 1814 | "", |
| 1815 | "error-format", |
| 1816 | "How errors and other messages are produced", |
| 1817 | "human|json|short", |
| 1818 | ), |
Alex Crichton | 1731233 | 2019-07-17 19:52:56 | [diff] [blame] | 1819 | opt::multi_s( |
Oliver Scherer | 96404ee | 2019-03-12 12:06:43 | [diff] [blame] | 1820 | "", |
Alex Crichton | 1731233 | 2019-07-17 19:52:56 | [diff] [blame] | 1821 | "json", |
| 1822 | "Configure the JSON output of the compiler", |
| 1823 | "CONFIG", |
Oliver Scherer | 96404ee | 2019-03-12 12:06:43 | [diff] [blame] | 1824 | ), |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1825 | opt::opt_s( |
| 1826 | "", |
| 1827 | "color", |
| 1828 | "Configure coloring of output: |
Guillaume Gomez | ded701b | 2016-03-15 08:09:29 | [diff] [blame] | 1829 | auto = colorize, if output goes to a tty (default); |
| 1830 | always = always colorize output; |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1831 | never = never colorize output", |
| 1832 | "auto|always|never", |
| 1833 | ), |
| 1834 | opt::opt( |
| 1835 | "", |
| 1836 | "pretty", |
| 1837 | "Pretty-print the input instead of compiling; |
Alex Crichton | 7694ca4 | 2017-09-23 04:34:27 | [diff] [blame] | 1838 | valid types are: `normal` (un-annotated source), |
| 1839 | `expanded` (crates expanded), or |
| 1840 | `expanded,identified` (fully parenthesized, AST nodes with IDs).", |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1841 | "TYPE", |
| 1842 | ), |
| 1843 | opt::multi_s( |
| 1844 | "", |
| 1845 | "remap-path-prefix", |
Jeremy Fitzhardinge | 6d534d5 | 2018-03-13 20:26:07 | [diff] [blame] | 1846 | "Remap source names in all output (compiler messages and output files)", |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1847 | "FROM=TO", |
| 1848 | ), |
Alex Crichton | 117984b | 2014-12-16 00:03:39 | [diff] [blame] | 1849 | ]); |
| 1850 | opts |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 1851 | } |
| 1852 | |
Guillaume Gomez | e221be8 | 2018-06-23 13:09:21 | [diff] [blame] | 1853 | pub fn get_cmd_lint_options(matches: &getopts::Matches, |
| 1854 | error_format: ErrorOutputType) |
| 1855 | -> (Vec<(String, lint::Level)>, bool, Option<lint::Level>) { |
| 1856 | let mut lint_opts = vec![]; |
| 1857 | let mut describe_lints = false; |
| 1858 | |
| 1859 | for &level in &[lint::Allow, lint::Warn, lint::Deny, lint::Forbid] { |
| 1860 | for lint_name in matches.opt_strs(level.as_str()) { |
| 1861 | if lint_name == "help" { |
| 1862 | describe_lints = true; |
| 1863 | } else { |
| 1864 | lint_opts.push((lint_name.replace("-", "_"), level)); |
| 1865 | } |
| 1866 | } |
| 1867 | } |
| 1868 | |
| 1869 | let lint_cap = matches.opt_str("cap-lints").map(|cap| { |
| 1870 | lint::Level::from_str(&cap) |
| 1871 | .unwrap_or_else(|| early_error(error_format, &format!("unknown lint level: `{}`", cap))) |
| 1872 | }); |
| 1873 | (lint_opts, describe_lints, lint_cap) |
| 1874 | } |
| 1875 | |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 1876 | /// Parses the `--color` flag. |
Alex Crichton | 1731233 | 2019-07-17 19:52:56 | [diff] [blame] | 1877 | pub fn parse_color(matches: &getopts::Matches) -> ColorConfig { |
| 1878 | match matches.opt_str("color").as_ref().map(|s| &s[..]) { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1879 | Some("auto") => ColorConfig::Auto, |
Nick Cameron | 6309b0f | 2015-12-13 22:17:55 | [diff] [blame] | 1880 | Some("always") => ColorConfig::Always, |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1881 | Some("never") => ColorConfig::Never, |
Barosl Lee | 71f39c1a | 2015-08-22 14:51:53 | [diff] [blame] | 1882 | |
Nick Cameron | 6309b0f | 2015-12-13 22:17:55 | [diff] [blame] | 1883 | None => ColorConfig::Auto, |
Barosl Lee | 71f39c1a | 2015-08-22 14:51:53 | [diff] [blame] | 1884 | |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1885 | Some(arg) => early_error( |
| 1886 | ErrorOutputType::default(), |
| 1887 | &format!( |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 1888 | "argument for `--color` must be auto, \ |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1889 | always or never (instead was `{}`)", |
| 1890 | arg |
| 1891 | ), |
| 1892 | ), |
Alex Crichton | 1731233 | 2019-07-17 19:52:56 | [diff] [blame] | 1893 | } |
| 1894 | } |
Barosl Lee | 71f39c1a | 2015-08-22 14:51:53 | [diff] [blame] | 1895 | |
Alex Crichton | 1731233 | 2019-07-17 19:52:56 | [diff] [blame] | 1896 | /// Parse the `--json` flag. |
| 1897 | /// |
| 1898 | /// The first value returned is how to render JSON diagnostics, and the second |
| 1899 | /// is whether or not artifact notifications are enabled. |
| 1900 | pub fn parse_json(matches: &getopts::Matches) -> (HumanReadableErrorType, bool) { |
| 1901 | let mut json_rendered: fn(ColorConfig) -> HumanReadableErrorType = |
| 1902 | HumanReadableErrorType::Default; |
| 1903 | let mut json_color = ColorConfig::Never; |
| 1904 | let mut json_artifact_notifications = false; |
| 1905 | for option in matches.opt_strs("json") { |
| 1906 | // For now conservatively forbid `--color` with `--json` since `--json` |
| 1907 | // won't actually be emitting any colors and anything colorized is |
| 1908 | // embedded in a diagnostic message anyway. |
| 1909 | if matches.opt_str("color").is_some() { |
ljedrz | 0b2e9f7 | 2018-10-10 13:33:10 | [diff] [blame] | 1910 | early_error( |
Kurtis Nusbaum | 51f5110 | 2018-04-19 20:56:26 | [diff] [blame] | 1911 | ErrorOutputType::default(), |
Alex Crichton | 1731233 | 2019-07-17 19:52:56 | [diff] [blame] | 1912 | "cannot specify the `--color` option with `--json`", |
| 1913 | ); |
| 1914 | } |
Kurtis Nusbaum | 51f5110 | 2018-04-19 20:56:26 | [diff] [blame] | 1915 | |
Alex Crichton | 1731233 | 2019-07-17 19:52:56 | [diff] [blame] | 1916 | for sub_option in option.split(',') { |
| 1917 | match sub_option { |
| 1918 | "diagnostic-short" => json_rendered = HumanReadableErrorType::Short, |
| 1919 | "diagnostic-rendered-ansi" => json_color = ColorConfig::Always, |
| 1920 | "artifacts" => json_artifact_notifications = true, |
| 1921 | s => { |
| 1922 | early_error( |
| 1923 | ErrorOutputType::default(), |
| 1924 | &format!("unknown `--json` option `{}`", s), |
| 1925 | ) |
| 1926 | } |
| 1927 | } |
| 1928 | } |
Kurtis Nusbaum | 320fdaa | 2018-04-20 04:03:21 | [diff] [blame] | 1929 | } |
Alex Crichton | 1731233 | 2019-07-17 19:52:56 | [diff] [blame] | 1930 | (json_rendered(json_color), json_artifact_notifications) |
| 1931 | } |
Kurtis Nusbaum | 320fdaa | 2018-04-20 04:03:21 | [diff] [blame] | 1932 | |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 1933 | /// Parses the `--error-format` flag. |
Alex Crichton | 1731233 | 2019-07-17 19:52:56 | [diff] [blame] | 1934 | pub fn parse_error_format( |
| 1935 | matches: &getopts::Matches, |
| 1936 | color: ColorConfig, |
| 1937 | json_rendered: HumanReadableErrorType, |
| 1938 | ) -> ErrorOutputType { |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 1939 | // We need the `opts_present` check because the driver will send us Matches |
Nick Cameron | 82f8e5c | 2016-01-06 20:23:01 | [diff] [blame] | 1940 | // with only stable options if no unstable options are used. Since error-format |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 1941 | // is unstable, it will not be present. We have to use `opts_present` not |
| 1942 | // `opt_present` because the latter will panic. |
Nick Cameron | 82f8e5c | 2016-01-06 20:23:01 | [diff] [blame] | 1943 | let error_format = if matches.opts_present(&["error-format".to_owned()]) { |
| 1944 | match matches.opt_str("error-format").as_ref().map(|s| &s[..]) { |
Oliver Scherer | 39b2137 | 2019-03-25 10:16:58 | [diff] [blame] | 1945 | None | |
| 1946 | Some("human") => ErrorOutputType::HumanReadable(HumanReadableErrorType::Default(color)), |
Philipp Hansch | c04a2cc | 2019-05-31 19:15:59 | [diff] [blame] | 1947 | Some("human-annotate-rs") => { |
Philipp Hansch | df076b2 | 2019-06-05 19:13:56 | [diff] [blame] | 1948 | ErrorOutputType::HumanReadable(HumanReadableErrorType::AnnotateSnippet(color)) |
Philipp Hansch | c04a2cc | 2019-05-31 19:15:59 | [diff] [blame] | 1949 | }, |
Oliver Scherer | 39b2137 | 2019-03-25 10:16:58 | [diff] [blame] | 1950 | Some("json") => ErrorOutputType::Json { pretty: false, json_rendered }, |
| 1951 | Some("pretty-json") => ErrorOutputType::Json { pretty: true, json_rendered }, |
| 1952 | Some("short") => ErrorOutputType::HumanReadable(HumanReadableErrorType::Short(color)), |
Nick Cameron | fd46c78 | 2015-12-31 03:50:06 | [diff] [blame] | 1953 | |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1954 | Some(arg) => early_error( |
Oliver Scherer | 39b2137 | 2019-03-25 10:16:58 | [diff] [blame] | 1955 | ErrorOutputType::HumanReadable(HumanReadableErrorType::Default(color)), |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1956 | &format!( |
Alexander Regueiro | 022d9c8 | 2019-09-01 17:09:59 | [diff] [blame] | 1957 | "argument for `--error-format` must be `human`, `json` or \ |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 1958 | `short` (instead was `{}`)", |
| 1959 | arg |
| 1960 | ), |
| 1961 | ), |
Nick Cameron | fd46c78 | 2015-12-31 03:50:06 | [diff] [blame] | 1962 | } |
| 1963 | } else { |
Oliver Scherer | 39b2137 | 2019-03-25 10:16:58 | [diff] [blame] | 1964 | ErrorOutputType::HumanReadable(HumanReadableErrorType::Default(color)) |
Nick Cameron | fd46c78 | 2015-12-31 03:50:06 | [diff] [blame] | 1965 | }; |
| 1966 | |
Alex Crichton | 1731233 | 2019-07-17 19:52:56 | [diff] [blame] | 1967 | match error_format { |
| 1968 | ErrorOutputType::Json { .. } => {} |
| 1969 | |
| 1970 | // Conservatively require that the `--json` argument is coupled with |
| 1971 | // `--error-format=json`. This means that `--json` is specified we |
| 1972 | // should actually be emitting JSON blobs. |
| 1973 | _ if matches.opt_strs("json").len() > 0 => { |
| 1974 | early_error( |
| 1975 | ErrorOutputType::default(), |
| 1976 | "using `--json` requires also using `--error-format=json`", |
| 1977 | ); |
| 1978 | } |
| 1979 | |
| 1980 | _ => {} |
| 1981 | } |
| 1982 | |
| 1983 | return error_format; |
| 1984 | } |
| 1985 | |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 1986 | fn parse_crate_edition(matches: &getopts::Matches) -> Edition { |
Alex Crichton | 1731233 | 2019-07-17 19:52:56 | [diff] [blame] | 1987 | let edition = match matches.opt_str("edition") { |
| 1988 | Some(arg) => Edition::from_str(&arg).unwrap_or_else(|_| |
| 1989 | early_error( |
| 1990 | ErrorOutputType::default(), |
| 1991 | &format!( |
Alexander Regueiro | 022d9c8 | 2019-09-01 17:09:59 | [diff] [blame] | 1992 | "argument for `--edition` must be one of: \ |
Alex Crichton | 1731233 | 2019-07-17 19:52:56 | [diff] [blame] | 1993 | {}. (instead was `{}`)", |
| 1994 | EDITION_NAME_LIST, |
| 1995 | arg |
| 1996 | ), |
| 1997 | ), |
| 1998 | ), |
| 1999 | None => DEFAULT_EDITION, |
| 2000 | }; |
| 2001 | |
| 2002 | if !edition.is_stable() && !nightly_options::is_nightly_build() { |
| 2003 | early_error( |
| 2004 | ErrorOutputType::default(), |
| 2005 | &format!( |
Alexander Regueiro | 022d9c8 | 2019-09-01 17:09:59 | [diff] [blame] | 2006 | "edition {} is unstable and only \ |
Alex Crichton | 1731233 | 2019-07-17 19:52:56 | [diff] [blame] | 2007 | available for nightly builds of rustc.", |
| 2008 | edition, |
| 2009 | ) |
| 2010 | ) |
| 2011 | } |
| 2012 | |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2013 | edition |
| 2014 | } |
Alex Crichton | 1731233 | 2019-07-17 19:52:56 | [diff] [blame] | 2015 | |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2016 | fn check_debug_option_stability( |
| 2017 | debugging_opts: &DebuggingOptions, |
| 2018 | error_format: ErrorOutputType, |
| 2019 | json_rendered: HumanReadableErrorType, |
| 2020 | ) { |
Oliver Scherer | 96404ee | 2019-03-12 12:06:43 | [diff] [blame] | 2021 | if !debugging_opts.unstable_options { |
Oliver Scherer | 39b2137 | 2019-03-25 10:16:58 | [diff] [blame] | 2022 | if let ErrorOutputType::Json { pretty: true, json_rendered } = error_format { |
Oliver Scherer | 96404ee | 2019-03-12 12:06:43 | [diff] [blame] | 2023 | early_error( |
Oliver Scherer | 39b2137 | 2019-03-25 10:16:58 | [diff] [blame] | 2024 | ErrorOutputType::Json { pretty: false, json_rendered }, |
Alexander Regueiro | 022d9c8 | 2019-09-01 17:09:59 | [diff] [blame] | 2025 | "`--error-format=pretty-json` is unstable", |
Oliver Scherer | 96404ee | 2019-03-12 12:06:43 | [diff] [blame] | 2026 | ); |
| 2027 | } |
Philipp Hansch | df076b2 | 2019-06-05 19:13:56 | [diff] [blame] | 2028 | if let ErrorOutputType::HumanReadable(HumanReadableErrorType::AnnotateSnippet(_)) = |
Philipp Hansch | c04a2cc | 2019-05-31 19:15:59 | [diff] [blame] | 2029 | error_format { |
| 2030 | early_error( |
| 2031 | ErrorOutputType::Json { pretty: false, json_rendered }, |
Alexander Regueiro | 022d9c8 | 2019-09-01 17:09:59 | [diff] [blame] | 2032 | "`--error-format=human-annotate-rs` is unstable", |
Philipp Hansch | c04a2cc | 2019-05-31 19:15:59 | [diff] [blame] | 2033 | ); |
| 2034 | } |
Oliver Schneider | c7cb2cf | 2017-11-03 12:38:26 | [diff] [blame] | 2035 | } |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2036 | } |
Oliver Schneider | c7cb2cf | 2017-11-03 12:38:26 | [diff] [blame] | 2037 | |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2038 | fn parse_output_types( |
| 2039 | debugging_opts: &DebuggingOptions, |
| 2040 | matches: &getopts::Matches, |
| 2041 | error_format: ErrorOutputType, |
| 2042 | ) -> OutputTypes { |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2043 | let mut output_types = BTreeMap::new(); |
Eduard Burtescu | a619901 | 2016-05-25 05:46:36 | [diff] [blame] | 2044 | if !debugging_opts.parse_only { |
Alex Crichton | 8c963c0 | 2015-09-30 17:08:37 | [diff] [blame] | 2045 | for list in matches.opt_strs("emit") { |
| 2046 | for output_type in list.split(',') { |
| 2047 | let mut parts = output_type.splitn(2, '='); |
Corey Farwell | c3ea358 | 2017-11-05 14:20:59 | [diff] [blame] | 2048 | let shorthand = parts.next().unwrap(); |
ljedrz | 0b2e9f7 | 2018-10-10 13:33:10 | [diff] [blame] | 2049 | let output_type = OutputType::from_shorthand(shorthand).unwrap_or_else(|| |
| 2050 | early_error( |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2051 | error_format, |
| 2052 | &format!( |
| 2053 | "unknown emission type: `{}` - expected one of: {}", |
| 2054 | shorthand, |
| 2055 | OutputType::shorthands_display(), |
| 2056 | ), |
| 2057 | ), |
ljedrz | 0b2e9f7 | 2018-10-10 13:33:10 | [diff] [blame] | 2058 | ); |
Alex Crichton | 8c963c0 | 2015-09-30 17:08:37 | [diff] [blame] | 2059 | let path = parts.next().map(PathBuf::from); |
| 2060 | output_types.insert(output_type, path); |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 2061 | } |
| 2062 | } |
| 2063 | }; |
Michael Kohl | 9873acc | 2017-05-28 06:49:14 | [diff] [blame] | 2064 | if output_types.is_empty() { |
Alex Crichton | 8c963c0 | 2015-09-30 17:08:37 | [diff] [blame] | 2065 | output_types.insert(OutputType::Exe, None); |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 2066 | } |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2067 | OutputTypes(output_types) |
| 2068 | } |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 2069 | |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2070 | fn should_override_cgus_and_disable_thinlto( |
| 2071 | output_types: &OutputTypes, |
| 2072 | matches: &getopts::Matches, |
| 2073 | error_format: ErrorOutputType, |
| 2074 | mut codegen_units: Option<usize>, |
| 2075 | ) -> (bool, Option<usize>) { |
Alex Crichton | 8bde2ac | 2018-01-16 23:02:31 | [diff] [blame] | 2076 | let mut disable_thinlto = false; |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 2077 | // Issue #30063: if user requests LLVM-related output to one |
Felix S. Klock II | f90c21a | 2015-12-04 18:35:16 | [diff] [blame] | 2078 | // particular path, disable codegen-units. |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2079 | let incompatible: Vec<_> = output_types.0 |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2080 | .iter() |
Alex Crichton | 9e35b79 | 2017-09-25 19:26:25 | [diff] [blame] | 2081 | .map(|ot_path| ot_path.0) |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2082 | .filter(|ot| !ot.is_compatible_with_codegen_units_and_single_output_file()) |
Alex Crichton | 9e35b79 | 2017-09-25 19:26:25 | [diff] [blame] | 2083 | .map(|ot| ot.shorthand()) |
| 2084 | .collect(); |
| 2085 | if !incompatible.is_empty() { |
| 2086 | match codegen_units { |
| 2087 | Some(n) if n > 1 => { |
| 2088 | if matches.opt_present("o") { |
| 2089 | for ot in &incompatible { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2090 | early_warn( |
| 2091 | error_format, |
| 2092 | &format!( |
Alexander Regueiro | 022d9c8 | 2019-09-01 17:09:59 | [diff] [blame] | 2093 | "`--emit={}` with `-o` incompatible with \ |
| 2094 | `-C codegen-units=N` for N > 1", |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2095 | ot |
| 2096 | ), |
| 2097 | ); |
Alex Crichton | 9e35b79 | 2017-09-25 19:26:25 | [diff] [blame] | 2098 | } |
| 2099 | early_warn(error_format, "resetting to default -C codegen-units=1"); |
| 2100 | codegen_units = Some(1); |
Alex Crichton | 8bde2ac | 2018-01-16 23:02:31 | [diff] [blame] | 2101 | disable_thinlto = true; |
Alex Crichton | 9e35b79 | 2017-09-25 19:26:25 | [diff] [blame] | 2102 | } |
Felix S. Klock II | f90c21a | 2015-12-04 18:35:16 | [diff] [blame] | 2103 | } |
Alex Crichton | 855f6d1 | 2017-11-25 19:13:58 | [diff] [blame] | 2104 | _ => { |
| 2105 | codegen_units = Some(1); |
Alex Crichton | 8bde2ac | 2018-01-16 23:02:31 | [diff] [blame] | 2106 | disable_thinlto = true; |
Alex Crichton | 855f6d1 | 2017-11-25 19:13:58 | [diff] [blame] | 2107 | } |
Felix S. Klock II | f90c21a | 2015-12-04 18:35:16 | [diff] [blame] | 2108 | } |
| 2109 | } |
| 2110 | |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2111 | if codegen_units == Some(0) { |
| 2112 | early_error( |
| 2113 | error_format, |
| 2114 | "value for codegen units must be a positive non-zero integer", |
| 2115 | ); |
| 2116 | } |
| 2117 | |
| 2118 | (disable_thinlto, codegen_units) |
| 2119 | } |
| 2120 | |
| 2121 | fn check_thread_count(debugging_opts: &DebuggingOptions, error_format: ErrorOutputType) { |
Mark Rousskov | 1a1067d | 2019-09-30 20:27:28 | [diff] [blame] | 2122 | if debugging_opts.threads == 0 { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2123 | early_error( |
| 2124 | error_format, |
Alexander Regueiro | 022d9c8 | 2019-09-01 17:09:59 | [diff] [blame] | 2125 | "value for threads must be a positive non-zero integer", |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2126 | ); |
John Kåre Alsaker | aa6065b | 2017-12-03 13:16:19 | [diff] [blame] | 2127 | } |
| 2128 | |
Mark Rousskov | 1a1067d | 2019-09-30 20:27:28 | [diff] [blame] | 2129 | if debugging_opts.threads > 1 && debugging_opts.fuel.is_some() { |
John Kåre Alsaker | a46f059 | 2018-04-01 06:20:39 | [diff] [blame] | 2130 | early_error( |
| 2131 | error_format, |
Alexander Regueiro | 022d9c8 | 2019-09-01 17:09:59 | [diff] [blame] | 2132 | "optimization fuel is incompatible with multiple threads", |
John Kåre Alsaker | a46f059 | 2018-04-01 06:20:39 | [diff] [blame] | 2133 | ); |
| 2134 | } |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2135 | } |
John Kåre Alsaker | a46f059 | 2018-04-01 06:20:39 | [diff] [blame] | 2136 | |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2137 | fn select_incremental_path( |
| 2138 | debugging_opts: &DebuggingOptions, |
| 2139 | cg: &CodegenOptions, |
| 2140 | error_format: ErrorOutputType, |
| 2141 | ) -> Option<PathBuf> { |
| 2142 | match (&debugging_opts.incremental, &cg.incremental) { |
| 2143 | (Some(path1), Some(path2)) => { |
Michael Woerister | 796264b | 2017-12-15 20:03:48 | [diff] [blame] | 2144 | if path1 != path2 { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2145 | early_error( |
| 2146 | error_format, |
| 2147 | &format!( |
| 2148 | "conflicting paths for `-Z incremental` and \ |
| 2149 | `-C incremental` specified: {} versus {}", |
| 2150 | path1, path2 |
| 2151 | ), |
| 2152 | ); |
Michael Woerister | 796264b | 2017-12-15 20:03:48 | [diff] [blame] | 2153 | } else { |
| 2154 | Some(path1) |
| 2155 | } |
| 2156 | } |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2157 | (Some(path), None) => Some(path), |
| 2158 | (None, Some(path)) => Some(path), |
| 2159 | (None, None) => None, |
| 2160 | }.map(|m| PathBuf::from(m)) |
| 2161 | } |
Michael Woerister | 796264b | 2017-12-15 20:03:48 | [diff] [blame] | 2162 | |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2163 | fn collect_print_requests( |
| 2164 | cg: &mut CodegenOptions, |
| 2165 | dopts: &mut DebuggingOptions, |
| 2166 | matches: &getopts::Matches, |
| 2167 | is_unstable_enabled: bool, |
| 2168 | error_format: ErrorOutputType, |
| 2169 | ) -> Vec<PrintRequest> { |
Cameron Hart | e1efa32 | 2016-07-10 14:22:13 | [diff] [blame] | 2170 | let mut prints = Vec::<PrintRequest>::new(); |
| 2171 | if cg.target_cpu.as_ref().map_or(false, |s| s == "help") { |
| 2172 | prints.push(PrintRequest::TargetCPUs); |
| 2173 | cg.target_cpu = None; |
| 2174 | }; |
| 2175 | if cg.target_feature == "help" { |
| 2176 | prints.push(PrintRequest::TargetFeatures); |
Matthias Krüger | ede1f7d | 2018-08-23 08:14:52 | [diff] [blame] | 2177 | cg.target_feature = String::new(); |
Cameron Hart | e1efa32 | 2016-07-10 14:22:13 | [diff] [blame] | 2178 | } |
| 2179 | if cg.relocation_model.as_ref().map_or(false, |s| s == "help") { |
| 2180 | prints.push(PrintRequest::RelocationModels); |
| 2181 | cg.relocation_model = None; |
| 2182 | } |
| 2183 | if cg.code_model.as_ref().map_or(false, |s| s == "help") { |
| 2184 | prints.push(PrintRequest::CodeModels); |
| 2185 | cg.code_model = None; |
| 2186 | } |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2187 | if dopts |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2188 | .tls_model |
| 2189 | .as_ref() |
| 2190 | .map_or(false, |s| s == "help") |
| 2191 | { |
Amanieu d'Antras | b233a6e | 2017-10-31 18:24:04 | [diff] [blame] | 2192 | prints.push(PrintRequest::TlsModels); |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2193 | dopts.tls_model = None; |
Amanieu d'Antras | b233a6e | 2017-10-31 18:24:04 | [diff] [blame] | 2194 | } |
Cameron Hart | e1efa32 | 2016-07-10 14:22:13 | [diff] [blame] | 2195 | |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2196 | prints.extend(matches.opt_strs("print").into_iter().map(|s| match &*s { |
| 2197 | "crate-name" => PrintRequest::CrateName, |
| 2198 | "file-names" => PrintRequest::FileNames, |
| 2199 | "sysroot" => PrintRequest::Sysroot, |
| 2200 | "cfg" => PrintRequest::Cfg, |
| 2201 | "target-list" => PrintRequest::TargetList, |
| 2202 | "target-cpus" => PrintRequest::TargetCPUs, |
| 2203 | "target-features" => PrintRequest::TargetFeatures, |
| 2204 | "relocation-models" => PrintRequest::RelocationModels, |
| 2205 | "code-models" => PrintRequest::CodeModels, |
| 2206 | "tls-models" => PrintRequest::TlsModels, |
| 2207 | "native-static-libs" => PrintRequest::NativeStaticLibs, |
| 2208 | "target-spec-json" => { |
| 2209 | if is_unstable_enabled { |
| 2210 | PrintRequest::TargetSpec |
| 2211 | } else { |
| 2212 | early_error( |
| 2213 | error_format, |
| 2214 | "the `-Z unstable-options` flag must also be passed to \ |
| 2215 | enable the target-spec-json print option", |
| 2216 | ); |
| 2217 | } |
| 2218 | } |
| 2219 | req => early_error(error_format, &format!("unknown print request `{}`", req)), |
| 2220 | })); |
Alex Crichton | 117984b | 2014-12-16 00:03:39 | [diff] [blame] | 2221 | |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2222 | prints |
| 2223 | } |
| 2224 | |
| 2225 | fn parse_target_triple(matches: &getopts::Matches, error_format: ErrorOutputType) -> TargetTriple { |
| 2226 | match matches.opt_str("target") { |
| 2227 | Some(target) if target.ends_with(".json") => { |
Philipp Oppermann | 7b49190 | 2018-03-24 19:14:59 | [diff] [blame] | 2228 | let path = Path::new(&target); |
ljedrz | 0b2e9f7 | 2018-10-10 13:33:10 | [diff] [blame] | 2229 | TargetTriple::from_path(&path).unwrap_or_else(|_| |
| 2230 | early_error(error_format, &format!("target file {:?} does not exist", path))) |
Philipp Oppermann | 3908b2e | 2018-03-14 14:27:06 | [diff] [blame] | 2231 | } |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2232 | Some(target) => TargetTriple::TargetTriple(target), |
| 2233 | _ => TargetTriple::from_triple(host_triple()), |
| 2234 | } |
| 2235 | } |
| 2236 | |
| 2237 | fn parse_opt_level( |
| 2238 | matches: &getopts::Matches, |
| 2239 | cg: &CodegenOptions, |
| 2240 | error_format: ErrorOutputType, |
| 2241 | ) -> OptLevel { |
| 2242 | // The `-O` and `-C opt-level` flags specify the same setting, so we want to be able |
| 2243 | // to use them interchangeably. However, because they're technically different flags, |
| 2244 | // we need to work out manually which should take precedence if both are supplied (i.e. |
| 2245 | // the rightmost flag). We do this by finding the (rightmost) position of both flags and |
| 2246 | // comparing them. Note that if a flag is not found, its position will be `None`, which |
| 2247 | // always compared less than `Some(_)`. |
| 2248 | let max_o = matches.opt_positions("O").into_iter().max(); |
| 2249 | let max_c = matches.opt_strs_pos("C").into_iter().flat_map(|(i, s)| { |
| 2250 | if let Some("opt-level") = s.splitn(2, '=').next() { |
| 2251 | Some(i) |
| 2252 | } else { |
| 2253 | None |
| 2254 | } |
| 2255 | }).max(); |
| 2256 | if max_o > max_c { |
| 2257 | OptLevel::Default |
Philipp Oppermann | 3908b2e | 2018-03-14 14:27:06 | [diff] [blame] | 2258 | } else { |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2259 | match cg.opt_level.as_ref().map(String::as_ref) { |
| 2260 | None => OptLevel::No, |
| 2261 | Some("0") => OptLevel::No, |
| 2262 | Some("1") => OptLevel::Less, |
| 2263 | Some("2") => OptLevel::Default, |
| 2264 | Some("3") => OptLevel::Aggressive, |
| 2265 | Some("s") => OptLevel::Size, |
| 2266 | Some("z") => OptLevel::SizeMin, |
| 2267 | Some(arg) => { |
| 2268 | early_error( |
| 2269 | error_format, |
| 2270 | &format!( |
| 2271 | "optimization level needs to be \ |
| 2272 | between 0-3, s or z (instead was `{}`)", |
| 2273 | arg |
| 2274 | ), |
| 2275 | ); |
Alex Crichton | 117984b | 2014-12-16 00:03:39 | [diff] [blame] | 2276 | } |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 2277 | } |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2278 | } |
| 2279 | } |
| 2280 | |
| 2281 | fn select_debuginfo( |
| 2282 | matches: &getopts::Matches, |
| 2283 | cg: &CodegenOptions, |
| 2284 | error_format: ErrorOutputType, |
| 2285 | ) -> DebugInfo { |
varkor | e8e43c9 | 2019-04-30 20:52:05 | [diff] [blame] | 2286 | let max_g = matches.opt_positions("g").into_iter().max(); |
| 2287 | let max_c = matches.opt_strs_pos("C").into_iter().flat_map(|(i, s)| { |
| 2288 | if let Some("debuginfo") = s.splitn(2, '=').next() { |
| 2289 | Some(i) |
| 2290 | } else { |
| 2291 | None |
Alex Crichton | 117984b | 2014-12-16 00:03:39 | [diff] [blame] | 2292 | } |
varkor | e8e43c9 | 2019-04-30 20:52:05 | [diff] [blame] | 2293 | }).max(); |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2294 | if max_g > max_c { |
Mark Rousskov | 2bc7197 | 2018-07-26 17:41:10 | [diff] [blame] | 2295 | DebugInfo::Full |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 2296 | } else { |
Alex Crichton | 117984b | 2014-12-16 00:03:39 | [diff] [blame] | 2297 | match cg.debuginfo { |
Mark Rousskov | 2bc7197 | 2018-07-26 17:41:10 | [diff] [blame] | 2298 | None | Some(0) => DebugInfo::None, |
| 2299 | Some(1) => DebugInfo::Limited, |
| 2300 | Some(2) => DebugInfo::Full, |
Alex Crichton | 117984b | 2014-12-16 00:03:39 | [diff] [blame] | 2301 | Some(arg) => { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2302 | early_error( |
| 2303 | error_format, |
| 2304 | &format!( |
| 2305 | "debug info level needs to be between \ |
| 2306 | 0-2 (instead was `{}`)", |
| 2307 | arg |
| 2308 | ), |
| 2309 | ); |
Alex Crichton | 117984b | 2014-12-16 00:03:39 | [diff] [blame] | 2310 | } |
| 2311 | } |
Alex Crichton | d085d9d | 2014-12-16 22:32:02 | [diff] [blame] | 2312 | } |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2313 | } |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 2314 | |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2315 | fn parse_libs( |
| 2316 | matches: &getopts::Matches, |
| 2317 | error_format: ErrorOutputType, |
| 2318 | ) -> Vec<(String, Option<String>, Option<cstore::NativeLibraryKind>)> { |
| 2319 | matches |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2320 | .opt_strs("l") |
| 2321 | .into_iter() |
| 2322 | .map(|s| { |
| 2323 | // Parse string of the form "[KIND=]lib[:new_name]", |
| 2324 | // where KIND is one of "dylib", "framework", "static". |
| 2325 | let mut parts = s.splitn(2, '='); |
| 2326 | let kind = parts.next().unwrap(); |
| 2327 | let (name, kind) = match (parts.next(), kind) { |
| 2328 | (None, name) => (name, None), |
| 2329 | (Some(name), "dylib") => (name, Some(cstore::NativeUnknown)), |
| 2330 | (Some(name), "framework") => (name, Some(cstore::NativeFramework)), |
| 2331 | (Some(name), "static") => (name, Some(cstore::NativeStatic)), |
| 2332 | (Some(name), "static-nobundle") => (name, Some(cstore::NativeStaticNobundle)), |
| 2333 | (_, s) => { |
| 2334 | early_error( |
| 2335 | error_format, |
| 2336 | &format!( |
| 2337 | "unknown library kind `{}`, expected \ |
| 2338 | one of dylib, framework, or static", |
| 2339 | s |
| 2340 | ), |
| 2341 | ); |
| 2342 | } |
| 2343 | }; |
| 2344 | if kind == Some(cstore::NativeStaticNobundle) && !nightly_options::is_nightly_build() { |
| 2345 | early_error( |
| 2346 | error_format, |
| 2347 | &format!( |
| 2348 | "the library kind 'static-nobundle' is only \ |
| 2349 | accepted on the nightly compiler" |
| 2350 | ), |
| 2351 | ); |
Alex Crichton | 8e6e846 | 2014-10-21 06:04:16 | [diff] [blame] | 2352 | } |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2353 | let mut name_parts = name.splitn(2, ':'); |
| 2354 | let name = name_parts.next().unwrap(); |
| 2355 | let new_name = name_parts.next(); |
ljedrz | e5eb538 | 2018-10-10 13:34:07 | [diff] [blame] | 2356 | (name.to_owned(), new_name.map(|n| n.to_owned()), kind) |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2357 | }) |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2358 | .collect() |
| 2359 | } |
Alex Crichton | 8e6e846 | 2014-10-21 06:04:16 | [diff] [blame] | 2360 | |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2361 | fn parse_borrowck_mode(dopts: &DebuggingOptions, error_format: ErrorOutputType) -> BorrowckMode { |
| 2362 | match dopts.borrowck.as_ref().map(|s| &s[..]) { |
Matthew Jasper | aa6fb6c | 2019-01-26 17:25:37 | [diff] [blame] | 2363 | None | Some("migrate") => BorrowckMode::Migrate, |
est31 | c9af68e | 2017-11-19 22:35:53 | [diff] [blame] | 2364 | Some("mir") => BorrowckMode::Mir, |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2365 | Some(m) => early_error(error_format, &format!("unknown borrowck mode `{}`", m)), |
Keegan McAllister | ad9a1da | 2014-09-12 15:17:58 | [diff] [blame] | 2366 | } |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2367 | } |
Keegan McAllister | ad9a1da | 2014-09-12 15:17:58 | [diff] [blame] | 2368 | |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2369 | fn parse_externs( |
| 2370 | matches: &getopts::Matches, |
| 2371 | debugging_opts: &DebuggingOptions, |
| 2372 | error_format: ErrorOutputType, |
| 2373 | is_unstable_enabled: bool, |
| 2374 | ) -> Externs { |
Aaron Hill | 48ec29d | 2019-01-30 20:33:50 | [diff] [blame] | 2375 | if matches.opt_present("extern-private") && !debugging_opts.unstable_options { |
| 2376 | early_error( |
| 2377 | ErrorOutputType::default(), |
| 2378 | "'--extern-private' is unstable and only \ |
| 2379 | available for nightly builds of rustc." |
| 2380 | ) |
| 2381 | } |
| 2382 | |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 2383 | // We start out with a `Vec<(Option<String>, bool)>>`, |
| 2384 | // and later convert it into a `BTreeSet<(Option<String>, bool)>` |
Aaron Hill | 7cc3ce3 | 2019-03-25 03:06:32 | [diff] [blame] | 2385 | // This allows to modify entries in-place to set their correct |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 2386 | // 'public' value. |
Aaron Hill | 482b77a | 2019-04-07 22:48:40 | [diff] [blame] | 2387 | let mut externs: BTreeMap<String, ExternEntry> = BTreeMap::new(); |
| 2388 | for (arg, private) in matches.opt_strs("extern").into_iter().map(|v| (v, false)) |
| 2389 | .chain(matches.opt_strs("extern-private").into_iter().map(|v| (v, true))) { |
Aaron Hill | 7cc3ce3 | 2019-03-25 03:06:32 | [diff] [blame] | 2390 | |
Alex Crichton | e98dce3 | 2015-04-01 18:28:34 | [diff] [blame] | 2391 | let mut parts = arg.splitn(2, '='); |
ljedrz | 0b2e9f7 | 2018-10-10 13:33:10 | [diff] [blame] | 2392 | let name = parts.next().unwrap_or_else(|| |
| 2393 | early_error(error_format, "--extern value must not be empty")); |
Eduard-Mihai Burtescu | 26b1ed1 | 2018-08-24 15:51:10 | [diff] [blame] | 2394 | let location = parts.next().map(|s| s.to_string()); |
Alexis Beingessner | fe8a413 | 2014-09-18 21:05:52 | [diff] [blame] | 2395 | |
Aaron Hill | 4dfce34 | 2019-04-09 21:24:24 | [diff] [blame] | 2396 | let entry = externs |
ljedrz | e5eb538 | 2018-10-10 13:34:07 | [diff] [blame] | 2397 | .entry(name.to_owned()) |
Aaron Hill | 4dfce34 | 2019-04-09 21:24:24 | [diff] [blame] | 2398 | .or_default(); |
Alex Crichton | cc3c8bb | 2014-07-01 15:37:54 | [diff] [blame] | 2399 | |
Aaron Hill | 482b77a | 2019-04-07 22:48:40 | [diff] [blame] | 2400 | |
Aaron Hill | 4dfce34 | 2019-04-09 21:24:24 | [diff] [blame] | 2401 | entry.locations.insert(location.clone()); |
| 2402 | |
| 2403 | // Crates start out being not private, |
| 2404 | // and go to being private if we see an '--extern-private' |
| 2405 | // flag |
| 2406 | entry.is_private_dep |= private; |
Aaron Hill | 482b77a | 2019-04-07 22:48:40 | [diff] [blame] | 2407 | } |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2408 | Externs(externs) |
| 2409 | } |
Aaron Hill | 7cc3ce3 | 2019-03-25 03:06:32 | [diff] [blame] | 2410 | |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2411 | fn parse_remap_path_prefix( |
| 2412 | matches: &getopts::Matches, |
| 2413 | error_format: ErrorOutputType |
| 2414 | ) -> Vec<(PathBuf, PathBuf)> { |
| 2415 | matches |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2416 | .opt_strs("remap-path-prefix") |
Jeremy Fitzhardinge | 56a6828 | 2018-02-18 23:05:24 | [diff] [blame] | 2417 | .into_iter() |
| 2418 | .map(|remap| { |
| 2419 | let mut parts = remap.rsplitn(2, '='); // reverse iterator |
| 2420 | let to = parts.next(); |
| 2421 | let from = parts.next(); |
| 2422 | match (from, to) { |
| 2423 | (Some(from), Some(to)) => (PathBuf::from(from), PathBuf::from(to)), |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2424 | _ => early_error( |
| 2425 | error_format, |
| 2426 | "--remap-path-prefix must contain '=' between FROM and TO", |
| 2427 | ), |
Jeremy Fitzhardinge | 56a6828 | 2018-02-18 23:05:24 | [diff] [blame] | 2428 | } |
| 2429 | }) |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2430 | .collect() |
| 2431 | } |
Jeremy Fitzhardinge | 56a6828 | 2018-02-18 23:05:24 | [diff] [blame] | 2432 | |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2433 | pub fn build_session_options(matches: &getopts::Matches) -> Options { |
| 2434 | let color = parse_color(matches); |
| 2435 | |
| 2436 | let edition = parse_crate_edition(matches); |
| 2437 | |
| 2438 | let (json_rendered, json_artifact_notifications) = parse_json(matches); |
| 2439 | |
| 2440 | let error_format = parse_error_format(matches, color, json_rendered); |
| 2441 | |
| 2442 | let unparsed_crate_types = matches.opt_strs("crate-type"); |
| 2443 | let crate_types = parse_crate_types_from_list(unparsed_crate_types) |
| 2444 | .unwrap_or_else(|e| early_error(error_format, &e[..])); |
| 2445 | |
| 2446 | let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format); |
| 2447 | |
| 2448 | let mut debugging_opts = build_debugging_options(matches, error_format); |
| 2449 | check_debug_option_stability(&debugging_opts, error_format, json_rendered); |
| 2450 | |
| 2451 | let output_types = parse_output_types(&debugging_opts, matches, error_format); |
| 2452 | |
| 2453 | let mut cg = build_codegen_options(matches, error_format); |
| 2454 | let (disable_thinlto, codegen_units) = should_override_cgus_and_disable_thinlto( |
| 2455 | &output_types, |
| 2456 | matches, |
| 2457 | error_format, |
| 2458 | cg.codegen_units, |
| 2459 | ); |
| 2460 | |
| 2461 | check_thread_count(&debugging_opts, error_format); |
| 2462 | |
| 2463 | let incremental = select_incremental_path(&debugging_opts, &cg, error_format); |
| 2464 | |
| 2465 | if debugging_opts.profile && incremental.is_some() { |
| 2466 | early_error( |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2467 | error_format, |
Mazdak Farrokhzad | 9d766ed | 2019-10-11 21:30:58 | [diff] [blame] | 2468 | "can't instrument with gcov profiling when compiling incrementally", |
| 2469 | ); |
| 2470 | } |
| 2471 | |
| 2472 | if cg.profile_generate.enabled() && cg.profile_use.is_some() { |
| 2473 | early_error( |
| 2474 | error_format, |
| 2475 | "options `-C profile-generate` and `-C profile-use` are exclusive", |
| 2476 | ); |
| 2477 | } |
| 2478 | |
| 2479 | let is_unstable_enabled = nightly_options::is_unstable_enabled(matches); |
| 2480 | let prints = collect_print_requests( |
| 2481 | &mut cg, |
| 2482 | &mut debugging_opts, |
| 2483 | matches, |
| 2484 | is_unstable_enabled, |
| 2485 | error_format, |
| 2486 | ); |
| 2487 | |
| 2488 | let cg = cg; |
| 2489 | |
| 2490 | let sysroot_opt = matches.opt_str("sysroot").map(|m| PathBuf::from(&m)); |
| 2491 | let target_triple = parse_target_triple(matches, error_format); |
| 2492 | let opt_level = parse_opt_level(matches, &cg, error_format); |
| 2493 | // The `-g` and `-C debuginfo` flags specify the same setting, so we want to be able |
| 2494 | // to use them interchangeably. See the note above (regarding `-O` and `-C opt-level`) |
| 2495 | // for more details. |
| 2496 | let debug_assertions = cg.debug_assertions.unwrap_or(opt_level == OptLevel::No); |
| 2497 | let debuginfo = select_debuginfo(matches, &cg, error_format); |
| 2498 | |
| 2499 | let mut search_paths = vec![]; |
| 2500 | for s in &matches.opt_strs("L") { |
| 2501 | search_paths.push(SearchPath::from_cli_opt(&s[..], error_format)); |
| 2502 | } |
| 2503 | |
| 2504 | let libs = parse_libs(matches, error_format); |
| 2505 | |
| 2506 | let test = matches.opt_present("test"); |
| 2507 | |
| 2508 | let borrowck_mode = parse_borrowck_mode(&debugging_opts, error_format); |
| 2509 | |
| 2510 | if !cg.remark.is_empty() && debuginfo == DebugInfo::None { |
| 2511 | early_warn( |
| 2512 | error_format, |
| 2513 | "-C remark requires \"-C debuginfo=n\" to show source locations", |
| 2514 | ); |
| 2515 | } |
| 2516 | |
| 2517 | let externs = parse_externs(matches, &debugging_opts, error_format, is_unstable_enabled); |
| 2518 | |
| 2519 | let crate_name = matches.opt_str("crate-name"); |
| 2520 | |
| 2521 | let remap_path_prefix = parse_remap_path_prefix(matches, error_format); |
| 2522 | |
| 2523 | Options { |
| 2524 | crate_types, |
| 2525 | optimize: opt_level, |
| 2526 | debuginfo, |
| 2527 | lint_opts, |
| 2528 | lint_cap, |
| 2529 | describe_lints, |
| 2530 | output_types, |
| 2531 | search_paths, |
| 2532 | maybe_sysroot: sysroot_opt, |
| 2533 | target_triple, |
| 2534 | test, |
| 2535 | incremental, |
| 2536 | debugging_opts, |
| 2537 | prints, |
| 2538 | borrowck_mode, |
| 2539 | cg, |
| 2540 | error_format, |
| 2541 | externs, |
| 2542 | crate_name, |
| 2543 | alt_std_name: None, |
| 2544 | libs, |
| 2545 | unstable_features: UnstableFeatures::from_environment(), |
| 2546 | debug_assertions, |
| 2547 | actually_rustdoc: false, |
| 2548 | cli_forced_codegen_units: codegen_units, |
| 2549 | cli_forced_thinlto_off: disable_thinlto, |
| 2550 | remap_path_prefix, |
| 2551 | edition, |
| 2552 | json_artifact_notifications, |
| 2553 | } |
Nick Cameron | cacd6b6 | 2015-01-30 08:44:27 | [diff] [blame] | 2554 | } |
| 2555 | |
Aaron Hill | 1498608 | 2019-07-20 20:34:41 | [diff] [blame] | 2556 | pub fn make_crate_type_option() -> RustcOptGroup { |
| 2557 | opt::multi_s( |
| 2558 | "", |
| 2559 | "crate-type", |
| 2560 | "Comma separated list of types of crates |
| 2561 | for the compiler to emit", |
| 2562 | "[bin|lib|rlib|dylib|cdylib|staticlib|proc-macro]", |
| 2563 | ) |
| 2564 | } |
| 2565 | |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2566 | pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateType>, String> { |
Brian Anderson | 1c3655b | 2014-07-20 04:11:26 | [diff] [blame] | 2567 | let mut crate_types: Vec<CrateType> = Vec::new(); |
Jorge Aparicio | d5d7e65 | 2015-01-31 17:20:46 | [diff] [blame] | 2568 | for unparsed_crate_type in &list_list { |
Jorge Aparicio | 00f3c3f | 2014-11-27 18:53:34 | [diff] [blame] | 2569 | for part in unparsed_crate_type.split(',') { |
Brian Anderson | 1c3655b | 2014-07-20 04:11:26 | [diff] [blame] | 2570 | let new_part = match part { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2571 | "lib" => default_lib_output(), |
Mark Rousskov | 2a93442 | 2018-07-26 17:13:11 | [diff] [blame] | 2572 | "rlib" => CrateType::Rlib, |
| 2573 | "staticlib" => CrateType::Staticlib, |
| 2574 | "dylib" => CrateType::Dylib, |
| 2575 | "cdylib" => CrateType::Cdylib, |
| 2576 | "bin" => CrateType::Executable, |
| 2577 | "proc-macro" => CrateType::ProcMacro, |
ljedrz | 942a796 | 2018-10-10 13:24:31 | [diff] [blame] | 2578 | _ => return Err(format!("unknown crate type: `{}`", part)) |
Brian Anderson | 1c3655b | 2014-07-20 04:11:26 | [diff] [blame] | 2579 | }; |
Simonas Kazlauskas | a6e8496 | 2015-02-09 17:30:22 | [diff] [blame] | 2580 | if !crate_types.contains(&new_part) { |
| 2581 | crate_types.push(new_part) |
| 2582 | } |
Brian Anderson | 1c3655b | 2014-07-20 04:11:26 | [diff] [blame] | 2583 | } |
| 2584 | } |
| 2585 | |
Michael Kohl | 9873acc | 2017-05-28 06:49:14 | [diff] [blame] | 2586 | Ok(crate_types) |
Brian Anderson | 1c3655b | 2014-07-20 04:11:26 | [diff] [blame] | 2587 | } |
| 2588 | |
Guillaume Gomez | ded701b | 2016-03-15 08:09:29 | [diff] [blame] | 2589 | pub mod nightly_options { |
| 2590 | use getopts; |
| 2591 | use syntax::feature_gate::UnstableFeatures; |
Tim Neumann | 3f287ef | 2016-09-24 17:20:57 | [diff] [blame] | 2592 | use super::{ErrorOutputType, OptionStability, RustcOptGroup}; |
Mark Mansi | e957ed9 | 2019-02-05 17:20:45 | [diff] [blame] | 2593 | use crate::session::early_error; |
Guillaume Gomez | ded701b | 2016-03-15 08:09:29 | [diff] [blame] | 2594 | |
| 2595 | pub fn is_unstable_enabled(matches: &getopts::Matches) -> bool { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2596 | is_nightly_build() |
| 2597 | && matches |
| 2598 | .opt_strs("Z") |
| 2599 | .iter() |
| 2600 | .any(|x| *x == "unstable-options") |
Guillaume Gomez | ded701b | 2016-03-15 08:09:29 | [diff] [blame] | 2601 | } |
| 2602 | |
Brandon Edens | 49d2825 | 2016-04-29 06:04:45 | [diff] [blame] | 2603 | pub fn is_nightly_build() -> bool { |
Tim Neumann | ba838dc | 2016-09-24 17:19:17 | [diff] [blame] | 2604 | UnstableFeatures::from_environment().is_nightly_build() |
Guillaume Gomez | ded701b | 2016-03-15 08:09:29 | [diff] [blame] | 2605 | } |
| 2606 | |
| 2607 | pub fn check_nightly_options(matches: &getopts::Matches, flags: &[RustcOptGroup]) { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2608 | let has_z_unstable_option = matches |
| 2609 | .opt_strs("Z") |
| 2610 | .iter() |
| 2611 | .any(|x| *x == "unstable-options"); |
| 2612 | let really_allows_unstable_options = |
| 2613 | UnstableFeatures::from_environment().is_nightly_build(); |
Guillaume Gomez | ded701b | 2016-03-15 08:09:29 | [diff] [blame] | 2614 | |
| 2615 | for opt in flags.iter() { |
| 2616 | if opt.stability == OptionStability::Stable { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2617 | continue; |
Guillaume Gomez | ded701b | 2016-03-15 08:09:29 | [diff] [blame] | 2618 | } |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 2619 | if !matches.opt_present(opt.name) { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2620 | continue; |
Guillaume Gomez | ded701b | 2016-03-15 08:09:29 | [diff] [blame] | 2621 | } |
Alex Crichton | 5c3d0e6 | 2017-06-08 21:20:55 | [diff] [blame] | 2622 | if opt.name != "Z" && !has_z_unstable_option { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2623 | early_error( |
| 2624 | ErrorOutputType::default(), |
| 2625 | &format!( |
| 2626 | "the `-Z unstable-options` flag must also be passed to enable \ |
| 2627 | the flag `{}`", |
| 2628 | opt.name |
| 2629 | ), |
| 2630 | ); |
Guillaume Gomez | ded701b | 2016-03-15 08:09:29 | [diff] [blame] | 2631 | } |
| 2632 | if really_allows_unstable_options { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2633 | continue; |
Guillaume Gomez | ded701b | 2016-03-15 08:09:29 | [diff] [blame] | 2634 | } |
| 2635 | match opt.stability { |
| 2636 | OptionStability::Unstable => { |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2637 | let msg = format!( |
| 2638 | "the option `{}` is only accepted on the \ |
| 2639 | nightly compiler", |
| 2640 | opt.name |
| 2641 | ); |
Guillaume Gomez | ded701b | 2016-03-15 08:09:29 | [diff] [blame] | 2642 | early_error(ErrorOutputType::default(), &msg); |
| 2643 | } |
Guillaume Gomez | ded701b | 2016-03-15 08:09:29 | [diff] [blame] | 2644 | OptionStability::Stable => {} |
| 2645 | } |
| 2646 | } |
| 2647 | } |
| 2648 | } |
| 2649 | |
Alex Crichton | 3cb9fa2 | 2015-01-20 23:45:07 | [diff] [blame] | 2650 | impl fmt::Display for CrateType { |
Zack M. Davis | 5b22d9b | 2018-08-30 05:02:42 | [diff] [blame] | 2651 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
Valerii Hiora | 70a79a9 | 2014-06-11 07:48:17 | [diff] [blame] | 2652 | match *self { |
Mark Rousskov | 2a93442 | 2018-07-26 17:13:11 | [diff] [blame] | 2653 | CrateType::Executable => "bin".fmt(f), |
| 2654 | CrateType::Dylib => "dylib".fmt(f), |
| 2655 | CrateType::Rlib => "rlib".fmt(f), |
| 2656 | CrateType::Staticlib => "staticlib".fmt(f), |
| 2657 | CrateType::Cdylib => "cdylib".fmt(f), |
| 2658 | CrateType::ProcMacro => "proc-macro".fmt(f), |
Valerii Hiora | 70a79a9 | 2014-06-11 07:48:17 | [diff] [blame] | 2659 | } |
| 2660 | } |
| 2661 | } |
Nick Cameron | 37ca367 | 2014-05-06 11:38:01 | [diff] [blame] | 2662 | |
Andy Russell | 4e35cbb2 | 2018-11-12 18:05:20 | [diff] [blame] | 2663 | /// Command-line arguments passed to the compiler have to be incorporated with |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2664 | /// the dependency tracking system for incremental compilation. This module |
| 2665 | /// provides some utilities to make this more convenient. |
| 2666 | /// |
Andy Russell | 4e35cbb2 | 2018-11-12 18:05:20 | [diff] [blame] | 2667 | /// The values of all command-line arguments that are relevant for dependency |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2668 | /// tracking are hashed into a single value that determines whether the |
| 2669 | /// incremental compilation cache can be re-used or not. This hashing is done |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 2670 | /// via the `DepTrackingHash` trait defined below, since the standard `Hash` |
| 2671 | /// implementation might not be suitable (e.g., arguments are stored in a `Vec`, |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2672 | /// the hash of which is order dependent, but we might not want the order of |
| 2673 | /// arguments to make a difference for the hash). |
| 2674 | /// |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 2675 | /// However, since the value provided by `Hash::hash` often *is* suitable, |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2676 | /// especially for primitive types, there is the |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 2677 | /// `impl_dep_tracking_hash_via_hash!()` macro that allows to simply reuse the |
| 2678 | /// `Hash` implementation for `DepTrackingHash`. It's important though that |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2679 | /// we have an opt-in scheme here, so one is hopefully forced to think about |
Andy Russell | 4e35cbb2 | 2018-11-12 18:05:20 | [diff] [blame] | 2680 | /// how the hash should be calculated when adding a new command-line argument. |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2681 | mod dep_tracking { |
Mark Mansi | e957ed9 | 2019-02-05 17:20:45 | [diff] [blame] | 2682 | use crate::lint; |
| 2683 | use crate::middle::cstore; |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2684 | use std::collections::BTreeMap; |
Alex Crichton | 10c3134 | 2016-09-29 00:23:36 | [diff] [blame] | 2685 | use std::hash::Hash; |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2686 | use std::path::PathBuf; |
Alex Crichton | 10c3134 | 2016-09-29 00:23:36 | [diff] [blame] | 2687 | use std::collections::hash_map::DefaultHasher; |
Michael Woerister | 24093a6 | 2018-09-04 15:57:17 | [diff] [blame] | 2688 | use super::{CrateType, DebugInfo, ErrorOutputType, OptLevel, OutputTypes, |
Eduard-Mihai Burtescu | 2092963 | 2019-01-29 05:24:32 | [diff] [blame] | 2689 | Passes, Sanitizer, LtoCli, LinkerPluginLto, SwitchWithOptPath, |
| 2690 | SymbolManglingVersion}; |
Peter Jin | b91d211 | 2018-12-31 18:58:13 | [diff] [blame] | 2691 | use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel, TargetTriple}; |
Kurtis Nusbaum | 320fdaa | 2018-04-20 04:03:21 | [diff] [blame] | 2692 | use syntax::edition::Edition; |
Alexander Regueiro | c1d29ee | 2019-09-06 02:57:44 | [diff] [blame] | 2693 | use syntax::feature_gate::UnstableFeatures; |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2694 | |
| 2695 | pub trait DepTrackingHash { |
est31 | d290849 | 2017-05-02 03:55:20 | [diff] [blame] | 2696 | fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType); |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2697 | } |
| 2698 | |
| 2699 | macro_rules! impl_dep_tracking_hash_via_hash { |
| 2700 | ($t:ty) => ( |
| 2701 | impl DepTrackingHash for $t { |
Alex Crichton | 10c3134 | 2016-09-29 00:23:36 | [diff] [blame] | 2702 | fn hash(&self, hasher: &mut DefaultHasher, _: ErrorOutputType) { |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2703 | Hash::hash(self, hasher); |
| 2704 | } |
| 2705 | } |
| 2706 | ) |
| 2707 | } |
| 2708 | |
| 2709 | macro_rules! impl_dep_tracking_hash_for_sortable_vec_of { |
| 2710 | ($t:ty) => ( |
| 2711 | impl DepTrackingHash for Vec<$t> { |
Alex Crichton | 10c3134 | 2016-09-29 00:23:36 | [diff] [blame] | 2712 | fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) { |
Michael Woerister | a7de0bc | 2016-08-09 19:28:24 | [diff] [blame] | 2713 | let mut elems: Vec<&$t> = self.iter().collect(); |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2714 | elems.sort(); |
Michael Woerister | a7de0bc | 2016-08-09 19:28:24 | [diff] [blame] | 2715 | Hash::hash(&elems.len(), hasher); |
| 2716 | for (index, elem) in elems.iter().enumerate() { |
| 2717 | Hash::hash(&index, hasher); |
| 2718 | DepTrackingHash::hash(*elem, hasher, error_format); |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2719 | } |
| 2720 | } |
| 2721 | } |
| 2722 | ); |
| 2723 | } |
| 2724 | |
| 2725 | impl_dep_tracking_hash_via_hash!(bool); |
| 2726 | impl_dep_tracking_hash_via_hash!(usize); |
Austin Hicks | 63ebf08 | 2017-03-08 21:28:47 | [diff] [blame] | 2727 | impl_dep_tracking_hash_via_hash!(u64); |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2728 | impl_dep_tracking_hash_via_hash!(String); |
Oliver Schneider | d732da8 | 2017-12-14 07:09:19 | [diff] [blame] | 2729 | impl_dep_tracking_hash_via_hash!(PathBuf); |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2730 | impl_dep_tracking_hash_via_hash!(lint::Level); |
| 2731 | impl_dep_tracking_hash_via_hash!(Option<bool>); |
| 2732 | impl_dep_tracking_hash_via_hash!(Option<usize>); |
| 2733 | impl_dep_tracking_hash_via_hash!(Option<String>); |
Austin Hicks | 63ebf08 | 2017-03-08 21:28:47 | [diff] [blame] | 2734 | impl_dep_tracking_hash_via_hash!(Option<(String, u64)>); |
Aaron Hill | fe15f71 | 2019-01-29 21:10:49 | [diff] [blame] | 2735 | impl_dep_tracking_hash_via_hash!(Option<Vec<String>>); |
Peter Jin | b91d211 | 2018-12-31 18:58:13 | [diff] [blame] | 2736 | impl_dep_tracking_hash_via_hash!(Option<MergeFunctions>); |
Jorge Aparicio | cbb967f | 2016-09-28 02:26:08 | [diff] [blame] | 2737 | impl_dep_tracking_hash_via_hash!(Option<PanicStrategy>); |
Johannes Löthberg | 94b9cc9 | 2017-07-14 20:01:37 | [diff] [blame] | 2738 | impl_dep_tracking_hash_via_hash!(Option<RelroLevel>); |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2739 | impl_dep_tracking_hash_via_hash!(Option<lint::Level>); |
| 2740 | impl_dep_tracking_hash_via_hash!(Option<PathBuf>); |
Peter Wagenet | ae32b6e | 2017-02-21 21:18:58 | [diff] [blame] | 2741 | impl_dep_tracking_hash_via_hash!(Option<cstore::NativeLibraryKind>); |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2742 | impl_dep_tracking_hash_via_hash!(CrateType); |
Peter Jin | b91d211 | 2018-12-31 18:58:13 | [diff] [blame] | 2743 | impl_dep_tracking_hash_via_hash!(MergeFunctions); |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2744 | impl_dep_tracking_hash_via_hash!(PanicStrategy); |
Johannes Löthberg | 94b9cc9 | 2017-07-14 20:01:37 | [diff] [blame] | 2745 | impl_dep_tracking_hash_via_hash!(RelroLevel); |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2746 | impl_dep_tracking_hash_via_hash!(Passes); |
| 2747 | impl_dep_tracking_hash_via_hash!(OptLevel); |
Michael Woerister | 24093a6 | 2018-09-04 15:57:17 | [diff] [blame] | 2748 | impl_dep_tracking_hash_via_hash!(LtoCli); |
Mark Rousskov | 2bc7197 | 2018-07-26 17:41:10 | [diff] [blame] | 2749 | impl_dep_tracking_hash_via_hash!(DebugInfo); |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2750 | impl_dep_tracking_hash_via_hash!(UnstableFeatures); |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2751 | impl_dep_tracking_hash_via_hash!(OutputTypes); |
| 2752 | impl_dep_tracking_hash_via_hash!(cstore::NativeLibraryKind); |
Jorge Aparicio | 0b06db5 | 2017-02-21 03:34:42 | [diff] [blame] | 2753 | impl_dep_tracking_hash_via_hash!(Sanitizer); |
| 2754 | impl_dep_tracking_hash_via_hash!(Option<Sanitizer>); |
Philipp Oppermann | 3908b2e | 2018-03-14 14:27:06 | [diff] [blame] | 2755 | impl_dep_tracking_hash_via_hash!(TargetTriple); |
Kurtis Nusbaum | 320fdaa | 2018-04-20 04:03:21 | [diff] [blame] | 2756 | impl_dep_tracking_hash_via_hash!(Edition); |
Michael Woerister | 04f425d | 2019-02-01 14:15:43 | [diff] [blame] | 2757 | impl_dep_tracking_hash_via_hash!(LinkerPluginLto); |
Michael Woerister | 64ee32e | 2019-05-28 14:13:59 | [diff] [blame] | 2758 | impl_dep_tracking_hash_via_hash!(SwitchWithOptPath); |
Eduard-Mihai Burtescu | 2092963 | 2019-01-29 05:24:32 | [diff] [blame] | 2759 | impl_dep_tracking_hash_via_hash!(SymbolManglingVersion); |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2760 | |
| 2761 | impl_dep_tracking_hash_for_sortable_vec_of!(String); |
Oliver Schneider | d732da8 | 2017-12-14 07:09:19 | [diff] [blame] | 2762 | impl_dep_tracking_hash_for_sortable_vec_of!(PathBuf); |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2763 | impl_dep_tracking_hash_for_sortable_vec_of!(CrateType); |
| 2764 | impl_dep_tracking_hash_for_sortable_vec_of!((String, lint::Level)); |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2765 | impl_dep_tracking_hash_for_sortable_vec_of!(( |
| 2766 | String, |
| 2767 | Option<String>, |
| 2768 | Option<cstore::NativeLibraryKind> |
| 2769 | )); |
Austin Hicks | 63ebf08 | 2017-03-08 21:28:47 | [diff] [blame] | 2770 | impl_dep_tracking_hash_for_sortable_vec_of!((String, u64)); |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2771 | |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2772 | impl<T1, T2> DepTrackingHash for (T1, T2) |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2773 | where |
| 2774 | T1: DepTrackingHash, |
| 2775 | T2: DepTrackingHash, |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2776 | { |
Alex Crichton | 10c3134 | 2016-09-29 00:23:36 | [diff] [blame] | 2777 | fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) { |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2778 | Hash::hash(&0, hasher); |
| 2779 | DepTrackingHash::hash(&self.0, hasher, error_format); |
| 2780 | Hash::hash(&1, hasher); |
| 2781 | DepTrackingHash::hash(&self.1, hasher, error_format); |
| 2782 | } |
| 2783 | } |
| 2784 | |
Vadim Chugunov | 13477c7 | 2016-11-24 00:09:51 | [diff] [blame] | 2785 | impl<T1, T2, T3> DepTrackingHash for (T1, T2, T3) |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2786 | where |
| 2787 | T1: DepTrackingHash, |
| 2788 | T2: DepTrackingHash, |
| 2789 | T3: DepTrackingHash, |
Vadim Chugunov | 13477c7 | 2016-11-24 00:09:51 | [diff] [blame] | 2790 | { |
| 2791 | fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) { |
| 2792 | Hash::hash(&0, hasher); |
| 2793 | DepTrackingHash::hash(&self.0, hasher, error_format); |
| 2794 | Hash::hash(&1, hasher); |
| 2795 | DepTrackingHash::hash(&self.1, hasher, error_format); |
| 2796 | Hash::hash(&2, hasher); |
| 2797 | DepTrackingHash::hash(&self.2, hasher, error_format); |
| 2798 | } |
| 2799 | } |
| 2800 | |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2801 | // This is a stable hash because BTreeMap is a sorted container |
Santiago Pastorino | 52a47d4 | 2018-03-06 05:29:03 | [diff] [blame] | 2802 | pub fn stable_hash( |
| 2803 | sub_hashes: BTreeMap<&'static str, &dyn DepTrackingHash>, |
| 2804 | hasher: &mut DefaultHasher, |
| 2805 | error_format: ErrorOutputType, |
| 2806 | ) { |
Michael Woerister | 3241431 | 2016-08-02 20:53:58 | [diff] [blame] | 2807 | for (key, sub_hash) in sub_hashes { |
| 2808 | // Using Hash::hash() instead of DepTrackingHash::hash() is fine for |
| 2809 | // the keys, as they are just plain strings |
| 2810 | Hash::hash(&key.len(), hasher); |
| 2811 | Hash::hash(key, hasher); |
| 2812 | sub_hash.hash(hasher, error_format); |
| 2813 | } |
| 2814 | } |
| 2815 | } |