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

147 lines
6.0 KiB
C++

// VDE 插件 SDK 模板:CAE 求解器(solve 骨架;纯 C ABI,不链接 VDE 内核)
//
// 演示 VdeCaeSolverPlugin 最小实现:
// - host->body_from_serialized 还原宿主传入的 VDE 序列化模型;
// - host->body_query/body_bbox 读取几何信息;
// - 结果 JSON 用 host->alloc 分配,宿主 free_buffer 释放;
// - 失败返回负错误码 + host->set_error,不跨 C ABI 抛异常。
//
// 本模板只做“契约演示”的估算(模型体积 + 参数回显),请替换为真实求解器。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include "vde/plugin/vde_plugin_api.h"
namespace {
int cae_fail(const VdePluginHost* host, int code, const char* message) {
if (host && host->set_error) host->set_error(message);
return code;
}
/// 本模板需要的宿主服务:模型反序列化 + 查询/bbox + 体销毁 + 缓冲分配。
int validate_host(const VdePluginHost* host) {
if (!host) return VDE_PLUGIN_ERR_INVALID_ARG;
if (host->abi_major != VDE_PLUGIN_ABI_MAJOR)
return cae_fail(host, VDE_PLUGIN_ERR_ABI, "cae template: host ABI major mismatch");
if (!host->alloc || !host->free || !host->set_error || !host->free_buffer)
return cae_fail(host, VDE_PLUGIN_ERR_UNSUPPORTED,
"cae template: host lacks alloc/free/set_error/free_buffer");
if (!host->body_from_serialized || !host->body_query || !host->body_bbox ||
!host->body_destroy)
return cae_fail(host, VDE_PLUGIN_ERR_UNSUPPORTED,
"cae template: host lacks body_from_serialized/query/bbox/destroy");
return VDE_PLUGIN_OK;
}
/// 极简 JSON 数值提取(演示用;生产实现请用 JSON 库;插件不链接内核)。
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 cae_solve(const VdePluginHost* host, const void* model_data, size_t model_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 cae_fail(host, VDE_PLUGIN_ERR_INVALID_ARG, "cae template: null result");
if (!model_data || model_size == 0)
return cae_fail(host, VDE_PLUGIN_ERR_INVALID_ARG, "cae template: empty model data");
VdeBody body = host->body_from_serialized(model_data, model_size);
if (!body) return cae_fail(host, VDE_PLUGIN_ERR_PARSE,
"cae template: body_from_serialized failed (see host error)");
VdeBodyInfo info{};
info.struct_size = static_cast<uint32_t>(sizeof(VdeBodyInfo));
int rc = host->body_query(body, &info);
if (rc != VDE_PLUGIN_OK) {
host->body_destroy(body);
return cae_fail(host, VDE_PLUGIN_ERR_INTERNAL, "cae template: body_query failed");
}
host->body_destroy(body);
// 演示参数:可替换为弹性模量/载荷/网格尺寸等求解参数。
const double load = json_number(params_json, "load", 1000.0);
char text[512];
const int written = std::snprintf(
text, sizeof(text),
"{\"solver_id\":\"example.linear_static\",\"ok\":true,"
"\"model_bytes\":%zu,\"volume\":%.10g,\"load\":%.10g,"
"\"results\":{\"note\":\"template stub; replace with real solver\"}}",
model_size, info.volume, load);
if (written <= 0)
return cae_fail(host, VDE_PLUGIN_ERR_INTERNAL, "cae template: result format failed");
const std::size_t size = static_cast<std::size_t>(written);
void* buffer = host->alloc(size + 1);
if (!buffer) return cae_fail(host, VDE_PLUGIN_ERR_BUFFER, "cae 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 CAE solver template (demo linear_static stub; ABI 1.3)";
}
const VdeCaeSolverPlugin kSolver = [] {
VdeCaeSolverPlugin solver{};
solver.struct_size = static_cast<uint32_t>(sizeof(VdeCaeSolverPlugin));
solver.solver_id = "example.linear_static";
solver.capabilities_json = "{\"fields\":[\"structural\"],\"demo\":true}";
solver.solve = &cae_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.cae";
info->name = "VDE CAE Solver Template";
info->version = "0.1.0";
info->kind = VDE_PLUGIN_KIND_CAE_SOLVER;
info->abi_major = VDE_PLUGIN_ABI_MAJOR;
info->abi_minor = VDE_PLUGIN_ABI_MINOR;
info->capabilities = "cae_solver:example.linear_static";
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_CAE_SOLVER;
reg->format = nullptr;
reg->generic = nullptr;
reg->cae_solver = &kSolver;
reg->cam_strategy = nullptr;
reg->gcs_solver = nullptr;
return VDE_PLUGIN_OK;
}
VDE_PLUGIN_EXPORT void vde_plugin_shutdown() {}
} // extern "C"