Skip to content

Commit ce697f9

Browse files
committed
Auto merge of rust-lang#131532 - Zalathar:rollup-688kw5t, r=Zalathar
Rollup of 3 pull requests Successful merges: - rust-lang#131305 (make `llvm::is_ci_llvm_modified` logic more precise) - rust-lang#131524 (compiletest: Remove the magic hacks for finding output with `lto=thin`) - rust-lang#131525 (compiletest: Simplify the choice of `--emit` mode for assembly tests) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0321e73 + 3bb5222 commit ce697f9

File tree

8 files changed

+52
-128
lines changed

8 files changed

+52
-128
lines changed

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

+24-11
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ use build_helper::git::get_closest_merge_commit;
2020

2121
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
2222
use crate::core::config::{Config, TargetSelection};
23-
use crate::utils::channel;
2423
use crate::utils::exec::command;
2524
use crate::utils::helpers::{
26-
self, HashStamp, exe, get_clang_cl_resource_dir, output, t, unhashed_basename, up_to_date,
25+
self, HashStamp, exe, get_clang_cl_resource_dir, t, unhashed_basename, up_to_date,
2726
};
2827
use crate::{CLang, GitRepo, Kind, generate_smart_stamp_hash};
2928

@@ -166,7 +165,7 @@ pub(crate) fn detect_llvm_sha(config: &Config, is_git: bool) -> String {
166165
config.src.join("src/version"),
167166
])
168167
.unwrap()
169-
} else if let Some(info) = channel::read_commit_info_file(&config.src) {
168+
} else if let Some(info) = crate::utils::channel::read_commit_info_file(&config.src) {
170169
info.sha.trim().to_owned()
171170
} else {
172171
"".to_owned()
@@ -242,15 +241,29 @@ pub(crate) fn is_ci_llvm_available(config: &Config, asserts: bool) -> bool {
242241

243242
/// Returns true if we're running in CI with modified LLVM (and thus can't download it)
244243
pub(crate) fn is_ci_llvm_modified(config: &Config) -> bool {
245-
CiEnv::is_rust_lang_managed_ci_job() && config.rust_info.is_managed_git_subrepository() && {
246-
// We assume we have access to git, so it's okay to unconditionally pass
247-
// `true` here.
248-
let llvm_sha = detect_llvm_sha(config, true);
249-
let head_sha =
250-
output(helpers::git(Some(&config.src)).arg("rev-parse").arg("HEAD").as_command_mut());
251-
let head_sha = head_sha.trim();
252-
llvm_sha == head_sha
244+
// If not running in a CI environment, return false.
245+
if !CiEnv::is_ci() {
246+
return false;
247+
}
248+
249+
// In rust-lang/rust managed CI, assert the existence of the LLVM submodule.
250+
if CiEnv::is_rust_lang_managed_ci_job() {
251+
assert!(
252+
config.in_tree_llvm_info.is_managed_git_subrepository(),
253+
"LLVM submodule must be fetched in rust-lang/rust managed CI builders."
254+
);
253255
}
256+
// If LLVM submodule isn't present, skip the change check as it won't work.
257+
else if !config.in_tree_llvm_info.is_managed_git_subrepository() {
258+
return false;
259+
}
260+
261+
let llvm_sha = detect_llvm_sha(config, true);
262+
let head_sha = crate::output(
263+
helpers::git(Some(&config.src)).arg("rev-parse").arg("HEAD").as_command_mut(),
264+
);
265+
let head_sha = head_sha.trim();
266+
llvm_sha == head_sha
254267
}
255268

256269
#[derive(Debug, Clone, Hash, PartialEq, Eq)]

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

+14-22
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,21 @@ pub(crate) fn parse(config: &str) -> Config {
2121

2222
#[test]
2323
fn download_ci_llvm() {
24-
if crate::core::build_steps::llvm::is_ci_llvm_modified(&parse("")) {
25-
eprintln!("Detected LLVM as non-available: running in CI and modified LLVM in this change");
26-
return;
24+
assert!(parse("").llvm_from_ci);
25+
assert!(parse("llvm.download-ci-llvm = true").llvm_from_ci);
26+
assert!(!parse("llvm.download-ci-llvm = false").llvm_from_ci);
27+
28+
let if_unchanged_config = parse("llvm.download-ci-llvm = \"if-unchanged\"");
29+
if if_unchanged_config.llvm_from_ci {
30+
let has_changes = if_unchanged_config
31+
.last_modified_commit(&["src/llvm-project"], "download-ci-llvm", true)
32+
.is_none();
33+
34+
assert!(
35+
!has_changes,
36+
"CI LLVM can't be enabled with 'if-unchanged' while there are changes in LLVM submodule."
37+
);
2738
}
28-
29-
let parse_llvm = |s| parse(s).llvm_from_ci;
30-
let if_unchanged = parse_llvm("llvm.download-ci-llvm = \"if-unchanged\"");
31-
32-
assert!(parse_llvm("llvm.download-ci-llvm = true"));
33-
assert!(!parse_llvm("llvm.download-ci-llvm = false"));
34-
assert_eq!(parse_llvm(""), if_unchanged);
35-
assert_eq!(parse_llvm("rust.channel = \"dev\""), if_unchanged);
36-
assert!(parse_llvm("rust.channel = \"stable\""));
37-
assert_eq!(parse_llvm("build.build = \"x86_64-unknown-linux-gnu\""), if_unchanged);
38-
assert_eq!(
39-
parse_llvm(
40-
"llvm.assertions = true \r\n build.build = \"x86_64-unknown-linux-gnu\" \r\n llvm.download-ci-llvm = \"if-unchanged\""
41-
),
42-
if_unchanged
43-
);
44-
assert!(!parse_llvm(
45-
"llvm.assertions = true \r\n build.build = \"aarch64-apple-darwin\" \r\n llvm.download-ci-llvm = \"if-unchanged\""
46-
));
4739
}
4840

4941
// FIXME(onur-ozkan): extend scope of the test

Diff for: src/tools/compiletest/src/runtest.rs

+14-67
Original file line numberDiff line numberDiff line change
@@ -1780,102 +1780,49 @@ impl<'test> TestCx<'test> {
17801780
proc_res.fatal(None, || on_failure(*self));
17811781
}
17821782

1783-
fn get_output_file(&self, extension: &str) -> TargetLocation {
1784-
let thin_lto = self.props.compile_flags.iter().any(|s| s.ends_with("lto=thin"));
1785-
if thin_lto {
1786-
TargetLocation::ThisDirectory(self.output_base_dir())
1787-
} else {
1788-
// This works with both `--emit asm` (as default output name for the assembly)
1789-
// and `ptx-linker` because the latter can write output at requested location.
1790-
let output_path = self.output_base_name().with_extension(extension);
1791-
1792-
TargetLocation::ThisFile(output_path.clone())
1793-
}
1794-
}
1795-
1796-
fn get_filecheck_file(&self, extension: &str) -> PathBuf {
1797-
let thin_lto = self.props.compile_flags.iter().any(|s| s.ends_with("lto=thin"));
1798-
if thin_lto {
1799-
let name = self.testpaths.file.file_stem().unwrap().to_str().unwrap();
1800-
let canonical_name = name.replace('-', "_");
1801-
let mut output_file = None;
1802-
for entry in self.output_base_dir().read_dir().unwrap() {
1803-
if let Ok(entry) = entry {
1804-
let entry_path = entry.path();
1805-
let entry_file = entry_path.file_name().unwrap().to_str().unwrap();
1806-
if entry_file.starts_with(&format!("{}.{}", name, canonical_name))
1807-
&& entry_file.ends_with(extension)
1808-
{
1809-
assert!(
1810-
output_file.is_none(),
1811-
"thinlto doesn't support multiple cgu tests"
1812-
);
1813-
output_file = Some(entry_file.to_string());
1814-
}
1815-
}
1816-
}
1817-
if let Some(output_file) = output_file {
1818-
self.output_base_dir().join(output_file)
1819-
} else {
1820-
self.output_base_name().with_extension(extension)
1821-
}
1822-
} else {
1823-
self.output_base_name().with_extension(extension)
1824-
}
1825-
}
1826-
18271783
// codegen tests (using FileCheck)
18281784

18291785
fn compile_test_and_save_ir(&self) -> (ProcRes, PathBuf) {
1830-
let output_file = self.get_output_file("ll");
1786+
let output_path = self.output_base_name().with_extension("ll");
18311787
let input_file = &self.testpaths.file;
18321788
let rustc = self.make_compile_args(
18331789
input_file,
1834-
output_file,
1790+
TargetLocation::ThisFile(output_path.clone()),
18351791
Emit::LlvmIr,
18361792
AllowUnused::No,
18371793
LinkToAux::Yes,
18381794
Vec::new(),
18391795
);
18401796

18411797
let proc_res = self.compose_and_run_compiler(rustc, None, self.testpaths);
1842-
let output_path = self.get_filecheck_file("ll");
18431798
(proc_res, output_path)
18441799
}
18451800

18461801
fn compile_test_and_save_assembly(&self) -> (ProcRes, PathBuf) {
1847-
let output_file = self.get_output_file("s");
1802+
// This works with both `--emit asm` (as default output name for the assembly)
1803+
// and `ptx-linker` because the latter can write output at requested location.
1804+
let output_path = self.output_base_name().with_extension("s");
18481805
let input_file = &self.testpaths.file;
18491806

1850-
let mut emit = Emit::None;
1851-
match self.props.assembly_output.as_ref().map(AsRef::as_ref) {
1852-
Some("emit-asm") => {
1853-
emit = Emit::Asm;
1854-
}
1855-
1856-
Some("bpf-linker") => {
1857-
emit = Emit::LinkArgsAsm;
1858-
}
1859-
1860-
Some("ptx-linker") => {
1861-
// No extra flags needed.
1862-
}
1863-
1864-
Some(header) => self.fatal(&format!("unknown 'assembly-output' header: {header}")),
1865-
None => self.fatal("missing 'assembly-output' header"),
1866-
}
1807+
// Use the `//@ assembly-output:` directive to determine how to emit assembly.
1808+
let emit = match self.props.assembly_output.as_deref() {
1809+
Some("emit-asm") => Emit::Asm,
1810+
Some("bpf-linker") => Emit::LinkArgsAsm,
1811+
Some("ptx-linker") => Emit::None, // No extra flags needed.
1812+
Some(other) => self.fatal(&format!("unknown 'assembly-output' directive: {other}")),
1813+
None => self.fatal("missing 'assembly-output' directive"),
1814+
};
18671815

18681816
let rustc = self.make_compile_args(
18691817
input_file,
1870-
output_file,
1818+
TargetLocation::ThisFile(output_path.clone()),
18711819
emit,
18721820
AllowUnused::No,
18731821
LinkToAux::Yes,
18741822
Vec::new(),
18751823
);
18761824

18771825
let proc_res = self.compose_and_run_compiler(rustc, None, self.testpaths);
1878-
let output_path = self.get_filecheck_file("s");
18791826
(proc_res, output_path)
18801827
}
18811828

Diff for: tests/assembly/thin-lto.rs

-7
This file was deleted.

Diff for: tests/codegen/thin-lto.rs

-6
This file was deleted.

Diff for: tests/coverage/thin-lto.cov-map

-8
This file was deleted.

Diff for: tests/coverage/thin-lto.coverage

-4
This file was deleted.

Diff for: tests/coverage/thin-lto.rs

-3
This file was deleted.

0 commit comments

Comments
 (0)