Skip to content

[ffigen] propagate deprecated attributes into generated dart bindings#3301

Open
Hassnaa9 wants to merge 2 commits intodart-lang:mainfrom
Hassnaa9:fix/propagate-deprecated-annotations
Open

[ffigen] propagate deprecated attributes into generated dart bindings#3301
Hassnaa9 wants to merge 2 commits intodart-lang:mainfrom
Hassnaa9:fix/propagate-deprecated-annotations

Conversation

@Hassnaa9
Copy link
Copy Markdown
Contributor

Fixes #3020
Propagates @deprecated('...') annotations from C/ObjC headers into generated Dart bindings.

@Hassnaa9
Copy link
Copy Markdown
Contributor Author

Hi @liamappelbe
After i follow your suggested steps here
i notice that there are two sources of deprecation info in libclang:
attribute((deprecated("msg"))) -> sets alwaysDeprecated=true and populates the deprecated_message output param of clang_getCursorPlatformAvailability, which was previously passed as nullptr and ignored
API_DEPRECATED("msg", ios(x,y)) -> message lives in platform[i].Message inside the platform availability array

@liamappelbe liamappelbe self-requested a review April 13, 2026 00:15
@github-actions
Copy link
Copy Markdown

PR Health

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?

This check can be disabled by tagging the PR with skip-breaking-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

Copy link
Copy Markdown
Contributor

@liamappelbe liamappelbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good. The CI failures are just outdated bindings. I'll regenerate them for you once we've resolved the other issues.

final deprecatedPrefix = deprecatedAnnotation != null
? '$deprecatedAnnotation\n '
: '';
s.write('\n $deprecatedPrefix${makeDartDoc(dartDoc)} ');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separate s.write calls would make more sense, like you have in the other cases.

String? get deprecatedAnnotation {
if (!isDeprecated) return null;
final msg = _effectiveDeprecationMessage;
final escaped = msg.replaceAll(r'\', r'\\').replaceAll("'", r"\'");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a util for escaping strings, here. It operates on Pointer<Char>, so the easiest way to use it is probably while converting the native string to a dart string.

Another option would be to refactor that util so that it operates on Dart strings, and do the conversion as a separate step (that's probably the better design, but refactoring that function would be more work).

if (deprecationMessage != null && deprecationMessage!.isNotEmpty) {
return deprecationMessage!;
}
final platformMsg = ios?.message ?? macos?.message;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the messages are different, can you report both, with "iOS:" or "macOS:" at the start?

expect(
trimmed,
contains('''
/// DeprecatedInterface
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this deleted?

final trimmed = bindings.split('\n').map((l) => l.trim()).join('\n');
expect(
trimmed,
isNot(contains("@Deprecated('Deprecated')\nint normalMethod")),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multi-line strings are easier to read here. Like the other tests.

@Hassnaa9 Hassnaa9 requested a review from liamappelbe April 14, 2026 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ffigen] propagate deprecated attributes into generated dart bindings

2 participants