-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmodel.cppm
More file actions
108 lines (88 loc) · 3.72 KB
/
model.cppm
File metadata and controls
108 lines (88 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// mcpp.toolchain.model - stable toolchain data model.
export module mcpp.toolchain.model;
import std;
export namespace mcpp::toolchain {
enum class CompilerId { Unknown, GCC, Clang, MSVC };
// Fine-grained sysroot paths derived from xpkgs payloads.
// When populated, flags are assembled from these paths instead of --sysroot.
struct PayloadPaths {
std::filesystem::path glibcInclude; // glibc headers (features.h, bits/)
std::filesystem::path glibcLib; // glibc runtime (libc.so, crt*.o, ld-linux)
std::filesystem::path linuxInclude; // linux kernel headers (linux/, asm/)
};
struct Toolchain {
CompilerId compiler = CompilerId::Unknown;
std::string version; // "15.1.0"
std::filesystem::path binaryPath;
std::string driverIdent; // normalized --version output
std::string targetTriple; // "x86_64-linux-gnu"
std::string stdlibId; // "libstdc++"
std::string stdlibVersion;
std::filesystem::path stdModuleSource; // bits/std.cc / std.cppm
std::filesystem::path stdCompatSource; // bits/std_compat.cc / std.compat.cppm
std::filesystem::path sysroot; // -print-sysroot output (or empty)
std::optional<PayloadPaths> payloadPaths; // fine-grained sysroot from xpkgs
std::vector<std::filesystem::path> compilerRuntimeDirs; // LD_LIBRARY_PATH for private tools
std::vector<std::filesystem::path> linkRuntimeDirs; // -L/-rpath dirs for produced binaries
bool hasImportStd = false;
std::string label() const {
return std::format("{} {} ({})", compiler_name(), version, targetTriple);
}
std::string_view compiler_name() const {
switch (compiler) {
case CompilerId::GCC: return "gcc";
case CompilerId::Clang: return "clang";
case CompilerId::MSVC: return "msvc";
default: return "unknown";
}
}
};
struct DetectError { std::string message; };
bool is_gcc(const Toolchain& tc);
bool is_clang(const Toolchain& tc);
bool is_musl_target(const Toolchain& tc);
bool is_msvc_target(const Toolchain& tc);
struct BmiTraits {
std::string_view bmiDir; // "gcm.cache" | "pcm.cache"
std::string_view bmiExt; // ".gcm" | ".pcm"
std::string_view manifestPrefix; // "gcm" | "pcm"
bool needsExplicitModuleOutput = false;
bool needsPrebuiltModulePath = false;
bool scanNeedsFModules = true;
};
BmiTraits bmi_traits(const Toolchain& tc);
} // namespace mcpp::toolchain
namespace mcpp::toolchain {
bool is_gcc(const Toolchain& tc) {
return tc.compiler == CompilerId::GCC;
}
bool is_clang(const Toolchain& tc) {
return tc.compiler == CompilerId::Clang;
}
bool is_musl_target(const Toolchain& tc) {
return tc.targetTriple.find("-musl") != std::string::npos;
}
bool is_msvc_target(const Toolchain& tc) {
return tc.targetTriple.find("msvc") != std::string::npos;
}
BmiTraits bmi_traits(const Toolchain& tc) {
if (is_clang(tc)) {
return {
.bmiDir = "pcm.cache",
.bmiExt = ".pcm",
.manifestPrefix = "pcm",
.needsExplicitModuleOutput = true,
.needsPrebuiltModulePath = true,
.scanNeedsFModules = false,
};
}
return {
.bmiDir = "gcm.cache",
.bmiExt = ".gcm",
.manifestPrefix = "gcm",
.needsExplicitModuleOutput = false,
.needsPrebuiltModulePath = false,
.scanNeedsFModules = true,
};
}
} // namespace mcpp::toolchain