aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/ApiExtractor/clangparser/compilersupport.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2025-06-19 09:08:56 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2025-06-27 11:30:13 +0200
commit244b5dd5e1869ea85c5b78d27259965f7ca2c7bb (patch)
treea2709e9d15f829a10b5462759fe0d490a0d20fd4 /sources/shiboken6/ApiExtractor/clangparser/compilersupport.cpp
parentdb8cd503f076d869ff38f660d73c42c4a023670d (diff)
shiboken6: Add a triplet parser and triplet builder with test
Task-number: PYSIDE-3105 Change-Id: I13faf4343705e6c1f636784da0cc3e105390b012 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'sources/shiboken6/ApiExtractor/clangparser/compilersupport.cpp')
-rw-r--r--sources/shiboken6/ApiExtractor/clangparser/compilersupport.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/sources/shiboken6/ApiExtractor/clangparser/compilersupport.cpp b/sources/shiboken6/ApiExtractor/clangparser/compilersupport.cpp
index 672235c12..394f6ea38 100644
--- a/sources/shiboken6/ApiExtractor/clangparser/compilersupport.cpp
+++ b/sources/shiboken6/ApiExtractor/clangparser/compilersupport.cpp
@@ -196,6 +196,100 @@ bool setArchitecture(const QString &name)
return result;
}
+// Parsing triplets
+static inline bool isVersionChar(QChar c)
+{
+ return c.isDigit() || c == u'.';
+}
+
+// "macosx15.0" -> "macosx"
+QStringView stripTrailingVersion(QStringView s)
+{
+ while (!s.isEmpty() && isVersionChar(s.at(s.size() - 1)))
+ s.chop(1);
+ return s;
+}
+
+bool parseTriplet(QStringView name, Architecture *a, Platform *p, Compiler *c)
+{
+ *a = hostArchitecture();
+ *p = hostPlatform();
+ *c = hostCompiler();
+ auto values = name.split(u'-');
+ if (values.size() < 2)
+ return false;
+ *a = parseArchitecture(values.constFirst());
+ if (*a == Architecture::Other)
+ return false;
+ // Try a trailing compiler?
+ Compiler comp{};
+ if (parseCompiler(stripTrailingVersion(values.constLast()), &comp)) {
+ *c = comp;
+ values.removeLast();
+ }
+ return parsePlatform(stripTrailingVersion(values.constLast()), p);
+}
+
+const char *compilerTripletValue(Compiler c)
+{
+ switch (c) {
+ case Compiler::Clang:
+ return "clang";
+ case Compiler::Msvc:
+ return "msvc";
+ case Compiler::Gpp:
+ break;
+ }
+ return "gnu";
+}
+
+QByteArray targetTripletForPlatform(Platform p, Architecture a, Compiler c)
+{
+ QByteArray result;
+ if (p == Platform::Unix || a == Architecture::Other)
+ return result; // too unspecific
+
+ switch (a) {
+ case Architecture::Other:
+ break;
+ case Architecture::X64:
+ result += "x86_64";
+ break;
+ case Architecture::X86:
+ result += "i586";
+ break;
+ case Architecture::Arm32:
+ result += "armv7a";
+ break;
+ case Architecture::Arm64:
+ result += p == Platform::Android ? "aarch64" : "arm64";
+ break;
+ }
+
+ result += '-';
+
+ switch (p) {
+ case Platform::Unix:
+ break;
+ case Platform::Linux:
+ result += "unknown-linux-"_ba + compilerTripletValue(c);
+ break;
+ case Platform::Windows:
+ result += "pc-windows-"_ba + compilerTripletValue(c);
+ break;
+ case Platform::macOS:
+ result += "apple-macosx"_ba;
+ break;
+ case Platform::Android:
+ result += "unknown-linux-android"_ba;
+ break;
+ case Platform::iOS:
+ result += "apple-ios"_ba;
+ break;
+ }
+ return result;
+}
+
// 3/2024: Use a recent MSVC2022 for libclang 18.X
static QByteArray msvcCompatVersion()
{