-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsysroot_complete.cppm
More file actions
52 lines (43 loc) · 2 KB
/
sysroot_complete.cppm
File metadata and controls
52 lines (43 loc) · 2 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
// mcpp.fallback.sysroot_complete — ensure sysroot has complete headers.
//
// When GCC's probed sysroot exists but may be missing linux kernel
// headers or glibc headers, symlink them from the payload xpkgs.
export module mcpp.fallback.sysroot_complete;
import std;
import mcpp.toolchain.model;
export namespace mcpp::fallback {
// Ensure sysroot directory has complete headers by symlinking from
// payload xpkgs. Called when GCC's probed sysroot exists but may
// be missing linux kernel headers or glibc headers.
void ensure_sysroot_complete(const std::filesystem::path& sysroot,
const mcpp::toolchain::PayloadPaths& pp) {
if (sysroot.empty()) return;
auto sysrootInclude = sysroot / "usr" / "include";
if (!std::filesystem::exists(sysrootInclude)) return;
std::error_code ec;
// Ensure linux kernel headers are present in sysroot.
// If missing, symlink from linux-headers payload.
if (!pp.linuxInclude.empty()) {
for (auto dir : {"linux", "asm", "asm-generic"}) {
auto target = sysrootInclude / dir;
auto source = pp.linuxInclude / dir;
if (!std::filesystem::exists(target, ec) && std::filesystem::exists(source, ec)) {
std::filesystem::create_directory_symlink(source, target, ec);
}
}
}
// Ensure glibc headers are present if sysroot is bare.
if (!std::filesystem::exists(sysrootInclude / "features.h", ec)) {
// Symlink individual glibc dirs/files into sysroot.
for (auto& entry : std::filesystem::directory_iterator(pp.glibcInclude, ec)) {
auto target = sysrootInclude / entry.path().filename();
if (!std::filesystem::exists(target, ec)) {
if (entry.is_directory(ec))
std::filesystem::create_directory_symlink(entry.path(), target, ec);
else
std::filesystem::create_symlink(entry.path(), target, ec);
}
}
}
}
} // namespace mcpp::fallback