From 8dd6db748fec30091c06f445b2b62654fcd3ce74 Mon Sep 17 00:00:00 2001 From: Donghyun Kim Date: Fri, 13 Sep 2024 02:52:38 +0900 Subject: [PATCH 1/3] Increase `rust-version` --- rust_crate/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust_crate/Cargo.toml b/rust_crate/Cargo.toml index 3da87ff9..607a1c22 100644 --- a/rust_crate/Cargo.toml +++ b/rust_crate/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT" description = "Rust for native business logic, Flutter for flexible and beautiful GUI" repository = "https://github.com/cunarist/rinf" documentation = "https://rinf.cunarist.com" -rust-version = "1.70" +rust-version = "1.80" [features] show-backtrace = ["backtrace"] From 8a5ad7a5505ba1052d820ba79d9f86c0aa685df1 Mon Sep 17 00:00:00 2001 From: Donghyun Kim Date: Fri, 13 Sep 2024 02:59:52 +0900 Subject: [PATCH 2/3] Fix comments and organize code --- flutter_package/lib/src/load_os.dart | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/flutter_package/lib/src/load_os.dart b/flutter_package/lib/src/load_os.dart index 29b23419..9c08e892 100644 --- a/flutter_package/lib/src/load_os.dart +++ b/flutter_package/lib/src/load_os.dart @@ -35,7 +35,7 @@ RustLibrary loadRustLibrary() { // because of Flutter's `RTLD_LOCAL` behavior. // Therefore we cannot use the efficient `RustLibraryNew`. // - https://github.com/dart-lang/native/issues/923 - return RustLibraryOld(lib); + return RustLibraryOld(lib: lib); } else { // Native library symbols are loaded in global space // thanks to Flutter's `RTLD_GLOBAL` behavior. @@ -129,7 +129,7 @@ abstract class RustLibrary { /// This is the efficient and ideal way to call native code. /// `@Native` decorator with `isLeaf` parameter /// that enables the `Uint8List.address` syntax -/// can only used on global native symbols. +/// can only be used on globally loaded native symbols. /// - https://github.com/dart-lang/sdk/issues/44589 class RustLibraryNew extends RustLibrary { void startRustLogic() { @@ -167,7 +167,7 @@ class RustLibraryNew extends RustLibrary { /// This is relatively inefficient because `malloc.allocate` is required. /// It involves extra memory copy before sending the data to Rust. class RustLibraryOld extends RustLibrary { - late DynamicLibrary lib; + final DynamicLibrary lib; late void Function() startRustLogicExtern; late void Function() stopRustLogicExtern; late void Function(int) prepareIsolateExtern; @@ -175,8 +175,7 @@ class RustLibraryOld extends RustLibrary { late void Function(int, Pointer, int, Pointer, int) sendDartSignalExtern; - RustLibraryOld(DynamicLibrary lib) { - this.lib = lib; + RustLibraryOld({required this.lib}) { this.startRustLogicExtern = lib.lookupFunction( 'start_rust_logic_extern', From 739694d5343a845af3ed502ac9da7b3801a31acd Mon Sep 17 00:00:00 2001 From: Donghyun Kim Date: Fri, 13 Sep 2024 03:02:45 +0900 Subject: [PATCH 3/3] Organize code --- flutter_package/lib/src/load_os.dart | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/flutter_package/lib/src/load_os.dart b/flutter_package/lib/src/load_os.dart index 9c08e892..8f14ae7b 100644 --- a/flutter_package/lib/src/load_os.dart +++ b/flutter_package/lib/src/load_os.dart @@ -67,6 +67,20 @@ typedef SendDartSignalWrap = void Function( int, ); +/// Abstract class for unifying the interface +/// for calling native functions. +abstract class RustLibrary { + void startRustLogic(); + void stopRustLogic(); + void prepareIsolate(int port); + void storeDartPostCObject(PostCObjectPtr postCObject); + void sendDartSignal( + int messageId, + Uint8List messageBytes, + Uint8List binary, + ); +} + // Direct access to global function symbols loaded in the process. // These are available only if the native library is // loaded into global space with `RTLD_GLOBAL` configuration. @@ -111,20 +125,6 @@ external void sendDartSignalExtern( int binaryLength, ); -/// Abstract class for unifying the interface -/// for calling native functions. -abstract class RustLibrary { - void startRustLogic(); - void stopRustLogic(); - void prepareIsolate(int port); - void storeDartPostCObject(PostCObjectPtr postCObject); - void sendDartSignal( - int messageId, - Uint8List messageBytes, - Uint8List binary, - ); -} - /// Class for global native library symbols loaded with `RTLD_GLOBAL`. /// This is the efficient and ideal way to call native code. /// `@Native` decorator with `isLeaf` parameter