-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,800 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# See `pure_dart` example for comments on the configs | ||
rust_input: rust/src/api/**/*.rs | ||
dart_output: lib/src/rust | ||
c_output: frb_generated.h | ||
dump_all: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
migrate_working_dir/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
**/doc/api/ | ||
**/ios/Flutter/.last_build_id | ||
.dart_tool/ | ||
.flutter-plugins | ||
.flutter-plugins-dependencies | ||
.packages | ||
.pub-cache/ | ||
.pub/ | ||
/build/ | ||
|
||
# Symbolication related | ||
app.*.symbols | ||
|
||
# Obfuscation related | ||
app.*.map.json | ||
|
||
# Android Studio will place build artifacts here | ||
/android/app/debug | ||
/android/app/profile | ||
/android/app/release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
analyzer: | ||
exclude: | ||
- rust/target/**.dart # contains dumped debug info, instead of normal code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import 'package:flutter_rust_bridge_utils/flutter_rust_bridge_utils.dart'; | ||
|
||
void main(List<String> args) async => simpleBuild(args); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
typedef struct DartCObject *WireSyncReturn; | ||
typedef struct _Dart_Handle* Dart_Handle; | ||
|
||
void wire_minimal_adder(int64_t port_, int32_t a, int32_t b); | ||
static int64_t dummy_method_to_enforce_bundling(void) { | ||
int64_t dummy_var = 0; | ||
dummy_var ^= ((int64_t) (void*) drop_dart_object); | ||
dummy_var ^= ((int64_t) (void*) get_dart_object); | ||
dummy_var ^= ((int64_t) (void*) new_dart_opaque); | ||
dummy_var ^= ((int64_t) (void*) store_dart_post_cobject); | ||
dummy_var ^= ((int64_t) (void*) wire_minimal_adder); | ||
return dummy_var; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// ignore_for_file: invalid_use_of_internal_member, unused_import | ||
|
||
import '../frb_generated.dart'; | ||
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; | ||
|
||
Future<int> minimalAdder({required int a, required int b, dynamic hint}) => | ||
RustLib.instance.api.minimalAdder(a: a, b: b, hint: hint); |
88 changes: 88 additions & 0 deletions
88
frb_example/deliberate_bad/lib/src/rust/frb_generated.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// ignore_for_file: unused_import, unused_element, duplicate_ignore | ||
|
||
import 'api/minimal.dart'; | ||
import 'dart:async'; | ||
import 'dart:convert'; | ||
import 'frb_generated.io.dart' if (dart.library.html) 'frb_generated.web.dart'; | ||
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; | ||
|
||
/// Main entrypoint of the Rust API | ||
class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> { | ||
@internal | ||
static final instance = RustLib._(); | ||
|
||
RustLib._(); | ||
|
||
/// Initialize flutter_rust_bridge | ||
static Future<void> init({ | ||
RustLibApi? api, | ||
BaseHandler? handler, | ||
}) async { | ||
await instance.initImpl(api: api, handler: handler); | ||
} | ||
|
||
/// Dispose flutter_rust_bridge | ||
/// | ||
/// The call to this function is optional, since flutter_rust_bridge (and everything else) | ||
/// is automatically disposed when the app stops. | ||
static void dispose() => instance.disposeImpl(); | ||
|
||
@override | ||
ApiImplConstructor<RustLibApiImpl, RustLibWire> get apiImplConstructor => | ||
RustLibApiImpl.new; | ||
|
||
@override | ||
WireConstructor<RustLibWire> get wireConstructor => | ||
RustLibWire.fromExternalLibrary; | ||
|
||
@override | ||
ExternalLibraryLoaderConfig get defaultExternalLibraryLoaderConfig => | ||
const ExternalLibraryLoaderConfig( | ||
stem: 'frb_example_dart_minimal', | ||
ioDirectory: 'rust/target/release/', | ||
webPrefix: 'pkg/', | ||
); | ||
} | ||
|
||
abstract class RustLibApi extends BaseApi { | ||
Future<int> minimalAdder({required int a, required int b, dynamic hint}); | ||
} | ||
|
||
class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { | ||
RustLibApiImpl({ | ||
super.handler, | ||
required super.wire, | ||
required super.generalizedFrbRustBinding, | ||
required super.dropPortManager, | ||
}); | ||
|
||
@override | ||
Future<int> minimalAdder({required int a, required int b, dynamic hint}) { | ||
var arg0 = api2wire_i_32(a); | ||
var arg1 = api2wire_i_32(b); | ||
return handler.executeNormal(NormalTask( | ||
callFfi: (port_) => wire.wire_minimal_adder(port_, arg0, arg1), | ||
parseSuccessData: _wire2api_i_32, | ||
parseErrorData: null, | ||
constMeta: kMinimalAdderConstMeta, | ||
argValues: [a, b], | ||
apiImpl: this, | ||
hint: hint, | ||
)); | ||
} | ||
|
||
TaskConstMeta get kMinimalAdderConstMeta => const TaskConstMeta( | ||
debugName: "minimal_adder", | ||
argNames: ["a", "b"], | ||
); | ||
|
||
int _wire2api_i_32(dynamic raw) { | ||
return raw as int; | ||
} | ||
} | ||
|
||
// Section: api2wire_funcs | ||
|
||
int api2wire_i_32(int raw) { | ||
return raw; | ||
} |
74 changes: 74 additions & 0 deletions
74
frb_example/deliberate_bad/lib/src/rust/frb_generated.io.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// ignore_for_file: unused_import, unused_element, duplicate_ignore | ||
|
||
import 'api/minimal.dart'; | ||
import 'dart:async'; | ||
import 'dart:convert'; | ||
import 'dart:ffi' as ffi; | ||
import 'frb_generated.dart'; | ||
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated_io.dart'; | ||
|
||
abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> { | ||
RustLibApiImplPlatform({ | ||
super.handler, | ||
required super.wire, | ||
required super.generalizedFrbRustBinding, | ||
required super.dropPortManager, | ||
}); | ||
} | ||
|
||
// Section: wire_class | ||
|
||
// 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 RustLibWire implements BaseWire { | ||
factory RustLibWire.fromExternalLibrary(ExternalLibrary lib) => | ||
RustLibWire(lib.ffiDynamicLibrary); | ||
|
||
/// Holds the symbol lookup function. | ||
final ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName) | ||
_lookup; | ||
|
||
/// The symbols are looked up in [dynamicLibrary]. | ||
RustLibWire(ffi.DynamicLibrary dynamicLibrary) | ||
: _lookup = dynamicLibrary.lookup; | ||
|
||
/// The symbols are looked up with [lookup]. | ||
RustLibWire.fromLookup( | ||
ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName) | ||
lookup) | ||
: _lookup = lookup; | ||
|
||
void wire_minimal_adder( | ||
int port_, | ||
int a, | ||
int b, | ||
) { | ||
return _wire_minimal_adder( | ||
port_, | ||
a, | ||
b, | ||
); | ||
} | ||
|
||
late final _wire_minimal_adderPtr = _lookup< | ||
ffi | ||
.NativeFunction<ffi.Void Function(ffi.Int64, ffi.Int32, ffi.Int32)>>( | ||
'wire_minimal_adder'); | ||
late final _wire_minimal_adder = | ||
_wire_minimal_adderPtr.asFunction<void Function(int, int, int)>(); | ||
|
||
int dummy_method_to_enforce_bundling() { | ||
return _dummy_method_to_enforce_bundling(); | ||
} | ||
|
||
late final _dummy_method_to_enforce_bundlingPtr = | ||
_lookup<ffi.NativeFunction<ffi.Int64 Function()>>( | ||
'dummy_method_to_enforce_bundling'); | ||
late final _dummy_method_to_enforce_bundling = | ||
_dummy_method_to_enforce_bundlingPtr.asFunction<int Function()>(); | ||
} |
40 changes: 40 additions & 0 deletions
40
frb_example/deliberate_bad/lib/src/rust/frb_generated.web.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// ignore_for_file: unused_import, unused_element, duplicate_ignore | ||
|
||
import 'api/minimal.dart'; | ||
import 'dart:async'; | ||
import 'dart:convert'; | ||
import 'frb_generated.dart'; | ||
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated_web.dart'; | ||
|
||
abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> { | ||
RustLibApiImplPlatform({ | ||
super.handler, | ||
required super.wire, | ||
required super.generalizedFrbRustBinding, | ||
required super.dropPortManager, | ||
}); | ||
} | ||
|
||
// Section: wire_class | ||
|
||
class RustLibWire extends BaseWire { | ||
// TODO | ||
// : super(WasmModule.cast<RustLibWasmModule>(lib.wasmModule)); | ||
RustLibWire.fromExternalLibrary(ExternalLibrary lib) {} | ||
|
||
void wire_minimal_adder(NativePortType port_, int a, int b) => | ||
wasmModule.wire_minimal_adder(port_, a, b); | ||
} | ||
|
||
@JS('wasm_bindgen') | ||
external RustLibWasmModule get wasmModule; | ||
|
||
@JS() | ||
@anonymous | ||
class RustLibWasmModule implements WasmModule { | ||
external Object /* Promise */ call([String? moduleName]); | ||
|
||
external RustLibWasmModule bind(dynamic thisArg, String moduleName); | ||
|
||
external void wire_minimal_adder(NativePortType port_, int a, int b); | ||
} |
Oops, something went wrong.