|
| 1 | +//! Compiler crate tests and codegen backend tests. |
| 2 | +
|
| 3 | +#![warn(unused_imports)] |
| 4 | + |
| 5 | +use super::test_helpers::Crate; |
| 6 | +use crate::core::build_steps::compile; |
| 7 | +use crate::core::build_steps::tool::SourceType; |
| 8 | +use crate::core::builder::{self, Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step}; |
| 9 | +use crate::core::config::TargetSelection; |
| 10 | +use crate::utils::helpers::{self, target_supports_cranelift_backend}; |
| 11 | +use crate::{DocTests, Mode}; |
| 12 | + |
| 13 | +/// Runs `cargo test` for the compiler crates in `compiler/`. |
| 14 | +/// |
| 15 | +/// (This step does not test `rustc_codegen_cranelift` or `rustc_codegen_gcc`, which have their own |
| 16 | +/// separate test steps.) |
| 17 | +#[derive(Debug, Clone, PartialEq, Eq, Hash)] |
| 18 | +pub struct CrateLibrustc { |
| 19 | + compiler: Compiler, |
| 20 | + target: TargetSelection, |
| 21 | + crates: Vec<String>, |
| 22 | +} |
| 23 | + |
| 24 | +impl Step for CrateLibrustc { |
| 25 | + type Output = (); |
| 26 | + const DEFAULT: bool = true; |
| 27 | + const ONLY_HOSTS: bool = true; |
| 28 | + |
| 29 | + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { |
| 30 | + run.crate_or_deps("rustc-main").path("compiler") |
| 31 | + } |
| 32 | + |
| 33 | + fn make_run(run: RunConfig<'_>) { |
| 34 | + let builder = run.builder; |
| 35 | + let host = run.build_triple(); |
| 36 | + let compiler = builder.compiler_for(builder.top_stage, host, host); |
| 37 | + let crates = run.make_run_crates(Alias::Compiler); |
| 38 | + |
| 39 | + builder.ensure(CrateLibrustc { compiler, target: run.target, crates }); |
| 40 | + } |
| 41 | + |
| 42 | + fn run(self, builder: &Builder<'_>) { |
| 43 | + builder.ensure(compile::Std::new(self.compiler, self.target)); |
| 44 | + |
| 45 | + // To actually run the tests, delegate to a copy of the `Crate` step. |
| 46 | + builder.ensure(Crate { |
| 47 | + compiler: self.compiler, |
| 48 | + target: self.target, |
| 49 | + mode: Mode::Rustc, |
| 50 | + crates: self.crates, |
| 51 | + }); |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +#[derive(Debug, Clone, PartialEq, Eq, Hash)] |
| 56 | +pub struct CodegenCranelift { |
| 57 | + compiler: Compiler, |
| 58 | + target: TargetSelection, |
| 59 | +} |
| 60 | + |
| 61 | +impl Step for CodegenCranelift { |
| 62 | + type Output = (); |
| 63 | + const DEFAULT: bool = true; |
| 64 | + const ONLY_HOSTS: bool = true; |
| 65 | + |
| 66 | + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { |
| 67 | + run.paths(&["compiler/rustc_codegen_cranelift"]) |
| 68 | + } |
| 69 | + |
| 70 | + fn make_run(run: RunConfig<'_>) { |
| 71 | + let builder = run.builder; |
| 72 | + let host = run.build_triple(); |
| 73 | + let compiler = run.builder.compiler_for(run.builder.top_stage, host, host); |
| 74 | + |
| 75 | + if builder.doc_tests == DocTests::Only { |
| 76 | + return; |
| 77 | + } |
| 78 | + |
| 79 | + if builder.download_rustc() { |
| 80 | + builder.info("CI rustc uses the default codegen backend. skipping"); |
| 81 | + return; |
| 82 | + } |
| 83 | + |
| 84 | + if !target_supports_cranelift_backend(run.target) { |
| 85 | + builder.info("target not supported by rustc_codegen_cranelift. skipping"); |
| 86 | + return; |
| 87 | + } |
| 88 | + |
| 89 | + if builder.remote_tested(run.target) { |
| 90 | + builder.info("remote testing is not supported by rustc_codegen_cranelift. skipping"); |
| 91 | + return; |
| 92 | + } |
| 93 | + |
| 94 | + if !builder.config.codegen_backends(run.target).contains(&"cranelift".to_owned()) { |
| 95 | + builder.info("cranelift not in rust.codegen-backends. skipping"); |
| 96 | + return; |
| 97 | + } |
| 98 | + |
| 99 | + builder.ensure(CodegenCranelift { compiler, target: run.target }); |
| 100 | + } |
| 101 | + |
| 102 | + fn run(self, builder: &Builder<'_>) { |
| 103 | + let compiler = self.compiler; |
| 104 | + let target = self.target; |
| 105 | + |
| 106 | + builder.ensure(compile::Std::new(compiler, target)); |
| 107 | + |
| 108 | + // If we're not doing a full bootstrap but we're testing a stage2 |
| 109 | + // version of libstd, then what we're actually testing is the libstd |
| 110 | + // produced in stage1. Reflect that here by updating the compiler that |
| 111 | + // we're working with automatically. |
| 112 | + let compiler = builder.compiler_for(compiler.stage, compiler.host, target); |
| 113 | + |
| 114 | + let build_cargo = || { |
| 115 | + let mut cargo = builder::Cargo::new( |
| 116 | + builder, |
| 117 | + compiler, |
| 118 | + Mode::Codegen, // Must be codegen to ensure dlopen on compiled dylibs works |
| 119 | + SourceType::InTree, |
| 120 | + target, |
| 121 | + Kind::Run, |
| 122 | + ); |
| 123 | + |
| 124 | + cargo.current_dir(&builder.src.join("compiler/rustc_codegen_cranelift")); |
| 125 | + cargo |
| 126 | + .arg("--manifest-path") |
| 127 | + .arg(builder.src.join("compiler/rustc_codegen_cranelift/build_system/Cargo.toml")); |
| 128 | + compile::rustc_cargo_env(builder, &mut cargo, target, compiler.stage); |
| 129 | + |
| 130 | + // Avoid incremental cache issues when changing rustc |
| 131 | + cargo.env("CARGO_BUILD_INCREMENTAL", "false"); |
| 132 | + |
| 133 | + cargo |
| 134 | + }; |
| 135 | + |
| 136 | + builder.info(&format!( |
| 137 | + "{} cranelift stage{} ({} -> {})", |
| 138 | + Kind::Test.description(), |
| 139 | + compiler.stage, |
| 140 | + &compiler.host, |
| 141 | + target |
| 142 | + )); |
| 143 | + let _time = helpers::timeit(builder); |
| 144 | + |
| 145 | + // FIXME handle vendoring for source tarballs before removing the --skip-test below |
| 146 | + let download_dir = builder.out.join("cg_clif_download"); |
| 147 | + |
| 148 | + // FIXME: Uncomment the `prepare` command below once vendoring is implemented. |
| 149 | + /* |
| 150 | + let mut prepare_cargo = build_cargo(); |
| 151 | + prepare_cargo.arg("--").arg("prepare").arg("--download-dir").arg(&download_dir); |
| 152 | + #[allow(deprecated)] |
| 153 | + builder.config.try_run(&mut prepare_cargo.into()).unwrap(); |
| 154 | + */ |
| 155 | + |
| 156 | + let mut cargo = build_cargo(); |
| 157 | + cargo |
| 158 | + .arg("--") |
| 159 | + .arg("test") |
| 160 | + .arg("--download-dir") |
| 161 | + .arg(&download_dir) |
| 162 | + .arg("--out-dir") |
| 163 | + .arg(builder.stage_out(compiler, Mode::ToolRustc).join("cg_clif")) |
| 164 | + .arg("--no-unstable-features") |
| 165 | + .arg("--use-backend") |
| 166 | + .arg("cranelift") |
| 167 | + // Avoid having to vendor the standard library dependencies |
| 168 | + .arg("--sysroot") |
| 169 | + .arg("llvm") |
| 170 | + // These tests depend on crates that are not yet vendored |
| 171 | + // FIXME remove once vendoring is handled |
| 172 | + .arg("--skip-test") |
| 173 | + .arg("testsuite.extended_sysroot"); |
| 174 | + |
| 175 | + cargo.into_cmd().run(builder); |
| 176 | + } |
| 177 | +} |
| 178 | + |
| 179 | +#[derive(Debug, Clone, PartialEq, Eq, Hash)] |
| 180 | +pub struct CodegenGCC { |
| 181 | + compiler: Compiler, |
| 182 | + target: TargetSelection, |
| 183 | +} |
| 184 | + |
| 185 | +impl Step for CodegenGCC { |
| 186 | + type Output = (); |
| 187 | + const DEFAULT: bool = true; |
| 188 | + const ONLY_HOSTS: bool = true; |
| 189 | + |
| 190 | + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { |
| 191 | + run.paths(&["compiler/rustc_codegen_gcc"]) |
| 192 | + } |
| 193 | + |
| 194 | + fn make_run(run: RunConfig<'_>) { |
| 195 | + let builder = run.builder; |
| 196 | + let host = run.build_triple(); |
| 197 | + let compiler = run.builder.compiler_for(run.builder.top_stage, host, host); |
| 198 | + |
| 199 | + if builder.doc_tests == DocTests::Only { |
| 200 | + return; |
| 201 | + } |
| 202 | + |
| 203 | + if builder.download_rustc() { |
| 204 | + builder.info("CI rustc uses the default codegen backend. skipping"); |
| 205 | + return; |
| 206 | + } |
| 207 | + |
| 208 | + let triple = run.target.triple; |
| 209 | + let target_supported = |
| 210 | + if triple.contains("linux") { triple.contains("x86_64") } else { false }; |
| 211 | + if !target_supported { |
| 212 | + builder.info("target not supported by rustc_codegen_gcc. skipping"); |
| 213 | + return; |
| 214 | + } |
| 215 | + |
| 216 | + if builder.remote_tested(run.target) { |
| 217 | + builder.info("remote testing is not supported by rustc_codegen_gcc. skipping"); |
| 218 | + return; |
| 219 | + } |
| 220 | + |
| 221 | + if !builder.config.codegen_backends(run.target).contains(&"gcc".to_owned()) { |
| 222 | + builder.info("gcc not in rust.codegen-backends. skipping"); |
| 223 | + return; |
| 224 | + } |
| 225 | + |
| 226 | + builder.ensure(CodegenGCC { compiler, target: run.target }); |
| 227 | + } |
| 228 | + |
| 229 | + fn run(self, builder: &Builder<'_>) { |
| 230 | + let compiler = self.compiler; |
| 231 | + let target = self.target; |
| 232 | + |
| 233 | + builder.ensure( |
| 234 | + compile::Std::new(compiler, target) |
| 235 | + .extra_rust_args(&["-Csymbol-mangling-version=v0", "-Cpanic=abort"]), |
| 236 | + ); |
| 237 | + |
| 238 | + // If we're not doing a full bootstrap but we're testing a stage2 |
| 239 | + // version of libstd, then what we're actually testing is the libstd |
| 240 | + // produced in stage1. Reflect that here by updating the compiler that |
| 241 | + // we're working with automatically. |
| 242 | + let compiler = builder.compiler_for(compiler.stage, compiler.host, target); |
| 243 | + |
| 244 | + let build_cargo = || { |
| 245 | + let mut cargo = builder::Cargo::new( |
| 246 | + builder, |
| 247 | + compiler, |
| 248 | + Mode::Codegen, // Must be codegen to ensure dlopen on compiled dylibs works |
| 249 | + SourceType::InTree, |
| 250 | + target, |
| 251 | + Kind::Run, |
| 252 | + ); |
| 253 | + |
| 254 | + cargo.current_dir(&builder.src.join("compiler/rustc_codegen_gcc")); |
| 255 | + cargo |
| 256 | + .arg("--manifest-path") |
| 257 | + .arg(builder.src.join("compiler/rustc_codegen_gcc/build_system/Cargo.toml")); |
| 258 | + compile::rustc_cargo_env(builder, &mut cargo, target, compiler.stage); |
| 259 | + |
| 260 | + // Avoid incremental cache issues when changing rustc |
| 261 | + cargo.env("CARGO_BUILD_INCREMENTAL", "false"); |
| 262 | + cargo.rustflag("-Cpanic=abort"); |
| 263 | + |
| 264 | + cargo |
| 265 | + }; |
| 266 | + |
| 267 | + builder.info(&format!( |
| 268 | + "{} GCC stage{} ({} -> {})", |
| 269 | + Kind::Test.description(), |
| 270 | + compiler.stage, |
| 271 | + &compiler.host, |
| 272 | + target |
| 273 | + )); |
| 274 | + let _time = helpers::timeit(builder); |
| 275 | + |
| 276 | + // FIXME: Uncomment the `prepare` command below once vendoring is implemented. |
| 277 | + /* |
| 278 | + let mut prepare_cargo = build_cargo(); |
| 279 | + prepare_cargo.arg("--").arg("prepare"); |
| 280 | + #[allow(deprecated)] |
| 281 | + builder.config.try_run(&mut prepare_cargo.into()).unwrap(); |
| 282 | + */ |
| 283 | + |
| 284 | + let mut cargo = build_cargo(); |
| 285 | + |
| 286 | + cargo |
| 287 | + // cg_gcc's build system ignores RUSTFLAGS. pass some flags through CG_RUSTFLAGS instead. |
| 288 | + .env("CG_RUSTFLAGS", "-Alinker-messages") |
| 289 | + .arg("--") |
| 290 | + .arg("test") |
| 291 | + .arg("--use-system-gcc") |
| 292 | + .arg("--use-backend") |
| 293 | + .arg("gcc") |
| 294 | + .arg("--out-dir") |
| 295 | + .arg(builder.stage_out(compiler, Mode::ToolRustc).join("cg_gcc")) |
| 296 | + .arg("--release") |
| 297 | + .arg("--mini-tests") |
| 298 | + .arg("--std-tests"); |
| 299 | + cargo.args(builder.config.test_args()); |
| 300 | + |
| 301 | + cargo.into_cmd().run(builder); |
| 302 | + } |
| 303 | +} |
0 commit comments