-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathlinux.cppm
More file actions
92 lines (75 loc) · 2.75 KB
/
linux.cppm
File metadata and controls
92 lines (75 loc) · 2.75 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
// mcpp.platform.linux — Linux-specific platform capabilities.
//
// Provides:
// build_ld_library_path() — construct LD_LIBRARY_PATH prefix
// runtime_lib_dirs() — Linux toolchain runtime library search paths
module;
export module mcpp.platform.linux;
import std;
import mcpp.platform.shell;
export namespace mcpp::platform::linux_ {
// Build an LD_LIBRARY_PATH shell prefix from a list of directories.
// Returns "env LD_LIBRARY_PATH=<dirs>:${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} "
// or "" if dirs is empty.
std::string build_ld_library_path_prefix(
const std::vector<std::filesystem::path>& dirs);
// Build an LD_LIBRARY_PATH shell prefix for toolchain host processes.
// Unlike build_ld_library_path_prefix(), this does not append inherited
// LD_LIBRARY_PATH, which may contain target-program runtime directories.
std::string build_clean_ld_library_path_prefix(
const std::vector<std::filesystem::path>& dirs);
// Return Linux toolchain runtime library directories.
std::vector<std::filesystem::path>
runtime_lib_dirs(const std::filesystem::path& toolchain_root);
} // namespace mcpp::platform::linux_
// ─── Implementation ──────────────────────────────────────────────────────
namespace mcpp::platform::linux_ {
namespace {
std::string join_dirs(const std::vector<std::filesystem::path>& dirs) {
std::string joined;
for (auto& d : dirs) {
if (!joined.empty()) joined += ':';
joined += d.string();
}
return joined;
}
} // namespace
std::string build_ld_library_path_prefix(
const std::vector<std::filesystem::path>& dirs) {
#if defined(__linux__)
if (dirs.empty()) return "";
auto joined = join_dirs(dirs);
return std::format("env LD_LIBRARY_PATH={}${{LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}} ",
mcpp::platform::shell::quote(joined));
#else
(void)dirs;
return "";
#endif
}
std::string build_clean_ld_library_path_prefix(
const std::vector<std::filesystem::path>& dirs) {
#if defined(__linux__)
if (dirs.empty()) return "";
auto joined = join_dirs(dirs);
return std::format("env LD_LIBRARY_PATH={} ",
mcpp::platform::shell::quote(joined));
#else
(void)dirs;
return "";
#endif
}
std::vector<std::filesystem::path>
runtime_lib_dirs(const std::filesystem::path& toolchain_root) {
std::vector<std::filesystem::path> dirs;
#if defined(__linux__)
auto add = [&](const std::filesystem::path& p) {
if (std::filesystem::exists(p))
dirs.push_back(p);
};
add(toolchain_root / "lib" / "x86_64-unknown-linux-gnu");
#else
(void)toolchain_root;
#endif
return dirs;
}
} // namespace mcpp::platform::linux_