fix(linux): C++20 build + FFI ImeResult struct-size fix for the Fcitx5 addon - #409
Open
trongnguyenbinh wants to merge 3 commits into
Open
fix(linux): C++20 build + FFI ImeResult struct-size fix for the Fcitx5 addon#409trongnguyenbinh wants to merge 3 commits into
trongnguyenbinh wants to merge 3 commits into
Conversation
Fcitx5 5.1.x FCITX_LOGC uses std::source_location + consteval meta-strings (needs C++20). Building at C++17 failed 'template argument invalid' on the Engine.cpp log macros. Verified: rebuild produces gonhanh.so cleanly.
The Linux Fcitx5 addon declared the FFI result struct with chars[32] (132 bytes), but the Rust core's #[repr(C)] Result uses chars: [u32; MAX] with MAX=256 (1028 bytes). The compile-time static_assert only checked the C++ side (132), so the mismatch was silent. Consequence: the addon read `action` at byte offset 128, while Rust writes it at offset 1024. Every ime_key_ext() result was read as action=0 (None), so the addon passed every keystroke through untransformed — telex never converted (e.g. "dd" stayed "dd" instead of becoming "đ"). Fix: chars[256], static_assert(1028), rename _pad -> flags (matches Rust, carries key_consumed bit), and remove the stale i<32 cap in the UTF-8 copy loop. Verified via a direct libgonhanh_core FFI harness: dd->đ, aa->â. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Adds selftest.sh + selftest_dbus.py: a reusable, automated end-to-end test that drives a REAL fcitx5 + the gonhanh addon over DBus (no human GUI typing). selftest.sh spins up a private, isolated fcitx5 in its own dbus-run-session with a throwaway config where gonhanh is the only input method, so it never touches the user's live input session. selftest_dbus.py creates an input context, activates gonhanh, injects telex keysyms via ProcessKeyEvent, and reconstructs the visible text from CommitString / DeleteSurroundingText / ForwardKey signals plus passthrough keys — then asserts telex->Vietnamese. Covers dd->đ, aa->â, as->á, oo->ô, ow->ơ, ddaay->đây, ddungs->đúng, vieejt->việt, tieengs->tiếng. Exit 0 iff all pass. This is the automated regression guard that would have caught the chars[32] ABI bug (FFI-layer checks alone missed it). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mô tả
Sửa để bộ gõ chạy đúng trên Linux / Fcitx5 (test trên Ubuntu). Trước đó addon Linux gõ telex không biến đổi ký tự — gõ
ddraddthay vìđ.Gồm 2 fix + 1 test, chỉ đụng
platforms/linux/(không thay đổi Rust core hay macOS):Build C++20 —
platforms/linux/CMakeLists.txtFcitx5 5.1.19 dùng
std::source_location+constevaltrong macro log (FCITX_*LOG*) → cần C++20; addon đang để C++17 nên không build được. BumpCMAKE_CXX_STANDARD 17 → 20.FFI struct-size mismatch —
platforms/linux/src/RustBridge.{h,cpp}Rust core khai
ImeResult.chars: [u32; 256](struct 1028 byte, fieldactionở offset 1024), nhưng phía C++ khaichars[32](132 byte, đọcactionở offset 128) → luôn đọcaction = 0→ mọi phím bị passthrough, không convert. Sửachars[32] → [256],static_assert(132 → 1028), và bỏ giới hạni < 32trong vòng copy UTF-8.static_assertcũ chỉ kiểm tra kích thước phía C++ nên mismatch bị "im lặng".E2E selftest —
platforms/linux/selftest.sh+selftest_dbus.pyDựng một fcitx5 cô lập qua DBus, bơm chuỗi phím telex bằng
ProcessKeyEvent, dựng lại text từCommitString/DeleteSurroundingTextrồi assert. Đây là guard bắt đúng loại lỗi ABI ở (2) — test FFI thuần (chỉ gọi hàm) không bắt được.Loại thay đổi
Testing
Test trên Ubuntu (Fcitx5 5.1.19). Build lại trên nhánh
mainmới nhất của repo gốc → build OK, chạyplatforms/linux/selftest.sh:Checklist
cargo test/cargo fmt/cargo clippykhông bị ảnh hưởng (chỉ sửa C++ Linux port)