feat(translation,ide): add native C driver, Ninja custom commands, CMake CXX_MODULES, and vbs ide integration
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s

This commit is contained in:
faumaray committed 2026-11-27 07:50:54 +03:00
1 parent 5e1916dc5c
commit 6c225c2dff
27 files changed
+3443 -331

No files matched your search

+150 -16
View File
@@ -47,10 +47,11 @@ std::map<std::string, std::string, std::less<>> capture_relevant_env() {
}
bool probe_compile_flag(const std::filesystem::path &compiler, const std::string &sysroot,
const std::vector<std::string> &extra_flags, std::string_view source_code) {
const std::vector<std::string> &extra_flags, std::string_view source_code,
std::string_view language = "c++") {
Platform::ProcessRequest req;
req.executable = compiler;
req.arguments = {"-x", "c++", "-fsyntax-only"};
req.arguments = {"-x", std::string{language}, "-fsyntax-only"};
if (!sysroot.empty()) {
req.arguments.push_back("--sysroot=" + sysroot);
}
@@ -70,6 +71,20 @@ std::size_t estimate_argv_bytes(const std::vector<std::string> &args) {
return total;
}
std::string c_standard_flag(CStandard standard) {
switch (standard) {
case CStandard::Default:
return {};
case CStandard::C11:
return "-std=c11";
case CStandard::C17:
return "-std=c17";
case CStandard::C23:
return "-std=c23";
}
return {};
}
std::string cxx_standard_flag(CxxStandard standard) {
switch (standard) {
case CxxStandard::Default:
@@ -108,6 +123,7 @@ std::string serialize_capabilities(const ToolchainCapabilities &cap) {
std::string out = "{";
out += "\"family\":" + json_quote(compiler_name(cap.family));
out += ",\"cxx_compiler\":" + json_quote(cap.cxx_compiler.string());
out += ",\"c_compiler\":" + json_quote(cap.c_compiler.string());
out += ",\"archiver\":" + json_quote(cap.archiver.string());
out += ",\"module_scanner\":" +
json_quote(cap.module_scanner ? cap.module_scanner->string() : std::string{});
@@ -115,7 +131,12 @@ std::string serialize_capabilities(const ToolchainCapabilities &cap) {
out += ",\"target_triple\":" + json_quote(cap.target_triple);
out += ",\"sysroot\":" + json_quote(cap.sysroot);
out += ",\"compiler_sha256\":" + json_quote(cap.compiler_sha256);
out += ",\"c_compiler_sha256\":" + json_quote(cap.c_compiler_sha256);
out += ",\"archiver_sha256\":" + json_quote(cap.archiver_sha256);
out += ",\"default_include_dirs\":" + json_array(cap.default_include_dirs, json_quote);
out += ",\"supports_c11\":" + std::string{cap.supports_c11 ? "true" : "false"};
out += ",\"supports_c17\":" + std::string{cap.supports_c17 ? "true" : "false"};
out += ",\"supports_c23\":" + std::string{cap.supports_c23 ? "true" : "false"};
out += ",\"supports_cxx17\":" + std::string{cap.supports_cxx17 ? "true" : "false"};
out += ",\"supports_cxx20\":" + std::string{cap.supports_cxx20 ? "true" : "false"};
out += ",\"supports_cxx23\":" + std::string{cap.supports_cxx23 ? "true" : "false"};
@@ -170,6 +191,7 @@ std::optional<ToolchainCapabilities> deserialize_capabilities(std::string_view t
ToolchainCapabilities cap;
cap.family = parse_compiler(get_str("family").value_or(""));
cap.cxx_compiler = get_str("cxx_compiler").value_or("");
cap.c_compiler = get_str("c_compiler").value_or("");
cap.archiver = get_str("archiver").value_or("");
if (auto scanner = get_str("module_scanner"); scanner && !scanner->empty()) {
cap.module_scanner = *scanner;
@@ -178,7 +200,22 @@ std::optional<ToolchainCapabilities> deserialize_capabilities(std::string_view t
cap.target_triple = get_str("target_triple").value_or("");
cap.sysroot = get_str("sysroot").value_or("");
cap.compiler_sha256 = get_str("compiler_sha256").value_or("");
cap.c_compiler_sha256 = get_str("c_compiler_sha256").value_or("");
cap.archiver_sha256 = get_str("archiver_sha256").value_or("");
if (const auto dit = obj->find("default_include_dirs"); dit != obj->end()) {
if (const auto *darr =
std::get_if<Void::Json::Strict::Value::Array>(&dit->second.value)) {
for (const auto &item : *darr) {
if (const auto *ds = std::get_if<std::string>(&item.value);
ds && !ds->empty()) {
cap.default_include_dirs.push_back(*ds);
}
}
}
}
cap.supports_c11 = get_bool("supports_c11").value_or(false);
cap.supports_c17 = get_bool("supports_c17").value_or(false);
cap.supports_c23 = get_bool("supports_c23").value_or(false);
cap.supports_cxx17 = get_bool("supports_cxx17").value_or(false);
cap.supports_cxx20 = get_bool("supports_cxx20").value_or(false);
cap.supports_cxx23 = get_bool("supports_cxx23").value_or(false);
@@ -242,6 +279,33 @@ discover_and_probe(const ProfileContext &context,
requested_compiler.string(), compiler_name(context.compiler)))};
}
std::filesystem::path requested_c_compiler =
context.compiler == CompilerFamily::Gcc ? "gcc" : "clang";
if (!context.compiler_path.empty()) {
const std::filesystem::path cp_path{context.compiler_path};
const std::string fname = cp_path.filename().string();
if (fname == "g++" || fname.ends_with("-g++")) {
const std::string c_name = fname.substr(0, fname.size() - 3) + "gcc";
requested_c_compiler = cp_path.parent_path().empty() ? std::filesystem::path{c_name}
: (cp_path.parent_path() / c_name);
} else if (fname == "clang++" || fname.ends_with("-clang++")) {
const std::string c_name = fname.substr(0, fname.size() - 7) + "clang";
requested_c_compiler = cp_path.parent_path().empty() ? std::filesystem::path{c_name}
: (cp_path.parent_path() / c_name);
}
}
auto resolved_c_compiler = Platform::resolve_executable(requested_c_compiler);
if (!resolved_c_compiler && !context.compiler_path.empty()) {
resolved_c_compiler =
Platform::resolve_executable(context.compiler == CompilerFamily::Gcc ? "gcc" : "clang");
}
std::string c_comp_hash;
if (resolved_c_compiler) {
if (auto ch = Util::sha256_file_hex(*resolved_c_compiler); ch) {
c_comp_hash = *ch;
}
}
std::optional<std::filesystem::path> resolved_ar;
if (context.compiler == CompilerFamily::Clang) {
resolved_ar = Platform::resolve_executable("llvm-ar");
@@ -271,9 +335,14 @@ discover_and_probe(const ProfileContext &context,
// Compute cache key BEFORE expensive compiler probes.
Util::Sha256Hasher key_hasher;
key_hasher.update_length_prefixed("vbs-probe-v2");
key_hasher.update_length_prefixed(compiler_name(context.compiler));
key_hasher.update_length_prefixed(resolved_compiler->string());
key_hasher.update_length_prefixed(*comp_hash);
if (resolved_c_compiler) {
key_hasher.update_length_prefixed(resolved_c_compiler->string());
key_hasher.update_length_prefixed(c_comp_hash);
}
key_hasher.update_length_prefixed(resolved_ar->string());
key_hasher.update_length_prefixed(*ar_hash);
key_hasher.update_length_prefixed(context.sysroot);
@@ -298,9 +367,11 @@ discover_and_probe(const ProfileContext &context,
ToolchainCapabilities cap;
cap.family = context.compiler;
cap.cxx_compiler = *resolved_compiler;
cap.c_compiler = resolved_c_compiler.value_or(std::filesystem::path{});
cap.archiver = *resolved_ar;
cap.sysroot = context.sysroot;
cap.compiler_sha256 = *comp_hash;
cap.c_compiler_sha256 = c_comp_hash;
cap.archiver_sha256 = *ar_hash;
cap.relevant_env = relevant_env;
@@ -338,9 +409,50 @@ discover_and_probe(const ProfileContext &context,
if (cap.family == CompilerFamily::Clang) {
cap.module_scanner = Platform::resolve_executable("clang-scan-deps");
cap.supports_p1689_scan = cap.module_scanner.has_value();
Platform::ProcessRequest ireq;
ireq.executable = cap.cxx_compiler;
ireq.arguments = {"-x", "c++", "-E", "-v"};
if (!cap.sysroot.empty()) {
ireq.arguments.push_back("--sysroot=" + cap.sysroot);
}
ireq.arguments.push_back("-");
ireq.timeout = std::chrono::seconds{10};
if (auto ires = Platform::run_supervised(ireq); ires) {
const std::string combined = ires->stderr_data + "\n" + ires->stdout_data;
bool in_search = false;
std::size_t pos = 0;
while (pos < combined.size()) {
const auto nl = combined.find('\n', pos);
const std::string line = trim(std::string_view{combined}.substr(
pos, nl == std::string::npos ? std::string::npos : nl - pos));
pos = (nl == std::string::npos) ? combined.size() : (nl + 1);
if (line.find("#include <...> search starts here:") != std::string::npos) {
in_search = true;
continue;
}
if (in_search) {
if (line.starts_with("End of search list")) {
break;
}
if (!line.empty() && line.find("(framework directory)") == std::string::npos) {
cap.default_include_dirs.push_back(line);
}
}
}
}
}
// Syntax-only capability probes (safe for cross-toolchains).
constexpr std::string_view kTrivialC = "int vbs_c_probe(void) { return 0; }\n";
if (!cap.c_compiler.empty()) {
cap.supports_c11 =
probe_compile_flag(cap.c_compiler, cap.sysroot, {"-std=c11"}, kTrivialC, "c");
cap.supports_c17 =
probe_compile_flag(cap.c_compiler, cap.sysroot, {"-std=c17"}, kTrivialC, "c");
cap.supports_c23 =
probe_compile_flag(cap.c_compiler, cap.sysroot, {"-std=c23"}, kTrivialC, "c");
}
constexpr std::string_view kTrivialCpp = "int vbs_probe() { return 0; }\n";
cap.supports_cxx17 =
probe_compile_flag(cap.cxx_compiler, cap.sysroot, {"-std=c++17"}, kTrivialCpp);
@@ -404,6 +516,7 @@ std::string compute_profile_identity(const ProfileContext &context,
hasher.update_length_prefixed(context.os);
hasher.update_length_prefixed(context.architecture);
hasher.update_length_prefixed(toolchain.identity_hash);
hasher.update_length_prefixed(c_standard_name(context.c_standard));
hasher.update_length_prefixed(cxx_standard_name(context.cxx_standard));
hasher.update_length_prefixed(lto_mode_name(context.lto));
hasher.update_length_prefixed(context.sysroot);
@@ -457,17 +570,32 @@ lower_compile_command(const ToolchainCapabilities &toolchain, const CompileReque
}
// Validate requested capabilities explicitly (never silently downgrade).
if (request.cxx_standard == CxxStandard::Cxx17 && !toolchain.supports_cxx17) {
return std::unexpected{make_error("target compiler does not support -std=c++17")};
}
if (request.cxx_standard == CxxStandard::Cxx20 && !toolchain.supports_cxx20) {
return std::unexpected{make_error("target compiler does not support -std=c++20")};
}
if (request.cxx_standard == CxxStandard::Cxx23 && !toolchain.supports_cxx23) {
return std::unexpected{make_error("target compiler does not support -std=c++23")};
}
if (request.cxx_standard == CxxStandard::Cxx26 && !toolchain.supports_cxx26) {
return std::unexpected{make_error("target compiler does not support -std=c++26")};
if (request.is_c_source) {
if (toolchain.c_compiler.empty()) {
return std::unexpected{make_error("target C compiler was not discovered")};
}
if (request.c_standard == CStandard::C11 && !toolchain.supports_c11) {
return std::unexpected{make_error("target C compiler does not support -std=c11")};
}
if (request.c_standard == CStandard::C17 && !toolchain.supports_c17) {
return std::unexpected{make_error("target C compiler does not support -std=c17")};
}
if (request.c_standard == CStandard::C23 && !toolchain.supports_c23) {
return std::unexpected{make_error("target C compiler does not support -std=c23")};
}
} else {
if (request.cxx_standard == CxxStandard::Cxx17 && !toolchain.supports_cxx17) {
return std::unexpected{make_error("target compiler does not support -std=c++17")};
}
if (request.cxx_standard == CxxStandard::Cxx20 && !toolchain.supports_cxx20) {
return std::unexpected{make_error("target compiler does not support -std=c++20")};
}
if (request.cxx_standard == CxxStandard::Cxx23 && !toolchain.supports_cxx23) {
return std::unexpected{make_error("target compiler does not support -std=c++23")};
}
if (request.cxx_standard == CxxStandard::Cxx26 && !toolchain.supports_cxx26) {
return std::unexpected{make_error("target compiler does not support -std=c++26")};
}
}
if (request.lto == LtoMode::Full && !toolchain.supports_lto_full) {
return std::unexpected{make_error("target compiler does not support full LTO (-flto)")};
@@ -495,14 +623,20 @@ lower_compile_command(const ToolchainCapabilities &toolchain, const CompileReque
}
LoweredCommand cmd;
cmd.executable = toolchain.cxx_compiler;
cmd.executable = request.is_c_source ? toolchain.c_compiler : toolchain.cxx_compiler;
std::vector<std::string> args;
if (!toolchain.sysroot.empty()) {
args.push_back("--sysroot=" + toolchain.sysroot);
}
if (const auto std_flag = cxx_standard_flag(request.cxx_standard); !std_flag.empty()) {
args.push_back(std_flag);
if (request.is_c_source) {
if (const auto std_flag = c_standard_flag(request.c_standard); !std_flag.empty()) {
args.push_back(std_flag);
}
} else {
if (const auto std_flag = cxx_standard_flag(request.cxx_standard); !std_flag.empty()) {
args.push_back(std_flag);
}
}
if (request.position_independent) {
args.push_back("-fPIC");