Skip to content

Commit 73ff1d4

Browse files
committed
check host's libstdc++ version when using ci llvm
Signed-off-by: onur-ozkan <[email protected]>
1 parent 3a70a81 commit 73ff1d4

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

Diff for: src/bootstrap/src/core/build_steps/tool.rs

+54
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::core::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun,
1010
use crate::core::config::TargetSelection;
1111
use crate::utils::channel::GitInfo;
1212
use crate::utils::exec::BootstrapCommand;
13+
use crate::utils::helpers::output;
1314
use crate::utils::helpers::{add_dylib_path, exe, t};
1415
use crate::Compiler;
1516
use crate::Mode;
@@ -804,6 +805,59 @@ impl Step for LlvmBitcodeLinker {
804805
}
805806
}
806807

808+
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
809+
pub struct LibcxxVersionTool {
810+
pub target: TargetSelection,
811+
}
812+
813+
#[derive(Debug, Clone)]
814+
pub enum LibcxxVersion {
815+
Gnu(usize),
816+
#[allow(dead_code)]
817+
Llvm(usize),
818+
}
819+
820+
impl Step for LibcxxVersionTool {
821+
type Output = LibcxxVersion;
822+
const DEFAULT: bool = false;
823+
const ONLY_HOSTS: bool = true;
824+
825+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
826+
run.never()
827+
}
828+
829+
fn run(self, builder: &Builder<'_>) -> LibcxxVersion {
830+
let out_dir = builder.out.join(self.target.to_string()).join("libcxx-version");
831+
let _ = fs::remove_dir_all(&out_dir);
832+
t!(fs::create_dir_all(&out_dir));
833+
834+
let compiler = builder.cxx(self.target).unwrap();
835+
let mut cmd = Command::new(compiler);
836+
837+
let executable = out_dir.join("libcxx-version");
838+
cmd.arg("-o").arg(&executable).arg(builder.src.join("src/tools/libcxx-version/main.cpp"));
839+
840+
builder.run_cmd(&mut cmd);
841+
842+
if !executable.exists() {
843+
panic!("Something went wrong. {} is not present", executable.display());
844+
}
845+
846+
let version_output = output(&mut Command::new(executable));
847+
848+
let version_str = version_output.split_once("version:").unwrap().1;
849+
let version = version_str.trim().parse::<usize>().unwrap();
850+
851+
if version_output.starts_with("libstdc++") {
852+
LibcxxVersion::Gnu(version)
853+
} else if version_output.starts_with("libc++") {
854+
LibcxxVersion::Llvm(version)
855+
} else {
856+
panic!("Coudln't recognize the standard library version.");
857+
}
858+
}
859+
}
860+
807861
macro_rules! tool_extended {
808862
(($sel:ident, $builder:ident),
809863
$($name:ident,

Diff for: src/bootstrap/src/core/sanity.rs

+35-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ use std::process::Command;
1818
#[cfg(not(feature = "bootstrap-self-test"))]
1919
use std::collections::HashSet;
2020

21-
use crate::builder::Kind;
21+
use crate::builder::{Builder, Kind};
22+
use crate::core::build_steps::tool;
2223
use crate::core::config::Target;
2324
use crate::utils::helpers::output;
2425
use crate::Build;
@@ -38,6 +39,10 @@ const STAGE0_MISSING_TARGETS: &[&str] = &[
3839
// just a dummy comment so the list doesn't get onelined
3940
];
4041

42+
/// Minimum version threshold for libstdc++ required when using prebuilt LLVM
43+
/// from CI (with`llvm.download-ci-llvm` option).
44+
const LIBSTDCXX_MIN_VERSION_THRESHOLD: usize = 8;
45+
4146
impl Finder {
4247
pub fn new() -> Self {
4348
Self { cache: HashMap::new(), path: env::var_os("PATH").unwrap_or_default() }
@@ -102,6 +107,35 @@ pub fn check(build: &mut Build) {
102107
cmd_finder.must_have("git");
103108
}
104109

110+
// Ensure that a compatible version of libstdc++ is available on the system when using `llvm.download-ci-llvm`.
111+
if !build.config.dry_run() && !build.build.is_msvc() && build.config.llvm_from_ci {
112+
let builder = Builder::new(build);
113+
let libcxx_version = builder.ensure(tool::LibcxxVersionTool { target: build.build });
114+
115+
match libcxx_version {
116+
tool::LibcxxVersion::Gnu(version) => {
117+
if LIBSTDCXX_MIN_VERSION_THRESHOLD > version {
118+
eprintln!(
119+
"\nYour system's libstdc++ version is too old for the `llvm.download-ci-llvm` option."
120+
);
121+
eprintln!("Current version detected: '{}'", version);
122+
eprintln!("Minimum required version: '{}'", LIBSTDCXX_MIN_VERSION_THRESHOLD);
123+
eprintln!(
124+
"Consider upgrading libstdc++ or disabling the `llvm.download-ci-llvm` option."
125+
);
126+
crate::exit!(1);
127+
}
128+
}
129+
tool::LibcxxVersion::Llvm(_) => {
130+
eprintln!(
131+
"\nYour system is using libc++, which is incompatible with the `llvm.download-ci-llvm` option."
132+
);
133+
eprintln!("Disable `llvm.download-ci-llvm` or switch to libstdc++.");
134+
crate::exit!(1);
135+
}
136+
}
137+
}
138+
105139
// We need cmake, but only if we're actually building LLVM or sanitizers.
106140
let building_llvm = build
107141
.hosts

0 commit comments

Comments
 (0)