Skip to content

Commit 615b485

Browse files
committed
Update version of cc crate to v1.0.97
Reason: In order to build the Windows version of the Rust toolchain for the Android platform, the following patch to the cc is crate is required to avoid incorrectly determining that we are building with the Android NDK: rust-lang/cc-rs@57853c4 This patch is present in version 1.0.80 and newer versions of the cc crate. The rustc source distribution currently has 3 different versions of cc in the vendor directory, only one of which has the necessary fix. We (the Android Rust toolchain) are currently maintaining local patches to upgrade the cc crate dependency versions, which we would like to upstream. Furthermore, beyond the specific reason, the cc crate in bootstrap is currently pinned at an old version due to problems in the past when trying to update it. It is worthwhile to figure out and resolve these problems so we can keep the dependency up-to-date. Other fixes: As of cc v1.0.78, object files are prefixed with a 16-character hash. Update src/bootstrap/src/core/build_steps/llvm.rs to account for this to avoid failures when building libunwind and libcrt. Note that while the hash prefix was introduced in v1.0.78, in order to determine the names of the object files without scanning the directory, we rely on the compile_intermediates method, which was introduced in cc v1.0.86 As of cc v1.0.86, compilation on MacOS uses the -mmacosx-version-min flag. A long-standing bug in the CMake rules for compiler-rt causes compilation to fail when this flag is specified. So we add a workaround to suppress this flag. Updating to cc v1.0.91 and newer requires fixes to bootstrap unit tests. The unit tests use targets named "A", "B", etc., which fail a validation check introduced in 1.0.91 of the cc crate.
1 parent 25e3949 commit 615b485

File tree

7 files changed

+116
-72
lines changed

7 files changed

+116
-72
lines changed

Diff for: src/bootstrap/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ dependencies = [
9898

9999
[[package]]
100100
name = "cc"
101-
version = "1.0.73"
101+
version = "1.0.97"
102102
source = "registry+https://github.com/rust-lang/crates.io-index"
103-
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
103+
checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4"
104104

105105
[[package]]
106106
name = "cfg-if"

Diff for: src/bootstrap/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ test = false
3636
# Most of the time updating these dependencies requires modifications to the
3737
# bootstrap codebase(e.g., https://github.com/rust-lang/rust/issues/124565);
3838
# otherwise, some targets will fail. That's why these dependencies are explicitly pinned.
39-
cc = "=1.0.73"
39+
cc = "=1.0.97"
4040
cmake = "=0.1.48"
4141

4242
build_helper = { path = "../tools/build_helper" }

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

+47-12
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ use std::sync::OnceLock;
2020
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
2121
use crate::core::config::{Config, TargetSelection};
2222
use crate::utils::channel;
23-
use crate::utils::helpers::{self, exe, get_clang_cl_resource_dir, output, t, up_to_date};
23+
use crate::utils::helpers::{
24+
self, exe, get_clang_cl_resource_dir, output, t, unhashed_basename, up_to_date,
25+
};
2426
use crate::{generate_smart_stamp_hash, CLang, GitRepo, Kind};
2527

2628
use build_helper::ci::CiEnv;
@@ -506,7 +508,7 @@ impl Step for Llvm {
506508
cfg.define("LLVM_VERSION_SUFFIX", suffix);
507509
}
508510

509-
configure_cmake(builder, target, &mut cfg, true, ldflags, &[]);
511+
configure_cmake(builder, target, &mut cfg, true, ldflags, &[], &[]);
510512
configure_llvm(builder, target, &mut cfg);
511513

512514
for (key, val) in &builder.config.llvm_build_config {
@@ -596,6 +598,7 @@ fn configure_cmake(
596598
use_compiler_launcher: bool,
597599
mut ldflags: LdFlags,
598600
extra_compiler_flags: &[&str],
601+
suppressed_compiler_flag_prefixes: &[&str],
599602
) {
600603
// Do not print installation messages for up-to-date files.
601604
// LLVM and LLD builds can produce a lot of those and hit CI limits on log size.
@@ -729,7 +732,17 @@ fn configure_cmake(
729732
}
730733

731734
cfg.build_arg("-j").build_arg(builder.jobs().to_string());
732-
let mut cflags: OsString = builder.cflags(target, GitRepo::Llvm, CLang::C).join(" ").into();
735+
let mut cflags: OsString = builder
736+
.cflags(target, GitRepo::Llvm, CLang::C)
737+
.into_iter()
738+
.filter(|flag| {
739+
!suppressed_compiler_flag_prefixes
740+
.iter()
741+
.any(|suppressed_prefix| flag.starts_with(suppressed_prefix))
742+
})
743+
.collect::<Vec<String>>()
744+
.join(" ")
745+
.into();
733746
if let Some(ref s) = builder.config.llvm_cflags {
734747
cflags.push(" ");
735748
cflags.push(s);
@@ -742,7 +755,17 @@ fn configure_cmake(
742755
cflags.push(&format!(" {flag}"));
743756
}
744757
cfg.define("CMAKE_C_FLAGS", cflags);
745-
let mut cxxflags: OsString = builder.cflags(target, GitRepo::Llvm, CLang::Cxx).join(" ").into();
758+
let mut cxxflags: OsString = builder
759+
.cflags(target, GitRepo::Llvm, CLang::Cxx)
760+
.into_iter()
761+
.filter(|flag| {
762+
!suppressed_compiler_flag_prefixes
763+
.iter()
764+
.any(|suppressed_prefix| flag.starts_with(suppressed_prefix))
765+
})
766+
.collect::<Vec<String>>()
767+
.join(" ")
768+
.into();
746769
if let Some(ref s) = builder.config.llvm_cxxflags {
747770
cxxflags.push(" ");
748771
cxxflags.push(s);
@@ -921,7 +944,7 @@ impl Step for Lld {
921944
ldflags.push_all("-Wl,-rpath,'$ORIGIN/../../../'");
922945
}
923946

924-
configure_cmake(builder, target, &mut cfg, true, ldflags, &[]);
947+
configure_cmake(builder, target, &mut cfg, true, ldflags, &[], &[]);
925948
configure_llvm(builder, target, &mut cfg);
926949

927950
// Re-use the same flags as llvm to control the level of debug information
@@ -1022,13 +1045,20 @@ impl Step for Sanitizers {
10221045
let use_compiler_launcher = !self.target.contains("apple-darwin");
10231046
let extra_compiler_flags: &[&str] =
10241047
if self.target.contains("apple") { &["-fembed-bitcode=off"] } else { &[] };
1048+
// Since v1.0.86, the cc crate adds -mmacosx-version-min to the default
1049+
// flags on MacOS. A long-standing bug in the CMake rules for compiler-rt
1050+
// causes architecture detection to be skipped when this flag is present,
1051+
// and compilation fails. https://github.com/llvm/llvm-project/issues/88780
1052+
let suppressed_compiler_flag_prefixes: &[&str] =
1053+
if self.target.contains("apple-darwin") { &["-mmacosx-version-min="] } else { &[] };
10251054
configure_cmake(
10261055
builder,
10271056
self.target,
10281057
&mut cfg,
10291058
use_compiler_launcher,
10301059
LdFlags::default(),
10311060
extra_compiler_flags,
1061+
suppressed_compiler_flag_prefixes,
10321062
);
10331063

10341064
t!(fs::create_dir_all(&out_dir));
@@ -1190,7 +1220,7 @@ impl Step for CrtBeginEnd {
11901220

11911221
let crtbegin_src = builder.src.join("src/llvm-project/compiler-rt/lib/builtins/crtbegin.c");
11921222
let crtend_src = builder.src.join("src/llvm-project/compiler-rt/lib/builtins/crtend.c");
1193-
if up_to_date(&crtbegin_src, &out_dir.join("crtbegin.o"))
1223+
if up_to_date(&crtbegin_src, &out_dir.join("crtbeginS.o"))
11941224
&& up_to_date(&crtend_src, &out_dir.join("crtendS.o"))
11951225
{
11961226
return out_dir;
@@ -1222,10 +1252,15 @@ impl Step for CrtBeginEnd {
12221252
.define("CRT_HAS_INITFINI_ARRAY", None)
12231253
.define("EH_USE_FRAME_REGISTRY", None);
12241254

1225-
cfg.compile("crt");
1255+
let objs = cfg.compile_intermediates();
1256+
assert_eq!(objs.len(), 2);
1257+
for obj in objs {
1258+
let base_name = unhashed_basename(&obj);
1259+
assert!(base_name == "crtbegin" || base_name == "crtend");
1260+
t!(fs::copy(&obj, out_dir.join(format!("{}S.o", base_name))));
1261+
t!(fs::rename(&obj, out_dir.join(format!("{}.o", base_name))));
1262+
}
12261263

1227-
t!(fs::copy(out_dir.join("crtbegin.o"), out_dir.join("crtbeginS.o")));
1228-
t!(fs::copy(out_dir.join("crtend.o"), out_dir.join("crtendS.o")));
12291264
out_dir
12301265
}
12311266
}
@@ -1372,9 +1407,9 @@ impl Step for Libunwind {
13721407
for entry in fs::read_dir(&out_dir).unwrap() {
13731408
let file = entry.unwrap().path().canonicalize().unwrap();
13741409
if file.is_file() && file.extension() == Some(OsStr::new("o")) {
1375-
// file name starts with "Unwind-EHABI", "Unwind-seh" or "libunwind"
1376-
let file_name = file.file_name().unwrap().to_str().expect("UTF-8 file name");
1377-
if cpp_sources.iter().any(|f| file_name.starts_with(&f[..f.len() - 4])) {
1410+
// Object file name without the hash prefix is "Unwind-EHABI", "Unwind-seh" or "libunwind".
1411+
let base_name = unhashed_basename(&file);
1412+
if cpp_sources.iter().any(|f| *base_name == f[..f.len() - 4]) {
13781413
cc_cfg.object(&file);
13791414
count += 1;
13801415
}

0 commit comments

Comments
 (0)