-
Notifications
You must be signed in to change notification settings - Fork 894
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
Please consider adding AOT support for .Diff.Compare<T>() #2082
Comments
Interesting that you're looking into AOT these days, since I'm on it as well 😄 Unfortunately, not all operations are successful and it's not only the git-diff that doesn't work.
I tried to make the library AOTable igiona#1 but it doesn't seem to help solving my problem. The [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern int git_repository_discover(
GitBuf buf,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictFilePathMarshaler))] FilePath start_path,
[MarshalAs(UnmanagedType.Bool)] bool across_fs,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictFilePathMarshaler))] FilePath ceiling_dirs); basically |
Does AOT do something funny with the filesystem? |
@ethomson It's interesting to me that |
Correct, it just doesn't work in AOT. I exposed it nastily to my Program.cs: Configuration.cs public static string TestMe() => Proxy.git_config_find_global()?.ToString() ?? "Was null"; Program.cs Console.WriteLine("=> {0}", Configuration.TestMe());
Also this call accesses the file-system, weather this is the relation though is hard to say for me. I added some debugging information in private static FilePath ConvertPath(Func<GitBuf, int> pathRetriever)
{
using (var buf = new GitBuf())
{
int result = pathRetriever(buf);
Console.WriteLine($"=> result {result}");
Console.WriteLine($"=> ptr {buf.ptr:x}");
if (result == (int)GitErrorCode.NotFound)
{
return null;
}
Ensure.ZeroResult(result);
return LaxFilePathMarshaler.FromNative(buf.ptr);
}
} AOT
|
I still get the null exception even in the AOT "friendly" branch. |
I guess I found the reason why AOT version doesn't work. The problem is more complicated than I thought. According to the documentation:
In other words, take 'git_config_find_global' as an example, we need to change [DllImport] part to
I would like to give it a try, but dealing with Unmanaged code is beyond my capabilities. |
I did take a look at this a bit this weekend, and I'm not sure that the issue is solely a It also seems a bit strange to me that there are analyzers that that point out other problematic code for AOT, but don't flag That being said, I do think the source of the problem is related to the non-trivial uses of It would be pretty easy to get LibGit2Sharp fully compatible with trimming and single-file deployment, but getting all the way to AOT is likely going to be a lot of tricky work, if it's possible at all currently. |
Found a couple more issues on the dotnet repo that likely explain a bit more what's going on here. Currently it looks like warnings for AOT-problematic P/Invokes via It also sounds like one benefit of moving to the source generator imports would be that you would actually get warnings for P/Invokes that aren't compatible with AOT. However, even if those places were properly identified, it's not clear to me yet if there would even be a way to change LibGit2Sharp to accommodate the AOT limitations. It's quite possible that a change on the libgit2 side would be required. |
What would we need to do on the libgit2 side? |
I'm just theorizing here, but if it turns out there was a libgit2 API pattern that there was no way to adjust the P/Invoke for to make it compatible with AOT, then the only way to solve it currently would be to modify the libgit2 API. Otherwise, we'd be waiting for Microsoft to change something in their AOT stack to make it work. I don't yet know if there is anything like that, though. It may turn out that every |
Got it. Happy to work on this if we need to. I think that we could also figure something out here where we build a shim over libgit2 to not break API compatibility but mutate it into something AOT can handle. 🤷 |
Having this compatible with AOT would be a huge benefit for tools using libgit2sharp, like GitVersion. I'm happy to help here, but source generators and unmanaged code are a new field for me |
That could already be achieved through publishing a trimmed self-contained application. AOT isn't required for that. |
That's an interesting approach indeed, I gave it a quick try on GitVersion targeting linux-x64: self-contained, I tested it by simply run the binary with default settings on a "normal" repo.
A part of the startup time which is remarkably faster on AOT, self-contained + trimming seems like a valuable and somewhat easier solution. |
I've already fixed them all locally while investigating the AOT stuff this weekend. They were actually nothing too bad. I'll look into pushing them up and getting them out soon.
Yes, startup time is one thing that AOT would improve. |
That's nice! |
Yes, I meant for LibGit2Sharp, which is all that is relevant here. 😄 But yes, all trimming errors would need to be addressed for whatever program you're trying to trim. AOT uses trimming as well, so the first prerequisite is to address all trimming problems. |
I just released LibGit2Sharp 0.30.0, which includes #2084, so it should be fully compatible with trimming and single file publishing now. I also started looking into what is involved in converting from For starters, In some ways, switching to However, there are some new requirements around the types involved in the P/Invoke definitions, and I suspect those are what are tripping up using AOT right now. Effectively, a lot of the existing interop types defined in LibGit2Sharp aren't blittable and require runtime marshalling to actually work. Lots of the interop types are defined as classes right now, and those need to be redefined as structs (along with other changes) to be able to work. However, making those changes has impacts on the higher layers of the code that also have to be understood and adjusted. I'm going to keep working on it, but no promises as to when I'll be able get it all done! For anyone interested in the details of the changes, I've pushed up my spike branch: https://github.com/libgit2/libgit2sharp/tree/libraryimport |
but can’t aot, wait libgit2/libgit2sharp#2082
* SubtitleParse/AssEvent: add Read(); Write() use stringbuilder * Ikkoku: extract NotZhConvert method * Ikkoku: init simple GitMergeDiff but can’t aot, wait libgit2/libgit2sharp#2082 * GitMergeDiff: fix paths and not use aot * IncludeNativeLibraries when PublishSingleFile * Ikkoku/Clean: trimend when process event It is a regression bug caused by 244bb2b. I used to trim space chars at the end of the event line when parse ass, but now I have moved it to the ikkoku/clean * Update ikkoku-dotnet-ci.yml * Update ikkoku-dotnet-ci.yml * Ikkoku/Clean: fix RemoveEndSpace wrong return * SubtitleParse: organize codes * SubtitleParse: move to src folder * SubtitleParse: update package info * SubtitleParse: fix script info parse * Test: update * Ikkoku: split and adjust to adapt SubtitleParse * Ikkoku: move files * Ikkoku: split Program * Ikkoku: rename GitMergeDiff * Ikkoku: merge add subcommand base-diff * Ikkoku/clean: add deleteFanhuaji (enable in preset More) * Ikkoku: disable mege/base-diff when NativeAOT * bump version: Ikkoku 0.3.2; SubtitleParse 0.3.0 * gha: update ikkoku-dotnet-ci.yml
When utilizing libgit2sharp in combination with the .NET 8 PublishAot feature, all repository creation, file staging and committing operations are successful, however, the git diff function throws a NullReferenceException.
Is there a way to get this working under AOT?
Steps To Reproduce:
dotnet new console -o aot-test cd aot-test
dotnet run
for testing, it will display:dotnet publish
,.\bin\Release\net8.0\win-x64\publish\aot-test.exe
to test the native AOT version, it throws an exception onrepo.Diff.Compare<Patch>()
:Current Behavior:
The native AOT functions for repository creation, file staging, and committing operations are functional, but the git diff function is not.
Anticipated Behavior:
Please consider adding AOT support for the git diff API.
Version of LibGit2Sharp (release number or SHA1)
0.29.0
Operating system(s) tested; .NET runtime tested
The text was updated successfully, but these errors were encountered: