Skip to content

Commit b78d305

Browse files
committed
fix issue#110087
modify CONFIG_CHANGE_HISTORY update change-id in bootstrap_test.py fix the second task for issue#110087
1 parent e918db8 commit b78d305

File tree

8 files changed

+108
-33
lines changed

8 files changed

+108
-33
lines changed

config.example.toml

+6-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#
3131
# If `change-id` does not match the version that is currently running,
3232
# `x.py` will prompt you to update it and check the related PR for more details.
33-
change-id = 116998
33+
change-id = 116881
3434

3535
# =============================================================================
3636
# Tweaking how LLVM is compiled
@@ -42,11 +42,14 @@ change-id = 116998
4242
# Unless you're developing for a target where Rust CI doesn't build a compiler
4343
# toolchain or changing LLVM locally, you probably want to leave this enabled.
4444
#
45-
# All tier 1 targets are currently supported; set this to `"if-available"` if
46-
# you are not sure whether you're on a tier 1 target.
45+
# Set this to `"if-available"` if you are not sure whether you're on a tier 1
46+
# target. All tier 1 targets are currently supported;
4747
#
4848
# We also currently only support this when building LLVM for the build triple.
4949
#
50+
# Set this to `"if-unchanged"` to only download if the llvm-project have not
51+
# been modified. (if no changes, the logic is the same as `"if-available"`)
52+
#
5053
# Note that many of the LLVM options are not currently supported for
5154
# downloading. Currently only the "assertions" option can be toggled.
5255
#download-ci-llvm = if rust.channel == "dev" { "if-available" } else { false }

src/bootstrap/bootstrap_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class GenerateAndParseConfig(unittest.TestCase):
103103
"""Test that we can serialize and deserialize a config.toml file"""
104104
def test_no_args(self):
105105
build = serialize_and_parse([])
106-
self.assertEqual(build.get_toml("change-id"), '116998')
106+
self.assertEqual(build.get_toml("change-id"), '116881')
107107
self.assertEqual(build.get_toml("profile"), 'dist')
108108
self.assertIsNone(build.get_toml("llvm.download-ci-llvm"))
109109

src/bootstrap/defaults/config.codegen.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ assertions = true
1010
# enable warnings during the llvm compilation
1111
enable-warnings = true
1212
# build llvm from source
13-
download-ci-llvm = false
13+
download-ci-llvm = "if-unchanged"
1414

1515
[rust]
1616
# This enables `RUSTC_LOG=debug`, avoiding confusing situations

src/bootstrap/download-ci-llvm-stamp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Change this file to make users of the `download-ci-llvm` configuration download
22
a new version of LLVM from CI, even if the LLVM submodule hasn’t changed.
33

4-
Last change is for: https://github.com/rust-lang/rust/pull/113996
4+
Last change is for: https://github.com/rust-lang/rust/pull/116881

src/bootstrap/src/core/build_steps/dist.rs

+9-15
Original file line numberDiff line numberDiff line change
@@ -2125,23 +2125,17 @@ impl Step for RustDev {
21252125
builder.ensure(crate::core::build_steps::llvm::Lld { target });
21262126

21272127
let src_bindir = builder.llvm_out(target).join("bin");
2128-
// If updating this list, you likely want to change
2128+
// If updating this, you likely want to change
21292129
// src/bootstrap/download-ci-llvm-stamp as well, otherwise local users
21302130
// will not pick up the extra file until LLVM gets bumped.
2131-
for bin in &[
2132-
"llvm-config",
2133-
"llvm-ar",
2134-
"llvm-objdump",
2135-
"llvm-profdata",
2136-
"llvm-bcanalyzer",
2137-
"llvm-cov",
2138-
"llvm-dwp",
2139-
"llvm-nm",
2140-
"llvm-dwarfdump",
2141-
"llvm-dis",
2142-
"llvm-tblgen",
2143-
] {
2144-
tarball.add_file(src_bindir.join(exe(bin, target)), "bin", 0o755);
2131+
if src_bindir.exists() {
2132+
for entry in walkdir::WalkDir::new(&src_bindir) {
2133+
let entry = t!(entry);
2134+
if entry.file_type().is_file() && !entry.path_is_symlink() {
2135+
let name = entry.file_name().to_str().unwrap();
2136+
tarball.add_file(src_bindir.join(name), "bin", 0o755);
2137+
}
2138+
}
21452139
}
21462140

21472141
// We don't build LLD on some platforms, so only add it if it exists

src/bootstrap/src/core/build_steps/setup.rs

+3
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ impl Step for Profile {
147147
}
148148

149149
fn run(self, builder: &Builder<'_>) {
150+
if self == Profile::Codegen {
151+
builder.update_submodule(&Path::new("src/llvm-project"));
152+
}
150153
setup(&builder.build.config, self)
151154
}
152155
}

src/bootstrap/src/core/config/config.rs

+86-11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::process::Command;
1919
use std::str::FromStr;
2020

2121
use crate::core::build_steps::compile::CODEGEN_BACKEND_PREFIX;
22+
use crate::core::build_steps::llvm;
2223
use crate::core::config::flags::{Color, Flags, Warnings};
2324
use crate::utils::cache::{Interned, INTERNER};
2425
use crate::utils::channel::{self, GitInfo};
@@ -1526,17 +1527,7 @@ impl Config {
15261527
config.llvm_build_config = llvm.build_config.clone().unwrap_or(Default::default());
15271528

15281529
let asserts = llvm_assertions.unwrap_or(false);
1529-
config.llvm_from_ci = match llvm.download_ci_llvm {
1530-
Some(StringOrBool::String(s)) => {
1531-
assert_eq!(s, "if-available", "unknown option `{s}` for download-ci-llvm");
1532-
crate::core::build_steps::llvm::is_ci_llvm_available(&config, asserts)
1533-
}
1534-
Some(StringOrBool::Bool(b)) => b,
1535-
None => {
1536-
config.channel == "dev"
1537-
&& crate::core::build_steps::llvm::is_ci_llvm_available(&config, asserts)
1538-
}
1539-
};
1530+
config.llvm_from_ci = config.parse_download_ci_llvm(llvm.download_ci_llvm, asserts);
15401531

15411532
if config.llvm_from_ci {
15421533
// None of the LLVM options, except assertions, are supported
@@ -2100,6 +2091,90 @@ impl Config {
21002091

21012092
Some(commit.to_string())
21022093
}
2094+
2095+
fn parse_download_ci_llvm(
2096+
&self,
2097+
download_ci_llvm: Option<StringOrBool>,
2098+
asserts: bool,
2099+
) -> bool {
2100+
match download_ci_llvm {
2101+
None => self.channel == "dev" && llvm::is_ci_llvm_available(&self, asserts),
2102+
Some(StringOrBool::Bool(b)) => b,
2103+
Some(StringOrBool::String(s)) if s == "if-available" => {
2104+
llvm::is_ci_llvm_available(&self, asserts)
2105+
}
2106+
Some(StringOrBool::String(s)) if s == "if-unchanged" => {
2107+
if self
2108+
.last_modified_commit(&["src/llvm-project"], "download-ci-llvm", true)
2109+
.is_none()
2110+
{
2111+
// there are some untracked changes in the the given paths.
2112+
false
2113+
} else {
2114+
llvm::is_ci_llvm_available(&self, asserts)
2115+
}
2116+
}
2117+
Some(StringOrBool::String(other)) => {
2118+
panic!("unrecognized option for download-ci-llvm: {:?}", other)
2119+
}
2120+
}
2121+
}
2122+
2123+
/// Returns the last commit in which any of `modified_paths` were changed,
2124+
/// or `None` if there are untracked changes in the working directory and `if_unchanged` is true.
2125+
pub fn last_modified_commit(
2126+
&self,
2127+
modified_paths: &[&str],
2128+
option_name: &str,
2129+
if_unchanged: bool,
2130+
) -> Option<String> {
2131+
// Handle running from a directory other than the top level
2132+
let top_level = output(self.git().args(&["rev-parse", "--show-toplevel"]));
2133+
let top_level = top_level.trim_end();
2134+
2135+
// Look for a version to compare to based on the current commit.
2136+
// Only commits merged by bors will have CI artifacts.
2137+
let merge_base = output(
2138+
self.git()
2139+
.arg("rev-list")
2140+
.arg(format!("--author={}", self.stage0_metadata.config.git_merge_commit_email))
2141+
.args(&["-n1", "--first-parent", "HEAD"]),
2142+
);
2143+
let commit = merge_base.trim_end();
2144+
if commit.is_empty() {
2145+
println!("error: could not find commit hash for downloading components from CI");
2146+
println!("help: maybe your repository history is too shallow?");
2147+
println!("help: consider disabling `{option_name}`");
2148+
println!("help: or fetch enough history to include one upstream commit");
2149+
crate::exit!(1);
2150+
}
2151+
2152+
// Warn if there were changes to the compiler or standard library since the ancestor commit.
2153+
let mut git = self.git();
2154+
git.args(&["diff-index", "--quiet", &commit, "--"]);
2155+
2156+
for path in modified_paths {
2157+
git.arg(format!("{top_level}/{path}"));
2158+
}
2159+
2160+
let has_changes = !t!(git.status()).success();
2161+
if has_changes {
2162+
if if_unchanged {
2163+
if self.verbose > 0 {
2164+
println!(
2165+
"warning: saw changes to one of {modified_paths:?} since {commit}; \
2166+
ignoring `{option_name}`"
2167+
);
2168+
}
2169+
return None;
2170+
}
2171+
println!(
2172+
"warning: `{option_name}` is enabled, but there are changes to one of {modified_paths:?}"
2173+
);
2174+
}
2175+
2176+
Some(commit.to_string())
2177+
}
21032178
}
21042179

21052180
fn set<T>(field: &mut T, val: Option<T>) {

src/bootstrap/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const LLD_FILE_NAMES: &[&str] = &["ld.lld", "ld64.lld", "lld-link", "wasm-ld"];
7878
///
7979
/// If you make any major changes (such as adding new values or changing default values), please
8080
/// ensure that the associated PR ID is added to the end of this list.
81-
pub const CONFIG_CHANGE_HISTORY: &[usize] = &[115898, 116998];
81+
pub const CONFIG_CHANGE_HISTORY: &[usize] = &[115898, 116998, 116881];
8282

8383
/// Extra --check-cfg to add when building
8484
/// (Mode restriction, config name, config values (if any))

0 commit comments

Comments
 (0)