Skip to content

build: prepare the app to draw report images over native FFI - #677

Open
whes1015 wants to merge 1 commit into
mainfrom
build/ffi-groundwork
Open

whes1015 wants to merge 1 commit into
mainfrom
build/ffi-groundwork

Conversation

@whes1015

@whes1015 whes1015 commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

這個 PR 做了什麼

接續 eq-report-pic(Rust 繪圖、C ABI),把 DPIP 這一端的 Flutter FFI 準備做好:之後建置流程把原生庫放進產物,就能直接畫橫式地震報告分享圖,不用再繞 Flutter UI 截圖。這支 PR 沒有任何畫面在用它,app 現在的行為不變。

改動內容:

正式程式碼

  • pubspec.yaml / pubspec.lock:ffi 從 transitive 改成直接相依(renderer 要自己 malloc/free 原生記憶體),版號仍由 lock 決定。
  • lib/core/platform/native_library.dart:平台 → 檔名的唯一一份對照(Android/Linux lib<name>.so、macOS .dylib、Windows .dll、iOS DynamicLibrary.process)。開不起來回 Result 不丟例外——少了這個原生庫的 build 還是要能發地震警報。
  • lib/shared/seismic/report_picture/eq_report_pic_bindings.dart:從 eq-report-pic dart/lib/eq_report_pic.dart(c6d3420)整支搬過來,兩處本地修改都標了 DPIP::拿掉它自己的 open()(改走 NativeLibrary),加上 freeRenderer
  • lib/shared/seismic/report_picture/report_picture.dart:ReportPicture.open() 建立 renderer(字型解析+底圖解碼在 isolate)、render() 每次丟到新的 isolate 畫、dispose() 釋放;ReportPictureFailure 分開「這個 build 沒有原生庫」與「畫失敗」,呼叫端可以決定退回 Flutter 畫的卡片。
  • lib/core/error/failure.dart:上述 ReportPictureFailure / ReportPictureFailureReason。
  • assets/fonts/report/:三支字型(13.8 MB,M+ 2p Bold/Gen Shin Gothic Bold/Noto Sans TC Black)與授權說明。不內嵌在 Rust 裡:內嵌會讓每個 Android ABI 都多一份;字型由 app 當 asset 帶著,建立 renderer 時依 fallback 順序傳進去。三支跟 cwa-eq-map 同一組,兩邊畫出來才會一樣。
  • ARCHITECTURE.md:新增 Native libraries(FFI)一節,寫清楚 isolate 規則、打包方式(Android jniLibs、iOS xcframework + -force_load)與「沒有原生庫也要能啟動」。

測試

  • test/core/platform/native_library_test.dart:檔名對照、iOS 走 process、缺檔與 loader 丟例外都轉成 Result。
  • test/shared/seismic/report_picture_test.dart:三支字型 asset 真的載得到且不是空檔;缺庫與 ABI 符號不符都在 open() 就回 unavailable,不會拖到 render 才炸。

沒做的、刻意留下的

  • 沒有把 eq-report-pic 編進 repo,也沒有加 CI 步驟去編它:那需要 cargo/NDK,會讓一般 Flutter build 多一個 Rust toolchain 相依。所以在建置流程把 .so/xcframework 放進去之前,ReportPicture.open() 一律回 unavailable。
  • 沒有 UI 串接。render 路徑沒有在實機跑過(沒有原生庫可載入)。

相關 issue

沒有對應的 issue。

上游:ExpTechTW/eq-report-pic(c6d3420)。

怎麼驗

  • tool/dev/analyze.sh:No issues found。
  • tool/dev/test.sh test/core/platform/native_library_test.dart test/shared/seismic/report_picture_test.dart:11 個測試通過。
  • tool/check.sh:format/analyze/codegen 與各道 bash gate(workflows、workflow_security、tooling、l10n、pubspec_lock、notification_sounds、build_info、widget_township_resources、layering、storage、wall_clock)都過;全套測試除了 test/tool/ 的 10 個環境失敗以外全過。
    • 那 10 個在乾淨的 origin/main worktree 一樣失敗,與這支 PR 無關:這個 clone 只有 60 個 commit(shallow),release_notes_platform_test 需要的 b6ea9e89/61f69f1a 不在物件庫;其餘是腳本在容器裡的執行權限。CI 的完整 checkout 不會有這個問題。
  • 沒有在實機/模擬器上看過:repo 裡沒有原生庫,render 這條路徑還沒真的跑過;等建置流程把庫放進來,請在 Android 與 iOS 各畫一張確認。

檢查清單

  • tool/check/commits.sh origin/main..HEAD 通過
  • 一個 commit 一件事
  • 新增的使用者可見字串:無(沒有 UI 變更)
  • CI 全部通過(gh pr checks:build、Android、iOS、code-review、codecov ×2 都是 pass;Instrumented skipped)
  • 沒有 UI 變更,不需要深色模式與 spacing 檢查

@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 21.58273% with 109 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.42%. Comparing base (3b1020d) to head (c632f75).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
...seismic/report_picture/eq_report_pic_bindings.dart 1.96% 50 Missing ⚠️
.../shared/seismic/report_picture/report_picture.dart 19.67% 49 Missing ⚠️
lib/core/platform/native_library.dart 61.53% 10 Missing ⚠️

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant