Skip to content

Commit 7a34120

Browse files
Run rustc_codegen_gcc tests in the CI
1 parent 17659c7 commit 7a34120

File tree

4 files changed

+168
-18
lines changed

4 files changed

+168
-18
lines changed

src/bootstrap/src/core/build_steps/compile.rs

+33-2
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,42 @@ pub struct Std {
4545
/// When using download-rustc, we need to use a new build of `std` for running unit tests of Std itself,
4646
/// but we need to use the downloaded copy of std for linking to rustdoc. Allow this to be overriden by `builder.ensure` from other steps.
4747
force_recompile: bool,
48+
extra_rust_args: &'static [&'static str],
4849
}
4950

5051
impl Std {
5152
pub fn new(compiler: Compiler, target: TargetSelection) -> Self {
52-
Self { target, compiler, crates: Default::default(), force_recompile: false }
53+
Self {
54+
target,
55+
compiler,
56+
crates: Default::default(),
57+
force_recompile: false,
58+
extra_rust_args: &[],
59+
}
5360
}
5461

5562
pub fn force_recompile(compiler: Compiler, target: TargetSelection) -> Self {
56-
Self { target, compiler, crates: Default::default(), force_recompile: true }
63+
Self {
64+
target,
65+
compiler,
66+
crates: Default::default(),
67+
force_recompile: true,
68+
extra_rust_args: &[],
69+
}
70+
}
71+
72+
pub fn new_with_extra_rust_args(
73+
compiler: Compiler,
74+
target: TargetSelection,
75+
extra_rust_args: &'static [&'static str],
76+
) -> Self {
77+
Self {
78+
target,
79+
compiler,
80+
crates: Default::default(),
81+
force_recompile: false,
82+
extra_rust_args,
83+
}
5784
}
5885
}
5986

@@ -81,6 +108,7 @@ impl Step for Std {
81108
target: run.target,
82109
crates,
83110
force_recompile: false,
111+
extra_rust_args: &[],
84112
});
85113
}
86114

@@ -188,6 +216,9 @@ impl Step for Std {
188216
if target.is_synthetic() {
189217
cargo.env("RUSTC_BOOTSTRAP_SYNTHETIC_TARGET", "1");
190218
}
219+
for rustflag in self.extra_rust_args.into_iter() {
220+
cargo.rustflag(rustflag);
221+
}
191222

192223
let _guard = builder.msg(
193224
Kind::Build,

src/bootstrap/src/core/build_steps/test.rs

+132-14
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use crate::core::config::flags::Subcommand;
2727
use crate::core::config::TargetSelection;
2828
use crate::utils;
2929
use crate::utils::cache::{Interned, INTERNER};
30-
use crate::utils::exec::BootstrapCommand;
3130
use crate::utils::helpers::{
3231
self, add_link_lib_path, dylib_path, dylib_path_var, output, t, up_to_date,
3332
};
@@ -630,7 +629,7 @@ impl Step for Miri {
630629
SourceType::InTree,
631630
&[],
632631
);
633-
let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "miri", host, target);
632+
let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "miri", host, host);
634633

635634
cargo.add_rustc_lib_path(builder, compiler);
636635

@@ -809,8 +808,8 @@ impl Step for Clippy {
809808

810809
let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "clippy", host, host);
811810

812-
// Clippy reports errors if it blessed the outputs
813-
if builder.run_cmd(BootstrapCommand::from(&mut cargo).allow_failure()) {
811+
#[allow(deprecated)] // Clippy reports errors if it blessed the outputs
812+
if builder.config.try_run(&mut cargo).is_ok() {
814813
// The tests succeeded; nothing to do.
815814
return;
816815
}
@@ -1567,12 +1566,10 @@ note: if you're sure you want to do this, please open an issue as to why. In the
15671566
cmd.arg("--coverage-dump-path").arg(coverage_dump);
15681567
}
15691568

1570-
if mode == "run-coverage" {
1571-
// The demangler doesn't need the current compiler, so we can avoid
1572-
// unnecessary rebuilds by using the bootstrap compiler instead.
1569+
if mode == "run-make" || mode == "run-coverage" {
15731570
let rust_demangler = builder
15741571
.ensure(tool::RustDemangler {
1575-
compiler: compiler.with_stage(0),
1572+
compiler,
15761573
target: compiler.host,
15771574
extra_features: Vec::new(),
15781575
})
@@ -3002,10 +2999,7 @@ impl Step for CodegenCranelift {
30022999

30033000
let triple = run.target.triple;
30043001
let target_supported = if triple.contains("linux") {
3005-
triple.contains("x86_64")
3006-
|| triple.contains("aarch64")
3007-
|| triple.contains("s390x")
3008-
|| triple.contains("riscv64gc")
3002+
triple.contains("x86_64") || triple.contains("aarch64") || triple.contains("s390x")
30093003
} else if triple.contains("darwin") || triple.contains("windows") {
30103004
triple.contains("x86_64")
30113005
} else {
@@ -3100,7 +3094,131 @@ impl Step for CodegenCranelift {
31003094
.arg("testsuite.extended_sysroot");
31013095
cargo.args(builder.config.test_args());
31023096

3103-
let mut cmd: Command = cargo.into();
3104-
builder.run_cmd(BootstrapCommand::from(&mut cmd).fail_fast());
3097+
#[allow(deprecated)]
3098+
builder.config.try_run(&mut cargo.into()).unwrap();
3099+
}
3100+
}
3101+
3102+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3103+
pub struct CodegenGCC {
3104+
compiler: Compiler,
3105+
target: TargetSelection,
3106+
}
3107+
3108+
impl Step for CodegenGCC {
3109+
type Output = ();
3110+
const DEFAULT: bool = true;
3111+
const ONLY_HOSTS: bool = true;
3112+
3113+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
3114+
run.paths(&["compiler/rustc_codegen_gcc"])
3115+
}
3116+
3117+
fn make_run(run: RunConfig<'_>) {
3118+
let builder = run.builder;
3119+
let host = run.build_triple();
3120+
let compiler = run.builder.compiler_for(run.builder.top_stage, host, host);
3121+
3122+
if builder.doc_tests == DocTests::Only {
3123+
return;
3124+
}
3125+
3126+
let triple = run.target.triple;
3127+
let target_supported = if triple.contains("linux") {
3128+
triple.contains("x86_64") || triple.contains("aarch64") || triple.contains("s390x")
3129+
} else if triple.contains("darwin") || triple.contains("windows") {
3130+
triple.contains("x86_64")
3131+
} else {
3132+
false
3133+
};
3134+
if !target_supported {
3135+
builder.info("target not supported by rustc_codegen_gcc. skipping");
3136+
return;
3137+
}
3138+
3139+
if builder.remote_tested(run.target) {
3140+
builder.info("remote testing is not supported by rustc_codegen_gcc. skipping");
3141+
return;
3142+
}
3143+
3144+
if !builder.config.rust_codegen_backends.contains(&INTERNER.intern_str("gcc")) {
3145+
builder.info("gcc not in rust.codegen-backends. skipping");
3146+
return;
3147+
}
3148+
3149+
builder.ensure(CodegenGCC { compiler, target: run.target });
3150+
}
3151+
3152+
fn run(self, builder: &Builder<'_>) {
3153+
let compiler = self.compiler;
3154+
let target = self.target;
3155+
3156+
builder.ensure(compile::Std::new_with_extra_rust_args(
3157+
compiler,
3158+
target,
3159+
&["-Csymbol-mangling-version=v0", "-Cpanic=abort", "-Zpanic-abort-tests"],
3160+
));
3161+
3162+
// If we're not doing a full bootstrap but we're testing a stage2
3163+
// version of libstd, then what we're actually testing is the libstd
3164+
// produced in stage1. Reflect that here by updating the compiler that
3165+
// we're working with automatically.
3166+
let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
3167+
3168+
let build_cargo = || {
3169+
let mut cargo = builder.cargo(
3170+
compiler,
3171+
Mode::Codegen, // Must be codegen to ensure dlopen on compiled dylibs works
3172+
SourceType::InTree,
3173+
target,
3174+
"run",
3175+
);
3176+
cargo.current_dir(&builder.src.join("compiler/rustc_codegen_gcc"));
3177+
cargo
3178+
.arg("--manifest-path")
3179+
.arg(builder.src.join("compiler/rustc_codegen_gcc/build_system/Cargo.toml"));
3180+
compile::rustc_cargo_env(builder, &mut cargo, target, compiler.stage);
3181+
3182+
// Avoid incremental cache issues when changing rustc
3183+
cargo.env("CARGO_BUILD_INCREMENTAL", "false");
3184+
cargo.rustflag("-Cpanic=abort");
3185+
3186+
cargo
3187+
};
3188+
3189+
builder.info(&format!(
3190+
"{} GCC stage{} ({} -> {})",
3191+
Kind::Test.description(),
3192+
compiler.stage,
3193+
&compiler.host,
3194+
target
3195+
));
3196+
let _time = helpers::timeit(&builder);
3197+
3198+
/*
3199+
let mut prepare_cargo = build_cargo();
3200+
prepare_cargo.arg("--").arg("prepare");
3201+
#[allow(deprecated)]
3202+
builder.config.try_run(&mut prepare_cargo.into()).unwrap();
3203+
*/
3204+
3205+
let mut cargo = build_cargo();
3206+
3207+
cargo
3208+
.arg("--")
3209+
.arg("test")
3210+
.arg("--use-system-gcc")
3211+
.arg("--use-backend")
3212+
.arg("gcc")
3213+
.arg("--out-dir")
3214+
.arg(builder.stage_out(compiler, Mode::ToolRustc).join("cg_gcc"))
3215+
.arg("--release")
3216+
.arg("--no-default-features")
3217+
.arg("--mini-tests")
3218+
.arg("--std-tests");
3219+
cargo.args(builder.config.test_args());
3220+
3221+
#[allow(deprecated)]
3222+
builder.config.try_run(&mut cargo.into()).unwrap();
31053223
}
31063224
}

src/bootstrap/src/core/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ impl<'a> Builder<'a> {
737737
test::Debuginfo,
738738
test::UiFullDeps,
739739
test::CodegenCranelift,
740+
test::CodegenGCC,
740741
test::Rustdoc,
741742
test::RunCoverageRustdoc,
742743
test::Pretty,

src/ci/run.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ else
124124

125125
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.verify-llvm-ir"
126126

127-
# Test the Cranelift backend in on CI, but don't ship it.
128-
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.codegen-backends=llvm,cranelift"
127+
# Test the Cranelift and GCC backends in on CI, but don't ship them.
128+
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.codegen-backends=llvm,cranelift,gcc"
129129

130130
# We enable this for non-dist builders, since those aren't trying to produce
131131
# fresh binaries. We currently don't entirely support distributing a fresh

0 commit comments

Comments
 (0)