Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into objcstaticfunc
Browse files Browse the repository at this point in the history
  • Loading branch information
liamappelbe committed Nov 1, 2023
2 parents 610d1dc + 2402531 commit 363acd1
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 26 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
# TODO: Change to 3.2.0 stable once it's released.
sdk: [3.2.0-114.0.dev]
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
- uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
with:
sdk: ${{ matrix.sdk }}
- id: install
Expand All @@ -42,8 +42,8 @@ jobs:
needs: analyze
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
- uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
with:
sdk: 3.2.0-114.0.dev
- name: Install dependencies
Expand All @@ -59,8 +59,8 @@ jobs:
needs: analyze
runs-on: macos-latest
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
- uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
with:
sdk: 3.2.0-114.0.dev
- name: Install dependencies
Expand All @@ -81,8 +81,8 @@ jobs:
needs: analyze
runs-on: windows-latest
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
- uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
with:
sdk: 3.2.0-114.0.dev
- name: Install dependencies
Expand All @@ -106,8 +106,8 @@ jobs:
needs: analyze
runs-on: windows-latest
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
- uses: subosito/flutter-action@48cafc24713cca54bbe03cdc3a423187d413aafa
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: subosito/flutter-action@2783a3f08e1baf891508463f8c6653c258246225
with:
channel: "master"
- name: Install dependencies
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Use Dart wrapper types in args and returns of ObjCBlocks.
- Use Dart wrapper types in args and returns of static functions.
- Bump min SDK version to 3.2.0-114.0.dev.
- Renamed `asset` to `assetId` for `ffi-native`.

# 9.0.1

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ type-map:

```yaml
ffi-native:
asset: 'myasset' # Optional.
assetId: 'myasset' # Optional.
```
</td>
</tr>
Expand Down
4 changes: 2 additions & 2 deletions example/ffinative/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

name: NativeLibrary
ffi-native:
# asset: 'assetname' # (optional)
assetId: 'package:ffinative_example/generated_bindings.dart' # (optional)
description: Bindings to `headers/example.h`.
output: 'generated_bindings.dart'
output: 'lib/generated_bindings.dart'
headers:
entry-points:
- 'headers/example.h'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,44 @@
import 'dart:ffi' as ffi;

/// Adds 2 integers.
@ffi.Native<ffi.Int Function(ffi.Int, ffi.Int)>(symbol: 'sum')
@ffi.Native<ffi.Int Function(ffi.Int, ffi.Int)>(
symbol: 'sum', assetId: 'package:ffinative_example/generated_bindings.dart')
external int sum(
int a,
int b,
);

/// Subtracts 2 integers.
@ffi.Native<ffi.Int Function(ffi.Int, ffi.Int)>(symbol: 'subtract')
@ffi.Native<ffi.Int Function(ffi.Int, ffi.Int)>(
symbol: 'subtract',
assetId: 'package:ffinative_example/generated_bindings.dart')
external int subtract(
int a,
int b,
);

/// Multiplies 2 integers, returns pointer to an integer,.
@ffi.Native<ffi.Pointer<ffi.Int> Function(ffi.Int, ffi.Int)>(symbol: 'multiply')
@ffi.Native<ffi.Pointer<ffi.Int> Function(ffi.Int, ffi.Int)>(
symbol: 'multiply',
assetId: 'package:ffinative_example/generated_bindings.dart')
external ffi.Pointer<ffi.Int> multiply(
int a,
int b,
);

/// Divides 2 integers, returns pointer to a float.
@ffi.Native<ffi.Pointer<ffi.Float> Function(ffi.Int, ffi.Int)>(symbol: 'divide')
@ffi.Native<ffi.Pointer<ffi.Float> Function(ffi.Int, ffi.Int)>(
symbol: 'divide',
assetId: 'package:ffinative_example/generated_bindings.dart')
external ffi.Pointer<ffi.Float> divide(
int a,
int b,
);

/// Divides 2 floats, returns a pointer to double.
@ffi.Native<ffi.Pointer<ffi.Double> Function(ffi.Float, ffi.Float)>(
symbol: 'dividePrecision')
symbol: 'dividePrecision',
assetId: 'package:ffinative_example/generated_bindings.dart')
external ffi.Pointer<ffi.Double> dividePrecision(
double a,
double b,
Expand Down
4 changes: 2 additions & 2 deletions ffigen.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,12 @@
"type": "object",
"additionalProperties": false,
"properties": {
"asset": {
"assetId": {
"type": "string"
}
},
"required": [
"asset"
"assetId"
]
}
]
Expand Down
4 changes: 2 additions & 2 deletions lib/src/code_generator/func.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ class Func extends LookUpBinding {
}

if (ffiNativeConfig.enabled) {
final assetString = ffiNativeConfig.asset != null
? ", asset: '${ffiNativeConfig.asset}'"
final assetString = ffiNativeConfig.assetId != null
? ", assetId: '${ffiNativeConfig.assetId}'"
: '';
final nativeFuncName = needsWrapper ? funcVarName : enclosingFuncName;
s.write('''
Expand Down
4 changes: 2 additions & 2 deletions lib/src/config_provider/config_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,9 @@ class ObjCModulePrefixer {

class FfiNativeConfig {
final bool enabled;
final String? asset;
final String? assetId;

const FfiNativeConfig({required this.enabled, this.asset});
const FfiNativeConfig({required this.enabled, this.assetId});
}

class SymbolFile {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/config_provider/spec_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,6 @@ FfiNativeConfig ffiNativeExtractor(dynamic yamlConfig) {
final yamlMap = yamlConfig as Map?;
return FfiNativeConfig(
enabled: true,
asset: yamlMap?[strings.ffiNativeAsset] as String?,
assetId: yamlMap?[strings.ffiNativeAsset] as String?,
);
}
2 changes: 1 addition & 1 deletion lib/src/strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ const doubleNaN = 'double.nan';
const dartHandleUsr = 'c:@S@_Dart_Handle';

const ffiNative = 'ffi-native';
const ffiNativeAsset = 'asset';
const ffiNativeAsset = 'assetId';

Directory? _tmpDir;

Expand Down
2 changes: 2 additions & 0 deletions test/native_test/native_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void main() {
rethrow;
}
});

test('bool', () {
expect(bindings.Function1Bool(true), false);
expect(bindings.Function1Bool(false), true);
Expand Down Expand Up @@ -112,6 +113,7 @@ void main() {
}
}
});

test('Array Workaround: Range Errors', () {
final struct1 = bindings.getStruct1();
// Index (get) above range.
Expand Down

0 comments on commit 363acd1

Please sign in to comment.