Skip to content

[Question] Support for Mono #264

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

Closed
gep13 opened this issue Oct 1, 2014 · 34 comments · Fixed by #816
Closed

[Question] Support for Mono #264

gep13 opened this issue Oct 1, 2014 · 34 comments · Fixed by #816

Comments

@gep13
Copy link
Member

gep13 commented Oct 1, 2014

Does GitVersion support running under Mono?

If not, are there any plans to support?

@JakeGinnivan
Copy link
Contributor

The issue is libgit2 and libgit2sharp. It would have to ship different versions of the native library to work on different operating systems afaik.

I seem to remember there being a thread about this. @nulltoken can probably tell you more

@gep13
Copy link
Member Author

gep13 commented Oct 1, 2014

Ah, good point. I have never built anything targeted at Mono, so wouldn't know where to start conditionally compiling the included DLL's depending on the target. Doesn't seem like it should be outwith the realm of possibility though.

@nulltoken
Copy link
Contributor

@gep13 Well, LibGit2Sharp actually runs on Mono. But, currently, this requires the user to build his/her own version of libgit2 (See https://github.com/libgit2/libgit2sharp/blob/vNext/build.libgit2sharp.sh).

@Therzok is maintaining a repo for Windows and Mac versions of libgit2 at https://github.com/mono/libgit-binary

However, I'm not sure how many versions of the compiled binaries we should maintain for other *nix plaforms (@carlosmn @ethomson Thoughts?)

@Therzok
Copy link

Therzok commented Oct 2, 2014

I think it's worth mentioning that my versions of the binaries support SSH.

@Therzok
Copy link

Therzok commented Oct 2, 2014

@nulltoken before you think I don't want to push the changes, it's because I haven't modeled a proper API for credentials. I've written some stubs which work. :P

@Therzok
Copy link

Therzok commented Oct 2, 2014

@nulltoken regarding how I build libgit2sharp inside MD.

For Windows and Mac I build libgit2sharp and copy the binaries to the output directory.
For Linux, I run a slightly modified version of the build.libgit2sharp.sh file to enable ssh. Grab the native binaries output directory and copy paste them.

@gep13
Copy link
Member Author

gep13 commented Oct 2, 2014

So, as a noob to this sort of thing, let's say I wanted to run GitVersion, using Mono, on an Ubuntu machine. What would be the process for getting this done?

  • Ensure that everything in GitVersion itself is Mono Compliant
  • Build LibGit2 on an Ubuntu Distro
  • Take the compiled DLL's and build LibGit2Sharp
  • Take both DLL's and reference them in GitVersion
  • Run the resulting exe on Ubuntu using mono

Is that about right? Or am I completely off?

@Therzok
Copy link

Therzok commented Oct 2, 2014

Make sure the libgit2 native livrary binaries are side-by-side with the libgit2sharp DLLs so you don't have to mess with library resolver path settings. Otherwise, it lgtm.

@carlosmn
Copy link

carlosmn commented Oct 2, 2014

@Therzok is this same-directory loading a mono extension? The documentation suggests that it simply delegates to dlopen(3) which won't do that unless you have '.' in LD_LIBRARY_PATH or the rpath option is given to the linker, which won't happen by default.

@nulltoken the binaries shouldn't be in kept in the repo, and there's too many variations to reasonably keep them in a single place.

The way to distribute binary libraries on unix is to make use of the package manager for a particular OS of family which can depend on the zlib, openssl, libssh2 and http-parser packages. Otherwise you're either going to have to ship a very limited version of libgit2 or field that kind of support requests.

@Therzok
Copy link

Therzok commented Oct 2, 2014

@carlosmn the way I implemented it in MD is without adding the libgit2 path to LD_LIBRARY_PATH. I have used install_name_tool on the native binaries to use @loader_path, maybe that's why it works. :P

@Therzok
Copy link

Therzok commented Oct 2, 2014

otool -L libgit2-69db893.dylib

libgit2-69db893.dylib:
    libgit2-69db893.dylib (compatibility version 21.0.0, current version 0.21.0)
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
    /usr/lib/libssl.0.9.8.dylib (compatibility version 0.9.8, current version 50.0.0)
    /usr/lib/libcrypto.0.9.8.dylib (compatibility version 0.9.8, current version 50.0.0)
    @loader_path/libssh2.dylib (compatibility version 2.0.0, current version 2.1.0)
    /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

@Therzok
Copy link

Therzok commented Oct 2, 2014

The sequence of commands I've used in this was:
install_name_tool -id libgit2-69db893.dylib libgit2-69db893.dylib
install_name_tool -change <absolute_path_to_libssh2> @loader_path/libssh2.dylib

@Therzok
Copy link

Therzok commented Oct 2, 2014

@carlosmn but on Linux it should justwork™. Linux user reported it worked without any extra effort if the libgit2 binaries are side-by-side with the libgit2sharp dlls.

@carlosmn
Copy link

carlosmn commented Oct 2, 2014

That shows how you can ship the dependencies of libgit2, but not how mono/LibGit2Sharp.dll knows to load libgit2-abcd.so from the current directory, since doing this should precisely not work unless you take extra steps. Do you have a LibGit2Sharp.dll.config file that lets you do that?

@Therzok
Copy link

Therzok commented Oct 2, 2014

Simply setting -id to the filename works.

@Therzok
Copy link

Therzok commented Oct 2, 2014

No, no .dll.config. those are all the changes implied. Same directory files, those linker changes. That is all.

@Therzok
Copy link

Therzok commented Oct 4, 2014

@carlosmn Here's a script I wrote which takes binaries you ship in a directory called 'mac' and makes dylibs loadable from the same directory as a managed dll.

https://github.com/mono/sharpsvn-binary/blob/master/fix_links.sh

@gep13
Copy link
Member Author

gep13 commented Oct 4, 2014

So, I must have sounded like I know more than I do, because you two have successfully lost me :-)

Would it be possible for either of you to break down each of the steps that I listed into actual implementation steps? i.e. how are each of them done? I get the premise of how to do each one, but how I would actually build the native DLL's I wouldn't know where to start. Venturing into the unknown here, I am Windows through and through just now :-)

@carlosmn
Copy link

carlosmn commented Oct 5, 2014

@gep13 to build libgit2sharp and the libgit2 which works with it, you run ./build.libgit2sharp.sh and then grab the shared object from libgit2/build/libgit2-<hash>.so.SOVERSION, which you could rename to simply libgit2-<hash>.so if you're just going to ship it, or take all three versions.

@gep13
Copy link
Member Author

gep13 commented Oct 5, 2014

Thanks for the information! I am not planning on shipping anything just now, this is really just an investigation I am doing to see what is possible :-)

@carlosmn
Copy link

carlosmn commented Oct 5, 2014

So it turns out the looking in the current path is the behaviour for Mach's dlopen(), so while that might work on OSX, it looks like it might not work on any other unix.

@asbjornu
Copy link
Member

Just as a reference (for search and such), I ran into this problem just now on OS X 10.9.5 with Mono 3.10.0, while running xbuild, using the GitVersionTask:

Target UpdateAssemblyInfo:
: error : Error occurred: System.TypeInitializationException: An exception was thrown by the type initializer for LibGit2Sharp.Core.NativeMethods ---> System.DllNotFoundException: git2-69db893
  at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_threads_init ()
  at LibGit2Sharp.Core.NativeMethods+LibraryLifetimeObject..ctor () [0x00000] in <filename unknown>:0
  at LibGit2Sharp.Core.NativeMethods..cctor () [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at LibGit2Sharp.Core.Proxy+<>c__DisplayClass32.<git_repository_discover>b__31 (LibGit2Sharp.Core.Handles.GitBuf buf) [0x00000] in <filename unknown>:0
  at LibGit2Sharp.Core.Proxy.ConvertPath (System.Func`2 pathRetriever) [0x00000] in <filename unknown>:0
  at LibGit2Sharp.Core.Proxy.git_repository_discover (LibGit2Sharp.Core.FilePath start_path) [0x00000] in <filename unknown>:0
  at LibGit2Sharp.Repository.Discover (System.String startingPath) [0x00000] in <filename unknown>:0
  at GitVersion.GitDirFinder.TreeWalkForGitDir (System.String currentDirectory) [0x00000] in <filename unknown>:0
  at VersionAndBranchFinder.TryGetVersion (System.String directory, CachedVersion& versionAndBranch) [0x00000] in <filename unknown>:0
  at GitVersionTask.WriteVersionInfoToBuildLog.InnerExecute () [0x00000] in <filename unknown>:0
  at GitVersionTask.WriteVersionInfoToBuildLog.Execute () [0x00000] in <filename unknown>:0
Task "WriteVersionInfoToBuildLog" execution -- FAILED
Done building target "UpdateAssemblyInfo" in project "/Volumes/Dev/Misc/raven-csharp/src/app/SharpRaven/SharpRaven.csproj".-- FAILED

It would be nice if GitVersion could conditionally bundle up the right version of LibGit2Sharp on the different platforms, somehow. Could this be solved through NuGet by having different package references on different platforms (if LibGit2Sharp even exists pre-built for other platforms than Windows)?

@JakeGinnivan
Copy link
Contributor

It would be great to have mono support and make GitVersion cross platform. It needs a champion to make this feature happen, if anyone wants to take it on feel free!

@nulltoken
Copy link
Contributor

Quick heads up. Check @bording's libgit2/libgit2sharp#984. It should help running LibGit2Sharp on non-Windows platform by embedding the Win/Mac OS X/Linux compiled binaries in a separate NuGet package.

@JakeGinnivan
Copy link
Contributor

That is awesome news @nulltoken. When this drops it would be good to try and get GitVersion running on mac/linux :D

@nulltoken
Copy link
Contributor

@JakeGinnivan That was the plan 😉 I'll keep you updated when it's ready for battlefield testing

@nulltoken
Copy link
Contributor

@JakeGinnivan Latest prerelease package (0.22.0-pre20150529055949) is waiting for you, Sir!

@therosco
Copy link

therosco commented Jul 1, 2015

Any progress?

@JakeGinnivan
Copy link
Contributor

Nope, still up for grabs if anyone wants to have a crack at it

@clairernovotny
Copy link

👍 would love to see this happen, esp to get Xamarin builds on OSX for iOS working the same as the Windows agents

@BeeWarloc
Copy link

I have made an attempt to upgrade to the latest prerelease of LibGit2Sharp to fix this for GitVersionTask, as it broke the build of one of my projects on mono.

#638

Due to a problem with how mono searches for dlls, I had to place them in libNativeBinaries instead of NativeBinaries. There is a discussion about this here: libgit2/libgit2sharp#1170

This has received limited testing, but it works for compiling a medium sized project with mono 4.0.3 on Ubuntu 15.04.

@hazzik
Copy link

hazzik commented Nov 25, 2015

What about switching to ngit? As it is fully managed library? @Therzok

@Therzok
Copy link

Therzok commented Nov 25, 2015

@hazzik NGit is unmaintained, and we switched away from it in MonoDevelop because of various issues that arose when using it. Updating it is not an easy task either.

@ghuntley
Copy link
Contributor

It seems by the comments on #638 that mono now works on x86/amd64 for Linux.

Mono on OSX remains unresolved.

https://gist.github.com/ghuntley/f7f9a120ab40a69f56e9

using

<title>GitVersion.CommandLine</title>
<version>3.4.1</version>

$ mono --version
Mono JIT compiler version 4.2.2 (explicit/996df3c Wed Jan 20 00:19:48 EST 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS:           normal
SIGSEGV:       altstack
Notification:  kqueue
Architecture:  x86
Disabled:      none
Misc:          softdebug
LLVM:          yes(3.6.0svn-mono-(detached/a173357)
GC:            sgen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.