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
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
This commit is contained in:
1 parent
5e1916dc5c
commit
6c225c2dff
27 files changed
+3443
-331
No files matched your search
@@ -266,6 +266,36 @@ SourceKind parse_source_kind(std::string_view name) {
|
||||
throw std::invalid_argument{"unknown source kind '" + std::string{name} + "'"};
|
||||
}
|
||||
|
||||
std::string_view c_standard_name(CStandard standard) {
|
||||
switch (standard) {
|
||||
case CStandard::Default:
|
||||
return "default";
|
||||
case CStandard::C11:
|
||||
return "c11";
|
||||
case CStandard::C17:
|
||||
return "c17";
|
||||
case CStandard::C23:
|
||||
return "c23";
|
||||
}
|
||||
throw std::invalid_argument{"unknown C standard"};
|
||||
}
|
||||
|
||||
CStandard parse_c_standard(std::string_view name) {
|
||||
if (name.empty() || name == "default") {
|
||||
return CStandard::Default;
|
||||
}
|
||||
if (name == "c11" || name == "11") {
|
||||
return CStandard::C11;
|
||||
}
|
||||
if (name == "c17" || name == "17" || name == "c18") {
|
||||
return CStandard::C17;
|
||||
}
|
||||
if (name == "c23" || name == "23" || name == "c2x") {
|
||||
return CStandard::C23;
|
||||
}
|
||||
throw std::invalid_argument{"unknown C standard '" + std::string{name} + "'"};
|
||||
}
|
||||
|
||||
std::string_view cxx_standard_name(CxxStandard standard) {
|
||||
switch (standard) {
|
||||
case CxxStandard::Default:
|
||||
@@ -451,6 +481,9 @@ ProfileContext Profiles::resolve(std::string_view name,
|
||||
if (desc->compiler) {
|
||||
context.compiler = *desc->compiler;
|
||||
}
|
||||
if (desc->c_standard) {
|
||||
context.c_standard = *desc->c_standard;
|
||||
}
|
||||
if (desc->cxx_standard) {
|
||||
context.cxx_standard = *desc->cxx_standard;
|
||||
}
|
||||
@@ -499,6 +532,9 @@ std::string Profiles::to_json() const {
|
||||
if (p.compiler) {
|
||||
out += ",\"compiler\":" + json_quote(compiler_name(*p.compiler));
|
||||
}
|
||||
if (p.c_standard) {
|
||||
out += ",\"c_standard\":" + json_quote(c_standard_name(*p.c_standard));
|
||||
}
|
||||
if (p.cxx_standard) {
|
||||
out += ",\"cxx_standard\":" + json_quote(cxx_standard_name(*p.cxx_standard));
|
||||
}
|
||||
@@ -701,6 +737,12 @@ Target &Target::depends_on(const Target &producer) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Target &Target::c_standard(CStandard standard) {
|
||||
(void)c_standard_name(standard);
|
||||
owner(owner_)->targets.at(index_).c_standard = standard;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Target &Target::cxx_standard(CxxStandard standard) {
|
||||
(void)cxx_standard_name(standard);
|
||||
owner(owner_)->targets.at(index_).cxx_standard = standard;
|
||||
@@ -1065,6 +1107,7 @@ std::string Project::to_json() const {
|
||||
",\"compile_options\":" + json_array(profile.compile_options, json_quote) +
|
||||
",\"link_options\":" + json_array(profile.link_options, json_quote) +
|
||||
",\"defines\":" + json_array(profile.defines, json_quote) +
|
||||
",\"c_standard\":" + json_quote(c_standard_name(profile.c_standard)) +
|
||||
",\"cxx_standard\":" + json_quote(cxx_standard_name(profile.cxx_standard)) +
|
||||
",\"lto\":" + json_quote(lto_mode_name(profile.lto)) + ",\"sanitizers\":" +
|
||||
json_array(profile.sanitizers, [](Sanitizer s) { return json_quote(sanitizer_name(s)); }) +
|
||||
@@ -1104,6 +1147,7 @@ std::string Project::to_json() const {
|
||||
json_quote(visibility_name(link.visibility)) + '}';
|
||||
}) +
|
||||
",\"prerequisites\":" + json_array(target.prerequisites, json_quote) +
|
||||
",\"c_standard\":" + json_quote(c_standard_name(target.c_standard)) +
|
||||
",\"cxx_standard\":" + json_quote(cxx_standard_name(target.cxx_standard)) +
|
||||
",\"precompiled_header\":" + json_quote(target.precompiled_header) +
|
||||
",\"unity_enabled\":" + std::string{target.unity_enabled ? "true" : "false"} +
|
||||
|
||||
@@ -105,6 +105,7 @@ Void::Build::ProfileContext parse_kv_context(std::string_view text) {
|
||||
else if (key == "compiler") ctx.compiler = Void::Build::parse_compiler(val);
|
||||
else if (key == "os") ctx.os = val;
|
||||
else if (key == "architecture") ctx.architecture = val;
|
||||
else if (key == "c_standard") ctx.c_standard = Void::Build::parse_c_standard(val);
|
||||
else if (key == "cxx_standard") ctx.cxx_standard = Void::Build::parse_cxx_standard(val);
|
||||
else if (key == "lto") ctx.lto = Void::Build::parse_lto_mode(val);
|
||||
else if (key == "sysroot") ctx.sysroot = val;
|
||||
@@ -182,6 +183,7 @@ std::string serialize_kv_context(const ProfileContext &ctx) {
|
||||
out += "compiler=" + std::string{compiler_name(ctx.compiler)} + "\n";
|
||||
out += "os=" + ctx.os + "\n";
|
||||
out += "architecture=" + ctx.architecture + "\n";
|
||||
out += "c_standard=" + std::string{Void::Build::c_standard_name(ctx.c_standard)} + "\n";
|
||||
out += "cxx_standard=" + std::string{cxx_standard_name(ctx.cxx_standard)} + "\n";
|
||||
out += "lto=" + std::string{lto_mode_name(ctx.lto)} + "\n";
|
||||
out += "sysroot=" + ctx.sysroot + "\n";
|
||||
@@ -629,6 +631,9 @@ discover_profiles(const CompiledDescriptor &descriptor, const FrontendOptions &o
|
||||
if (auto comp = get_str(*po, "compiler"); comp && !comp->empty()) {
|
||||
pd.compiler = parse_compiler(*comp);
|
||||
}
|
||||
if (auto std_str = get_str(*po, "c_standard"); std_str && !std_str->empty()) {
|
||||
pd.c_standard = Void::Build::parse_c_standard(*std_str);
|
||||
}
|
||||
if (auto std_str = get_str(*po, "cxx_standard"); std_str && !std_str->empty()) {
|
||||
pd.cxx_standard = parse_cxx_standard(*std_str);
|
||||
}
|
||||
|
||||
+522
-4
@@ -46,6 +46,20 @@ std::string_view status_name(GenerationStatus s) {
|
||||
return "invalid";
|
||||
}
|
||||
|
||||
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:
|
||||
@@ -193,6 +207,48 @@ update_managed_root_alias(const std::filesystem::path &project_root,
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string escape_xml_attr(std::string_view sv) {
|
||||
std::string out;
|
||||
out.reserve(sv.size());
|
||||
for (const char c : sv) {
|
||||
switch (c) {
|
||||
case '&':
|
||||
out += "&";
|
||||
break;
|
||||
case '<':
|
||||
out += "<";
|
||||
break;
|
||||
case '>':
|
||||
out += ">";
|
||||
break;
|
||||
case '"':
|
||||
out += """;
|
||||
break;
|
||||
case '\'':
|
||||
out += "'";
|
||||
break;
|
||||
default:
|
||||
out.push_back(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string workspace_var_path(const std::filesystem::path &project_root,
|
||||
const std::filesystem::path &target, std::string_view prefix_var) {
|
||||
const auto norm_root = project_root.lexically_normal();
|
||||
const auto norm_target = target.lexically_normal();
|
||||
if (!norm_root.empty() && Platform::path_is_within(norm_root, norm_target)) {
|
||||
const auto rel = norm_target.lexically_relative(norm_root);
|
||||
if (!rel.empty() && rel != ".") {
|
||||
return std::string{prefix_var} + "/" + rel.generic_string();
|
||||
}
|
||||
return std::string{prefix_var};
|
||||
}
|
||||
return norm_target.string();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::vector<EditorCommandEntry> project_editor_commands(const Graph::BuildGraph &graph) {
|
||||
@@ -228,8 +284,14 @@ std::vector<EditorCommandEntry> project_editor_commands(const Graph::BuildGraph
|
||||
if (!graph.toolchain.sysroot.empty()) {
|
||||
entry.arguments.push_back("--sysroot=" + graph.toolchain.sysroot);
|
||||
}
|
||||
if (const auto std_flag = cxx_standard_flag(act.cxx_standard); !std_flag.empty()) {
|
||||
entry.arguments.push_back(std_flag);
|
||||
if (act.is_c_source) {
|
||||
if (const auto std_flag = c_standard_flag(act.c_standard); !std_flag.empty()) {
|
||||
entry.arguments.push_back(std_flag);
|
||||
}
|
||||
} else {
|
||||
if (const auto std_flag = cxx_standard_flag(act.cxx_standard); !std_flag.empty()) {
|
||||
entry.arguments.push_back(std_flag);
|
||||
}
|
||||
}
|
||||
if (act.position_independent) {
|
||||
entry.arguments.push_back("-fPIC");
|
||||
@@ -250,7 +312,7 @@ std::vector<EditorCommandEntry> project_editor_commands(const Graph::BuildGraph
|
||||
entry.arguments.push_back("-fsanitize=" + list);
|
||||
entry.arguments.push_back("-fno-omit-frame-pointer");
|
||||
}
|
||||
if (act.precompiled_header) {
|
||||
if (act.precompiled_header && !act.is_c_source) {
|
||||
entry.arguments.push_back("-include");
|
||||
entry.arguments.push_back(act.precompiled_header->string());
|
||||
}
|
||||
@@ -292,6 +354,76 @@ std::vector<EditorCommandEntry> project_editor_commands(const Graph::BuildGraph
|
||||
return entries;
|
||||
}
|
||||
|
||||
std::vector<EditorCommandEntry> project_build_descriptor_commands(
|
||||
const std::filesystem::path &project_root, const std::filesystem::path &build_root,
|
||||
const std::filesystem::path &sdk_include_dir, const std::filesystem::path &host_cxx_compiler,
|
||||
const std::vector<std::filesystem::path> &extra_build_sources) {
|
||||
std::vector<EditorCommandEntry> entries;
|
||||
if (sdk_include_dir.empty() || host_cxx_compiler.empty()) {
|
||||
return entries;
|
||||
}
|
||||
|
||||
std::error_code ec;
|
||||
const auto raw_canon = std::filesystem::weakly_canonical(project_root, ec);
|
||||
const auto canon_root = (ec ? project_root : raw_canon).lexically_normal();
|
||||
const auto desc_obj_root = build_root / ".vbs" / "editor-desc";
|
||||
|
||||
std::vector<std::filesystem::path> candidates;
|
||||
std::set<std::filesystem::path> seen;
|
||||
auto push_if_file = [&](const std::filesystem::path &p) {
|
||||
const auto norm = (p.is_absolute() ? p : (canon_root / p)).lexically_normal();
|
||||
if (std::filesystem::is_regular_file(norm, ec) && seen.insert(norm).second) {
|
||||
candidates.push_back(norm);
|
||||
}
|
||||
};
|
||||
|
||||
push_if_file("build.cpp");
|
||||
push_if_file("build.profiles.cpp");
|
||||
const auto support_dir = canon_root / "build-support";
|
||||
if (std::filesystem::is_directory(support_dir, ec)) {
|
||||
std::vector<std::filesystem::path> support_files;
|
||||
for (const auto &ent : std::filesystem::recursive_directory_iterator(support_dir, ec)) {
|
||||
if (!ent.is_regular_file(ec)) {
|
||||
continue;
|
||||
}
|
||||
const auto ext = ent.path().extension().string();
|
||||
if (ext == ".cpp" || ext == ".cc" || ext == ".cxx") {
|
||||
support_files.push_back(ent.path().lexically_normal());
|
||||
}
|
||||
}
|
||||
std::ranges::sort(support_files);
|
||||
for (const auto &sf : support_files) {
|
||||
push_if_file(sf);
|
||||
}
|
||||
}
|
||||
for (const auto &extra : extra_build_sources) {
|
||||
push_if_file(extra);
|
||||
}
|
||||
|
||||
const bool has_support = std::filesystem::is_directory(support_dir, ec);
|
||||
for (const auto &src : candidates) {
|
||||
const std::string tag = Util::sha256_hex(src.string()).substr(0, 12);
|
||||
const auto out_obj = desc_obj_root / (src.filename().string() + "_" + tag + ".o");
|
||||
EditorCommandEntry entry;
|
||||
entry.directory = canon_root;
|
||||
entry.file = src;
|
||||
entry.output = out_obj;
|
||||
entry.target_name = "__vbs_build_description";
|
||||
entry.arguments = {host_cxx_compiler.string(), "-std=c++26", "-I",
|
||||
sdk_include_dir.lexically_normal().string()};
|
||||
if (has_support) {
|
||||
entry.arguments.push_back("-I");
|
||||
entry.arguments.push_back(support_dir.string());
|
||||
}
|
||||
entry.arguments.push_back("-c");
|
||||
entry.arguments.push_back(src.string());
|
||||
entry.arguments.push_back("-o");
|
||||
entry.arguments.push_back(out_obj.string());
|
||||
entries.push_back(std::move(entry));
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
std::string format_compile_commands_json(const std::vector<EditorCommandEntry> &entries) {
|
||||
using Util::json_array;
|
||||
using Util::json_quote;
|
||||
@@ -339,7 +471,20 @@ reserve_selection_ticket(const std::filesystem::path &project_root,
|
||||
|
||||
Void::Result::Result<EditorGeneration, Void::Result::Error>
|
||||
publish_profile_compdb(const Graph::BuildGraph &graph, const PublishOptions &options) {
|
||||
const auto entries = project_editor_commands(graph);
|
||||
auto entries = project_editor_commands(graph);
|
||||
if (!options.sdk_include_dir.empty()) {
|
||||
auto desc_entries = project_build_descriptor_commands(
|
||||
options.project_root, options.build_root, options.sdk_include_dir,
|
||||
graph.toolchain.cxx_compiler, options.extra_build_sources);
|
||||
for (auto &de : desc_entries) {
|
||||
const bool already = std::ranges::any_of(entries, [&](const EditorCommandEntry &ex) {
|
||||
return ex.file.lexically_normal() == de.file.lexically_normal();
|
||||
});
|
||||
if (!already) {
|
||||
entries.push_back(std::move(de));
|
||||
}
|
||||
}
|
||||
}
|
||||
const std::string compdb_json = format_compile_commands_json(entries);
|
||||
const std::string gen_id =
|
||||
Util::sha256_hex(graph.profile_identity + "\n" + compdb_json).substr(0, 16);
|
||||
@@ -571,4 +716,377 @@ recover_editor_pointers(const std::filesystem::path &project_root) {
|
||||
return {};
|
||||
}
|
||||
|
||||
Void::Result::Result<IdeKind, Void::Result::Error> parse_ide_kind(std::string_view name) {
|
||||
if (name == "all" || name == "All") {
|
||||
return IdeKind::All;
|
||||
}
|
||||
if (name == "clangd" || name == "Clangd") {
|
||||
return IdeKind::Clangd;
|
||||
}
|
||||
if (name == "vscode" || name == "VsCode") {
|
||||
return IdeKind::VsCode;
|
||||
}
|
||||
if (name == "clion" || name == "CLion") {
|
||||
return IdeKind::CLion;
|
||||
}
|
||||
if (name == "zed" || name == "Zed") {
|
||||
return IdeKind::Zed;
|
||||
}
|
||||
return std::unexpected{make_error(
|
||||
std::format("unknown IDE kind '{}' (expected: all, clangd, vscode, clion, zed)", name))};
|
||||
}
|
||||
|
||||
std::string_view ide_kind_name(IdeKind kind) {
|
||||
switch (kind) {
|
||||
case IdeKind::Clangd:
|
||||
return "clangd";
|
||||
case IdeKind::VsCode:
|
||||
return "vscode";
|
||||
case IdeKind::CLion:
|
||||
return "clion";
|
||||
case IdeKind::Zed:
|
||||
return "zed";
|
||||
case IdeKind::All:
|
||||
return "all";
|
||||
}
|
||||
return "all";
|
||||
}
|
||||
|
||||
Void::Result::Result<IdeConfigReport, Void::Result::Error>
|
||||
generate_ide_configs(const Graph::BuildGraph &graph, const IdeConfigOptions &options) {
|
||||
using Util::json_array;
|
||||
using Util::json_quote;
|
||||
|
||||
const auto proj_root =
|
||||
(options.project_root.empty() ? graph.project_root : options.project_root)
|
||||
.lexically_normal();
|
||||
const auto build_root =
|
||||
(options.build_root.empty() ? graph.profile_build_dir.parent_path().parent_path()
|
||||
: options.build_root)
|
||||
.lexically_normal();
|
||||
const auto vbs_bin =
|
||||
options.vbs_executable.empty() ? std::string{"vbs"} : options.vbs_executable.string();
|
||||
|
||||
std::filesystem::path compdb_dir = build_root;
|
||||
if (!options.compdb_path.empty()) {
|
||||
compdb_dir =
|
||||
options.compdb_path.has_parent_path() ? options.compdb_path.parent_path() : compdb_dir;
|
||||
}
|
||||
compdb_dir = compdb_dir.lexically_normal();
|
||||
std::string compdb_rel_or_abs = compdb_dir.string();
|
||||
if (Platform::path_is_within(proj_root, compdb_dir)) {
|
||||
const auto rel = compdb_dir.lexically_relative(proj_root);
|
||||
compdb_rel_or_abs = rel.empty() ? "." : rel.generic_string();
|
||||
}
|
||||
|
||||
IdeConfigReport report;
|
||||
std::error_code ec;
|
||||
auto write_ide_file =
|
||||
[&](const std::filesystem::path &path,
|
||||
std::string_view content) -> Void::Result::Result<void, Void::Result::Error> {
|
||||
if (!options.force &&
|
||||
(std::filesystem::exists(path, ec) || std::filesystem::is_symlink(path, ec))) {
|
||||
report.skipped_existing_files.push_back(path);
|
||||
return {};
|
||||
}
|
||||
auto w = Platform::atomic_write_file(path, content, false);
|
||||
if (!w) {
|
||||
return std::unexpected{w.error()};
|
||||
}
|
||||
report.written_files.push_back(path);
|
||||
return {};
|
||||
};
|
||||
|
||||
const bool want_all = (options.editor == IdeKind::All);
|
||||
|
||||
// 1. .clangd configuration (GCC-16 flag sanitization + CompilationDatabase pointer).
|
||||
if (want_all || options.editor == IdeKind::Clangd) {
|
||||
std::string yaml = "# Generated by VoidBuildSystem (`vbs ide generate`). Re-run with "
|
||||
"`--force` to update.\n"
|
||||
"CompileFlags:\n"
|
||||
" CompilationDatabase: " +
|
||||
json_quote(compdb_rel_or_abs) +
|
||||
"\n"
|
||||
" Remove:\n"
|
||||
" - -freflection\n"
|
||||
" - -fmodules\n"
|
||||
" - -fmodules-ts\n"
|
||||
" - \"-fmodule-mapper=*\"\n"
|
||||
" - \"-frandom-seed=*\"\n"
|
||||
" - \"-fdeps-format=*\"\n"
|
||||
" - \"-fdeps-file=*\"\n"
|
||||
" - \"-fdeps-target=*\"\n";
|
||||
if (auto r = write_ide_file(proj_root / ".clangd", yaml); !r) {
|
||||
return std::unexpected{r.error()};
|
||||
}
|
||||
}
|
||||
|
||||
struct RunnableTarget {
|
||||
std::string name;
|
||||
bool is_test{false};
|
||||
std::filesystem::path program;
|
||||
};
|
||||
std::vector<RunnableTarget> runnables;
|
||||
std::vector<std::string> buildable_targets;
|
||||
for (const auto &t : graph.targets) {
|
||||
if (!t.enabled) {
|
||||
continue;
|
||||
}
|
||||
if (t.kind == TargetKind::Executable || t.kind == TargetKind::Test ||
|
||||
t.kind == TargetKind::StaticLibrary || t.kind == TargetKind::SharedLibrary) {
|
||||
buildable_targets.push_back(t.name);
|
||||
}
|
||||
if ((t.kind == TargetKind::Executable || t.kind == TargetKind::Test) &&
|
||||
!t.primary_outputs.empty()) {
|
||||
runnables.push_back({t.name, t.kind == TargetKind::Test, t.primary_outputs.front()});
|
||||
}
|
||||
}
|
||||
|
||||
// 2. VS Code / Cursor / Antigravity (.vscode/tasks.json, launch.json, settings.json).
|
||||
if (want_all || options.editor == IdeKind::VsCode) {
|
||||
auto make_vs_task = [&](const std::string &label, const std::vector<std::string> &args,
|
||||
const std::string &group, bool is_default) {
|
||||
std::string t = " {\n";
|
||||
t += " \"label\": " + json_quote(label) + ",\n";
|
||||
t += " \"type\": \"process\",\n";
|
||||
t += " \"command\": " + json_quote(vbs_bin) + ",\n";
|
||||
t += " \"args\": " + json_array(args, json_quote) + ",\n";
|
||||
t += " \"options\": {\"cwd\": \"${workspaceFolder}\"},\n";
|
||||
if (!group.empty()) {
|
||||
if (is_default) {
|
||||
t += " \"group\": {\"kind\": " + json_quote(group) +
|
||||
", \"isDefault\": true},\n";
|
||||
} else {
|
||||
t += " \"group\": " + json_quote(group) + ",\n";
|
||||
}
|
||||
}
|
||||
t += " \"problemMatcher\": [\"$gcc\"]\n";
|
||||
t += " }";
|
||||
return t;
|
||||
};
|
||||
|
||||
std::vector<std::string> vs_tasks;
|
||||
vs_tasks.push_back(make_vs_task("vbs: build (" + graph.profile.name + ")",
|
||||
{"build", "--profile", graph.profile.name}, "build", true));
|
||||
vs_tasks.push_back(make_vs_task("vbs: test (" + graph.profile.name + ")",
|
||||
{"test", "--profile", graph.profile.name}, "test", true));
|
||||
vs_tasks.push_back(make_vs_task("vbs: clean", {"clean"}, "", false));
|
||||
vs_tasks.push_back(make_vs_task("vbs: refresh compile_commands.json",
|
||||
{"compdb", "export", "--profile", graph.profile.name}, "",
|
||||
false));
|
||||
for (const auto &tname : buildable_targets) {
|
||||
vs_tasks.push_back(make_vs_task(
|
||||
"vbs: build " + tname,
|
||||
{"build", "--profile", graph.profile.name, "--target", tname}, "build", false));
|
||||
}
|
||||
for (const auto &rt : runnables) {
|
||||
if (rt.is_test) {
|
||||
vs_tasks.push_back(make_vs_task(
|
||||
"vbs: test " + rt.name,
|
||||
{"test", "--profile", graph.profile.name, "--target", rt.name}, "test", false));
|
||||
}
|
||||
}
|
||||
|
||||
std::string tasks_json = "{\n \"version\": \"2.0.0\",\n \"tasks\": [\n";
|
||||
for (std::size_t i = 0; i < vs_tasks.size(); ++i) {
|
||||
tasks_json += vs_tasks[i];
|
||||
if (i + 1 < vs_tasks.size()) {
|
||||
tasks_json += ',';
|
||||
}
|
||||
tasks_json += '\n';
|
||||
}
|
||||
tasks_json += " ]\n}\n";
|
||||
if (auto r = write_ide_file(proj_root / ".vscode" / "tasks.json", tasks_json); !r) {
|
||||
return std::unexpected{r.error()};
|
||||
}
|
||||
|
||||
std::string launch_json = "{\n \"version\": \"0.2.0\",\n \"configurations\": [\n";
|
||||
for (std::size_t i = 0; i < runnables.size(); ++i) {
|
||||
const auto &rt = runnables[i];
|
||||
const std::string prog =
|
||||
workspace_var_path(proj_root, rt.program, "${workspaceFolder}");
|
||||
launch_json += " {\n";
|
||||
launch_json += " \"name\": " + json_quote("Debug " + rt.name + " (vbs)") + ",\n";
|
||||
launch_json += " \"type\": \"cppdbg\",\n";
|
||||
launch_json += " \"request\": \"launch\",\n";
|
||||
launch_json += " \"program\": " + json_quote(prog) + ",\n";
|
||||
launch_json += " \"args\": [],\n";
|
||||
launch_json += " \"stopAtEntry\": false,\n";
|
||||
launch_json += " \"cwd\": \"${workspaceFolder}\",\n";
|
||||
launch_json += " \"MIMode\": \"gdb\",\n";
|
||||
launch_json += " \"preLaunchTask\": " + json_quote("vbs: build " + rt.name) + "\n";
|
||||
launch_json += " }";
|
||||
if (i + 1 < runnables.size()) {
|
||||
launch_json += ',';
|
||||
}
|
||||
launch_json += '\n';
|
||||
}
|
||||
launch_json += " ]\n}\n";
|
||||
if (auto r = write_ide_file(proj_root / ".vscode" / "launch.json", launch_json); !r) {
|
||||
return std::unexpected{r.error()};
|
||||
}
|
||||
|
||||
const std::filesystem::path compdb_file = options.compdb_path.empty()
|
||||
? (compdb_dir / "compile_commands.json")
|
||||
: options.compdb_path;
|
||||
const std::string vs_compdb =
|
||||
workspace_var_path(proj_root, compdb_file, "${workspaceFolder}");
|
||||
const std::string vs_compdb_dir =
|
||||
workspace_var_path(proj_root, compdb_dir, "${workspaceFolder}");
|
||||
std::string settings_json =
|
||||
"{\n"
|
||||
" \"C_Cpp.default.compileCommands\": " +
|
||||
json_quote(vs_compdb) +
|
||||
",\n"
|
||||
" \"C_Cpp.intelliSenseEngine\": \"disabled\",\n"
|
||||
" \"clangd.arguments\": " +
|
||||
json_array(std::vector<std::string>{"--compile-commands-dir=" + vs_compdb_dir,
|
||||
"--header-insertion=never"},
|
||||
json_quote) +
|
||||
",\n"
|
||||
" \"files.exclude\": {\n"
|
||||
" \"**/.vbs\": true\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
if (auto r = write_ide_file(proj_root / ".vscode" / "settings.json", settings_json); !r) {
|
||||
return std::unexpected{r.error()};
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Zed (.zed/tasks.json, .zed/debug.json).
|
||||
if (want_all || options.editor == IdeKind::Zed) {
|
||||
auto make_zed_task = [&](const std::string &label, const std::vector<std::string> &args) {
|
||||
return " {\"label\": " + json_quote(label) + ", \"command\": " + json_quote(vbs_bin) +
|
||||
", \"args\": " + json_array(args, json_quote) +
|
||||
", \"cwd\": \"$ZED_WORKTREE_ROOT\"}";
|
||||
};
|
||||
std::vector<std::string> ztasks;
|
||||
ztasks.push_back(make_zed_task("vbs: build", {"build", "--profile", graph.profile.name}));
|
||||
ztasks.push_back(make_zed_task("vbs: test", {"test", "--profile", graph.profile.name}));
|
||||
ztasks.push_back(make_zed_task("vbs: clean", {"clean"}));
|
||||
for (const auto &rt : runnables) {
|
||||
ztasks.push_back(
|
||||
make_zed_task("vbs: build " + rt.name,
|
||||
{"build", "--profile", graph.profile.name, "--target", rt.name}));
|
||||
if (rt.is_test) {
|
||||
ztasks.push_back(
|
||||
make_zed_task("vbs: test " + rt.name,
|
||||
{"test", "--profile", graph.profile.name, "--target", rt.name}));
|
||||
}
|
||||
}
|
||||
std::string ztasks_json = "[\n";
|
||||
for (std::size_t i = 0; i < ztasks.size(); ++i) {
|
||||
ztasks_json += ztasks[i];
|
||||
if (i + 1 < ztasks.size()) {
|
||||
ztasks_json += ',';
|
||||
}
|
||||
ztasks_json += '\n';
|
||||
}
|
||||
ztasks_json += "]\n";
|
||||
if (auto r = write_ide_file(proj_root / ".zed" / "tasks.json", ztasks_json); !r) {
|
||||
return std::unexpected{r.error()};
|
||||
}
|
||||
|
||||
std::string zdebug_json = "[\n";
|
||||
for (std::size_t i = 0; i < runnables.size(); ++i) {
|
||||
const auto &rt = runnables[i];
|
||||
const std::string prog =
|
||||
workspace_var_path(proj_root, rt.program, "$ZED_WORKTREE_ROOT");
|
||||
zdebug_json += " {\n";
|
||||
zdebug_json += " \"label\": " + json_quote("Debug " + rt.name + " (vbs)") + ",\n";
|
||||
zdebug_json += " \"adapter\": \"CodeLLDB\",\n";
|
||||
zdebug_json += " \"request\": \"launch\",\n";
|
||||
zdebug_json += " \"program\": " + json_quote(prog) + ",\n";
|
||||
zdebug_json += " \"cwd\": \"$ZED_WORKTREE_ROOT\"\n";
|
||||
zdebug_json += " }";
|
||||
if (i + 1 < runnables.size()) {
|
||||
zdebug_json += ',';
|
||||
}
|
||||
zdebug_json += '\n';
|
||||
}
|
||||
zdebug_json += "]\n";
|
||||
if (auto r = write_ide_file(proj_root / ".zed" / "debug.json", zdebug_json); !r) {
|
||||
return std::unexpected{r.error()};
|
||||
}
|
||||
}
|
||||
|
||||
// 4. CLion Custom Build Targets (.idea/customTargets.xml).
|
||||
if (want_all || options.editor == IdeKind::CLion) {
|
||||
const std::string vbs_xml = escape_xml_attr(vbs_bin);
|
||||
const std::string prof_xml = escape_xml_attr(graph.profile.name);
|
||||
std::string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
"<project version=\"4\">\n"
|
||||
" <component name=\"CLionExternalBuildManager\">\n"
|
||||
" <target id=\"vbs-build\" name=\"vbs build\" defaultType=\"TOOL\">\n"
|
||||
" <configuration id=\"vbs-build-cfg\" name=\"" +
|
||||
prof_xml +
|
||||
"\">\n"
|
||||
" <build type=\"TOOL\">\n"
|
||||
" <tool name=\"vbs build\" program=\"" +
|
||||
vbs_xml + "\" arguments=\"build --profile " + prof_xml +
|
||||
"\" workingDir=\"$PROJECT_DIR$\" />\n"
|
||||
" </build>\n"
|
||||
" <clean type=\"TOOL\">\n"
|
||||
" <tool name=\"vbs clean\" program=\"" +
|
||||
vbs_xml +
|
||||
"\" arguments=\"clean\" workingDir=\"$PROJECT_DIR$\" />\n"
|
||||
" </clean>\n"
|
||||
" </configuration>\n"
|
||||
" </target>\n"
|
||||
" </component>\n"
|
||||
"</project>\n";
|
||||
if (auto r = write_ide_file(proj_root / ".idea" / "customTargets.xml", xml); !r) {
|
||||
return std::unexpected{r.error()};
|
||||
}
|
||||
}
|
||||
|
||||
return report;
|
||||
}
|
||||
|
||||
std::string format_ide_query_json(const Graph::BuildGraph &graph,
|
||||
const std::filesystem::path &compdb_path,
|
||||
const std::filesystem::path &sdk_include_dir) {
|
||||
using Util::json_array;
|
||||
using Util::json_quote;
|
||||
|
||||
const auto build_root = graph.profile_build_dir.parent_path().parent_path().lexically_normal();
|
||||
std::string out = "{";
|
||||
out += "\"schema_version\":1";
|
||||
out += ",\"project_root\":" + json_quote(graph.project_root.string());
|
||||
out += ",\"build_root\":" + json_quote(build_root.string());
|
||||
out += ",\"profile\":" + json_quote(graph.profile.name);
|
||||
out += ",\"profile_identity\":" + json_quote(graph.profile_identity);
|
||||
out += ",\"compiler_family\":" + json_quote(compiler_name(graph.toolchain.family));
|
||||
out += ",\"c_compiler\":" + json_quote(graph.toolchain.c_compiler.string());
|
||||
out += ",\"cxx_compiler\":" + json_quote(graph.toolchain.cxx_compiler.string());
|
||||
out += ",\"sdk_include_dir\":" + json_quote(sdk_include_dir.string());
|
||||
out += ",\"compdb_path\":" + json_quote(compdb_path.string());
|
||||
out += ",\"targets\":[";
|
||||
for (std::size_t i = 0; i < graph.targets.size(); ++i) {
|
||||
const auto &t = graph.targets[i];
|
||||
if (i > 0) {
|
||||
out += ',';
|
||||
}
|
||||
const bool is_exec = (t.kind == TargetKind::Executable);
|
||||
const bool is_test = (t.kind == TargetKind::Test);
|
||||
out += "{\"name\":" + json_quote(t.name);
|
||||
out += ",\"kind\":" + json_quote(target_kind_name(t.kind));
|
||||
out += ",\"enabled\":" + std::string{t.enabled ? "true" : "false"};
|
||||
out += ",\"is_executable\":" + std::string{is_exec ? "true" : "false"};
|
||||
out += ",\"is_test\":" + std::string{is_test ? "true" : "false"};
|
||||
out += ",\"sources\":" + json_array(t.expanded_sources, [](const std::filesystem::path &p) {
|
||||
return json_quote(p.string());
|
||||
});
|
||||
out += ",\"primary_outputs\":" +
|
||||
json_array(t.primary_outputs,
|
||||
[](const std::filesystem::path &p) { return json_quote(p.string()); });
|
||||
out += ",\"runtime_shared_libraries\":" +
|
||||
json_array(t.runtime_shared_libraries,
|
||||
[](const std::filesystem::path &p) { return json_quote(p.string()); });
|
||||
out += '}';
|
||||
}
|
||||
out += "]}\n";
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace Void::Build::Editor
|
||||
+255
-110
@@ -110,6 +110,10 @@ bool is_module_source_extension(const std::filesystem::path &p) {
|
||||
return ext == ".cppm" || ext == ".ixx" || ext == ".ccm";
|
||||
}
|
||||
|
||||
bool is_c_source_extension(const std::filesystem::path &p) {
|
||||
return p.extension().string() == ".c";
|
||||
}
|
||||
|
||||
bool is_cpp_source_extension(const std::filesystem::path &p) {
|
||||
const auto ext = p.extension().string();
|
||||
return ext == ".cpp" || ext == ".cc" || ext == ".cxx" || ext == ".c" ||
|
||||
@@ -221,6 +225,7 @@ ProjectDescription::from_json(std::string_view json_text) {
|
||||
desc.profile.compile_options = get_str_array(*prof, "compile_options");
|
||||
desc.profile.link_options = get_str_array(*prof, "link_options");
|
||||
desc.profile.defines = get_str_array(*prof, "defines");
|
||||
desc.profile.c_standard = parse_c_standard(get_str(*prof, "c_standard", "default"));
|
||||
desc.profile.cxx_standard = parse_cxx_standard(get_str(*prof, "cxx_standard", "default"));
|
||||
desc.profile.lto = parse_lto_mode(get_str(*prof, "lto", "none"));
|
||||
for (const auto &s : get_str_array(*prof, "sanitizers")) {
|
||||
@@ -292,6 +297,7 @@ ProjectDescription::from_json(std::string_view json_text) {
|
||||
}
|
||||
}
|
||||
t.prerequisites = get_str_array(*to, "prerequisites");
|
||||
t.c_standard = parse_c_standard(get_str(*to, "c_standard", "default"));
|
||||
t.cxx_standard = parse_cxx_standard(get_str(*to, "cxx_standard", "default"));
|
||||
t.precompiled_header = get_str(*to, "precompiled_header");
|
||||
t.unity_enabled = get_bool(*to, "unity_enabled", false);
|
||||
@@ -661,6 +667,8 @@ lower_project_graph(const ProjectDescription &description,
|
||||
std::vector<std::filesystem::path> exported_objects;
|
||||
std::vector<std::string> exported_link_options;
|
||||
std::vector<std::string> exported_prerequisite_actions;
|
||||
std::map<std::string, std::filesystem::path, std::less<>> exported_module_bmis;
|
||||
std::map<std::string, std::string, std::less<>> exported_module_action_ids;
|
||||
};
|
||||
std::map<std::string, TargetComputed, std::less<>> computed;
|
||||
|
||||
@@ -731,6 +739,7 @@ lower_project_graph(const ProjectDescription &description,
|
||||
}
|
||||
for (const auto &aid : computed.at(pre_name).exported_prerequisite_actions) {
|
||||
add_unique_str(target_prereq_actions, aid);
|
||||
add_unique_str(tc.exported_prerequisite_actions, aid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -783,7 +792,13 @@ lower_project_graph(const ProjectDescription &description,
|
||||
|
||||
for (const auto &in : t.action_inputs) {
|
||||
const auto p = std::filesystem::path{in};
|
||||
act.declared_inputs.push_back(p.is_absolute() ? p : (canonical_root / p));
|
||||
const auto resolved_in =
|
||||
(p.is_absolute() ? p : (canonical_root / p)).lexically_normal();
|
||||
if (const auto prod_it = output_owner.find(resolved_in);
|
||||
prod_it != output_owner.end()) {
|
||||
add_unique_str(act.dependencies, prod_it->second);
|
||||
}
|
||||
act.declared_inputs.push_back(resolved_in);
|
||||
}
|
||||
for (const auto &out : t.action_outputs) {
|
||||
const auto p = std::filesystem::path{out};
|
||||
@@ -813,6 +828,8 @@ lower_project_graph(const ProjectDescription &description,
|
||||
std::vector<std::string> effective_link_opts = description.profile.link_options;
|
||||
|
||||
// Ordered transitive link inputs (preserve exact order; never sort!).
|
||||
std::map<std::string, std::filesystem::path, std::less<>> external_module_bmis;
|
||||
std::map<std::string, std::string, std::less<>> external_module_action_ids;
|
||||
std::vector<std::filesystem::path> link_objects;
|
||||
std::vector<std::filesystem::path> link_static_libs;
|
||||
std::vector<std::filesystem::path> link_shared_libs;
|
||||
@@ -894,6 +911,12 @@ lower_project_graph(const ProjectDescription &description,
|
||||
effective_compile_opts.insert(effective_compile_opts.end(),
|
||||
dep.exported_compile_options.begin(),
|
||||
dep.exported_compile_options.end());
|
||||
for (const auto &[mname, bmi_p] : dep.exported_module_bmis) {
|
||||
external_module_bmis.try_emplace(mname, bmi_p);
|
||||
}
|
||||
for (const auto &[mname, aid] : dep.exported_module_action_ids) {
|
||||
external_module_action_ids.try_emplace(mname, aid);
|
||||
}
|
||||
}
|
||||
if (link.visibility != Visibility::Private) {
|
||||
tc.exported_includes.insert(tc.exported_includes.end(),
|
||||
@@ -905,6 +928,12 @@ lower_project_graph(const ProjectDescription &description,
|
||||
tc.exported_compile_options.insert(tc.exported_compile_options.end(),
|
||||
dep.exported_compile_options.begin(),
|
||||
dep.exported_compile_options.end());
|
||||
for (const auto &[mname, bmi_p] : dep.exported_module_bmis) {
|
||||
tc.exported_module_bmis.try_emplace(mname, bmi_p);
|
||||
}
|
||||
for (const auto &[mname, aid] : dep.exported_module_action_ids) {
|
||||
tc.exported_module_action_ids.try_emplace(mname, aid);
|
||||
}
|
||||
}
|
||||
|
||||
// Link usage: static private dependencies STILL propagate to final linkers!
|
||||
@@ -979,6 +1008,9 @@ lower_project_graph(const ProjectDescription &description,
|
||||
effective_compile_opts.insert(effective_compile_opts.end(),
|
||||
imp.compile_options.begin(),
|
||||
imp.compile_options.end());
|
||||
for (const auto &[mname, bmi_p] : imp.module_bmis) {
|
||||
external_module_bmis.try_emplace(mname, bmi_p);
|
||||
}
|
||||
}
|
||||
if (link.visibility != Visibility::Private) {
|
||||
tc.exported_includes.insert(tc.exported_includes.end(),
|
||||
@@ -988,6 +1020,9 @@ lower_project_graph(const ProjectDescription &description,
|
||||
tc.exported_compile_options.insert(tc.exported_compile_options.end(),
|
||||
imp.compile_options.begin(),
|
||||
imp.compile_options.end());
|
||||
for (const auto &[mname, bmi_p] : imp.module_bmis) {
|
||||
tc.exported_module_bmis.try_emplace(mname, bmi_p);
|
||||
}
|
||||
}
|
||||
const bool propagate_to_consumers = (link.visibility != Visibility::Private) ||
|
||||
(t.kind == TargetKind::StaticLibrary) ||
|
||||
@@ -1081,12 +1116,15 @@ lower_project_graph(const ProjectDescription &description,
|
||||
summary.expanded_sources = expanded_sources;
|
||||
|
||||
if (t.kind == TargetKind::HeaderOnly) {
|
||||
summary.exported_module_bmis = tc.exported_module_bmis;
|
||||
computed[t.name] = std::move(tc);
|
||||
graph.targets.push_back(std::move(summary));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Effective C++ standard, LTO, sanitizers (target overrides/extends profile).
|
||||
// Effective C & C++ standards, LTO, sanitizers (target overrides/extends profile).
|
||||
const CStandard eff_c_std =
|
||||
t.c_standard != CStandard::Default ? t.c_standard : description.profile.c_standard;
|
||||
const CxxStandard eff_std = t.cxx_standard != CxxStandard::Default
|
||||
? t.cxx_standard
|
||||
: description.profile.cxx_standard;
|
||||
@@ -1251,6 +1289,7 @@ lower_project_graph(const ProjectDescription &description,
|
||||
std::filesystem::path logical_src;
|
||||
std::filesystem::path physical_src;
|
||||
std::vector<std::string> tu_opts;
|
||||
bool is_c{false};
|
||||
bool is_explicit_module{false};
|
||||
bool has_per_file_override{false};
|
||||
};
|
||||
@@ -1265,6 +1304,7 @@ lower_project_graph(const ProjectDescription &description,
|
||||
cu.tu_opts = effective_compile_opts;
|
||||
cu.is_explicit_module =
|
||||
explicit_module_sources.contains(src_path) || is_module_source_extension(src_path);
|
||||
cu.is_c = !cu.is_explicit_module && is_c_source_extension(src_path);
|
||||
for (const auto &pfo : t.per_file_options) {
|
||||
if (pfo.source_path == src_path.generic_string() ||
|
||||
pfo.source_path == cu.logical_src.generic_string()) {
|
||||
@@ -1284,7 +1324,7 @@ lower_project_graph(const ProjectDescription &description,
|
||||
const auto norm_phys = cu.physical_src.lexically_normal();
|
||||
all_phys.push_back(norm_phys);
|
||||
raw_by_phys[norm_phys] = &cu;
|
||||
if (cu.is_explicit_module || cu.has_per_file_override) {
|
||||
if (cu.is_c || cu.is_explicit_module || cu.has_per_file_override) {
|
||||
excluded_phys.push_back(norm_phys);
|
||||
}
|
||||
}
|
||||
@@ -1310,14 +1350,18 @@ lower_project_graph(const ProjectDescription &description,
|
||||
compile_units = std::move(raw_units);
|
||||
}
|
||||
|
||||
// 6. Compile actions (C++20/23/26 P1689 named modules & partitions OR regular TUs).
|
||||
// 6. Compile actions (C++20/23/26 P1689 named modules & partitions OR regular C/C++ TUs).
|
||||
std::vector<std::string> compile_action_ids;
|
||||
const bool has_module_sources = std::ranges::any_of(
|
||||
compile_units, [](const CompileUnitSpec &u) { return u.is_explicit_module; });
|
||||
const bool has_cpp_sources =
|
||||
std::ranges::any_of(compile_units, [](const CompileUnitSpec &u) { return !u.is_c; });
|
||||
const bool run_module_pipeline =
|
||||
has_module_sources || (has_cpp_sources && !external_module_bmis.empty());
|
||||
|
||||
std::optional<std::filesystem::path> shared_hu_mapper;
|
||||
if (!gcc_header_unit_mapper_lines.empty() && toolchain.family == CompilerFamily::Gcc &&
|
||||
!has_module_sources) {
|
||||
!run_module_pipeline) {
|
||||
shared_hu_mapper = target_bmi_root / "header_units.modmap";
|
||||
if (auto w = Platform::atomic_write_file(*shared_hu_mapper,
|
||||
gcc_header_unit_mapper_lines, false);
|
||||
@@ -1326,9 +1370,121 @@ lower_project_graph(const ProjectDescription &description,
|
||||
}
|
||||
}
|
||||
|
||||
if (has_module_sources) {
|
||||
auto emit_regular_compile_action =
|
||||
[&](const CompileUnitSpec &cu) -> Void::Result::Result<void, Void::Result::Error> {
|
||||
const std::string src_hash = Util::sha256_hex(cu.logical_src.string()).substr(0, 12);
|
||||
const auto obj_path =
|
||||
objects_root / sanitize_id_component(t.name) /
|
||||
(sanitize_id_component(cu.logical_src.filename().string()) + "_" + src_hash + ".o");
|
||||
const auto dep_path = std::filesystem::path{obj_path.string() + ".d"};
|
||||
|
||||
Toolchain::CompileRequest req;
|
||||
req.source_file = cu.physical_src;
|
||||
req.output_object = obj_path;
|
||||
req.depfile = dep_path;
|
||||
req.response_file_dir = rsp_root;
|
||||
req.include_dirs = physical_includes;
|
||||
req.defines = effective_defines;
|
||||
req.compile_options = cu.tu_opts;
|
||||
req.is_c_source = cu.is_c;
|
||||
req.c_standard = cu.is_c ? eff_c_std : CStandard::Default;
|
||||
req.cxx_standard =
|
||||
cu.is_c ? CxxStandard::Default
|
||||
: ((!header_unit_bmi_paths.empty() && eff_std == CxxStandard::Default)
|
||||
? CxxStandard::Cxx20
|
||||
: eff_std);
|
||||
req.lto = eff_lto;
|
||||
req.sanitizers = eff_sans;
|
||||
req.position_independent = pic;
|
||||
req.precompiled_header = cu.is_c ? std::nullopt : pch_include_prefix;
|
||||
req.prefix_maps = prefix_maps;
|
||||
req.reproducibility_epoch = description.profile.reproducibility_epoch;
|
||||
req.nondeterministic = t.nondeterministic || description.profile.nondeterministic;
|
||||
req.response_file_threshold = options.response_file_threshold;
|
||||
if (!cu.is_c) {
|
||||
if (shared_hu_mapper) {
|
||||
req.module_mapper_file = shared_hu_mapper;
|
||||
} else if (!header_unit_bmi_paths.empty() &&
|
||||
toolchain.family == CompilerFamily::Clang) {
|
||||
for (const auto &hb : header_unit_bmi_paths) {
|
||||
req.module_bmi_imports.emplace_back(std::string{}, hb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto lowered = Toolchain::lower_compile_command(toolchain, req);
|
||||
if (!lowered) {
|
||||
return std::unexpected{lowered.error()};
|
||||
}
|
||||
|
||||
ActionNode act;
|
||||
act.id = "compile:" + sanitize_id_component(t.name) + ":" + src_hash;
|
||||
act.kind = ActionKind::Compile;
|
||||
act.target_name = t.name;
|
||||
act.executable = lowered->executable;
|
||||
act.arguments = std::move(lowered->arguments);
|
||||
act.environment = std::move(lowered->environment);
|
||||
act.working_directory = canonical_root;
|
||||
act.response_file = lowered->response_file;
|
||||
act.response_file_content = std::move(lowered->response_file_content);
|
||||
act.declared_inputs = {cu.physical_src};
|
||||
if (!cu.is_c) {
|
||||
for (const auto &hb : header_unit_bmi_paths) {
|
||||
act.declared_inputs.push_back(hb);
|
||||
}
|
||||
if (shared_hu_mapper) {
|
||||
act.declared_inputs.push_back(*shared_hu_mapper);
|
||||
}
|
||||
}
|
||||
act.declared_outputs = {obj_path};
|
||||
act.depfile = dep_path;
|
||||
act.logical_source_file = cu.logical_src;
|
||||
act.physical_source_file = cu.physical_src;
|
||||
act.logical_output_file = obj_path;
|
||||
act.physical_output_file = obj_path;
|
||||
act.logical_include_dirs = effective_includes;
|
||||
act.physical_include_dirs = physical_includes;
|
||||
act.defines = effective_defines;
|
||||
act.compile_options = cu.tu_opts;
|
||||
act.is_c_source = req.is_c_source;
|
||||
act.c_standard = req.c_standard;
|
||||
act.cxx_standard = req.cxx_standard;
|
||||
act.lto = eff_lto;
|
||||
act.sanitizers = eff_sans;
|
||||
act.position_independent = pic;
|
||||
act.precompiled_header = req.precompiled_header;
|
||||
act.dependencies = target_prereq_actions;
|
||||
if (!cu.is_c) {
|
||||
if (pch_action_id) {
|
||||
add_unique_str(act.dependencies, *pch_action_id);
|
||||
}
|
||||
for (const auto &huid : header_unit_action_ids) {
|
||||
add_unique_str(act.dependencies, huid);
|
||||
}
|
||||
}
|
||||
if (const auto prod_it = output_owner.find(cu.logical_src);
|
||||
prod_it != output_owner.end()) {
|
||||
add_unique_str(act.dependencies, prod_it->second);
|
||||
}
|
||||
act.nondeterministic = req.nondeterministic;
|
||||
act.cacheable = !act.nondeterministic;
|
||||
if (auto reg = register_output(obj_path, act.id); !reg) {
|
||||
return std::unexpected{reg.error()};
|
||||
}
|
||||
act.action_key = compute_action_key(act, graph);
|
||||
compile_action_ids.push_back(act.id);
|
||||
tc.object_files.push_back(obj_path);
|
||||
summary.action_ids.push_back(act.id);
|
||||
graph.action_index_by_id[act.id] = graph.actions.size();
|
||||
graph.actions.push_back(std::move(act));
|
||||
return {};
|
||||
};
|
||||
|
||||
if (run_module_pipeline) {
|
||||
const CxxStandard mod_std =
|
||||
(eff_std == CxxStandard::Default) ? CxxStandard::Cxx20 : eff_std;
|
||||
(eff_std == CxxStandard::Default || eff_std == CxxStandard::Cxx17)
|
||||
? CxxStandard::Cxx20
|
||||
: eff_std;
|
||||
const auto scan_dir =
|
||||
graph.profile_build_dir / "modscan" / sanitize_id_component(t.name);
|
||||
|
||||
@@ -1336,6 +1492,12 @@ lower_project_graph(const ProjectDescription &description,
|
||||
scanned.reserve(compile_units.size());
|
||||
std::map<std::filesystem::path, const CompileUnitSpec *> cu_by_phys;
|
||||
for (const auto &cu : compile_units) {
|
||||
if (cu.is_c) {
|
||||
if (auto r = emit_regular_compile_action(cu); !r) {
|
||||
return std::unexpected{r.error()};
|
||||
}
|
||||
continue;
|
||||
}
|
||||
const auto norm_phys = cu.physical_src.lexically_normal();
|
||||
cu_by_phys[norm_phys] = &cu;
|
||||
auto scan = Modules::scan_translation_unit(toolchain, norm_phys, scan_dir,
|
||||
@@ -1347,8 +1509,9 @@ lower_project_graph(const ProjectDescription &description,
|
||||
scanned.push_back(std::move(*scan));
|
||||
}
|
||||
|
||||
auto collated = Modules::collate_modules(
|
||||
scanned, target_bmi_root, graph.profile_identity + ":" + t.name, bmi_ext);
|
||||
auto collated = Modules::collate_modules(scanned, target_bmi_root,
|
||||
graph.profile_identity + ":" + t.name, bmi_ext,
|
||||
external_module_bmis);
|
||||
if (!collated) {
|
||||
return std::unexpected{collated.error()};
|
||||
}
|
||||
@@ -1365,10 +1528,14 @@ lower_project_graph(const ProjectDescription &description,
|
||||
std::vector<std::pair<std::string, std::filesystem::path>> bmis;
|
||||
std::set<std::string> seen;
|
||||
std::queue<std::string> q;
|
||||
bool uses_external = false;
|
||||
for (const auto &r : direct_reqs) {
|
||||
if (seen.insert(r).second) {
|
||||
q.push(r);
|
||||
}
|
||||
if (external_module_bmis.contains(r)) {
|
||||
uses_external = true;
|
||||
}
|
||||
}
|
||||
while (!q.empty()) {
|
||||
const auto cur = q.front();
|
||||
@@ -1376,6 +1543,10 @@ lower_project_graph(const ProjectDescription &description,
|
||||
if (const auto bit = collated->module_to_bmi.find(cur);
|
||||
bit != collated->module_to_bmi.end()) {
|
||||
bmis.emplace_back(cur, bit->second);
|
||||
} else if (const auto ebit = external_module_bmis.find(cur);
|
||||
ebit != external_module_bmis.end()) {
|
||||
bmis.emplace_back(cur, ebit->second);
|
||||
uses_external = true;
|
||||
}
|
||||
if (const auto dit = module_deps_by_name.find(cur);
|
||||
dit != module_deps_by_name.end()) {
|
||||
@@ -1386,6 +1557,13 @@ lower_project_graph(const ProjectDescription &description,
|
||||
}
|
||||
}
|
||||
}
|
||||
if (uses_external) {
|
||||
for (const auto &[mname, bmi_p] : external_module_bmis) {
|
||||
if (seen.insert(mname).second) {
|
||||
bmis.emplace_back(mname, bmi_p);
|
||||
}
|
||||
}
|
||||
}
|
||||
return bmis;
|
||||
};
|
||||
for (const auto &node : collated->ordered_units) {
|
||||
@@ -1397,6 +1575,10 @@ lower_project_graph(const ProjectDescription &description,
|
||||
"_" + src_hash + ".o");
|
||||
const auto dep_path = std::filesystem::path{obj_path.string() + ".d"};
|
||||
|
||||
const bool tu_uses_modules =
|
||||
!node.provides.empty() || !node.required_modules.empty();
|
||||
const CxxStandard tu_std = tu_uses_modules ? mod_std : eff_std;
|
||||
|
||||
std::vector<std::string> unit_deps = target_prereq_actions;
|
||||
if (pch_action_id) {
|
||||
add_unique_str(unit_deps, *pch_action_id);
|
||||
@@ -1408,8 +1590,25 @@ lower_project_graph(const ProjectDescription &description,
|
||||
prod_it != output_owner.end()) {
|
||||
add_unique_str(unit_deps, prod_it->second);
|
||||
}
|
||||
bool tu_uses_external_mod = false;
|
||||
for (const auto &req_mod : node.required_modules) {
|
||||
add_unique_str(unit_deps, provider_action_by_module.at(req_mod));
|
||||
if (const auto pit = provider_action_by_module.find(req_mod);
|
||||
pit != provider_action_by_module.end()) {
|
||||
add_unique_str(unit_deps, pit->second);
|
||||
} else {
|
||||
tu_uses_external_mod = true;
|
||||
if (const auto epit = external_module_action_ids.find(req_mod);
|
||||
epit != external_module_action_ids.end()) {
|
||||
add_unique_str(unit_deps, epit->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tu_uses_external_mod ||
|
||||
(!node.provides.empty() && !external_module_action_ids.empty())) {
|
||||
for (const auto &[mname, aid] : external_module_action_ids) {
|
||||
(void)mname;
|
||||
add_unique_str(unit_deps, aid);
|
||||
}
|
||||
}
|
||||
|
||||
if (toolchain.family == CompilerFamily::Gcc) {
|
||||
@@ -1447,7 +1646,7 @@ lower_project_graph(const ProjectDescription &description,
|
||||
req.include_dirs = physical_includes;
|
||||
req.defines = effective_defines;
|
||||
req.compile_options = tu_opts;
|
||||
req.cxx_standard = mod_std;
|
||||
req.cxx_standard = tu_std;
|
||||
req.lto = eff_lto;
|
||||
req.sanitizers = eff_sans;
|
||||
req.position_independent = pic;
|
||||
@@ -1480,6 +1679,14 @@ lower_project_graph(const ProjectDescription &description,
|
||||
(void)mname;
|
||||
act.declared_inputs.push_back(bmi_p);
|
||||
}
|
||||
if (tu_uses_external_mod || !node.provides.empty()) {
|
||||
for (const auto &[mname, bmi_p] : external_module_bmis) {
|
||||
(void)mname;
|
||||
if (!std::ranges::contains(act.declared_inputs, bmi_p)) {
|
||||
act.declared_inputs.push_back(bmi_p);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto &hb : header_unit_bmi_paths) {
|
||||
act.declared_inputs.push_back(hb);
|
||||
}
|
||||
@@ -1502,7 +1709,7 @@ lower_project_graph(const ProjectDescription &description,
|
||||
act.physical_include_dirs = physical_includes;
|
||||
act.defines = effective_defines;
|
||||
act.compile_options = tu_opts;
|
||||
act.cxx_standard = mod_std;
|
||||
act.cxx_standard = tu_std;
|
||||
act.lto = eff_lto;
|
||||
act.sanitizers = eff_sans;
|
||||
act.position_independent = pic;
|
||||
@@ -1516,6 +1723,20 @@ lower_project_graph(const ProjectDescription &description,
|
||||
act.action_key = compute_action_key(act, graph);
|
||||
for (const auto &prov : node.provides) {
|
||||
provider_action_by_module[prov] = act.id;
|
||||
tc.exported_module_bmis[prov] = node.bmi_output_path;
|
||||
tc.exported_module_action_ids[prov] = act.id;
|
||||
}
|
||||
if (!node.provides.empty()) {
|
||||
for (const auto &[imp_m, imp_bmi] : node.imported_bmis) {
|
||||
tc.exported_module_bmis.try_emplace(imp_m, imp_bmi);
|
||||
if (const auto pit = provider_action_by_module.find(imp_m);
|
||||
pit != provider_action_by_module.end()) {
|
||||
tc.exported_module_action_ids.try_emplace(imp_m, pit->second);
|
||||
} else if (const auto epit = external_module_action_ids.find(imp_m);
|
||||
epit != external_module_action_ids.end()) {
|
||||
tc.exported_module_action_ids.try_emplace(imp_m, epit->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
compile_action_ids.push_back(act.id);
|
||||
tc.object_files.push_back(obj_path);
|
||||
@@ -1545,7 +1766,7 @@ lower_project_graph(const ProjectDescription &description,
|
||||
breq.include_dirs = physical_includes;
|
||||
breq.defines = effective_defines;
|
||||
breq.compile_options = bmi_opts;
|
||||
breq.cxx_standard = mod_std;
|
||||
breq.cxx_standard = tu_std;
|
||||
breq.lto = eff_lto;
|
||||
breq.sanitizers = eff_sans;
|
||||
breq.position_independent = pic;
|
||||
@@ -1596,6 +1817,21 @@ lower_project_graph(const ProjectDescription &description,
|
||||
const std::string bmi_act_id = bmi_act.id;
|
||||
for (const auto &prov : node.provides) {
|
||||
provider_action_by_module[prov] = bmi_act_id;
|
||||
tc.exported_module_bmis[prov] = node.bmi_output_path;
|
||||
tc.exported_module_action_ids[prov] = bmi_act_id;
|
||||
}
|
||||
for (const auto &[imp_m, imp_bmi] : clang_imports) {
|
||||
if (imp_m.empty()) {
|
||||
continue;
|
||||
}
|
||||
tc.exported_module_bmis.try_emplace(imp_m, imp_bmi);
|
||||
if (const auto pit = provider_action_by_module.find(imp_m);
|
||||
pit != provider_action_by_module.end()) {
|
||||
tc.exported_module_action_ids.try_emplace(imp_m, pit->second);
|
||||
} else if (const auto epit = external_module_action_ids.find(imp_m);
|
||||
epit != external_module_action_ids.end()) {
|
||||
tc.exported_module_action_ids.try_emplace(imp_m, epit->second);
|
||||
}
|
||||
}
|
||||
summary.action_ids.push_back(bmi_act_id);
|
||||
graph.action_index_by_id[bmi_act_id] = graph.actions.size();
|
||||
@@ -1606,7 +1842,7 @@ lower_project_graph(const ProjectDescription &description,
|
||||
oreq.source_file = node.bmi_output_path;
|
||||
oreq.output_object = obj_path;
|
||||
oreq.response_file_dir = rsp_root;
|
||||
oreq.cxx_standard = mod_std;
|
||||
oreq.cxx_standard = tu_std;
|
||||
oreq.lto = eff_lto;
|
||||
oreq.sanitizers = eff_sans;
|
||||
oreq.position_independent = pic;
|
||||
@@ -1661,7 +1897,7 @@ lower_project_graph(const ProjectDescription &description,
|
||||
req.include_dirs = physical_includes;
|
||||
req.defines = effective_defines;
|
||||
req.compile_options = cu.tu_opts;
|
||||
req.cxx_standard = mod_std;
|
||||
req.cxx_standard = tu_std;
|
||||
req.lto = eff_lto;
|
||||
req.sanitizers = eff_sans;
|
||||
req.position_independent = pic;
|
||||
@@ -1703,7 +1939,7 @@ lower_project_graph(const ProjectDescription &description,
|
||||
act.physical_include_dirs = physical_includes;
|
||||
act.defines = effective_defines;
|
||||
act.compile_options = cu.tu_opts;
|
||||
act.cxx_standard = mod_std;
|
||||
act.cxx_standard = tu_std;
|
||||
act.lto = eff_lto;
|
||||
act.sanitizers = eff_sans;
|
||||
act.position_independent = pic;
|
||||
@@ -1725,101 +1961,9 @@ lower_project_graph(const ProjectDescription &description,
|
||||
}
|
||||
} else {
|
||||
for (const auto &cu : compile_units) {
|
||||
const std::string src_hash =
|
||||
Util::sha256_hex(cu.logical_src.string()).substr(0, 12);
|
||||
const auto obj_path = objects_root / sanitize_id_component(t.name) /
|
||||
(sanitize_id_component(cu.logical_src.filename().string()) +
|
||||
"_" + src_hash + ".o");
|
||||
const auto dep_path = std::filesystem::path{obj_path.string() + ".d"};
|
||||
|
||||
Toolchain::CompileRequest req;
|
||||
req.source_file = cu.physical_src;
|
||||
req.output_object = obj_path;
|
||||
req.depfile = dep_path;
|
||||
req.response_file_dir = rsp_root;
|
||||
req.include_dirs = physical_includes;
|
||||
req.defines = effective_defines;
|
||||
req.compile_options = cu.tu_opts;
|
||||
req.cxx_standard =
|
||||
(!header_unit_bmi_paths.empty() && eff_std == CxxStandard::Default)
|
||||
? CxxStandard::Cxx20
|
||||
: eff_std;
|
||||
req.lto = eff_lto;
|
||||
req.sanitizers = eff_sans;
|
||||
req.position_independent = pic;
|
||||
req.precompiled_header = pch_include_prefix;
|
||||
req.prefix_maps = prefix_maps;
|
||||
req.reproducibility_epoch = description.profile.reproducibility_epoch;
|
||||
req.nondeterministic = t.nondeterministic || description.profile.nondeterministic;
|
||||
req.response_file_threshold = options.response_file_threshold;
|
||||
if (shared_hu_mapper) {
|
||||
req.module_mapper_file = shared_hu_mapper;
|
||||
} else if (!header_unit_bmi_paths.empty() &&
|
||||
toolchain.family == CompilerFamily::Clang) {
|
||||
for (const auto &hb : header_unit_bmi_paths) {
|
||||
req.module_bmi_imports.emplace_back(std::string{}, hb);
|
||||
}
|
||||
if (auto r = emit_regular_compile_action(cu); !r) {
|
||||
return std::unexpected{r.error()};
|
||||
}
|
||||
|
||||
auto lowered = Toolchain::lower_compile_command(toolchain, req);
|
||||
if (!lowered) {
|
||||
return std::unexpected{lowered.error()};
|
||||
}
|
||||
|
||||
ActionNode act;
|
||||
act.id = "compile:" + sanitize_id_component(t.name) + ":" + src_hash;
|
||||
act.kind = ActionKind::Compile;
|
||||
act.target_name = t.name;
|
||||
act.executable = lowered->executable;
|
||||
act.arguments = std::move(lowered->arguments);
|
||||
act.environment = std::move(lowered->environment);
|
||||
act.working_directory = canonical_root;
|
||||
act.response_file = lowered->response_file;
|
||||
act.response_file_content = std::move(lowered->response_file_content);
|
||||
act.declared_inputs = {cu.physical_src};
|
||||
for (const auto &hb : header_unit_bmi_paths) {
|
||||
act.declared_inputs.push_back(hb);
|
||||
}
|
||||
if (shared_hu_mapper) {
|
||||
act.declared_inputs.push_back(*shared_hu_mapper);
|
||||
}
|
||||
act.declared_outputs = {obj_path};
|
||||
act.depfile = dep_path;
|
||||
act.logical_source_file = cu.logical_src;
|
||||
act.physical_source_file = cu.physical_src;
|
||||
act.logical_output_file = obj_path;
|
||||
act.physical_output_file = obj_path;
|
||||
act.logical_include_dirs = effective_includes;
|
||||
act.physical_include_dirs = physical_includes;
|
||||
act.defines = effective_defines;
|
||||
act.compile_options = cu.tu_opts;
|
||||
act.cxx_standard = req.cxx_standard;
|
||||
act.lto = eff_lto;
|
||||
act.sanitizers = eff_sans;
|
||||
act.position_independent = pic;
|
||||
act.precompiled_header = pch_include_prefix;
|
||||
act.dependencies = target_prereq_actions;
|
||||
if (pch_action_id) {
|
||||
add_unique_str(act.dependencies, *pch_action_id);
|
||||
}
|
||||
for (const auto &huid : header_unit_action_ids) {
|
||||
add_unique_str(act.dependencies, huid);
|
||||
}
|
||||
if (const auto prod_it = output_owner.find(cu.logical_src);
|
||||
prod_it != output_owner.end()) {
|
||||
add_unique_str(act.dependencies, prod_it->second);
|
||||
}
|
||||
act.nondeterministic = req.nondeterministic;
|
||||
act.cacheable = !act.nondeterministic;
|
||||
if (auto reg = register_output(obj_path, act.id); !reg) {
|
||||
return std::unexpected{reg.error()};
|
||||
}
|
||||
act.action_key = compute_action_key(act, graph);
|
||||
compile_action_ids.push_back(act.id);
|
||||
tc.object_files.push_back(obj_path);
|
||||
summary.action_ids.push_back(act.id);
|
||||
graph.action_index_by_id[act.id] = graph.actions.size();
|
||||
graph.actions.push_back(std::move(act));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1938,6 +2082,7 @@ lower_project_graph(const ProjectDescription &description,
|
||||
graph.actions.push_back(std::move(act));
|
||||
}
|
||||
|
||||
summary.exported_module_bmis = tc.exported_module_bmis;
|
||||
computed[t.name] = std::move(tc);
|
||||
graph.targets.push_back(std::move(summary));
|
||||
}
|
||||
|
||||
+246
-1
@@ -798,6 +798,8 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
popts.build_root = build_root;
|
||||
popts.update_selection = (*opts.editor_profile == prof_name);
|
||||
popts.reserved_ticket = *reserved_ticket;
|
||||
popts.sdk_include_dir = fopts.sdk_include_dir;
|
||||
popts.extra_build_sources = extra_build_sources;
|
||||
if (auto pub_db = Editor::publish_profile_compdb(*graph, popts); pub_db) {
|
||||
Void::Log::debug("CompDb", "[{}] Published compile_commands.json ({})", prof_name,
|
||||
pub_db->compdb_path.string());
|
||||
@@ -1707,6 +1709,222 @@ int execute_graph_command(const GraphCmdOptions &opts) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct IdeCmdOptions {
|
||||
std::string project_arg;
|
||||
std::optional<std::string> build_arg;
|
||||
std::string profile_name{"debug"};
|
||||
std::optional<std::string> compiler_arg;
|
||||
std::string editor_name{"all"};
|
||||
bool force{false};
|
||||
};
|
||||
|
||||
int execute_ide_command(std::string_view sub, const IdeCmdOptions &opts) {
|
||||
Editor::IdeKind ide_kind = Editor::IdeKind::All;
|
||||
if (sub == "generate") {
|
||||
auto parsed_kind = Editor::parse_ide_kind(opts.editor_name);
|
||||
if (!parsed_kind) {
|
||||
std::cerr << "vbs ide: " << parsed_kind.error().message() << '\n';
|
||||
return 2;
|
||||
}
|
||||
ide_kind = *parsed_kind;
|
||||
}
|
||||
|
||||
std::optional<CompilerFamily> compiler_override;
|
||||
if (opts.compiler_arg) {
|
||||
try {
|
||||
compiler_override = parse_compiler(*opts.compiler_arg);
|
||||
} catch (const std::exception &ex) {
|
||||
std::cerr << "vbs ide: " << ex.what() << '\n';
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
const std::filesystem::path project_root{opts.project_arg};
|
||||
const std::filesystem::path build_root =
|
||||
opts.build_arg ? std::filesystem::path{*opts.build_arg} : (project_root / "build");
|
||||
const auto fopts = make_frontend_opts(project_root, build_root, {});
|
||||
|
||||
auto compiled = Config::compile_descriptor(fopts);
|
||||
if (!compiled) {
|
||||
std::cerr << "vbs ide: " << compiled.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
auto profs = Config::discover_profiles(*compiled, fopts);
|
||||
if (!profs) {
|
||||
std::cerr << "vbs ide: " << profs.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
|
||||
ProfileContext ctx;
|
||||
try {
|
||||
ctx = profs->resolve(opts.profile_name, compiler_override, Toolchain::host_os_name(),
|
||||
Toolchain::host_architecture_name());
|
||||
} catch (const std::exception &ex) {
|
||||
std::cerr << "vbs ide: " << ex.what() << '\n';
|
||||
return 2;
|
||||
}
|
||||
|
||||
auto tc = Toolchain::discover_and_probe(ctx, build_root / ".vbs" / "probes");
|
||||
if (!tc) {
|
||||
std::cerr << "vbs ide: " << tc.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto desc = Config::evaluate_project(*compiled, ctx, fopts);
|
||||
if (!desc) {
|
||||
std::cerr << "vbs ide: " << desc.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
|
||||
// MetadataOnly provider loading: inspect cached provider exports if already built; never
|
||||
// run foreign configure/build/fetch. On unbuilt checkouts, synthesize empty placeholders so
|
||||
// IDE configuration still succeeds before the initial build.
|
||||
std::map<std::string, Graph::ImportedTargetInterface, std::less<>> imported_targets;
|
||||
std::vector<Package::NormalizedDependency> toml_deps;
|
||||
std::error_code ec;
|
||||
for (const auto &df : desc->dependency_files) {
|
||||
const auto p = std::filesystem::path{df}.is_absolute() ? std::filesystem::path{df}
|
||||
: (project_root / df);
|
||||
if (auto loaded = Package::load_dependencies_toml(p); loaded) {
|
||||
toml_deps.insert(toml_deps.end(), loaded->begin(), loaded->end());
|
||||
}
|
||||
}
|
||||
auto merged_deps = Package::merge_dependencies(desc->dependencies, toml_deps);
|
||||
if (merged_deps && !merged_deps->empty()) {
|
||||
std::optional<Package::PinnedLock> pinned_lock;
|
||||
if (auto pl = Package::load_pinned_lock(project_root / "vbs.lock"); pl) {
|
||||
pinned_lock = *pl;
|
||||
}
|
||||
auto resolved = resolve_and_materialize_deps(ctx, *merged_deps, project_root, build_root,
|
||||
pinned_lock, true, false);
|
||||
if (resolved) {
|
||||
for (const auto &[dep_rec, mat] : resolved->materialized) {
|
||||
DependencyRecord effective_dep = dep_rec;
|
||||
if (effective_dep.builder.empty()) {
|
||||
if (std::filesystem::is_regular_file(mat.source_dir / "build.cpp", ec)) {
|
||||
effective_dep.builder = "native";
|
||||
} else if (std::filesystem::is_regular_file(mat.source_dir / "CMakeLists.txt",
|
||||
ec)) {
|
||||
effective_dep.builder = "cmake";
|
||||
} else if (std::filesystem::is_regular_file(mat.source_dir / "meson.build",
|
||||
ec)) {
|
||||
effective_dep.builder = "meson";
|
||||
}
|
||||
}
|
||||
if (!effective_dep.builder.empty()) {
|
||||
Provider::ProviderRequest preq{effective_dep,
|
||||
mat,
|
||||
ctx,
|
||||
*tc,
|
||||
build_root / ".vbs" / "providers",
|
||||
Provider::ProviderMode::MetadataOnly,
|
||||
{},
|
||||
fopts.sdk_include_dir,
|
||||
fopts.sdk_source_dir,
|
||||
fopts.sdk_library_path.empty()
|
||||
? std::nullopt
|
||||
: std::optional{fopts.sdk_library_path},
|
||||
nullptr,
|
||||
0};
|
||||
auto exp = Provider::resolve_foreign_provider(preq);
|
||||
if (exp && !exp->stale_needs_build) {
|
||||
for (const auto &[k, v] : exp->targets) {
|
||||
imported_targets[k] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto &t : desc->targets) {
|
||||
for (const auto &link : t.links) {
|
||||
if (link.kind == LinkKind::Imported) {
|
||||
const std::string key = link.dependency + "::" + link.target;
|
||||
if (!imported_targets.contains(key) && !imported_targets.contains(link.target)) {
|
||||
Void::Log::warn(
|
||||
"Ide",
|
||||
"Dependency target '{}' is not built yet; run 'vbs build' to populate "
|
||||
"imported include paths",
|
||||
key);
|
||||
imported_targets.emplace(
|
||||
key, Graph::ImportedTargetInterface{
|
||||
link.dependency, link.target, {}, {}, {}, {}, {}, {}, {}, {}, {}});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const auto snap_inputs = collect_snapshot_inputs(*desc, project_root);
|
||||
Snapshot::SnapshotOptions sopts;
|
||||
sopts.project_root = project_root;
|
||||
sopts.snapshot_store_dir = build_root / ".vbs" / "snapshots";
|
||||
sopts.reproducibility_epoch = ctx.reproducibility_epoch;
|
||||
sopts.materialize = false;
|
||||
auto snap =
|
||||
Snapshot::capture_snapshot(sopts, snap_inputs.explicit_files, snap_inputs.scan_roots);
|
||||
if (!snap) {
|
||||
std::cerr << "vbs ide: " << snap.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
|
||||
Graph::GraphLowerOptions gopts{project_root, build_root, &(*snap), std::move(imported_targets),
|
||||
32768};
|
||||
auto graph = Graph::lower_project_graph(*desc, *tc, gopts);
|
||||
if (!graph) {
|
||||
std::cerr << "vbs ide: " << graph.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
|
||||
const auto existing_sel = Editor::read_selection_state(project_root).value_or(std::nullopt);
|
||||
Editor::PublishOptions popts;
|
||||
popts.project_root = project_root;
|
||||
popts.build_root = build_root;
|
||||
popts.update_selection = !existing_sel.has_value();
|
||||
popts.sdk_include_dir = fopts.sdk_include_dir;
|
||||
auto pub = Editor::publish_profile_compdb(*graph, popts);
|
||||
if (!pub) {
|
||||
std::cerr << "vbs ide: " << pub.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
|
||||
const auto root_compdb = build_root / "compile_commands.json";
|
||||
const auto compdb_path =
|
||||
std::filesystem::exists(root_compdb, ec) ? root_compdb : pub->compdb_path;
|
||||
|
||||
if (sub == "query") {
|
||||
std::cout << Editor::format_ide_query_json(*graph, compdb_path, fopts.sdk_include_dir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::filesystem::path vbs_exe{"vbs"};
|
||||
if (const auto self_exe = std::filesystem::read_symlink("/proc/self/exe", ec);
|
||||
!ec && !self_exe.empty()) {
|
||||
vbs_exe = self_exe;
|
||||
}
|
||||
|
||||
Editor::IdeConfigOptions ide_opts;
|
||||
ide_opts.project_root = project_root;
|
||||
ide_opts.build_root = build_root;
|
||||
ide_opts.sdk_include_dir = fopts.sdk_include_dir;
|
||||
ide_opts.vbs_executable = vbs_exe;
|
||||
ide_opts.compdb_path = compdb_path;
|
||||
ide_opts.editor = ide_kind;
|
||||
ide_opts.force = opts.force;
|
||||
|
||||
auto rep = Editor::generate_ide_configs(*graph, ide_opts);
|
||||
if (!rep) {
|
||||
std::cerr << "vbs ide: " << rep.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
for (const auto &w : rep->written_files) {
|
||||
std::cout << "wrote " << w.string() << '\n';
|
||||
}
|
||||
for (const auto &s : rep->skipped_existing_files) {
|
||||
std::cout << "preserved " << s.string() << " (pass --force to overwrite)\n";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
@@ -1742,6 +1960,8 @@ int main(int argc, char **argv) {
|
||||
clean_opts.build_arg = (std::filesystem::path{cwd} / "build").string();
|
||||
GraphCmdOptions graph_opts;
|
||||
graph_opts.project_arg = cwd;
|
||||
IdeCmdOptions ide_opts;
|
||||
ide_opts.project_arg = cwd;
|
||||
|
||||
auto add_log_flags = [&](Void::Argparse::Parser &p, bool allow_short_v = true) {
|
||||
p.flag("--verbose", allow_short_v ? "-v" : "", "Enable verbose debug logs", verbose)
|
||||
@@ -1932,6 +2152,26 @@ int main(int argc, char **argv) {
|
||||
.option_default("--format", "-f", "Output format (dot|json)", graph_opts.format, "dot");
|
||||
add_log_flags(graph_cmd);
|
||||
|
||||
auto &ide_cmd =
|
||||
root.subcommand("ide", "Generate editor/IDE configs and query workspace metadata");
|
||||
auto configure_ide_common = [&](Void::Argparse::Parser &p) {
|
||||
p.option_default("--project", "-C", "Project directory", ide_opts.project_arg, cwd)
|
||||
.option("--build-dir", "-B", "Build output directory", ide_opts.build_arg)
|
||||
.option_default("--profile", "-p", "Profile name", ide_opts.profile_name, "debug")
|
||||
.option("--compiler", "", "Override compiler family (gcc|clang)",
|
||||
ide_opts.compiler_arg);
|
||||
add_log_flags(p);
|
||||
};
|
||||
auto &ide_gen_cmd =
|
||||
ide_cmd.subcommand("generate", "Generate .clangd, .vscode/, .zed/, and .idea/ IDE configs");
|
||||
configure_ide_common(ide_gen_cmd);
|
||||
ide_gen_cmd
|
||||
.option_default("--editor", "-e", "Editor preset (all|clangd|vscode|clion|zed)",
|
||||
ide_opts.editor_name, "all")
|
||||
.flag("--force", "", "Overwrite existing IDE configuration files", ide_opts.force);
|
||||
configure_ide_common(
|
||||
ide_cmd.subcommand("query", "Emit versioned JSON workspace, target, and compdb metadata"));
|
||||
|
||||
const auto parsed = root.parse_detailed(argc, argv);
|
||||
if (parsed.is_help()) {
|
||||
std::cout << parsed.message;
|
||||
@@ -1958,7 +2198,9 @@ int main(int argc, char **argv) {
|
||||
const bool machine_quiet_default =
|
||||
(cmd == "describe") || (cmd == "graph") || (cmd == "doctor") ||
|
||||
(cmd == "compdb" && parsed.matched_command_path.size() >= 2 &&
|
||||
parsed.matched_command_path[1] == "show");
|
||||
parsed.matched_command_path[1] == "show") ||
|
||||
(cmd == "ide" && parsed.matched_command_path.size() >= 2 &&
|
||||
parsed.matched_command_path[1] == "query");
|
||||
const Void::Log::Level log_level =
|
||||
verbose ? Void::Log::Level::Debug
|
||||
: ((quiet || machine_quiet_default) ? Void::Log::Level::Warning
|
||||
@@ -2016,6 +2258,9 @@ int main(int argc, char **argv) {
|
||||
if (cmd == "graph") {
|
||||
return execute_graph_command(graph_opts);
|
||||
}
|
||||
if (cmd == "ide") {
|
||||
return execute_ide_command(parsed.matched_command_path.at(1), ide_opts);
|
||||
}
|
||||
|
||||
std::cerr << "vbs: unhandled subcommand '" << cmd << "'\n";
|
||||
return 2;
|
||||
|
||||
@@ -209,6 +209,10 @@ scan_translation_unit(const Toolchain::ToolchainCapabilities &toolchain,
|
||||
req.arguments.push_back(is_sys ? "-isystem" : "-I");
|
||||
req.arguments.push_back(inc.string());
|
||||
}
|
||||
for (const auto &sys_inc : toolchain.default_include_dirs) {
|
||||
req.arguments.push_back("-isystem");
|
||||
req.arguments.push_back(sys_inc);
|
||||
}
|
||||
for (const auto &def : defines) {
|
||||
req.arguments.push_back("-D" + def);
|
||||
}
|
||||
@@ -226,13 +230,19 @@ scan_translation_unit(const Toolchain::ToolchainCapabilities &toolchain,
|
||||
return parse_p1689_json(proc->stdout_data, source_file);
|
||||
}
|
||||
|
||||
Void::Result::Result<CollatedModulePlan, Void::Result::Error>
|
||||
collate_modules(const std::vector<ModuleScanUnit> &units, const std::filesystem::path &bmi_root,
|
||||
const std::string &context_isolation_key, std::string_view bmi_extension) {
|
||||
Void::Result::Result<CollatedModulePlan, Void::Result::Error> collate_modules(
|
||||
const std::vector<ModuleScanUnit> &units, const std::filesystem::path &bmi_root,
|
||||
const std::string &context_isolation_key, std::string_view bmi_extension,
|
||||
const std::map<std::string, std::filesystem::path, std::less<>> &external_module_bmis) {
|
||||
// 1. Index module providers and reject duplicates immediately.
|
||||
std::map<std::string, std::size_t, std::less<>> provider_by_name;
|
||||
for (std::size_t i = 0; i < units.size(); ++i) {
|
||||
for (const auto &mod : units[i].provides) {
|
||||
if (external_module_bmis.contains(mod)) {
|
||||
return std::unexpected{make_error(std::format(
|
||||
"duplicate module provider for '{}': defined in '{}' and imported dependency",
|
||||
mod, units[i].source_file.string()))};
|
||||
}
|
||||
const auto [it, inserted] = provider_by_name.emplace(mod, i);
|
||||
if (!inserted) {
|
||||
return std::unexpected{make_error(std::format(
|
||||
@@ -249,6 +259,9 @@ collate_modules(const std::vector<ModuleScanUnit> &units, const std::filesystem:
|
||||
for (const auto &req_mod : units[i].required_modules) {
|
||||
const auto it = provider_by_name.find(req_mod);
|
||||
if (it == provider_by_name.end()) {
|
||||
if (external_module_bmis.contains(req_mod)) {
|
||||
continue;
|
||||
}
|
||||
return std::unexpected{
|
||||
make_error(std::format("missing module provider for '{}' imported by '{}'",
|
||||
req_mod, units[i].source_file.string()))};
|
||||
@@ -306,15 +319,38 @@ collate_modules(const std::vector<ModuleScanUnit> &units, const std::filesystem:
|
||||
}
|
||||
}
|
||||
|
||||
// Build GCC module-mapper file mapping all required + provided modules.
|
||||
// Build GCC module-mapper file mapping all required + provided (+ transitive external)
|
||||
// modules.
|
||||
std::string mapper;
|
||||
std::set<std::string, std::less<>> mapped_names;
|
||||
for (const auto &mod : u.provides) {
|
||||
mapped_names.insert(mod);
|
||||
mapper += mod + " " + node.bmi_output_path.string() + "\n";
|
||||
}
|
||||
bool uses_external = false;
|
||||
for (const auto &req_mod : u.required_modules) {
|
||||
const auto &bmi = plan.module_to_bmi.at(req_mod);
|
||||
node.imported_bmis.emplace_back(req_mod, bmi);
|
||||
mapper += req_mod + " " + bmi.string() + "\n";
|
||||
std::filesystem::path bmi;
|
||||
if (const auto lit = plan.module_to_bmi.find(req_mod);
|
||||
lit != plan.module_to_bmi.end()) {
|
||||
bmi = lit->second;
|
||||
} else if (const auto eit = external_module_bmis.find(req_mod);
|
||||
eit != external_module_bmis.end()) {
|
||||
bmi = eit->second;
|
||||
uses_external = true;
|
||||
}
|
||||
if (!bmi.empty()) {
|
||||
node.imported_bmis.emplace_back(req_mod, bmi);
|
||||
if (mapped_names.insert(req_mod).second) {
|
||||
mapper += req_mod + " " + bmi.string() + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (uses_external || !u.provides.empty()) {
|
||||
for (const auto &[mname, bmi] : external_module_bmis) {
|
||||
if (mapped_names.insert(mname).second) {
|
||||
mapper += mname + " " + bmi.string() + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!mapper.empty()) {
|
||||
const std::string mtag = Util::sha256_hex(u.source_file.string()).substr(0, 12);
|
||||
@@ -396,8 +432,10 @@ generate_unity_batches(const std::string &target_name,
|
||||
for (const auto &src : sources) {
|
||||
const auto norm = src.lexically_normal();
|
||||
const auto ext = norm.extension().string();
|
||||
// Exclude module interface/partition extensions and explicitly excluded files from unity!
|
||||
if (excluded.contains(norm) || ext == ".cppm" || ext == ".ixx" || ext == ".ccm") {
|
||||
// Exclude C sources, module interface/partition extensions and explicitly excluded files
|
||||
// from unity!
|
||||
if (excluded.contains(norm) || ext == ".c" || ext == ".cppm" || ext == ".ixx" ||
|
||||
ext == ".ccm") {
|
||||
result.standalone_files.push_back(norm);
|
||||
} else {
|
||||
batchable.push_back(norm);
|
||||
|
||||
@@ -113,7 +113,16 @@ std::string serialize_export(const ProviderExport &exp) {
|
||||
",\"runtime_files\":" +
|
||||
json_array(iface.runtime_files,
|
||||
[](const std::filesystem::path &p) { return json_quote(p.string()); }) +
|
||||
'}';
|
||||
",\"module_bmis\":{";
|
||||
bool first_mod = true;
|
||||
for (const auto &[mname, bmi_p] : iface.module_bmis) {
|
||||
if (!first_mod) {
|
||||
out += ',';
|
||||
}
|
||||
first_mod = false;
|
||||
out += json_quote(mname) + ':' + json_quote(bmi_p.string());
|
||||
}
|
||||
out += "}}";
|
||||
}
|
||||
out += "}}\n";
|
||||
return out;
|
||||
@@ -175,7 +184,16 @@ std::optional<ProviderExport> load_cached_export(const std::filesystem::path &ex
|
||||
for (const auto &s : get_str_array(*io, "runtime_files")) {
|
||||
iface.runtime_files.emplace_back(s);
|
||||
}
|
||||
// Verify materialized library artifacts still exist on disk!
|
||||
if (const auto *mv = find_key(*io, "module_bmis")) {
|
||||
if (const auto *mobj = std::get_if<JsonVal::Object>(&mv->value)) {
|
||||
for (const auto &[mname, mval] : *mobj) {
|
||||
if (const auto *ms = std::get_if<std::string>(&mval.value)) {
|
||||
iface.module_bmis.emplace(mname, *ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Verify materialized library and BMI artifacts still exist on disk!
|
||||
std::error_code ec;
|
||||
for (const auto &lib : iface.static_libraries) {
|
||||
if (!std::filesystem::is_regular_file(lib, ec)) {
|
||||
@@ -187,6 +205,12 @@ std::optional<ProviderExport> load_cached_export(const std::filesystem::path &ex
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
for (const auto &[mname, bmi_p] : iface.module_bmis) {
|
||||
(void)mname;
|
||||
if (!std::filesystem::is_regular_file(bmi_p, ec)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
exp.targets[k] = std::move(iface);
|
||||
}
|
||||
}
|
||||
@@ -254,6 +278,9 @@ run_cmake_provider(const ProviderRequest &request, const std::filesystem::path &
|
||||
req.arguments.push_back("-G");
|
||||
req.arguments.push_back("Ninja");
|
||||
}
|
||||
if (!request.toolchain.c_compiler.empty()) {
|
||||
req.arguments.push_back("-DCMAKE_C_COMPILER=" + request.toolchain.c_compiler.string());
|
||||
}
|
||||
req.arguments.push_back("-DCMAKE_CXX_COMPILER=" + request.toolchain.cxx_compiler.string());
|
||||
const std::string cfg =
|
||||
(request.profile.name == "release" || request.profile.name == "Release") ? "Release"
|
||||
@@ -706,6 +733,9 @@ run_meson_provider(const ProviderRequest &request, const std::filesystem::path &
|
||||
for (const auto &[k, v] : request.dependency.options) {
|
||||
req.arguments.push_back("-D" + k + "=" + meson_option_value(v));
|
||||
}
|
||||
if (!request.toolchain.c_compiler.empty()) {
|
||||
req.environment.set_vars["CC"] = request.toolchain.c_compiler.string();
|
||||
}
|
||||
req.environment.set_vars["CXX"] = request.toolchain.cxx_compiler.string();
|
||||
req.timeout = std::chrono::seconds{180};
|
||||
auto proc = Platform::run_supervised(req, stop);
|
||||
@@ -1278,6 +1308,11 @@ run_native_provider(const ProviderRequest &request, const std::filesystem::path
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sum_it != summary_by_name.end()) {
|
||||
for (const auto &[mname, bmi_p] : sum_it->second->exported_module_bmis) {
|
||||
iface.module_bmis.try_emplace(mname, bmi_p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exp.targets[request.dependency.name + "::" + t.name] = iface;
|
||||
|
||||
+1309
-108
File diff suppressed because it is too large.
Load diff
+150
-16
@@ -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");
|
||||
|
||||
@@ -262,6 +262,8 @@ WatchCycleReport run_reconcile_cycle(const WatchLoopOptions &options, std::size_
|
||||
popts.build_root = options.frontend.build_root;
|
||||
popts.update_selection = allow_selection_update;
|
||||
popts.reserved_ticket = reserved_ticket;
|
||||
popts.sdk_include_dir = options.frontend.sdk_include_dir;
|
||||
popts.extra_build_sources = options.frontend.extra_build_sources;
|
||||
auto pub = Editor::publish_profile_compdb(*graph, popts);
|
||||
if (!pub) {
|
||||
rep.diagnostic = pub.error().message();
|
||||
|
||||
Reference in new issue
Block a user