Skip to content

Commit

Permalink
Auto merge of rust-lang#131455 - onur-ozkan:debug, r=<try>
Browse files Browse the repository at this point in the history
debug

**DO NOT MERGE**

try-build: aarch64-apple
  • Loading branch information
bors committed Oct 9, 2024
2 parents a1eceec + df445b9 commit a68bad1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 15 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_serialize/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ impl<D: Decoder, const N: usize> Decodable<D> for [u8; N] {
}
}

impl<'a, S: Encoder, T: Encodable<S>> Encodable<S> for Cow<'a, [T]>
impl<S: Encoder, T: Encodable<S>> Encodable<S> for Cow<'_, [T]>
where
[T]: ToOwned<Owned = Vec<T>>,
{
Expand All @@ -345,14 +345,14 @@ where
}
}

impl<'a, S: Encoder> Encodable<S> for Cow<'a, str> {
impl<S: Encoder> Encodable<S> for Cow<'_, str> {
fn encode(&self, s: &mut S) {
let val: &str = self;
val.encode(s)
}
}

impl<'a, D: Decoder> Decodable<D> for Cow<'a, str> {
impl<D: Decoder> Decodable<D> for Cow<'_, str> {
fn decode(d: &mut D) -> Cow<'static, str> {
let v: String = Decodable::decode(d);
Cow::Owned(v)
Expand Down
47 changes: 36 additions & 11 deletions src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ use build_helper::git::get_closest_merge_commit;

use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
use crate::core::config::{Config, TargetSelection};
use crate::utils::channel;
use crate::utils::exec::command;
use crate::utils::helpers::{
self, HashStamp, exe, get_clang_cl_resource_dir, output, t, unhashed_basename, up_to_date,
self, HashStamp, exe, get_clang_cl_resource_dir, t, unhashed_basename, up_to_date,
};
use crate::{CLang, GitRepo, Kind, generate_smart_stamp_hash};

Expand Down Expand Up @@ -157,6 +156,7 @@ pub fn prebuilt_llvm_config(
}

/// This retrieves the LLVM sha we *want* to use, according to git history.
#[cfg(not(feature = "bootstrap-self-test"))]
pub(crate) fn detect_llvm_sha(config: &Config, is_git: bool) -> String {
let llvm_sha = if is_git {
get_closest_merge_commit(Some(&config.src), &config.git_config(), &[
Expand All @@ -166,7 +166,7 @@ pub(crate) fn detect_llvm_sha(config: &Config, is_git: bool) -> String {
config.src.join("src/version"),
])
.unwrap()
} else if let Some(info) = channel::read_commit_info_file(&config.src) {
} else if let Some(info) = crate::utils::channel::read_commit_info_file(&config.src) {
info.sha.trim().to_owned()
} else {
"".to_owned()
Expand Down Expand Up @@ -242,15 +242,40 @@ pub(crate) fn is_ci_llvm_available(config: &Config, asserts: bool) -> bool {

/// Returns true if we're running in CI with modified LLVM (and thus can't download it)
pub(crate) fn is_ci_llvm_modified(config: &Config) -> bool {
CiEnv::is_rust_lang_managed_ci_job() && config.rust_info.is_managed_git_subrepository() && {
// We assume we have access to git, so it's okay to unconditionally pass
// `true` here.
let llvm_sha = detect_llvm_sha(config, true);
let head_sha =
output(helpers::git(Some(&config.src)).arg("rev-parse").arg("HEAD").as_command_mut());
let head_sha = head_sha.trim();
llvm_sha == head_sha
// If not running in a CI environment, return false.
if !CiEnv::is_ci() {
return false;
}

// In rust-lang/rust managed CI, assert the existence of the LLVM submodule.
if CiEnv::is_rust_lang_managed_ci_job() {
assert!(
config.in_tree_llvm_info.is_managed_git_subrepository(),
"LLVM submodule must be fetched in rust-lang/rust managed CI builders."
);
}
// If LLVM submodule isn't present, skip the change check as it won't work.
else if !config.in_tree_llvm_info.is_managed_git_subrepository() {
return false;
}

let commit = t!(get_closest_merge_commit(Some(&config.src), &config.git_config(), &[]));

#[allow(clippy::let_and_return)] // makes it look more clear
let is_modified = !t!(helpers::git(Some(&config.src))
.args(["diff-index", "--quiet", &commit])
.arg("--")
.args([
config.src.join("src/llvm-project"),
config.src.join("src/bootstrap/download-ci-llvm-stamp"),
// the LLVM shared object file is named `LLVM-12-rust-{version}-nightly`
config.src.join("src/version"),
])
.as_command_mut()
.status())
.success();

is_modified
}

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
Expand Down
6 changes: 6 additions & 0 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ fn alias_and_path_for_library() {

#[test]
fn ci_rustc_if_unchanged_logic() {
if env::var_os("NO_DOWNLOAD_CI_RUSTC").is_some_and(|s| s == "1" || s == "true") {
// FIXME: Find the actual reason.
println!("This test is incompatible in runners configured with `NO_DOWNLOAD_CI_RUSTC`.");
return;
}

let config = Config::parse_inner(
Flags::parse(&[
"build".to_owned(),
Expand Down
7 changes: 7 additions & 0 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,13 @@ impl Config {
Some(commit) => {
self.download_ci_rustc(commit);

// We never enable `download-rustc` without `download-ci-llvm`. If `self.llvm_from_ci` is false,
// it means the "if-unchanged" logic has detected some changes in the LLVM submodule.
if CiEnv::is_ci() && !self.llvm_from_ci {
println!("WARNING: LLVM submodule has changes, `download-rustc` will be disabled.");
return None;
}

if let Some(config_path) = &self.config {
let ci_config_toml = match self.get_builder_toml("ci-rustc") {
Ok(ci_config_toml) => ci_config_toml,
Expand Down

0 comments on commit a68bad1

Please sign in to comment.