Skip to content

Commit cfe2253

Browse files
authored
Rollup merge of #80932 - jyn514:download-windows-llvm, r=Mark-Simulacrum
Allow downloading LLVM on Windows and MacOS - Don't ignore packaging `llvm/lib/` for `rust-dev` when LLVM is linked statically - Add `link-type.txt` so bootstrap knows whether llvm was linked statically or dynamically - Don't assume CI LLVM is linked dynamically in `bootstrap::config` - Fall back to dynamic linking if `link-type.txt` doesn't exist - Fix existing bug that split the output of `llvm-config` on lines, not spaces - Only special case MacOS when dynamic linking. Static linking works fine. - Enable building LLVM tests This works around the following llvm bug: ``` llvm-config: error: component libraries and shared library llvm-config: error: missing: /home/joshua/rustc2/build/x86_64-unknown-linux-gnu/llvm/build/lib/libgtest.a llvm-config: error: missing: /home/joshua/rustc2/build/x86_64-unknown-linux-gnu/llvm/build/lib/libgtest_main.a llvm-config: error: missing: /home/joshua/rustc2/build/x86_64-unknown-linux-gnu/llvm/build/lib/libLLVMTestingSupport.a thread 'main' panicked at 'command did not execute successfully: "/home/joshua/rustc2/build/x86_64-unknown-linux-gnu/llvm/build/bin/llvm-config" "--libfiles" ``` I'm not sure why llvm-config thinks these are required, but to avoid the error, this builds them anyway. - Bump version of `download-ci-llvm-stamp` `src/llvm-project` hasn't changed, but the generated tarball has. Fixes #77084. # Current Status This works on both MacOS and Windows! 🎉 🎉 Thanks to ```@nagisa,``` ```@halkcyon,``` ```@Lokathor,``` ```@jryans,``` and ```@poliorcetics``` for helping me test! The `if-available` check now supports all tier 1 platforms. Although only x64 apple and x64 msvc have been tested, none of the changes here are Windows or Mac specific, and I expect this to work anywhere that LLVM artifacts are uploaded to CI (i.e. the `rust-dev` component exists). ## Windows Note that if you have an old version of MSVC build tools you'll need to update them. VS Build Tools 2019 14.28 and later are known to work. With old tools, you may see an error like the following: ``` error LNK2001: unresolved external symbol __imp___std_init_once_complete ```
2 parents ffcbeef + 5c4adbe commit cfe2253

File tree

6 files changed

+54
-26
lines changed

6 files changed

+54
-26
lines changed

config.toml.example

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ changelog-seen = 2
3535
# Unless you're developing for a target where Rust CI doesn't build a compiler
3636
# toolchain or changing LLVM locally, you probably want to set this to true.
3737
#
38-
# It's currently false by default due to being newly added; please file bugs if
39-
# enabling this did not work for you on x86_64-unknown-linux-gnu.
40-
# Other target triples are currently not supported; see #77084.
38+
# This is false by default so that distributions don't unexpectedly download
39+
# LLVM from the internet.
40+
#
41+
# All tier 1 targets are currently supported; set this to `"if-supported"` if
42+
# you are not sure whether you're on a tier 1 target.
4143
#
4244
# We also currently only support this when building LLVM for the build triple.
4345
#

src/bootstrap/bootstrap.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,21 @@ def download_stage0(self):
465465

466466
def downloading_llvm(self):
467467
opt = self.get_toml('download-ci-llvm', 'llvm')
468+
# This is currently all tier 1 targets (since others may not have CI
469+
# artifacts)
470+
# https://doc.rust-lang.org/rustc/platform-support.html#tier-1
471+
supported_platforms = [
472+
"aarch64-unknown-linux-gnu",
473+
"i686-pc-windows-gnu",
474+
"i686-pc-windows-msvc",
475+
"i686-unknown-linux-gnu",
476+
"x86_64-unknown-linux-gnu",
477+
"x86_64-apple-darwin",
478+
"x86_64-pc-windows-gnu",
479+
"x86_64-pc-windows-msvc",
480+
]
468481
return opt == "true" \
469-
or (opt == "if-available" and self.build == "x86_64-unknown-linux-gnu")
482+
or (opt == "if-available" and self.build in supported_platforms)
470483

471484
def _download_stage0_helper(self, filename, pattern, tarball_suffix, date=None):
472485
if date is None:

src/bootstrap/config.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,10 @@ impl Config {
816816
check_ci_llvm!(llvm.allow_old_toolchain);
817817
check_ci_llvm!(llvm.polly);
818818

819-
// CI-built LLVM is shared
820-
config.llvm_link_shared = true;
819+
// CI-built LLVM can be either dynamic or static.
820+
let ci_llvm = config.out.join(&*config.build.triple).join("ci-llvm");
821+
let link_type = t!(std::fs::read_to_string(ci_llvm.join("link-type.txt")));
822+
config.llvm_link_shared = link_type == "dynamic";
821823
}
822824

823825
if config.llvm_thin_lto {

src/bootstrap/dist.rs

+30-18
Original file line numberDiff line numberDiff line change
@@ -1800,19 +1800,11 @@ fn add_env(builder: &Builder<'_>, cmd: &mut Command, target: TargetSelection) {
18001800
}
18011801
}
18021802

1803-
/// Maybe add libLLVM.so to the given destination lib-dir. It will only have
1804-
/// been built if LLVM tools are linked dynamically.
1803+
/// Maybe add LLVM object files to the given destination lib-dir. Allows either static or dynamic linking.
18051804
///
1806-
/// Note: This function does not yet support Windows, but we also don't support
1807-
/// linking LLVM tools dynamically on Windows yet.
1808-
fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir: &Path) {
1809-
if !builder.config.llvm_link_shared {
1810-
// We do not need to copy LLVM files into the sysroot if it is not
1811-
// dynamically linked; it is already included into librustc_llvm
1812-
// statically.
1813-
return;
1814-
}
18151805
1806+
/// Returns whether the files were actually copied.
1807+
fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir: &Path) -> bool {
18161808
if let Some(config) = builder.config.target_config.get(&target) {
18171809
if config.llvm_config.is_some() && !builder.config.llvm_from_ci {
18181810
// If the LLVM was externally provided, then we don't currently copy
@@ -1828,7 +1820,7 @@ fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir
18281820
//
18291821
// If the LLVM is coming from ourselves (just from CI) though, we
18301822
// still want to install it, as it otherwise won't be available.
1831-
return;
1823+
return false;
18321824
}
18331825
}
18341826

@@ -1837,31 +1829,48 @@ fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir
18371829
// clear why this is the case, though. llvm-config will emit the versioned
18381830
// paths and we don't want those in the sysroot (as we're expecting
18391831
// unversioned paths).
1840-
if target.contains("apple-darwin") {
1832+
if target.contains("apple-darwin") && builder.config.llvm_link_shared {
18411833
let src_libdir = builder.llvm_out(target).join("lib");
18421834
let llvm_dylib_path = src_libdir.join("libLLVM.dylib");
18431835
if llvm_dylib_path.exists() {
18441836
builder.install(&llvm_dylib_path, dst_libdir, 0o644);
18451837
}
1838+
!builder.config.dry_run
18461839
} else if let Ok(llvm_config) = crate::native::prebuilt_llvm_config(builder, target) {
1847-
let files = output(Command::new(llvm_config).arg("--libfiles"));
1848-
for file in files.lines() {
1840+
let mut cmd = Command::new(llvm_config);
1841+
cmd.arg("--libfiles");
1842+
builder.verbose(&format!("running {:?}", cmd));
1843+
let files = output(&mut cmd);
1844+
for file in files.trim_end().split(' ') {
18491845
builder.install(Path::new(file), dst_libdir, 0o644);
18501846
}
1847+
!builder.config.dry_run
1848+
} else {
1849+
false
18511850
}
18521851
}
18531852

18541853
/// Maybe add libLLVM.so to the target lib-dir for linking.
18551854
pub fn maybe_install_llvm_target(builder: &Builder<'_>, target: TargetSelection, sysroot: &Path) {
18561855
let dst_libdir = sysroot.join("lib/rustlib").join(&*target.triple).join("lib");
1857-
maybe_install_llvm(builder, target, &dst_libdir);
1856+
// We do not need to copy LLVM files into the sysroot if it is not
1857+
// dynamically linked; it is already included into librustc_llvm
1858+
// statically.
1859+
if builder.config.llvm_link_shared {
1860+
maybe_install_llvm(builder, target, &dst_libdir);
1861+
}
18581862
}
18591863

18601864
/// Maybe add libLLVM.so to the runtime lib-dir for rustc itself.
18611865
pub fn maybe_install_llvm_runtime(builder: &Builder<'_>, target: TargetSelection, sysroot: &Path) {
18621866
let dst_libdir =
18631867
sysroot.join(builder.sysroot_libdir_relative(Compiler { stage: 1, host: target }));
1864-
maybe_install_llvm(builder, target, &dst_libdir);
1868+
// We do not need to copy LLVM files into the sysroot if it is not
1869+
// dynamically linked; it is already included into librustc_llvm
1870+
// statically.
1871+
if builder.config.llvm_link_shared {
1872+
maybe_install_llvm(builder, target, &dst_libdir);
1873+
}
18651874
}
18661875

18671876
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
@@ -1973,7 +1982,10 @@ impl Step for RustDev {
19731982
// `$ORIGIN/../lib` can find it. It may also be used as a dependency
19741983
// of `rustc-dev` to support the inherited `-lLLVM` when using the
19751984
// compiler libraries.
1976-
maybe_install_llvm(builder, target, &tarball.image_dir().join("lib"));
1985+
let dst_libdir = tarball.image_dir().join("lib");
1986+
maybe_install_llvm(builder, target, &dst_libdir);
1987+
let link_type = if builder.config.llvm_link_shared { "dynamic" } else { "static" };
1988+
t!(std::fs::write(tarball.image_dir().join("link-type.txt"), link_type), dst_libdir);
19771989

19781990
Some(tarball.generate())
19791991
}

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/80087
4+
Last change is for: https://github.com/rust-lang/rust/pull/80932

src/bootstrap/native.rs

-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ impl Step for Llvm {
171171
.define("LLVM_TARGETS_TO_BUILD", llvm_targets)
172172
.define("LLVM_EXPERIMENTAL_TARGETS_TO_BUILD", llvm_exp_targets)
173173
.define("LLVM_INCLUDE_EXAMPLES", "OFF")
174-
.define("LLVM_INCLUDE_TESTS", "OFF")
175174
.define("LLVM_INCLUDE_DOCS", "OFF")
176175
.define("LLVM_INCLUDE_BENCHMARKS", "OFF")
177176
.define("LLVM_ENABLE_TERMINFO", "OFF")

0 commit comments

Comments
 (0)