From 2388953dffb456b6905d789fa85186810bccaae3 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 11 Oct 2019 09:24:33 +0200 Subject: Switch clang-apple to primary/variant version setup --- libbuild2/cc/compile-rule.cxx | 10 ++------ libbuild2/cc/guess.cxx | 59 ++++++++++++++++++++++++++++++++++++++++++- libbuild2/cxx/init.cxx | 30 ---------------------- 3 files changed, 60 insertions(+), 39 deletions(-) diff --git a/libbuild2/cc/compile-rule.cxx b/libbuild2/cc/compile-rule.cxx index cf2f2a8..c46355c 100644 --- a/libbuild2/cc/compile-rule.cxx +++ b/libbuild2/cc/compile-rule.cxx @@ -2588,15 +2588,9 @@ namespace build2 } case compiler_type::clang: { - // -frewrite-includes is available since vanilla Clang 3.2.0. + // -frewrite-includes is available since Clang 3.2.0. // - // Apple Clang 5.0 is based on LLVM 3.3svn so it should have this - // option (4.2 is based on 3.2svc so it may or may not have it and, - // no, we are not going to try to find out). - // - if (cvariant == "apple" - ? (cmaj >= 5) - : (cmaj > 3 || (cmaj == 3 && cmin >= 2))) + if (cmaj > 3 || (cmaj == 3 && cmin >= 2)) pp = "-frewrite-includes"; break; diff --git a/libbuild2/cc/guess.cxx b/libbuild2/cc/guess.cxx index f7074f0..cf78774 100644 --- a/libbuild2/cc/guess.cxx +++ b/libbuild2/cc/guess.cxx @@ -15,6 +15,8 @@ namespace build2 { namespace cc { + using std::to_string; + string to_string (compiler_type t) { @@ -1465,6 +1467,7 @@ namespace build2 // (which for some reason doesn't work for -x). // bool cl (gr.id.type == compiler_type::msvc); + bool apple (gr.id.variant == "apple"); const process_path& xp (gr.path); @@ -1541,10 +1544,64 @@ namespace build2 ver.major = next ("major", false); ver.minor = next ("minor", false); - ver.patch = next ("patch", gr.id.variant == "apple"); + ver.patch = next ("patch", apple); if (e != s.size ()) ver.build.assign (s, e + 1, string::npos); + + // Map Apple to vanilla Clang version, preserving the original as + // the variant version. + // + if (apple) + { + var_ver = move (ver); + + // Apple no longer discloses the mapping so it's a guesswork and we + // better be conservative. For details see: + // + // https://gist.github.com/yamaya/2924292 + // + // Note that this is Apple Clang version and not XCode version. + // + // 4.2 -> 3.2svn + // 5.0 -> 3.3svn + // 5.1 -> 3.4svn + // 6.0 -> 3.5svn + // 6.1.0 -> 3.6svn + // 7.0.0 -> 3.7 + // 7.3.0 -> 3.8 + // 8.0.0 -> 3.9 + // 8.1.0 -> ? + // 9.0.0 -> 4.0 + // 9.1.0 -> 5.0 + // 10.0.0 -> 6.0 + // 10.0.1 -> ? + // 11.0.0 -> 7.0 (?) + // + uint64_t mj (var_ver->major); + uint64_t mi (var_ver->minor); + + if (mj >= 11) {mj = 7; mi = 0;} + else if (mj == 10) {mj = 6; mi = 0;} + else if (mj == 9 && mi >= 1) {mj = 5; mi = 0;} + else if (mj == 9) {mj = 4; mi = 0;} + else if (mj == 8) {mj = 3; mi = 9;} + else if (mj == 7 && mi >= 3) {mj = 3; mi = 8;} + else if (mj == 7) {mj = 3; mi = 7;} + else if (mj == 6 && mi >= 1) {mj = 3; mi = 5;} + else if (mj == 6) {mj = 3; mi = 4;} + else if (mj == 5 && mi >= 1) {mj = 3; mi = 3;} + else if (mj == 5) {mj = 3; mi = 2;} + else if (mj == 4 && mi >= 2) {mj = 3; mi = 1;} + else {mj = 3; mi = 0;} + + ver = compiler_version { + to_string (mj) + '.' + to_string (mi) + ".0", + mj, + mi, + 0, + ""}; + } } // Figure out the target architecture. diff --git a/libbuild2/cxx/init.cxx b/libbuild2/cxx/init.cxx index 52f3f5a..9bf54eb 100644 --- a/libbuild2/cxx/init.cxx +++ b/libbuild2/cxx/init.cxx @@ -202,36 +202,6 @@ namespace build2 } case compiler_type::clang: { - // Remap Apple versions to vanilla Clang based on the - // following release point. Note that Apple no longer - // discloses the mapping so it's a guesswork and we try to be - // conservative. For details see: - // - // https://gist.github.com/yamaya/2924292 - // - // 5.1 -> 3.4 - // 6.0 -> 3.5 - // 7.0 -> 3.7 - // 7.3 -> 3.8 - // 8.0 -> 3.9 - // 9.0 -> 4.0 (later ones could be 5.0) - // 9.1 -> ? - // 10.0 -> ? - // - // Note that this mapping is also used to enable experimental - // features below. - // - if (ci.id.variant == "apple") - { - if (mj >= 9) {mj = 4; mi = 0;} - else if (mj == 8) {mj = 3; mi = 9;} - else if (mj == 7 && mi >= 3) {mj = 3; mi = 8;} - else if (mj == 7) {mj = 3; mi = 7;} - else if (mj == 6) {mj = 3; mi = 5;} - else if (mj == 5 && mi >= 1) {mj = 3; mi = 4;} - else {mj = 3; mi = 0;} - } - if (mj >= 5) o = "-std=c++2a"; else if (mj > 3 || (mj == 3 && mi >= 5)) o = "-std=c++1z"; else if (mj == 3 && mi >= 4) o = "-std=c++1y"; -- cgit v1.1