refactor: 迁移 CMake 到模块化目录构建并添加新入口

This commit is contained in:
2026-05-09 23:03:00 +08:00
parent 0d4a907dd8
commit 601c0f3d1a
2 changed files with 91 additions and 81 deletions

57
src/main.c Normal file
View File

@@ -0,0 +1,57 @@
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include "base/log.h"
#include "config/runtime_config.h"
#include "core/backend.h"
#include "core/runtime.h"
static void bootstrap(runtime_t *runtime) {
auto backend = backend_create(nullptr);
auto detect = backend_detect(backend);
if (!backend || !detect || detect->output_count == 0) {
fatal("backend detect failed");
}
runtime_init_desc_t desc = {
.backend = backend,
.outputs = detect->outputs,
.output_count = detect->output_count,
};
if (!runtime_config_load(nullptr, &desc)) {
fatal("failed to build runtime inputs");
}
backend = nullptr;
bool inited = runtime_init(runtime, &desc);
runtime_init_desc_cleanup(&desc);
backend_detect_destroy(detect);
if (!inited) {
fatal("runtime init failed");
}
}
char **cmd_argv = nullptr;
int main(int argc, char *argv[]) {
cmd_argv = argv;
runtime_t runtime = {0};
bootstrap(&runtime);
runtime_setup(&runtime);
runtime_scan(&runtime);
runtime_run(&runtime);
runtime_shutdown(&runtime);
if (runtime.will_restart) {
execvp(cmd_argv[0], cmd_argv);
fatal("execvp() failed: %s", strerror(errno));
}
return 0;
}