-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Expand file tree
/
Copy pathcommon.rs
More file actions
1305 lines (1144 loc) · 48.3 KB
/
Copy pathcommon.rs
File metadata and controls
1305 lines (1144 loc) · 48.3 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
use std::borrow::Cow;
use std::collections::{BTreeSet, HashMap, HashSet};
use std::iter;
use std::process::Command;
use std::sync::OnceLock;
use build_helper::git::GitConfig;
use camino::{Utf8Path, Utf8PathBuf};
use semver::Version;
use crate::edition::Edition;
use crate::fatal;
use crate::util::{Utf8PathBufExt, add_dylib_path, string_enum};
string_enum! {
#[derive(Clone, Copy, PartialEq, Debug)]
pub(crate) enum TestMode {
Pretty => "pretty",
DebugInfo => "debuginfo",
Codegen => "codegen",
RustdocHtml => "rustdoc-html",
RustdocJson => "rustdoc-json",
CodegenUnits => "codegen-units",
Incremental => "incremental",
RunMake => "run-make",
Ui => "ui",
RustdocJs => "rustdoc-js",
MirOpt => "mir-opt",
Assembly => "assembly",
CoverageMap => "coverage-map",
CoverageRun => "coverage-run",
Crashes => "crashes",
}
}
impl TestMode {
pub(crate) fn aux_dir_disambiguator(self) -> &'static str {
// Pretty-printing tests could run concurrently, and if they do,
// they need to keep their output segregated.
match self {
TestMode::Pretty => ".pretty",
_ => "",
}
}
pub(crate) fn output_dir_disambiguator(self) -> &'static str {
// Coverage tests use the same test files for multiple test modes,
// so each mode should have a separate output directory.
match self {
TestMode::CoverageMap | TestMode::CoverageRun => self.to_str(),
_ => "",
}
}
}
// Note that coverage tests use the same test files for multiple test modes.
string_enum! {
#[derive(Clone, Copy, PartialEq, Debug)]
pub(crate) enum TestSuite {
AssemblyLlvm => "assembly-llvm",
CodegenLlvm => "codegen-llvm",
CodegenUnits => "codegen-units",
Coverage => "coverage",
CoverageRunRustdoc => "coverage-run-rustdoc",
Crashes => "crashes",
Debuginfo => "debuginfo",
Incremental => "incremental",
MirOpt => "mir-opt",
Pretty => "pretty",
RunMake => "run-make",
RunMakeCargo => "run-make-cargo",
RustdocHtml => "rustdoc-html",
RustdocGui => "rustdoc-gui",
RustdocJs => "rustdoc-js",
RustdocJsStd=> "rustdoc-js-std",
RustdocJson => "rustdoc-json",
RustdocUi => "rustdoc-ui",
Ui => "ui",
UiFullDeps => "ui-fulldeps",
BuildStd => "build-std",
}
}
string_enum! {
#[derive(Clone, Copy, PartialEq, Debug, Hash)]
pub(crate) enum PassMode {
Check => "check",
Build => "build",
Run => "run",
}
}
string_enum! {
#[derive(Clone, Copy, PartialEq, Debug, Hash)]
pub(crate) enum RunResult {
Pass => "run-pass",
Fail => "run-fail",
Crash => "run-crash",
}
}
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
pub(crate) enum RunFailMode {
/// Running the program must make it exit with a regular failure exit code
/// in the range `1..=127`. If the program is terminated by e.g. a signal
/// the test will fail.
Fail,
/// Running the program must result in a crash, e.g. by `SIGABRT` or
/// `SIGSEGV` on Unix or on Windows by having an appropriate NTSTATUS high
/// bit in the exit code.
Crash,
/// Running the program must either fail or crash. Useful for e.g. sanitizer
/// tests since some sanitizer implementations exit the process with code 1
/// to in the face of memory errors while others abort (crash) the process
/// in the face of memory errors.
FailOrCrash,
}
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
pub(crate) enum FailMode {
Check,
Build,
Run(RunFailMode),
}
string_enum! {
#[derive(Clone, Debug, PartialEq)]
pub(crate) enum CompareMode {
Polonius => "polonius",
NextSolver => "next-solver",
NextSolverCoherence => "next-solver-coherence",
SplitDwarf => "split-dwarf",
SplitDwarfSingle => "split-dwarf-single",
}
}
string_enum! {
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) enum Debugger {
Cdb => "cdb",
Gdb => "gdb",
Lldb => "lldb",
}
}
#[derive(Clone, Copy, Debug, PartialEq, Default, serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
pub(crate) enum PanicStrategy {
#[default]
Unwind,
Abort,
}
impl PanicStrategy {
pub(crate) fn for_miropt_test_tools(&self) -> miropt_test_tools::PanicStrategy {
match self {
PanicStrategy::Unwind => miropt_test_tools::PanicStrategy::Unwind,
PanicStrategy::Abort => miropt_test_tools::PanicStrategy::Abort,
}
}
}
#[derive(Clone, Debug, PartialEq, serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
pub(crate) enum Sanitizer {
Address,
Cfi,
Dataflow,
Kcfi,
KernelAddress,
KernelHwaddress,
Leak,
Memory,
Memtag,
Safestack,
ShadowCallStack,
Thread,
Hwaddress,
Realtime,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) enum CodegenBackend {
Cranelift,
Gcc,
Llvm,
}
impl<'a> TryFrom<&'a str> for CodegenBackend {
type Error = &'static str;
fn try_from(value: &'a str) -> Result<Self, Self::Error> {
match value.to_lowercase().as_str() {
"cranelift" => Ok(Self::Cranelift),
"gcc" => Ok(Self::Gcc),
"llvm" => Ok(Self::Llvm),
_ => Err("unknown backend"),
}
}
}
impl CodegenBackend {
pub(crate) fn as_str(self) -> &'static str {
match self {
Self::Cranelift => "cranelift",
Self::Gcc => "gcc",
Self::Llvm => "llvm",
}
}
pub(crate) fn is_llvm(self) -> bool {
matches!(self, Self::Llvm)
}
}
/// Configuration for `compiletest` *per invocation*.
///
/// In terms of `bootstrap`, this means that `./x test tests/ui tests/run-make` actually correspond
/// to *two* separate invocations of `compiletest`.
///
/// FIXME: this `Config` struct should be broken up into smaller logically contained sub-config
/// structs, it's too much of a "soup" of everything at the moment.
///
/// # Configuration sources
///
/// Configuration values for `compiletest` comes from several sources:
///
/// - CLI args passed from `bootstrap` while running the `compiletest` binary.
/// - Env vars.
/// - Discovery (e.g. trying to identify a suitable debugger based on filesystem discovery).
/// - Cached output of running the `rustc` under test (e.g. output of `rustc` print requests).
///
/// FIXME: make sure we *clearly* account for sources of *all* config options.
///
/// FIXME: audit these options to make sure we are not hashing less than necessary for build stamp
/// (for changed test detection).
#[derive(Debug, Clone)]
pub struct Config {
/// Some [`TestMode`]s support [snapshot testing], where a *reference snapshot* of outputs (of
/// `stdout`, `stderr`, or other form of artifacts) can be compared to the *actual output*.
///
/// This option can be set to `true` to update the *reference snapshots* in-place, otherwise
/// `compiletest` will only try to compare.
///
/// [snapshot testing]: https://jestjs.io/docs/snapshot-testing
pub(crate) bless: bool,
/// Attempt to stop as soon as possible after any test fails. We may still run a few more tests
/// before stopping when multiple test threads are used.
pub(crate) fail_fast: bool,
/// Path to libraries needed to run the *staged* `rustc`-under-test on the **host** platform.
///
/// For example:
/// - `/home/ferris/rust/build/x86_64-unknown-linux-gnu/stage1/bin/lib`
pub(crate) host_compile_lib_path: Utf8PathBuf,
/// Path to libraries needed to run the compiled executable for the **target** platform. This
/// corresponds to the **target** sysroot libraries, including the **target** standard library.
///
/// For example:
/// - `/home/ferris/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/i686-unknown-linux-gnu/lib`
///
/// FIXME: this is very under-documented in conjunction with the `remote-test-client` scheme and
/// `RUNNER` scheme to actually run the target executable under the target platform environment,
/// cf. [`Self::remote_test_client`] and [`Self::runner`].
pub(crate) target_run_lib_path: Utf8PathBuf,
/// Path to the `rustc`-under-test.
///
/// For `ui-fulldeps` test suite specifically:
///
/// - This is the **stage 0** compiler when testing `ui-fulldeps` under `--stage=1`.
/// - This is the **stage 2** compiler when testing `ui-fulldeps` under `--stage=2`.
///
/// See [`Self::query_rustc_path`] for the `--stage=1` `ui-fulldeps` scenario where a separate
/// in-tree `rustc` is used for querying target information.
///
/// For example:
/// - `/home/ferris/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc`
///
/// # Note on forced stage0
///
/// It is possible for this `rustc` to be a stage 0 `rustc` if explicitly configured with the
/// bootstrap option `build.compiletest-allow-stage0=true` and specifying `--stage=0`.
pub(crate) rustc_path: Utf8PathBuf,
/// Path to a *staged* **host** platform cargo executable (unless stage 0 is forced). This
/// staged `cargo` is only used within `run-make` test recipes during recipe run time (and is
/// *not* used to compile the test recipes), and so must be staged as there may be differences
/// between e.g. beta `cargo` vs in-tree `cargo`.
///
/// For example:
/// - `/home/ferris/rust/build/x86_64-unknown-linux-gnu/stage1-tools-bin/cargo`
///
/// FIXME: maybe rename this to reflect that this is a *staged* host cargo.
pub(crate) cargo_path: Option<Utf8PathBuf>,
/// Path to the stage 0 `rustc` used to build `run-make` recipes. This must not be confused with
/// [`Self::rustc_path`].
///
/// For example:
/// - `/home/ferris/rust/build/x86_64-unknown-linux-gnu/stage0/bin/rustc`
pub(crate) stage0_rustc_path: Option<Utf8PathBuf>,
/// Path to the stage 1 or higher `rustc` used to obtain target information via
/// `--print=all-target-specs-json` and similar queries.
///
/// Normally this is unset, because [`Self::rustc_path`] can be used instead.
/// But when running "stage 1" ui-fulldeps tests, `rustc_path` is a stage 0
/// compiler, whereas target specs must be obtained from a stage 1+ compiler
/// (in case the JSON format has changed since the last bootstrap bump).
pub(crate) query_rustc_path: Option<Utf8PathBuf>,
/// Path to the `rustdoc`-under-test. Like [`Self::rustc_path`], this `rustdoc` is *staged*.
pub(crate) rustdoc_path: Option<Utf8PathBuf>,
/// Path to the `src/tools/coverage-dump/` bootstrap tool executable.
pub(crate) coverage_dump_path: Option<Utf8PathBuf>,
/// Path to the Python 3 executable to use for htmldocck and some run-make tests.
pub(crate) python: String,
/// Path to the `src/tools/jsondocck/` bootstrap tool executable.
pub(crate) jsondocck_path: Option<Utf8PathBuf>,
/// Path to the `src/tools/jsondoclint/` bootstrap tool executable.
pub(crate) jsondoclint_path: Option<Utf8PathBuf>,
/// Path to a host LLVM `FileCheck` executable.
pub(crate) llvm_filecheck: Option<Utf8PathBuf>,
/// Path to a host LLVM bintools directory.
///
/// For example:
/// - `/home/ferris/rust/build/x86_64-unknown-linux-gnu/llvm/bin`
pub(crate) llvm_bin_dir: Option<Utf8PathBuf>,
/// The path to the **target** `clang` executable to run `clang`-based tests with. If `None`,
/// then these tests will be ignored.
pub(crate) run_clang_based_tests_with: Option<Utf8PathBuf>,
/// Path to the directory containing the sources. This corresponds to the root folder of a
/// `rust-lang/rust` checkout.
///
/// For example:
/// - `/home/ferris/rust`
///
/// FIXME: this name is confusing, because this is actually `$checkout_root`, **not** the
/// `$checkout_root/src/` folder.
pub(crate) src_root: Utf8PathBuf,
/// Absolute path to the test suite directory.
///
/// For example:
/// - `/home/ferris/rust/tests/ui`
/// - `/home/ferris/rust/tests/coverage`
pub(crate) src_test_suite_root: Utf8PathBuf,
/// Path to the top-level build directory used by bootstrap.
///
/// For example:
/// - `/home/ferris/rust/build`
pub(crate) build_root: Utf8PathBuf,
/// Path to the build directory used by the current test suite.
///
/// For example:
/// - `/home/ferris/rust/build/x86_64-unknown-linux-gnu/test/ui`
/// - `/home/ferris/rust/build/x86_64-unknown-linux-gnu/test/coverage`
pub(crate) build_test_suite_root: Utf8PathBuf,
/// Path to the directory containing the sysroot of the `rustc`-under-test.
///
/// For example:
/// - `/home/ferris/rust/build/x86_64-unknown-linux-gnu/stage1`
/// - `/home/ferris/rust/build/x86_64-unknown-linux-gnu/stage2`
///
/// When stage 0 is forced, this will correspond to the sysroot *of* that specified stage 0
/// `rustc`.
///
/// FIXME: this name is confusing, because it doesn't specify *which* compiler this sysroot
/// corresponds to. It's actually the `rustc`-under-test, and not the bootstrap `rustc`, unless
/// stage 0 is forced and no custom stage 0 `rustc` was otherwise specified (so that it
/// *happens* to run against the bootstrap `rustc`, but this non-custom bootstrap `rustc` case
/// is not really supported).
pub(crate) sysroot_base: Utf8PathBuf,
/// The number of the stage under test.
pub(crate) stage: u32,
/// The id of the stage under test (stage1-xxx, etc).
///
/// FIXME: reconsider this string; this is hashed for test build stamp.
pub(crate) stage_id: String,
/// The [`TestMode`]. E.g. [`TestMode::Ui`]. Each test mode can correspond to one or more test
/// suites.
///
/// FIXME: stop using stringly-typed test suites!
pub(crate) mode: TestMode,
/// The test suite.
///
/// Example: `tests/ui/` is [`TestSuite::Ui`] test *suite*, which happens to also be of the
/// [`TestMode::Ui`] test *mode*.
///
/// Note that the same test suite (e.g. `tests/coverage/`) may correspond to multiple test
/// modes, e.g. `tests/coverage/` can be run under both [`TestMode::CoverageRun`] and
/// [`TestMode::CoverageMap`].
pub(crate) suite: TestSuite,
/// When specified, **only** the specified [`Debugger`] will be used to run against the
/// `tests/debuginfo` test suite. When unspecified, `compiletest` will attempt to find all three
/// of {`lldb`, `cdb`, `gdb`} implicitly, and then try to run the `debuginfo` test suite against
/// all three debuggers.
///
/// FIXME: this implicit behavior is really nasty, in that it makes it hard for the user to
/// control *which* debugger(s) are available and used to run the debuginfo test suite. We
/// should have `bootstrap` allow the user to *explicitly* configure the debuggers, and *not*
/// try to implicitly discover some random debugger from the user environment. This makes the
/// debuginfo test suite particularly hard to work with.
pub(crate) debugger: Option<Debugger>,
/// Run ignored tests *unconditionally*, overriding their ignore reason.
///
/// FIXME: this is wired up through the test execution logic, but **not** accessible from
/// `bootstrap` directly; `compiletest` exposes this as `--ignored`. I.e. you'd have to use `./x
/// test $test_suite -- --ignored=true`.
pub(crate) run_ignored: bool,
/// Whether *staged* `rustc`-under-test was built with debug assertions.
///
/// FIXME: make it clearer that this refers to the staged `rustc`-under-test, not stage 0
/// `rustc`.
pub(crate) with_rustc_debug_assertions: bool,
/// Whether *staged* `std` was built with debug assertions.
///
/// FIXME: make it clearer that this refers to the staged `std`, not stage 0 `std`.
pub(crate) with_std_debug_assertions: bool,
/// Whether *staged* `std` was built with remapping of debuginfo.
///
/// FIXME: make it clearer that this refers to the staged `std`, not stage 0 `std`.
pub(crate) with_std_remap_debuginfo: bool,
/// Only run tests that match these filters (using `libtest` "test name contains" filter logic).
///
/// FIXME(#139660): the current hand-rolled test executor intentionally mimics the `libtest`
/// "test name contains" filter matching logic to preserve previous `libtest` executor behavior,
/// but this is often not intuitive. We should consider changing that behavior with an MCP to do
/// test path *prefix* matching which better corresponds to how `compiletest` `tests/` are
/// organized, and how users would intuitively expect the filtering logic to work like.
pub(crate) filters: Vec<String>,
/// Skip tests matching these substrings. The matching logic exactly corresponds to
/// [`Self::filters`] but inverted.
///
/// FIXME(#139660): ditto on test matching behavior.
pub(crate) skip: Vec<String>,
/// Exactly match the filter, rather than a substring.
///
/// FIXME(#139660): ditto on test matching behavior.
pub(crate) filter_exact: bool,
/// Force the pass mode of a check/build/run test to instead use this mode instead.
///
/// FIXME: make it even more obvious (especially in PR CI where `--pass=check` is used) when a
/// pass mode is forced when the test fails, because it can be very non-obvious when e.g. an
/// error is emitted only when `//@ build-pass` but not `//@ check-pass`.
pub(crate) force_pass_mode: Option<PassMode>,
/// Explicitly enable or disable running of the target test binary.
///
/// FIXME: this scheme is a bit confusing, and at times questionable. Re-evaluate this run
/// scheme.
///
/// FIXME: Currently `--run` is a tri-state, it can be `--run={auto,always,never}`, and when
/// `--run=auto` is specified, it's run if the platform doesn't end with `-fuchsia`. See
/// [`Config::run_enabled`].
pub(crate) run: Option<bool>,
/// A command line to prefix target program execution with, for running under valgrind for
/// example, i.e. `$runner target.exe [args..]`. Similar to `CARGO_*_RUNNER` configuration.
///
/// Note: this is not to be confused with [`Self::remote_test_client`], which is a different
/// scheme.
///
/// FIXME: the runner scheme is very under-documented.
pub(crate) runner: Option<String>,
/// Compiler flags to pass to the *staged* `rustc`-under-test when building for the **host**
/// platform.
pub(crate) host_rustcflags: Vec<String>,
/// Compiler flags to pass to the *staged* `rustc`-under-test when building for the **target**
/// platform.
pub(crate) target_rustcflags: Vec<String>,
/// Whether the *staged* `rustc`-under-test and the associated *staged* `std` has been built
/// with randomized struct layouts.
pub(crate) rust_randomized_layout: bool,
/// Whether tests should be optimized by default (`-O`). Individual test suites and test files
/// may override this setting.
///
/// FIXME: this flag / config option is somewhat misleading. For instance, in ui tests, it's
/// *only* applied to the [`PassMode::Run`] test crate and not its auxiliaries.
pub(crate) optimize_tests: bool,
/// Target platform tuple.
pub(crate) target: String,
/// Host platform tuple.
pub(crate) host: String,
/// Path to / name of the Microsoft Console Debugger (CDB) executable.
///
/// FIXME: this is an *opt-in* "override" option. When this isn't provided, we try to conjure a
/// cdb by looking at the user's program files on Windows... See `debuggers::find_cdb`.
pub(crate) cdb: Option<Utf8PathBuf>,
/// Version of CDB.
///
/// FIXME: `cdb_version` is *derived* from cdb, but it's *not* technically a config!
///
/// FIXME: audit cdb version gating.
pub(crate) cdb_version: Option<[u16; 4]>,
/// Path to / name of the GDB executable.
///
/// FIXME: the fallback path when `gdb` isn't provided tries to find *a* `gdb` or `gdb.exe` from
/// `PATH`, which is... arguably questionable.
///
/// FIXME: we are propagating a python from `PYTHONPATH`, not from an explicit config for gdb
/// debugger script.
pub(crate) gdb: Option<Utf8PathBuf>,
/// Version of GDB, encoded as ((major * 1000) + minor) * 1000 + patch
///
/// FIXME: this gdb version gating scheme is possibly questionable -- gdb does not use semver,
/// only its major version is likely materially meaningful, cf.
/// <https://sourceware.org/gdb/wiki/Internals%20Versions>. Even the major version I'm not sure
/// is super meaningful. Maybe min gdb `major.minor` version gating is sufficient for the
/// purposes of debuginfo tests?
///
/// FIXME: `gdb_version` is *derived* from gdb, but it's *not* technically a config!
pub(crate) gdb_version: Option<u32>,
/// Path to or name of the LLDB executable to use for debuginfo tests.
pub(crate) lldb: Option<Utf8PathBuf>,
/// Version of LLDB.
///
/// FIXME: `lldb_version` is *derived* from lldb, but it's *not* technically a config!
pub(crate) lldb_version: Option<u32>,
/// Version of LLVM.
///
/// FIXME: Audit the fallback derivation of
/// [`crate::directives::extract_llvm_version_from_binary`], that seems very questionable?
pub(crate) llvm_version: Option<Version>,
/// Is LLVM a system LLVM.
pub(crate) system_llvm: bool,
/// Path to the android tools.
///
/// Note: this is only used for android gdb debugger script in the debuginfo test suite.
///
/// FIXME: take a look at this; this is piggy-backing off of gdb code paths but only for
/// `arm-linux-androideabi` target.
pub(crate) android_cross_path: Option<Utf8PathBuf>,
/// Extra parameter to run adb on `arm-linux-androideabi`.
///
/// FIXME: is this *only* `arm-linux-androideabi`, or is it also for other Tier 2/3 android
/// targets?
///
/// FIXME: take a look at this; this is piggy-backing off of gdb code paths but only for
/// `arm-linux-androideabi` target.
pub(crate) adb_path: Option<Utf8PathBuf>,
/// Extra parameter to run test suite on `arm-linux-androideabi`.
///
/// FIXME: is this *only* `arm-linux-androideabi`, or is it also for other Tier 2/3 android
/// targets?
///
/// FIXME: take a look at this; this is piggy-backing off of gdb code paths but only for
/// `arm-linux-androideabi` target.
pub(crate) adb_test_dir: Option<Utf8PathBuf>,
/// Status whether android device available or not. When unavailable, this will cause tests to
/// panic when the test binary is attempted to be run.
///
/// FIXME: take a look at this; this also influences adb in gdb code paths in a strange way.
pub(crate) adb_device_status: bool,
/// Verbose dump a lot of info.
///
/// FIXME: this is *way* too coarse; the user can't select *which* info to verbosely dump.
pub(crate) verbose: bool,
/// Where to find the remote test client process, if we're using it.
///
/// Note: this is *only* used for target platform executables created by `run-make` test
/// recipes.
///
/// Note: this is not to be confused with [`Self::runner`], which is a different scheme.
///
/// FIXME: the `remote_test_client` scheme is very under-documented.
pub(crate) remote_test_client: Option<Utf8PathBuf>,
/// [`CompareMode`] describing what file the actual ui output will be compared to.
///
/// FIXME: currently, [`CompareMode`] is a mishmash of lot of things (different borrow-checker
/// model, different trait solver, different debugger, etc.).
pub(crate) compare_mode: Option<CompareMode>,
/// If true, this will generate a coverage file with UI test files that run `MachineApplicable`
/// diagnostics but are missing `run-rustfix` annotations. The generated coverage file is
/// created in `$test_suite_build_root/rustfix_missing_coverage.txt`
pub(crate) rustfix_coverage: bool,
/// Whether to run `enzyme` autodiff tests.
pub(crate) has_enzyme: bool,
/// Whether to run `offload` autodiff tests.
pub(crate) has_offload: bool,
/// The current Rust channel info.
///
/// FIXME: treat this more carefully; "stable", "beta" and "nightly" are definitely valid, but
/// channel might also be "dev" or such, which should be treated as "nightly".
pub(crate) channel: String,
/// Whether adding git commit information such as the commit hash has been enabled for building.
///
/// FIXME: `compiletest` cannot trust `bootstrap` for this information, because `bootstrap` can
/// have bugs and had bugs on that logic. We need to figure out how to obtain this e.g. directly
/// from CI or via git locally.
pub(crate) git_hash: bool,
/// The default Rust edition.
pub(crate) edition: Option<Edition>,
// Configuration for various run-make tests frobbing things like C compilers or querying about
// various LLVM component information.
//
// FIXME: this really should be better packaged together.
// FIXME: these need better docs, e.g. for *host*, or for *target*?
pub(crate) cc: String,
pub(crate) cxx: String,
pub(crate) cflags: String,
pub(crate) cxxflags: String,
pub(crate) ar: String,
pub(crate) target_linker: Option<String>,
pub(crate) host_linker: Option<String>,
pub(crate) llvm_components: String,
/// Path to a NodeJS executable. Used for JS doctests, emscripten and WASM tests.
pub(crate) nodejs: Option<Utf8PathBuf>,
/// Whether to rerun tests even if the inputs are unchanged.
pub(crate) force_rerun: bool,
/// Only rerun the tests that result has been modified according to `git status`.
///
/// FIXME: this is undocumented.
///
/// FIXME: how does this interact with [`Self::force_rerun`]?
pub(crate) only_modified: bool,
// FIXME: these are really not "config"s, but rather are information derived from
// `rustc`-under-test. This poses an interesting conundrum: if we're testing the
// `rustc`-under-test, can we trust its print request outputs and target cfgs? In theory, this
// itself can break or be unreliable -- ideally, we'd be sharing these kind of information not
// through `rustc`-under-test's execution output. In practice, however, print requests are very
// unlikely to completely break (we also have snapshot ui tests for them). Furthermore, even if
// we share them via some kind of static config, that static config can still be wrong! Who
// tests the tester? Therefore, we make a pragmatic compromise here, and use information derived
// from print requests produced by the `rustc`-under-test.
//
// FIXME: move them out from `Config`, because they are *not* configs.
pub(crate) target_cfgs: OnceLock<TargetCfgs>,
pub(crate) builtin_cfg_names: OnceLock<HashSet<String>>,
pub(crate) supported_crate_types: OnceLock<HashSet<String>>,
/// Should we capture console output that would be printed by test runners via their `stdout`
/// and `stderr` trait objects, or via the custom panic hook.
///
/// The default is `true`. This can be disabled via the compiletest cli flag `--no-capture`
/// (which mirrors the libtest `--no-capture` flag).
pub(crate) capture: bool,
/// Needed both to construct [`build_helper::git::GitConfig`].
pub(crate) nightly_branch: String,
pub(crate) git_merge_commit_email: String,
/// True if the profiler runtime is enabled for this target. Used by the
/// `needs-profiler-runtime` directive in test files.
pub(crate) profiler_runtime: bool,
/// Command for visual diff display, e.g. `diff-tool --color=always`.
pub(crate) diff_command: Option<String>,
/// Path to minicore aux library (`tests/auxiliary/minicore.rs`), used for `no_core` tests that
/// need `core` stubs in cross-compilation scenarios that do not otherwise want/need to
/// `-Zbuild-std`. Used in e.g. ABI tests.
pub(crate) minicore_path: Utf8PathBuf,
/// Current codegen backend used.
pub(crate) default_codegen_backend: CodegenBackend,
/// Name/path of the backend to use instead of `default_codegen_backend`.
pub(crate) override_codegen_backend: Option<String>,
/// Whether to ignore `//@ ignore-backends`.
pub(crate) bypass_ignore_backends: bool,
/// Number of parallel jobs configured for the build.
///
/// This is forwarded from bootstrap's `jobs` configuration.
pub(crate) jobs: u32,
/// Number of parallel threads to use for the frontend when building test artifacts.
pub(crate) parallel_frontend_threads: u32,
/// Number of times to execute each test.
pub(crate) iteration_count: u32,
}
impl Config {
pub(crate) const DEFAULT_PARALLEL_FRONTEND_THREADS: u32 = 1;
pub(crate) const DEFAULT_ITERATION_COUNT: u32 = 1;
/// FIXME: this run scheme is... confusing.
pub(crate) fn run_enabled(&self) -> bool {
self.run.unwrap_or_else(|| {
// Auto-detect whether to run based on the platform.
!self.target.ends_with("-fuchsia")
})
}
pub(crate) fn target_cfgs(&self) -> &TargetCfgs {
self.target_cfgs.get_or_init(|| TargetCfgs::new(self))
}
pub(crate) fn target_cfg(&self) -> &TargetCfg {
&self.target_cfgs().current
}
pub(crate) fn matches_arch(&self, arch: &str) -> bool {
self.target_cfg().arch == arch
|| {
// Matching all the thumb variants as one can be convenient.
// (thumbv6m, thumbv7em, thumbv7m, etc.)
arch == "thumb" && self.target.starts_with("thumb")
}
|| (arch == "i586" && self.target.starts_with("i586-"))
}
pub(crate) fn matches_os(&self, os: &str) -> bool {
self.target_cfg().os == os
}
pub(crate) fn matches_env(&self, env: &str) -> bool {
self.target_cfg().env == env
}
pub(crate) fn matches_abi(&self, abi: &str) -> bool {
self.target_cfg().abi == abi
}
#[cfg_attr(not(test), expect(dead_code, reason = "only used by tests for `ignore-{family}`"))]
pub(crate) fn matches_family(&self, family: &str) -> bool {
self.target_cfg().families.iter().any(|f| f == family)
}
pub(crate) fn is_big_endian(&self) -> bool {
self.target_cfg().endian == Endian::Big
}
pub(crate) fn get_pointer_width(&self) -> u32 {
*&self.target_cfg().pointer_width
}
pub(crate) fn can_unwind(&self) -> bool {
self.target_cfg().panic == PanicStrategy::Unwind
}
/// Get the list of builtin, 'well known' cfg names
pub(crate) fn builtin_cfg_names(&self) -> &HashSet<String> {
self.builtin_cfg_names.get_or_init(|| builtin_cfg_names(self))
}
/// Get the list of crate types that the target platform supports.
pub(crate) fn supported_crate_types(&self) -> &HashSet<String> {
self.supported_crate_types.get_or_init(|| supported_crate_types(self))
}
pub(crate) fn has_threads(&self) -> bool {
// Wasm targets don't have threads unless `-threads` is in the target
// name, such as `wasm32-wasip1-threads`.
if self.target.starts_with("wasm") {
return self.target.contains("threads");
}
true
}
pub(crate) fn has_asm_support(&self) -> bool {
// This should match the stable list in `LoweringContext::lower_inline_asm`.
static ASM_SUPPORTED_ARCHS: &[&str] = &[
"x86",
"x86_64",
"arm",
"aarch64",
"arm64ec",
"riscv32",
"riscv64",
"loongarch32",
"loongarch64",
"s390x",
// These targets require an additional asm_experimental_arch feature.
// "nvptx64", "hexagon", "mips", "mips64", "spirv", "wasm32",
];
ASM_SUPPORTED_ARCHS.contains(&self.target_cfg().arch.as_str())
}
pub(crate) fn git_config(&self) -> GitConfig<'_> {
GitConfig {
nightly_branch: &self.nightly_branch,
git_merge_commit_email: &self.git_merge_commit_email,
}
}
pub(crate) fn has_subprocess_support(&self) -> bool {
// FIXME(#135928): compiletest is always a **host** tool. Building and running an
// capability detection executable against the **target** is not trivial. The short term
// solution here is to hard-code some targets to allow/deny, unfortunately.
let unsupported_target = self.target_cfg().env == "sgx"
|| matches!(self.target_cfg().arch.as_str(), "wasm32" | "wasm64")
|| self.target_cfg().os == "emscripten";
!unsupported_target
}
/// Whether the parallel frontend is enabled,
/// which is the case when `parallel_frontend_threads` is not set to `1`.
///
/// - `0` means auto-detect: use the number of available hardware threads on the host.
/// But we treat it as the parallel frontend being enabled in this case.
/// - `1` means single-threaded (parallel frontend disabled).
/// - `>1` means an explicitly configured thread count.
pub(crate) fn parallel_frontend_enabled(&self) -> bool {
self.parallel_frontend_threads != 1
}
}
/// Known widths of `target_has_atomic`.
pub(crate) const KNOWN_TARGET_HAS_ATOMIC_WIDTHS: &[&str] = &["8", "16", "32", "64", "128", "ptr"];
#[derive(Debug, Clone)]
pub(crate) struct TargetCfgs {
pub(crate) current: TargetCfg,
pub(crate) all_targets: HashSet<String>,
pub(crate) all_archs: HashSet<String>,
pub(crate) all_oses: HashSet<String>,
pub(crate) all_oses_and_envs: HashSet<String>,
pub(crate) all_envs: HashSet<String>,
pub(crate) all_abis: HashSet<String>,
pub(crate) all_families: HashSet<String>,
pub(crate) all_pointer_widths: HashSet<String>,
pub(crate) all_rustc_abis: HashSet<String>,
}
impl TargetCfgs {
fn new(config: &Config) -> TargetCfgs {
let mut targets: HashMap<String, TargetCfg> = serde_json::from_str(&query_rustc_output(
config,
&["--print=all-target-specs-json", "-Zunstable-options"],
Default::default(),
))
.unwrap();
let mut all_targets = HashSet::new();
let mut all_archs = HashSet::new();
let mut all_oses = HashSet::new();
let mut all_oses_and_envs = HashSet::new();
let mut all_envs = HashSet::new();
let mut all_abis = HashSet::new();
let mut all_families = HashSet::new();
let mut all_pointer_widths = HashSet::new();
// NOTE: for distinction between `abi` and `rustc_abi`, see comment on
// `TargetCfg::rustc_abi`.
let mut all_rustc_abis = HashSet::new();
// If current target is not included in the `--print=all-target-specs-json` output,
// we check whether it is a custom target from the user or a synthetic target from bootstrap.
if !targets.contains_key(&config.target) {
let mut envs: HashMap<String, String> = HashMap::new();
if let Ok(t) = std::env::var("RUST_TARGET_PATH") {
envs.insert("RUST_TARGET_PATH".into(), t);
}
// This returns false only when the target is neither a synthetic target
// nor a custom target from the user, indicating it is most likely invalid.
if config.target.ends_with(".json") || !envs.is_empty() {
targets.insert(
config.target.clone(),
serde_json::from_str(&query_rustc_output(
config,
&[
"--print=target-spec-json",
"-Zunstable-options",
"--target",
&config.target,
],
envs,
))
.unwrap(),
);
}
}
for (target, cfg) in targets.iter() {
all_archs.insert(cfg.arch.clone());
all_oses.insert(cfg.os.clone());
all_oses_and_envs.insert(cfg.os_and_env());
all_envs.insert(cfg.env.clone());
all_abis.insert(cfg.abi.clone());
for family in &cfg.families {
all_families.insert(family.clone());
}
all_pointer_widths.insert(format!("{}bit", cfg.pointer_width));
if let Some(rustc_abi) = &cfg.rustc_abi {
all_rustc_abis.insert(rustc_abi.clone());
}
all_targets.insert(target.clone());
}
Self {
current: Self::get_current_target_config(config, &targets),
all_targets,
all_archs,
all_oses,
all_oses_and_envs,
all_envs,
all_abis,
all_families,
all_pointer_widths,
all_rustc_abis,
}
}
fn get_current_target_config(
config: &Config,
targets: &HashMap<String, TargetCfg>,
) -> TargetCfg {
let mut cfg = targets[&config.target].clone();
// To get the target information for the current target, we take the target spec obtained
// from `--print=all-target-specs-json`, and then we enrich it with the information
// gathered from `--print=cfg --target=$target`.
//
// This is done because some parts of the target spec can be overridden with `-C` flags,
// which are respected for `--print=cfg` but not for `--print=all-target-specs-json`. The
// code below extracts them from `--print=cfg`: make sure to only override fields that can
// actually be changed with `-C` flags.
for config in query_rustc_output(
config,
// `-Zunstable-options` is necessary when compiletest is running with custom targets
// (such as synthetic targets used to bless mir-opt tests).
&["-Zunstable-options", "--print=cfg", "--target", &config.target],
Default::default(),
)
.trim()
.lines()
{
let (name, value) = config
.split_once("=\"")
.map(|(name, value)| {
(
name,
Some(
value
.strip_suffix('\"')
.expect("key-value pair should be properly quoted"),
),
)
})
.unwrap_or_else(|| (config, None));
match (name, value) {
// Can be overridden with `-C panic=$strategy`.
("panic", Some("abort")) => cfg.panic = PanicStrategy::Abort,
("panic", Some("unwind")) => cfg.panic = PanicStrategy::Unwind,
("panic", other) => panic!("unexpected value for panic cfg: {other:?}"),
("target_has_atomic", Some(width))