-
Notifications
You must be signed in to change notification settings - Fork 49
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
Support @Native
fields and addressOf
#860
Conversation
@Native
field and addressOf
@Native
fields and addressOf
You're on a roll @simolus3 ! 🔥
As long as the FFIgen version itself is a WIP or dev release we can track an SDK constraint that is a dev/beta. When FFIgen was it's own repo, we had a stable branch for making releases against the stable branch. https://github.com/dart-lang/ffigen/wiki/Branches I haven't thought about a process yet in the mono-repo world. cc @liamappelbe looking at the FFIgen changelog, we have |
PR HealthBreaking changes ✔️Details
Changelog Entry ✔️Details
Changes to files need to be accounted for in their respective changelogs. Coverage
|
File | Coverage |
---|---|
pkgs/ffigen/example/ffinative/lib/generated_bindings.dart | 💔 Not covered |
pkgs/ffigen/lib/src/code_generator/compound.dart | 💔 98 % ⬇️ 0 % |
pkgs/ffigen/lib/src/code_generator/func.dart | 💚 80 % ⬆️ 1 % |
pkgs/ffigen/lib/src/code_generator/global.dart | 💚 98 % ⬆️ 1 % |
pkgs/ffigen/lib/src/code_generator/imports.dart | 💚 81 % ⬆️ 0 % |
pkgs/ffigen/lib/src/code_generator/library.dart | 💚 91 % ⬆️ 2 % |
pkgs/ffigen/lib/src/code_generator/pointer.dart | 💚 47 % ⬆️ 16 % |
pkgs/ffigen/lib/src/code_generator/utils.dart | 💚 95 % ⬆️ 2 % |
pkgs/ffigen/lib/src/code_generator/writer.dart | 💚 93 % ⬆️ 1 % |
pkgs/ffigen/lib/src/header_parser/sub_parsers/var_parser.dart | 💚 95 % ⬆️ 10 % |
pkgs/ffigen/lib/src/header_parser/type_extractor/extractor.dart | 💚 78 % ⬆️ 0 % |
pkgs/ffigen/lib/src/header_parser/utils.dart | 💚 88 % |
This check for test coverage is informational (issues shown here will not fail the PR).
This check can be disabled by tagging the PR with skip-coverage-check
The license workflow has encountered an exception and did not complete.
Package publish validation ✔️
Details
Package | Version | Status |
---|---|---|
package:ffigen | 12.0.0-dev | ready to publish |
package:jni | 0.8.0-wip | WIP (no publish necessary) |
package:jnigen | 0.8.0-wip | WIP (no publish necessary) |
package:native_assets_builder | 0.3.1-wip | WIP (no publish necessary) |
package:native_assets_cli | 0.3.3-wip | WIP (no publish necessary) |
package:native_toolchain_c | 0.3.3 | already published at pub.dev |
Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.
Everything should be landed in |
|
It seems to work with that version, thanks. Could you apply the |
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.
LGTM! Thanks @simolus3 ❤️
|
||
/// Adds 2 integers. | ||
@ffi.Native<ffi.Int Function(ffi.Int, ffi.Int)>( | ||
symbol: 'sum', assetId: 'package:ffinative_example/generated_bindings.dart') | ||
assetId: 'package:ffinative_example/generated_bindings.dart') |
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.
Nice, reusing the symbol.
Side note which does not have to be addressed in this CL: Should we consider generating
@DefaultAsset('package:ffinative_example/generated_bindings.dart')
library;
instead of an assetId
in every @Native
?
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.
I think we should do that, especially considering that there can only be a single assetId
in the config file at the moment. But even if we want different asset ids based on symbol patterns, we can always specify the id for those symbols only.
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.
Please file an issue for us to do this later, or add it in this PR.
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.
I've removed the assetId
to generate a @DefaultAsset
annotation instead.
pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart
Show resolved
Hide resolved
FYI @mannprerak2, happy to get your feedback on this PR as well! And, happy new year to you all! 🎉 |
Happy new year to all of you from me as well! If we do a v11 release before this, the |
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.
LGTM with minor nit 👍🏻
P.S Happy new year 🎉
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();'; | ||
} |
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.
Can we skip the type specifier here? I feel it's better to avoid changes in generated code unless neccessary.
pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_global_native_bindings.dart
Outdated
Show resolved
Hide resolved
I've released v11 and removed the label. @mannprerak2 Thanks! I would have missed the array thing! |
Try setting the SDK in https://github.com/dart-lang/native/blob/main/.github/workflows/health.yaml |
Package publishing
Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation. |
.github/workflows/ffigen.yml
Outdated
@@ -28,7 +28,8 @@ jobs: | |||
strategy: | |||
fail-fast: false | |||
matrix: | |||
sdk: [3.2.0] | |||
sdk: [dev] | |||
# sdk: [3.2.0] |
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.
Maybe update the commented stuff to 3.3.0, and file an issue to update this when 3.3.0 beta is released.
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.
Done - #876.
.github/workflows/health.yaml
Outdated
@@ -10,5 +10,6 @@ jobs: | |||
coverage_web: false | |||
checks: "version,changelog,license,do-not-submit,breaking" | |||
use-flutter: true | |||
sdk: dev |
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.
Does it work if you put an actual version number here instead of "dev"?
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.
I think the health check is running as intended, only the publish validation workflow needed the dev version. The health check fails due to a missing license on a golden file which never had a license header (and on the libclang bindings file, which probably shouldn't have a Dart license header).
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.
Right, that should not have a header file.
Though I'm still seeing Dart versio issues on the CI?
Done, found 52 files without license headers
Collecting packages without changed changelogs:
Done, found 5 packages.
Collecting files without license headers in those packages:
Done, found 0 packages with a need for a changelog.
Look for changes in pkgs/ffigen with base ../../../base_repo/pkgs/ffigen
Error: Exception: The current Dart SDK version is 3.2.3.
Because ffigen requires SDK version >=3.3.0-252.0.dev <4.0.0, version solving failed.
You can try the following suggestion to make the pubspec resolve:
* Try using the Dart SDK version: 3.3.0. See https://dart.dev/get-dart.
[...]
Changed 55 dependencies!
1 package has newer versions incompatible with dependency constraints.
Try `dart pub outdated` for more information.
Preparing .
Copying sources from .
Preparing package dependencies for local package .
Resolving dependencies...
The current Dart SDK version is 3.2.3.
Because ffigen requires SDK version >=3.3.0-252.0.dev <4.0.0, version solving failed.
You can try the following suggestion to make the pubspec resolve:
* Try using the Dart SDK version: 3.3.0. See https://dart.dev/get-dart.
Unhandled exception:
PathNotFoundException: Cannot open file, path = 'pkgs/ffigen/report.json' (OS Error: No such file or directory, errno = 2)
#0 _File.throwIfError (dart:io/file_impl.dart:675:7)
#1 _File.openSync (dart:io/file_impl.dart:490:5)
#2 _File.readAsBytesSync (dart:io/file_impl.dart:574:18)
#3 _File.readAsStringSync (dart:io/file_impl.dart:624:18)
#4 Health.breakingCheck (package:firehose/src/health/health.dart:137:41)
#5 Health.healthCheck (package:firehose/src/health/health.dart:82:30)
<asynchronous suspension>
#6 main (file:///opt/hostedtoolcache/flutter/stable-3.16.5-x64/.pub-cache/hosted/pub.dev/firehose-0.4.2/bin/health.dart:32:3)
<asynchronous suspension>
Error: Process completed with exit code 255.
https://github.com/dart-lang/native/actions/runs/7402310627/job/20139919918?pr=860
@mosuem Any guidance on how to make the health check happy?
- We have files in third_party/ folders which require a different license than the Dart one
- In various places the health check fails to resolve the Dart SDK version.
(I'm almost inclined to ignore or disable the health check, as it seems too strict for this repo.)
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.
I will check it out. Thanks for dogfooding the health workflow :)
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.
@simolus3 The CI issues have been resolved. So we can land this after the last small nits are addressed. 🚀
|
||
/// Adds 2 integers. | ||
@ffi.Native<ffi.Int Function(ffi.Int, ffi.Int)>( | ||
symbol: 'sum', assetId: 'package:ffinative_example/generated_bindings.dart') | ||
assetId: 'package:ffinative_example/generated_bindings.dart') |
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.
Please file an issue for us to do this later, or add it in this PR.
@@ -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 |
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.
Shouldn't only the new files have 2024? We don't need to update existing headers.
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.
The problem is that the header for these goldens in defined in code_generator_test.dart
and shared between all of them. So whenever we add a new test, the health check will complain about a newly added file with an old year in its header and we have to update all of them. Since this PR has skipped those checks I have reverted these changes and instead given the new tests a 2023 header as well.
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.
Maybe we should make it conditional later, but lets leave that for another PR and lets get this in!
Thanks @simolus3! 🚀 |
…, shelf, tools, webdev Revisions updated by `dart tools/rev_sdk_deps.dart`. async (https://github.com/dart-lang/async/compare/9924570..e83d054): e83d054 2024-01-08 Futuristic Goo Fix typo (dart-archive/async#262) ecosystem (https://github.com/dart-lang/ecosystem/compare/dc44e82..1e2785d): 1e2785d 2024-01-09 Jacob MacDonald fix saving of comment ids to disk (dart-lang/ecosystem#221) 244a28d 2024-01-09 Moritz Update publish.yaml (dart-lang/ecosystem#217) bab9833 2024-01-09 Moritz Fix health commenting (dart-lang/ecosystem#219) f87e6f4 2024-01-08 Moritz Update health workflow (dart-lang/ecosystem#216) a58c7d8 2024-01-03 Moritz Fix `labeler.yml` (dart-lang/ecosystem#214) leak_tracker (https://github.com/dart-lang/leak_tracker/compare/3d4c0d6..4a5b077): 4a5b077 2024-01-09 Polina Cherkasova Enhance scripting. (dart-lang/leak_tracker#204) e7094f4 2024-01-08 Polina Cherkasova Ignore test helpers. (dart-lang/leak_tracker#196) 6591934 2024-01-03 Polina Cherkasova Handle deprecation in Flutter. (dart-lang/leak_tracker#203) markdown (https://github.com/dart-lang/markdown/compare/d2e7903..7fdfa55): 7fdfa55 2024-01-01 dependabot[bot] Bump actions/stale from 8.0.0 to 9.0.0 (dart-lang/markdown#571) 5fab3a7 2023-12-19 Alex Li ✨ Introduce AlertBlockSyntax (dart-lang/markdown#570) native (https://github.com/dart-lang/native/compare/0605d9a..14f6da1): 14f6da1d 2024-01-09 Simon Binder Support `@Native` fields and `addressOf` (dart-lang/native#860) protobuf (https://github.com/dart-lang/protobuf/compare/20ec685..a293fb9): a293fb9 2024-01-08 Ömer Sinan Ağacan Handle deprecated options in grpc services and methods, enum types and values, messages (google/protobuf.dart#908) 9a408a7 2024-01-08 Ömer Sinan Ağacan Generate docs of enums and rpc clients, some refactoring (google/protobuf.dart#909) c4fd596 2024-01-06 Ömer Sinan Ağacan Export GeneratedMessageGenericExtensions in generated files (google/protobuf.dart#907) shelf (https://github.com/dart-lang/shelf/compare/733588f..823966f): 823966f 2024-01-03 Moritz Fix `labeler.yml` (dart-lang/shelf#403) tools (https://github.com/dart-lang/tools/compare/2f59ab4..8ffc077): 8ffc077 2024-01-03 Moritz Fix `labeler.yml` (dart-lang/tools#224) webdev (https://github.com/dart-lang/webdev/compare/b2405cb..c08a65c): c08a65c9 2024-01-09 Elliott Brooks Loosen `vm_service` constraints and prepare DWDS for release to 23.1.1 (dart-lang/webdev#2329) 651bdae6 2024-01-08 Derek Xu Make FrontendServerClient start the frontend server from AOT snapshot by default (dart-lang/webdev#2263) 4d1de266 2024-01-03 Elliott Brooks Prepare DWDS for release to version 23.1.0 (dart-lang/webdev#2328) Change-Id: I4d7fd994cc54ac2d72335c3ebf40710f3bd020e6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345366 Commit-Queue: Konstantin Shcheglov <[email protected]> Auto-Submit: Devon Carew <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
This adds support for native fields with an approach similar to what we're doing for functions.
This also enables taking the address of functions and fields by generating a call to
Native.addressOf
.I'm opening this as a WIP because it depends on SDK changes that haven't landed yet, afterwards the CI may have to be changed to test
ffigen
with beta or dev builds (or we'll just wait a little longer).I wasn't sure where to put tests for this - it looks like the only tests using
@Native
are related to ObjectiveC at the moment. Do we add new tests tocode_generator_tests/expected_bindings
?Closes #852.