From ddb0a4a81459387c0af585e78612c5f42e3776fb Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Wed, 13 Dec 2023 15:05:47 +0100 Subject: [PATCH 01/21] Implement native fields and addressOf --- pkgs/ffigen/example/ffinative/config.yaml | 8 +++ .../example/ffinative/headers/example.h | 3 + .../ffinative/lib/generated_bindings.dart | 13 ++++ pkgs/ffigen/lib/src/code_generator/func.dart | 9 +++ .../ffigen/lib/src/code_generator/global.dart | 67 +++++++++++++------ .../lib/src/code_generator/library.dart | 36 +++------- .../ffigen/lib/src/code_generator/writer.dart | 62 +++++++++++++---- .../header_parser/sub_parsers/var_parser.dart | 10 +-- 8 files changed, 142 insertions(+), 66 deletions(-) diff --git a/pkgs/ffigen/example/ffinative/config.yaml b/pkgs/ffigen/example/ffinative/config.yaml index 1bb3dac0c4..f24eb25c51 100644 --- a/pkgs/ffigen/example/ffinative/config.yaml +++ b/pkgs/ffigen/example/ffinative/config.yaml @@ -10,3 +10,11 @@ headers: - 'headers/example.h' preamble: | // ignore_for_file: deprecated_member_use +functions: + symbol-address: + include: + - sum +globals: + symbol-address: + include: + - library_version diff --git a/pkgs/ffigen/example/ffinative/headers/example.h b/pkgs/ffigen/example/ffinative/headers/example.h index 44056dd7da..38a309174b 100644 --- a/pkgs/ffigen/example/ffinative/headers/example.h +++ b/pkgs/ffigen/example/ffinative/headers/example.h @@ -16,3 +16,6 @@ float *divide(int a, int b); /** Divides 2 floats, returns a pointer to double. */ double *dividePrecision(float a, float b); + +/** Version of the native C library */ +const char* const library_version = "1.0.0-native"; diff --git a/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart b/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart index 13c7d2b9b3..d5d9308e88 100644 --- a/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart +++ b/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart @@ -49,3 +49,16 @@ external ffi.Pointer dividePrecision( double a, double b, ); + +/// Version of the native C library +@ffi.Native>() +external final library_version; +const _SymbolAddresses addresses = _SymbolAddresses(); + +class _SymbolAddresses { + const _SymbolAddresses(); + ffi.Pointer> get sum => + ffi.Native.addressOf(sum); + ffi.Pointer> get library_version => + ffi.Native.addressOf(library_version); +} diff --git a/pkgs/ffigen/lib/src/code_generator/func.dart b/pkgs/ffigen/lib/src/code_generator/func.dart index 766cc289ee..907d6b9fe3 100644 --- a/pkgs/ffigen/lib/src/code_generator/func.dart +++ b/pkgs/ffigen/lib/src/code_generator/func.dart @@ -164,6 +164,15 @@ $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'); diff --git a/pkgs/ffigen/lib/src/code_generator/global.dart b/pkgs/ffigen/lib/src/code_generator/global.dart index 47aee0de1e..18976311cd 100644 --- a/pkgs/ffigen/lib/src/code_generator/global.dart +++ b/pkgs/ffigen/lib/src/code_generator/global.dart @@ -2,6 +2,7 @@ // 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. +import '../config_provider/config_types.dart'; import 'binding.dart'; import 'binding_string.dart'; import 'compound.dart'; @@ -22,6 +23,7 @@ import 'writer.dart'; class Global extends LookUpBinding { final Type type; final bool exposeSymbolAddress; + final FfiNativeConfig nativeConfig; final bool constant; Global({ @@ -32,6 +34,7 @@ class Global extends LookUpBinding { super.dartDoc, this.exposeSymbolAddress = false, this.constant = false, + this.nativeConfig = const FfiNativeConfig(enabled: false), }); @override @@ -41,35 +44,55 @@ class Global extends LookUpBinding { if (dartDoc != null) { s.write(makeDartDoc(dartDoc!)); } - final pointerName = w.wrapperLevelUniqueNamer.makeUnique('_$globalVarName'); final dartType = type.getFfiDartType(w); final cType = type.getCType(w); - s.write( - "late final ${w.ffiLibraryPrefix}.Pointer<$cType> $pointerName = ${w.lookupFuncIdentifier}<$cType>('$originalName');\n\n"); - final baseTypealiasType = type.typealiasType; - if (baseTypealiasType is Compound) { - if (baseTypealiasType.isOpaque) { - s.write( - '${w.ffiLibraryPrefix}.Pointer<$cType> get $globalVarName => $pointerName;\n\n'); - } else { - s.write('$dartType get $globalVarName => $pointerName.ref;\n\n'); + if (nativeConfig.enabled) { + s + ..write('@${w.ffiLibraryPrefix}.Native<') + ..write(cType) + ..writeln('>()') + ..write('external '); + if (constant) { + s.write('final '); + } + + s.writeln('$globalVarName;'); + + if (exposeSymbolAddress) { + w.symbolAddressWriter.addNativeSymbol( + type: '${w.ffiLibraryPrefix}.Pointer<$cType>', name: name); } } else { - s.write('$dartType get $globalVarName => $pointerName.value;\n\n'); - if (!constant) { - s.write( - 'set $globalVarName($dartType value) => $pointerName.value = value;\n\n'); + final pointerName = + w.wrapperLevelUniqueNamer.makeUnique('_$globalVarName'); + + s.write( + "late final ${w.ffiLibraryPrefix}.Pointer<$cType> $pointerName = ${w.lookupFuncIdentifier}<$cType>('$originalName');\n\n"); + final baseTypealiasType = type.typealiasType; + if (baseTypealiasType is Compound) { + if (baseTypealiasType.isOpaque) { + s.write( + '${w.ffiLibraryPrefix}.Pointer<$cType> get $globalVarName => $pointerName;\n\n'); + } else { + s.write('$dartType get $globalVarName => $pointerName.ref;\n\n'); + } + } else { + s.write('$dartType get $globalVarName => $pointerName.value;\n\n'); + if (!constant) { + s.write( + 'set $globalVarName($dartType value) => $pointerName.value = value;\n\n'); + } } - } - if (exposeSymbolAddress) { - // Add to SymbolAddress in writer. - w.symbolAddressWriter.addSymbol( - type: '${w.ffiLibraryPrefix}.Pointer<$cType>', - name: name, - ptrName: pointerName, - ); + if (exposeSymbolAddress) { + // Add to SymbolAddress in writer. + w.symbolAddressWriter.addSymbol( + type: '${w.ffiLibraryPrefix}.Pointer<$cType>', + name: name, + ptrName: pointerName, + ); + } } return BindingString(type: BindingStringType.global, string: s.toString()); diff --git a/pkgs/ffigen/lib/src/code_generator/library.dart b/pkgs/ffigen/lib/src/code_generator/library.dart index 75cbdebc9b..4bfa569bf6 100644 --- a/pkgs/ffigen/lib/src/code_generator/library.dart +++ b/pkgs/ffigen/lib/src/code_generator/library.dart @@ -5,13 +5,13 @@ import 'dart:io'; import 'package:cli_util/cli_util.dart'; +import 'package:collection/collection.dart'; import 'package:ffigen/src/code_generator.dart'; import 'package:ffigen/src/config_provider/config_types.dart'; import 'package:logging/logging.dart'; import 'package:path/path.dart' as p; import 'package:yaml_edit/yaml_edit.dart'; -import '../strings.dart' as strings; import 'utils.dart'; import 'writer.dart'; @@ -52,7 +52,6 @@ class Library { for (final b in this.bindings) { _warnIfPrivateDeclaration(b); _resolveIfNameConflicts(declConflictHandler, b); - _warnIfExposeSymbolAddressAndFfiNative(b); } // Override pack values according to config. We do this after declaration @@ -66,23 +65,20 @@ class Library { } // Seperate bindings which require lookup. - final lookUpBindings = this.bindings.whereType().where((e) { - if (e is Func) { - return !e.ffiNativeConfig.enabled; - } - return true; - }).toList(); - final ffiNativeBindings = this - .bindings - .whereType() - .where((e) => e.ffiNativeConfig.enabled) - .toList(); + final byLookupKind = groupBy( + bindings.whereType(), + (e) => switch (e) { + Func() => !e.ffiNativeConfig.enabled, + Global() => !e.nativeConfig.enabled, + _ => true, + }, + ); final noLookUpBindings = this.bindings.whereType().toList(); _writer = Writer( - lookUpBindings: lookUpBindings, - ffiNativeBindings: ffiNativeBindings, + lookUpBindings: byLookupKind[true]?.toList() ?? const [], + ffiNativeBindings: byLookupKind[false]?.toList() ?? const [], noLookUpBindings: noLookUpBindings, className: name, classDocComment: description, @@ -113,16 +109,6 @@ class Library { } } - /// Logs a warning if generated declaration will be private. - void _warnIfExposeSymbolAddressAndFfiNative(Binding b) { - if (b is Func) { - if (b.exposeSymbolAddress && b.ffiNativeConfig.enabled) { - _logger.warning( - "Ignoring ${strings.symbolAddress} for '${b.name}' because it is generated as FfiNative."); - } - } - } - /// Sort all bindings in alphabetical order. void _sort() { bindings.sort((b1, b2) => b1.name.compareTo(b2.name)); diff --git a/pkgs/ffigen/lib/src/code_generator/writer.dart b/pkgs/ffigen/lib/src/code_generator/writer.dart index d20db66c17..a44b9da1ed 100644 --- a/pkgs/ffigen/lib/src/code_generator/writer.dart +++ b/pkgs/ffigen/lib/src/code_generator/writer.dart @@ -250,8 +250,14 @@ class Writer { s.write('}\n\n'); } - for (final b in ffiNativeBindings) { - s.write(b.toBindingString(this).string); + if (ffiNativeBindings.isNotEmpty) { + for (final b in ffiNativeBindings) { + s.write(b.toBindingString(this).string); + } + + if (symbolAddressWriter.shouldGenerate) { + s.write(symbolAddressWriter.writeObject(this)); + } } if (symbolAddressWriter.shouldGenerate) { @@ -329,29 +335,58 @@ class SymbolAddressWriter { /// Used to check if we need to generate `_SymbolAddress` class. bool get shouldGenerate => _addresses.isNotEmpty; + bool get hasNonNativeAddress => _addresses.any((e) => !e.native); + void addSymbol({ required String type, required String name, required String ptrName, }) { - _addresses.add(_SymbolAddressUnit(type, name, ptrName)); + _addresses.add(_SymbolAddressUnit(type, name, ptrName, false)); + } + + void addNativeSymbol({required String type, required String name}) { + _addresses.add(_SymbolAddressUnit(type, name, '', true)); } String writeObject(Writer w) { - return 'late final ${w._symbolAddressVariableName} = ${w._symbolAddressClassName}(this);'; + final className = w._symbolAddressClassName; + final fieldName = w._symbolAddressVariableName; + + if (hasNonNativeAddress) { + return 'late final $className $fieldName = $className(this);'; + } else { + return 'const $className $fieldName = $className();'; + } } String writeClass(Writer w) { final sb = StringBuffer(); sb.write('class ${w._symbolAddressClassName} {\n'); - // Write Library object. - sb.write('final ${w._className} ${w._symbolAddressLibraryVarName};\n'); - // Write Constructor. - sb.write( - '${w._symbolAddressClassName}(this.${w._symbolAddressLibraryVarName});\n'); - for (final address in _addresses) { + + if (hasNonNativeAddress) { + // Write Library object. + sb.write('final ${w._className} ${w._symbolAddressLibraryVarName};\n'); + // Write Constructor. sb.write( - '${address.type} get ${address.name} => ${w._symbolAddressLibraryVarName}.${address.ptrName};\n'); + '${w._symbolAddressClassName}(this.${w._symbolAddressLibraryVarName});\n'); + } else { + // Native bindings are top-level, so we don't need a field here. + sb.write('const ${w._symbolAddressClassName}();'); + } + + for (final address in _addresses) { + sb.write('${address.type} get ${address.name} => '); + + if (address.native) { + // For native fields and functions, we can use Native.addressOf to look + // up their address. + sb.writeln('${w.ffiLibraryPrefix}.Native.addressOf(${address.name});'); + } else { + // For other elements, the generator will write a private field of type + // Pointer which we can reference here. + sb.writeln('${w._symbolAddressLibraryVarName}.${address.ptrName};'); + } } sb.write('}\n'); return sb.toString(); @@ -362,5 +397,8 @@ class SymbolAddressWriter { class _SymbolAddressUnit { final String type, name, ptrName; - _SymbolAddressUnit(this.type, this.name, this.ptrName); + /// Whether the symbol we're looking up has been declared with `@Native`. + final bool native; + + _SymbolAddressUnit(this.type, this.name, this.ptrName, this.native); } diff --git a/pkgs/ffigen/lib/src/header_parser/sub_parsers/var_parser.dart b/pkgs/ffigen/lib/src/header_parser/sub_parsers/var_parser.dart index bea3e8091a..7fea094eb9 100644 --- a/pkgs/ffigen/lib/src/header_parser/sub_parsers/var_parser.dart +++ b/pkgs/ffigen/lib/src/header_parser/sub_parsers/var_parser.dart @@ -34,21 +34,17 @@ Global? parseVarDeclaration(clang_types.CXCursor cursor) { return null; } - if (config.ffiNativeConfig.enabled) { - _logger - .warning("Skipped global variable '$name', not supported in Natives."); - return null; - } - final global = Global( originalName: name, name: config.globals.renameUsingConfig(name), usr: usr, type: type, dartDoc: getCursorDocComment(cursor), - exposeSymbolAddress: config.functionDecl.shouldIncludeSymbolAddress(name), + exposeSymbolAddress: config.globals.shouldIncludeSymbolAddress(name), constant: cType.isConstQualified, + nativeConfig: config.ffiNativeConfig, ); bindingsIndex.addGlobalVarToSeen(usr, global); + return global; } From 99366b889fd0eccd517952a2e2dc67d251f75b18 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Wed, 13 Dec 2023 15:07:36 +0100 Subject: [PATCH 02/21] Add changelog entry --- pkgs/ffigen/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/ffigen/CHANGELOG.md b/pkgs/ffigen/CHANGELOG.md index ac8e9a4ef0..cc931cb2d9 100644 --- a/pkgs/ffigen/CHANGELOG.md +++ b/pkgs/ffigen/CHANGELOG.md @@ -6,6 +6,9 @@ bindings if the compiler makes a wrong guess. A flag `--ignore-source-errors` (o 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. +- 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. ## 10.0.0 From b9d738c0bd23b35f6dd26750a665d3fdb994a1f0 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Wed, 13 Dec 2023 15:18:17 +0100 Subject: [PATCH 03/21] Fix missing type name --- pkgs/ffigen/example/ffinative/lib/generated_bindings.dart | 2 +- pkgs/ffigen/lib/src/code_generator/global.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart b/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart index d5d9308e88..814796006f 100644 --- a/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart +++ b/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart @@ -52,7 +52,7 @@ external ffi.Pointer dividePrecision( /// Version of the native C library @ffi.Native>() -external final library_version; +external final ffi.Pointer library_version; const _SymbolAddresses addresses = _SymbolAddresses(); class _SymbolAddresses { diff --git a/pkgs/ffigen/lib/src/code_generator/global.dart b/pkgs/ffigen/lib/src/code_generator/global.dart index 18976311cd..8f4080bbdd 100644 --- a/pkgs/ffigen/lib/src/code_generator/global.dart +++ b/pkgs/ffigen/lib/src/code_generator/global.dart @@ -57,7 +57,7 @@ class Global extends LookUpBinding { s.write('final '); } - s.writeln('$globalVarName;'); + s.writeln('$dartType $globalVarName;'); if (exposeSymbolAddress) { w.symbolAddressWriter.addNativeSymbol( From 01e77521ec2409d1f54f68ac5acb4f30b4f2bc3d Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Fri, 15 Dec 2023 00:05:52 +0100 Subject: [PATCH 04/21] Support array fields --- .../example/ffinative/headers/example.h | 2 ++ .../ffinative/lib/generated_bindings.dart | 4 ++++ .../ffigen/lib/src/code_generator/global.dart | 23 +++++++++++++++++++ .../lib/src/code_generator/pointer.dart | 13 ++++++++++- .../header_parser/sub_parsers/var_parser.dart | 6 ++++- .../type_extractor/extractor.dart | 8 ++++--- pkgs/ffigen/lib/src/header_parser/utils.dart | 4 ++-- 7 files changed, 53 insertions(+), 7 deletions(-) diff --git a/pkgs/ffigen/example/ffinative/headers/example.h b/pkgs/ffigen/example/ffinative/headers/example.h index 38a309174b..2a8fbb960e 100644 --- a/pkgs/ffigen/example/ffinative/headers/example.h +++ b/pkgs/ffigen/example/ffinative/headers/example.h @@ -17,5 +17,7 @@ float *divide(int a, int b); /** Divides 2 floats, returns a pointer to double. */ double *dividePrecision(float a, float b); +const int array[10]; + /** Version of the native C library */ const char* const library_version = "1.0.0-native"; diff --git a/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart b/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart index 814796006f..ef72312ba9 100644 --- a/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart +++ b/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart @@ -50,6 +50,10 @@ external ffi.Pointer dividePrecision( double b, ); +@ffi.Array(10) +@ffi.Native>() +external ffi.Array array; + /// Version of the native C library @ffi.Native>() external final ffi.Pointer library_version; diff --git a/pkgs/ffigen/lib/src/code_generator/global.dart b/pkgs/ffigen/lib/src/code_generator/global.dart index 8f4080bbdd..d4d73100ce 100644 --- a/pkgs/ffigen/lib/src/code_generator/global.dart +++ b/pkgs/ffigen/lib/src/code_generator/global.dart @@ -6,6 +6,7 @@ import '../config_provider/config_types.dart'; import 'binding.dart'; import 'binding_string.dart'; import 'compound.dart'; +import 'pointer.dart'; import 'type.dart'; import 'utils.dart'; import 'writer.dart'; @@ -48,6 +49,10 @@ class Global extends LookUpBinding { final cType = type.getCType(w); if (nativeConfig.enabled) { + if (type case final ConstantArray arr) { + arr.generateSizeAnnotation(s, w); + } + s ..write('@${w.ffiLibraryPrefix}.Native<') ..write(cType) @@ -106,3 +111,21 @@ class Global extends LookUpBinding { type.addDependencies(dependencies); } } + +extension on ConstantArray { + void generateSizeAnnotation(StringBuffer buffer, Writer w) { + buffer.write('@${w.ffiLibraryPrefix}.Array('); + + Type? array = this; + var first = true; + while (array is ConstantArray) { + if (!first) buffer.write(', '); + + buffer.write(array.length); + first = false; + array = array.baseArrayType; + } + + buffer.writeln(')'); + } +} diff --git a/pkgs/ffigen/lib/src/code_generator/pointer.dart b/pkgs/ffigen/lib/src/code_generator/pointer.dart index 30e2e6ba78..6e4fe1debd 100644 --- a/pkgs/ffigen/lib/src/code_generator/pointer.dart +++ b/pkgs/ffigen/lib/src/code_generator/pointer.dart @@ -45,7 +45,9 @@ class PointerType extends Type { /// Represents a constant array, which has a fixed size. class ConstantArray extends PointerType { final int length; - ConstantArray(this.length, Type child) : super._(child); + final bool useArrayType; + + ConstantArray(this.length, this.useArrayType, Type child) : super._(child); @override Type get baseArrayType => child.baseArrayType; @@ -58,6 +60,15 @@ class ConstantArray extends PointerType { @override String cacheKey() => '${child.cacheKey()}[$length]'; + + @override + String getCType(Writer w) { + if (useArrayType) { + return '${w.ffiLibraryPrefix}.Array<${child.getCType(w)}>'; + } + + return super.getCType(w); + } } /// Represents an incomplete array, which has an unknown size. diff --git a/pkgs/ffigen/lib/src/header_parser/sub_parsers/var_parser.dart b/pkgs/ffigen/lib/src/header_parser/sub_parsers/var_parser.dart index 7fea094eb9..e77ff76a47 100644 --- a/pkgs/ffigen/lib/src/header_parser/sub_parsers/var_parser.dart +++ b/pkgs/ffigen/lib/src/header_parser/sub_parsers/var_parser.dart @@ -26,7 +26,11 @@ Global? parseVarDeclaration(clang_types.CXCursor cursor) { _logger.fine('++++ Adding Global: ${cursor.completeStringRepr()}'); final cType = cursor.type(); - final type = cType.toCodeGenType(); + + final type = cType.toCodeGenType( + // Native fields can be arrays, but if we use the lookup based method of + // reading fields there's no way to turn a Pointer into an array. + supportNonInlineArray: config.ffiNativeConfig.enabled); if (type.baseType is UnimplementedType) { _logger.fine('---- Removed Global, reason: unsupported type: ' '${cursor.completeStringRepr()}'); diff --git a/pkgs/ffigen/lib/src/header_parser/type_extractor/extractor.dart b/pkgs/ffigen/lib/src/header_parser/type_extractor/extractor.dart index 5eb7a02592..bdfac0bf80 100644 --- a/pkgs/ffigen/lib/src/header_parser/type_extractor/extractor.dart +++ b/pkgs/ffigen/lib/src/header_parser/type_extractor/extractor.dart @@ -39,6 +39,7 @@ Type getCodeGenType( /// Cursor of the declaration, currently this is useful only to extract /// parameter names in function types. clang_types.CXCursor? originalCursor, + bool supportNonInlineArray = false, }) { _logger.fine('${_padding}getCodeGenType ${cxtype.completeStringRepr()}'); @@ -121,12 +122,13 @@ Type getCodeGenType( case clang_types.CXTypeKind.CXType_ConstantArray: // Primarily used for constant array in struct members. final numElements = clang.clang_getNumElements(cxtype); - final elementType = - clang.clang_getArrayElementType(cxtype).toCodeGenType(); + final elementType = clang + .clang_getArrayElementType(cxtype) + .toCodeGenType(supportNonInlineArray: supportNonInlineArray); // Handle numElements being 0 as an incomplete array. return numElements == 0 ? IncompleteArray(elementType) - : ConstantArray(numElements, elementType); + : ConstantArray(numElements, supportNonInlineArray, elementType); case clang_types.CXTypeKind.CXType_IncompleteArray: // Primarily used for incomplete array in function parameters. return IncompleteArray( diff --git a/pkgs/ffigen/lib/src/header_parser/utils.dart b/pkgs/ffigen/lib/src/header_parser/utils.dart index d142370f23..9e80414dfa 100644 --- a/pkgs/ffigen/lib/src/header_parser/utils.dart +++ b/pkgs/ffigen/lib/src/header_parser/utils.dart @@ -273,8 +273,8 @@ String? removeRawCommentMarkups(String? string) { extension CXTypeExt on clang_types.CXType { /// Get code_gen [Type] representation of [clang_types.CXType]. - Type toCodeGenType() { - return getCodeGenType(this); + Type toCodeGenType({bool supportNonInlineArray = false}) { + return getCodeGenType(this, supportNonInlineArray: supportNonInlineArray); } /// Spelling for a [clang_types.CXTypeKind], useful for debug purposes. From d3e9841ccbb64f15b78d80ca719c014430217520 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Thu, 21 Dec 2023 15:58:36 +0100 Subject: [PATCH 05/21] Include asset id if desired --- .../ffinative/lib/generated_bindings.dart | 12 ++++------ pkgs/ffigen/lib/src/code_generator/func.dart | 12 ++++++---- .../ffigen/lib/src/code_generator/global.dart | 10 +++++--- pkgs/ffigen/lib/src/code_generator/utils.dart | 23 +++++++++++++++++++ 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart b/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart index ef72312ba9..ec9666f491 100644 --- a/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart +++ b/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart @@ -8,7 +8,7 @@ import 'dart:ffi' as ffi; /// Adds 2 integers. @ffi.Native( - symbol: 'sum', assetId: 'package:ffinative_example/generated_bindings.dart') + assetId: 'package:ffinative_example/generated_bindings.dart') external int sum( int a, int b, @@ -16,7 +16,6 @@ external int sum( /// Subtracts 2 integers. @ffi.Native( - symbol: 'subtract', assetId: 'package:ffinative_example/generated_bindings.dart') external int subtract( int a, @@ -25,7 +24,6 @@ external int subtract( /// Multiplies 2 integers, returns pointer to an integer,. @ffi.Native Function(ffi.Int, ffi.Int)>( - symbol: 'multiply', assetId: 'package:ffinative_example/generated_bindings.dart') external ffi.Pointer multiply( int a, @@ -34,7 +32,6 @@ external ffi.Pointer multiply( /// Divides 2 integers, returns pointer to a float. @ffi.Native Function(ffi.Int, ffi.Int)>( - symbol: 'divide', assetId: 'package:ffinative_example/generated_bindings.dart') external ffi.Pointer divide( int a, @@ -43,7 +40,6 @@ external ffi.Pointer divide( /// Divides 2 floats, returns a pointer to double. @ffi.Native Function(ffi.Float, ffi.Float)>( - symbol: 'dividePrecision', assetId: 'package:ffinative_example/generated_bindings.dart') external ffi.Pointer dividePrecision( double a, @@ -51,11 +47,13 @@ external ffi.Pointer dividePrecision( ); @ffi.Array(10) -@ffi.Native>() +@ffi.Native>( + assetId: 'package:ffinative_example/generated_bindings.dart') external ffi.Array array; /// Version of the native C library -@ffi.Native>() +@ffi.Native>( + assetId: 'package:ffinative_example/generated_bindings.dart') external final ffi.Pointer library_version; const _SymbolAddresses addresses = _SymbolAddresses(); diff --git a/pkgs/ffigen/lib/src/code_generator/func.dart b/pkgs/ffigen/lib/src/code_generator/func.dart index 5ccd4a90d1..e0439f357a 100644 --- a/pkgs/ffigen/lib/src/code_generator/func.dart +++ b/pkgs/ffigen/lib/src/code_generator/func.dart @@ -145,13 +145,15 @@ class Func extends LookUpBinding { } if (ffiNativeConfig.enabled) { - final assetString = ffiNativeConfig.assetId != null - ? ", assetId: '${ffiNativeConfig.assetId}'" - : ''; - final isLeafString = isLeaf ? ', isLeaf:true' : ''; final nativeFuncName = needsWrapper ? funcVarName : enclosingFuncName; s.write(''' -@${w.ffiLibraryPrefix}.Native<$cType>(symbol: '$originalName'$assetString$isLeafString) +${makeNativeAnnotation( + w, + nativeType: cType, + differentName: originalName != nativeFuncName ? originalName : null, + assetId: ffiNativeConfig.assetId, + isLeaf: isLeaf, + )} external $ffiReturnType $nativeFuncName($ffiArgDeclString); '''); diff --git a/pkgs/ffigen/lib/src/code_generator/global.dart b/pkgs/ffigen/lib/src/code_generator/global.dart index d4d73100ce..4659dd5760 100644 --- a/pkgs/ffigen/lib/src/code_generator/global.dart +++ b/pkgs/ffigen/lib/src/code_generator/global.dart @@ -54,9 +54,13 @@ class Global extends LookUpBinding { } s - ..write('@${w.ffiLibraryPrefix}.Native<') - ..write(cType) - ..writeln('>()') + ..writeln(makeNativeAnnotation( + w, + nativeType: cType, + assetId: nativeConfig.assetId, + differentName: globalVarName != originalName ? originalName : null, + isLeaf: false, + )) ..write('external '); if (constant) { s.write('final '); diff --git a/pkgs/ffigen/lib/src/code_generator/utils.dart b/pkgs/ffigen/lib/src/code_generator/utils.dart index 5c18c7f621..b34b9dcdab 100644 --- a/pkgs/ffigen/lib/src/code_generator/utils.dart +++ b/pkgs/ffigen/lib/src/code_generator/utils.dart @@ -1,4 +1,5 @@ import 'dart_keywords.dart'; +import 'writer.dart'; class UniqueNamer { final Set _usedUpNames; @@ -75,3 +76,25 @@ String makeDoc(String text) { return s.toString(); } + +String makeNativeAnnotation( + Writer w, { + required String? nativeType, + String? differentName, + String? assetId, + bool isLeaf = false, +}) { + final args = <(String, String)>[]; + if (differentName != null) { + args.add(('symbol', '"$differentName"')); + } + if (assetId != null) { + args.add(('assetId', "'$assetId'")); + } + if (isLeaf) { + args.add(('isLeaf', 'true')); + } + + final combinedArgs = args.map((e) => '${e.$1}: ${e.$2}').join(', '); + return '@${w.ffiLibraryPrefix}.Native<$nativeType>($combinedArgs)'; +} From 305c357d6f2b60650b528974bc8b96bf524b9d82 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Thu, 21 Dec 2023 17:04:12 +0100 Subject: [PATCH 06/21] Add generation tests --- .../lib/src/code_generator/library.dart | 54 ++++++------ .../lib/src/code_generator/pointer.dart | 3 +- .../type_extractor/extractor.dart | 6 +- pkgs/ffigen/pubspec.yaml | 2 + .../code_generator_test.dart | 88 +++++++++++++++---- ..._expected_function_ffiNative_bindings.dart | 11 ++- .../_expected_global_bindings.dart | 5 ++ .../_expected_global_native_bindings.dart | 25 ++++++ .../_expected_native_symbol_bindings.dart | 17 ++++ .../function_n_struct_test.dart | 9 +- 10 files changed, 169 insertions(+), 51 deletions(-) create mode 100644 pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart create mode 100644 pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_native_symbol_bindings.dart diff --git a/pkgs/ffigen/lib/src/code_generator/library.dart b/pkgs/ffigen/lib/src/code_generator/library.dart index 4bfa569bf6..41774e62f3 100644 --- a/pkgs/ffigen/lib/src/code_generator/library.dart +++ b/pkgs/ffigen/lib/src/code_generator/library.dart @@ -34,18 +34,7 @@ class Library { StructPackingOverride? packingOverride, Set? libraryImports, }) { - /// Get all dependencies (includes itself). - final dependencies = {}; - for (final b in bindings) { - b.addDependencies(dependencies); - } - - /// Save bindings. - this.bindings = dependencies.toList(); - - if (sort) { - _sort(); - } + _findBindings(bindings, sort); /// Handle any declaration-declaration name conflicts and emit warnings. final declConflictHandler = UniqueNamer({}); @@ -65,20 +54,24 @@ class Library { } // Seperate bindings which require lookup. - final byLookupKind = groupBy( - bindings.whereType(), - (e) => switch (e) { - Func() => !e.ffiNativeConfig.enabled, - Global() => !e.nativeConfig.enabled, + final lookupBindings = []; + final nativeBindings = []; + + for (final binding in this.bindings.whereType()) { + final usesLookup = switch (binding) { + Func() => !binding.ffiNativeConfig.enabled, + Global() => !binding.nativeConfig.enabled, _ => true, - }, - ); + }; + + (usesLookup ? lookupBindings : nativeBindings).add(binding); + } final noLookUpBindings = this.bindings.whereType().toList(); _writer = Writer( - lookUpBindings: byLookupKind[true]?.toList() ?? const [], - ffiNativeBindings: byLookupKind[false]?.toList() ?? const [], + lookUpBindings: lookupBindings, + ffiNativeBindings: nativeBindings, noLookUpBindings: noLookUpBindings, className: name, classDocComment: description, @@ -87,6 +80,20 @@ class Library { ); } + void _findBindings(List original, bool sort) { + /// Get all dependencies (includes itself). + final dependencies = {}; + for (final b in original) { + b.addDependencies(dependencies); + } + + /// Save bindings. + bindings = dependencies.toList(); + if (sort) { + bindings.sortBy((b) => b.name); + } + } + /// Logs a warning if generated declaration will be private. void _warnIfPrivateDeclaration(Binding b) { if (b.name.startsWith('_') && !b.isInternal) { @@ -109,11 +116,6 @@ class Library { } } - /// Sort all bindings in alphabetical order. - void _sort() { - bindings.sort((b1, b2) => b1.name.compareTo(b2.name)); - } - /// Generates [file] by generating C bindings. /// /// If format is true(default), the formatter will be called to format the generated file. diff --git a/pkgs/ffigen/lib/src/code_generator/pointer.dart b/pkgs/ffigen/lib/src/code_generator/pointer.dart index 6e4fe1debd..b3f6cfb621 100644 --- a/pkgs/ffigen/lib/src/code_generator/pointer.dart +++ b/pkgs/ffigen/lib/src/code_generator/pointer.dart @@ -47,7 +47,8 @@ class ConstantArray extends PointerType { final int length; final bool useArrayType; - ConstantArray(this.length, this.useArrayType, Type child) : super._(child); + ConstantArray(this.length, Type child, {required this.useArrayType}) + : super._(child); @override Type get baseArrayType => child.baseArrayType; diff --git a/pkgs/ffigen/lib/src/header_parser/type_extractor/extractor.dart b/pkgs/ffigen/lib/src/header_parser/type_extractor/extractor.dart index bdfac0bf80..079e6573f8 100644 --- a/pkgs/ffigen/lib/src/header_parser/type_extractor/extractor.dart +++ b/pkgs/ffigen/lib/src/header_parser/type_extractor/extractor.dart @@ -128,7 +128,11 @@ Type getCodeGenType( // Handle numElements being 0 as an incomplete array. return numElements == 0 ? IncompleteArray(elementType) - : ConstantArray(numElements, supportNonInlineArray, elementType); + : ConstantArray( + numElements, + elementType, + useArrayType: supportNonInlineArray, + ); case clang_types.CXTypeKind.CXType_IncompleteArray: // Primarily used for incomplete array in function parameters. return IncompleteArray( diff --git a/pkgs/ffigen/pubspec.yaml b/pkgs/ffigen/pubspec.yaml index b926ee5db8..dabbd84d61 100644 --- a/pkgs/ffigen/pubspec.yaml +++ b/pkgs/ffigen/pubspec.yaml @@ -28,8 +28,10 @@ dependencies: file: ^7.0.0 package_config: ^2.1.0 yaml_edit: ^2.0.3 + collection: ^1.18.0 dev_dependencies: lints: ^2.0.1 test: ^1.16.2 json_schema: ^5.1.1 + meta: ^1.11.0 diff --git a/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart b/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart index c4dd1a120a..6354a75007 100644 --- a/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart +++ b/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart @@ -4,7 +4,9 @@ import 'package:ffigen/src/code_generator.dart'; import 'package:ffigen/src/config_provider/config_types.dart'; +import 'package:meta/meta.dart'; import 'package:test/test.dart'; + import '../test_utils.dart'; void main() { @@ -15,7 +17,16 @@ void main() { '''; group('code_generator: ', () { - void functionBindings(bool enableFfiNative) { + @isTestGroup + void withAndWithoutNative(String description, void Function(bool) runTest) { + group(description, () { + test('without Native', () => runTest(false)); + test('with Native', () => runTest(true)); + }); + } + + withAndWithoutNative('Function Binding (primitives, pointers)', + (enableFfiNative) { final library = Library( name: 'Bindings', header: licenseHeader, @@ -99,14 +110,6 @@ void main() { ); _matchLib(library, enableFfiNative ? 'function_ffiNative' : 'function'); - } - - test('Function Binding (primitives, pointers)', () { - functionBindings(false); - }); - - test('Function Binding (primitives, pointers) (ffiNative)', () { - functionBindings(true); }); test('Struct Binding (primitives, pointers)', () { @@ -250,23 +253,27 @@ void main() { _matchLib(library, 'function_n_struct'); }); - test('global (primitives, pointers, pointer to struct)', () { + withAndWithoutNative('global (primitives, pointers, pointer to struct)', + (enableNative) { final structSome = Struct( name: 'Some', ); final emptyGlobalStruct = Struct(name: 'EmptyStruct'); + final nativeConfig = FfiNativeConfig(enabled: enableNative); final library = Library( name: 'Bindings', header: licenseHeader, bindings: [ Global( + nativeConfig: nativeConfig, name: 'test1', type: NativeType( SupportedNativeType.Int32, ), ), Global( + nativeConfig: nativeConfig, name: 'test2', type: PointerType( NativeType( @@ -275,18 +282,35 @@ void main() { ), constant: true, ), + Global( + nativeConfig: nativeConfig, + name: 'test3', + type: ConstantArray( + 10, + NativeType( + SupportedNativeType.Float, + ), + useArrayType: enableNative, + ), + constant: true, + ), structSome, Global( + nativeConfig: nativeConfig, name: 'test5', type: PointerType( structSome, ), ), emptyGlobalStruct, - Global(name: 'globalStruct', type: emptyGlobalStruct), + Global( + nativeConfig: nativeConfig, + name: 'globalStruct', + type: emptyGlobalStruct, + ), ], ); - _matchLib(library, 'global'); + _matchLib(library, enableNative ? 'global_native' : 'global'); }); test('constant', () { @@ -329,6 +353,7 @@ void main() { ); _matchLib(library, 'enumclass'); }); + test('Internal conflict resolution', () { final library = Library( name: 'init_dylib', @@ -361,6 +386,8 @@ void main() { NativeType( SupportedNativeType.Int8, ), + // Arrays are always supported in struct fields + useArrayType: true, ), ), ], @@ -376,6 +403,30 @@ void main() { ); _matchLib(library, 'internal_conflict_resolution'); }); + + test('Adds Native symbol on mismatch', () { + final nativeConfig = FfiNativeConfig(enabled: true); + final library = Library( + name: 'init_dylib', + header: + '$licenseHeader\n// ignore_for_file: unused_element, camel_case_types, non_constant_identifier_names\n', + bindings: [ + Func( + ffiNativeConfig: nativeConfig, + name: 'test', + originalName: '_test', + returnType: NativeType(SupportedNativeType.Void), + ), + Global( + nativeConfig: nativeConfig, + name: 'testField', + originalName: '_testField', + type: NativeType(SupportedNativeType.Int16), + ), + ], + ); + _matchLib(library, 'native_symbol'); + }); }); test('boolean_dartBool', () { final library = Library( @@ -467,10 +518,15 @@ void main() { Member(name: 'd', type: PointerType(struct1)), ]), Union(name: 'WithArray', members: [ - Member(name: 'a', type: ConstantArray(10, charType)), - Member(name: 'b', type: ConstantArray(10, union1)), - Member(name: 'b', type: ConstantArray(10, struct1)), - Member(name: 'c', type: ConstantArray(10, PointerType(union1))), + Member( + name: 'a', type: ConstantArray(10, charType, useArrayType: true)), + Member( + name: 'b', type: ConstantArray(10, union1, useArrayType: true)), + Member( + name: 'b', type: ConstantArray(10, struct1, useArrayType: true)), + Member( + name: 'c', + type: ConstantArray(10, PointerType(union1), useArrayType: true)), ]), ], ); diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_ffiNative_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_ffiNative_bindings.dart index 9b4ebf4f5b..120567d92b 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_ffiNative_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_ffiNative_bindings.dart @@ -10,26 +10,25 @@ import 'dart:ffi' as ffi; /// Just a test function /// heres another line -@ffi.Native(symbol: 'noParam') +@ffi.Native() external int noParam(); -@ffi.Native( - symbol: 'withPrimitiveParam') +@ffi.Native() external int withPrimitiveParam( int a, int b, ); @ffi.Native< - ffi.Pointer Function(ffi.Pointer, - ffi.Pointer>)>(symbol: 'withPointerParam') + ffi.Pointer Function( + ffi.Pointer, ffi.Pointer>)>() external ffi.Pointer withPointerParam( ffi.Pointer a, ffi.Pointer> b, ); /// A function with isLeaf: true -@ffi.Native(symbol: 'leafFunc', isLeaf: true) +@ffi.Native(isLeaf: true) external int leafFunc( int a, ); diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_bindings.dart index 85b3b18434..066f9ee0be 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_bindings.dart @@ -33,6 +33,11 @@ class Bindings { ffi.Pointer get test2 => _test2.value; + late final ffi.Pointer> _test3 = + _lookup>('test3'); + + ffi.Pointer get test3 => _test3.value; + late final ffi.Pointer> _test5 = _lookup>('test5'); diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart new file mode 100644 index 0000000000..920addb84e --- /dev/null +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart @@ -0,0 +1,25 @@ +// Copyright (c) 2023, 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. + +// AUTO GENERATED FILE, DO NOT EDIT. +// +// Generated by `package:ffigen`. +// ignore_for_file: type=lint +import 'dart:ffi' as ffi; + +@ffi.Native() +external int test1; +@ffi.Native>() +external final ffi.Pointer test2; +@ffi.Array(10) +@ffi.Native>() +external final ffi.Array test3; +@ffi.Native>() +external ffi.Pointer test5; +@ffi.Native() +external EmptyStruct globalStruct; + +final class Some extends ffi.Opaque {} + +final class EmptyStruct extends ffi.Opaque {} diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_native_symbol_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_native_symbol_bindings.dart new file mode 100644 index 0000000000..234cf2c96d --- /dev/null +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_native_symbol_bindings.dart @@ -0,0 +1,17 @@ +// Copyright (c) 2023, 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: unused_element, camel_case_types, non_constant_identifier_names + +// AUTO GENERATED FILE, DO NOT EDIT. +// +// Generated by `package:ffigen`. +// ignore_for_file: type=lint +import 'dart:ffi' as ffi; + +@ffi.Native(symbol: "_test") +external void test(); + +@ffi.Native(symbol: "_testField") +external int testField; diff --git a/pkgs/ffigen/test/header_parser_tests/function_n_struct_test.dart b/pkgs/ffigen/test/header_parser_tests/function_n_struct_test.dart index 5ddd58afa9..028da3d7f1 100644 --- a/pkgs/ffigen/test/header_parser_tests/function_n_struct_test.dart +++ b/pkgs/ffigen/test/header_parser_tests/function_n_struct_test.dart @@ -118,7 +118,14 @@ Library expectedLibrary() { Struct(name: 'Struct4'), Struct(name: 'Struct5'), Struct(name: 'Struct6', members: [ - Member(name: 'a', type: ConstantArray(2, ConstantArray(10, intType))) + Member( + name: 'a', + type: ConstantArray( + 2, + ConstantArray(10, intType, useArrayType: false), + useArrayType: false, + ), + ) ]), Struct(name: 'Struct7'), ], From 5e4b97d141a2ff4d622686ea92a7819e98b9ed34 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Thu, 21 Dec 2023 17:11:35 +0100 Subject: [PATCH 07/21] Fix license headers --- pkgs/ffigen/example/ffinative/config.yaml | 4 ++++ pkgs/ffigen/example/ffinative/lib/generated_bindings.dart | 4 ++++ pkgs/ffigen/lib/src/code_generator/utils.dart | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/pkgs/ffigen/example/ffinative/config.yaml b/pkgs/ffigen/example/ffinative/config.yaml index f24eb25c51..002d7feda3 100644 --- a/pkgs/ffigen/example/ffinative/config.yaml +++ b/pkgs/ffigen/example/ffinative/config.yaml @@ -9,6 +9,10 @@ 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: diff --git a/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart b/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart index ec9666f491..0d952c4786 100644 --- a/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart +++ b/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart @@ -1,3 +1,7 @@ +// Copyright (c) 2023, 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. diff --git a/pkgs/ffigen/lib/src/code_generator/utils.dart b/pkgs/ffigen/lib/src/code_generator/utils.dart index b34b9dcdab..67d6adfd19 100644 --- a/pkgs/ffigen/lib/src/code_generator/utils.dart +++ b/pkgs/ffigen/lib/src/code_generator/utils.dart @@ -1,3 +1,7 @@ +// Copyright (c) 2023, 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. + import 'dart_keywords.dart'; import 'writer.dart'; From f521df2c390238260fd73162da5b316eefee4c81 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Sun, 24 Dec 2023 14:51:10 +0100 Subject: [PATCH 08/21] Use dev sdk for tests --- .github/workflows/ffigen.yml | 9 +++++---- .github/workflows/ffigen_weekly.yml | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ffigen.yml b/.github/workflows/ffigen.yml index 945cca21c6..2099353457 100644 --- a/.github/workflows/ffigen.yml +++ b/.github/workflows/ffigen.yml @@ -28,7 +28,8 @@ jobs: strategy: fail-fast: false matrix: - sdk: [3.2.0] + sdk: [dev] +# sdk: [3.2.0] steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d @@ -56,7 +57,7 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: - sdk: 3.2.0 + sdk: dev #3.2.0 - name: Install dependencies run: dart pub get - name: Install libclang-14-dev @@ -77,7 +78,7 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: - sdk: 3.2.0 + sdk: dev #3.2.0 - name: Install dependencies run: dart pub get - name: Build test dylib and bindings @@ -110,7 +111,7 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: - sdk: 3.2.0 + sdk: dev #3.2.0 - name: Install dependencies run: dart pub get - name: Build test dylib and bindings diff --git a/.github/workflows/ffigen_weekly.yml b/.github/workflows/ffigen_weekly.yml index 4d8d1060ac..c3720a05da 100644 --- a/.github/workflows/ffigen_weekly.yml +++ b/.github/workflows/ffigen_weekly.yml @@ -22,7 +22,7 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: - sdk: 3.2.0 + sdk: dev #3.2.0 - name: Install dependencies run: dart pub get - name: Build test dylib and bindings From bc19c460698e19996c7b11e426be060c32e74f8e Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Sun, 24 Dec 2023 15:47:57 +0100 Subject: [PATCH 09/21] Use self imports --- .../example/ffinative/lib/generated_bindings.dart | 7 ++++--- pkgs/ffigen/example/ffinative/pubspec.yaml | 2 +- pkgs/ffigen/lib/src/code_generator/imports.dart | 1 + pkgs/ffigen/lib/src/code_generator/writer.dart | 12 +++++++++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart b/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart index 0d952c4786..c93f361c0b 100644 --- a/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart +++ b/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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. @@ -9,6 +9,7 @@ // Generated by `package:ffigen`. // ignore_for_file: type=lint import 'dart:ffi' as ffi; +import '' as self; /// Adds 2 integers. @ffi.Native( @@ -64,7 +65,7 @@ const _SymbolAddresses addresses = _SymbolAddresses(); class _SymbolAddresses { const _SymbolAddresses(); ffi.Pointer> get sum => - ffi.Native.addressOf(sum); + ffi.Native.addressOf(self.sum); ffi.Pointer> get library_version => - ffi.Native.addressOf(library_version); + ffi.Native.addressOf(self.library_version); } diff --git a/pkgs/ffigen/example/ffinative/pubspec.yaml b/pkgs/ffigen/example/ffinative/pubspec.yaml index e97103113b..b3094bd6bb 100644 --- a/pkgs/ffigen/example/ffinative/pubspec.yaml +++ b/pkgs/ffigen/example/ffinative/pubspec.yaml @@ -5,7 +5,7 @@ name: ffinative_example environment: - sdk: '>=3.2.0 <4.0.0' + sdk: '>=3.3.0-dev <4.0.0' dependencies: ffi: ^2.0.1 diff --git a/pkgs/ffigen/lib/src/code_generator/imports.dart b/pkgs/ffigen/lib/src/code_generator/imports.dart index e9dda1ccd2..f620909b61 100644 --- a/pkgs/ffigen/lib/src/code_generator/imports.dart +++ b/pkgs/ffigen/lib/src/code_generator/imports.dart @@ -76,6 +76,7 @@ class SelfImportedType extends Type { final ffiImport = LibraryImport('ffi', 'dart:ffi'); final ffiPkgImport = LibraryImport('pkg_ffi', 'package:ffi/ffi.dart'); +final self = LibraryImport('self', ''); final voidType = ImportedType(ffiImport, 'Void', 'void'); diff --git a/pkgs/ffigen/lib/src/code_generator/writer.dart b/pkgs/ffigen/lib/src/code_generator/writer.dart index a44b9da1ed..3acc5ef73c 100644 --- a/pkgs/ffigen/lib/src/code_generator/writer.dart +++ b/pkgs/ffigen/lib/src/code_generator/writer.dart @@ -57,6 +57,13 @@ class Writer { return _ffiPkgLibraryPrefix = import.prefix; } + late String selfImportPrefix = () { + final import = _usedImports + .firstWhere((element) => element.name == self.name, orElse: () => self); + _usedImports.add(import); + return import.prefix; + }(); + final Set _usedImports = {}; late String _lookupFuncIdentifier; @@ -381,7 +388,10 @@ class SymbolAddressWriter { if (address.native) { // For native fields and functions, we can use Native.addressOf to look // up their address. - sb.writeln('${w.ffiLibraryPrefix}.Native.addressOf(${address.name});'); + // The name of address getter shadows the actual element in the library, + // so we need to use a self-import. + final arg = '${w.selfImportPrefix}.${address.name}'; + sb.writeln('${w.ffiLibraryPrefix}.Native.addressOf($arg);'); } else { // For other elements, the generator will write a private field of type // Pointer which we can reference here. From 44be5678aebeda90e00695e049a81741d7b3f779 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Fri, 29 Dec 2023 17:54:19 +0100 Subject: [PATCH 10/21] Raise SDK constraints --- pkgs/ffigen/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/ffigen/pubspec.yaml b/pkgs/ffigen/pubspec.yaml index dabbd84d61..94853a0201 100644 --- a/pkgs/ffigen/pubspec.yaml +++ b/pkgs/ffigen/pubspec.yaml @@ -14,7 +14,7 @@ topics: - codegen environment: - sdk: '>=3.2.0 <4.0.0' + sdk: '>=3.3.0-0 <4.0.0' dependencies: ffi: ^2.0.1 From d4b1388a5fafd8fe167e800c57802c9277b86612 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Fri, 29 Dec 2023 18:18:59 +0100 Subject: [PATCH 11/21] Update expectations --- pkgs/ffigen/example/libclang-example/generated_bindings.dart | 2 +- .../_expected_decl_symbol_address_collision_bindings.dart | 2 +- .../expected_bindings/_expected_functions_bindings.dart | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/ffigen/example/libclang-example/generated_bindings.dart b/pkgs/ffigen/example/libclang-example/generated_bindings.dart index 7cf663e388..3351a661c6 100644 --- a/pkgs/ffigen/example/libclang-example/generated_bindings.dart +++ b/pkgs/ffigen/example/libclang-example/generated_bindings.dart @@ -6827,7 +6827,7 @@ class LibClang { late final _clang_Type_visitFields = _clang_Type_visitFieldsPtr.asFunction(); - late final addresses = _SymbolAddresses(this); + late final _SymbolAddresses addresses = _SymbolAddresses(this); } class _SymbolAddresses { diff --git a/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_symbol_address_collision_bindings.dart b/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_symbol_address_collision_bindings.dart index 0d5473f942..0c5814b2f8 100644 --- a/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_symbol_address_collision_bindings.dart +++ b/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_symbol_address_collision_bindings.dart @@ -38,7 +38,7 @@ class Bindings1 { late final __SymbolAddresses_1 = __SymbolAddresses_1Ptr.asFunction(); - late final addresses = _SymbolAddresses1(this); + late final _SymbolAddresses1 addresses = _SymbolAddresses1(this); } class _SymbolAddresses1 { diff --git a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_functions_bindings.dart b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_functions_bindings.dart index 7475b09d3a..28db51f016 100644 --- a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_functions_bindings.dart +++ b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_functions_bindings.dart @@ -132,7 +132,7 @@ class NativeLibrary { ffi.Char Function(ffi.UnsignedChar, ffi.SignedChar)>>('diffChars'); late final _diffChars = _diffCharsPtr.asFunction(); - late final addresses = _SymbolAddresses(this); + late final _SymbolAddresses addresses = _SymbolAddresses(this); } class _SymbolAddresses { From b9a548f444a7f5b67c2d547956487aed6ce43b3d Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Tue, 2 Jan 2024 19:23:11 +0100 Subject: [PATCH 12/21] Review feedback --- pkgs/ffigen/example/ffinative/headers/example.h | 4 +++- .../ffinative/lib/generated_bindings.dart | 7 ++++++- pkgs/ffigen/example/ffinative/pubspec.yaml | 2 +- pkgs/ffigen/lib/src/code_generator/func.dart | 3 ++- pkgs/ffigen/lib/src/code_generator/global.dart | 5 +++-- pkgs/ffigen/lib/src/code_generator/utils.dart | 7 ++++--- pkgs/ffigen/pubspec.yaml | 2 +- .../code_generator_test.dart | 17 ++++++++++++----- .../_expected_global_native_bindings.dart | 4 ++++ 9 files changed, 36 insertions(+), 15 deletions(-) diff --git a/pkgs/ffigen/example/ffinative/headers/example.h b/pkgs/ffigen/example/ffinative/headers/example.h index 2a8fbb960e..82df9c7bd8 100644 --- a/pkgs/ffigen/example/ffinative/headers/example.h +++ b/pkgs/ffigen/example/ffinative/headers/example.h @@ -17,7 +17,9 @@ float *divide(int a, int b); /** Divides 2 floats, returns a pointer to double. */ double *dividePrecision(float a, float b); -const int array[10]; +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"; diff --git a/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart b/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart index c93f361c0b..f95fec28e4 100644 --- a/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart +++ b/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart @@ -51,7 +51,11 @@ external ffi.Pointer dividePrecision( double b, ); -@ffi.Array(10) +@ffi.Native( + assetId: 'package:ffinative_example/generated_bindings.dart') +external int log_level; + +@ffi.Array(5) @ffi.Native>( assetId: 'package:ffinative_example/generated_bindings.dart') external ffi.Array array; @@ -60,6 +64,7 @@ external ffi.Array array; @ffi.Native>( assetId: 'package:ffinative_example/generated_bindings.dart') external final ffi.Pointer library_version; + const _SymbolAddresses addresses = _SymbolAddresses(); class _SymbolAddresses { diff --git a/pkgs/ffigen/example/ffinative/pubspec.yaml b/pkgs/ffigen/example/ffinative/pubspec.yaml index b3094bd6bb..226c26cb6b 100644 --- a/pkgs/ffigen/example/ffinative/pubspec.yaml +++ b/pkgs/ffigen/example/ffinative/pubspec.yaml @@ -5,7 +5,7 @@ name: ffinative_example environment: - sdk: '>=3.3.0-dev <4.0.0' + sdk: '>=3.3.0-252.0.dev <4.0.0' dependencies: ffi: ^2.0.1 diff --git a/pkgs/ffigen/lib/src/code_generator/func.dart b/pkgs/ffigen/lib/src/code_generator/func.dart index e0439f357a..c7f84ba287 100644 --- a/pkgs/ffigen/lib/src/code_generator/func.dart +++ b/pkgs/ffigen/lib/src/code_generator/func.dart @@ -150,7 +150,8 @@ class Func extends LookUpBinding { ${makeNativeAnnotation( w, nativeType: cType, - differentName: originalName != nativeFuncName ? originalName : null, + dartName: nativeFuncName, + nativeSymbolName: originalName, assetId: ffiNativeConfig.assetId, isLeaf: isLeaf, )} diff --git a/pkgs/ffigen/lib/src/code_generator/global.dart b/pkgs/ffigen/lib/src/code_generator/global.dart index 4659dd5760..512cdef91d 100644 --- a/pkgs/ffigen/lib/src/code_generator/global.dart +++ b/pkgs/ffigen/lib/src/code_generator/global.dart @@ -58,7 +58,8 @@ class Global extends LookUpBinding { w, nativeType: cType, assetId: nativeConfig.assetId, - differentName: globalVarName != originalName ? originalName : null, + dartName: globalVarName, + nativeSymbolName: originalName, isLeaf: false, )) ..write('external '); @@ -66,7 +67,7 @@ class Global extends LookUpBinding { s.write('final '); } - s.writeln('$dartType $globalVarName;'); + s.writeln('$dartType $globalVarName;\n'); if (exposeSymbolAddress) { w.symbolAddressWriter.addNativeSymbol( diff --git a/pkgs/ffigen/lib/src/code_generator/utils.dart b/pkgs/ffigen/lib/src/code_generator/utils.dart index 67d6adfd19..a7fee731b6 100644 --- a/pkgs/ffigen/lib/src/code_generator/utils.dart +++ b/pkgs/ffigen/lib/src/code_generator/utils.dart @@ -84,13 +84,14 @@ String makeDoc(String text) { String makeNativeAnnotation( Writer w, { required String? nativeType, - String? differentName, + required String dartName, + required String nativeSymbolName, String? assetId, bool isLeaf = false, }) { final args = <(String, String)>[]; - if (differentName != null) { - args.add(('symbol', '"$differentName"')); + if (dartName != nativeSymbolName) { + args.add(('symbol', '"$nativeSymbolName"')); } if (assetId != null) { args.add(('assetId', "'$assetId'")); diff --git a/pkgs/ffigen/pubspec.yaml b/pkgs/ffigen/pubspec.yaml index 94853a0201..40b390c39e 100644 --- a/pkgs/ffigen/pubspec.yaml +++ b/pkgs/ffigen/pubspec.yaml @@ -14,7 +14,7 @@ topics: - codegen environment: - sdk: '>=3.3.0-0 <4.0.0' + sdk: '>=3.3.0-252.0.dev' dependencies: ffi: ^2.0.1 diff --git a/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart b/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart index 6354a75007..7ee979727f 100644 --- a/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart +++ b/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart @@ -519,14 +519,21 @@ void main() { ]), Union(name: 'WithArray', members: [ Member( - name: 'a', type: ConstantArray(10, charType, useArrayType: true)), + name: 'a', + type: ConstantArray(10, charType, useArrayType: true), + ), Member( - name: 'b', type: ConstantArray(10, union1, useArrayType: true)), + name: 'b', + type: ConstantArray(10, union1, useArrayType: true), + ), Member( - name: 'b', type: ConstantArray(10, struct1, useArrayType: true)), + name: 'b', + type: ConstantArray(10, struct1, useArrayType: true), + ), Member( - name: 'c', - type: ConstantArray(10, PointerType(union1), useArrayType: true)), + name: 'c', + type: ConstantArray(10, PointerType(union1), useArrayType: true), + ), ]), ], ); diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart index 920addb84e..858aa4c684 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart @@ -10,13 +10,17 @@ import 'dart:ffi' as ffi; @ffi.Native() external int test1; + @ffi.Native>() external final ffi.Pointer test2; + @ffi.Array(10) @ffi.Native>() external final ffi.Array test3; + @ffi.Native>() external ffi.Pointer test5; + @ffi.Native() external EmptyStruct globalStruct; From cb886818906a5a30c7dfe9a0f5322e09700c2aac Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Tue, 2 Jan 2024 19:34:45 +0100 Subject: [PATCH 13/21] Happy new year dear health check --- .../code_generator_tests/code_generator_test.dart | 2 +- .../_expected_boolean_dartbool_bindings.dart | 2 +- .../_expected_constant_bindings.dart | 2 +- .../_expected_enumclass_bindings.dart | 2 +- .../_expected_function_bindings.dart | 2 +- .../_expected_function_ffiNative_bindings.dart | 2 +- .../_expected_function_n_struct_bindings.dart | 2 +- .../expected_bindings/_expected_global_bindings.dart | 2 +- .../_expected_global_native_bindings.dart | 2 +- ...xpected_internal_conflict_resolution_bindings.dart | 2 +- .../_expected_native_symbol_bindings.dart | 2 +- .../_expected_packed_structs_bindings.dart | 2 +- .../_expected_sort_bindings_bindings.dart | 2 +- .../expected_bindings/_expected_struct_bindings.dart | 2 +- .../_expected_typealias_bindings.dart | 2 +- .../expected_bindings/_expected_unions_bindings.dart | 2 +- .../decl_symbol_address_collision_test.dart | 11 +++++++++-- ...pected_decl_symbol_address_collision_bindings.dart | 4 ++++ 18 files changed, 29 insertions(+), 18 deletions(-) diff --git a/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart b/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart index 7ee979727f..47cb65f911 100644 --- a/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart +++ b/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart @@ -11,7 +11,7 @@ import '../test_utils.dart'; void main() { const licenseHeader = ''' -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2024, 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. '''; diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_boolean_dartbool_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_boolean_dartbool_bindings.dart index f379c7b7d2..733fb53f80 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_boolean_dartbool_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_boolean_dartbool_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2024, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_constant_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_constant_bindings.dart index b47cf7041e..100fb8daeb 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_constant_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_constant_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2024, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_bindings.dart index 80820af15d..7b554ae005 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2024, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_bindings.dart index 886f284994..ebc80340e1 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2024, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_ffiNative_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_ffiNative_bindings.dart index 120567d92b..0133bcea38 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_ffiNative_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_ffiNative_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2024, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_n_struct_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_n_struct_bindings.dart index c8680a8486..c80b680064 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_n_struct_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_n_struct_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2024, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_bindings.dart index 066f9ee0be..90198df49e 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2024, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart index 858aa4c684..a8bd5a259e 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2024, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_internal_conflict_resolution_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_internal_conflict_resolution_bindings.dart index af97952ad4..7530c379c2 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_internal_conflict_resolution_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_internal_conflict_resolution_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2024, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_native_symbol_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_native_symbol_bindings.dart index 234cf2c96d..133853eb1a 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_native_symbol_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_native_symbol_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2024, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_packed_structs_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_packed_structs_bindings.dart index 5c1b17a5bd..7a3beb65ee 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_packed_structs_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_packed_structs_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2024, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_sort_bindings_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_sort_bindings_bindings.dart index 1e9d1dc113..0c0e863dd7 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_sort_bindings_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_sort_bindings_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2024, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_struct_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_struct_bindings.dart index aa862baa7b..8f2a742d4c 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_struct_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_struct_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2024, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_typealias_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_typealias_bindings.dart index 0e1662da5c..b3edfe5ccf 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_typealias_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_typealias_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2024, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_unions_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_unions_bindings.dart index 1d000e5c42..a6ebc33bce 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_unions_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_unions_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2024, 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. diff --git a/pkgs/ffigen/test/collision_tests/decl_symbol_address_collision_test.dart b/pkgs/ffigen/test/collision_tests/decl_symbol_address_collision_test.dart index 0280732ba9..1ee01ae855 100644 --- a/pkgs/ffigen/test/collision_tests/decl_symbol_address_collision_test.dart +++ b/pkgs/ffigen/test/collision_tests/decl_symbol_address_collision_test.dart @@ -9,13 +9,20 @@ import '../test_utils.dart'; late Library actual; void main() { + const licenseHeader = ''' +// Copyright (c) 2024, 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: unused_element, camel_case_types, non_constant_identifier_names +'''; + group('decl_symbol_address_collision_test', () { setUpAll(() { logWarnings(Level.SEVERE); actual = Library( name: 'Bindings', - header: - '// ignore_for_file: unused_element, camel_case_types, non_constant_identifier_names\n', + header: licenseHeader, bindings: [ Struct(name: 'addresses'), Struct(name: '_SymbolAddresses'), diff --git a/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_symbol_address_collision_bindings.dart b/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_symbol_address_collision_bindings.dart index 0c5814b2f8..61939ce3d1 100644 --- a/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_symbol_address_collision_bindings.dart +++ b/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_symbol_address_collision_bindings.dart @@ -1,3 +1,7 @@ +// Copyright (c) 2024, 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: unused_element, camel_case_types, non_constant_identifier_names // AUTO GENERATED FILE, DO NOT EDIT. From 7a858deca18ba5ac17a1768bf6eb70ea721a023d Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Wed, 3 Jan 2024 13:03:25 +0100 Subject: [PATCH 14/21] More review feedback --- .../ffinative/lib/generated_bindings.dart | 2 +- .../lib/src/code_generator/compound.dart | 15 ++------------ .../ffigen/lib/src/code_generator/global.dart | 20 +------------------ pkgs/ffigen/lib/src/code_generator/utils.dart | 13 ++++++++++++ .../ffigen/lib/src/code_generator/writer.dart | 4 ++-- .../code_generator_test.dart | 3 ++- .../_expected_global_native_bindings.dart | 2 +- 7 files changed, 22 insertions(+), 37 deletions(-) diff --git a/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart b/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart index f95fec28e4..be5c2dd019 100644 --- a/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart +++ b/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart @@ -65,7 +65,7 @@ external ffi.Array array; assetId: 'package:ffinative_example/generated_bindings.dart') external final ffi.Pointer library_version; -const _SymbolAddresses addresses = _SymbolAddresses(); +const addresses = _SymbolAddresses(); class _SymbolAddresses { const _SymbolAddresses(); diff --git a/pkgs/ffigen/lib/src/code_generator/compound.dart b/pkgs/ffigen/lib/src/code_generator/compound.dart index 1f9706e307..1cc3697870 100644 --- a/pkgs/ffigen/lib/src/code_generator/compound.dart +++ b/pkgs/ffigen/lib/src/code_generator/compound.dart @@ -80,16 +80,6 @@ abstract class Compound extends BindingType { } } - List _getArrayDimensionLengths(Type type) { - final array = []; - 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<' @@ -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 { diff --git a/pkgs/ffigen/lib/src/code_generator/global.dart b/pkgs/ffigen/lib/src/code_generator/global.dart index 512cdef91d..f335765749 100644 --- a/pkgs/ffigen/lib/src/code_generator/global.dart +++ b/pkgs/ffigen/lib/src/code_generator/global.dart @@ -50,7 +50,7 @@ class Global extends LookUpBinding { if (nativeConfig.enabled) { if (type case final ConstantArray arr) { - arr.generateSizeAnnotation(s, w); + s.writeln(makeArrayAnnotation(w, arr)); } s @@ -116,21 +116,3 @@ class Global extends LookUpBinding { type.addDependencies(dependencies); } } - -extension on ConstantArray { - void generateSizeAnnotation(StringBuffer buffer, Writer w) { - buffer.write('@${w.ffiLibraryPrefix}.Array('); - - Type? array = this; - var first = true; - while (array is ConstantArray) { - if (!first) buffer.write(', '); - - buffer.write(array.length); - first = false; - array = array.baseArrayType; - } - - buffer.writeln(')'); - } -} diff --git a/pkgs/ffigen/lib/src/code_generator/utils.dart b/pkgs/ffigen/lib/src/code_generator/utils.dart index a7fee731b6..4b1f6b6748 100644 --- a/pkgs/ffigen/lib/src/code_generator/utils.dart +++ b/pkgs/ffigen/lib/src/code_generator/utils.dart @@ -3,6 +3,8 @@ // BSD-style license that can be found in the LICENSE file. import 'dart_keywords.dart'; +import 'pointer.dart'; +import 'type.dart'; import 'writer.dart'; class UniqueNamer { @@ -103,3 +105,14 @@ String makeNativeAnnotation( final combinedArgs = args.map((e) => '${e.$1}: ${e.$2}').join(', '); return '@${w.ffiLibraryPrefix}.Native<$nativeType>($combinedArgs)'; } + +String makeArrayAnnotation(Writer w, ConstantArray arrayType) { + final dimensions = []; + Type type = arrayType; + while (type is ConstantArray) { + dimensions.add(type.length); + type = type.child; + } + + return '@${w.ffiLibraryPrefix}.Array.multi([${dimensions.join(', ')}])'; +} diff --git a/pkgs/ffigen/lib/src/code_generator/writer.dart b/pkgs/ffigen/lib/src/code_generator/writer.dart index 3acc5ef73c..77a69da040 100644 --- a/pkgs/ffigen/lib/src/code_generator/writer.dart +++ b/pkgs/ffigen/lib/src/code_generator/writer.dart @@ -361,9 +361,9 @@ class SymbolAddressWriter { final fieldName = w._symbolAddressVariableName; if (hasNonNativeAddress) { - return 'late final $className $fieldName = $className(this);'; + return 'late final $fieldName = $className(this);'; } else { - return 'const $className $fieldName = $className();'; + return 'const $fieldName = $className();'; } } diff --git a/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart b/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart index 47cb65f911..dcf74431e0 100644 --- a/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart +++ b/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart @@ -386,7 +386,8 @@ void main() { NativeType( SupportedNativeType.Int8, ), - // Arrays are always supported in struct fields + // This flag is ignored for struct fields, which always use + // inline arrays. useArrayType: true, ), ), diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart index a8bd5a259e..807504e4ea 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart @@ -14,7 +14,7 @@ external int test1; @ffi.Native>() external final ffi.Pointer test2; -@ffi.Array(10) +@ffi.Array.multi([10]) @ffi.Native>() external final ffi.Array test3; From 2f96aaa93dcf9078a76eb8c18560a5d89c7127b5 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Wed, 3 Jan 2024 13:30:13 +0100 Subject: [PATCH 15/21] Fix tests --- pkgs/ffigen/example/ffinative/lib/generated_bindings.dart | 2 +- pkgs/ffigen/example/libclang-example/generated_bindings.dart | 2 +- .../_expected_decl_symbol_address_collision_bindings.dart | 2 +- .../expected_bindings/_expected_functions_bindings.dart | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart b/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart index be5c2dd019..485ce23c1f 100644 --- a/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart +++ b/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart @@ -55,7 +55,7 @@ external ffi.Pointer dividePrecision( assetId: 'package:ffinative_example/generated_bindings.dart') external int log_level; -@ffi.Array(5) +@ffi.Array.multi([5]) @ffi.Native>( assetId: 'package:ffinative_example/generated_bindings.dart') external ffi.Array array; diff --git a/pkgs/ffigen/example/libclang-example/generated_bindings.dart b/pkgs/ffigen/example/libclang-example/generated_bindings.dart index 3351a661c6..7cf663e388 100644 --- a/pkgs/ffigen/example/libclang-example/generated_bindings.dart +++ b/pkgs/ffigen/example/libclang-example/generated_bindings.dart @@ -6827,7 +6827,7 @@ class LibClang { late final _clang_Type_visitFields = _clang_Type_visitFieldsPtr.asFunction(); - late final _SymbolAddresses addresses = _SymbolAddresses(this); + late final addresses = _SymbolAddresses(this); } class _SymbolAddresses { diff --git a/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_symbol_address_collision_bindings.dart b/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_symbol_address_collision_bindings.dart index 61939ce3d1..0bd74d6f43 100644 --- a/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_symbol_address_collision_bindings.dart +++ b/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_symbol_address_collision_bindings.dart @@ -42,7 +42,7 @@ class Bindings1 { late final __SymbolAddresses_1 = __SymbolAddresses_1Ptr.asFunction(); - late final _SymbolAddresses1 addresses = _SymbolAddresses1(this); + late final addresses = _SymbolAddresses1(this); } class _SymbolAddresses1 { diff --git a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_functions_bindings.dart b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_functions_bindings.dart index 28db51f016..7475b09d3a 100644 --- a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_functions_bindings.dart +++ b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_functions_bindings.dart @@ -132,7 +132,7 @@ class NativeLibrary { ffi.Char Function(ffi.UnsignedChar, ffi.SignedChar)>>('diffChars'); late final _diffChars = _diffCharsPtr.asFunction(); - late final _SymbolAddresses addresses = _SymbolAddresses(this); + late final addresses = _SymbolAddresses(this); } class _SymbolAddresses { From 0abde28eb9f702c253c30bf700ffa337e2eca0d9 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Wed, 3 Jan 2024 13:33:49 +0100 Subject: [PATCH 16/21] Use dev SDK --- .github/workflows/health.yaml | 1 + .github/workflows/publish.yaml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/health.yaml b/.github/workflows/health.yaml index 0e0c19460b..4537a71590 100644 --- a/.github/workflows/health.yaml +++ b/.github/workflows/health.yaml @@ -10,5 +10,6 @@ jobs: coverage_web: false checks: "version,changelog,license,do-not-submit,breaking" use-flutter: true + sdk: dev permissions: pull-requests: write diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 4c00b141b6..111e4ec748 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -17,4 +17,4 @@ jobs: pull-requests: write # Required for writing the pull request note with: write-comments: false - sdk: beta + sdk: dev From 4021f284d03fbdfae09c99e0f598bcc0857fce4c Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Wed, 3 Jan 2024 13:38:27 +0100 Subject: [PATCH 17/21] Bring back upper SDK bound --- pkgs/ffigen/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/ffigen/pubspec.yaml b/pkgs/ffigen/pubspec.yaml index 9f7ae3009b..20703e3310 100644 --- a/pkgs/ffigen/pubspec.yaml +++ b/pkgs/ffigen/pubspec.yaml @@ -14,7 +14,7 @@ topics: - codegen environment: - sdk: '>=3.3.0-252.0.dev' + sdk: '>=3.3.0-252.0.dev <4.0.0' dependencies: ffi: ^2.0.1 From 81bce63f74a4889f674b172c4dadb449cee55374 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Wed, 3 Jan 2024 13:40:31 +0100 Subject: [PATCH 18/21] Remove version from health job --- .github/workflows/health.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/health.yaml b/.github/workflows/health.yaml index 4537a71590..0e0c19460b 100644 --- a/.github/workflows/health.yaml +++ b/.github/workflows/health.yaml @@ -10,6 +10,5 @@ jobs: coverage_web: false checks: "version,changelog,license,do-not-submit,breaking" use-flutter: true - sdk: dev permissions: pull-requests: write From 127e5b19a62b9dffce424ebb82ce812263dd6155 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Wed, 3 Jan 2024 21:55:00 +0100 Subject: [PATCH 19/21] Add comments for 3.3 release --- .github/workflows/ffigen.yml | 2 +- .github/workflows/ffigen_weekly.yml | 2 +- .github/workflows/publish.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ffigen.yml b/.github/workflows/ffigen.yml index 2099353457..ab75de5eb8 100644 --- a/.github/workflows/ffigen.yml +++ b/.github/workflows/ffigen.yml @@ -29,7 +29,7 @@ jobs: fail-fast: false matrix: sdk: [dev] -# sdk: [3.2.0] +# sdk: [3.3.0] steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d diff --git a/.github/workflows/ffigen_weekly.yml b/.github/workflows/ffigen_weekly.yml index c3720a05da..80488b7ba3 100644 --- a/.github/workflows/ffigen_weekly.yml +++ b/.github/workflows/ffigen_weekly.yml @@ -22,7 +22,7 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: - sdk: dev #3.2.0 + sdk: dev #3.3.0 - name: Install dependencies run: dart pub get - name: Build test dylib and bindings diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 111e4ec748..c7f1d2cde5 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -17,4 +17,4 @@ jobs: pull-requests: write # Required for writing the pull request note with: write-comments: false - sdk: dev + sdk: dev # use beta/stable after 3.3.0 From ba586afffde93987d0327320e01205ea1e59751d Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 4 Jan 2024 11:35:44 +0100 Subject: [PATCH 20/21] Update health.yaml --- .github/workflows/health.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/health.yaml b/.github/workflows/health.yaml index 0e0c19460b..72e04d29d9 100644 --- a/.github/workflows/health.yaml +++ b/.github/workflows/health.yaml @@ -10,5 +10,6 @@ jobs: coverage_web: false checks: "version,changelog,license,do-not-submit,breaking" use-flutter: true + sdk: master permissions: pull-requests: write From 3c5bb800bf21fd5c881ac0b9ee57fa8475d3b248 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Mon, 8 Jan 2024 23:13:02 +0100 Subject: [PATCH 21/21] Revert license header change in test --- .github/workflows/ffigen.yml | 6 ++-- .../ffinative/lib/generated_bindings.dart | 27 +++++++---------- pkgs/ffigen/lib/src/code_generator/func.dart | 1 - .../ffigen/lib/src/code_generator/global.dart | 1 - .../lib/src/code_generator/library.dart | 15 +++++++--- pkgs/ffigen/lib/src/code_generator/utils.dart | 4 --- .../ffigen/lib/src/code_generator/writer.dart | 15 ++++++++++ .../code_generator_test.dart | 30 ++++++++++--------- .../_expected_boolean_dartbool_bindings.dart | 2 +- .../_expected_constant_bindings.dart | 2 +- .../_expected_enumclass_bindings.dart | 2 +- .../_expected_function_bindings.dart | 2 +- ..._expected_function_ffiNative_bindings.dart | 5 +++- .../_expected_function_n_struct_bindings.dart | 2 +- .../_expected_global_bindings.dart | 2 +- .../_expected_global_native_bindings.dart | 5 +++- ...internal_conflict_resolution_bindings.dart | 2 +- .../_expected_native_symbol_bindings.dart | 2 +- .../_expected_packed_structs_bindings.dart | 2 +- .../_expected_sort_bindings_bindings.dart | 2 +- .../_expected_struct_bindings.dart | 2 +- .../_expected_typealias_bindings.dart | 2 +- .../_expected_unions_bindings.dart | 2 +- .../decl_symbol_address_collision_test.dart | 11 ++----- ...ecl_symbol_address_collision_bindings.dart | 4 --- 25 files changed, 79 insertions(+), 71 deletions(-) diff --git a/.github/workflows/ffigen.yml b/.github/workflows/ffigen.yml index ab75de5eb8..4c290e779e 100644 --- a/.github/workflows/ffigen.yml +++ b/.github/workflows/ffigen.yml @@ -57,7 +57,7 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: - sdk: dev #3.2.0 + sdk: dev #3.3.0 - name: Install dependencies run: dart pub get - name: Install libclang-14-dev @@ -78,7 +78,7 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: - sdk: dev #3.2.0 + sdk: dev #3.3.0 - name: Install dependencies run: dart pub get - name: Build test dylib and bindings @@ -111,7 +111,7 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d with: - sdk: dev #3.2.0 + sdk: dev #3.3.0 - name: Install dependencies run: dart pub get - name: Build test dylib and bindings diff --git a/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart b/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart index 485ce23c1f..39e098469a 100644 --- a/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart +++ b/pkgs/ffigen/example/ffinative/lib/generated_bindings.dart @@ -8,61 +8,56 @@ // // 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( - assetId: 'package:ffinative_example/generated_bindings.dart') +@ffi.Native() external int sum( int a, int b, ); /// Subtracts 2 integers. -@ffi.Native( - assetId: 'package:ffinative_example/generated_bindings.dart') +@ffi.Native() external int subtract( int a, int b, ); /// Multiplies 2 integers, returns pointer to an integer,. -@ffi.Native Function(ffi.Int, ffi.Int)>( - assetId: 'package:ffinative_example/generated_bindings.dart') +@ffi.Native Function(ffi.Int, ffi.Int)>() external ffi.Pointer multiply( int a, int b, ); /// Divides 2 integers, returns pointer to a float. -@ffi.Native Function(ffi.Int, ffi.Int)>( - assetId: 'package:ffinative_example/generated_bindings.dart') +@ffi.Native Function(ffi.Int, ffi.Int)>() external ffi.Pointer divide( int a, int b, ); /// Divides 2 floats, returns a pointer to double. -@ffi.Native Function(ffi.Float, ffi.Float)>( - assetId: 'package:ffinative_example/generated_bindings.dart') +@ffi.Native Function(ffi.Float, ffi.Float)>() external ffi.Pointer dividePrecision( double a, double b, ); -@ffi.Native( - assetId: 'package:ffinative_example/generated_bindings.dart') +@ffi.Native() external int log_level; @ffi.Array.multi([5]) -@ffi.Native>( - assetId: 'package:ffinative_example/generated_bindings.dart') +@ffi.Native>() external ffi.Array array; /// Version of the native C library -@ffi.Native>( - assetId: 'package:ffinative_example/generated_bindings.dart') +@ffi.Native>() external final ffi.Pointer library_version; const addresses = _SymbolAddresses(); diff --git a/pkgs/ffigen/lib/src/code_generator/func.dart b/pkgs/ffigen/lib/src/code_generator/func.dart index c7f84ba287..1c518f9f68 100644 --- a/pkgs/ffigen/lib/src/code_generator/func.dart +++ b/pkgs/ffigen/lib/src/code_generator/func.dart @@ -152,7 +152,6 @@ ${makeNativeAnnotation( nativeType: cType, dartName: nativeFuncName, nativeSymbolName: originalName, - assetId: ffiNativeConfig.assetId, isLeaf: isLeaf, )} external $ffiReturnType $nativeFuncName($ffiArgDeclString); diff --git a/pkgs/ffigen/lib/src/code_generator/global.dart b/pkgs/ffigen/lib/src/code_generator/global.dart index f335765749..439a2f3262 100644 --- a/pkgs/ffigen/lib/src/code_generator/global.dart +++ b/pkgs/ffigen/lib/src/code_generator/global.dart @@ -57,7 +57,6 @@ class Global extends LookUpBinding { ..writeln(makeNativeAnnotation( w, nativeType: cType, - assetId: nativeConfig.assetId, dartName: globalVarName, nativeSymbolName: originalName, isLeaf: false, diff --git a/pkgs/ffigen/lib/src/code_generator/library.dart b/pkgs/ffigen/lib/src/code_generator/library.dart index 41774e62f3..60ad7c3ffb 100644 --- a/pkgs/ffigen/lib/src/code_generator/library.dart +++ b/pkgs/ffigen/lib/src/code_generator/library.dart @@ -56,14 +56,20 @@ class Library { // Seperate bindings which require lookup. final lookupBindings = []; final nativeBindings = []; + FfiNativeConfig? nativeConfig; for (final binding in this.bindings.whereType()) { - final usesLookup = switch (binding) { - Func() => !binding.ffiNativeConfig.enabled, - Global() => !binding.nativeConfig.enabled, - _ => true, + final nativeConfigForBinding = switch (binding) { + Func() => binding.ffiNativeConfig, + Global() => binding.nativeConfig, + _ => null, }; + // At the moment, all bindings share their native config. + nativeConfig ??= nativeConfigForBinding; + + final usesLookup = + nativeConfigForBinding == null || !nativeConfigForBinding.enabled; (usesLookup ? lookupBindings : nativeBindings).add(binding); } final noLookUpBindings = @@ -72,6 +78,7 @@ class Library { _writer = Writer( lookUpBindings: lookupBindings, ffiNativeBindings: nativeBindings, + nativeAssetId: nativeConfig?.assetId, noLookUpBindings: noLookUpBindings, className: name, classDocComment: description, diff --git a/pkgs/ffigen/lib/src/code_generator/utils.dart b/pkgs/ffigen/lib/src/code_generator/utils.dart index 4b1f6b6748..4bad8e3dd3 100644 --- a/pkgs/ffigen/lib/src/code_generator/utils.dart +++ b/pkgs/ffigen/lib/src/code_generator/utils.dart @@ -88,16 +88,12 @@ String makeNativeAnnotation( required String? nativeType, required String dartName, required String nativeSymbolName, - String? assetId, bool isLeaf = false, }) { final args = <(String, String)>[]; if (dartName != nativeSymbolName) { args.add(('symbol', '"$nativeSymbolName"')); } - if (assetId != null) { - args.add(('assetId', "'$assetId'")); - } if (isLeaf) { args.add(('isLeaf', 'true')); } diff --git a/pkgs/ffigen/lib/src/code_generator/writer.dart b/pkgs/ffigen/lib/src/code_generator/writer.dart index 77a69da040..8193de1c0b 100644 --- a/pkgs/ffigen/lib/src/code_generator/writer.dart +++ b/pkgs/ffigen/lib/src/code_generator/writer.dart @@ -23,6 +23,9 @@ class Writer { /// Holds bindings which don't lookup symbols. final List noLookUpBindings; + /// The default asset id to use for [ffiNativeBindings]. + final String? nativeAssetId; + /// Manages the `_SymbolAddress` class. final symbolAddressWriter = SymbolAddressWriter(); @@ -99,6 +102,7 @@ class Writer { required this.ffiNativeBindings, required this.noLookUpBindings, required String className, + required this.nativeAssetId, Set? additionalImports, this.classDocComment, this.header, @@ -224,6 +228,17 @@ class Writer { result.write(makeDoc('ignore_for_file: type=lint')); } + // If there are any @Native bindings, the file needs to have an + // `@DefaultAsset` annotation for the symbols to resolve properly. This + // avoids duplicating the asset on every element. + // Since the annotation goes on a `library;` directive, it needs to appear + // before other definitions in the file. + if (ffiNativeBindings.isNotEmpty && nativeAssetId != null) { + result + ..writeln("@$ffiLibraryPrefix.DefaultAsset('$nativeAssetId')") + ..writeln('library;\n'); + } + /// Write [lookUpBindings]. if (lookUpBindings.isNotEmpty) { // Write doc comment for wrapper class. diff --git a/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart b/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart index dcf74431e0..c9de2e13a5 100644 --- a/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart +++ b/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart @@ -11,28 +11,30 @@ import '../test_utils.dart'; void main() { const licenseHeader = ''' -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2023, 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. '''; group('code_generator: ', () { @isTestGroup - void withAndWithoutNative(String description, void Function(bool) runTest) { + void withAndWithoutNative( + String description, void Function(FfiNativeConfig) runTest) { group(description, () { - test('without Native', () => runTest(false)); - test('with Native', () => runTest(true)); + test('without Native', () => runTest(FfiNativeConfig(enabled: false))); + test('with Native', + () => runTest(FfiNativeConfig(enabled: true, assetId: 'test'))); }); } withAndWithoutNative('Function Binding (primitives, pointers)', - (enableFfiNative) { + (nativeConfig) { final library = Library( name: 'Bindings', header: licenseHeader, bindings: [ Func( - ffiNativeConfig: FfiNativeConfig(enabled: enableFfiNative), + ffiNativeConfig: nativeConfig, name: 'noParam', dartDoc: 'Just a test function\nheres another line', returnType: NativeType( @@ -40,7 +42,7 @@ void main() { ), ), Func( - ffiNativeConfig: FfiNativeConfig(enabled: enableFfiNative), + ffiNativeConfig: nativeConfig, name: 'withPrimitiveParam', parameters: [ Parameter( @@ -61,7 +63,7 @@ void main() { ), ), Func( - ffiNativeConfig: FfiNativeConfig(enabled: enableFfiNative), + ffiNativeConfig: nativeConfig, name: 'withPointerParam', parameters: [ Parameter( @@ -90,7 +92,7 @@ void main() { ), ), Func( - ffiNativeConfig: FfiNativeConfig(enabled: enableFfiNative), + ffiNativeConfig: nativeConfig, isLeaf: true, name: 'leafFunc', dartDoc: 'A function with isLeaf: true', @@ -109,7 +111,8 @@ void main() { ], ); - _matchLib(library, enableFfiNative ? 'function_ffiNative' : 'function'); + _matchLib( + library, nativeConfig.enabled ? 'function_ffiNative' : 'function'); }); test('Struct Binding (primitives, pointers)', () { @@ -254,12 +257,11 @@ void main() { }); withAndWithoutNative('global (primitives, pointers, pointer to struct)', - (enableNative) { + (nativeConfig) { final structSome = Struct( name: 'Some', ); final emptyGlobalStruct = Struct(name: 'EmptyStruct'); - final nativeConfig = FfiNativeConfig(enabled: enableNative); final library = Library( name: 'Bindings', @@ -290,7 +292,7 @@ void main() { NativeType( SupportedNativeType.Float, ), - useArrayType: enableNative, + useArrayType: nativeConfig.enabled, ), constant: true, ), @@ -310,7 +312,7 @@ void main() { ), ], ); - _matchLib(library, enableNative ? 'global_native' : 'global'); + _matchLib(library, nativeConfig.enabled ? 'global_native' : 'global'); }); test('constant', () { diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_boolean_dartbool_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_boolean_dartbool_bindings.dart index 733fb53f80..f379c7b7d2 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_boolean_dartbool_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_boolean_dartbool_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2023, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_constant_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_constant_bindings.dart index 100fb8daeb..b47cf7041e 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_constant_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_constant_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2023, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_bindings.dart index 7b554ae005..80820af15d 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2023, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_bindings.dart index ebc80340e1..886f284994 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2023, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_ffiNative_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_ffiNative_bindings.dart index 0133bcea38..e77b71487f 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_ffiNative_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_ffiNative_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2023, 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. @@ -6,6 +6,9 @@ // // Generated by `package:ffigen`. // ignore_for_file: type=lint +@ffi.DefaultAsset('test') +library; + import 'dart:ffi' as ffi; /// Just a test function diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_n_struct_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_n_struct_bindings.dart index c80b680064..c8680a8486 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_n_struct_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_n_struct_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2023, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_bindings.dart index 90198df49e..066f9ee0be 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2023, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart index 807504e4ea..601c079d5a 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2023, 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. @@ -6,6 +6,9 @@ // // Generated by `package:ffigen`. // ignore_for_file: type=lint +@ffi.DefaultAsset('test') +library; + import 'dart:ffi' as ffi; @ffi.Native() diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_internal_conflict_resolution_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_internal_conflict_resolution_bindings.dart index 7530c379c2..af97952ad4 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_internal_conflict_resolution_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_internal_conflict_resolution_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2023, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_native_symbol_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_native_symbol_bindings.dart index 133853eb1a..234cf2c96d 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_native_symbol_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_native_symbol_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2023, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_packed_structs_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_packed_structs_bindings.dart index 7a3beb65ee..5c1b17a5bd 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_packed_structs_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_packed_structs_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2023, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_sort_bindings_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_sort_bindings_bindings.dart index 0c0e863dd7..1e9d1dc113 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_sort_bindings_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_sort_bindings_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2023, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_struct_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_struct_bindings.dart index 8f2a742d4c..aa862baa7b 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_struct_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_struct_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2023, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_typealias_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_typealias_bindings.dart index b3edfe5ccf..0e1662da5c 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_typealias_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_typealias_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2023, 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. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_unions_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_unions_bindings.dart index a6ebc33bce..1d000e5c42 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_unions_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_unions_bindings.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2023, 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. diff --git a/pkgs/ffigen/test/collision_tests/decl_symbol_address_collision_test.dart b/pkgs/ffigen/test/collision_tests/decl_symbol_address_collision_test.dart index 1ee01ae855..0280732ba9 100644 --- a/pkgs/ffigen/test/collision_tests/decl_symbol_address_collision_test.dart +++ b/pkgs/ffigen/test/collision_tests/decl_symbol_address_collision_test.dart @@ -9,20 +9,13 @@ import '../test_utils.dart'; late Library actual; void main() { - const licenseHeader = ''' -// Copyright (c) 2024, 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: unused_element, camel_case_types, non_constant_identifier_names -'''; - group('decl_symbol_address_collision_test', () { setUpAll(() { logWarnings(Level.SEVERE); actual = Library( name: 'Bindings', - header: licenseHeader, + header: + '// ignore_for_file: unused_element, camel_case_types, non_constant_identifier_names\n', bindings: [ Struct(name: 'addresses'), Struct(name: '_SymbolAddresses'), diff --git a/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_symbol_address_collision_bindings.dart b/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_symbol_address_collision_bindings.dart index 0bd74d6f43..0d5473f942 100644 --- a/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_symbol_address_collision_bindings.dart +++ b/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_symbol_address_collision_bindings.dart @@ -1,7 +1,3 @@ -// Copyright (c) 2024, 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: unused_element, camel_case_types, non_constant_identifier_names // AUTO GENERATED FILE, DO NOT EDIT.