Files
hm 4ef08ec011
Build & Test / build-and-test (push) Canceled after 0s
VDE Build & Test / build-and-test (push) Canceled after 0s
Build & Test / python-bindings (push) Canceled after 0s
feat: VDE_INSTALL/嵌入式消费完善 + 插件 SDK 模板包与 tool --check(1.0.71)
### P3-11 嵌入式消费/安装完善(VDE-1251 响应)
- option(VDE_INSTALL ON):OFF 统一关闭 VDE install/export 规则(kernel SDK/插件 SDK/CLI),宿主自身规则保留;
  未用 CMAKE_SKIP_INSTALL_RULES,采用 install 前置变量屏蔽;VDE_INSTALL_SDK 关系文档化;
- CI 新增 embedding-consumer job(ubuntu,模拟宿主普通 _vd_eigen3 + add_subdirectory(VDE),
  VDE_INSTALL=ON 断言 vde-kernel 包、OFF 断言无 VDE 包/内核库但宿主 exe 安装;防 VDE-1250/1251 回归);
- module-manual:vde_cae 显式链接说明(1.0.46 起)+ 嵌入消费方集成章节;CHANGELOG 1.0.70 补注;
- 验证:默认 build 0 error + 相关 ctest 274/274;嵌入 ON/OFF configure/build/run/install 全通过(EMBED_CONSUMER_PASS);

### P3-12 插件 SDK 模板包 + vde_plugin_tool --check
- plugins/templates/:format/CAE/CAM/GCS 四类最小模板(源码+manifest ABI1.3+独立 CMake+README),不加入默认构建,
  只依赖纯 C ABI;4 模板独立 configure/build 0 error;
- vde_plugin_tool --check:清单/entry DLL/query 与清单一致性/ABI 兼容/artifacts 路径+SHA-256/kind↔能力 warning,退出码 0/2/3;
  4/4 PASS、负例 RC=3、旧 ABI 1.1 RC=0、既有插件 PASS;默认构建零引用;
- 文档 plugin-development §14、roadmap P3-12 进展;

### 工程
- 版本 1.0.71(CMake/version.h/test_version/README/docs index/module-manual);
- 全量构建 0 error(345 targets);全量 ctest 7499 注册、7404/7404 PASS(0 failed,25 skipped,177.98s)。
2026-10-29 00:08:46 +08:00

129 lines
5.0 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// VDE 插件 SDK 模板:GCS 几何约束求解器(solve 骨架;纯 C ABI,不链接 VDE 内核)
//
// 背景:VDE-1201 决策「VDE 不内嵌求解器」;GCS 以插件形式可选集成(ABI 1.3)。
// 本模板演示 VdeGcsSolverPlugin 契约:sketch JSON + params JSON → 结果 JSON,
// 输出用 host->alloc 分配、宿主 free_buffer 释放;失败负错误码 + set_error。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include "vde/plugin/vde_plugin_api.h"
namespace {
int gcs_fail(const VdePluginHost* host, int code, const char* message) {
if (host && host->set_error) host->set_error(message);
return code;
}
/// GCS 求解本身不需要几何服务,只需要跨 ABI 缓冲分配/错误上报。
int validate_host(const VdePluginHost* host) {
if (!host) return VDE_PLUGIN_ERR_INVALID_ARG;
if (host->abi_major != VDE_PLUGIN_ABI_MAJOR)
return gcs_fail(host, VDE_PLUGIN_ERR_ABI, "gcs template: host ABI major mismatch");
if (!host->alloc || !host->free || !host->set_error || !host->free_buffer)
return gcs_fail(host, VDE_PLUGIN_ERR_UNSUPPORTED,
"gcs template: host lacks alloc/free/set_error/free_buffer");
return VDE_PLUGIN_OK;
}
double json_number(const char* text, const char* key, double fallback) {
if (!text || !key) return fallback;
const std::string pattern = std::string("\"") + key + "\"";
const char* pos = std::strstr(text, pattern.c_str());
if (!pos) return fallback;
pos += pattern.size();
while (*pos == ' ' || *pos == '\t' || *pos == '\r' || *pos == '\n') ++pos;
if (*pos != ':') return fallback;
++pos;
char* end = nullptr;
const double value = std::strtod(pos, &end);
return end == pos ? fallback : value;
}
int gcs_solve(const VdePluginHost* host, const char* sketch_json, size_t sketch_size,
const char* params_json, VdeBuffer* result_json) {
if (result_json) {
result_json->data = nullptr;
result_json->size = 0;
}
const int host_rc = validate_host(host);
if (host_rc != VDE_PLUGIN_OK) return host_rc;
if (!result_json) return gcs_fail(host, VDE_PLUGIN_ERR_INVALID_ARG, "gcs template: null result");
// 空草图允许(返回空解);替换为真实解析/求解逻辑。
const size_t point_markers = sketch_json ? std::strlen(sketch_json) : 0;
const double max_iterations = json_number(params_json, "max_iterations", 100.0);
(void)point_markers;
char text[512];
const int written = std::snprintf(
text, sizeof(text),
"{\"solver_id\":\"example.gcs.2d\",\"ok\":true,\"converged\":true,"
"\"iterations\":0,\"dof\":0,\"points\":[],\"constraint_status\":[],"
"\"params\":{\"max_iterations\":%.10g},"
"\"diagnostics\":[\"template stub; replace with real constraint solver\"]}",
max_iterations);
if (written <= 0)
return gcs_fail(host, VDE_PLUGIN_ERR_INTERNAL, "gcs template: result format failed");
const std::size_t size = static_cast<std::size_t>(written);
void* buffer = host->alloc(size + 1);
if (!buffer) return gcs_fail(host, VDE_PLUGIN_ERR_BUFFER, "gcs template: result alloc failed");
std::memcpy(buffer, text, size + 1);
result_json->data = buffer;
result_json->size = size;
return VDE_PLUGIN_OK;
}
const char* describe() {
return "VDE GCS solver template (example.gcs.2d stub; ABI 1.3)";
}
const VdeGcsSolverPlugin kSolver = [] {
VdeGcsSolverPlugin solver{};
solver.struct_size = static_cast<uint32_t>(sizeof(VdeGcsSolverPlugin));
solver.solver_id = "example.gcs.2d";
solver.capabilities_json =
"{\"dimensions\":2,\"constraint_types\":[\"distance\",\"horizontal\","
"\"vertical\",\"coincident\",\"fix\"],\"demo\":true}";
solver.solve = &gcs_solve;
solver.describe = &describe;
return solver;
}();
} // namespace
extern "C" {
VDE_PLUGIN_EXPORT int vde_plugin_query(uint32_t host_abi_major, VdePluginInfo* info) {
if (!info || info->struct_size < sizeof(VdePluginInfo)) return VDE_PLUGIN_ERR_ABI;
if (host_abi_major != VDE_PLUGIN_ABI_MAJOR) return VDE_PLUGIN_ERR_ABI;
info->id = "com.example.vde.gcs";
info->name = "VDE GCS Solver Template";
info->version = "0.1.0";
info->kind = VDE_PLUGIN_KIND_GCS_SOLVER;
info->abi_major = VDE_PLUGIN_ABI_MAJOR;
info->abi_minor = VDE_PLUGIN_ABI_MINOR;
info->capabilities = "gcs:solve";
info->license = "Apache-2.0";
return VDE_PLUGIN_OK;
}
VDE_PLUGIN_EXPORT int vde_plugin_init(const VdePluginHost* host,
VdePluginRegistration* reg) {
if (!reg || reg->struct_size < sizeof(VdePluginRegistration)) return VDE_PLUGIN_ERR_ABI;
const int host_rc = validate_host(host);
if (host_rc != VDE_PLUGIN_OK) return host_rc;
reg->kind = VDE_PLUGIN_KIND_GCS_SOLVER;
reg->format = nullptr;
reg->generic = nullptr;
reg->cae_solver = nullptr;
reg->cam_strategy = nullptr;
reg->gcs_solver = &kSolver;
return VDE_PLUGIN_OK;
}
VDE_PLUGIN_EXPORT void vde_plugin_shutdown() {}
} // extern "C"