]>
Commit | Line | Data |
---|---|---|
7453a54e SL |
1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
a7813a04 XL |
11 | //! Serialized configuration of a build. |
12 | //! | |
ea8adc8c XL |
13 | //! This module implements parsing `config.toml` configuration files to tweak |
14 | //! how the build runs. | |
a7813a04 | 15 | |
2c00a5a8 | 16 | use std::collections::{HashMap, HashSet}; |
7453a54e | 17 | use std::env; |
83c7162d | 18 | use std::fs::{self, File}; |
7453a54e | 19 | use std::io::prelude::*; |
2c00a5a8 | 20 | use std::path::{Path, PathBuf}; |
7453a54e | 21 | use std::process; |
3b2f2976 | 22 | use std::cmp; |
7453a54e SL |
23 | |
24 | use num_cpus; | |
3b2f2976 | 25 | use toml; |
3b2f2976 XL |
26 | use cache::{INTERNER, Interned}; |
27 | use flags::Flags; | |
28 | pub use flags::Subcommand; | |
7453a54e SL |
29 | |
30 | /// Global configuration for the entire build and/or bootstrap. | |
31 | /// | |
32 | /// This structure is derived from a combination of both `config.toml` and | |
33 | /// `config.mk`. As of the time of this writing it's unlikely that `config.toml` | |
34 | /// is used all that much, so this is primarily filled out by `config.mk` which | |
35 | /// is generated from `./configure`. | |
36 | /// | |
37 | /// Note that this structure is not decoded directly into, but rather it is | |
a7813a04 XL |
38 | /// filled out from the decoded forms of the structs below. For documentation |
39 | /// each field, see the corresponding fields in | |
3b2f2976 | 40 | /// `config.toml.example`. |
7453a54e SL |
41 | #[derive(Default)] |
42 | pub struct Config { | |
476ff2be | 43 | pub ccache: Option<String>, |
a7813a04 | 44 | pub ninja: bool, |
32a655c1 | 45 | pub verbose: usize, |
7453a54e | 46 | pub submodules: bool, |
0531ce1d | 47 | pub fast_submodules: bool, |
7453a54e SL |
48 | pub compiler_docs: bool, |
49 | pub docs: bool, | |
8bb4bdeb | 50 | pub locked_deps: bool, |
476ff2be | 51 | pub vendor: bool, |
3b2f2976 | 52 | pub target_config: HashMap<Interned<String>, Target>, |
32a655c1 SL |
53 | pub full_bootstrap: bool, |
54 | pub extended: bool, | |
2c00a5a8 | 55 | pub tools: Option<HashSet<String>>, |
8bb4bdeb | 56 | pub sanitizers: bool, |
041b39d2 | 57 | pub profiler: bool, |
3b2f2976 | 58 | pub ignore_git: bool, |
2c00a5a8 | 59 | pub exclude: Vec<PathBuf>, |
0531ce1d | 60 | pub rustc_error_format: Option<String>, |
3b2f2976 XL |
61 | |
62 | pub run_host_only: bool, | |
63 | ||
64 | pub on_fail: Option<String>, | |
65 | pub stage: Option<u32>, | |
8faf50e0 | 66 | pub keep_stage: Vec<u32>, |
3b2f2976 XL |
67 | pub src: PathBuf, |
68 | pub jobs: Option<u32>, | |
69 | pub cmd: Subcommand, | |
70 | pub incremental: bool, | |
83c7162d XL |
71 | pub dry_run: bool, |
72 | ||
73 | pub deny_warnings: bool, | |
74 | pub backtrace_on_ice: bool, | |
7453a54e SL |
75 | |
76 | // llvm codegen options | |
3b2f2976 | 77 | pub llvm_enabled: bool, |
7453a54e SL |
78 | pub llvm_assertions: bool, |
79 | pub llvm_optimize: bool, | |
b7449926 | 80 | pub llvm_thin_lto: bool, |
476ff2be | 81 | pub llvm_release_debuginfo: bool, |
7453a54e SL |
82 | pub llvm_version_check: bool, |
83 | pub llvm_static_stdcpp: bool, | |
476ff2be | 84 | pub llvm_link_shared: bool, |
94b46f34 | 85 | pub llvm_clang_cl: Option<String>, |
32a655c1 | 86 | pub llvm_targets: Option<String>, |
ff7c6d11 | 87 | pub llvm_experimental_targets: String, |
8bb4bdeb | 88 | pub llvm_link_jobs: Option<u32>, |
b7449926 | 89 | pub llvm_version_suffix: Option<String>, |
7453a54e | 90 | |
0531ce1d | 91 | pub lld_enabled: bool, |
b7449926 | 92 | pub lldb_enabled: bool, |
8faf50e0 | 93 | pub llvm_tools_enabled: bool, |
0531ce1d | 94 | |
7453a54e SL |
95 | // rust codegen options |
96 | pub rust_optimize: bool, | |
abe05a73 | 97 | pub rust_codegen_units: Option<u32>, |
7453a54e SL |
98 | pub rust_debug_assertions: bool, |
99 | pub rust_debuginfo: bool, | |
c30ab7b3 | 100 | pub rust_debuginfo_lines: bool, |
476ff2be | 101 | pub rust_debuginfo_only_std: bool, |
83c7162d | 102 | pub rust_debuginfo_tools: bool, |
7453a54e | 103 | pub rust_rpath: bool, |
ff7c6d11 | 104 | pub rustc_parallel_queries: bool, |
7453a54e | 105 | pub rustc_default_linker: Option<String>, |
a7813a04 XL |
106 | pub rust_optimize_tests: bool, |
107 | pub rust_debuginfo_tests: bool, | |
8bb4bdeb | 108 | pub rust_dist_src: bool, |
2c00a5a8 | 109 | pub rust_codegen_backends: Vec<Interned<String>>, |
0531ce1d | 110 | pub rust_codegen_backends_dir: String, |
8faf50e0 | 111 | pub rust_verify_llvm_ir: bool, |
b7449926 | 112 | pub rust_remap_debuginfo: bool, |
7453a54e | 113 | |
3b2f2976 XL |
114 | pub build: Interned<String>, |
115 | pub hosts: Vec<Interned<String>>, | |
116 | pub targets: Vec<Interned<String>>, | |
3157f602 | 117 | pub local_rebuild: bool, |
7453a54e | 118 | |
32a655c1 SL |
119 | // dist misc |
120 | pub dist_sign_folder: Option<PathBuf>, | |
121 | pub dist_upload_addr: Option<String>, | |
122 | pub dist_gpg_password_file: Option<PathBuf>, | |
123 | ||
7453a54e SL |
124 | // libstd features |
125 | pub debug_jemalloc: bool, | |
126 | pub use_jemalloc: bool, | |
5bcae85e | 127 | pub backtrace: bool, // support for RUST_BACKTRACE |
2c00a5a8 | 128 | pub wasm_syscall: bool, |
7453a54e SL |
129 | |
130 | // misc | |
7cac9316 | 131 | pub low_priority: bool, |
7453a54e | 132 | pub channel: String, |
94b46f34 | 133 | pub verbose_tests: bool, |
ea8adc8c | 134 | pub test_miri: bool, |
ff7c6d11 | 135 | pub save_toolstates: Option<PathBuf>, |
0531ce1d | 136 | pub print_step_timings: bool, |
ff7c6d11 | 137 | |
9e0c209e | 138 | // Fallback musl-root for all targets |
7453a54e | 139 | pub musl_root: Option<PathBuf>, |
32a655c1 | 140 | pub prefix: Option<PathBuf>, |
7cac9316 | 141 | pub sysconfdir: Option<PathBuf>, |
2c00a5a8 | 142 | pub datadir: Option<PathBuf>, |
32a655c1 | 143 | pub docdir: Option<PathBuf>, |
7cac9316 | 144 | pub bindir: Option<PathBuf>, |
32a655c1 | 145 | pub libdir: Option<PathBuf>, |
32a655c1 | 146 | pub mandir: Option<PathBuf>, |
9e0c209e SL |
147 | pub codegen_tests: bool, |
148 | pub nodejs: Option<PathBuf>, | |
c30ab7b3 | 149 | pub gdb: Option<PathBuf>, |
476ff2be | 150 | pub python: Option<PathBuf>, |
8bb4bdeb | 151 | pub openssl_static: bool, |
ea8adc8c | 152 | pub configure_args: Vec<String>, |
041b39d2 XL |
153 | |
154 | // These are either the stage0 downloaded binaries or the locally installed ones. | |
155 | pub initial_cargo: PathBuf, | |
156 | pub initial_rustc: PathBuf, | |
83c7162d | 157 | pub out: PathBuf, |
7453a54e SL |
158 | } |
159 | ||
160 | /// Per-target configuration stored in the global configuration structure. | |
161 | #[derive(Default)] | |
162 | pub struct Target { | |
041b39d2 | 163 | /// Some(path to llvm-config) if using an external LLVM. |
7453a54e SL |
164 | pub llvm_config: Option<PathBuf>, |
165 | pub jemalloc: Option<PathBuf>, | |
166 | pub cc: Option<PathBuf>, | |
167 | pub cxx: Option<PathBuf>, | |
abe05a73 | 168 | pub ar: Option<PathBuf>, |
b7449926 | 169 | pub ranlib: Option<PathBuf>, |
abe05a73 | 170 | pub linker: Option<PathBuf>, |
7453a54e | 171 | pub ndk: Option<PathBuf>, |
3b2f2976 | 172 | pub crt_static: Option<bool>, |
9e0c209e | 173 | pub musl_root: Option<PathBuf>, |
8bb4bdeb | 174 | pub qemu_rootfs: Option<PathBuf>, |
83c7162d | 175 | pub no_std: bool, |
7453a54e SL |
176 | } |
177 | ||
178 | /// Structure of the `config.toml` file that configuration is read from. | |
179 | /// | |
180 | /// This structure uses `Decodable` to automatically decode a TOML configuration | |
181 | /// file into this format, and then this is traversed and written into the above | |
182 | /// `Config` structure. | |
3b2f2976 XL |
183 | #[derive(Deserialize, Default)] |
184 | #[serde(deny_unknown_fields, rename_all = "kebab-case")] | |
7453a54e SL |
185 | struct TomlConfig { |
186 | build: Option<Build>, | |
32a655c1 | 187 | install: Option<Install>, |
7453a54e SL |
188 | llvm: Option<Llvm>, |
189 | rust: Option<Rust>, | |
190 | target: Option<HashMap<String, TomlTarget>>, | |
32a655c1 | 191 | dist: Option<Dist>, |
7453a54e SL |
192 | } |
193 | ||
194 | /// TOML representation of various global build decisions. | |
3b2f2976 XL |
195 | #[derive(Deserialize, Default, Clone)] |
196 | #[serde(deny_unknown_fields, rename_all = "kebab-case")] | |
7453a54e SL |
197 | struct Build { |
198 | build: Option<String>, | |
3b2f2976 | 199 | #[serde(default)] |
7453a54e | 200 | host: Vec<String>, |
3b2f2976 | 201 | #[serde(default)] |
7453a54e SL |
202 | target: Vec<String>, |
203 | cargo: Option<String>, | |
204 | rustc: Option<String>, | |
7cac9316 | 205 | low_priority: Option<bool>, |
7453a54e SL |
206 | compiler_docs: Option<bool>, |
207 | docs: Option<bool>, | |
c30ab7b3 | 208 | submodules: Option<bool>, |
0531ce1d | 209 | fast_submodules: Option<bool>, |
c30ab7b3 | 210 | gdb: Option<String>, |
8bb4bdeb | 211 | locked_deps: Option<bool>, |
476ff2be SL |
212 | vendor: Option<bool>, |
213 | nodejs: Option<String>, | |
214 | python: Option<String>, | |
32a655c1 SL |
215 | full_bootstrap: Option<bool>, |
216 | extended: Option<bool>, | |
2c00a5a8 | 217 | tools: Option<HashSet<String>>, |
8bb4bdeb XL |
218 | verbose: Option<usize>, |
219 | sanitizers: Option<bool>, | |
041b39d2 | 220 | profiler: Option<bool>, |
8bb4bdeb | 221 | openssl_static: Option<bool>, |
ea8adc8c XL |
222 | configure_args: Option<Vec<String>>, |
223 | local_rebuild: Option<bool>, | |
0531ce1d | 224 | print_step_timings: Option<bool>, |
32a655c1 SL |
225 | } |
226 | ||
227 | /// TOML representation of various global install decisions. | |
3b2f2976 XL |
228 | #[derive(Deserialize, Default, Clone)] |
229 | #[serde(deny_unknown_fields, rename_all = "kebab-case")] | |
32a655c1 SL |
230 | struct Install { |
231 | prefix: Option<String>, | |
7cac9316 | 232 | sysconfdir: Option<String>, |
2c00a5a8 | 233 | datadir: Option<String>, |
32a655c1 | 234 | docdir: Option<String>, |
7cac9316 | 235 | bindir: Option<String>, |
32a655c1 | 236 | libdir: Option<String>, |
7cac9316 | 237 | mandir: Option<String>, |
abe05a73 XL |
238 | |
239 | // standard paths, currently unused | |
abe05a73 XL |
240 | infodir: Option<String>, |
241 | localstatedir: Option<String>, | |
7453a54e SL |
242 | } |
243 | ||
244 | /// TOML representation of how the LLVM build is configured. | |
3b2f2976 XL |
245 | #[derive(Deserialize, Default)] |
246 | #[serde(deny_unknown_fields, rename_all = "kebab-case")] | |
7453a54e | 247 | struct Llvm { |
3b2f2976 | 248 | enabled: Option<bool>, |
476ff2be | 249 | ccache: Option<StringOrBool>, |
a7813a04 | 250 | ninja: Option<bool>, |
7453a54e SL |
251 | assertions: Option<bool>, |
252 | optimize: Option<bool>, | |
b7449926 | 253 | thin_lto: Option<bool>, |
476ff2be | 254 | release_debuginfo: Option<bool>, |
7453a54e SL |
255 | version_check: Option<bool>, |
256 | static_libstdcpp: Option<bool>, | |
32a655c1 | 257 | targets: Option<String>, |
041b39d2 | 258 | experimental_targets: Option<String>, |
8bb4bdeb | 259 | link_jobs: Option<u32>, |
ea8adc8c | 260 | link_shared: Option<bool>, |
b7449926 | 261 | version_suffix: Option<String>, |
94b46f34 | 262 | clang_cl: Option<String> |
32a655c1 SL |
263 | } |
264 | ||
3b2f2976 XL |
265 | #[derive(Deserialize, Default, Clone)] |
266 | #[serde(deny_unknown_fields, rename_all = "kebab-case")] | |
32a655c1 SL |
267 | struct Dist { |
268 | sign_folder: Option<String>, | |
269 | gpg_password_file: Option<String>, | |
270 | upload_addr: Option<String>, | |
8bb4bdeb | 271 | src_tarball: Option<bool>, |
7453a54e SL |
272 | } |
273 | ||
3b2f2976 XL |
274 | #[derive(Deserialize)] |
275 | #[serde(untagged)] | |
476ff2be SL |
276 | enum StringOrBool { |
277 | String(String), | |
278 | Bool(bool), | |
279 | } | |
280 | ||
281 | impl Default for StringOrBool { | |
282 | fn default() -> StringOrBool { | |
283 | StringOrBool::Bool(false) | |
284 | } | |
285 | } | |
286 | ||
7453a54e | 287 | /// TOML representation of how the Rust build is configured. |
3b2f2976 XL |
288 | #[derive(Deserialize, Default)] |
289 | #[serde(deny_unknown_fields, rename_all = "kebab-case")] | |
7453a54e SL |
290 | struct Rust { |
291 | optimize: Option<bool>, | |
292 | codegen_units: Option<u32>, | |
293 | debug_assertions: Option<bool>, | |
294 | debuginfo: Option<bool>, | |
c30ab7b3 | 295 | debuginfo_lines: Option<bool>, |
476ff2be | 296 | debuginfo_only_std: Option<bool>, |
83c7162d | 297 | debuginfo_tools: Option<bool>, |
ff7c6d11 | 298 | experimental_parallel_queries: Option<bool>, |
7453a54e SL |
299 | debug_jemalloc: Option<bool>, |
300 | use_jemalloc: Option<bool>, | |
5bcae85e | 301 | backtrace: Option<bool>, |
7453a54e | 302 | default_linker: Option<String>, |
7453a54e SL |
303 | channel: Option<String>, |
304 | musl_root: Option<String>, | |
305 | rpath: Option<bool>, | |
a7813a04 XL |
306 | optimize_tests: Option<bool>, |
307 | debuginfo_tests: Option<bool>, | |
9e0c209e | 308 | codegen_tests: Option<bool>, |
3b2f2976 | 309 | ignore_git: Option<bool>, |
ea8adc8c XL |
310 | debug: Option<bool>, |
311 | dist_src: Option<bool>, | |
94b46f34 | 312 | verbose_tests: Option<bool>, |
ea8adc8c | 313 | test_miri: Option<bool>, |
94b46f34 | 314 | incremental: Option<bool>, |
ff7c6d11 | 315 | save_toolstates: Option<String>, |
2c00a5a8 | 316 | codegen_backends: Option<Vec<String>>, |
0531ce1d | 317 | codegen_backends_dir: Option<String>, |
2c00a5a8 | 318 | wasm_syscall: Option<bool>, |
0531ce1d | 319 | lld: Option<bool>, |
b7449926 | 320 | lldb: Option<bool>, |
8faf50e0 | 321 | llvm_tools: Option<bool>, |
83c7162d XL |
322 | deny_warnings: Option<bool>, |
323 | backtrace_on_ice: Option<bool>, | |
8faf50e0 | 324 | verify_llvm_ir: Option<bool>, |
b7449926 | 325 | remap_debuginfo: Option<bool>, |
7453a54e SL |
326 | } |
327 | ||
328 | /// TOML representation of how each build target is configured. | |
3b2f2976 XL |
329 | #[derive(Deserialize, Default)] |
330 | #[serde(deny_unknown_fields, rename_all = "kebab-case")] | |
7453a54e SL |
331 | struct TomlTarget { |
332 | llvm_config: Option<String>, | |
333 | jemalloc: Option<String>, | |
334 | cc: Option<String>, | |
335 | cxx: Option<String>, | |
abe05a73 | 336 | ar: Option<String>, |
b7449926 | 337 | ranlib: Option<String>, |
abe05a73 | 338 | linker: Option<String>, |
7453a54e | 339 | android_ndk: Option<String>, |
3b2f2976 | 340 | crt_static: Option<bool>, |
c30ab7b3 | 341 | musl_root: Option<String>, |
8bb4bdeb | 342 | qemu_rootfs: Option<String>, |
7453a54e SL |
343 | } |
344 | ||
345 | impl Config { | |
83c7162d XL |
346 | fn path_from_python(var_key: &str) -> PathBuf { |
347 | match env::var_os(var_key) { | |
348 | // Do not trust paths from Python and normalize them slightly (#49785). | |
349 | Some(var_val) => Path::new(&var_val).components().collect(), | |
350 | _ => panic!("expected '{}' to be set", var_key), | |
351 | } | |
352 | } | |
353 | ||
354 | pub fn default_opts() -> Config { | |
7453a54e | 355 | let mut config = Config::default(); |
3b2f2976 | 356 | config.llvm_enabled = true; |
7453a54e | 357 | config.llvm_optimize = true; |
abe05a73 | 358 | config.llvm_version_check = true; |
7453a54e | 359 | config.use_jemalloc = true; |
5bcae85e | 360 | config.backtrace = true; |
7453a54e | 361 | config.rust_optimize = true; |
a7813a04 | 362 | config.rust_optimize_tests = true; |
7453a54e | 363 | config.submodules = true; |
0531ce1d | 364 | config.fast_submodules = true; |
7453a54e SL |
365 | config.docs = true; |
366 | config.rust_rpath = true; | |
7453a54e | 367 | config.channel = "dev".to_string(); |
9e0c209e | 368 | config.codegen_tests = true; |
3b2f2976 | 369 | config.ignore_git = false; |
8bb4bdeb | 370 | config.rust_dist_src = true; |
ea8adc8c | 371 | config.test_miri = false; |
2c00a5a8 | 372 | config.rust_codegen_backends = vec![INTERNER.intern_str("llvm")]; |
0531ce1d | 373 | config.rust_codegen_backends_dir = "codegen-backends".to_owned(); |
83c7162d XL |
374 | config.deny_warnings = true; |
375 | ||
376 | // set by bootstrap.py | |
377 | config.build = INTERNER.intern_str(&env::var("BUILD").expect("'BUILD' to be set")); | |
378 | config.src = Config::path_from_python("SRC"); | |
379 | config.out = Config::path_from_python("BUILD_DIR"); | |
380 | ||
8faf50e0 XL |
381 | config.initial_rustc = Config::path_from_python("RUSTC"); |
382 | config.initial_cargo = Config::path_from_python("CARGO"); | |
7453a54e | 383 | |
83c7162d XL |
384 | config |
385 | } | |
386 | ||
387 | pub fn parse(args: &[String]) -> Config { | |
388 | let flags = Flags::parse(&args); | |
389 | let file = flags.config.clone(); | |
390 | let mut config = Config::default_opts(); | |
391 | config.exclude = flags.exclude; | |
0531ce1d | 392 | config.rustc_error_format = flags.rustc_error_format; |
3b2f2976 XL |
393 | config.on_fail = flags.on_fail; |
394 | config.stage = flags.stage; | |
3b2f2976 XL |
395 | config.jobs = flags.jobs; |
396 | config.cmd = flags.cmd; | |
397 | config.incremental = flags.incremental; | |
83c7162d | 398 | config.dry_run = flags.dry_run; |
3b2f2976 | 399 | config.keep_stage = flags.keep_stage; |
83c7162d XL |
400 | if let Some(value) = flags.warnings { |
401 | config.deny_warnings = value; | |
402 | } | |
403 | ||
404 | if config.dry_run { | |
405 | let dir = config.out.join("tmp-dry-run"); | |
406 | t!(fs::create_dir_all(&dir)); | |
407 | config.out = dir; | |
408 | } | |
3b2f2976 XL |
409 | |
410 | // If --target was specified but --host wasn't specified, don't run any host-only tests. | |
0531ce1d | 411 | config.run_host_only = !(flags.host.is_empty() && !flags.target.is_empty()); |
3b2f2976 | 412 | |
7453a54e SL |
413 | let toml = file.map(|file| { |
414 | let mut f = t!(File::open(&file)); | |
3b2f2976 XL |
415 | let mut contents = String::new(); |
416 | t!(f.read_to_string(&mut contents)); | |
417 | match toml::from_str(&contents) { | |
418 | Ok(table) => table, | |
419 | Err(err) => { | |
420 | println!("failed to parse TOML configuration '{}': {}", | |
421 | file.display(), err); | |
7453a54e SL |
422 | process::exit(2); |
423 | } | |
424 | } | |
425 | }).unwrap_or_else(|| TomlConfig::default()); | |
426 | ||
427 | let build = toml.build.clone().unwrap_or(Build::default()); | |
83c7162d | 428 | // set by bootstrap.py |
3b2f2976 | 429 | config.hosts.push(config.build.clone()); |
7453a54e | 430 | for host in build.host.iter() { |
3b2f2976 XL |
431 | let host = INTERNER.intern_str(host); |
432 | if !config.hosts.contains(&host) { | |
433 | config.hosts.push(host); | |
7453a54e SL |
434 | } |
435 | } | |
3b2f2976 XL |
436 | for target in config.hosts.iter().cloned() |
437 | .chain(build.target.iter().map(|s| INTERNER.intern_str(s))) | |
438 | { | |
439 | if !config.targets.contains(&target) { | |
440 | config.targets.push(target); | |
7453a54e SL |
441 | } |
442 | } | |
3b2f2976 XL |
443 | config.hosts = if !flags.host.is_empty() { |
444 | flags.host | |
445 | } else { | |
446 | config.hosts | |
447 | }; | |
448 | config.targets = if !flags.target.is_empty() { | |
449 | flags.target | |
450 | } else { | |
451 | config.targets | |
452 | }; | |
453 | ||
454 | ||
476ff2be | 455 | config.nodejs = build.nodejs.map(PathBuf::from); |
c30ab7b3 | 456 | config.gdb = build.gdb.map(PathBuf::from); |
476ff2be | 457 | config.python = build.python.map(PathBuf::from); |
7cac9316 | 458 | set(&mut config.low_priority, build.low_priority); |
7453a54e SL |
459 | set(&mut config.compiler_docs, build.compiler_docs); |
460 | set(&mut config.docs, build.docs); | |
c30ab7b3 | 461 | set(&mut config.submodules, build.submodules); |
0531ce1d | 462 | set(&mut config.fast_submodules, build.fast_submodules); |
8bb4bdeb | 463 | set(&mut config.locked_deps, build.locked_deps); |
476ff2be | 464 | set(&mut config.vendor, build.vendor); |
32a655c1 SL |
465 | set(&mut config.full_bootstrap, build.full_bootstrap); |
466 | set(&mut config.extended, build.extended); | |
2c00a5a8 | 467 | config.tools = build.tools; |
8bb4bdeb XL |
468 | set(&mut config.verbose, build.verbose); |
469 | set(&mut config.sanitizers, build.sanitizers); | |
041b39d2 | 470 | set(&mut config.profiler, build.profiler); |
8bb4bdeb | 471 | set(&mut config.openssl_static, build.openssl_static); |
ea8adc8c XL |
472 | set(&mut config.configure_args, build.configure_args); |
473 | set(&mut config.local_rebuild, build.local_rebuild); | |
0531ce1d | 474 | set(&mut config.print_step_timings, build.print_step_timings); |
3b2f2976 | 475 | config.verbose = cmp::max(config.verbose, flags.verbose); |
32a655c1 SL |
476 | |
477 | if let Some(ref install) = toml.install { | |
478 | config.prefix = install.prefix.clone().map(PathBuf::from); | |
7cac9316 | 479 | config.sysconfdir = install.sysconfdir.clone().map(PathBuf::from); |
2c00a5a8 | 480 | config.datadir = install.datadir.clone().map(PathBuf::from); |
32a655c1 | 481 | config.docdir = install.docdir.clone().map(PathBuf::from); |
7cac9316 | 482 | config.bindir = install.bindir.clone().map(PathBuf::from); |
32a655c1 | 483 | config.libdir = install.libdir.clone().map(PathBuf::from); |
7cac9316 | 484 | config.mandir = install.mandir.clone().map(PathBuf::from); |
32a655c1 | 485 | } |
7453a54e | 486 | |
ea8adc8c XL |
487 | // Store off these values as options because if they're not provided |
488 | // we'll infer default values for them later | |
489 | let mut llvm_assertions = None; | |
490 | let mut debuginfo_lines = None; | |
491 | let mut debuginfo_only_std = None; | |
83c7162d | 492 | let mut debuginfo_tools = None; |
ea8adc8c XL |
493 | let mut debug = None; |
494 | let mut debug_jemalloc = None; | |
495 | let mut debuginfo = None; | |
496 | let mut debug_assertions = None; | |
497 | let mut optimize = None; | |
498 | let mut ignore_git = None; | |
499 | ||
7453a54e | 500 | if let Some(ref llvm) = toml.llvm { |
476ff2be SL |
501 | match llvm.ccache { |
502 | Some(StringOrBool::String(ref s)) => { | |
503 | config.ccache = Some(s.to_string()) | |
504 | } | |
505 | Some(StringOrBool::Bool(true)) => { | |
506 | config.ccache = Some("ccache".to_string()); | |
507 | } | |
508 | Some(StringOrBool::Bool(false)) | None => {} | |
509 | } | |
a7813a04 | 510 | set(&mut config.ninja, llvm.ninja); |
3b2f2976 | 511 | set(&mut config.llvm_enabled, llvm.enabled); |
ea8adc8c | 512 | llvm_assertions = llvm.assertions; |
7453a54e | 513 | set(&mut config.llvm_optimize, llvm.optimize); |
b7449926 | 514 | set(&mut config.llvm_thin_lto, llvm.thin_lto); |
476ff2be | 515 | set(&mut config.llvm_release_debuginfo, llvm.release_debuginfo); |
7453a54e SL |
516 | set(&mut config.llvm_version_check, llvm.version_check); |
517 | set(&mut config.llvm_static_stdcpp, llvm.static_libstdcpp); | |
ea8adc8c | 518 | set(&mut config.llvm_link_shared, llvm.link_shared); |
32a655c1 | 519 | config.llvm_targets = llvm.targets.clone(); |
ff7c6d11 | 520 | config.llvm_experimental_targets = llvm.experimental_targets.clone() |
b7449926 | 521 | .unwrap_or("WebAssembly;RISCV".to_string()); |
8bb4bdeb | 522 | config.llvm_link_jobs = llvm.link_jobs; |
b7449926 | 523 | config.llvm_version_suffix = llvm.version_suffix.clone(); |
94b46f34 | 524 | config.llvm_clang_cl = llvm.clang_cl.clone(); |
7453a54e | 525 | } |
32a655c1 | 526 | |
7453a54e | 527 | if let Some(ref rust) = toml.rust { |
ea8adc8c XL |
528 | debug = rust.debug; |
529 | debug_assertions = rust.debug_assertions; | |
530 | debuginfo = rust.debuginfo; | |
531 | debuginfo_lines = rust.debuginfo_lines; | |
532 | debuginfo_only_std = rust.debuginfo_only_std; | |
83c7162d | 533 | debuginfo_tools = rust.debuginfo_tools; |
ea8adc8c XL |
534 | optimize = rust.optimize; |
535 | ignore_git = rust.ignore_git; | |
536 | debug_jemalloc = rust.debug_jemalloc; | |
a7813a04 XL |
537 | set(&mut config.rust_optimize_tests, rust.optimize_tests); |
538 | set(&mut config.rust_debuginfo_tests, rust.debuginfo_tests); | |
9e0c209e | 539 | set(&mut config.codegen_tests, rust.codegen_tests); |
7453a54e | 540 | set(&mut config.rust_rpath, rust.rpath); |
7453a54e | 541 | set(&mut config.use_jemalloc, rust.use_jemalloc); |
5bcae85e | 542 | set(&mut config.backtrace, rust.backtrace); |
7453a54e | 543 | set(&mut config.channel, rust.channel.clone()); |
ea8adc8c | 544 | set(&mut config.rust_dist_src, rust.dist_src); |
94b46f34 | 545 | set(&mut config.verbose_tests, rust.verbose_tests); |
ea8adc8c | 546 | set(&mut config.test_miri, rust.test_miri); |
94b46f34 XL |
547 | // in the case "false" is set explicitly, do not overwrite the command line args |
548 | if let Some(true) = rust.incremental { | |
549 | config.incremental = true; | |
550 | } | |
2c00a5a8 | 551 | set(&mut config.wasm_syscall, rust.wasm_syscall); |
0531ce1d | 552 | set(&mut config.lld_enabled, rust.lld); |
b7449926 | 553 | set(&mut config.lldb_enabled, rust.lldb); |
8faf50e0 | 554 | set(&mut config.llvm_tools_enabled, rust.llvm_tools); |
ff7c6d11 | 555 | config.rustc_parallel_queries = rust.experimental_parallel_queries.unwrap_or(false); |
7453a54e | 556 | config.rustc_default_linker = rust.default_linker.clone(); |
7453a54e | 557 | config.musl_root = rust.musl_root.clone().map(PathBuf::from); |
ff7c6d11 | 558 | config.save_toolstates = rust.save_toolstates.clone().map(PathBuf::from); |
83c7162d XL |
559 | set(&mut config.deny_warnings, rust.deny_warnings.or(flags.warnings)); |
560 | set(&mut config.backtrace_on_ice, rust.backtrace_on_ice); | |
8faf50e0 | 561 | set(&mut config.rust_verify_llvm_ir, rust.verify_llvm_ir); |
b7449926 | 562 | set(&mut config.rust_remap_debuginfo, rust.remap_debuginfo); |
7453a54e | 563 | |
2c00a5a8 XL |
564 | if let Some(ref backends) = rust.codegen_backends { |
565 | config.rust_codegen_backends = backends.iter() | |
566 | .map(|s| INTERNER.intern_str(s)) | |
567 | .collect(); | |
568 | } | |
569 | ||
0531ce1d XL |
570 | set(&mut config.rust_codegen_backends_dir, rust.codegen_backends_dir.clone()); |
571 | ||
7453a54e | 572 | match rust.codegen_units { |
abe05a73 XL |
573 | Some(0) => config.rust_codegen_units = Some(num_cpus::get() as u32), |
574 | Some(n) => config.rust_codegen_units = Some(n), | |
7453a54e SL |
575 | None => {} |
576 | } | |
577 | } | |
578 | ||
579 | if let Some(ref t) = toml.target { | |
580 | for (triple, cfg) in t { | |
581 | let mut target = Target::default(); | |
582 | ||
583 | if let Some(ref s) = cfg.llvm_config { | |
83c7162d | 584 | target.llvm_config = Some(config.src.join(s)); |
7453a54e SL |
585 | } |
586 | if let Some(ref s) = cfg.jemalloc { | |
83c7162d | 587 | target.jemalloc = Some(config.src.join(s)); |
7453a54e SL |
588 | } |
589 | if let Some(ref s) = cfg.android_ndk { | |
83c7162d | 590 | target.ndk = Some(config.src.join(s)); |
7453a54e | 591 | } |
7453a54e | 592 | target.cc = cfg.cc.clone().map(PathBuf::from); |
abe05a73 XL |
593 | target.cxx = cfg.cxx.clone().map(PathBuf::from); |
594 | target.ar = cfg.ar.clone().map(PathBuf::from); | |
b7449926 | 595 | target.ranlib = cfg.ranlib.clone().map(PathBuf::from); |
abe05a73 | 596 | target.linker = cfg.linker.clone().map(PathBuf::from); |
3b2f2976 | 597 | target.crt_static = cfg.crt_static.clone(); |
c30ab7b3 | 598 | target.musl_root = cfg.musl_root.clone().map(PathBuf::from); |
8bb4bdeb | 599 | target.qemu_rootfs = cfg.qemu_rootfs.clone().map(PathBuf::from); |
7453a54e | 600 | |
3b2f2976 | 601 | config.target_config.insert(INTERNER.intern_string(triple.clone()), target); |
7453a54e SL |
602 | } |
603 | } | |
604 | ||
32a655c1 SL |
605 | if let Some(ref t) = toml.dist { |
606 | config.dist_sign_folder = t.sign_folder.clone().map(PathBuf::from); | |
607 | config.dist_gpg_password_file = t.gpg_password_file.clone().map(PathBuf::from); | |
608 | config.dist_upload_addr = t.upload_addr.clone(); | |
8bb4bdeb | 609 | set(&mut config.rust_dist_src, t.src_tarball); |
32a655c1 SL |
610 | } |
611 | ||
ea8adc8c XL |
612 | // Now that we've reached the end of our configuration, infer the |
613 | // default values for all options that we haven't otherwise stored yet. | |
7cac9316 | 614 | |
83c7162d XL |
615 | set(&mut config.initial_rustc, build.rustc.map(PathBuf::from)); |
616 | set(&mut config.initial_cargo, build.cargo.map(PathBuf::from)); | |
617 | ||
abe05a73 | 618 | let default = false; |
ea8adc8c | 619 | config.llvm_assertions = llvm_assertions.unwrap_or(default); |
7453a54e | 620 | |
ea8adc8c XL |
621 | let default = match &config.channel[..] { |
622 | "stable" | "beta" | "nightly" => true, | |
623 | _ => false, | |
624 | }; | |
625 | config.rust_debuginfo_lines = debuginfo_lines.unwrap_or(default); | |
626 | config.rust_debuginfo_only_std = debuginfo_only_std.unwrap_or(default); | |
83c7162d | 627 | config.rust_debuginfo_tools = debuginfo_tools.unwrap_or(false); |
7453a54e | 628 | |
ea8adc8c XL |
629 | let default = debug == Some(true); |
630 | config.debug_jemalloc = debug_jemalloc.unwrap_or(default); | |
631 | config.rust_debuginfo = debuginfo.unwrap_or(default); | |
632 | config.rust_debug_assertions = debug_assertions.unwrap_or(default); | |
633 | config.rust_optimize = optimize.unwrap_or(!default); | |
7453a54e | 634 | |
ea8adc8c XL |
635 | let default = config.channel == "dev"; |
636 | config.ignore_git = ignore_git.unwrap_or(default); | |
8bb4bdeb | 637 | |
ea8adc8c | 638 | config |
7453a54e | 639 | } |
32a655c1 | 640 | |
2c00a5a8 XL |
641 | /// Try to find the relative path of `libdir`. |
642 | pub fn libdir_relative(&self) -> Option<&Path> { | |
643 | let libdir = self.libdir.as_ref()?; | |
644 | if libdir.is_relative() { | |
645 | Some(libdir) | |
646 | } else { | |
647 | // Try to make it relative to the prefix. | |
648 | libdir.strip_prefix(self.prefix.as_ref()?).ok() | |
649 | } | |
650 | } | |
651 | ||
32a655c1 SL |
652 | pub fn verbose(&self) -> bool { |
653 | self.verbose > 0 | |
654 | } | |
655 | ||
656 | pub fn very_verbose(&self) -> bool { | |
657 | self.verbose > 1 | |
658 | } | |
7453a54e SL |
659 | } |
660 | ||
661 | fn set<T>(field: &mut T, val: Option<T>) { | |
662 | if let Some(v) = val { | |
663 | *field = v; | |
664 | } | |
665 | } |