Skip to content

Commit

Permalink
use if-unchanged only when ci rustc is available
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <work@onurozkan.dev>
  • Loading branch information
onur-ozkan committed Oct 8, 2024
1 parent b21949b commit eb5e623
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::core::build_steps::compile::CODEGEN_BACKEND_PREFIX;
use crate::core::build_steps::llvm;
pub use crate::core::config::flags::Subcommand;
use crate::core::config::flags::{Color, Flags, Warnings};
use crate::core::download::is_download_ci_available;
use crate::utils::cache::{INTERNER, Interned};
use crate::utils::channel::{self, GitInfo};
use crate::utils::helpers::{self, exe, output, t};
Expand Down Expand Up @@ -1627,9 +1628,11 @@ impl Config {
config.mandir = mandir.map(PathBuf::from);
}

config.llvm_assertions =
toml.llvm.as_ref().map_or(false, |llvm| llvm.assertions.unwrap_or(false));

// Store off these values as options because if they're not provided
// we'll infer default values for them later
let mut llvm_assertions = None;
let mut llvm_tests = None;
let mut llvm_enzyme = None;
let mut llvm_plugins = None;
Expand Down Expand Up @@ -1712,7 +1715,8 @@ impl Config {
is_user_configured_rust_channel = channel.is_some();
set(&mut config.channel, channel.clone());

config.download_rustc_commit = config.download_ci_rustc_commit(download_rustc);
config.download_rustc_commit =
config.download_ci_rustc_commit(download_rustc, config.llvm_assertions);

debug = debug_toml;
debug_assertions = debug_assertions_toml;
Expand Down Expand Up @@ -1848,7 +1852,7 @@ impl Config {
optimize: optimize_toml,
thin_lto,
release_debuginfo,
assertions,
assertions: _,
tests,
enzyme,
plugins,
Expand Down Expand Up @@ -1882,7 +1886,6 @@ impl Config {
Some(StringOrBool::Bool(false)) | None => {}
}
set(&mut config.ninja_in_file, ninja);
llvm_assertions = assertions;
llvm_tests = tests;
llvm_enzyme = enzyme;
llvm_plugins = plugins;
Expand Down Expand Up @@ -1911,8 +1914,8 @@ impl Config {
config.llvm_enable_warnings = enable_warnings.unwrap_or(false);
config.llvm_build_config = build_config.clone().unwrap_or(Default::default());

let asserts = llvm_assertions.unwrap_or(false);
config.llvm_from_ci = config.parse_download_ci_llvm(download_ci_llvm, asserts);
config.llvm_from_ci =
config.parse_download_ci_llvm(download_ci_llvm, config.llvm_assertions);

if config.llvm_from_ci {
let warn = |option: &str| {
Expand Down Expand Up @@ -2080,7 +2083,6 @@ impl Config {
// Now that we've reached the end of our configuration, infer the
// default values for all options that we haven't otherwise stored yet.

config.llvm_assertions = llvm_assertions.unwrap_or(false);
config.llvm_tests = llvm_tests.unwrap_or(false);
config.llvm_enzyme = llvm_enzyme.unwrap_or(false);
config.llvm_plugins = llvm_plugins.unwrap_or(false);
Expand Down Expand Up @@ -2711,12 +2713,18 @@ impl Config {
}

/// Returns the commit to download, or `None` if we shouldn't download CI artifacts.
fn download_ci_rustc_commit(&self, download_rustc: Option<StringOrBool>) -> Option<String> {
fn download_ci_rustc_commit(
&self,
download_rustc: Option<StringOrBool>,
llvm_assertions: bool,
) -> Option<String> {
// If `download-rustc` is not set, default to rebuilding.
let if_unchanged = match download_rustc {
None | Some(StringOrBool::Bool(false)) => return None,
Some(StringOrBool::Bool(true)) => false,
Some(StringOrBool::String(s)) if s == "if-unchanged" => true,
Some(StringOrBool::String(s)) if s == "if-unchanged" => {
is_download_ci_available(&self.build.triple, llvm_assertions)
}
Some(StringOrBool::String(other)) => {
panic!("unrecognized option for download-rustc: {other}")
}
Expand Down
40 changes: 40 additions & 0 deletions src/bootstrap/src/core/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,3 +832,43 @@ fn path_is_dylib(path: &Path) -> bool {
// The .so is not necessarily the extension, it might be libLLVM.so.18.1
path.to_str().map_or(false, |path| path.contains(".so"))
}

/// Checks whether the CI rustc is available for the given target triple.
pub(crate) fn is_download_ci_available(target_triple: &str, llvm_assertions: bool) -> bool {
// All tier 1 targets and tier 2 targets with host tools.
const SUPPORTED_PLATFORMS: &[&str] = &[
"aarch64-apple-darwin",
"aarch64-pc-windows-msvc",
"aarch64-unknown-linux-gnu",
"aarch64-unknown-linux-musl",
"arm-unknown-linux-gnueabi",
"arm-unknown-linux-gnueabihf",
"armv7-unknown-linux-gnueabihf",
"i686-pc-windows-gnu",
"i686-pc-windows-msvc",
"i686-unknown-linux-gnu",
"loongarch64-unknown-linux-gnu",
"powerpc-unknown-linux-gnu",
"powerpc64-unknown-linux-gnu",
"powerpc64le-unknown-linux-gnu",
"riscv64gc-unknown-linux-gnu",
"s390x-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-pc-windows-gnu",
"x86_64-pc-windows-msvc",
"x86_64-unknown-freebsd",
"x86_64-unknown-illumos",
"x86_64-unknown-linux-gnu",
"x86_64-unknown-linux-musl",
"x86_64-unknown-netbsd",
];

const SUPPORTED_PLATFORMS_WITH_ASSERTIONS: &[&str] =
&["x86_64-unknown-linux-gnu", "x86_64-pc-windows-msvc"];

if llvm_assertions {
SUPPORTED_PLATFORMS_WITH_ASSERTIONS.contains(&target_triple)
} else {
SUPPORTED_PLATFORMS.contains(&target_triple)
}
}

0 comments on commit eb5e623

Please sign in to comment.