Skip to content

Commit b885407

Browse files
committed
add new field forced_compiler to Compiler
Signed-off-by: onur-ozkan <[email protected]>
1 parent fd17dea commit b885407

File tree

4 files changed

+97
-75
lines changed

4 files changed

+97
-75
lines changed

Diff for: src/bootstrap/src/core/build_steps/dist.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2112,8 +2112,7 @@ pub fn maybe_install_llvm_target(builder: &Builder<'_>, target: TargetSelection,
21122112
),
21132113
)]
21142114
pub fn maybe_install_llvm_runtime(builder: &Builder<'_>, target: TargetSelection, sysroot: &Path) {
2115-
let dst_libdir =
2116-
sysroot.join(builder.sysroot_libdir_relative(Compiler { stage: 1, host: target }));
2115+
let dst_libdir = sysroot.join(builder.sysroot_libdir_relative(Compiler::new(1, target)));
21172116
// We do not need to copy LLVM files into the sysroot if it is not
21182117
// dynamically linked; it is already included into librustc_llvm
21192118
// statically.

Diff for: src/bootstrap/src/core/builder/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ impl<'a> Builder<'a> {
12341234
),
12351235
)]
12361236
pub fn compiler(&self, stage: u32, host: TargetSelection) -> Compiler {
1237-
self.ensure(compile::Assemble { target_compiler: Compiler { stage, host } })
1237+
self.ensure(compile::Assemble { target_compiler: Compiler::new(stage, host) })
12381238
}
12391239

12401240
/// Similar to `compiler`, except handles the full-bootstrap option to
@@ -1272,7 +1272,7 @@ impl<'a> Builder<'a> {
12721272
target: TargetSelection,
12731273
) -> Compiler {
12741274
#![allow(clippy::let_and_return)]
1275-
let resolved_compiler = if self.build.force_use_stage2(stage) {
1275+
let mut resolved_compiler = if self.build.force_use_stage2(stage) {
12761276
trace!(target: "COMPILER_FOR", ?stage, "force_use_stage2");
12771277
self.compiler(2, self.config.build)
12781278
} else if self.build.force_use_stage1(stage, target) {
@@ -1282,6 +1282,11 @@ impl<'a> Builder<'a> {
12821282
trace!(target: "COMPILER_FOR", ?stage, ?host, "no force, fallback to `compiler()`");
12831283
self.compiler(stage, host)
12841284
};
1285+
1286+
if stage != resolved_compiler.stage {
1287+
resolved_compiler.forced_compiler(true);
1288+
}
1289+
12851290
trace!(target: "COMPILER_FOR", ?resolved_compiler);
12861291
resolved_compiler
12871292
}

Diff for: src/bootstrap/src/core/builder/tests.rs

+58-70
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn check_cli<const N: usize>(paths: [&str; N]) {
7171
macro_rules! std {
7272
($host:ident => $target:ident, stage = $stage:literal) => {
7373
compile::Std::new(
74-
Compiler { host: TargetSelection::from_user($host), stage: $stage },
74+
Compiler::new($stage, TargetSelection::from_user($host)),
7575
TargetSelection::from_user($target),
7676
)
7777
};
@@ -84,7 +84,7 @@ macro_rules! doc_std {
8484
macro_rules! rustc {
8585
($host:ident => $target:ident, stage = $stage:literal) => {
8686
compile::Rustc::new(
87-
Compiler { host: TargetSelection::from_user($host), stage: $stage },
87+
Compiler::new($stage, TargetSelection::from_user($host)),
8888
TargetSelection::from_user($target),
8989
)
9090
};
@@ -296,7 +296,7 @@ mod defaults {
296296
first(cache.all::<tool::Rustdoc>()),
297297
// Recall that rustdoc stages are off-by-one
298298
// - this is the compiler it's _linked_ to, not built with.
299-
&[tool::Rustdoc { compiler: Compiler { host: a, stage: 1 } }],
299+
&[tool::Rustdoc { compiler: Compiler::new(1, a) }],
300300
);
301301
assert_eq!(
302302
first(cache.all::<compile::Rustc>()),
@@ -319,7 +319,7 @@ mod defaults {
319319
first(cache.all::<tool::Rustdoc>()),
320320
// This is the beta rustdoc.
321321
// Add an assert here to make sure this is the only rustdoc built.
322-
&[tool::Rustdoc { compiler: Compiler { host: a, stage: 0 } }],
322+
&[tool::Rustdoc { compiler: Compiler::new(0, a) }],
323323
);
324324
assert!(cache.all::<compile::Rustc>().is_empty());
325325
}
@@ -352,16 +352,16 @@ mod defaults {
352352
assert_eq!(
353353
first(cache.all::<compile::Assemble>()),
354354
&[
355-
compile::Assemble { target_compiler: Compiler { host: a, stage: 0 } },
356-
compile::Assemble { target_compiler: Compiler { host: a, stage: 1 } },
357-
compile::Assemble { target_compiler: Compiler { host: b, stage: 1 } },
355+
compile::Assemble { target_compiler: Compiler::new(0, a) },
356+
compile::Assemble { target_compiler: Compiler::new(1, a) },
357+
compile::Assemble { target_compiler: Compiler::new(1, b) },
358358
]
359359
);
360360
assert_eq!(
361361
first(cache.all::<tool::Rustdoc>()),
362362
&[
363-
tool::Rustdoc { compiler: Compiler { host: a, stage: 1 } },
364-
tool::Rustdoc { compiler: Compiler { host: b, stage: 1 } },
363+
tool::Rustdoc { compiler: Compiler::new(1, a) },
364+
tool::Rustdoc { compiler: Compiler::new(1, b) },
365365
],
366366
);
367367
assert_eq!(
@@ -386,14 +386,14 @@ mod defaults {
386386
assert_eq!(first(cache.all::<doc::ErrorIndex>()), &[doc::ErrorIndex { target: a },]);
387387
assert_eq!(
388388
first(cache.all::<tool::ErrorIndex>()),
389-
&[tool::ErrorIndex { compiler: Compiler { host: a, stage: 0 } }]
389+
&[tool::ErrorIndex { compiler: Compiler::new(0, a) }]
390390
);
391391
// docs should be built with the beta compiler, not with the stage0 artifacts.
392392
// recall that rustdoc is off-by-one: `stage` is the compiler rustdoc is _linked_ to,
393393
// not the one it was built by.
394394
assert_eq!(
395395
first(cache.all::<tool::Rustdoc>()),
396-
&[tool::Rustdoc { compiler: Compiler { host: a, stage: 0 } },]
396+
&[tool::Rustdoc { compiler: Compiler::new(0, a) },]
397397
);
398398
}
399399
}
@@ -418,17 +418,17 @@ mod dist {
418418
assert_eq!(first(cache.all::<dist::Mingw>()), &[dist::Mingw { host: a },]);
419419
assert_eq!(
420420
first(cache.all::<dist::Rustc>()),
421-
&[dist::Rustc { compiler: Compiler { host: a, stage: 2 } },]
421+
&[dist::Rustc { compiler: Compiler::new(2, a) },]
422422
);
423423
assert_eq!(
424424
first(cache.all::<dist::Std>()),
425-
&[dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },]
425+
&[dist::Std { compiler: Compiler::new(1, a), target: a },]
426426
);
427427
assert_eq!(first(cache.all::<dist::Src>()), &[dist::Src]);
428428
// Make sure rustdoc is only built once.
429429
assert_eq!(
430430
first(cache.all::<tool::Rustdoc>()),
431-
&[tool::Rustdoc { compiler: Compiler { host: a, stage: 2 } },]
431+
&[tool::Rustdoc { compiler: Compiler::new(2, a) },]
432432
);
433433
}
434434

@@ -450,13 +450,13 @@ mod dist {
450450
);
451451
assert_eq!(
452452
first(cache.all::<dist::Rustc>()),
453-
&[dist::Rustc { compiler: Compiler { host: a, stage: 2 } },]
453+
&[dist::Rustc { compiler: Compiler::new(2, a) },]
454454
);
455455
assert_eq!(
456456
first(cache.all::<dist::Std>()),
457457
&[
458-
dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
459-
dist::Std { compiler: Compiler { host: a, stage: 2 }, target: b },
458+
dist::Std { compiler: Compiler::new(1, a), target: a },
459+
dist::Std { compiler: Compiler::new(2, a), target: b },
460460
]
461461
);
462462
assert_eq!(first(cache.all::<dist::Src>()), &[dist::Src]);
@@ -483,15 +483,15 @@ mod dist {
483483
assert_eq!(
484484
first(cache.all::<dist::Rustc>()),
485485
&[
486-
dist::Rustc { compiler: Compiler { host: a, stage: 2 } },
487-
dist::Rustc { compiler: Compiler { host: b, stage: 2 } },
486+
dist::Rustc { compiler: Compiler::new(2, a) },
487+
dist::Rustc { compiler: Compiler::new(2, b) },
488488
]
489489
);
490490
assert_eq!(
491491
first(cache.all::<dist::Std>()),
492492
&[
493-
dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
494-
dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
493+
dist::Std { compiler: Compiler::new(1, a), target: a },
494+
dist::Std { compiler: Compiler::new(1, a), target: b },
495495
]
496496
);
497497
assert_eq!(
@@ -519,7 +519,7 @@ mod dist {
519519

520520
assert_eq!(
521521
first(cache.all::<dist::Rustc>()),
522-
&[dist::Rustc { compiler: Compiler { host: b, stage: 2 } },]
522+
&[dist::Rustc { compiler: Compiler::new(2, b) },]
523523
);
524524
assert_eq!(
525525
first(cache.all::<compile::Rustc>()),
@@ -556,16 +556,16 @@ mod dist {
556556
assert_eq!(
557557
first(cache.all::<dist::Rustc>()),
558558
&[
559-
dist::Rustc { compiler: Compiler { host: a, stage: 2 } },
560-
dist::Rustc { compiler: Compiler { host: b, stage: 2 } },
559+
dist::Rustc { compiler: Compiler::new(2, a) },
560+
dist::Rustc { compiler: Compiler::new(2, b) },
561561
]
562562
);
563563
assert_eq!(
564564
first(cache.all::<dist::Std>()),
565565
&[
566-
dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
567-
dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
568-
dist::Std { compiler: Compiler { host: a, stage: 2 }, target: c },
566+
dist::Std { compiler: Compiler::new(1, a), target: a },
567+
dist::Std { compiler: Compiler::new(1, a), target: b },
568+
dist::Std { compiler: Compiler::new(2, a), target: c },
569569
]
570570
);
571571
assert_eq!(first(cache.all::<dist::Src>()), &[dist::Src]);
@@ -583,7 +583,7 @@ mod dist {
583583
assert_eq!(first(cache.all::<dist::Mingw>()), &[dist::Mingw { host: c },]);
584584
assert_eq!(
585585
first(cache.all::<dist::Std>()),
586-
&[dist::Std { compiler: Compiler { host: a, stage: 2 }, target: c },]
586+
&[dist::Std { compiler: Compiler::new(2, a), target: c },]
587587
);
588588
}
589589

@@ -608,15 +608,15 @@ mod dist {
608608
assert_eq!(
609609
first(cache.all::<dist::Rustc>()),
610610
&[
611-
dist::Rustc { compiler: Compiler { host: a, stage: 2 } },
612-
dist::Rustc { compiler: Compiler { host: b, stage: 2 } },
611+
dist::Rustc { compiler: Compiler::new(2, a) },
612+
dist::Rustc { compiler: Compiler::new(2, b) },
613613
]
614614
);
615615
assert_eq!(
616616
first(cache.all::<dist::Std>()),
617617
&[
618-
dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
619-
dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
618+
dist::Std { compiler: Compiler::new(1, a), target: a },
619+
dist::Std { compiler: Compiler::new(1, a), target: b },
620620
]
621621
);
622622
assert_eq!(first(cache.all::<dist::Src>()), &[dist::Src]);
@@ -633,10 +633,10 @@ mod dist {
633633
assert_eq!(
634634
first(cache.all::<compile::Assemble>()),
635635
&[
636-
compile::Assemble { target_compiler: Compiler { host: a, stage: 0 } },
637-
compile::Assemble { target_compiler: Compiler { host: a, stage: 1 } },
638-
compile::Assemble { target_compiler: Compiler { host: a, stage: 2 } },
639-
compile::Assemble { target_compiler: Compiler { host: b, stage: 2 } },
636+
compile::Assemble { target_compiler: Compiler::new(0, a) },
637+
compile::Assemble { target_compiler: Compiler::new(1, a) },
638+
compile::Assemble { target_compiler: Compiler::new(2, a) },
639+
compile::Assemble { target_compiler: Compiler::new(2, b) },
640640
]
641641
);
642642
}
@@ -683,28 +683,16 @@ mod dist {
683683
first(builder.cache.all::<compile::Assemble>()),
684684
&[
685685
compile::Assemble {
686-
target_compiler: Compiler {
687-
host: TargetSelection::from_user(TEST_TRIPLE_1),
688-
stage: 0
689-
}
686+
target_compiler: Compiler::new(0, TargetSelection::from_user(TEST_TRIPLE_1),)
690687
},
691688
compile::Assemble {
692-
target_compiler: Compiler {
693-
host: TargetSelection::from_user(TEST_TRIPLE_1),
694-
stage: 1
695-
}
689+
target_compiler: Compiler::new(1, TargetSelection::from_user(TEST_TRIPLE_1),)
696690
},
697691
compile::Assemble {
698-
target_compiler: Compiler {
699-
host: TargetSelection::from_user(TEST_TRIPLE_1),
700-
stage: 2
701-
}
692+
target_compiler: Compiler::new(2, TargetSelection::from_user(TEST_TRIPLE_1),)
702693
},
703694
compile::Assemble {
704-
target_compiler: Compiler {
705-
host: TargetSelection::from_user(TEST_TRIPLE_2),
706-
stage: 2
707-
}
695+
target_compiler: Compiler::new(2, TargetSelection::from_user(TEST_TRIPLE_2),)
708696
},
709697
]
710698
);
@@ -747,9 +735,9 @@ mod dist {
747735
assert_eq!(
748736
first(builder.cache.all::<compile::Assemble>()),
749737
&[
750-
compile::Assemble { target_compiler: Compiler { host: a, stage: 0 } },
751-
compile::Assemble { target_compiler: Compiler { host: a, stage: 1 } },
752-
compile::Assemble { target_compiler: Compiler { host: a, stage: 2 } },
738+
compile::Assemble { target_compiler: Compiler::new(0, a) },
739+
compile::Assemble { target_compiler: Compiler::new(1, a) },
740+
compile::Assemble { target_compiler: Compiler::new(2, a) },
753741
]
754742
);
755743
assert_eq!(
@@ -798,7 +786,7 @@ mod dist {
798786
assert_eq!(
799787
first(builder.cache.all::<test::Crate>()),
800788
&[test::Crate {
801-
compiler: Compiler { host, stage: 0 },
789+
compiler: Compiler::new(0, host),
802790
target: host,
803791
mode: crate::Mode::Std,
804792
crates: vec!["std".to_owned()],
@@ -824,13 +812,13 @@ mod dist {
824812
);
825813
assert_eq!(
826814
first(builder.cache.all::<tool::ErrorIndex>()),
827-
&[tool::ErrorIndex { compiler: Compiler { host: a, stage: 1 } }]
815+
&[tool::ErrorIndex { compiler: Compiler::new(1, a) }]
828816
);
829817
// This is actually stage 1, but Rustdoc::run swaps out the compiler with
830818
// stage minus 1 if --stage is not 0. Very confusing!
831819
assert_eq!(
832820
first(builder.cache.all::<tool::Rustdoc>()),
833-
&[tool::Rustdoc { compiler: Compiler { host: a, stage: 2 } },]
821+
&[tool::Rustdoc { compiler: Compiler::new(2, a) },]
834822
);
835823
}
836824

@@ -870,7 +858,7 @@ mod dist {
870858
);
871859
assert_eq!(
872860
first(builder.cache.all::<tool::ErrorIndex>()),
873-
&[tool::ErrorIndex { compiler: Compiler { host: a, stage: 1 } }]
861+
&[tool::ErrorIndex { compiler: Compiler::new(1, a) }]
874862
);
875863
// Unfortunately rustdoc is built twice. Once from stage1 for compiletest
876864
// (and other things), and once from stage0 for std crates. Ideally it
@@ -886,9 +874,9 @@ mod dist {
886874
assert_eq!(
887875
first(builder.cache.all::<tool::Rustdoc>()),
888876
&[
889-
tool::Rustdoc { compiler: Compiler { host: a, stage: 0 } },
890-
tool::Rustdoc { compiler: Compiler { host: a, stage: 1 } },
891-
tool::Rustdoc { compiler: Compiler { host: a, stage: 2 } },
877+
tool::Rustdoc { compiler: Compiler::new(0, a) },
878+
tool::Rustdoc { compiler: Compiler::new(1, a) },
879+
tool::Rustdoc { compiler: Compiler::new(2, a) },
892880
]
893881
);
894882
}
@@ -904,7 +892,7 @@ mod sysroot_target_dirs {
904892
let build = Build::new(configure("build", &[TEST_TRIPLE_1], &[TEST_TRIPLE_1]));
905893
let builder = Builder::new(&build);
906894
let target_triple_1 = TargetSelection::from_user(TEST_TRIPLE_1);
907-
let compiler = Compiler { stage: 1, host: target_triple_1 };
895+
let compiler = Compiler::new(1, target_triple_1);
908896
let target_triple_2 = TargetSelection::from_user(TEST_TRIPLE_2);
909897
let actual = builder.sysroot_target_libdir(compiler, target_triple_2);
910898

@@ -924,7 +912,7 @@ mod sysroot_target_dirs {
924912
let build = Build::new(configure("build", &[TEST_TRIPLE_1], &[TEST_TRIPLE_1]));
925913
let builder = Builder::new(&build);
926914
let target_triple_1 = TargetSelection::from_user(TEST_TRIPLE_1);
927-
let compiler = Compiler { stage: 1, host: target_triple_1 };
915+
let compiler = Compiler::new(1, target_triple_1);
928916
let target_triple_2 = TargetSelection::from_user(TEST_TRIPLE_2);
929917
let actual = builder.sysroot_target_bindir(compiler, target_triple_2);
930918

@@ -1128,13 +1116,13 @@ fn test_get_tool_rustc_compiler() {
11281116

11291117
let target_triple_1 = TargetSelection::from_user(TEST_TRIPLE_1);
11301118

1131-
let compiler = Compiler { stage: 2, host: target_triple_1 };
1132-
let expected = Compiler { stage: 1, host: target_triple_1 };
1119+
let compiler = Compiler::new(2, target_triple_1);
1120+
let expected = Compiler::new(1, target_triple_1);
11331121
let actual = tool::get_tool_rustc_compiler(&builder, compiler);
11341122
assert_eq!(expected, actual);
11351123

1136-
let compiler = Compiler { stage: 1, host: target_triple_1 };
1137-
let expected = Compiler { stage: 0, host: target_triple_1 };
1124+
let compiler = Compiler::new(1, target_triple_1);
1125+
let expected = Compiler::new(0, target_triple_1);
11381126
let actual = tool::get_tool_rustc_compiler(&builder, compiler);
11391127
assert_eq!(expected, actual);
11401128

@@ -1143,8 +1131,8 @@ fn test_get_tool_rustc_compiler() {
11431131
let build = Build::new(config);
11441132
let builder = Builder::new(&build);
11451133

1146-
let compiler = Compiler { stage: 1, host: target_triple_1 };
1147-
let expected = Compiler { stage: 1, host: target_triple_1 };
1134+
let compiler = Compiler::new(1, target_triple_1);
1135+
let expected = Compiler::new(1, target_triple_1);
11481136
let actual = tool::get_tool_rustc_compiler(&builder, compiler);
11491137
assert_eq!(expected, actual);
11501138
}

0 commit comments

Comments
 (0)