-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Expand file tree
/
Copy pathconfig.rs
More file actions
2631 lines (2397 loc) · 108 KB
/
Copy pathconfig.rs
File metadata and controls
2631 lines (2397 loc) · 108 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//! This module defines the central `Config` struct, which aggregates all components
//! of the bootstrap configuration into a single unit.
//!
//! It serves as the primary public interface for accessing the bootstrap configuration.
//! The module coordinates the overall configuration parsing process using logic from `parsing.rs`
//! and provides top-level methods such as `Config::parse()` for initialization, as well as
//! utility methods for querying and manipulating the complete configuration state.
//!
//! Additionally, this module contains the core logic for parsing, validating, and inferring
//! the final `Config` from various raw inputs.
//!
//! It manages the process of reading command-line arguments, environment variables,
//! and the `bootstrap.toml` file—merging them, applying defaults, and performing
//! cross-component validation. The main `parse_inner` function and its supporting
//! helpers reside here, transforming raw `Toml` data into the structured `Config` type.
use std::cell::Cell;
use std::collections::{BTreeSet, HashMap, HashSet};
use std::io::IsTerminal;
use std::path::{Path, PathBuf, absolute};
use std::str::FromStr;
use std::sync::{Arc, Mutex};
use std::{cmp, env, fs};
use build_helper::ci::CiEnv;
use build_helper::exit;
use build_helper::git::{GitConfig, PathFreshness, check_path_modifications};
use serde::Deserialize;
#[cfg(feature = "tracing")]
use tracing::{instrument, span};
use crate::core::build_steps::llvm;
use crate::core::build_steps::llvm::LLVM_INVALIDATION_PATHS;
pub use crate::core::config::flags::Subcommand;
use crate::core::config::flags::{Color, Flags, Warnings};
use crate::core::config::target_selection::TargetSelectionList;
use crate::core::config::toml::TomlConfig;
use crate::core::config::toml::build::{Build, Tool};
use crate::core::config::toml::change_id::ChangeId;
use crate::core::config::toml::dist::Dist;
use crate::core::config::toml::gcc::Gcc;
use crate::core::config::toml::install::Install;
use crate::core::config::toml::llvm::Llvm;
use crate::core::config::toml::rust::{
BootstrapOverrideLld, Rust, RustOptimize, check_incompatible_options_for_ci_rustc,
parse_codegen_backends,
};
use crate::core::config::toml::target::{
DefaultLinuxLinkerOverride, Target, TomlTarget, default_linux_linker_overrides,
};
use crate::core::config::{
CompilerBuiltins, DebuginfoLevel, DryRun, GccCiMode, LlvmLibunwind, Merge, ReplaceOpt,
RustcLto, SplitDebuginfo, StringOrBool, threads_from_config,
};
use crate::core::download::{
DownloadContext, download_beta_toolchain, is_download_ci_available, maybe_download_rustfmt,
};
use crate::utils::channel;
use crate::utils::exec::{ExecutionContext, command};
use crate::utils::helpers::{exe, get_host_target};
use crate::{CodegenBackendKind, GitInfo, OnceLock, TargetSelection, check_ci_llvm, helpers, t};
/// Each path in this list is considered "allowed" in the `download-rustc="if-unchanged"` logic.
/// This means they can be modified and changes to these paths should never trigger a compiler build
/// when "if-unchanged" is set.
///
/// NOTE: Paths must have the ":!" prefix to tell git to ignore changes in those paths during
/// the diff check.
///
/// WARNING: Be cautious when adding paths to this list. If a path that influences the compiler build
/// is added here, it will cause bootstrap to skip necessary rebuilds, which may lead to risky results.
/// For example, "src/bootstrap" should never be included in this list as it plays a crucial role in the
/// final output/compiler, which can be significantly affected by changes made to the bootstrap sources.
#[rustfmt::skip] // We don't want rustfmt to oneline this list
pub const RUSTC_IF_UNCHANGED_ALLOWED_PATHS: &[&str] = &[
":!library",
":!src/tools",
":!src/librustdoc",
":!src/rustdoc-json-types",
":!tests",
":!triagebot.toml",
];
/// Global configuration for the entire build and/or bootstrap.
///
/// This structure is parsed from `bootstrap.toml`, and some of the fields are inferred from `git` or build-time parameters.
///
/// Note that this structure is not decoded directly into, but rather it is
/// filled out from the decoded forms of the structs below. For documentation
/// on each field, see the corresponding fields in
/// `bootstrap.example.toml`.
#[derive(Default, Clone)]
pub struct Config {
pub change_id: Option<ChangeId>,
pub bypass_bootstrap_lock: bool,
pub ccache: Option<String>,
/// Call Build::ninja() instead of this.
pub ninja_in_file: bool,
pub submodules: Option<bool>,
pub compiler_docs: bool,
pub library_docs_private_items: bool,
pub docs_minification: bool,
pub docs: bool,
pub locked_deps: bool,
pub vendor: bool,
pub target_config: HashMap<TargetSelection, Target>,
pub full_bootstrap: bool,
pub bootstrap_cache_path: Option<PathBuf>,
pub extended: bool,
pub tools: Option<HashSet<String>>,
/// Specify build configuration specific for some tool, such as enabled features, see [Tool].
/// The key in the map is the name of the tool, and the value is tool-specific configuration.
pub tool: HashMap<String, Tool>,
pub sanitizers: bool,
pub profiler: bool,
pub omit_git_hash: bool,
pub skip: Vec<PathBuf>,
pub include_default_paths: bool,
pub rustc_error_format: Option<String>,
pub json_output: bool,
pub compile_time_deps: bool,
pub test_compare_mode: bool,
pub color: Color,
pub patch_binaries_for_nix: Option<bool>,
pub stage0_metadata: build_helper::stage0_parser::Stage0,
pub android_ndk: Option<PathBuf>,
pub optimized_compiler_builtins: CompilerBuiltins,
pub stdout_is_tty: bool,
pub stderr_is_tty: bool,
pub on_fail: Option<String>,
pub explicit_stage_from_cli: bool,
pub explicit_stage_from_config: bool,
pub stage: u32,
pub keep_stage: Vec<u32>,
pub keep_stage_std: Vec<u32>,
pub src: PathBuf,
/// defaults to `bootstrap.toml`
pub config: Option<PathBuf>,
pub jobs: Option<u32>,
pub cmd: Subcommand,
pub incremental: bool,
pub dump_bootstrap_shims: bool,
/// Arguments appearing after `--` to be forwarded to tools,
/// e.g. `--fix-broken` or test arguments.
pub free_args: Vec<String>,
/// `None` if we shouldn't download CI compiler artifacts, or the commit to download if we should.
pub download_rustc_commit: Option<String>,
pub deny_warnings: bool,
pub backtrace_on_ice: bool,
// llvm codegen options
pub llvm_assertions: bool,
pub llvm_tests: bool,
pub llvm_enzyme: bool,
pub llvm_offload: bool,
pub llvm_plugins: bool,
pub llvm_optimize: bool,
pub llvm_thin_lto: bool,
pub llvm_release_debuginfo: bool,
pub llvm_static_stdcpp: bool,
pub llvm_libzstd: bool,
pub llvm_link_shared: Cell<Option<bool>>,
pub llvm_clang_cl: Option<String>,
pub llvm_targets: Option<String>,
pub llvm_experimental_targets: Option<String>,
pub llvm_link_jobs: Option<u32>,
pub llvm_version_suffix: Option<String>,
pub llvm_use_linker: Option<String>,
pub llvm_clang_dir: Option<PathBuf>,
pub llvm_allow_old_toolchain: bool,
pub llvm_polly: bool,
pub llvm_clang: bool,
pub llvm_enable_warnings: bool,
pub llvm_from_ci: bool,
pub llvm_build_config: HashMap<String, String>,
pub bootstrap_override_lld: BootstrapOverrideLld,
pub lld_enabled: bool,
pub llvm_tools_enabled: bool,
pub llvm_bitcode_linker_enabled: bool,
pub llvm_cflags: Option<String>,
pub llvm_cxxflags: Option<String>,
pub llvm_ldflags: Option<String>,
pub llvm_use_libcxx: bool,
// gcc codegen options
pub gcc_ci_mode: GccCiMode,
pub libgccjit_libs_dir: Option<PathBuf>,
// rust codegen options
pub rust_optimize: RustOptimize,
pub rust_codegen_units: Option<u32>,
pub rust_codegen_units_std: Option<u32>,
pub rustc_debug_assertions: bool,
pub std_debug_assertions: bool,
pub tools_debug_assertions: bool,
pub rust_overflow_checks: bool,
pub rust_overflow_checks_std: bool,
pub rust_debug_logging: bool,
pub rust_debuginfo_level_rustc: DebuginfoLevel,
pub rust_debuginfo_level_std: DebuginfoLevel,
pub rust_debuginfo_level_tools: DebuginfoLevel,
pub rust_debuginfo_level_tests: DebuginfoLevel,
pub rust_rpath: bool,
pub rust_strip: bool,
pub rust_frame_pointers: bool,
pub rust_stack_protector: Option<String>,
pub rustc_default_linker: Option<String>,
pub rust_optimize_tests: bool,
pub rust_dist_src: bool,
pub rust_codegen_backends: Vec<CodegenBackendKind>,
pub rust_verify_llvm_ir: bool,
pub rust_thin_lto_import_instr_limit: Option<u32>,
pub rust_randomize_layout: bool,
pub rust_remap_debuginfo: bool,
pub rust_new_symbol_mangling: Option<bool>,
pub rust_annotate_moves_size_limit: Option<u64>,
pub rust_profile_use: Option<String>,
pub rust_profile_generate: Option<String>,
pub rust_lto: RustcLto,
pub rust_validate_mir_opts: Option<u32>,
pub rust_std_features: BTreeSet<String>,
pub rust_break_on_ice: bool,
pub rust_parallel_frontend_threads: Option<u32>,
pub rust_rustflags: Vec<String>,
pub llvm_profile_use: Option<String>,
pub llvm_profile_generate: bool,
pub llvm_libunwind_default: Option<LlvmLibunwind>,
pub enable_bolt_settings: bool,
pub reproducible_artifacts: Vec<String>,
pub host_target: TargetSelection,
pub hosts: Vec<TargetSelection>,
pub targets: Vec<TargetSelection>,
pub local_rebuild: bool,
pub jemalloc: bool,
pub control_flow_guard: bool,
pub ehcont_guard: bool,
// dist misc
pub dist_sign_folder: Option<PathBuf>,
pub dist_upload_addr: Option<String>,
pub dist_compression_formats: Option<Vec<String>>,
pub dist_compression_profile: String,
pub dist_include_mingw_linker: bool,
pub dist_vendor: bool,
// libstd features
pub backtrace: bool, // support for RUST_BACKTRACE
// misc
pub low_priority: bool,
pub channel: String,
pub description: Option<String>,
pub verbose_tests: bool,
pub save_toolstates: Option<PathBuf>,
pub print_step_timings: bool,
pub print_step_rusage: bool,
// Fallback musl-root for all targets
pub musl_root: Option<PathBuf>,
pub prefix: Option<PathBuf>,
pub sysconfdir: Option<PathBuf>,
pub datadir: Option<PathBuf>,
pub docdir: Option<PathBuf>,
pub bindir: PathBuf,
pub libdir: Option<PathBuf>,
pub mandir: Option<PathBuf>,
pub codegen_tests: bool,
pub nodejs: Option<PathBuf>,
pub yarn: Option<PathBuf>,
pub gdb: Option<PathBuf>,
pub lldb: Option<PathBuf>,
pub python: Option<PathBuf>,
pub windows_rc: Option<PathBuf>,
pub reuse: Option<PathBuf>,
pub cargo_native_static: bool,
pub configure_args: Vec<String>,
pub out: PathBuf,
pub rust_info: channel::GitInfo,
pub cargo_info: channel::GitInfo,
pub rust_analyzer_info: channel::GitInfo,
pub clippy_info: channel::GitInfo,
pub miri_info: channel::GitInfo,
pub rustfmt_info: channel::GitInfo,
pub enzyme_info: channel::GitInfo,
pub in_tree_llvm_info: channel::GitInfo,
pub in_tree_gcc_info: channel::GitInfo,
// These are either the stage0 downloaded binaries or the locally installed ones.
pub initial_cargo: PathBuf,
pub initial_rustc: PathBuf,
pub initial_cargo_clippy: Option<PathBuf>,
pub initial_sysroot: PathBuf,
pub initial_rustfmt: Option<PathBuf>,
/// The paths to work with. For example: with `./x check foo bar` we get
/// `paths=["foo", "bar"]`.
pub paths: Vec<PathBuf>,
/// Command for visual diff display, e.g. `diff-tool --color=always`.
pub compiletest_diff_tool: Option<String>,
/// Whether to allow running both `compiletest` self-tests and `compiletest`-managed test suites
/// against the stage 0 (rustc, std).
///
/// This is only intended to be used when the stage 0 compiler is actually built from in-tree
/// sources.
pub compiletest_allow_stage0: bool,
/// Default value for `--extra-checks`
pub tidy_extra_checks: Option<String>,
pub is_running_on_ci: bool,
/// Cache for determining path modifications
pub path_modification_cache: Arc<Mutex<HashMap<Vec<&'static str>, PathFreshness>>>,
/// Skip checking the standard library if `rust.download-rustc` isn't available.
/// This is mostly for RA as building the stage1 compiler to check the library tree
/// on each code change might be too much for some computers.
pub skip_std_check_if_no_download_rustc: bool,
pub exec_ctx: ExecutionContext,
}
impl Config {
pub fn set_dry_run(&mut self, dry_run: DryRun) {
self.exec_ctx.set_dry_run(dry_run);
}
pub fn get_dry_run(&self) -> &DryRun {
self.exec_ctx.get_dry_run()
}
#[cfg_attr(
feature = "tracing",
instrument(target = "CONFIG_HANDLING", level = "trace", name = "Config::parse", skip_all)
)]
pub fn parse(flags: Flags) -> Config {
Self::parse_inner(flags, Self::get_toml)
}
#[cfg_attr(
feature = "tracing",
instrument(
target = "CONFIG_HANDLING",
level = "trace",
name = "Config::parse_inner",
skip_all
)
)]
pub(crate) fn parse_inner(
flags: Flags,
get_toml: impl Fn(&Path) -> Result<TomlConfig, toml::de::Error>,
) -> Config {
// Destructure flags to ensure that we use all its fields
// The field variables are prefixed with `flags_` to avoid clashes
// with values from TOML config files with same names.
let Flags {
cmd: flags_cmd,
verbose: flags_verbose,
incremental: flags_incremental,
config: flags_config,
build_dir: flags_build_dir,
build: flags_build,
host: flags_host,
target: flags_target,
exclude: flags_exclude,
skip: flags_skip,
include_default_paths: flags_include_default_paths,
rustc_error_format: flags_rustc_error_format,
on_fail: flags_on_fail,
dry_run: flags_dry_run,
dump_bootstrap_shims: flags_dump_bootstrap_shims,
stage: flags_stage,
keep_stage: flags_keep_stage,
keep_stage_std: flags_keep_stage_std,
src: flags_src,
jobs: flags_jobs,
warnings: flags_warnings,
json_output: flags_json_output,
compile_time_deps: flags_compile_time_deps,
color: flags_color,
bypass_bootstrap_lock: flags_bypass_bootstrap_lock,
rust_profile_generate: flags_rust_profile_generate,
rust_profile_use: flags_rust_profile_use,
llvm_profile_use: flags_llvm_profile_use,
llvm_profile_generate: flags_llvm_profile_generate,
enable_bolt_settings: flags_enable_bolt_settings,
skip_stage0_validation: flags_skip_stage0_validation,
reproducible_artifact: flags_reproducible_artifact,
paths: flags_paths,
set: flags_set,
free_args: flags_free_args,
ci: flags_ci,
skip_std_check_if_no_download_rustc: flags_skip_std_check_if_no_download_rustc,
} = flags;
#[cfg(feature = "tracing")]
span!(
target: "CONFIG_HANDLING",
tracing::Level::TRACE,
"collecting paths and path exclusions",
"flags.paths" = ?flags_paths,
"flags.skip" = ?flags_skip,
"flags.exclude" = ?flags_exclude
);
// Set config values based on flags.
let mut exec_ctx = ExecutionContext::new(flags_verbose, flags_cmd.fail_fast());
exec_ctx.set_dry_run(if flags_dry_run { DryRun::UserSelected } else { DryRun::Disabled });
let default_src_dir = {
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
// Undo `src/bootstrap`
manifest_dir.parent().unwrap().parent().unwrap().to_owned()
};
let src = if let Some(s) = compute_src_directory(flags_src, &exec_ctx) {
s
} else {
default_src_dir.clone()
};
#[cfg(test)]
{
if let Some(config_path) = flags_config.as_ref() {
assert!(
!config_path.starts_with(&src),
"Path {config_path:?} should not be inside or equal to src dir {src:?}"
);
} else {
panic!("During test the config should be explicitly added");
}
}
// Now load the TOML config, as soon as possible
let (mut toml, toml_path) = load_toml_config(&src, flags_config, &get_toml);
postprocess_toml(&mut toml, &src, toml_path.clone(), &exec_ctx, &flags_set, &get_toml);
// Now override TOML values with flags, to make sure that we won't later override flags with
// TOML values by accident instead, because flags have higher priority.
let Build {
description: build_description,
build: build_build,
host: build_host,
target: build_target,
build_dir: build_build_dir,
cargo: mut build_cargo,
rustc: mut build_rustc,
rustfmt: build_rustfmt,
cargo_clippy: build_cargo_clippy,
docs: build_docs,
compiler_docs: build_compiler_docs,
library_docs_private_items: build_library_docs_private_items,
docs_minification: build_docs_minification,
submodules: build_submodules,
gdb: build_gdb,
lldb: build_lldb,
nodejs: build_nodejs,
yarn: build_yarn,
npm: build_npm,
python: build_python,
windows_rc: build_windows_rc,
reuse: build_reuse,
locked_deps: build_locked_deps,
vendor: build_vendor,
full_bootstrap: build_full_bootstrap,
bootstrap_cache_path: build_bootstrap_cache_path,
extended: build_extended,
tools: build_tools,
tool: build_tool,
verbose: build_verbose,
sanitizers: build_sanitizers,
profiler: build_profiler,
cargo_native_static: build_cargo_native_static,
low_priority: build_low_priority,
configure_args: build_configure_args,
local_rebuild: build_local_rebuild,
print_step_timings: build_print_step_timings,
print_step_rusage: build_print_step_rusage,
check_stage: build_check_stage,
doc_stage: build_doc_stage,
build_stage: build_build_stage,
test_stage: build_test_stage,
install_stage: build_install_stage,
dist_stage: build_dist_stage,
bench_stage: build_bench_stage,
patch_binaries_for_nix: build_patch_binaries_for_nix,
// This field is only used by bootstrap.py
metrics: _,
android_ndk: build_android_ndk,
optimized_compiler_builtins: build_optimized_compiler_builtins,
jobs: build_jobs,
compiletest_diff_tool: build_compiletest_diff_tool,
// No longer has any effect; kept (for now) to avoid breaking people's configs.
compiletest_use_stage0_libtest: _,
tidy_extra_checks: build_tidy_extra_checks,
ccache: build_ccache,
exclude: build_exclude,
compiletest_allow_stage0: build_compiletest_allow_stage0,
} = toml.build.unwrap_or_default();
let Install {
prefix: install_prefix,
sysconfdir: install_sysconfdir,
docdir: install_docdir,
bindir: install_bindir,
libdir: install_libdir,
mandir: install_mandir,
datadir: install_datadir,
} = toml.install.unwrap_or_default();
let Rust {
optimize: rust_optimize,
debug: rust_debug,
codegen_units: rust_codegen_units,
codegen_units_std: rust_codegen_units_std,
rustc_debug_assertions: rust_rustc_debug_assertions,
std_debug_assertions: rust_std_debug_assertions,
tools_debug_assertions: rust_tools_debug_assertions,
overflow_checks: rust_overflow_checks,
overflow_checks_std: rust_overflow_checks_std,
debug_logging: rust_debug_logging,
debuginfo_level: rust_debuginfo_level,
debuginfo_level_rustc: rust_debuginfo_level_rustc,
debuginfo_level_std: rust_debuginfo_level_std,
debuginfo_level_tools: rust_debuginfo_level_tools,
debuginfo_level_tests: rust_debuginfo_level_tests,
backtrace: rust_backtrace,
incremental: rust_incremental,
randomize_layout: rust_randomize_layout,
default_linker: rust_default_linker,
channel: rust_channel,
musl_root: rust_musl_root,
rpath: rust_rpath,
verbose_tests: rust_verbose_tests,
optimize_tests: rust_optimize_tests,
codegen_tests: rust_codegen_tests,
omit_git_hash: rust_omit_git_hash,
dist_src: rust_dist_src,
save_toolstates: rust_save_toolstates,
codegen_backends: rust_codegen_backends,
lld: rust_lld_enabled,
llvm_tools: rust_llvm_tools,
llvm_bitcode_linker: rust_llvm_bitcode_linker,
deny_warnings: rust_deny_warnings,
backtrace_on_ice: rust_backtrace_on_ice,
verify_llvm_ir: rust_verify_llvm_ir,
thin_lto_import_instr_limit: rust_thin_lto_import_instr_limit,
parallel_frontend_threads: rust_parallel_frontend_threads,
remap_debuginfo: rust_remap_debuginfo,
jemalloc: rust_jemalloc,
test_compare_mode: rust_test_compare_mode,
llvm_libunwind: rust_llvm_libunwind,
control_flow_guard: rust_control_flow_guard,
ehcont_guard: rust_ehcont_guard,
new_symbol_mangling: rust_new_symbol_mangling,
annotate_moves_size_limit: rust_annotate_moves_size_limit,
profile_generate: rust_profile_generate,
profile_use: rust_profile_use,
download_rustc: rust_download_rustc,
lto: rust_lto,
validate_mir_opts: rust_validate_mir_opts,
frame_pointers: rust_frame_pointers,
stack_protector: rust_stack_protector,
strip: rust_strip,
bootstrap_override_lld: rust_bootstrap_override_lld,
bootstrap_override_lld_legacy: rust_bootstrap_override_lld_legacy,
std_features: rust_std_features,
break_on_ice: rust_break_on_ice,
rustflags: rust_rustflags,
} = toml.rust.unwrap_or_default();
let Llvm {
optimize: llvm_optimize,
thin_lto: llvm_thin_lto,
release_debuginfo: llvm_release_debuginfo,
assertions: llvm_assertions,
tests: llvm_tests,
enzyme: llvm_enzyme,
plugins: llvm_plugin,
static_libstdcpp: llvm_static_libstdcpp,
libzstd: llvm_libzstd,
ninja: llvm_ninja,
targets: llvm_targets,
experimental_targets: llvm_experimental_targets,
link_jobs: llvm_link_jobs,
link_shared: llvm_link_shared,
version_suffix: llvm_version_suffix,
clang_cl: llvm_clang_cl,
cflags: llvm_cflags,
cxxflags: llvm_cxxflags,
ldflags: llvm_ldflags,
use_libcxx: llvm_use_libcxx,
use_linker: llvm_use_linker,
allow_old_toolchain: llvm_allow_old_toolchain,
offload: llvm_offload,
offload_clang_dir: llvm_clang_dir,
polly: llvm_polly,
clang: llvm_clang,
enable_warnings: llvm_enable_warnings,
download_ci_llvm: llvm_download_ci_llvm,
build_config: llvm_build_config,
} = toml.llvm.unwrap_or_default();
let Dist {
sign_folder: dist_sign_folder,
upload_addr: dist_upload_addr,
src_tarball: dist_src_tarball,
compression_formats: dist_compression_formats,
compression_profile: dist_compression_profile,
include_mingw_linker: dist_include_mingw_linker,
vendor: dist_vendor,
} = toml.dist.unwrap_or_default();
let Gcc {
download_ci_gcc: gcc_download_ci_gcc,
libgccjit_libs_dir: gcc_libgccjit_libs_dir,
} = toml.gcc.unwrap_or_default();
if rust_bootstrap_override_lld.is_some() && rust_bootstrap_override_lld_legacy.is_some() {
panic!(
"Cannot use both `rust.use-lld` and `rust.bootstrap-override-lld`. Please use only `rust.bootstrap-override-lld`"
);
}
let bootstrap_override_lld =
rust_bootstrap_override_lld.or(rust_bootstrap_override_lld_legacy).unwrap_or_default();
if rust_optimize.as_ref().is_some_and(|v| matches!(v, RustOptimize::Bool(false))) {
eprintln!(
"WARNING: setting `optimize` to `false` is known to cause errors and \
should be considered unsupported. Refer to `bootstrap.example.toml` \
for more details."
);
}
// Prefer CLI verbosity flags if set (`flags_verbose` > 0), otherwise take the value from
// TOML.
exec_ctx.set_verbosity(cmp::max(build_verbose.unwrap_or_default() as u8, flags_verbose));
let stage0_metadata = build_helper::stage0_parser::parse_stage0_file();
let path_modification_cache = Arc::new(Mutex::new(HashMap::new()));
let host_target = flags_build
.or(build_build)
.map(|build| TargetSelection::from_user(&build))
.unwrap_or_else(get_host_target);
let hosts = flags_host
.map(|TargetSelectionList(hosts)| hosts)
.or_else(|| {
build_host.map(|h| h.iter().map(|t| TargetSelection::from_user(t)).collect())
})
.unwrap_or_else(|| vec![host_target]);
let llvm_assertions = llvm_assertions.unwrap_or(false);
let mut target_config = HashMap::new();
let mut channel = "dev".to_string();
let out = flags_build_dir.or_else(|| build_build_dir.map(PathBuf::from));
let out = if cfg!(test) {
out.expect("--build-dir has to be specified in tests")
} else {
out.unwrap_or_else(|| PathBuf::from("build"))
};
// NOTE: Bootstrap spawns various commands with different working directories.
// To avoid writing to random places on the file system, `config.out` needs to be an absolute path.
let mut out = if !out.is_absolute() {
// `canonicalize` requires the path to already exist. Use our vendored copy of `absolute` instead.
absolute(&out).expect("can't make empty path absolute")
} else {
out
};
let default_stage0_rustc_path = |dir: &Path| {
dir.join(host_target).join("stage0").join("bin").join(exe("rustc", host_target))
};
if cfg!(test) {
// When configuring bootstrap for tests, make sure to set the rustc and Cargo to the
// same ones used to call the tests (if custom ones are not defined in the toml). If we
// don't do that, bootstrap will use its own detection logic to find a suitable rustc
// and Cargo, which doesn't work when the caller is specìfying a custom local rustc or
// Cargo in their bootstrap.toml.
build_rustc = build_rustc.take().or(std::env::var_os("RUSTC").map(|p| p.into()));
build_cargo = build_cargo.take().or(std::env::var_os("CARGO").map(|p| p.into()));
// If we are running only `cargo test` (and not `x test bootstrap`), which is useful
// e.g. for debugging bootstrap itself, then we won't have RUSTC and CARGO set to the
// proper paths.
// We thus "guess" that the build directory is located at <src>/build, and try to load
// rustc and cargo from there
let is_test_outside_x = std::env::var("CARGO_TARGET_DIR").is_err();
if is_test_outside_x && build_rustc.is_none() {
let stage0_rustc = default_stage0_rustc_path(&default_src_dir.join("build"));
assert!(
stage0_rustc.exists(),
"Trying to run cargo test without having a stage0 rustc available in {}",
stage0_rustc.display()
);
build_rustc = Some(stage0_rustc);
}
}
if !flags_skip_stage0_validation {
if let Some(rustc) = &build_rustc {
check_stage0_version(rustc, "rustc", &src, &exec_ctx);
}
if let Some(cargo) = &build_cargo {
check_stage0_version(cargo, "cargo", &src, &exec_ctx);
}
}
if build_cargo_clippy.is_some() && build_rustc.is_none() {
println!(
"WARNING: Using `build.cargo-clippy` without `build.rustc` usually fails due to toolchain conflict."
);
}
let is_running_on_ci = flags_ci.unwrap_or(CiEnv::is_ci());
let dwn_ctx = DownloadContext {
path_modification_cache: path_modification_cache.clone(),
src: &src,
submodules: &build_submodules,
host_target,
patch_binaries_for_nix: build_patch_binaries_for_nix,
exec_ctx: &exec_ctx,
stage0_metadata: &stage0_metadata,
llvm_assertions,
bootstrap_cache_path: &build_bootstrap_cache_path,
is_running_on_ci,
};
let initial_rustc = build_rustc.unwrap_or_else(|| {
download_beta_toolchain(&dwn_ctx, &out);
default_stage0_rustc_path(&out)
});
let initial_sysroot = t!(PathBuf::from_str(
command(&initial_rustc)
.args(["--print", "sysroot"])
.run_in_dry_run()
.run_capture_stdout(&exec_ctx)
.stdout()
.trim()
));
let initial_cargo = build_cargo.unwrap_or_else(|| {
download_beta_toolchain(&dwn_ctx, &out);
initial_sysroot.join("bin").join(exe("cargo", host_target))
});
// NOTE: it's important this comes *after* we set `initial_rustc` just above.
if exec_ctx.dry_run() {
out = out.join("tmp-dry-run");
fs::create_dir_all(&out).expect("Failed to create dry-run directory");
}
let file_content = t!(fs::read_to_string(src.join("src/ci/channel")));
let ci_channel = file_content.trim_end();
let is_user_configured_rust_channel = match rust_channel {
Some(channel_) if channel_ == "auto-detect" => {
channel = ci_channel.into();
true
}
Some(channel_) => {
channel = channel_;
true
}
None => false,
};
let omit_git_hash = rust_omit_git_hash.unwrap_or(channel == "dev");
let rust_info = git_info(&exec_ctx, omit_git_hash, &src);
if !is_user_configured_rust_channel && rust_info.is_from_tarball() {
channel = ci_channel.into();
}
// FIXME(#133381): alt rustc builds currently do *not* have rustc debug assertions
// enabled. We should not download a CI alt rustc if we need rustc to have debug
// assertions (e.g. for crashes test suite). This can be changed once something like
// [Enable debug assertions on alt
// builds](https://github.com/rust-lang/rust/pull/131077) lands.
//
// Note that `rust.debug = true` currently implies `rust.debug-assertions = true`!
//
// This relies also on the fact that the global default for `download-rustc` will be
// `false` if it's not explicitly set.
let debug_assertions_requested = matches!(rust_rustc_debug_assertions, Some(true))
|| (matches!(rust_debug, Some(true))
&& !matches!(rust_rustc_debug_assertions, Some(false)));
if debug_assertions_requested
&& let Some(ref opt) = rust_download_rustc
&& opt.is_string_or_true()
{
eprintln!(
"WARN: currently no CI rustc builds have rustc debug assertions \
enabled. Please either set `rust.debug-assertions` to `false` if you \
want to use download CI rustc or set `rust.download-rustc` to `false`."
);
}
let mut download_rustc_commit =
download_ci_rustc_commit(&dwn_ctx, &rust_info, rust_download_rustc, llvm_assertions);
if debug_assertions_requested && download_rustc_commit.is_some() {
eprintln!(
"WARN: `rust.debug-assertions = true` will prevent downloading CI rustc as alt CI \
rustc is not currently built with debug assertions."
);
// We need to put this later down_ci_rustc_commit.
download_rustc_commit = None;
}
// We need to override `rust.channel` if it's manually specified when using the CI rustc.
// This is because if the compiler uses a different channel than the one specified in bootstrap.toml,
// tests may fail due to using a different channel than the one used by the compiler during tests.
if let Some(commit) = &download_rustc_commit
&& is_user_configured_rust_channel
{
println!(
"WARNING: `rust.download-rustc` is enabled. The `rust.channel` option will be overridden by the CI rustc's channel."
);
channel =
read_file_by_commit(&dwn_ctx, &rust_info, Path::new("src/ci/channel"), commit)
.trim()
.to_owned();
}
if build_npm.is_some() {
println!(
"WARNING: `build.npm` set in bootstrap.toml, this option no longer has any effect. . Use `build.yarn` instead to provide a path to a `yarn` binary."
);
}
let mut lld_enabled = rust_lld_enabled.unwrap_or(false);
// Linux targets for which the user explicitly overrode the used linker
let mut targets_with_user_linker_override = HashSet::new();
if let Some(t) = toml.target {
for (triple, cfg) in t {
let TomlTarget {
cc: target_cc,
cxx: target_cxx,
ar: target_ar,
ranlib: target_ranlib,
default_linker: target_default_linker,
default_linker_linux_override: target_default_linker_linux_override,
linker: target_linker,
split_debuginfo: target_split_debuginfo,
llvm_config: target_llvm_config,
llvm_has_rust_patches: target_llvm_has_rust_patches,
llvm_filecheck: target_llvm_filecheck,
llvm_libunwind: target_llvm_libunwind,
sanitizers: target_sanitizers,
profiler: target_profiler,
rpath: target_rpath,
rustflags: target_rustflags,
crt_static: target_crt_static,
musl_root: target_musl_root,
musl_libdir: target_musl_libdir,
wasi_root: target_wasi_root,
qemu_rootfs: target_qemu_rootfs,
no_std: target_no_std,
codegen_backends: target_codegen_backends,
runner: target_runner,
optimized_compiler_builtins: target_optimized_compiler_builtins,
jemalloc: target_jemalloc,
} = cfg;
let mut target = Target::from_triple(&triple);
if target_default_linker_linux_override.is_some() {
targets_with_user_linker_override.insert(triple.clone());
}
let default_linker_linux_override = match target_default_linker_linux_override {
Some(DefaultLinuxLinkerOverride::SelfContainedLldCc) => {
if rust_default_linker.is_some() {
panic!(
"cannot set both `default-linker` and `default-linker-linux` for target `{triple}`"
);
}
if !triple.contains("linux-gnu") {
panic!(
"`default-linker-linux` can only be set for Linux GNU targets, not for `{triple}`"
);
}
if !lld_enabled {
panic!(
"Trying to override the default Linux linker for `{triple}` to be self-contained LLD, but LLD is not being built. Enable it with rust.lld = true."
);
}
DefaultLinuxLinkerOverride::SelfContainedLldCc
}
Some(DefaultLinuxLinkerOverride::Off) => DefaultLinuxLinkerOverride::Off,
None => DefaultLinuxLinkerOverride::default(),
};
if let Some(ref s) = target_llvm_config {
if download_rustc_commit.is_some() && triple == *host_target.triple {
panic!(
"setting llvm_config for the host is incompatible with download-rustc"
);
}
target.llvm_config = Some(src.join(s));
}
if let Some(patches) = target_llvm_has_rust_patches {
assert!(
build_submodules == Some(false) || target_llvm_config.is_some(),
"use of `llvm-has-rust-patches` is restricted to cases where either submodules are disabled or llvm-config been provided"
);
target.llvm_has_rust_patches = Some(patches);
}
if let Some(ref s) = target_llvm_filecheck {
target.llvm_filecheck = Some(src.join(s));
}
target.llvm_libunwind = target_llvm_libunwind.as_ref().map(|v| {
v.parse().unwrap_or_else(|_| {
panic!("failed to parse target.{triple}.llvm-libunwind")
})
});
if let Some(s) = target_no_std {
target.no_std = s;
}
target.cc = target_cc.map(PathBuf::from);
target.cxx = target_cxx.map(PathBuf::from);
target.ar = target_ar.map(PathBuf::from);
target.ranlib = target_ranlib.map(PathBuf::from);
target.linker = target_linker.map(PathBuf::from);
target.crt_static = target_crt_static;
target.default_linker = target_default_linker;
target.default_linker_linux_override = default_linker_linux_override;
target.musl_root = target_musl_root.map(PathBuf::from);
target.musl_libdir = target_musl_libdir.map(PathBuf::from);
target.wasi_root = target_wasi_root.map(PathBuf::from);
target.qemu_rootfs = target_qemu_rootfs.map(PathBuf::from);
target.runner = target_runner;
target.sanitizers = target_sanitizers;
target.profiler = target_profiler;
target.rpath = target_rpath;
target.rustflags = target_rustflags.unwrap_or_default();
target.optimized_compiler_builtins = target_optimized_compiler_builtins;
target.jemalloc = target_jemalloc;
if let Some(backends) = target_codegen_backends {
target.codegen_backends =
Some(parse_codegen_backends(backends, &format!("target.{triple}")))
}
target.split_debuginfo = target_split_debuginfo.as_ref().map(|v| {
v.parse().unwrap_or_else(|_| {
panic!("invalid value for target.{triple}.split-debuginfo")
})
});
target_config.insert(TargetSelection::from_user(&triple), target);
}
}
let llvm_from_ci = parse_download_ci_llvm(
&dwn_ctx,
&rust_info,
&download_rustc_commit,
llvm_download_ci_llvm,
llvm_assertions,
);
let is_host_system_llvm =
is_system_llvm(&target_config, llvm_from_ci, host_target, host_target);
if llvm_from_ci {
let warn = |option: &str| {
println!(
"WARNING: `{option}` will only be used on `compiler/rustc_llvm` build, not for the LLVM build."
);
println!(
"HELP: To use `{option}` for LLVM builds, set `download-ci-llvm` option to false."
);
};
if llvm_static_libstdcpp.is_some() {
warn("static-libstdcpp");
}