Skip to content
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

Add Linux support to Pigeon #5100

Merged
merged 147 commits into from
Jul 25, 2024
Merged

Conversation

robert-ancell
Copy link
Contributor

@robert-ancell robert-ancell commented Oct 10, 2023

Add Linux support for Pigeon. This has minimal work porting the generator and some manually written generated code so we can review this before implementing the generator support.

flutter/flutter#73740

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

Nice! Thanks for tackling this :)

packages/pigeon/example/app/pigeons/messages.dart Outdated Show resolved Hide resolved
packages/pigeon/example/app/linux/messages.g.h Outdated Show resolved Hide resolved
packages/pigeon/example/app/linux/messages.g.h Outdated Show resolved Hide resolved
packages/pigeon/example/app/linux/messages.g.h Outdated Show resolved Hide resolved
packages/pigeon/example/app/linux/messages.g.h Outdated Show resolved Hide resolved
@stuartmorgan
Copy link
Contributor

Is this blocked on anything now that custom codec support has landed, or just waiting for you to have time to get back to it?

@robert-ancell
Copy link
Contributor Author

Just blocked on getting back to it after the GTK4 work.

@robert-ancell robert-ancell force-pushed the pigeon-linux branch 8 times, most recently from 13aeabc to b7cdd5f Compare March 5, 2024 03:41
@robert-ancell
Copy link
Contributor Author

@stuartmorgan I think this PR is now close enough to be ready to land. I think I've included what was previously discussed, but this is probably worth doing a full review as it might have changed since last time. There's one feature I know that isn't there, which is nullable values, might be worth doing in a follow up PR.

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

Overall this looks good (with the usual caveats about my poor gobject-fu). I mostly just skimmed the generator code; @tarrinneal should review that for structure.

The main thing we'll need in order to land this is wiring up Linux in platform_tests/test_plugin/ and the test suites in tool so that we're running integration tests and have confidence that everything is working end to end. Let me know if you'd like me to do that part.

I'll also try this out on url_launcher_linux and see how it works for me in practice, since we often find things that we missed in review once we actually use the generators.

packages/pigeon/CHANGELOG.md Outdated Show resolved Hide resolved
packages/pigeon/CHANGELOG.md Outdated Show resolved Hide resolved
packages/pigeon/example/README.md Outdated Show resolved Hide resolved
packages/pigeon/example/README.md Show resolved Hide resolved
return;
}

g_printerr("Got result from Flutter method: %s\n", return_value);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is inconsistent with the other examples, but also seems more useful. @tarrinneal what do you think about changing the other examples to show a simple example like this of handling success and failure, instead of just being straight passthroughs that don't do anything with the result?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like a very reasonable idea

packages/pigeon/lib/linux_generator.dart Outdated Show resolved Hide resolved
packages/pigeon/lib/linux_generator.dart Outdated Show resolved Hide resolved
packages/pigeon/lib/linux_generator.dart Outdated Show resolved Hide resolved
packages/pigeon/lib/linux_generator.dart Outdated Show resolved Hide resolved
packages/pigeon/lib/linux_generator.dart Outdated Show resolved Hide resolved
packages/pigeon/lib/linux_generator.dart Outdated Show resolved Hide resolved
@@ -11,6 +11,9 @@ import 'package:pigeon/pigeon.dart';
cppOptions: CppOptions(namespace: 'pigeon_example'),
cppHeaderOut: 'windows/runner/messages.g.h',
cppSourceOut: 'windows/runner/messages.g.cpp',
linuxHeaderOut: 'linux/messages.g.h',
linuxSourceOut: 'linux/messages.g.cc',
linuxOptions: LinuxOptions(),
Copy link
Contributor

@tarrinneal tarrinneal Mar 19, 2024

Choose a reason for hiding this comment

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

Seems like module may be doing that work. It is prepended to all class names.

@robert-ancell
Copy link
Contributor Author

As far as I know everything is implemented, or at least as much as the c++ generator has (which this was originally copied off). I'm sure there'll be a few things that will be noticed once we're using it in projects, but nothing comes to mind. @stuartmorgan is there anything that I'm unaware of that might not be there?

@stuartmorgan
Copy link
Contributor

I haven't had time to do a full review (hopefully today), but given that you've eliminated all of the integration test skips, and that we've tried to make the integration tests pretty comprehensive in terms of feature support, I would expect that the green tests mean we're on par with the other generators modulo the kind of polish issues we always find as we start to use it.

(I'll also try using this on our native Linux plugins ASAP. Those aren't especially complex plugins so they probably won't find anything that the tests didn't, but it'll be another data point.)

@robert-ancell
Copy link
Contributor Author

@stuartmorgan another review please! Hopefully all issues are resolved.

@stuartmorgan
Copy link
Contributor

@stuartmorgan another review please! Hopefully all issues are resolved.

Sorry, I'd been trying to find some time to update my url_launcher_linux rework prototype again, since using the generator often lets me find issues I would miss in review (like the lifetime thing from the last round).

Now I'm running into issues with unit tests. It looks like the response objects generated by pigeon are totally opaque, which means we can't write unit tests directly against the handlers that we use to populate the vtable. Doing that is the pattern we use in most of our plugin tests in other languages, because it means we can do integration-y tests of just the native part, without leaving out any code that's not Pigeon-generated.

Can we put some accessors for the value and error of the response in the generated header?

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

Other than needing the query methods for host API responses, this looks great! I've both reviewed it and successfully used it for url_launcher_linux locally, and don't have any other feedback at this point.

Thank you so much for tackling this! It's awesome that we're going to have complete 1P platform coverage for Pigeon now.


indent.newln();
indent.writeln('/**');
indent.writeln(' * ${responseMethodPrefix}_is_error:');
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like we just need to have these five methods for Host API response classes too.

packages/pigeon/lib/gobject_generator.dart Show resolved Hide resolved
Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

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

The Changelog was merged improperly, but everything is fine besides that. I can do the doc comment stuff later (since it only effects code maintenance). Thanks again, a ton, for putting in all this time and effort to this project! (and I hope I can reach out for help on occasion when I'm working on this in the future :)

Comment on lines 1 to 5
## 20.1.0

* [java] Adds `equals` and `hashCode` support for data classes.
* [swift] Fully-qualifies types in Equatable extension test.
* Adds GObject (Linux) support.
Copy link
Contributor

Choose a reason for hiding this comment

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

The 20.1.0 and Adds GObject lines should be their own entry, not merged with the previous

Comment on lines 222 to 253
indent.writeln('/**');
indent.writeln(' * ${methodPrefix}_new:');
for (final NamedType field in classDefinition.fields) {
final String fieldName = _getFieldName(field.name);
indent.writeln(' * $fieldName: field in this object.');
if (_isNumericListType(field.type)) {
indent.writeln(' * ${fieldName}_length: length of @$fieldName.');
}
}
indent.writeln(' *');
indent.writeln(' * Creates a new #${classDefinition.name} object.');
indent.writeln(' *');
indent.writeln(' * Returns: a new #$className');
indent.writeln(' */');
indent.writeln(
"$className* ${methodPrefix}_new(${constructorArgs.join(', ')});");

for (final NamedType field in classDefinition.fields) {
final String fieldName = _getFieldName(field.name);
final String returnType = _getType(module, field.type);

indent.newln();
indent.writeln('/**');
indent.writeln(' * ${methodPrefix}_get_$fieldName');
indent.writeln(' * @object: a #$className.');
if (_isNumericListType(field.type)) {
indent
.writeln(' * @length: location to write the length of this value.');
}
indent.writeln(' *');
if (field.documentationComments.isNotEmpty) {
addDocumentationComments(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can these documentation comments be added using the addDocumentationComments method? If there's a reason not to, it's ok as is.

Copy link
Contributor

Choose a reason for hiding this comment

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

This comment applies to any manually added documentation comments.

Copy link
Contributor

Choose a reason for hiding this comment

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

I can also do it later myself if you don't want to deal with it :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I pushed a change to adopt addDocumentationComment everywhere; do you want to give it a quick review? (I validated that the output is identical to before, so just the code structure).

@stuartmorgan
Copy link
Contributor

Now I'm running into issues with unit tests. It looks like the response objects generated by pigeon are totally opaque, which means we can't write unit tests directly against the handlers that we use to populate the vtable. Doing that is the pattern we use in most of our plugin tests in other languages, because it means we can do integration-y tests of just the native part, without leaving out any code that's not Pigeon-generated.

Can we put some accessors for the value and error of the response in the generated header?

Per offline discussion, we're going to go ahead and land without that since adding them later won't affect any existing code, and we have a short-term work-around. I filed flutter/flutter#152166 to track adding it.

I'll do the final tiny cleanup on this PR, and then land it! 🎉

Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

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

another check mark for this

@stuartmorgan stuartmorgan added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 25, 2024
@auto-submit auto-submit bot merged commit 2c1f713 into flutter:main Jul 25, 2024
76 checks passed
@robert-ancell robert-ancell deleted the pigeon-linux branch July 25, 2024 10:42
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 25, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jul 25, 2024
flutter/packages@1c319ac...19daf6f

2024-07-25 [email protected] Modernize the rest of the `index.html` files to support WASM compilation (flutter/packages#7192)
2024-07-25 [email protected] Add Linux support to Pigeon (flutter/packages#5100)
2024-07-24 [email protected] [gis_web] Allow package:web 1.0.0 (flutter/packages#7203)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: pigeon platform-linux triage-linux Should be looked at in Linux triage
Projects
None yet
3 participants