libgit2 / libgit2sharp

Git + .NET = ❤
http://libgit2.github.com
MIT License
3.15k stars 887 forks source link

libgit2.wasm > libgit2.dll assembly #1675

Open ctaggart opened 5 years ago

ctaggart commented 5 years ago

It would be amazing if libgit2 could be compiled to wasm and then the wasm could be compiled to a .NET assembly. Having a managed version of libgit2 would help out a ton of projects, including a couple I contribute to.

@ericsink's wasm2cil https://twitter.com/eric_sink/status/1120811624271683585 https://ericsink.com/entries/wasm_wasi_dotnet.html https://github.com/ericsink/wasm2cil

@RyanLamansky's dotnet-webassembly https://twitter.com/WasmWeekly/status/1120935617335037952 https://github.com/RyanLamansky/dotnet-webassembly

ctaggart commented 5 years ago

A concrete example of how this would help is with the nbgv dotnet global tool. Trying to add dotcoreapp3.0 support I hit an issue with the dotnet sdk and native folder https://github.com/AArnott/Nerdbank.GitVersioning/pull/326 and then the dotnet sdk with the wrong RID https://github.com/AArnott/Nerdbank.GitVersioning/pull/322 which is used to look up the native libraries to load.

On top of that, the npkg is almost 24 MB due to the large and multiple copies of libgit2sharp required for distribution.

PS C:\Users\taggac\github\Nerdbank.GitVersioning\bin\nbgv\Release\nbgv.2.3.147-g11b51ea17f\tools> tree /F
Folder PATH listing for volume OS
Volume serial number is 381C-8BE3
C:.
├───netcoreapp2.1
│   └───any
│       │   DotnetToolSettings.xml
│       │   LibGit2Sharp.dll
│       │   Microsoft.Build.dll
│       │   Microsoft.Build.Framework.dll
│       │   Microsoft.DotNet.PlatformAbstractions.dll
│       │   nbgv.deps.json
│       │   nbgv.dll
│       │   nbgv.pdb
│       │   nbgv.runtimeconfig.json
│       │   NerdBank.GitVersioning.dll
│       │   NerdBank.GitVersioning.pdb
│       │   NerdBank.GitVersioning.xml
│       │   Newtonsoft.Json.dll
│       │   NuGet.Common.dll
│       │   NuGet.Configuration.dll
│       │   NuGet.Frameworks.dll
│       │   NuGet.PackageManagement.dll
│       │   NuGet.Packaging.Core.dll
│       │   NuGet.Packaging.dll
│       │   NuGet.Protocol.dll
│       │   NuGet.Resolver.dll
│       │   NuGet.Versioning.dll
│       │   System.CommandLine.dll
│       │   Validation.dll
│       │
│       └───runtimes
│           ├───alpine-x64
│           │   └───native
│           │           libgit2-a904fc6.so
│           │
│           ├───debian.9-x64
│           │   └───native
│           │           libgit2-a904fc6.so
│           │
│           ├───fedora-x64
│           │   └───native
│           │           libgit2-a904fc6.so
│           │
│           ├───linux-x64
│           │   └───native
│           │           libgit2-a904fc6.so
│           │
│           ├───osx
│           │   └───native
│           │           libgit2-a904fc6.dylib
│           │
│           ├───rhel-x64
│           │   └───native
│           │           libgit2-a904fc6.so
│           │
│           ├───ubuntu.18.04-x64
│           │   └───native
│           │           libgit2-a904fc6.so
│           │
│           ├───unix
│           │   └───lib
│           │       └───netstandard1.3
│           │               System.Security.Cryptography.ProtectedData.dll
│           │               System.Text.Encoding.CodePages.dll
│           │
│           ├───win
│           │   └───lib
│           │       └───netstandard1.3
│           │               System.Security.Cryptography.ProtectedData.dll
│           │               System.Text.Encoding.CodePages.dll
│           │
│           ├───win-x64
│           │   └───native
│           │           git2-a904fc6.dll
│           │           git2-a904fc6.pdb
│           │
│           └───win-x86
│               └───native
│                       git2-a904fc6.dll
│                       git2-a904fc6.pdb
│
└───netcoreapp3.0
    └───any
        │   DotnetToolSettings.xml
        │   LibGit2Sharp.dll
        │   Microsoft.Build.dll
        │   Microsoft.Build.Framework.dll
        │   Microsoft.DotNet.PlatformAbstractions.dll
        │   nbgv.deps.json
        │   nbgv.dll
        │   nbgv.pdb
        │   nbgv.runtimeconfig.json
        │   NerdBank.GitVersioning.dll
        │   NerdBank.GitVersioning.pdb
        │   NerdBank.GitVersioning.xml
        │   Newtonsoft.Json.dll
        │   NuGet.Common.dll
        │   NuGet.Configuration.dll
        │   NuGet.Frameworks.dll
        │   NuGet.PackageManagement.dll
        │   NuGet.Packaging.Core.dll
        │   NuGet.Packaging.dll
        │   NuGet.Protocol.dll
        │   NuGet.Resolver.dll
        │   NuGet.Versioning.dll
        │   System.CommandLine.dll
        │   Validation.dll
        │
        └───runtimes
            ├───alpine-x64
            │   └───native
            │           libgit2-a904fc6.so
            │
            ├───debian.9-x64
            │   └───native
            │           libgit2-a904fc6.so
            │
            ├───fedora-x64
            │   └───native
            │           libgit2-a904fc6.so
            │
            ├───linux-x64
            │   └───native
            │           libgit2-a904fc6.so
            │
            ├───osx
            │   └───native
            │           libgit2-a904fc6.dylib
            │
            ├───rhel-x64
            │   └───native
            │           libgit2-a904fc6.so
            │
            ├───ubuntu.18.04-x64
            │   └───native
            │           libgit2-a904fc6.so
            │
            ├───unix
            │   └───lib
            │       └───netstandard1.3
            │               System.Security.Cryptography.ProtectedData.dll
            │               System.Text.Encoding.CodePages.dll
            │
            ├───win
            │   └───lib
            │       └───netstandard1.3
            │               System.Security.Cryptography.ProtectedData.dll
            │               System.Text.Encoding.CodePages.dll
            │
            ├───win-x64
            │   └───native
            │           git2-a904fc6.dll
            │           git2-a904fc6.pdb
            │
            └───win-x86
                └───native
                        git2-a904fc6.dll
                        git2-a904fc6.pdb
ericsink commented 5 years ago

The first step would be to get the code compiled with clang-8 and wasi-sysroot.

In that context, WASI looks like a unix platform which is missing some features. Like threads, for example.

I've looked briefly at the build setup for libgit2. I lack sufficient knowledge of cmake for this to be straightforward for me.

Another issue is that any dependencies need to be compiled the same way. It looks like libgit2 depends on openssl, for example, so getting that going would be a step before the first step.

bording commented 5 years ago

As @ericsink mentions, libgit2 does have a dependency on OpenSSL for the linux versions of the binary, and I can't imagine actually getting that compiled into wasm and then IL That would also mean we'd have to start shipping a version of it, which we've been reluctant to take on that burden in the past.

We have been considering ways to get rid of the OpenSSL dependency for the version of libgit2 we ship, for example see #1618.

Of course, even if we could get it to work as a managed assembly, that would require massive changes throughout the codebase.

@ctaggart I'd suggest opening an issue on the libgit2 repo since all the initial work would have to happen there anyway.

petersalomonsen commented 5 years ago

https://www.npmjs.com/package/libgit2.js

built from: https://github.com/libgit2/libgit2/pull/4400

demo video: https://www.youtube.com/watch?v=rcBluzpUWE4