From dede983f81624d232067d4473c6f2b6dd11ad029 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 15 Jul 2015 18:30:46 -0500 Subject: [PATCH 1/4] Update/build scripts: allow custom DLL names Allow custom shared library names (eg, `git2-mycompany.dll` instead of `git2-hash.dll`) to allow a single process to potentially load multiple instances of libgit2. --- UpdateLibgit2ToSha.ps1 | 9 +++++++-- build.libgit2.ps1 | 8 +++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/UpdateLibgit2ToSha.ps1 b/UpdateLibgit2ToSha.ps1 index fa7fdb5c..fa1a09e1 100644 --- a/UpdateLibgit2ToSha.ps1 +++ b/UpdateLibgit2ToSha.ps1 @@ -6,7 +6,8 @@ #> Param( - [string]$sha = 'HEAD' + [string]$sha = 'HEAD', + [string]$libgit2Name = '' ) Set-StrictMode -Version Latest @@ -83,7 +84,11 @@ Push-Location $libgit2Directory sc -Encoding ASCII (Join-Path $projectDirectory "nuget.package\libgit2\libgit2_hash.txt") $sha - $binaryFilename = "git2-" + $sha.Substring(0,7) + if (![string]::IsNullOrEmpty($libgit2Name)) { + $binaryFilename = $libgit2Name + } else { + $binaryFilename = "git2-" + $sha.Substring(0,7) + } $buildProperties = @" diff --git a/build.libgit2.ps1 b/build.libgit2.ps1 index 7f6bc114..d4d65e54 100644 --- a/build.libgit2.ps1 +++ b/build.libgit2.ps1 @@ -11,6 +11,7 @@ Param( [string]$vs = '10', + [string]$libgit2Name = '', [switch]$test, [switch]$debug ) @@ -23,7 +24,12 @@ $x86Directory = Join-Path $projectDirectory "nuget.package\libgit2\windows\x86" $x64Directory = Join-Path $projectDirectory "nuget.package\libgit2\windows\amd64" $hashFile = Join-Path $projectDirectory "nuget.package\libgit2\libgit2_hash.txt" $sha = Get-Content $hashFile -$binaryFilename = "git2-" + $sha.Substring(0,7) + +if (![string]::IsNullOrEmpty($libgit2Name)) { + $binaryFilename = $libgit2Name +} else { + $binaryFilename = "git2-" + $sha.Substring(0,7) +} $build_clar = 'OFF' if ($test.IsPresent) { $build_clar = 'ON' } From d9efc5880c4e9f4f16002acdf4ca345b2672bf55 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 15 Jul 2015 18:32:34 -0500 Subject: [PATCH 2/4] buildpackage: use the Nuget.exe in the cwd Not everybody has `.` in their path, and we include `Nuget.exe` in the build package. Use that explicitly. --- buildpackage.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildpackage.ps1 b/buildpackage.ps1 index 24b73c19..06337c17 100644 --- a/buildpackage.ps1 +++ b/buildpackage.ps1 @@ -38,4 +38,4 @@ if ( -Not (Test-Path $linuxDirectory\*.so) ) Set-Content $linuxDirectory\addbinaries.here $null } -Nuget.exe Pack nuget.package\NativeBinaries.nuspec -Version $version$versionSuffix -NoPackageAnalysis +.\Nuget.exe Pack nuget.package\NativeBinaries.nuspec -Version $version$versionSuffix -NoPackageAnalysis From 58e36e0350224f57f6da3639d9a67bb4e9aa8abe Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 16 Jul 2015 11:10:01 -0500 Subject: [PATCH 3/4] Update script: propagate custom DLL name LibGit2Sharp must know the custom DLL name to be able to load it. --- UpdateLibgit2ToSha.ps1 | 6 ++++-- nuget.package/libgit2/libgit2_filename.txt | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 nuget.package/libgit2/libgit2_filename.txt diff --git a/UpdateLibgit2ToSha.ps1 b/UpdateLibgit2ToSha.ps1 index fa1a09e1..445cfa53 100644 --- a/UpdateLibgit2ToSha.ps1 +++ b/UpdateLibgit2ToSha.ps1 @@ -82,19 +82,21 @@ Push-Location $libgit2Directory Pop-Location - sc -Encoding ASCII (Join-Path $projectDirectory "nuget.package\libgit2\libgit2_hash.txt") $sha - if (![string]::IsNullOrEmpty($libgit2Name)) { $binaryFilename = $libgit2Name } else { $binaryFilename = "git2-" + $sha.Substring(0,7) } + sc -Encoding ASCII (Join-Path $projectDirectory "nuget.package\libgit2\libgit2_hash.txt") $sha + sc -Encoding ASCII (Join-Path $projectDirectory "nuget.package\libgit2\libgit2_filename.txt") $binaryFilename + $buildProperties = @" + diff --git a/nuget.package/libgit2/libgit2_filename.txt b/nuget.package/libgit2/libgit2_filename.txt new file mode 100644 index 00000000..f0a7897a --- /dev/null +++ b/nuget.package/libgit2/libgit2_filename.txt @@ -0,0 +1 @@ +git2-4d6362b From 57af6be13ef34f8d321036545105cfbfa1cc8d27 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 16 Jul 2015 11:10:20 -0500 Subject: [PATCH 4/4] README: provide some information to future hackers --- README.md | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..da6f3c52 --- /dev/null +++ b/README.md @@ -0,0 +1,104 @@ +Native Binaries NuGet Package for LibGit2Sharp +============================================== + +[Libgit2Sharp](https://github.com/libgit2/libgit2sharp) is a managed +wrapper around [libgit2](https://github.com/libgit2/libgit2), and as +such requires compilation of libgit2 for your platform. LibGit2Sharp +makes this easy by distributing NuGet packages that include precompiled +versions of these native binaries. + +If you need to build your own native binaries for some reason, you can +do so easily with the scripts in this repository: + +1. Clone the `LibGit2Sharp.NativeBinaries` repository. Do so recursively + to ensure that the `libgit2` submodule is initialized automatically: + + `git clone --recursive https://github.com/libgit2/libgit2sharp.nativebinaries` + + (If you have already cloned this repository (which seems quite + likely since you are reading this file!) then you can simply run + `git submodule init` followed by `git submodule update`.) + +2. Update the included libgit2 sources and configuration files to the + version of libgit2 you want to build. For example, to build + commit `1a2b3c4`: + + `UpdateLibgit2ToSha.ps1 1a2b3c4` + + Or you can specify references. To build the remote's `master` branch: + + `UpdateLibgit2ToSha.ps1 master` + +3. Build the libgit2 binaries. For Windows, this requires a Visual Studio + installation, and will compile both x86 and amd64 variants. (See + "Notes on Visual Studio", below). Run the build PowerShell script, + specifying the version number of Visual Studio as the first argument. + For example, to build with Visual Studio 2013 (aka "Visual Studio 12.0"): + + `build.libgit2.ps1 12` + + For Linux, this will build only the architecture that you're running + (x86 or amd64). For Mac OS X, this will build a fat library that + includes both x86 and amd64. Run the shell script: + + `build.libgit2.sh` + +4. Create the NuGet package from the built binaries. You will need to + specify the version number of the resultant NuGet package that you + want to generate. Note that you may wish to provide a suffix to + disambiguate your custom package from the official, published NuGet + packages. For example, if you are building a product called + `fooproduct` then that may be a helpful suffix. + + To build a NuGet package at version `1.2.3-foo`: + + `buildpackage.ps1 1.2.3-foo` + + And the result will be a NuGet package in the current directory: + + `LibGit2Sharp.NativeBinaries.1.2.3-foo.nupkg` + + Note that the `-foo` suffix technically makes this a "prerelease" + package, according to NuGet, which may be further help in avoiding + any mixups with the official packages, but may also require you to + opt-in to prerelease packages in your NuGet package manager. + +Specifying custom DLL names +--------------------------- +If you want to redistribute a LibGit2Sharp that uses a custom libgit2, +you may want to change the name of the libgit2 shared library file to +disambiguate it from other installations. This may be useful if you +are running as a plugin inside a larger process and wish to avoid +conflicting with other plugins who may wish to use LibGit2Sharp and +want to ensure that *your* version of libgit2 is loaded into memory +and available to you. + +For example, if your plugin names if `fooplugin`, you may wish to +distribute a DLL named `git2-fooplugin.dll`. You can specify the +custom DLL name as the second argument to the update and build scripts: + + UpdateLibgit2ToSha.ps1 1a2b3c4 git2-fooplugin + build.libgit2.sh 14 git2-fooplugin + +Then build the NuGet package as described above, making sure to provide +a helpful suffix to ensure that your NuGet package will not be confused +with the official packages. + +Notes on Visual Studio +---------------------- +Visual Studio is required to build the native binaries, however you +do not need to install a *paid* version of Visual Studio. libgit2 +can be compiled using [Visual Studio Community](https://www.visualstudio.com/en-us/products/visual-studio-community-vs), +which is free for building open source applications. + +You need to specify the actual version number (not the marketing name) +of Visual Studio. (For example, "Visual Studio 2013" is the name of the +product, but its actual version number is "12.0".) A handy guide: + +| Marketing Name | Version Number +|--------------------|--------------- +| Visual Studio 2010 | 10 +| Visual Studio 2012 | 11 +| Visual Studio 2013 | 12 +| Visual Studio 2015 | 14 +