diff options
| author | onur-ozkan <work@onurozkan.dev> | 2024-05-23 11:53:27 +0300 |
|---|---|---|
| committer | onur-ozkan <work@onurozkan.dev> | 2024-06-06 07:01:28 +0300 |
| commit | 3a70a810d5d271f18489a7e5a8cbbd2e6262b1b7 (patch) | |
| tree | fcd0bd17d2bf7dbc9833bebc2fb89ce98b9de0f0 | |
| parent | d0ccb5413ee2d9d40b574ad7998ffa866811d3f8 (diff) | |
| download | rust-3a70a810d5d271f18489a7e5a8cbbd2e6262b1b7.tar.gz rust-3a70a810d5d271f18489a7e5a8cbbd2e6262b1b7.zip | |
create libcxx-version tool for getting currently used libcxx version
Signed-off-by: onur-ozkan <work@onurozkan.dev>
| -rw-r--r-- | src/tools/libcxx-version/main.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/tools/libcxx-version/main.cpp b/src/tools/libcxx-version/main.cpp new file mode 100644 index 00000000000..d12078abbb8 --- /dev/null +++ b/src/tools/libcxx-version/main.cpp @@ -0,0 +1,28 @@ +// 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. +// +// ignore-tidy-linelength + +#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; +} |
