-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToolchain.cpp
More file actions
100 lines (85 loc) · 2.71 KB
/
Copy pathToolchain.cpp
File metadata and controls
100 lines (85 loc) · 2.71 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
/**
*
* @file Toolchain.cpp
* @author Gaspard Kirira
*
* Copyright 2026, Gaspard Kirira. All rights reserved.
* https://github.com/vixcpp/vix
* Use of this source code is governed by a MIT license
* that can be found in the License file.
*
* Vix.cpp
*
* Build graph task model
*
*/
#include <vix/engine/Toolchain.hpp>
#include <sstream>
#include <string>
#include "ExecutableLookup.hpp"
namespace vix::engine
{
std::string infer_processor_from_triple(std::string_view triple)
{
if (triple.rfind("aarch64", 0) == 0)
return "aarch64";
if (triple.rfind("arm", 0) == 0)
return "arm";
if (triple.rfind("x86_64", 0) == 0)
return "x86_64";
if (triple.rfind("riscv64", 0) == 0)
return "riscv64";
return "unknown";
}
std::string toolchain_contents_for_triple(
const std::string &triple,
const std::string &sysroot)
{
const std::string proc = infer_processor_from_triple(triple);
std::ostringstream tc;
tc << "# Auto-generated by Vix (vix build --target " << triple << ")\n";
tc << "set(CMAKE_SYSTEM_NAME Linux)\n";
tc << "set(CMAKE_SYSTEM_PROCESSOR \"" << proc << "\")\n\n";
if (!sysroot.empty())
{
tc << "set(CMAKE_SYSROOT \"" << sysroot << "\")\n";
tc << "set(CMAKE_FIND_ROOT_PATH \"" << sysroot << "\")\n";
tc << "set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)\n";
tc << "set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)\n";
tc << "set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)\n\n";
}
tc << "set(VIX_TARGET_TRIPLE \"" << triple
<< "\" CACHE STRING \"Vix target triple\")\n\n";
tc << "set(CMAKE_C_COMPILER \"" << triple
<< "-gcc\" CACHE FILEPATH \"\" FORCE)\n";
tc << "set(CMAKE_CXX_COMPILER \"" << triple
<< "-g++\" CACHE FILEPATH \"\" FORCE)\n";
tc << "set(CMAKE_AR \"" << triple
<< "-ar\" CACHE FILEPATH \"\" FORCE)\n";
tc << "set(CMAKE_RANLIB \"" << triple
<< "-ranlib\" CACHE FILEPATH \"\" FORCE)\n";
tc << "set(CMAKE_STRIP \"" << triple
<< "-strip\" CACHE FILEPATH \"\" FORCE)\n\n";
tc << "set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)\n";
return tc.str();
}
std::vector<std::string> detect_available_targets()
{
static const std::vector<std::string> known = {
"x86_64-linux-gnu",
"aarch64-linux-gnu",
"arm-linux-gnueabihf",
"riscv64-linux-gnu"};
std::vector<std::string> out;
out.reserve(known.size());
for (const auto &target : known)
{
if (detail::executable_on_path(target + "-gcc") &&
detail::executable_on_path(target + "-g++"))
{
out.push_back(target);
}
}
return out;
}
} // namespace vix::engine