Git Product home page Git Product logo

Comments (20)

AArnott avatar AArnott commented on July 19, 2024 1

Tip: AssemblyLoadContext is how I got it to work for my scenario where I couldn't rely on the CoreCLR to automatically find it.

https://github.com/AArnott/Nerdbank.MSBuildExtension/blob/master/src/Nerdbank.MSBuildExtension/netstandard1.5/ContextIsolatedTask.cs#L113
https://github.com/AArnott/Nerdbank.GitVersioning/blob/master/src/NerdBank.GitVersioning/GitExtensions.cs#L349

from alpacka.

AArnott avatar AArnott commented on July 19, 2024 1

so if i understand this correctly i need o make a custom AssemblyLoader that can find the libgit.so
and start the code that i want libgit to use also in there ? is there no way to register it and hook it into the current context ?

Correct. You can get at the current AssemblyLoadContext and it exposes an event to help the CLR find managed assemblies. But it does not allow for helping to discover native libraries. For that, you must create your own type, override the virtual method, and then get your code running within it.

also what is up with that xm file that provides the dllmapping ?

I don't know. I think I heard that that's used by mono, but I didn't write that file and have never seen it used myself.

from alpacka.

NikkyAI avatar NikkyAI commented on July 19, 2024

might need more testing on the officially supported distros
https://www.microsoft.com/net/core#linuxcentos

  • RHEL 7
  • Ubuntu 14.04
  • Ubuntu 16.10
  • Linux Mint 17
  • Debian 8
  • Fedora
  • openSUSE

from alpacka.

skyem123 avatar skyem123 commented on July 19, 2024

So... as a workaround we could find the .so file ourselves and load it manually?
Sounds a bit risky.

from alpacka.

NikkyAI avatar NikkyAI commented on July 19, 2024

if you can figure out how to load it ?
and the so file is in platform/linux/

from alpacka.

skyem123 avatar skyem123 commented on July 19, 2024

If you know where the .so file is, it makes it easier...
https://docs.microsoft.com/en-us/dotnet/api/system.runtime.loader.assemblyloadcontext?view=netcore-1.1.0 seems to be what he was referring to...

There's the LoadUnmanagedDll (DLL is the windows version of SO)... but... all the documentation seems to be "To be added."

That's not very helpful...

from alpacka.

NikkyAI avatar NikkyAI commented on July 19, 2024

you can test this behaviour with this repo https://github.com/NikkyAI/lg2s

git clone [email protected]:NikkyAI/lg2s.git
cd lg2s
./test.sh

if you want to try something out of a different branch there, ask so i can add contributors
whoever solves it first and cleanest gets hugs

from alpacka.

skyem123 avatar skyem123 commented on July 19, 2024

Problem is I don't have a working Linux system to test.
However, looking around a bit I have found this:
https://github.com/libgit2/libgit2sharp.nativebinaries#specifying-custom-dll-names

from alpacka.

skyem123 avatar skyem123 commented on July 19, 2024

Reading a bit, it seems to be that we need to compile our own native libgit2sharp, then own libgit2sharp? I hope I'm misunderstanding there...
Or we have to use some kind of reflection style hacks to replace the AssemblyLoadContext...

Either way, this seems very tricky.

from alpacka.

skyem123 avatar skyem123 commented on July 19, 2024

Some thinking...
Libraries are only for 64-bit Linux distros? Something to be aware of for testing on virtual machines.
What happens if we rename .so to .dll?

from alpacka.

NikkyAI avatar NikkyAI commented on July 19, 2024

i attempted to load the library git2-1196807 using a custom AssemblyLoader
but that failed ..

de to load a program with an incorrect format.

i probably misunderstood the hints.. and i did not figure out how LoadUnmanagedDll is called

from alpacka.

NikkyAI avatar NikkyAI commented on July 19, 2024

i am also pretty sure its not whats needed to make this https://github.com/AArnott/libgit2sharp/blob/portable/LibGit2Sharp/Core/NativeMethods.cs#L94 work
it is native code after all

@AArnott could you explain how a Custom AssemblyLoader affects System.Runtime.InteropServices.DllImport ?

from alpacka.

NikkyAI avatar NikkyAI commented on July 19, 2024

my current suspiscion is that this is not used which explains why it loads on windows.. maybe ?
LibGit2Sharp.dll.config

<configuration>
    <dllmap os="linux" cpu="x86-64" wordsize="64" dll="git2-1196807" target="lib/linux/x86_64/libgit2-1196807.so" />
    <dllmap os="osx" cpu="x86,x86-64" dll="git2-1196807" target="lib/osx/libgit2-1196807.dylib" />
</configuration>

on windows it works fine even after deleting the file
(running dotnet bin/Debug/netcoreapp1.1/lg2s.dll to prevent rebuilding the file )

from alpacka.

NikkyAI avatar NikkyAI commented on July 19, 2024

tested using travis trusty ( https://docs.travis-ci.com/user/trusty-ci-environment/ )
ssame environment as the LibGit2Sharp travis setup uses
basically ubuntu in a container

and it does not break

from alpacka.

NikkyAI avatar NikkyAI commented on July 19, 2024

waiting on dotnet/coreclr#11005

from alpacka.

NikkyAI avatar NikkyAI commented on July 19, 2024

https://github.com/dotnet/coreclr/issues/10520#issuecomment-289692357 this can be a fix on the aur PKGBUILD
we just need to copy the .so file into the default location if it really ignores the dll mapping

from alpacka.

AArnott avatar AArnott commented on July 19, 2024

could you explain how a Custom AssemblyLoader affects System.Runtime.InteropServices.DllImport ?

DllImport just takes a filename. The CLR at runtime has to find a path for that file, or let the OS find it via its probing path. The way CoreCLR lets you customize this native binary discovery is through AssemblyLoadContext, which your managed assembly must be running within in order to work.

from alpacka.

NikkyAI avatar NikkyAI commented on July 19, 2024

so if i understand this correctly i need o make a custom AssemblyLoader that can find the libgit.so
and start the code that i want libgit to use also in there ? is there no way to register it and hook it into the current context ?
also what is up with that xm file that provides the dllmapping ?

from alpacka.

NikkyAI avatar NikkyAI commented on July 19, 2024

generated by the last version of the test script, a few trace logs of lg2s trying to find git2-1196807
http://nikky.moe/alpacka/
if anybody else who has more time would want to diff them and see what the big difference is..

from alpacka.

NikkyAI avatar NikkyAI commented on July 19, 2024

this is now fixed.. more or less by replacing the .so file,
keeping the issue broken as long as there is no real clean solution

from alpacka.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.