Skip to content

Commit

Permalink
Merge branch 'main' into addLinkingScript
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Jan 16, 2024
2 parents 9d6c1fb + f38afa2 commit 3edfc66
Show file tree
Hide file tree
Showing 140 changed files with 7,673 additions and 496 deletions.
21 changes: 14 additions & 7 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
# Configuration for .github/workflows/pull_request_label.yml.

'type-infra':
- '.github/**'
- changed-files:
- any-glob-to-any-file: '.github/**'

'package:ffigen':
- 'pkgs/ffigen/**'
- changed-files:
- any-glob-to-any-file: 'pkgs/ffigen/**'

'package:jnigen':
- 'pkgs/jnigen/**'
- changed-files:
- any-glob-to-any-file: 'pkgs/jnigen/**'

'package:jni':
- 'pkgs/jni/**'
- changed-files:
- any-glob-to-any-file: 'pkgs/jni/**'

'package:native_assets_builder':
- 'pkgs/native_assets_builder/**'
- changed-files:
- any-glob-to-any-file: 'pkgs/native_assets_builder/**'

'package:native_assets_cli':
- 'pkgs/native_assets_cli/**'
- changed-files:
- any-glob-to-any-file: 'pkgs/native_assets_cli/**'

'package:native_toolchain_c':
- 'pkgs/native_toolchain_c/**'
- changed-files:
- any-glob-to-any-file: 'pkgs/native_toolchain_c/**'
9 changes: 5 additions & 4 deletions .github/workflows/ffigen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ jobs:
strategy:
fail-fast: false
matrix:
sdk: [3.2.0]
sdk: [dev]
# sdk: [3.3.0]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
Expand Down Expand Up @@ -56,7 +57,7 @@ jobs:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
with:
sdk: 3.2.0
sdk: dev #3.3.0
- name: Install dependencies
run: dart pub get
- name: Install libclang-14-dev
Expand All @@ -77,7 +78,7 @@ jobs:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
with:
sdk: 3.2.0
sdk: dev #3.3.0
- name: Install dependencies
run: dart pub get
- name: Build test dylib and bindings
Expand Down Expand Up @@ -110,7 +111,7 @@ jobs:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
with:
sdk: 3.2.0
sdk: dev #3.3.0
- name: Install dependencies
run: dart pub get
- name: Build test dylib and bindings
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ffigen_weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
with:
sdk: 3.2.0
sdk: dev #3.3.0
- name: Install dependencies
run: dart pub get
- name: Build test dylib and bindings
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/health.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ jobs:
uses: dart-lang/ecosystem/.github/workflows/health.yaml@main
with:
coverage_web: false
checks: "version,changelog,license,coverage,do-not-submit,breaking"
checks: "version,changelog,license,do-not-submit,breaking,coverage"
use-flutter: true
sdk: master
permissions:
pull-requests: write
9 changes: 9 additions & 0 deletions .github/workflows/native.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ jobs:
ndk-version: r26b
if: ${{ matrix.sdk == 'stable' }}

- run: dart run ../../tools/check_pubspec_overrides.dart

- run: dart run ../../tools/delete_pubspec_overrides.dart
if: ${{ matrix.dependencies == 'published' }}

Expand Down Expand Up @@ -93,6 +95,9 @@ jobs:
- run: dart pub get -C example/native_add_library/
if: ${{ matrix.package == 'native_assets_cli' }}

- run: dart pub get -C example/use_dart_api/
if: ${{ matrix.package == 'native_assets_cli' }}

- run: dart analyze --fatal-infos
# Run on dev to ensure we're not depending on deprecated SDK things.

Expand Down Expand Up @@ -122,6 +127,10 @@ jobs:
working-directory: pkgs/${{ matrix.package }}/example/native_add_app/bin/native_add_app/
if: ${{ matrix.package == 'native_assets_cli' && matrix.sdk == 'dev' && !matrix.breaking-change }}

- run: dart --enable-experiment=native-assets test
working-directory: pkgs/${{ matrix.package }}/example/use_dart_api/
if: ${{ matrix.package == 'native_assets_cli' && matrix.sdk == 'dev' && !matrix.breaking-change }}

- name: Install coverage
run: dart pub global activate coverage
if: ${{ matrix.sdk == 'stable' && matrix.dependencies == 'published' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/no-response.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'dart-lang' }}
steps:
- uses: actions/stale@1160a2240286f5da8ec72b1c0816ce2481aabf84
- uses: actions/stale@28ca1036281a5e5922ead5184a1bbf96e5fc984e
with:
# Don't automatically mark inactive issues+PRs as stale.
days-before-stale: -1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
pull-requests: write # Required for writing the pull request note
with:
write-comments: false
sdk: beta
sdk: dev # use beta/stable after 3.3.0
2 changes: 1 addition & 1 deletion .github/workflows/pull_request_label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@ac9175f8a1f3625fd0d4fb234536d26811351594
- uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
sync-labels: true
10 changes: 9 additions & 1 deletion pkgs/ffigen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
## 11.0.0-wip
## 12.0.0-wip

- Global variables are now compatible with the `ffi-native` option.
- Exposing symbol addresses of functions and globals is now compatible with the
`ffi-native` option.

## 11.0.0

- Any compiler errors/warnings in source header files will now result in
bindings to **not** be generated by default, since it may result in invalid
bindings if the compiler makes a wrong guess. A flag `--ignore-source-errors` (or yaml config `ignore-source-errors: true`)
must be passed to change this behaviour.
- __Breaking change__: Stop generating setters for global variables marked `const` in C.
- Fix objc_msgSend being used on arm64 platforms where it's not available.
- Fix missing comma with `ffi-native` functions marked `leaf`.
- Add support for finding libclang in Conda environment.

## 10.0.0

Expand Down
12 changes: 12 additions & 0 deletions pkgs/ffigen/example/ffinative/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,16 @@ headers:
entry-points:
- 'headers/example.h'
preamble: |
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// ignore_for_file: deprecated_member_use
functions:
symbol-address:
include:
- sum
globals:
symbol-address:
include:
- library_version
7 changes: 7 additions & 0 deletions pkgs/ffigen/example/ffinative/headers/example.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ float *divide(int a, int b);

/** Divides 2 floats, returns a pointer to double. */
double *dividePrecision(float a, float b);

int log_level = -1;

const int array[5] = {0, 1, 2, 3, 4};

/** Version of the native C library */
const char* const library_version = "1.0.0-native";
48 changes: 34 additions & 14 deletions pkgs/ffigen/example/ffinative/lib/generated_bindings.dart
Original file line number Diff line number Diff line change
@@ -1,51 +1,71 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// ignore_for_file: deprecated_member_use

// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
// ignore_for_file: type=lint
@ffi.DefaultAsset('package:ffinative_example/generated_bindings.dart')
library;

import 'dart:ffi' as ffi;
import '' as self;

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

/// Subtracts 2 integers.
@ffi.Native<ffi.Int Function(ffi.Int, ffi.Int)>(
symbol: 'subtract',
assetId: 'package:ffinative_example/generated_bindings.dart')
@ffi.Native<ffi.Int Function(ffi.Int, ffi.Int)>()
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',
assetId: 'package:ffinative_example/generated_bindings.dart')
@ffi.Native<ffi.Pointer<ffi.Int> Function(ffi.Int, ffi.Int)>()
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',
assetId: 'package:ffinative_example/generated_bindings.dart')
@ffi.Native<ffi.Pointer<ffi.Float> Function(ffi.Int, ffi.Int)>()
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',
assetId: 'package:ffinative_example/generated_bindings.dart')
@ffi.Native<ffi.Pointer<ffi.Double> Function(ffi.Float, ffi.Float)>()
external ffi.Pointer<ffi.Double> dividePrecision(
double a,
double b,
);

@ffi.Native<ffi.Int>()
external int log_level;

@ffi.Array.multi([5])
@ffi.Native<ffi.Array<ffi.Int>>()
external ffi.Array<ffi.Int> array;

/// Version of the native C library
@ffi.Native<ffi.Pointer<ffi.Char>>()
external final ffi.Pointer<ffi.Char> library_version;

const addresses = _SymbolAddresses();

class _SymbolAddresses {
const _SymbolAddresses();
ffi.Pointer<ffi.NativeFunction<ffi.Int Function(ffi.Int, ffi.Int)>> get sum =>
ffi.Native.addressOf(self.sum);
ffi.Pointer<ffi.Pointer<ffi.Char>> get library_version =>
ffi.Native.addressOf(self.library_version);
}
2 changes: 1 addition & 1 deletion pkgs/ffigen/example/ffinative/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
name: ffinative_example

environment:
sdk: '>=3.2.0 <4.0.0'
sdk: '>=3.3.0-252.0.dev <4.0.0'

dependencies:
ffi: ^2.0.1
Expand Down
15 changes: 2 additions & 13 deletions pkgs/ffigen/lib/src/code_generator/compound.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,6 @@ abstract class Compound extends BindingType {
}
}

List<int> _getArrayDimensionLengths(Type type) {
final array = <int>[];
var startType = type;
while (startType is ConstantArray) {
array.add(startType.length);
startType = startType.child;
}
return array;
}

String _getInlineArrayTypeString(Type type, Writer w) {
if (type is ConstantArray) {
return '${w.ffiLibraryPrefix}.Array<'
Expand Down Expand Up @@ -132,9 +122,8 @@ abstract class Compound extends BindingType {
s.writeAll(m.dartDoc!.split('\n'), '\n$depth/// ');
s.write('\n');
}
if (m.type is ConstantArray) {
s.write('$depth@${w.ffiLibraryPrefix}.Array.multi(');
s.write('${_getArrayDimensionLengths(m.type)})\n');
if (m.type case final ConstantArray arrayType) {
s.writeln(makeArrayAnnotation(w, arrayType));
s.write('${depth}external ${_getInlineArrayTypeString(m.type, w)} ');
s.write('${m.name};\n\n');
} else {
Expand Down
22 changes: 17 additions & 5 deletions pkgs/ffigen/lib/src/code_generator/func.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ class Func extends LookUpBinding {
functionType.getFfiDartType(w, writeArgumentNames: false);
final needsWrapper = !functionType.sameDartAndFfiDartType && !isInternal;

final isLeafString = isLeaf ? 'isLeaf:true' : '';
final funcVarName = w.wrapperLevelUniqueNamer.makeUnique('_$name');
final ffiReturnType = functionType.returnType.getFfiDartType(w);
final ffiArgDeclString = functionType.dartTypeParameters
Expand Down Expand Up @@ -146,12 +145,15 @@ class Func extends LookUpBinding {
}

if (ffiNativeConfig.enabled) {
final assetString = ffiNativeConfig.assetId != null
? ", assetId: '${ffiNativeConfig.assetId}'"
: '';
final nativeFuncName = needsWrapper ? funcVarName : enclosingFuncName;
s.write('''
@${w.ffiLibraryPrefix}.Native<$cType>(symbol: '$originalName'$assetString$isLeafString)
${makeNativeAnnotation(
w,
nativeType: cType,
dartName: nativeFuncName,
nativeSymbolName: originalName,
isLeaf: isLeaf,
)}
external $ffiReturnType $nativeFuncName($ffiArgDeclString);
''');
Expand All @@ -164,8 +166,18 @@ $dartReturnType $enclosingFuncName($libArg$dartArgDeclString) => $funcImplCall;
''');
}

if (exposeSymbolAddress) {
// Add to SymbolAddress in writer.
w.symbolAddressWriter.addNativeSymbol(
type:
'${w.ffiLibraryPrefix}.Pointer<${w.ffiLibraryPrefix}.NativeFunction<$cType>>',
name: name,
);
}
} else {
funcPointerName = w.wrapperLevelUniqueNamer.makeUnique('_${name}Ptr');
final isLeafString = isLeaf ? 'isLeaf:true' : '';

// Write enclosing function.
s.write('''
Expand Down
Loading

0 comments on commit 3edfc66

Please sign in to comment.