// P4-43 / P4-59 官方语言绑定元信息插件(ABI 1.8;纯 C ABI,不链接内核)。 // VdeBindingPlugin::get_manifest_json 无 options 参数(ABI 1.8),语言通过环境变量 // VDE_BINDING_LANGUAGE 选择:python(默认)|csharp|typescript;未知语言返回 // VDE_PLUGIN_ERR_INVALID_ARG + set_error。输出确定性的绑定元信息 JSON: // binding_id/language/version/module/entry/symbols/type_mappings/build_hints。 #include #include #include #include #include #include "vde/plugin/vde_plugin_api.h" namespace { constexpr const char* kBindingId = "binding.python"; constexpr const char* kApiVersion = "1.0"; std::string selected_language() { const char* raw = std::getenv("VDE_BINDING_LANGUAGE"); if (raw == nullptr || *raw == '\0') return "python"; std::string language(raw); for (char& c : language) { if (c >= 'A' && c <= 'Z') c = static_cast(c - 'A' + 'a'); } return language; } const char* manifest_for_language(const std::string& language) { if (language == "python") { return "{\"binding_id\":\"binding.python\",\"language\":\"python\"," "\"version\":\"1.0\",\"module\":\"vde\",\"entry\":\"vde._ctypes\"," "\"symbols\":[\"vde_body_create_box\",\"vde_body_volume\"," "\"vde_body_destroy\"],\"type_mappings\":{" "\"Vector3D\":\"tuple[float, float, float]\"," "\"BrepModel\":\"vde._ctypes.Body\"},\"build_hints\":{" "\"native\":\"vde_capi shared library\"," "\"smoke\":\"python python/smoke_test_ctypes.py --library " "/src/libvde_capi.so\"}}"; } if (language == "csharp") { return "{\"binding_id\":\"binding.python\",\"language\":\"csharp\"," "\"version\":\"1.0\",\"module\":\"Vde.Native\"," "\"entry\":\"Vde.Native.NativeMethods\"," "\"symbols\":[\"CreateBox\",\"GetVolume\",\"DestroyBody\"]," "\"type_mappings\":{\"Vector3D\":\"System.Numerics.Vector3\"," "\"BrepModel\":\"Vde.Native.BodyHandle\"},\"build_hints\":{" "\"native\":\"vde_capi shared library\"," "\"interop\":\"P/Invoke (DllImport)\"}}"; } if (language == "typescript") { return "{\"binding_id\":\"binding.python\",\"language\":\"typescript\"," "\"version\":\"1.0\",\"module\":\"@vde/core\",\"entry\":\"createBox\"," "\"symbols\":[\"createBox\",\"bodyVolume\",\"destroyBody\"]," "\"type_mappings\":{\"Vector3D\":\"[number, number, number]\"," "\"BrepModel\":\"BodyHandle\"},\"build_hints\":{" "\"wasm\":\"vde_wasm (planned)\",\"types\":\"index.d.ts\"}}"; } return nullptr; } int get_manifest_json(const VdePluginHost* host, VdeBuffer* result_json) { if (result_json) { result_json->data = nullptr; result_json->size = 0; } if (!host || !host->alloc || !host->set_error || !result_json) return VDE_PLUGIN_ERR_INVALID_ARG; const std::string language = selected_language(); const char* json = manifest_for_language(language); if (json == nullptr) { host->set_error(("binding_meta: unknown language '" + language + "' (expect python|csharp|typescript)").c_str()); return VDE_PLUGIN_ERR_INVALID_ARG; } const std::size_t size = std::strlen(json); void* out = host->alloc(size + 1); if (!out) { host->set_error("binding_meta: alloc failed"); return VDE_PLUGIN_ERR_BUFFER; } std::memcpy(out, json, size + 1); result_json->data = out; result_json->size = size; return VDE_PLUGIN_OK; } const char* describe() { return "VDE official binding metadata (python/csharp/typescript; " "VDE_BINDING_LANGUAGE env select; ABI 1.8)"; } const VdeBindingPlugin kBinding = [] { VdeBindingPlugin plugin{}; plugin.struct_size = sizeof(VdeBindingPlugin); plugin.binding_id = kBindingId; plugin.language = "python"; // 注册默认语言;manifest 由 VDE_BINDING_LANGUAGE 选择 plugin.capabilities_json = "{\"languages\":[\"python\",\"csharp\",\"typescript\"]," "\"module\":\"vde\",\"api_version\":\"1.0\"," "\"selection\":\"VDE_BINDING_LANGUAGE\"}"; plugin.get_manifest_json = &get_manifest_json; plugin.describe = &describe; return plugin; }(); } // namespace extern "C" { VDE_PLUGIN_EXPORT int vde_plugin_query(std::uint32_t host_abi_major, VdePluginInfo* info) { if (!info || info->struct_size < sizeof(VdePluginInfo)) return VDE_PLUGIN_ERR_INVALID_ARG; if (host_abi_major != VDE_PLUGIN_ABI_MAJOR) return VDE_PLUGIN_ERR_ABI; info->id = "com.vde.official.binding.python"; info->name = "VDE Official Binding Metadata"; info->version = "1.0.0"; info->kind = VDE_PLUGIN_KIND_BINDING; info->abi_major = VDE_PLUGIN_ABI_MAJOR; info->abi_minor = VDE_PLUGIN_ABI_MINOR; info->capabilities = "binding:python;binding:csharp;binding:typescript"; info->license = "Apache-2.0"; return VDE_PLUGIN_OK; } VDE_PLUGIN_EXPORT int vde_plugin_init(const VdePluginHost* host, VdePluginRegistration* reg) { (void)host; if (!reg) return VDE_PLUGIN_ERR_INVALID_ARG; if (reg->struct_size < sizeof(VdePluginRegistration)) return VDE_PLUGIN_ERR_ABI; reg->kind = VDE_PLUGIN_KIND_BINDING; reg->format = nullptr; reg->generic = nullptr; reg->cae_solver = nullptr; reg->cam_strategy = nullptr; reg->gcs_solver = nullptr; reg->mesher = nullptr; reg->optimizer = nullptr; reg->io_batch = nullptr; reg->geom_op = nullptr; reg->binding = &kBinding; return VDE_PLUGIN_OK; } VDE_PLUGIN_EXPORT void vde_plugin_shutdown() {} } // extern "C"