Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
tpict committed Oct 3, 2023
1 parent e9fd107 commit f38615a
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ jobs:
run: cargo build -r

# Dart/Flutter
- name: Check Dart format
run: melos run check-format --no-select
- name: Dart code analysis
run: melos run analyze --no-select
- name: Run Dart tests
run: melos run test
# TODO: ignore generated files
# - name: Check Dart format
# run: melos run check-format --no-select
# - name: Dart code analysis
# run: melos run analyze --no-select
# - name: Run Dart tests
# run: melos run test

macos_integration_test:
runs-on: macos-latest
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Test
# Test2
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ const weights = [

void main() {
test('test', () async {
final SavGol = createLib();
print(await SavGol.savgolFilter(
final api = createLib();
await api.savgolFilter(
x: Float64List.fromList(weights),
windowLength: 11,
polyOrder: 2,
derivative: 1));
derivative: 1);
});
}
4 changes: 2 additions & 2 deletions packages/flutter_savgol/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.2+3"
version: "0.0.1"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -303,7 +303,7 @@ packages:
path: "../../savgol"
relative: true
source: path
version: "1.1.0"
version: "0.1.0"
shelf:
dependency: transitive
description:
Expand Down
1 change: 0 additions & 1 deletion packages/flutter_savgol/lib/flutter_savgol.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ final DynamicLibrary _dylib = () {
/// The bindings to the native functions in [_dylib].
final FlutterSavgolBindings _bindings = FlutterSavgolBindings(_dylib);


/// A request to compute `sum`.
///
/// Typically sent from one isolate to another.
Expand Down
43 changes: 24 additions & 19 deletions packages/savgol/lib/src/bridge_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,54 @@ import 'dart:async';
import 'package:meta/meta.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge.dart';
import 'package:uuid/uuid.dart';
import 'bridge_generated.io.dart' if (dart.library.html) 'bridge_generated.web.dart';
import 'bridge_generated.io.dart'
if (dart.library.html) 'bridge_generated.web.dart';

abstract class Savgol {
Future<Float64List> savgolFilter({required Float64List x, required int windowLength, required int polyOrder, required int derivative, dynamic hint});
Future<Float64List> savgolFilter(
{required Float64List x,
required int windowLength,
required int polyOrder,
required int derivative,
dynamic hint});

FlutterRustBridgeTaskConstMeta get kSavgolFilterConstMeta;
}

class SavgolImpl implements Savgol {
final SavgolPlatform _platform;
factory SavgolImpl(ExternalLibrary dylib) => SavgolImpl.raw(SavgolPlatform(dylib));
factory SavgolImpl(ExternalLibrary dylib) =>
SavgolImpl.raw(SavgolPlatform(dylib));

/// Only valid on web/WASM platforms.
factory SavgolImpl.wasm(FutureOr<WasmModule> module) => SavgolImpl(module as ExternalLibrary);
factory SavgolImpl.wasm(FutureOr<WasmModule> module) =>
SavgolImpl(module as ExternalLibrary);
SavgolImpl.raw(this._platform);
Future<Float64List> savgolFilter({required Float64List x, required int windowLength, required int polyOrder, required int derivative, dynamic hint}) {
Future<Float64List> savgolFilter(
{required Float64List x,
required int windowLength,
required int polyOrder,
required int derivative,
dynamic hint}) {
var arg0 = _platform.api2wire_float_64_list(x);
var arg1 = api2wire_usize(windowLength);
var arg2 = api2wire_usize(polyOrder);
var arg3 = api2wire_usize(derivative);
return _platform.executeNormal(FlutterRustBridgeTask(
callFfi: (port_) => _platform.inner.wire_savgol_filter(port_, arg0, arg1, arg2, arg3),
callFfi: (port_) =>
_platform.inner.wire_savgol_filter(port_, arg0, arg1, arg2, arg3),
parseSuccessData: _wire2api_float_64_list,
parseErrorData: _wire2api_String,
constMeta: kSavgolFilterConstMeta,
argValues: [
x,
windowLength,
polyOrder,
derivative
],
argValues: [x, windowLength, polyOrder, derivative],
hint: hint,
));
}

FlutterRustBridgeTaskConstMeta get kSavgolFilterConstMeta => const FlutterRustBridgeTaskConstMeta(
FlutterRustBridgeTaskConstMeta get kSavgolFilterConstMeta =>
const FlutterRustBridgeTaskConstMeta(
debugName: "savgol_filter",
argNames: [
"x",
"windowLength",
"polyOrder",
"derivative"
],
argNames: ["x", "windowLength", "polyOrder", "derivative"],
);

void dispose() {
Expand Down
73 changes: 53 additions & 20 deletions packages/savgol/lib/src/bridge_generated.io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@ class SavgolWire implements FlutterRustBridgeWireBase {
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;
final ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
_lookup;

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

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

void store_dart_post_cobject(
DartPostCObjectFnType ptr,
Expand All @@ -57,8 +62,11 @@ class SavgolWire implements FlutterRustBridgeWireBase {
);
}

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)>();
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,
Expand All @@ -68,8 +76,11 @@ class SavgolWire implements FlutterRustBridgeWireBase {
);
}

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)>();
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,
Expand All @@ -79,8 +90,11 @@ class SavgolWire implements FlutterRustBridgeWireBase {
);
}

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)>();
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,
Expand All @@ -90,8 +104,11 @@ class SavgolWire implements FlutterRustBridgeWireBase {
);
}

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)>();
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,
Expand All @@ -101,8 +118,11 @@ class SavgolWire implements FlutterRustBridgeWireBase {
);
}

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>)>();
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_savgol_filter(
int port_,
Expand All @@ -120,8 +140,12 @@ class SavgolWire implements FlutterRustBridgeWireBase {
);
}

late final _wire_savgol_filterPtr = _lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int64, ffi.Pointer<wire_float_64_list>, ffi.UintPtr, ffi.UintPtr, ffi.UintPtr)>>('wire_savgol_filter');
late final _wire_savgol_filter = _wire_savgol_filterPtr.asFunction<void Function(int, ffi.Pointer<wire_float_64_list>, int, int, int)>();
late final _wire_savgol_filterPtr = _lookup<
ffi.NativeFunction<
ffi.Void Function(ffi.Int64, ffi.Pointer<wire_float_64_list>,
ffi.UintPtr, ffi.UintPtr, ffi.UintPtr)>>('wire_savgol_filter');
late final _wire_savgol_filter = _wire_savgol_filterPtr.asFunction<
void Function(int, ffi.Pointer<wire_float_64_list>, int, int, int)>();

ffi.Pointer<wire_float_64_list> new_float_64_list_0(
int len,
Expand All @@ -131,8 +155,12 @@ class SavgolWire implements FlutterRustBridgeWireBase {
);
}

late final _new_float_64_list_0Ptr = _lookup<ffi.NativeFunction<ffi.Pointer<wire_float_64_list> Function(ffi.Int32)>>('new_float_64_list_0');
late final _new_float_64_list_0 = _new_float_64_list_0Ptr.asFunction<ffi.Pointer<wire_float_64_list> Function(int)>();
late final _new_float_64_list_0Ptr = _lookup<
ffi.NativeFunction<
ffi.Pointer<wire_float_64_list> Function(
ffi.Int32)>>('new_float_64_list_0');
late final _new_float_64_list_0 = _new_float_64_list_0Ptr
.asFunction<ffi.Pointer<wire_float_64_list> Function(int)>();

void free_WireSyncReturn(
WireSyncReturn ptr,
Expand All @@ -142,8 +170,11 @@ class SavgolWire implements FlutterRustBridgeWireBase {
);
}

late final _free_WireSyncReturnPtr = _lookup<ffi.NativeFunction<ffi.Void Function(WireSyncReturn)>>('free_WireSyncReturn');
late final _free_WireSyncReturn = _free_WireSyncReturnPtr.asFunction<void Function(WireSyncReturn)>();
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 {}
Expand All @@ -155,5 +186,7 @@ final class wire_float_64_list extends ffi.Struct {
external int len;
}

typedef DartPostCObjectFnType = ffi.Pointer<ffi.NativeFunction<ffi.Bool Function(DartPort port_id, ffi.Pointer<ffi.Void> message)>>;
typedef DartPostCObjectFnType = ffi.Pointer<
ffi.NativeFunction<
ffi.Bool Function(DartPort port_id, ffi.Pointer<ffi.Void> message)>>;
typedef DartPort = ffi.Int64;
14 changes: 10 additions & 4 deletions packages/savgol/lib/src/bridge_generated.web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import 'package:uuid/uuid.dart';
import 'bridge_generated.dart';
export 'bridge_generated.dart';

class SavgolPlatform extends FlutterRustBridgeBase<SavgolWire> with FlutterRustBridgeSetupMixin {
class SavgolPlatform extends FlutterRustBridgeBase<SavgolWire>
with FlutterRustBridgeSetupMixin {
SavgolPlatform(FutureOr<WasmModule> dylib) : super(SavgolWire(dylib)) {
setupMixinConstructor();
}
Expand All @@ -36,13 +37,18 @@ external SavgolWasmModule get wasmModule;
class SavgolWasmModule implements WasmModule {
external Object /* Promise */ call([String? moduleName]);
external SavgolWasmModule bind(dynamic thisArg, String moduleName);
external dynamic /* void */ wire_savgol_filter(NativePortType port_, Float64List x, int window_length, int poly_order, int derivative);
external dynamic /* void */ wire_savgol_filter(NativePortType port_,
Float64List x, int window_length, int poly_order, int derivative);
}

// Section: WASM wire connector

class SavgolWire extends FlutterRustBridgeWasmWireBase<SavgolWasmModule> {
SavgolWire(FutureOr<WasmModule> module) : super(WasmModule.cast<SavgolWasmModule>(module));
SavgolWire(FutureOr<WasmModule> module)
: super(WasmModule.cast<SavgolWasmModule>(module));

void wire_savgol_filter(NativePortType port_, Float64List x, int window_length, int poly_order, int derivative) => wasmModule.wire_savgol_filter(port_, x, window_length, poly_order, derivative);
void wire_savgol_filter(NativePortType port_, Float64List x,
int window_length, int poly_order, int derivative) =>
wasmModule.wire_savgol_filter(
port_, x, window_length, poly_order, derivative);
}
3 changes: 1 addition & 2 deletions packages/savgol/lib/src/ffi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ Savgol createWrapper(ExternalLibrary lib) {
return _wrapper!;
}

Savgol createLib() =>
createWrapper(createLibraryImpl());
Savgol createLib() => createWrapper(createLibraryImpl());
3 changes: 1 addition & 2 deletions packages/savgol/lib/src/ffi/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import 'package:savgol/src/bridge_generated.dart';

typedef ExternalLibrary = DynamicLibrary;

Savgol createWrapperImpl(ExternalLibrary dylib) =>
SavgolImpl(dylib);
Savgol createWrapperImpl(ExternalLibrary dylib) => SavgolImpl(dylib);

DynamicLibrary createLibraryImpl() {
const base = 'savgol';
Expand Down
3 changes: 1 addition & 2 deletions packages/savgol/lib/src/ffi/stub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:savgol/src/bridge_generated.dart';
/// Will be a DynamicLibrary for dart:io or WasmModule for dart:html
typedef ExternalLibrary = Object;

Savgol createWrapperImpl(ExternalLibrary lib) =>
throw UnimplementedError();
Savgol createWrapperImpl(ExternalLibrary lib) => throw UnimplementedError();

Object createLibraryImpl() => throw UnimplementedError();
3 changes: 1 addition & 2 deletions packages/savgol/lib/src/ffi/web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import 'package:flutter_rust_bridge/flutter_rust_bridge.dart';

typedef ExternalLibrary = WasmModule;

Savgol createWrapperImpl(ExternalLibrary module) =>
SavgolImpl.wasm(module);
Savgol createWrapperImpl(ExternalLibrary module) => SavgolImpl.wasm(module);

WasmModule createLibraryImpl() {
// TODO add web support. See:
Expand Down
11 changes: 5 additions & 6 deletions packages/savgol/native/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ pub fn savgol_filter(
poly_order: usize,
derivative: usize,
) -> Result<Vec<f64>, String> {
return lib_savgol_filter(&SavGolInput {
lib_savgol_filter(&SavGolInput {
data: &x,
window_length: window_length,
poly_order: poly_order,
derivative: derivative,
});
window_length,
poly_order,
derivative,
})
}

2 changes: 1 addition & 1 deletion packages/savgol/native/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mod bridge_generated; /* AUTO INJECTED BY flutter_rust_bridge. This line may not be accurate, and you can change it according to your needs. */
mod api;
mod bridge_generated; /* AUTO INJECTED BY flutter_rust_bridge. This line may not be accurate, and you can change it according to your needs. */

0 comments on commit f38615a

Please sign in to comment.