-
Notifications
You must be signed in to change notification settings - Fork 113
[ffigen] skip SWIFT_UNAVAILABLE #3208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Hassnaa9
wants to merge
11
commits into
dart-lang:main
Choose a base branch
from
Hassnaa9:fix/swift-unavail
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
51f7a4d
fix(ffigen): skip SWIFT_UNAVAILABLE methods and suppress inherited no…
Hassnaa9 8575536
refactoring: move SWIFT_UNAVAILABLE guard to codegen time
Hassnaa9 01c3b27
fix(ffigen): add ObjCMethod.unavailable and filter SWIFT_UNAVAILABLE …
Hassnaa9 099f226
fix:_getAvailability bug and completly apply enhanced approach
Hassnaa9 2abf7b7
regen
liamappelbe 13c429d
regen bindings
liamappelbe 5ce8854
filter SWIFT_UNAVAILABLE and always-unavailable/deprecated ObjC metho…
Hassnaa9 c55ea69
Merge branch 'main' into fix/swift-unavail
Hassnaa9 8b7c398
Update CHANGELOG.md with recent changes
Hassnaa9 0e3652d
Update CHANGELOG with recent changes and fixes
Hassnaa9 d51c1ee
test remove treatSwiftUnavailableAsUnavailable logic&revert deprecate…
Hassnaa9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
pkgs/ffigen/test/native_objc_test/swift_unavailable_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // Copyright (c) 2025, 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. | ||
|
|
||
| // Objective C support is only available on mac. | ||
| @TestOn('mac-os') | ||
| library; | ||
|
|
||
| import 'dart:io'; | ||
|
|
||
| import 'package:ffigen/ffigen.dart'; | ||
| import 'package:path/path.dart' as path; | ||
| import 'package:test/test.dart'; | ||
|
|
||
| import '../test_utils.dart'; | ||
|
|
||
| void main() { | ||
| group('swift_unavailable', () { | ||
| late final String bindings; | ||
|
|
||
| setUpAll(() { | ||
| FfiGenerator( | ||
| output: Output( | ||
| dartFile: Uri.file( | ||
| path.join( | ||
| packagePathForTests, | ||
| 'test', | ||
| 'native_objc_test', | ||
| 'swift_unavailable_bindings.dart', | ||
| ), | ||
| ), | ||
| format: false, | ||
| style: const DynamicLibraryBindings( | ||
| wrapperName: 'SwiftUnavailableTestLibrary', | ||
| wrapperDocComment: 'Tests SWIFT_UNAVAILABLE annotation', | ||
| ), | ||
| ), | ||
| headers: Headers( | ||
| entryPoints: [ | ||
| Uri.file( | ||
| path.join( | ||
| packagePathForTests, | ||
| 'test', | ||
| 'native_objc_test', | ||
| 'swift_unavailable_test.m', | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| objectiveC: ObjectiveC( | ||
| interfaces: Interfaces( | ||
| include: (decl) => {'Animal'}.contains(decl.originalName), | ||
| ), | ||
| ), | ||
| ).generate(logger: createTestLogger()); | ||
|
|
||
| bindings = File( | ||
| path.join( | ||
| packagePathForTests, | ||
| 'test', | ||
| 'native_objc_test', | ||
| 'swift_unavailable_bindings.dart', | ||
| ), | ||
| ).readAsStringSync(); | ||
| }); | ||
|
|
||
| test('initWithName is generated (designated initializer)', () { | ||
| expect(bindings, contains('initWithName')); | ||
| }); | ||
|
|
||
| test('init is NOT generated (SWIFT_UNAVAILABLE)', () { | ||
| expect(RegExp(r"'init'\b").hasMatch(bindings), isFalse); | ||
| }); | ||
|
|
||
| test('new is NOT generated (SWIFT_UNAVAILABLE_MSG)', () { | ||
| expect(bindings, isNot(contains("'new'"))); | ||
| }); | ||
|
|
||
| test('no-arg Animal() constructor is NOT generated', () { | ||
| expect(bindings, isNot(contains('Animal()'))); | ||
| }); | ||
| }); | ||
| } |
20 changes: 20 additions & 0 deletions
20
pkgs/ffigen/test/native_objc_test/swift_unavailable_test.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Copyright (c) 2025, 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 <Foundation/Foundation.h> | ||
|
|
||
| #define SWIFT_UNAVAILABLE \ | ||
| __attribute__((availability(swift, unavailable))) | ||
| #define SWIFT_UNAVAILABLE_MSG(msg) \ | ||
| __attribute__((availability(swift, unavailable, message = msg))) | ||
| #define OBJC_DESIGNATED_INITIALIZER \ | ||
| __attribute__((objc_designated_initializer)) | ||
|
|
||
| @interface Animal : NSObject | ||
| @property(nonatomic, copy) NSString* _Nonnull name; | ||
| - (nonnull instancetype)initWithName:(NSString* _Nonnull)name | ||
| OBJC_DESIGNATED_INITIALIZER; | ||
| - (nonnull instancetype)init SWIFT_UNAVAILABLE; | ||
| + (nonnull instancetype)new SWIFT_UNAVAILABLE_MSG("-init is unavailable"); | ||
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still necessary? I thought your fixes to the deprecated test meant you didn't need this extra treatSwiftUnavailableAsUnavailable logic anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liamappelbe The deprecated fix means the guard isn't needed for filterMethods. But it still needed for _shouldReplaceMethod. Without it _shouldReplaceMethod block NSObject's methods from being copied to subclasses, So when i tried to remove it, alot of tests fail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok, then the correct fix is to update
_shouldReplaceMethodwith this special case. Is this issue specific toNSObject, or does it apply to allisObjCImports? Could you upload a version of the PR that shows those errors, so I can see them on the bots?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liamappelbe Yeah it's apply to all
isObjCImports, Do you want me to push a version without the guard so you can see the failures on CI?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Hassnaa9 yes please. I'm curious about the error.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liamappelbe Ok, i pushed it