Skip to content

Commit 5f5e53b

Browse files
committed
Merge pull request #17 from libgit2/custom_dllname
Allow custom DLL names
2 parents e9c5450 + 57af6be commit 5f5e53b

File tree

5 files changed

+123
-5
lines changed

5 files changed

+123
-5
lines changed

README.md

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
Native Binaries NuGet Package for LibGit2Sharp
2+
==============================================
3+
4+
[Libgit2Sharp](https://github.com/libgit2/libgit2sharp) is a managed
5+
wrapper around [libgit2](https://github.com/libgit2/libgit2), and as
6+
such requires compilation of libgit2 for your platform. LibGit2Sharp
7+
makes this easy by distributing NuGet packages that include precompiled
8+
versions of these native binaries.
9+
10+
If you need to build your own native binaries for some reason, you can
11+
do so easily with the scripts in this repository:
12+
13+
1. Clone the `LibGit2Sharp.NativeBinaries` repository. Do so recursively
14+
to ensure that the `libgit2` submodule is initialized automatically:
15+
16+
`git clone --recursive https://github.com/libgit2/libgit2sharp.nativebinaries`
17+
18+
(If you have already cloned this repository (which seems quite
19+
likely since you are reading this file!) then you can simply run
20+
`git submodule init` followed by `git submodule update`.)
21+
22+
2. Update the included libgit2 sources and configuration files to the
23+
version of libgit2 you want to build. For example, to build
24+
commit `1a2b3c4`:
25+
26+
`UpdateLibgit2ToSha.ps1 1a2b3c4`
27+
28+
Or you can specify references. To build the remote's `master` branch:
29+
30+
`UpdateLibgit2ToSha.ps1 master`
31+
32+
3. Build the libgit2 binaries. For Windows, this requires a Visual Studio
33+
installation, and will compile both x86 and amd64 variants. (See
34+
"Notes on Visual Studio", below). Run the build PowerShell script,
35+
specifying the version number of Visual Studio as the first argument.
36+
For example, to build with Visual Studio 2013 (aka "Visual Studio 12.0"):
37+
38+
`build.libgit2.ps1 12`
39+
40+
For Linux, this will build only the architecture that you're running
41+
(x86 or amd64). For Mac OS X, this will build a fat library that
42+
includes both x86 and amd64. Run the shell script:
43+
44+
`build.libgit2.sh`
45+
46+
4. Create the NuGet package from the built binaries. You will need to
47+
specify the version number of the resultant NuGet package that you
48+
want to generate. Note that you may wish to provide a suffix to
49+
disambiguate your custom package from the official, published NuGet
50+
packages. For example, if you are building a product called
51+
`fooproduct` then that may be a helpful suffix.
52+
53+
To build a NuGet package at version `1.2.3-foo`:
54+
55+
`buildpackage.ps1 1.2.3-foo`
56+
57+
And the result will be a NuGet package in the current directory:
58+
59+
`LibGit2Sharp.NativeBinaries.1.2.3-foo.nupkg`
60+
61+
Note that the `-foo` suffix technically makes this a "prerelease"
62+
package, according to NuGet, which may be further help in avoiding
63+
any mixups with the official packages, but may also require you to
64+
opt-in to prerelease packages in your NuGet package manager.
65+
66+
Specifying custom DLL names
67+
---------------------------
68+
If you want to redistribute a LibGit2Sharp that uses a custom libgit2,
69+
you may want to change the name of the libgit2 shared library file to
70+
disambiguate it from other installations. This may be useful if you
71+
are running as a plugin inside a larger process and wish to avoid
72+
conflicting with other plugins who may wish to use LibGit2Sharp and
73+
want to ensure that *your* version of libgit2 is loaded into memory
74+
and available to you.
75+
76+
For example, if your plugin names if `fooplugin`, you may wish to
77+
distribute a DLL named `git2-fooplugin.dll`. You can specify the
78+
custom DLL name as the second argument to the update and build scripts:
79+
80+
UpdateLibgit2ToSha.ps1 1a2b3c4 git2-fooplugin
81+
build.libgit2.sh 14 git2-fooplugin
82+
83+
Then build the NuGet package as described above, making sure to provide
84+
a helpful suffix to ensure that your NuGet package will not be confused
85+
with the official packages.
86+
87+
Notes on Visual Studio
88+
----------------------
89+
Visual Studio is required to build the native binaries, however you
90+
do not need to install a *paid* version of Visual Studio. libgit2
91+
can be compiled using [Visual Studio Community](https://www.visualstudio.com/en-us/products/visual-studio-community-vs),
92+
which is free for building open source applications.
93+
94+
You need to specify the actual version number (not the marketing name)
95+
of Visual Studio. (For example, "Visual Studio 2013" is the name of the
96+
product, but its actual version number is "12.0".) A handy guide:
97+
98+
| Marketing Name | Version Number
99+
|--------------------|---------------
100+
| Visual Studio 2010 | 10
101+
| Visual Studio 2012 | 11
102+
| Visual Studio 2013 | 12
103+
| Visual Studio 2015 | 14
104+

UpdateLibgit2ToSha.ps1

+10-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#>
77

88
Param(
9-
[string]$sha = 'HEAD'
9+
[string]$sha = 'HEAD',
10+
[string]$libgit2Name = ''
1011
)
1112

1213
Set-StrictMode -Version Latest
@@ -81,15 +82,21 @@ Push-Location $libgit2Directory
8182

8283
Pop-Location
8384

85+
if (![string]::IsNullOrEmpty($libgit2Name)) {
86+
$binaryFilename = $libgit2Name
87+
} else {
88+
$binaryFilename = "git2-" + $sha.Substring(0,7)
89+
}
90+
8491
sc -Encoding ASCII (Join-Path $projectDirectory "nuget.package\libgit2\libgit2_hash.txt") $sha
85-
86-
$binaryFilename = "git2-" + $sha.Substring(0,7)
92+
sc -Encoding ASCII (Join-Path $projectDirectory "nuget.package\libgit2\libgit2_filename.txt") $binaryFilename
8793

8894
$buildProperties = @"
8995
<?xml version="1.0" encoding="utf-8"?>
9096
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
9197
<ItemGroup>
9298
<EmbeddedResource Include="`$(MSBuildThisFileDirectory)\..\libgit2\libgit2_hash.txt" />
99+
<EmbeddedResource Include="`$(MSBuildThisFileDirectory)\..\libgit2\libgit2_filename.txt" />
93100
</ItemGroup>
94101
<ItemGroup>
95102
<None Condition="Exists('`$(MSBuildThisFileDirectory)\..\libgit2\windows\amd64\$binaryFilename.dll')" Include="`$(MSBuildThisFileDirectory)\..\libgit2\windows\amd64\$binaryFilename.dll">

build.libgit2.ps1

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
Param(
1313
[string]$vs = '10',
14+
[string]$libgit2Name = '',
1415
[switch]$test,
1516
[switch]$debug
1617
)
@@ -23,7 +24,12 @@ $x86Directory = Join-Path $projectDirectory "nuget.package\libgit2\windows\x86"
2324
$x64Directory = Join-Path $projectDirectory "nuget.package\libgit2\windows\amd64"
2425
$hashFile = Join-Path $projectDirectory "nuget.package\libgit2\libgit2_hash.txt"
2526
$sha = Get-Content $hashFile
26-
$binaryFilename = "git2-" + $sha.Substring(0,7)
27+
28+
if (![string]::IsNullOrEmpty($libgit2Name)) {
29+
$binaryFilename = $libgit2Name
30+
} else {
31+
$binaryFilename = "git2-" + $sha.Substring(0,7)
32+
}
2733

2834
$build_clar = 'OFF'
2935
if ($test.IsPresent) { $build_clar = 'ON' }

buildpackage.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ if ( -Not (Test-Path $linuxDirectory\*.so) )
3838
Set-Content $linuxDirectory\addbinaries.here $null
3939
}
4040

41-
Nuget.exe Pack nuget.package\NativeBinaries.nuspec -Version $version$versionSuffix -NoPackageAnalysis
41+
.\Nuget.exe Pack nuget.package\NativeBinaries.nuspec -Version $version$versionSuffix -NoPackageAnalysis
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
git2-4d6362b

0 commit comments

Comments
 (0)