Skip to content

Commit

Permalink
Merge pull request #427 from cunarist/increase-rust-version
Browse files Browse the repository at this point in the history
Increase `rust-version`
  • Loading branch information
temeddix authored Sep 12, 2024
2 parents f6ac782 + 739694d commit c169078
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
37 changes: 18 additions & 19 deletions flutter_package/lib/src/load_os.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -111,25 +125,11 @@ 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
/// 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() {
Expand Down Expand Up @@ -167,16 +167,15 @@ 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;
late void Function(PostCObjectPtr) storeDartPostCObjectExtern;
late void Function(int, Pointer<Uint8>, int, Pointer<Uint8>, int)
sendDartSignalExtern;

RustLibraryOld(DynamicLibrary lib) {
this.lib = lib;
RustLibraryOld({required this.lib}) {
this.startRustLogicExtern =
lib.lookupFunction<Void Function(), void Function()>(
'start_rust_logic_extern',
Expand Down
2 changes: 1 addition & 1 deletion rust_crate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit c169078

Please sign in to comment.