Change:
From Switching to static linking would preclude any of the improvements from , so it would be better to use dynamic linking instead which would allow any contributor to get started without building LLVM from source or using system LLVM. That said, it sounds like dynamic linking will be very hard to do on other platforms. cc
Cc - do we know what the right way to bring the issues (bugs?) I found to LLVM developers? Are there active maintainers of LLVMs build system?
LLVM’s bugzilla is pretty much the only place for bug reports. If its something less defined than a precise bug report, talking it out on the mailing lists is the way to go.
In which way is static linking making downloaded LLVM impossible?
I don't think it's impossible to download/ship the statically linked LLVM, it's something I want to explore. That said, we want to move to dynamically linking LLVM because we ideally want to be applying ThinLTO to LLVM everywhere, not just on x86_64-unknown-linux-gnu, and since LTO happens at link-time, we want that to happen once, not on the multiple LLVM links occurring during CI.

Discussion:
# Unless you're developing for a target where Rust CI doesn't build a compiler # toolchain or changing LLVM locally, you probably want to set this to true. # <del> # It's currently false by default due to being newly added; please file bugs if # enabling this did not work for you on x86_64-unknown-linux-gnu. # Other target triples are currently not supported; see #77084. </del> <ins> # This is false by default so that distributions don't unexpectedly download # LLVM from the internet. # # All tier 1 targets are currently supported; set this to `"if-supported"` if # you are not sure whether you're on a tier 1 target. </ins> # # We also currently only support this when building LLVM for the build triple. #

def downloading_llvm(self): opt = self.get_toml('download-ci-llvm', 'llvm') <ins> # This is currently all tier 1 targets (since others may not have CI # artifacts) # https://doc.rust-lang.org/rustc/platform-support.html#tier-1 supported_platforms = [ "aarch64-unknown-linux-gnu", "i686-pc-windows-gnu", "i686-pc-windows-msvc", "i686-unknown-linux-gnu", "x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-gnu", "x86_64-pc-windows-msvc", ] </ins> return opt == "true"  <del> or (opt == "if-available" and self.build == "x86_64-unknown-linux-gnu") </del> <ins> or (opt == "if-available" and self.build in supported_platforms) </ins> def _download_stage0_helper(self, filename, pattern, tarball_suffix, date=None): if date is None:

check_ci_llvm!(llvm.allow_old_toolchain); check_ci_llvm!(llvm.polly); <del> // CI-built LLVM is shared config.llvm_link_shared = true; </del> <ins> // CI-built LLVM can be either dynamic or static. let ci_llvm = config.out.join(&*config.build.triple).join("ci-llvm"); let link_type = t!(std::fs::read_to_string(ci_llvm.join("link-type.txt"))); config.llvm_link_shared = link_type == "dynamic"; </ins> } if config.llvm_thin_lto {

} } <del> /// Maybe add libLLVM.so to the given destination lib-dir. It will only have /// been built if LLVM tools are linked dynamically. </del> <ins> /// Maybe add LLVM object files to the given destination lib-dir. Allows either static or dynamic linking. </ins> /// <del> /// Note: This function does not yet support Windows, but we also don't support ///       linking LLVM tools dynamically on Windows yet. fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir: &Path) { if !builder.config.llvm_link_shared { // We do not need to copy LLVM files into the sysroot if it is not // dynamically linked; it is already included into librustc_llvm // statically. return; } </del> <ins> /// Returns whether the files were actually copied. fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir: &Path) -> bool { </ins> if let Some(config) = builder.config.target_config.get(&target) { if config.llvm_config.is_some() && !builder.config.llvm_from_ci { // If the LLVM was externally provided, then we don't currently copy

// // If the LLVM is coming from ourselves (just from CI) though, we // still want to install it, as it otherwise won't be available. <del> return; </del> <ins> return false; </ins> } }

// clear why this is the case, though. llvm-config will emit the versioned // paths and we don't want those in the sysroot (as we're expecting // unversioned paths). <del> if target.contains("apple-darwin") { </del> <ins> if target.contains("apple-darwin") && builder.config.llvm_link_shared { </ins> let src_libdir = builder.llvm_out(target).join("lib"); let llvm_dylib_path = src_libdir.join("libLLVM.dylib"); if llvm_dylib_path.exists() { builder.install(&llvm_dylib_path, dst_libdir, 0o644); } <ins> !builder.config.dry_run </ins> } else if let Ok(llvm_config) = crate::native::prebuilt_llvm_config(builder, target) { <del> let files = output(Command::new(llvm_config).arg("--libfiles")); for file in files.lines() { </del> <ins> let mut cmd = Command::new(llvm_config); cmd.arg("--libfiles"); builder.verbose(&format!("running {:?}", cmd)); let files = output(&mut cmd); for file in files.trim_end().split(' ') { </ins> builder.install(Path::new(file), dst_libdir, 0o644); } <ins> !builder.config.dry_run } else { false </ins> } } /// Maybe add libLLVM.so to the target lib-dir for linking. pub fn maybe_install_llvm_target(builder: &Builder<'_>, target: TargetSelection, sysroot: &Path) { let dst_libdir = sysroot.join("lib/rustlib").join(&*target.triple).join("lib"); <del> maybe_install_llvm(builder, target, &dst_libdir); </del> <ins> // We do not need to copy LLVM files into the sysroot if it is not // dynamically linked; it is already included into librustc_llvm // statically. if builder.config.llvm_link_shared { maybe_install_llvm(builder, target, &dst_libdir); } </ins> } /// Maybe add libLLVM.so to the runtime lib-dir for rustc itself. pub fn maybe_install_llvm_runtime(builder: &Builder<'_>, target: TargetSelection, sysroot: &Path) { let dst_libdir = sysroot.join(builder.sysroot_libdir_relative(Compiler { stage: 1, host: target })); <del> maybe_install_llvm(builder, target, &dst_libdir); </del> <ins> // We do not need to copy LLVM files into the sysroot if it is not // dynamically linked; it is already included into librustc_llvm // statically. if builder.config.llvm_link_shared { maybe_install_llvm(builder, target, &dst_libdir); } </ins> } #[derive(Clone, Debug, Eq, Hash, PartialEq)]

// `$ORIGIN/../lib` can find it. It may also be used as a dependency // of `rustc-dev` to support the inherited `-lLLVM` when using the // compiler libraries. <del> maybe_install_llvm(builder, target, &tarball.image_dir().join("lib")); </del> <ins> let dst_libdir = tarball.image_dir().join("lib"); maybe_install_llvm(builder, target, &dst_libdir); let link_type = if builder.config.llvm_link_shared { "dynamic" } else { "static" }; t!(std::fs::write(tarball.image_dir().join("link-type.txt"), link_type), dst_libdir); </ins> Some(tarball.generate()) }

Change this file to make users of the `download-ci-llvm` configuration download a new version of LLVM from CI, even if the LLVM submodule hasn’t changed. <del> Last change is for: https://github.com/rust-lang/rust/pull/80087 </del> <ins> Last change is for: https://github.com/rust-lang/rust/pull/80932 </ins>

.define("LLVM_TARGETS_TO_BUILD", llvm_targets) .define("LLVM_EXPERIMENTAL_TARGETS_TO_BUILD", llvm_exp_targets) .define("LLVM_INCLUDE_EXAMPLES", "OFF") <del> .define("LLVM_INCLUDE_TESTS", "OFF") </del> .define("LLVM_INCLUDE_DOCS", "OFF") .define("LLVM_INCLUDE_BENCHMARKS", "OFF") .define("LLVM_ENABLE_TERMINFO", "OFF")