Skip to content

Commit

Permalink
chore: empty package deliberate_bad
Browse files Browse the repository at this point in the history
  • Loading branch information
fzyzcjy committed Dec 1, 2023
1 parent 7468186 commit 3158816
Show file tree
Hide file tree
Showing 23 changed files with 1,800 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exclude = [
# For example, the `target` directory is different with and without workspaces.
"frb_example/dart_minimal/rust",
"frb_example/pure_dart/rust",
"frb_example/deliberate_bad/rust",
"frb_example/flutter_via_create/rust",
"frb_example/flutter_via_integrate/rust",
]
Expand Down
5 changes: 5 additions & 0 deletions frb_example/deliberate_bad/.flutter_rust_bridge.yaml
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
44 changes: 44 additions & 0 deletions frb_example/deliberate_bad/.gitignore
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
3 changes: 3 additions & 0 deletions frb_example/deliberate_bad/analysis_options.yaml
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
3 changes: 3 additions & 0 deletions frb_example/deliberate_bad/build.dart
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);
16 changes: 16 additions & 0 deletions frb_example/deliberate_bad/frb_generated.h
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;
}
7 changes: 7 additions & 0 deletions frb_example/deliberate_bad/lib/src/rust/api/minimal.dart
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 frb_example/deliberate_bad/lib/src/rust/frb_generated.dart
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 frb_example/deliberate_bad/lib/src/rust/frb_generated.io.dart
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 frb_example/deliberate_bad/lib/src/rust/frb_generated.web.dart
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);
}
Loading

0 comments on commit 3158816

Please sign in to comment.