xidlc 使用指南
使用 xidlc
Section titled “使用 xidlc”xidlc 是 XIDL 的标准入口。它读取一个或多个 .idl 文件,并为选定目标生成产物。
先建立正确心智模型
Section titled “先建立正确心智模型”xidlc 的工作方式很简单:
- 输入一份或多份 IDL
- 选择一个目标生成器
- 指定输出目录
- 获得该目标对应的文件
最小命令:
xidlc gen --out-dir out rust path/to/file.idl短写:
xidlc gen -o out rust path/to/file.idl--out-dir,-o:指定输出目录<lang>:选择xidlc gen下的目标生成器子命令--client:为支持该参数的目标额外生成客户端相关产物--server:为支持该参数的目标生成服务端相关产物--dry-run:执行解析和生成流程,但不落盘
生成 Rust 类型
Section titled “生成 Rust 类型”xidlc gen -o src/generated rust api.idl生成 Axum HTTP 绑定
Section titled “生成 Axum HTTP 绑定”xidlc gen -o src/generated rust-axum api.idl生成 JSON-RPC 绑定
Section titled “生成 JSON-RPC 绑定”xidlc gen -o src/generated rust-jsonrpc api.idl生成 OpenAPI
Section titled “生成 OpenAPI”xidlc gen -o generated openapi api.idl生成 OpenRPC
Section titled “生成 OpenRPC”xidlc gen -o generated openrpc api.idlCLI 同时提供格式化子命令:
xidlc fmt path/to/file.idl就地改写:
xidlc fmt --inplace path/to/file.idl