-
Notifications
You must be signed in to change notification settings - Fork 899
Feature: Offer CoreCLR-compatible portable library #1293
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
Comments
I'd be happy to see CoreCLR compatibility, and we'd accept a PR as long as it doesn't reduce compatibility elsewhere (which I don't think that it would). (Probably makes sense to discuss those details in a PR.) |
Great. To keep this issue (which could get long) readable, I'll keep a running list of issues and their resolutions in the initial description. Then we can comment and discuss below, and I'll update with decisions in the description. |
Can someone please review the custom marshaler solution I've described in the description above? |
Project owners, subscribers, etc don't get notifications when you edit the initial description - so while that's fine to keep a summary, please do also follow up with a comment. :) |
What if a method takes 5 strings? Does it make two overloads (one with all What actually generates the code? Can you point me to a similar example? Is it an MSBuild task or something? |
Yes, I'll do that
We have total control over it. The goal is just one overload is generated (making 2 in total).
It's a Roslyn-based code generation framework, with custom generation code specifically for libgit2sharp added to it. The PInvoke project is an example of a shipping project that uses this technique in order to define very low level overloads (using I've completed the code generator for libgit2sharp and will push very soon so you can actually see it working on your own project. |
I've pushed the code generator and a significant set of altered p/invoke signatures to my branch. |
I'm trying to understand how this Also, I did some reading on use of custom marshalers and the MSDN docs seem to fixate on them being used to marshal COM objects rather than other values for P/Invoke signatures. Is this even a proper use? |
When this change is complete, should I expect it to merge into master or vNext? |
libgit2 does. If libgit2 is allocating the memory, it will also free it. If you give me an example of a function that you're looking at, then I can provide more details about the lifecycle, but (for example) calling
By what metric are you defining "proper use"?
master is now our main branch. |
I was looking at
Well, between MSDN only talking about it in the context of COM, and not supporting it on CoreCLR which has no support for COM but does support p/invokes, it seems like this attribute is being used where it was not designed to, and thus leaves open the question in my mind as to whether it's possible for it to marshal memory properly. For example, if it only marshals COM objects, then freeing memory isn't an issue since COM objects release themselves based on reference counting. But if you're marshaling other values as you're doing here, then the attribute has to somehow know how to call back into the native library to free the memory, yet as a marshaling attribute I don't see how it can do so. |
Yes, exactly so.
It doesn't need to. We make explicit calls to our various At the moment, we typically do not hold on to the native objects, and so the pattern is to create a managed diff object, copy all the data in and then release the native object immediately. So we very quickly free the associated native memory. This is an approach that we're revisiting, but that's a detail that really doesn't matter to the marshalling. Anyway, if you're asking for |
Thanks. I think that's all I need at the moment. Have you had a chance to look at my branch, open it up in VS, and get a feel for how it works (with code gen, etc)? |
I've got the portable project building. No more compile errors. I haven't run tests yet. Before I spend much more time on this, I'd like a pre-review of the changes as a course check so I'm not wasting time going in an unfruitful direction. Can a committer please sign up to take a look? I can file a PR for purposes of review and discussion if that's helpful. |
Sure, @AArnott , I'll try to take a look tomorrow evening. |
👀 |
Ping :) |
I've got all the tests passing for the desktop and portable libraries! (modulo the 3 that are already failing in master). |
Thanks for staying on top of this @AArnott . My Windows VM apparently konked out and I had to reinstall this weekend. (Fast ring of death?) In any case, I'm going to try to make some time for this again this weekend. Side note: you have three tests failing in master? That's unexpected. Presumably some local configuration on your machine that we're failing to sandbox for correctly. Would you be so kind as to open an issue? |
👍 , commenting to get notification. |
@DiryBoy you can just click the "Subscribe" button on the right. |
@AArnott Thanks but that button would show 'Unsubscribe' if you already watched the repository, so I just don't trust it. |
As part of this it would be nice to also distribute the native binaries in a new-style package, I created an issue here: libgit2/libgit2sharp.nativebinaries#39 |
@ah- that might be nice, but I wouldn't want to do it "as part of this" lest we make this already big project significantly bigger. |
Yes, makes sense to do that bit later. The new package layout is fully compatible without cutting off any users of old tooling if the build.props for them are adjusted to the new paths. But I see that this will require some actual testing, which can be done after this has been merged. |
What ever happened to this? With PowerShell going cross-platform, I was looking for .NetStandard version of the library ;-) |
Looking forward to this PR. Thank you for your efforts guys. |
does this issue cover support for the W10 UWP, or should i open a new one? |
Any updates on this? |
As discussed in #874:
I'd like an active issue to track this exploration where I can share ideas for making this work with the project owners, and verify owners' willingness to ultimately accept a PR when the work is done.
Work ongoing in PR #1318
#if
blocks around desktop-only serializable supportICustomMarshaler
ReliabilityContract
#if
blocks around theseX509Certificate
SecureString
BufferedStream
CriticalFinalizerObject
#if
around base class declarationEnvironment.OSVersion
#if Desktop
keep,#else
use CoreCLRRuntimeInformation
Trace
#if
blocks around theseCode generation design
The p/invoke signature that is hand-written changes from this:
To this:
Notice the change from using the
MarshalAs
attribute to usingCustomMarshaler
. This attribute causes another overload of this method to be automatically generated during the build (and available to Intellisense):Notice this generated overload uses
string
as the marshaled parameter type, keeping the ease of use that we had before. It then emulates what the desktop marshaler would have done (at least, as far as I understand it).The text was updated successfully, but these errors were encountered: