Skip to content

Commit

Permalink
fix loading
Browse files Browse the repository at this point in the history
  • Loading branch information
temeddix committed Sep 9, 2024
1 parent 2b0b9ff commit 6aa77e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
3 changes: 3 additions & 0 deletions flutter_ffi_plugin/lib/src/interface_os.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ void setCompiledLibPathReal(String path) {
Future<void> prepareInterfaceReal(
AssignRustSignal assignRustSignal,
) async {
// Load the native library.
loadRustLibrary();

/// This should be called once at startup
/// to enable `allo_isolate` to send data from the Rust side.
storeDartPostCObjectReal(NativeApi.postCObject);
Expand Down
15 changes: 7 additions & 8 deletions flutter_ffi_plugin/lib/src/load_os.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,29 @@ import 'dart:io' as io;
import 'dart:ffi';

String? dynamicLibPath;
final rustLibrary = loadRustLibrary();

void setDynamicLibPath(String path) {
dynamicLibPath = path;
}

DynamicLibrary loadRustLibrary() {
void loadRustLibrary() {
// Use provided dynamic library path if possible.
final path = dynamicLibPath;
if (path != null) {
return DynamicLibrary.open(path);
DynamicLibrary.open(path);
}

// Otherewise, use the default path.
if (io.Platform.isLinux) {
return DynamicLibrary.open('libhub.so');
DynamicLibrary.open('libhub.so');
} else if (io.Platform.isAndroid) {
return DynamicLibrary.open('libhub.so');
DynamicLibrary.open('libhub.so');
} else if (io.Platform.isWindows) {
return DynamicLibrary.open('hub.dll');
DynamicLibrary.open('hub.dll');
} else if (io.Platform.isIOS) {
return DynamicLibrary.open('rinf.framework/rinf');
DynamicLibrary.open('rinf.framework/rinf');
} else if (io.Platform.isMacOS) {
return DynamicLibrary.open('rinf.framework/rinf');
DynamicLibrary.open('rinf.framework/rinf');
} else {
throw UnsupportedError('This operating system is not supported.');
}
Expand Down

0 comments on commit 6aa77e8

Please sign in to comment.