-
Notifications
You must be signed in to change notification settings - Fork 533
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
Binding: Vision #5352
Comments
When working on #5348 I found you can do |
It sounds like this proposal is basically doing 2 things for the user:
We could probably even automate this without much effort in today's projects if we wanted to and resolve it at compile time:
Additional Considerations to Flesh OutNuGet MetadataFrom my reading of that link, I don't think NuGet supports searching arbitrary metadata. It seems to only support searching the official NuGet supported metadata. Thus we would need to decide which of those fields we would use. Additions considerations:
Visual Studio UXHow extensible is the built-in VS template UI system? Can we prompt the user to enter Maven information that we can use? Is the template system robust enough that it can run our custom logic to query Maven and resolve dependencies in order to generate projects? If we can only do this outside of VS, do we think users will find and use it? UpdatesOnce a package has been bound and a new release is posted to Maven, what does the update process look like for updating our binding? Cases to consider:
Publishing to NuGetWe need to understand what the target user is going to do with the binding: consume it locally or publish to NuGet. If publishing to NuGet then there are a few additional issues like:
|
Trivial.
Not only Maven. What if we have bindings? maven gives a sheet about
I am testing client API for search NOTE:
I did not play with that more than 15 minutes.
dunno. Trying to have something - then I can make new steps...
Writing xummary and pseudo-code. Coming soon |
Nope. Side project. Will be easily embeddable. Or code copied with whatever changes needed (namespace changes etc)
If the ItemGroup is defined we could:
Why working with files? Now more details: We have 2 sources od ultimate divine truth (priority list):
Pick this:
What I am trying to implement right now:
|
POM does not have stable name (yet) it is basically Maven 4.0.0 XSD schema transformed into C# classes I used XML to from AndroidX and GPS-FB to generate C#, - BUT there were some fields missing. So last week I generated C# from maven XSD |
My plan is 20201202 for next 2 weeks:
|
An additional consideration from @Redth: Maven is like NuGet, there can be many feeds, some of which may require authentication. So we may need to support specifying a URL, and possibly a username/password as well. |
We should really back up a step here and sit down to discuss a few things:
|
In very few cases they do. Usually expect to be done by Microsoft or some partner. Basically wishes to have some SDK bindings are submitted as issues in (AndroidX/AndroidSupport, GPS-FB and XamarinComponents). Some are submitted as internal mails and very few (for me personally) over social media.
Challenges I personally have:
Improving productivity will most likely increase abstraction (add one or more levels of APIs) that might drive some users away from bindings. Needed APIs:
NOTE: More details to come.
I work with Google's maven right now, but I do plan to add others (mavenCentral and jcenter/Bintray). I would not bother with private repos or repos that need authentication. There must be some reason artifacts are not public. We could add that later. |
Maven API (extended)20201208 Initial data for current version of
https://github.com/xamarin/AndroidX/blob/master/config.json#L172-L179 NOTE: For AndroidX and GPS-FB there is almost 200 artifacts to bind with growing number. Because it is manual process (currently) order of json data is important for me, because I can easily check/verify Artifact VersionsSo with 20201208 there is extended info with versions (available for artifact):
This will provide opportunity to verify version given for bindings ("1.0.0-alpha6" would fail) and to CacheWIP - deserializing locally dumped Maven repo data - if not grab it. ProjectObjectModel POMCurrently POM is grabbed and deserialized. WIP on extracting important data like dependecies:
Extras
|
NuGet API20201208 Currently there are 3 Nuget Client API use cases:
Search is very limited regarding filtering and customizations and searches using Furthermore Search does not return DependecySets to filter out based on TargetFramework, so for each Search So, the closest API in few days that returns the same results (3 results for "androidx+car" search ) is:
And it returns serialized:
Extras
|
I did a spike on a lot of this some time ago: https://github.com/Redth/Xamarin.Binding.Helpers The idea was to use a .gradle file to specify the dependencies for the binding and let gradle/maven resolve the dependency graph for you, since that's what it's good at. With a small plugin added to the .gradle file, I was able to serialize all of the dependency graph from gradle in a way that msbuild tasks could parse it out and use it to obtain the dependency tree info (maven artifact group, id, version, binaries, etc). This could all be completely automated such that a gradle config is created for the top level maven artifacts specified by the developer and gradle can be downloaded and invoked on behalf of the user to get this info. The bonus here is things like maven feed authentication do not need re-inventing or engineering. Once the dependency graph was known, all of the actual aar/jar binaries could be downloaded and included as appropriate items in the binding project. However, as mentioned in this issue several times, there's already lots of nuget packages out there that ship these artifacts in binding projects and would conflict during builds. Often these packages are desirable instead of just bundling the artifacts since their binding c# api surface may be required. I did some work in the same repo around matching up NuGet packages. The idea of having metadata in nuget packages to match up their maven artifacts is great.... except... we'll likely never be able to get the entire ecosystem updated to this model. If that's an assumption then this mechanism would only be reliable for packages we control, or otherwise well known community packages. If we assume that, we can pretty much identify that set of packages already and map out some rules for the artifacts that packages map. This is exactly what I did here: https://github.com/Redth/Xamarin.Binding.Helpers/blob/main/Xamarin.Binding.Helpers/NuGetResolvers/AndroidXMavenNugetResolver.cs There are others for Firebase, GPS, and other well known package: https://github.com/Redth/Xamarin.Binding.Helpers/blob/main/Xamarin.Binding.Helpers/NuGetResolvers/KnownMavenNugetResolver.cs#L12-L98 It's really not that bad of a set of rules/mappings to have/maintain perhaps in addition to new packages being able to publish maven artifact related metadata (and fallback to these mappings). The idea was that these rules would apply, and/or you could specify explicit mappings yourself if you know they exist, like this:
So, for this whole library you would basically reference and android studio / gradle project in your xamarin binding project like this:
This would even go build the native project for you and include the module's binary (aar) as a so that it would generate bindings (or not if you disabled that option). It would link in the entire dependency tree of maven artifacts based on the android project's declared compile dependencies, but it would substitute those for NuGet packages according to the resolvers or explicit mapping override info you specified. This isn't a perfect approach by any means, and I could see taking it a step further to not require the android studio project at all, but this is a good start to look at. |
It looks like Consequently, it should be possible to distribute a Assuming this works, it means we can reliably add a Gradle task to retrieve the artifacts of the Gradle build, so that we can automagically determine paths to built artifacts + dependencies. |
I've been giving this some thought recently, and maybe we should do less automatically for the user (since that's where the dragons live), and focus first on helping the user ensure they are creating correct bindings. TL:DRWe will initially focus on tackling two pain points of binding from Maven:
|
These features have been implemented for .NET 9 in the following PRs:
I think the rest of this issue is conjectural and not really actionable. Any additional steps we want to consider taking should probably be proposed and fleshed out in new issue(s). |
The current binding infrastructure is "janky":
.aar
or.jar
file to bind.@(LibraryProjectZip)
or@(EmbeddedJar)
.In practice, (1) and (3) can be incredibly annoying. (At least for @jonpryor, it's not always obvious where to obtain the files referenced by a Maven artifact, and (3) is full of peril.)
(3) will remain "out of scope" for this vision; fixing (3) involves ensuring that
generator
can always emit compilable output, and that we expand the Java constructs thatgenerator
supports. We should absolutely do this, but addressing these deficits involves finding the "less-than-ideal" constructs, filing issues for them, and fixing them.Which leaves (1) and (2): can anything be done there?
Artifact Retrieval & Binding
Instead of a
.aar
or.jar
file as being the "primary starting point", can we instead have a Maven artifact ID be the primary point?Then, given a set of Maven artifact IDs:
Specify the Maven IDs
How should the Maven IDs be specified? What's the "user interface"?
Obtain Maven Dependency Graph
I believe @moljac has code to do this, as part of Binderator: https://github.com/xamarin/XamarinComponents/tree/master/Util/Xamarin.AndroidBinderator
Find existing bindings
It appears that NuGet.org allows searching arbitrary package metadata. If we ensure that all new NuGet packages contain NuGet.org-searchable package metadata containing the Maven artifact ID & version, then it should be possible to find existing bindings.
@moljac is working on this.
Bind unbound packages
For any maven artifacts in the dependency graph which haven't been bound, presumably including the "root" dependencies, we should bind them.
Proposal: Item Group?
We can imagine using an MSBuild item group to specify the "root" maven IDs, either directly:
or by using a file (file format? Gradle? JSON? XML?) to contain the information.
Implicit in this idea is that these are like
@(PackageReference)
item group: the containing.csproj
can have as many of them as desired, which in turn means that the.csproj
could emit "many" output assemblies (dozens?), one per bound library as well as the "intentioned" output assembly.Additionally, how would
@(TransformFile)
(e.g.metadata.xml
) work in such an environment? All@(TransformFile)
s apply to all unbound artifacts?Proposal:
dotnet new
?Instead of using an item group, add a new tool, e.g.
This command would in turn emit a solution, with one
.csproj
project per unbound artifact. This "answers" the@(TransformFile)
question: each project uses has its own set of@(TransformFile)
s.Less well defined is this: how does one update an existing "binding solution"? Changing the root artifact version will "ripple" across the entire solution; is it possible to update such a directory tree in-place? Or would we need to re-invoke the
dotnet new maven-binding
command into a new directory, and require the user manually copy over any required@(TransformFile)
s & partial classes and such?The text was updated successfully, but these errors were encountered: