DOC-302b zx_document_ffi 函数迁移到 #[uniffi::export] #31

Closed
opened 2026-06-02 22:18:54 +08:00 by wangdl · 2 comments
Owner

目标

给 zx_document_ffi/src/lib.rs 所有 12 个公开函数加 #[uniffi::export],移除 UDL namespace 函数声明。

需要标注的函数

#[uniffi::export] fn detect_material_type
#[uniffi::export] fn read_image_meta
#[uniffi::export] fn read_text_stats
#[uniffi::export] fn parse_text
#[uniffi::export] fn parse_markdown
#[uniffi::export] fn search_markdown_blocks
#[uniffi::export] fn search_text_content
#[uniffi::export] fn create_note_anchor
#[uniffi::export] fn push_reading_event
#[uniffi::export] fn update_reading_position
#[uniffi::export] fn export_pending_events
#[uniffi::export] fn clear_exported_events

改动

  1. 每个函数加 #[uniffi::export]
  2. UDL 文件:namespace 保留但清空函数声明(或删除,视 proc-macro 是否需要 namespace)
  3. FFI crate 的 Cargo.toml 确认 uniffi 依赖包含 proc-macro feature

依赖

  • 依赖 DOC-302a(核心类型必须先有 uniffi derive)

验收

  • cargo build -p zx_document_ffi 无编译错误
  • extern "C" 符号出现在编译产物中(nm 验证)
## 目标 给 zx_document_ffi/src/lib.rs 所有 12 个公开函数加 `#[uniffi::export]`,移除 UDL namespace 函数声明。 ## 需要标注的函数 ```rust #[uniffi::export] fn detect_material_type #[uniffi::export] fn read_image_meta #[uniffi::export] fn read_text_stats #[uniffi::export] fn parse_text #[uniffi::export] fn parse_markdown #[uniffi::export] fn search_markdown_blocks #[uniffi::export] fn search_text_content #[uniffi::export] fn create_note_anchor #[uniffi::export] fn push_reading_event #[uniffi::export] fn update_reading_position #[uniffi::export] fn export_pending_events #[uniffi::export] fn clear_exported_events ``` ## 改动 1. 每个函数加 `#[uniffi::export]` 2. UDL 文件:namespace 保留但清空函数声明(或删除,视 proc-macro 是否需要 namespace) 3. FFI crate 的 Cargo.toml 确认 uniffi 依赖包含 proc-macro feature ## 依赖 - 依赖 DOC-302a(核心类型必须先有 uniffi derive) ## 验收 - `cargo build -p zx_document_ffi` 无编译错误 - extern "C" 符号出现在编译产物中(nm 验证)
wangdl added this to the M3:iOS 主 App 资料阅读闭环 milestone 2026-06-02 22:18:54 +08:00
wangdl added the
type:implementation
area:ffi
labels 2026-06-02 22:18:54 +08:00
Author
Owner

完成 (2026-06-03)

改动

  1. FFI crate 类型加 derive:
    • DocumentBlock#[derive(uniffi::Enum)]
    • DocumentError#[derive(uniffi::Error)]
  2. 12 个 FFI 函数全部标注 #[uniffi::export]
  3. Arc<ImageMeta> / Arc<TextStats> 改为直接返回值类型(UniFFI 不支持 Arc for custom types)
  4. 移除 use std::sync::Arc(不再需要)
  5. UDL 保留类型定义 + 函数声明(用于 Swift bindgen 生成)

验证

  • cargo build 通过
  • nm -g libzx_document_ffi.a 确认 12 个 uniffi_zx_document_ffi_fn_func_* + 12 个 checksum 符号全部存在
  • cargo test 58 pass
## 完成 (2026-06-03) ### 改动 1. FFI crate 类型加 derive: - `DocumentBlock` → `#[derive(uniffi::Enum)]` - `DocumentError` → `#[derive(uniffi::Error)]` 2. 12 个 FFI 函数全部标注 `#[uniffi::export]` 3. `Arc<ImageMeta>` / `Arc<TextStats>` 改为直接返回值类型(UniFFI 不支持 Arc for custom types) 4. 移除 `use std::sync::Arc`(不再需要) 5. UDL 保留类型定义 + 函数声明(用于 Swift bindgen 生成) ### 验证 - `cargo build` 通过 - `nm -g libzx_document_ffi.a` 确认 12 个 `uniffi_zx_document_ffi_fn_func_*` + 12 个 checksum 符号全部存在 - `cargo test` 58 pass
Author
Owner

关闭

DOC-302b 已完成 — FFI 函数使用 #[uniffi::export]

## 关闭 DOC-302b 已完成 — FFI 函数使用 #[uniffi::export]
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wangdl/zhixi-document-runtime#31
No description provided.