Skip to content

Commit c0583a0

Browse files
committed
Auto merge of #112701 - bjorn3:test_cg_clif_in_ci2, r=Mark-Simulacrum
Run part of cg_clif's tests in CI While currently cg_clif is already built in CI ensuring that it always compiles, sometimes there is a bug in the changes that were made causing tests to fail. This PR is one step towards preventing this. Part of the test suite is still skipped until vendoring for the projects that are being tested is implemented. I will implement that in a future PR. Fixes part of https://github.com/bjorn3/rustc_codegen_cranelift/issues/1290 Fixes part of #95518 Required for #81746
2 parents 7418413 + 238d8e3 commit c0583a0

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

Diff for: src/bootstrap/builder.rs

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

Diff for: src/bootstrap/test.rs

+126
Original file line numberDiff line numberDiff line change
@@ -2967,3 +2967,129 @@ impl Step for TestHelpers {
29672967
.compile("rust_test_helpers");
29682968
}
29692969
}
2970+
2971+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2972+
pub struct CodegenCranelift {
2973+
compiler: Compiler,
2974+
target: TargetSelection,
2975+
}
2976+
2977+
impl Step for CodegenCranelift {
2978+
type Output = ();
2979+
const DEFAULT: bool = true;
2980+
const ONLY_HOSTS: bool = true;
2981+
2982+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2983+
run.paths(&["compiler/rustc_codegen_cranelift"])
2984+
}
2985+
2986+
fn make_run(run: RunConfig<'_>) {
2987+
let builder = run.builder;
2988+
let host = run.build_triple();
2989+
let compiler = run.builder.compiler_for(run.builder.top_stage, host, host);
2990+
2991+
if builder.doc_tests == DocTests::Only {
2992+
return;
2993+
}
2994+
2995+
let triple = run.target.triple;
2996+
let target_supported = if triple.contains("linux") {
2997+
triple.contains("x86_64") || triple.contains("aarch64") || triple.contains("s390x")
2998+
} else if triple.contains("darwin") || triple.contains("windows") {
2999+
triple.contains("x86_64")
3000+
} else {
3001+
false
3002+
};
3003+
if !target_supported {
3004+
builder.info("target not supported by rustc_codegen_cranelift. skipping");
3005+
return;
3006+
}
3007+
3008+
if builder.remote_tested(run.target) {
3009+
builder.info("remote testing is not supported by rustc_codegen_cranelift. skipping");
3010+
return;
3011+
}
3012+
3013+
if !builder.config.rust_codegen_backends.contains(&INTERNER.intern_str("cranelift")) {
3014+
builder.info("cranelift not in rust.codegen-backends. skipping");
3015+
return;
3016+
}
3017+
3018+
builder.ensure(CodegenCranelift { compiler, target: run.target });
3019+
}
3020+
3021+
fn run(self, builder: &Builder<'_>) {
3022+
let compiler = self.compiler;
3023+
let target = self.target;
3024+
3025+
builder.ensure(compile::Std::new(compiler, target));
3026+
3027+
// If we're not doing a full bootstrap but we're testing a stage2
3028+
// version of libstd, then what we're actually testing is the libstd
3029+
// produced in stage1. Reflect that here by updating the compiler that
3030+
// we're working with automatically.
3031+
let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
3032+
3033+
let build_cargo = || {
3034+
let mut cargo = builder.cargo(
3035+
compiler,
3036+
Mode::Codegen, // Must be codegen to ensure dlopen on compiled dylibs works
3037+
SourceType::InTree,
3038+
target,
3039+
"run",
3040+
);
3041+
cargo.current_dir(&builder.src.join("compiler/rustc_codegen_cranelift"));
3042+
cargo
3043+
.arg("--manifest-path")
3044+
.arg(builder.src.join("compiler/rustc_codegen_cranelift/build_system/Cargo.toml"));
3045+
compile::rustc_cargo_env(builder, &mut cargo, target, compiler.stage);
3046+
3047+
// Avoid incremental cache issues when changing rustc
3048+
cargo.env("CARGO_BUILD_INCREMENTAL", "false");
3049+
3050+
cargo
3051+
};
3052+
3053+
builder.info(&format!(
3054+
"{} cranelift stage{} ({} -> {})",
3055+
Kind::Test.description(),
3056+
compiler.stage,
3057+
&compiler.host,
3058+
target
3059+
));
3060+
let _time = util::timeit(&builder);
3061+
3062+
// FIXME handle vendoring for source tarballs before removing the --skip-test below
3063+
let download_dir = builder.out.join("cg_clif_download");
3064+
3065+
/*
3066+
let mut prepare_cargo = build_cargo();
3067+
prepare_cargo.arg("--").arg("prepare").arg("--download-dir").arg(&download_dir);
3068+
#[allow(deprecated)]
3069+
builder.config.try_run(&mut prepare_cargo.into()).unwrap();
3070+
*/
3071+
3072+
let mut cargo = build_cargo();
3073+
cargo
3074+
.arg("--")
3075+
.arg("test")
3076+
.arg("--download-dir")
3077+
.arg(&download_dir)
3078+
.arg("--out-dir")
3079+
.arg(builder.stage_out(compiler, Mode::ToolRustc).join("cg_clif"))
3080+
.arg("--no-unstable-features")
3081+
.arg("--use-backend")
3082+
.arg("cranelift")
3083+
// Avoid having to vendor the standard library dependencies
3084+
.arg("--sysroot")
3085+
.arg("llvm")
3086+
// These tests depend on crates that are not yet vendored
3087+
// FIXME remove once vendoring is handled
3088+
.arg("--skip-test")
3089+
.arg("testsuite.extended_sysroot");
3090+
cargo.args(builder.config.test_args());
3091+
3092+
#[allow(deprecated)]
3093+
builder.config.try_run(&mut cargo.into()).unwrap();
3094+
}
3095+
}

Diff for: src/ci/run.sh

+3
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ else
123123

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

126+
# Test the Cranelift backend in on CI, but don't ship it.
127+
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.codegen-backends=llvm,cranelift"
128+
126129
# We enable this for non-dist builders, since those aren't trying to produce
127130
# fresh binaries. We currently don't entirely support distributing a fresh
128131
# copy of the compiler (including llvm tools, etc.) if we haven't actually

0 commit comments

Comments
 (0)