mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-09-22 09:58:06 +00:00
feat: multi-platform .hmap bundle + platform auto-selection
- PluginManifest: add platforms field declaring supported OS - validatePackage: accept bundle .hmap with platform-aware binary check - extractPackage: extract only current OS binary, skip others (macOS renames .dylib → .so) - installFromPath/installFromURL: path install keeps source, URL install auto-cleanup - cabi/loader.go + dynamic.go: add linux/darwin build constraints for Windows cross-compile - dynamic_loader_unix/windows: split SO loading with proper build tags - package/build.sh: enable windows/amd64 for homed, add CXX export for arm64 - tryLoadSO: fallback to plugin.dylib on macOS - docs: update PLUGIN_DEV.md for bundle format and install methods
This commit is contained in:
@ -112,26 +112,50 @@ Execution process:
|
||||
2. **Go plugin**: Runs `go build -buildmode=c-shared` (produces `.so` + C ABI header)
|
||||
3. **Lua plugin**: Packages source code directly, no compilation needed
|
||||
4. Generates `plugin.json` manifest file
|
||||
5. Packages as `.hmap` distribution (zip format, containing `plugin.json` + `plugin.so` + `plugin.dll` + `main.lua`)
|
||||
5. Packages as `.hmap` distribution (zip format, containing `plugin.json` + platform binary)
|
||||
|
||||
The `platforms` field in `plugin.json` declares supported platforms; the build includes the corresponding binary:
|
||||
|
||||
| Platform | Binary name |
|
||||
|----------|-------------|
|
||||
| Linux | `plugin.so` |
|
||||
| macOS | `plugin.dylib` |
|
||||
| Windows | `plugin.dll` |
|
||||
|
||||
> Use `--bundle` to build a multi-platform bundle — the resulting `.hmap` contains binaries for all platforms.
|
||||
> During installation, the kernel automatically selects the correct binary for the current OS, skipping others.
|
||||
|
||||
Output in `dist/` directory:
|
||||
```
|
||||
dist/
|
||||
├── myplugin_linux_amd64.hmap # Go plugin Linux version
|
||||
├── myplugin_windows_amd64.hmap # Go plugin Windows version
|
||||
├── myplugin_darwin_amd64.hmap # Go plugin macOS version
|
||||
└── myplugin_lua.hmap # Lua plugin
|
||||
```
|
||||
|
||||
### Deployment
|
||||
|
||||
Install via PluginMgr HTTP API:
|
||||
Install via PluginMgr HTTP API (three methods):
|
||||
|
||||
```bash
|
||||
# Kernel PluginMgr listens on :9876
|
||||
# 1. Install from URL (auto-cleanup)
|
||||
curl -X POST http://127.0.0.1:9876/plugins \
|
||||
-F "file=@dist/myplugin_linux_amd64.hmap"
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"url": "https://example.com/myplugin.hmap"}'
|
||||
|
||||
# 2. Install from local path (keeps source file)
|
||||
curl -X POST http://127.0.0.1:9876/plugins \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"path": "/path/to/myplugin.hmap"}'
|
||||
|
||||
# 3. Upload binary directly
|
||||
curl -X POST http://127.0.0.1:9876/plugins \
|
||||
--data-binary @dist/myplugin.hmap
|
||||
```
|
||||
|
||||
Reload plugins via `/api/v1/plugins/reload` or restart the kernel to activate.
|
||||
|
||||
Or upload via WebUI plugin management page.
|
||||
|
||||
---
|
||||
|
||||
@ -113,27 +113,51 @@ plugindev build
|
||||
2. **Go 插件**:执行 `go build -buildmode=c-shared`(生成 `.so` + C ABI header)
|
||||
3. **Lua 插件**:直接打包源码,无需编译
|
||||
4. 生成 `plugin.json` 清单文件
|
||||
5. 打包为 `.hmap` 分发包(zip 格式,内含 `plugin.json` + `plugin.so` + `plugin.dll` + `main.lua`)
|
||||
5. 打包为 `.hmap` 分发包(zip 格式,内含 `plugin.json` + 平台二进制)
|
||||
|
||||
`plugin.json` 的 `platforms` 字段声明支持的平台,打包时自动包含对应二进制:
|
||||
|
||||
| 平台 | 二进制文件名 |
|
||||
|------|-------------|
|
||||
| Linux | `plugin.so` |
|
||||
| macOS | `plugin.dylib` |
|
||||
| Windows | `plugin.dll` |
|
||||
|
||||
> 使用 `--bundle` 可一次打包多平台,生成的 `.hmap` 内含所有平台的二进制。
|
||||
> 安装时核心自动选择当前平台的文件,跳过其他平台。
|
||||
|
||||
输出在 `dist/` 目录:
|
||||
```
|
||||
dist/
|
||||
├── myplugin_linux_amd64.hmap # Go 插件 Linux 版
|
||||
├── myplugin_windows_amd64.hmap # Go 插件 Windows 版
|
||||
├── myplugin_darwin_amd64.hmap # Go 插件 macOS 版
|
||||
└── myplugin_lua.hmap # Lua 插件
|
||||
```
|
||||
|
||||
### 安装部署
|
||||
|
||||
通过 PluginMgr HTTP API 安装:
|
||||
通过 PluginMgr HTTP API 安装,支持三种方式:
|
||||
|
||||
```bash
|
||||
# 内核 PluginMgr 监听 :9876
|
||||
# 1. 从 URL 安装(自动清理安装包)
|
||||
curl -X POST http://127.0.0.1:9876/plugins \
|
||||
-F "file=@dist/myplugin_linux_amd64.hmap"
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"url": "https://example.com/myplugin.hmap"}'
|
||||
|
||||
# 2. 从本地路径安装(保留安装包)
|
||||
curl -X POST http://127.0.0.1:9876/plugins \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"path": "/path/to/myplugin.hmap"}'
|
||||
|
||||
# 3. 直接上传二进制
|
||||
curl -X POST http://127.0.0.1:9876/plugins \
|
||||
--data-binary @dist/myplugin.hmap
|
||||
```
|
||||
|
||||
或通过 WebUI 插件管理页面上传安装。
|
||||
安装后需调用 `/api/v1/plugins/reload` 或重启内核生效。
|
||||
|
||||
也可通过 WebUI 插件管理页面上传安装。
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user