@@ -114,23 +114,20 @@ pub fn prebuilt_llvm_config(
114114 Err ( Meta { stamp, build_llvm_config, out_dir, root : root. into ( ) } )
115115}
116116
117- pub ( crate ) fn maybe_download_ci_llvm ( builder : & Builder < ' _ > ) {
118- let config = & builder. config ;
119- if !config. llvm_from_ci {
120- return ;
121- }
117+ /// This retrieves the LLVM sha we *want* to use, according to git history.
118+ pub ( crate ) fn detect_llvm_sha ( config : & crate :: config:: Config ) -> String {
122119 let mut rev_list = config. git ( ) ;
123120 rev_list. args ( & [
124121 PathBuf :: from ( "rev-list" ) ,
125- format ! ( "--author={}" , builder . config. stage0_metadata. config. git_merge_commit_email) . into ( ) ,
122+ format ! ( "--author={}" , config. stage0_metadata. config. git_merge_commit_email) . into ( ) ,
126123 "-n1" . into ( ) ,
127124 "--first-parent" . into ( ) ,
128125 "HEAD" . into ( ) ,
129126 "--" . into ( ) ,
130- builder . src . join ( "src/llvm-project" ) ,
131- builder . src . join ( "src/bootstrap/download-ci-llvm-stamp" ) ,
127+ config . src . join ( "src/llvm-project" ) ,
128+ config . src . join ( "src/bootstrap/download-ci-llvm-stamp" ) ,
132129 // the LLVM shared object file is named `LLVM-12-rust-{version}-nightly`
133- builder . src . join ( "src/version" ) ,
130+ config . src . join ( "src/version" ) ,
134131 ] ) ;
135132 let llvm_sha = output ( & mut rev_list) ;
136133 let llvm_sha = llvm_sha. trim ( ) ;
@@ -143,8 +140,76 @@ pub(crate) fn maybe_download_ci_llvm(builder: &Builder<'_>) {
143140 panic ! ( ) ;
144141 }
145142
143+ llvm_sha. to_owned ( )
144+ }
145+
146+ /// Returns whether the CI-found LLVM is currently usable.
147+ ///
148+ /// This checks both the build triple platform to confirm we're usable at all,
149+ /// and then verifies if the current HEAD matches the detected LLVM SHA head,
150+ /// in which case LLVM is indicated as not available.
151+ pub ( crate ) fn is_ci_llvm_available ( config : & crate :: config:: Config ) -> bool {
152+ // This is currently all tier 1 targets and tier 2 targets with host tools
153+ // (since others may not have CI artifacts)
154+ // https://doc.rust-lang.org/rustc/platform-support.html#tier-1
155+ let supported_platforms = [
156+ // tier 1
157+ "aarch64-unknown-linux-gnu" ,
158+ "i686-pc-windows-gnu" ,
159+ "i686-pc-windows-msvc" ,
160+ "i686-unknown-linux-gnu" ,
161+ "x86_64-unknown-linux-gnu" ,
162+ "x86_64-apple-darwin" ,
163+ "x86_64-pc-windows-gnu" ,
164+ "x86_64-pc-windows-msvc" ,
165+ // tier 2 with host tools
166+ "aarch64-apple-darwin" ,
167+ "aarch64-pc-windows-msvc" ,
168+ "aarch64-unknown-linux-musl" ,
169+ "arm-unknown-linux-gnueabi" ,
170+ "arm-unknown-linux-gnueabihf" ,
171+ "armv7-unknown-linux-gnueabihf" ,
172+ "mips-unknown-linux-gnu" ,
173+ "mips64-unknown-linux-gnuabi64" ,
174+ "mips64el-unknown-linux-gnuabi64" ,
175+ "mipsel-unknown-linux-gnu" ,
176+ "powerpc-unknown-linux-gnu" ,
177+ "powerpc64-unknown-linux-gnu" ,
178+ "powerpc64le-unknown-linux-gnu" ,
179+ "riscv64gc-unknown-linux-gnu" ,
180+ "s390x-unknown-linux-gnu" ,
181+ "x86_64-unknown-freebsd" ,
182+ "x86_64-unknown-illumos" ,
183+ "x86_64-unknown-linux-musl" ,
184+ "x86_64-unknown-netbsd" ,
185+ ] ;
186+ if !supported_platforms. contains ( & & * config. build . triple ) {
187+ return false ;
188+ }
189+
190+ if crate :: util:: CiEnv :: is_ci ( ) {
191+ let llvm_sha = detect_llvm_sha ( config) ;
192+ let head_sha = output ( config. git ( ) . arg ( "rev-parse" ) . arg ( "HEAD" ) ) ;
193+ let head_sha = head_sha. trim ( ) ;
194+ if llvm_sha == head_sha {
195+ eprintln ! (
196+ "Detected LLVM as non-available: running in CI and modified LLVM in this change"
197+ ) ;
198+ return false ;
199+ }
200+ }
201+
202+ true
203+ }
204+
205+ pub ( crate ) fn maybe_download_ci_llvm ( builder : & Builder < ' _ > ) {
206+ let config = & builder. config ;
207+ if !config. llvm_from_ci {
208+ return ;
209+ }
146210 let llvm_root = config. ci_llvm_root ( ) ;
147211 let llvm_stamp = llvm_root. join ( ".llvm-stamp" ) ;
212+ let llvm_sha = detect_llvm_sha ( & config) ;
148213 let key = format ! ( "{}{}" , llvm_sha, config. llvm_assertions) ;
149214 if program_out_of_date ( & llvm_stamp, & key) && !config. dry_run {
150215 download_ci_llvm ( builder, & llvm_sha) ;
0 commit comments