khoren93 / flutter_zxing

Flutter plugin for scanning and generating QR codes using the ZXing library, supporting Android, iOS, and desktop platforms
https://pub.dev/packages/flutter_zxing
MIT License
88 stars 50 forks source link

ffi: linux support. ci: add build + integration test to CI. #144

Closed phlip9 closed 1 month ago

phlip9 commented 1 month ago

Hey again! Back with another pass at fixing up the native glue code. I recently needed to run our app on a Linux machine and encountered a crash with flutter_zxing whenever it called encodeBarcode. With this PR, I can now confidently run flutter_zxing on Linux w/o issues!

Overview

This PR:

  1. Adds support for Linux (minus camera support, of course). Had to fix some SEGFAULTs in the native code to get this working.
  2. Adds an integration test exercising the FFI code.
  3. Adds flutter build and flutter test integration_test Github CI workflows running across android, iOS, macOS, and linux. Windows build fails to compile though.
  4. Enforces strict allocator discipline in the native code. Memory freed in C++ from Dart must use dart_free. Memory freed in Dart from C++ must be allocated with dart_malloc.
  5. Tries hard to ensure we don't throw/unwind exceptions across the FFI boundary, which is unsafe. Public FFI functions are marked noexcept.

I recommend reviewing by commit.

phlip9 commented 1 month ago

cc @khoren93

khoren93 commented 1 month ago

Hey @phlip9

Thanks for the great work on fixing up the native glue code and adding Linux support. The PR has been merged!