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

Provide a Source Generator backend in addition to the S.R.E backend. #79

Closed
jkoritzinsky opened this issue May 25, 2020 · 13 comments
Closed

Comments

@jkoritzinsky
Copy link

Currently, using Tmds.DBus uses reflection exclusively to dynamically emit code to connect to D-Bus. With the new Roslyn source generators feature, it should be possible to provide a no-runtime-emit path via generated source. This would enable reliable usage with the IL Linker to help enable smaller program sizes with reliable functionality.

@tmds
Copy link
Owner

tmds commented Jun 25, 2020

@jkoritzinsky I agree, this would be really useful. I won't get to it on short term though.

@tmds
Copy link
Owner

tmds commented Jan 19, 2022

I've created #119 to expose a D-Bus protocol API. A source generator would target that API.

@tmds
Copy link
Owner

tmds commented Mar 9, 2022

A source generator would target that API.

The tool can now generate code that targets the Protocol API.

It can only generate code for proxies (that is: to use an object from a service), not for adaptors (that is: to provide an object).

If you want to try it (and maybe give feedback) you can grab packages of this NuGet feed:

<add key="tmds" value="https://www.myget.org/F/tmds/api/v3/index.json" />

@tmds
Copy link
Owner

tmds commented May 17, 2022

@jkoritzinsky any interest in being an early adopter of the Protocol library?

@jkoritzinsky
Copy link
Author

I don't have time at the moment, but I'll pass this along to the other contributors to the project that prompted me to open this issue.

@affederaffe
Copy link
Contributor

I created a source generator some time ago that uses the new Protocol library, see https://github.com/affederaffe/Tmds.DBus.SourceGenerator.
There's also a pending PR to replace the S.R.E backend usage in Avalonia, though there are still some blockers:

  1. There's a bug in the Protocol library which would affect Avalonia, though there's already a PR to fix this
  2. There's still no NuGet package, so a submodule is currently used, which is suboptimal
  3. The source generator itself isn't on NuGet, though I'd like to have 1. and 2. fixed before publishing.

I'd love to see those PRs merged within Avalonia 11, are there any plans on releasing Tmds.DBus.Protocol on NuGet?

@tmds
Copy link
Owner

tmds commented Feb 9, 2023

I like that you built a source-generator for the protocol library.

Are you aware the Tmds.DBus.Tool can generate proxies for the protocol library?
Have you tried using it?
I haven't found much time to work on this in the past year.

There's a bug in the Protocol library which would affect Avalonia, though there's already #179

I'll look at the PR.

are there any plans on releasing Tmds.DBus.Protocol on NuGet?

And I'll make a release of the library in its current state by early next week.

@tmds
Copy link
Owner

tmds commented Feb 9, 2023

Are you aware the Tmds.DBus.Tool can generate proxies for the protocol library?

What it can't do is: generate code for you to implement objects to be made available through D-Bus.
Does your source-generator support that?

@affederaffe
Copy link
Contributor

The source generator has some advantages over the Tmds.DBus.Tool generation:

  1. It doesn't require you to add auto-generated code to your repository, see DBus Codegen AvaloniaUI/Avalonia#9810 (comment)
  2. It generates needed methods for writing generic types, so there's no reflection at all (Tmds.DBus.Protocol uses MakeGenericType for example)
  3. It also deals with variants

Yes, it also generates abstract handler classes for the user to implement.

Thanks, I appreciate your effort!

@tmds
Copy link
Owner

tmds commented Feb 9, 2023

It doesn't require you to add auto-generated code to your repository, see AvaloniaUI/Avalonia#9810 (comment)

I don't have issues adding generated code to a project.
I opted for that because I assumed a user might want to tweak the code, but probably they don't.

It generates needed methods for writing generic types, so there's no reflection at all (Tmds.DBus.Protocol uses MakeGenericType for example)

I'm curious how your library handles a type like: (int, (string, string))[]. I will look at some generated code.

It also deals with variants

Tmds.DBus.Protocol supports variants as objects (for reading and writing). But it does use MakeGenericType to make that work.
Again, I'll take a look how this works.

The code generated by Tmds.DBus.Tool, even though using MakeGenericType, is AOT compatible.

Yes, it also generates abstract handler classes for the user to implement.

Nice!

If it's ok with you, I'll put a reference to your generator on the README.

@affederaffe
Copy link
Contributor

Sure, that'd be great!

@tmds
Copy link
Owner

tmds commented Feb 15, 2023

@affederaffe I'll be making a release to nuget.org today.

If you want to verify it will work for you, you can try with the latest CI build: Tmds.DBus.Protocol.0.11.1-160-9b0363f81af98d82a459973c41a8a5a7295bea57.nupkg from https://www.myget.org/F/tmds/api/v2/package.

@tmds
Copy link
Owner

tmds commented Feb 15, 2023

The protocol library is now on nuget.org, and can be targeted using the source generator implemented by @affederaffe.

@tmds tmds closed this as completed Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants