Skip to content

Commit 19e1aac

Browse files
committed
Auto merge of rust-lang#77756 - alarsyo:setup-llvm-detect, r=jyn514
Detect configuration for LLVM during setup This is a first draft to address rust-lang#77579, setting `download-ci-llvm` to true on Linux, but I could also implement the `if-available` setting mentioned in the issue. On other platforms I was thinking about using [the which crate](https://crates.io/crates/which), if adding a dependency on it is considered okay of course, to detect the presence of `llvm-config` in the path, and use it if found. Still a work in progress of course.
2 parents f42692b + b8ae4c5 commit 19e1aac

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

src/bootstrap/bootstrap.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,8 @@ def download_stage0(self):
447447

448448
def downloading_llvm(self):
449449
opt = self.get_toml('download-ci-llvm', 'llvm')
450-
return opt == "true"
450+
return opt == "true" \
451+
or (opt == "if-available" and self.build == "x86_64-unknown-linux-gnu")
451452

452453
def _download_stage0_helper(self, filename, pattern, tarball_suffix, date=None):
453454
if date is None:
@@ -892,7 +893,7 @@ def update_submodules(self):
892893
submodules_names = []
893894
for module in submodules:
894895
if module.endswith("llvm-project"):
895-
if self.get_toml('llvm-config') or self.get_toml('download-ci-llvm') == 'true':
896+
if self.get_toml('llvm-config') or self.downloading_llvm():
896897
if self.get_toml('lld') != 'true':
897898
continue
898899
check = self.check_submodule(module, slow_submodules)
@@ -1003,6 +1004,16 @@ def bootstrap(help_triggered):
10031004
with open(toml_path) as config:
10041005
build.config_toml = config.read()
10051006

1007+
profile = build.get_toml('profile')
1008+
if profile is not None:
1009+
include_file = 'config.{}.toml'.format(profile)
1010+
include_dir = os.path.join(build.rust_root, 'src', 'bootstrap', 'defaults')
1011+
include_path = os.path.join(include_dir, include_file)
1012+
# HACK: This works because `build.get_toml()` returns the first match it finds for a
1013+
# specific key, so appending our defaults at the end allows the user to override them
1014+
with open(include_path) as included_toml:
1015+
build.config_toml += os.linesep + included_toml.read()
1016+
10061017
config_verbose = build.get_toml('verbose', 'build')
10071018
if config_verbose is not None:
10081019
build.verbose = max(build.verbose, int(config_verbose))

src/bootstrap/config.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ struct Llvm {
391391
use_libcxx: Option<bool>,
392392
use_linker: Option<String>,
393393
allow_old_toolchain: Option<bool>,
394-
download_ci_llvm: Option<bool>,
394+
download_ci_llvm: Option<StringOrBool>,
395395
}
396396

397397
#[derive(Deserialize, Default, Clone, Merge)]
@@ -735,7 +735,14 @@ impl Config {
735735
set(&mut config.llvm_use_libcxx, llvm.use_libcxx);
736736
config.llvm_use_linker = llvm.use_linker.clone();
737737
config.llvm_allow_old_toolchain = llvm.allow_old_toolchain;
738-
config.llvm_from_ci = llvm.download_ci_llvm.unwrap_or(false);
738+
config.llvm_from_ci = match llvm.download_ci_llvm {
739+
Some(StringOrBool::String(s)) => {
740+
assert!(s == "if-available", "unknown option `{}` for download-ci-llvm", s);
741+
config.build.triple == "x86_64-unknown-linux-gnu"
742+
}
743+
Some(StringOrBool::Bool(b)) => b,
744+
None => false,
745+
};
739746

740747
if config.llvm_from_ci {
741748
// None of the LLVM options, except assertions, are supported

src/bootstrap/defaults/config.compiler.toml

+5
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@
66
debug-logging = true
77
# This greatly increases the speed of rebuilds, especially when there are only minor changes. However, it makes the initial build slightly slower.
88
incremental = true
9+
10+
[llvm]
11+
# Will download LLVM from CI if available on your platform (Linux only for now)
12+
# https://github.com/rust-lang/rust/issues/77084 tracks support for more platforms
13+
download-ci-llvm = "if-available"

src/bootstrap/defaults/config.library.toml

+5
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ bench-stage = 0
88
[rust]
99
# This greatly increases the speed of rebuilds, especially when there are only minor changes. However, it makes the initial build slightly slower.
1010
incremental = true
11+
12+
[llvm]
13+
# Will download LLVM from CI if available on your platform (Linux only for now)
14+
# https://github.com/rust-lang/rust/issues/77084 tracks support for more platforms
15+
download-ci-llvm = "if-available"

0 commit comments

Comments
 (0)