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
+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;
|
||||
|
||||
Reference in new issue
Block a user