Skip to content

Commit

Permalink
Rollup merge of rust-lang#75064 - petrochenkov:llvmtarg, r=Mark-Simul…
Browse files Browse the repository at this point in the history
…acrum

compiletest: Support ignoring tests requiring missing LLVM components

This PR implements a more principled solution to the problem described in rust-lang#66084.

Builds of LLVM backends take a lot of time and disk space.
So it usually makes sense to build rustc with
```toml
[llvm]
targets = "X86"
experimental-targets = ""
```
unless you are working on some target-specific tasks.

A few tests, however, require non-x86 backends to be built.
A new test directive `// needs-llvm-components: component1 component2 component3` makes such tests to be automatically ignored if one of the listed components is missing in the provided LLVM (this is determined through `llvm-config --components`).

As a result, the test suite now fully passes with LLVM built only with the x86 backend. The component list in this case is
```
aggressiveinstcombine all all-targets analysis asmparser asmprinter binaryformat bitreader bitstreamreader bitwriter cfguard codegen core coroutines coverage debuginfocodeview debuginfodwarf debuginfogsym debuginfomsf debuginfopdb demangle dlltooldriver dwarflinker engine executionengine frontendopenmp fuzzmutate globalisel instcombine instrumentation interpreter ipo irreader jitlink libdriver lineeditor linker lto mc mca mcdisassembler mcjit mcparser mirparser native nativecodegen objcarcopts object objectyaml option orcerror orcjit passes profiledata remarks runtimedyld scalaropts selectiondag support symbolize tablegen target textapi transformutils vectorize windowsmanifest x86 x86asmparser x86codegen x86desc x86disassembler x86info x86utils xray
```

(With the default target list it's much larger.)
```
aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils aggressiveinstcombine all all-targets analysis arm armasmparser armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter avr avrasmparser avrcodegen avrdesc avrdisassembler avrinfo binaryformat bitreader bitstreamreader bitwriter cfguard codegen core coroutines coverage debuginfocodeview debuginfodwarf debuginfogsym debuginfomsf debuginfopdb demangle dlltooldriver dwarflinker engine executionengine frontendopenmp fuzzmutate globalisel hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo instcombine instrumentation interpreter ipo irreader jitlink libdriver lineeditor linker lto mc mca mcdisassembler mcjit mcparser mips mipsasmparser mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmparser msp430codegen msp430desc msp430disassembler msp430info native nativecodegen nvptx nvptxcodegen nvptxdesc nvptxinfo objcarcopts object objectyaml option orcerror orcjit passes powerpc powerpcasmparser powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata remarks riscv riscvasmparser riscvcodegen riscvdesc riscvdisassembler riscvinfo riscvutils runtimedyld scalaropts selectiondag sparc sparcasmparser sparccodegen sparcdesc sparcdisassembler sparcinfo support symbolize systemz systemzasmparser systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target textapi transformutils vectorize webassembly webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler webassemblyinfo windowsmanifest x86 x86asmparser x86codegen x86desc x86disassembler x86info x86utils xray
```

rust-lang#66084 is also reverted now.

r? @Mark-Simulacrum
  • Loading branch information
Manishearth authored Aug 2, 2020
2 parents 9471ab0 + d3277b9 commit 0bf2dcf
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 17 deletions.
30 changes: 15 additions & 15 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,13 +1158,19 @@ impl Step for Compiletest {
cmd.arg("--quiet");
}

let mut llvm_components_passed = false;
let mut copts_passed = false;
if builder.config.llvm_enabled() {
let llvm_config = builder.ensure(native::Llvm { target: builder.config.build });
if !builder.config.dry_run {
let llvm_version = output(Command::new(&llvm_config).arg("--version"));
let llvm_components = output(Command::new(&llvm_config).arg("--components"));
// Remove trailing newline from llvm-config output.
let llvm_version = llvm_version.trim_end();
cmd.arg("--llvm-version").arg(llvm_version);
cmd.arg("--llvm-version")
.arg(llvm_version.trim())
.arg("--llvm-components")
.arg(llvm_components.trim());
llvm_components_passed = true;
}
if !builder.is_rust_llvm(target) {
cmd.arg("--system-llvm");
Expand All @@ -1182,15 +1188,13 @@ impl Step for Compiletest {
// Only pass correct values for these flags for the `run-make` suite as it
// requires that a C++ compiler was configured which isn't always the case.
if !builder.config.dry_run && suite == "run-make-fulldeps" {
let llvm_components = output(Command::new(&llvm_config).arg("--components"));
cmd.arg("--cc")
.arg(builder.cc(target))
.arg("--cxx")
.arg(builder.cxx(target).unwrap())
.arg("--cflags")
.arg(builder.cflags(target, GitRepo::Rustc).join(" "))
.arg("--llvm-components")
.arg(llvm_components.trim());
.arg(builder.cflags(target, GitRepo::Rustc).join(" "));
copts_passed = true;
if let Some(ar) = builder.ar(target) {
cmd.arg("--ar").arg(ar);
}
Expand Down Expand Up @@ -1220,15 +1224,11 @@ impl Step for Compiletest {
}
}

if suite != "run-make-fulldeps" {
cmd.arg("--cc")
.arg("")
.arg("--cxx")
.arg("")
.arg("--cflags")
.arg("")
.arg("--llvm-components")
.arg("");
if !llvm_components_passed {
cmd.arg("--llvm-components").arg("");
}
if !copts_passed {
cmd.arg("--cc").arg("").arg("--cxx").arg("").arg("--cflags").arg("");
}

if builder.remote_tested(target) {
Expand Down
1 change: 1 addition & 0 deletions src/test/assembly/asm/aarch64-modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// assembly-output: emit-asm
// compile-flags: -O
// compile-flags: --target aarch64-unknown-linux-gnu
// needs-llvm-components: aarch64

#![feature(no_core, lang_items, rustc_attrs)]
#![crate_type = "rlib"]
Expand Down
1 change: 1 addition & 0 deletions src/test/assembly/asm/aarch64-types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// no-system-llvm
// assembly-output: emit-asm
// compile-flags: --target aarch64-unknown-linux-gnu
// needs-llvm-components: aarch64

#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![crate_type = "rlib"]
Expand Down
1 change: 1 addition & 0 deletions src/test/assembly/asm/arm-modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// compile-flags: -O
// compile-flags: --target armv7-unknown-linux-gnueabihf
// compile-flags: -C target-feature=+neon
// needs-llvm-components: arm

#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![crate_type = "rlib"]
Expand Down
1 change: 1 addition & 0 deletions src/test/assembly/asm/arm-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// assembly-output: emit-asm
// compile-flags: --target armv7-unknown-linux-gnueabihf
// compile-flags: -C target-feature=+neon
// needs-llvm-components: arm

#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![crate_type = "rlib"]
Expand Down
1 change: 1 addition & 0 deletions src/test/assembly/asm/hexagon-types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// no-system-llvm
// assembly-output: emit-asm
// compile-flags: --target hexagon-unknown-linux-musl
// needs-llvm-components: hexagon

#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![crate_type = "rlib"]
Expand Down
1 change: 1 addition & 0 deletions src/test/assembly/asm/nvptx-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// assembly-output: emit-asm
// compile-flags: --target nvptx64-nvidia-cuda
// compile-flags: --crate-type cdylib
// needs-llvm-components: nvptx

#![feature(no_core, lang_items, rustc_attrs)]
#![no_core]
Expand Down
1 change: 1 addition & 0 deletions src/test/assembly/asm/riscv-modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// compile-flags: -O
// compile-flags: --target riscv64gc-unknown-linux-gnu
// compile-flags: -C target-feature=+f
// needs-llvm-components: riscv

#![feature(no_core, lang_items, rustc_attrs)]
#![crate_type = "rlib"]
Expand Down
1 change: 1 addition & 0 deletions src/test/assembly/asm/riscv-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//[riscv64] compile-flags: --target riscv64imac-unknown-none-elf
//[riscv32] compile-flags: --target riscv32imac-unknown-none-elf
// compile-flags: -C target-feature=+d
// needs-llvm-components: riscv

#![feature(no_core, lang_items, rustc_attrs)]
#![crate_type = "rlib"]
Expand Down
8 changes: 6 additions & 2 deletions src/test/codegen/abi-efiapi.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Checks if the correct annotation for the efiapi ABI is passed to llvm.

// revisions:x86_64 i686 arm

// revisions:x86_64 i686 aarch64 arm riscv
// min-llvm-version: 9.0
// needs-llvm-components: aarch64 arm riscv

//[x86_64] compile-flags: --target x86_64-unknown-uefi
//[i686] compile-flags: --target i686-unknown-linux-musl
//[aarch64] compile-flags: --target aarch64-unknown-none
//[arm] compile-flags: --target armv7r-none-eabi
//[riscv] compile-flags: --target riscv64gc-unknown-none-elf
// compile-flags: -C no-prepopulate-passes

#![crate_type = "lib"]
Expand All @@ -22,6 +24,8 @@ trait Copy { }

//x86_64: define win64cc void @has_efiapi
//i686: define void @has_efiapi
//aarch64: define void @has_efiapi
//arm: define void @has_efiapi
//riscv: define void @has_efiapi
#[no_mangle]
pub extern "efiapi" fn has_efiapi() {}
1 change: 1 addition & 0 deletions src/test/codegen/avr/avr-func-addrspace.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// compile-flags: -O --target=avr-unknown-unknown --crate-type=rlib
// needs-llvm-components: avr

// This test validates that function pointers can be stored in global variables
// and called upon. It ensures that Rust emits function pointers in the correct
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-37131.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// compile-flags: --target=thumbv6m-none-eabi
// ignore-arm
// needs-llvm-components: arm

// error-pattern:target may not be installed
fn main() { }
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-49851/compiler-builtins-error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//~ ERROR 1:1: 1:1: can't find crate for `core` [E0463]

// compile-flags: --target thumbv7em-none-eabihf
// needs-llvm-components: arm
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_std]
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-50993.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// compile-flags: --crate-type dylib --target thumbv7em-none-eabihf
// needs-llvm-components: arm
// build-pass
// error-pattern: dropping unsupported crate type `dylib` for target `thumbv7em-none-eabihf`

Expand Down
12 changes: 12 additions & 0 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::HashSet;
use std::env;
use std::fs::File;
use std::io::prelude::*;
Expand Down Expand Up @@ -186,6 +187,17 @@ impl EarlyProps {
if config.system_llvm && line.starts_with("no-system-llvm") {
return true;
}
if let Some(needed_components) =
config.parse_name_value_directive(line, "needs-llvm-components")
{
let components: HashSet<_> = config.llvm_components.split_whitespace().collect();
if !needed_components
.split_whitespace()
.all(|needed_component| components.contains(needed_component))
{
return true;
}
}
if let Some(actual_version) = config.llvm_version {
if let Some(rest) = line.strip_prefix("min-llvm-version:").map(str::trim) {
let min_version = extract_llvm_version(rest).unwrap();
Expand Down

0 comments on commit 0bf2dcf

Please sign in to comment.