Skip to content

Commit

Permalink
Merge branch 'rust'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.metadata
#	macos/Runner.xcodeproj/project.pbxproj
#	pubspec.lock
#	test/widget_test.dart
  • Loading branch information
springeye committed Jun 14, 2023
2 parents cdfc917 + e903947 commit c2b37b4
Show file tree
Hide file tree
Showing 23 changed files with 2,399 additions and 83 deletions.
204 changes: 204 additions & 0 deletions lib/bridge_generated.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
// AUTO GENERATED FILE, DO NOT EDIT.
// Generated by `flutter_rust_bridge`@ 1.77.1.
// ignore_for_file: non_constant_identifier_names, unused_element, duplicate_ignore, directives_ordering, curly_braces_in_flow_control_structures, unnecessary_lambdas, slash_for_doc_comments, prefer_const_literals_to_create_immutables, implicit_dynamic_list_literal, duplicate_import, unused_import, unnecessary_import, prefer_single_quotes, prefer_const_constructors, use_super_parameters, always_use_package_imports, annotate_overrides, invalid_use_of_protected_member, constant_identifier_names, invalid_use_of_internal_member, prefer_is_empty, unnecessary_const

import 'dart:convert';
import 'dart:async';
import 'package:meta/meta.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge.dart';
import 'package:uuid/uuid.dart';

import 'dart:ffi' as ffi;

abstract class RustFfi {
Stream<String> query({dynamic hint});

FlutterRustBridgeTaskConstMeta get kQueryConstMeta;
}

class RustFfiImpl implements RustFfi {
final RustFfiPlatform _platform;
factory RustFfiImpl(ExternalLibrary dylib) =>
RustFfiImpl.raw(RustFfiPlatform(dylib));

/// Only valid on web/WASM platforms.
factory RustFfiImpl.wasm(FutureOr<WasmModule> module) =>
RustFfiImpl(module as ExternalLibrary);
RustFfiImpl.raw(this._platform);
Stream<String> query({dynamic hint}) {
return _platform.executeStream(FlutterRustBridgeTask(
callFfi: (port_) => _platform.inner.wire_query(port_),
parseSuccessData: _wire2api_String,
constMeta: kQueryConstMeta,
argValues: [],
hint: hint,
));
}

FlutterRustBridgeTaskConstMeta get kQueryConstMeta =>
const FlutterRustBridgeTaskConstMeta(
debugName: "query",
argNames: [],
);

void dispose() {
_platform.dispose();
}
// Section: wire2api

String _wire2api_String(dynamic raw) {
return raw as String;
}

int _wire2api_u8(dynamic raw) {
return raw as int;
}

Uint8List _wire2api_uint_8_list(dynamic raw) {
return raw as Uint8List;
}
}

// Section: api2wire

// Section: finalizer

class RustFfiPlatform extends FlutterRustBridgeBase<RustFfiWire> {
RustFfiPlatform(ffi.DynamicLibrary dylib) : super(RustFfiWire(dylib));

// Section: api2wire

// Section: finalizer

// Section: api_fill_to_wire
}

// ignore_for_file: camel_case_types, non_constant_identifier_names, avoid_positional_boolean_parameters, annotate_overrides, constant_identifier_names

// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
// ignore_for_file: type=lint

/// generated by flutter_rust_bridge
class RustFfiWire implements FlutterRustBridgeWireBase {
@internal
late final dartApi = DartApiDl(init_frb_dart_api_dl);

/// Holds the symbol lookup function.
final ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
_lookup;

/// The symbols are looked up in [dynamicLibrary].
RustFfiWire(ffi.DynamicLibrary dynamicLibrary)
: _lookup = dynamicLibrary.lookup;

/// The symbols are looked up with [lookup].
RustFfiWire.fromLookup(
ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
lookup)
: _lookup = lookup;

void store_dart_post_cobject(
DartPostCObjectFnType ptr,
) {
return _store_dart_post_cobject(
ptr,
);
}

late final _store_dart_post_cobjectPtr =
_lookup<ffi.NativeFunction<ffi.Void Function(DartPostCObjectFnType)>>(
'store_dart_post_cobject');
late final _store_dart_post_cobject = _store_dart_post_cobjectPtr
.asFunction<void Function(DartPostCObjectFnType)>();

Object get_dart_object(
int ptr,
) {
return _get_dart_object(
ptr,
);
}

late final _get_dart_objectPtr =
_lookup<ffi.NativeFunction<ffi.Handle Function(ffi.UintPtr)>>(
'get_dart_object');
late final _get_dart_object =
_get_dart_objectPtr.asFunction<Object Function(int)>();

void drop_dart_object(
int ptr,
) {
return _drop_dart_object(
ptr,
);
}

late final _drop_dart_objectPtr =
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.UintPtr)>>(
'drop_dart_object');
late final _drop_dart_object =
_drop_dart_objectPtr.asFunction<void Function(int)>();

int new_dart_opaque(
Object handle,
) {
return _new_dart_opaque(
handle,
);
}

late final _new_dart_opaquePtr =
_lookup<ffi.NativeFunction<ffi.UintPtr Function(ffi.Handle)>>(
'new_dart_opaque');
late final _new_dart_opaque =
_new_dart_opaquePtr.asFunction<int Function(Object)>();

int init_frb_dart_api_dl(
ffi.Pointer<ffi.Void> obj,
) {
return _init_frb_dart_api_dl(
obj,
);
}

late final _init_frb_dart_api_dlPtr =
_lookup<ffi.NativeFunction<ffi.IntPtr Function(ffi.Pointer<ffi.Void>)>>(
'init_frb_dart_api_dl');
late final _init_frb_dart_api_dl = _init_frb_dart_api_dlPtr
.asFunction<int Function(ffi.Pointer<ffi.Void>)>();

void wire_query(
int port_,
) {
return _wire_query(
port_,
);
}

late final _wire_queryPtr =
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int64)>>('wire_query');
late final _wire_query = _wire_queryPtr.asFunction<void Function(int)>();

void free_WireSyncReturn(
WireSyncReturn ptr,
) {
return _free_WireSyncReturn(
ptr,
);
}

late final _free_WireSyncReturnPtr =
_lookup<ffi.NativeFunction<ffi.Void Function(WireSyncReturn)>>(
'free_WireSyncReturn');
late final _free_WireSyncReturn =
_free_WireSyncReturnPtr.asFunction<void Function(WireSyncReturn)>();
}

final class _Dart_Handle extends ffi.Opaque {}

typedef DartPostCObjectFnType = ffi.Pointer<
ffi.NativeFunction<
ffi.Bool Function(DartPort port_id, ffi.Pointer<ffi.Void> message)>>;
typedef DartPort = ffi.Int64;
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:fterm/bootstrap/launcher.dart';
import 'package:fterm/bootstrap/options.dart';
import 'package:fterm/bootstrap/runner.dart';

import 'native.dart';

Future<void> main(List<String> arguments) async {
print("launch arguments==>$arguments");
if (kDebugMode) Bloc.observer = _AppBlocObserver();
Expand Down
28 changes: 28 additions & 0 deletions lib/native.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'dart:ffi';
import 'dart:io' as io;
import 'dart:isolate';
import 'dart:typed_data';
import 'package:ffi/ffi.dart';

import 'bridge_generated.dart';

const _base = 'rust_ffi';

// On MacOS, the dynamic library is not bundled with the binary,
// but rather directly **linked** against the binary.
final _dylib = io.Platform.isWindows ? '$_base.dll' : 'lib$_base.so';

//@executable_path/../Frameworks/
class Native2Api {
final String? path;
final RustFfi _api;

Native2Api({this.path})
: _api = RustFfiImpl(io.Platform.isIOS || io.Platform.isMacOS
? DynamicLibrary.executable()
: DynamicLibrary.open(_dylib));

Stream<String> query() {
return _api.query();
}
}
1 change: 1 addition & 0 deletions linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ set_target_properties(${BINARY_NAME}
# Generated plugin build rules, which manage building the plugins and adding
# them to the application.
include(flutter/generated_plugins.cmake)
include(./rust.cmake)


# === Installation ===
Expand Down
21 changes: 21 additions & 0 deletions linux/rust.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# We include Corrosion inline here, but ideally in a project with
# many dependencies we would need to install Corrosion on the system.
# See instructions on https://github.com/AndrewGaspar/corrosion#cmake-install
# Once done, uncomment this line:
# find_package(Corrosion REQUIRED)

include(FetchContent)

FetchContent_Declare(
Corrosion
GIT_REPOSITORY https://github.com/AndrewGaspar/corrosion.git
GIT_TAG origin/master # Optionally specify a version tag or branch here
)

FetchContent_MakeAvailable(Corrosion)

corrosion_import_crate(MANIFEST_PATH ../rust_ffi/Cargo.toml IMPORTED_CRATES imported_crates)
target_link_libraries(${BINARY_NAME} PRIVATE ${imported_crates})
foreach(imported_crate ${imported_crates})
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${imported_crate}-shared>)
endforeach()
Loading

0 comments on commit c2b37b4

Please sign in to comment.