Skip to content

Commit d5cdd83

Browse files
committed
[cli] Show full MSVC version
1 parent 0b06164 commit d5cdd83

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ fn main() {
8181
// all the source files here rather than go through CMake.
8282
cxx_build::bridge("src/lib.rs")
8383
.flag_if_supported("-std=c++11")
84+
.flag_if_supported("/std:c++11")
8485
.file("src/shim.cpp")
8586
.files(sources::geographiclib_cpp().unwrap())
8687
.flag("-I./include")

src/shim.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#include <optional>
2+
#include <sstream>
3+
14
#include <GeographicLib/Config.h>
25
#include <GeographicLib/Geocentric.hpp>
36
#include <GeographicLib/Geodesic.hpp>
@@ -56,9 +59,27 @@ rust::Str geographiclib_version() noexcept {
5659
return GEOGRAPHICLIB_VERSION_STRING;
5760
}
5861

62+
static std::string ver_string;
63+
64+
const char* msvc_version() noexcept {
65+
if (!ver_string.empty()) {
66+
return ver_string.c_str();
67+
}
68+
69+
unsigned long full_ver = _MSC_FULL_VER;
70+
auto major = full_ver / 10000000;
71+
auto minor = (full_ver / 100000) % 100;
72+
auto patch = full_ver % 100000;
73+
74+
std::ostringstream s;
75+
s << "MSVC " << major << "." << minor << "." << patch;
76+
ver_string = s.str();
77+
return ver_string.c_str();
78+
}
79+
5980
rust::Str compiler_version() noexcept {
60-
#if defined(_MSC_VER)
61-
return "MSVC " STRINGIFY(_MSC_VER);
81+
#if defined(_MSC_FULL_VER)
82+
return msvc_version();
6283
#elif defined(__clang__)
6384
return "clang " STRINGIFY(__clang_major__) "." STRINGIFY(__clang_minor__) "." STRINGIFY(__clang_patchlevel__);
6485
#else

0 commit comments

Comments
 (0)