-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
check host's libstdc++ version when using ci llvm #125411
Changes from all commits
3a70a81
73ff1d4
1a07e58
a2407e8
6bfdb04
dd99021
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,10 @@ use std::fs; | |
use std::path::PathBuf; | ||
use std::process::Command; | ||
|
||
#[cfg(not(feature = "bootstrap-self-test"))] | ||
use crate::builder::Builder; | ||
#[cfg(not(feature = "bootstrap-self-test"))] | ||
use crate::core::build_steps::tool; | ||
#[cfg(not(feature = "bootstrap-self-test"))] | ||
use std::collections::HashSet; | ||
|
||
|
@@ -38,6 +42,11 @@ const STAGE0_MISSING_TARGETS: &[&str] = &[ | |
// just a dummy comment so the list doesn't get onelined | ||
]; | ||
|
||
/// Minimum version threshold for libstdc++ required when using prebuilt LLVM | ||
/// from CI (with`llvm.download-ci-llvm` option). | ||
#[cfg(not(feature = "bootstrap-self-test"))] | ||
const LIBSTDCXX_MIN_VERSION_THRESHOLD: usize = 8; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is minimum really the right thing here? I'd expect that we need an exact match? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless there is a breaking change, different versions can be compatible (just like libc). It doesn't need to be the same version. |
||
|
||
impl Finder { | ||
pub fn new() -> Self { | ||
Self { cache: HashMap::new(), path: env::var_os("PATH").unwrap_or_default() } | ||
|
@@ -102,6 +111,32 @@ pub fn check(build: &mut Build) { | |
cmd_finder.must_have("git"); | ||
} | ||
|
||
// Ensure that a compatible version of libstdc++ is available on the system when using `llvm.download-ci-llvm`. | ||
#[cfg(not(feature = "bootstrap-self-test"))] | ||
if !build.config.dry_run() && !build.build.is_msvc() && build.config.llvm_from_ci { | ||
let builder = Builder::new(build); | ||
let libcxx_version = builder.ensure(tool::LibcxxVersionTool { target: build.build }); | ||
|
||
match libcxx_version { | ||
tool::LibcxxVersion::Gnu(version) => { | ||
if LIBSTDCXX_MIN_VERSION_THRESHOLD > version { | ||
eprintln!( | ||
"\nYour system's libstdc++ version is too old for the `llvm.download-ci-llvm` option." | ||
); | ||
eprintln!("Current version detected: '{}'", version); | ||
eprintln!("Minimum required version: '{}'", LIBSTDCXX_MIN_VERSION_THRESHOLD); | ||
eprintln!( | ||
"Consider upgrading libstdc++ or disabling the `llvm.download-ci-llvm` option." | ||
); | ||
crate::exit!(1); | ||
} | ||
} | ||
tool::LibcxxVersion::Llvm(_) => { | ||
// FIXME: Handle libc++ version check. | ||
} | ||
} | ||
} | ||
|
||
// We need cmake, but only if we're actually building LLVM or sanitizers. | ||
let building_llvm = build | ||
.hosts | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Detecting the standard library version manually using a bunch of shell commands is very | ||
// complicated and fragile across different platforms. This program provides the major version | ||
// of the standard library on any target platform without requiring any messy work. | ||
// | ||
// It's nothing more than specifying the name of the standard library implementation (either libstdc++ or libc++) | ||
// and its major version. | ||
|
||
#include <iostream> | ||
|
||
int main() { | ||
#ifdef _GLIBCXX_RELEASE | ||
std::cout << "libstdc++ version: " << _GLIBCXX_RELEASE << std::endl; | ||
#elif defined(_LIBCPP_VERSION) | ||
// _LIBCPP_VERSION follows "XXYYZZ" format (e.g., 170001 for 17.0.1). | ||
// ref: https://github.com/llvm/llvm-project/blob/f64732195c1030ee2627ff4e4142038e01df1d26/libcxx/include/__config#L51-L54 | ||
// | ||
// Since we use the major version from _GLIBCXX_RELEASE, we need to extract only the first 2 characters of _LIBCPP_VERSION | ||
// to provide the major version for consistency. | ||
std::cout << "libc++ version: " << std::to_string(_LIBCPP_VERSION).substr(0, 2) << std::endl; | ||
#else | ||
std::cerr << "Coudln't recognize the standard library version." << std::endl; | ||
return 1; | ||
#endif | ||
|
||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@onur-ozkan
How did it pass CI on Windows?
It trivially fails for me locally, because there's no
libcxx-version
, onlylibcxx-version.exe
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#126086 should handle this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it passed because windows-gnu CI uses env that disables llvm download?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, most likely.