Skip to content

Commit 0d870da

Browse files
committed
Create LibGit2Sharp.NativeBinaries NuGet package
1 parent e1728a5 commit 0d870da

15 files changed

+1401
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.nupkg
2+
*.dll
3+
*.pdb
4+
*.dylib
5+
*.so
6+
*.zip
7+
8+
# nuget package placeholder
9+
*.here

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "libgit2"]
2+
path = libgit2
3+
url = https://github.com/libgit2/libgit2.git

.travis.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
language: c
2+
3+
os:
4+
- osx
5+
- linux
6+
7+
branches:
8+
only:
9+
- master
10+
11+
before_install:
12+
- date -u
13+
- uname -a
14+
- env | grep -v "BINTRAY_API_KEY" | sort
15+
16+
install: true
17+
18+
script: ./build.libgit2.sh
19+
20+
after_success: ./uploadbinaries.sh

NuGet.exe

1.59 MB
Binary file not shown.

UpdateLibgit2ToSha.ps1

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<#
2+
.SYNOPSIS
3+
Updates the libgit2 submodule to the specified commit and updates libgit2_hash.txt and NativeBinaries.props with the new hash value.
4+
.PARAMETER sha
5+
Desired libgit2 version. This is run through `git rev-parse`, so branch names are okay too.
6+
#>
7+
8+
Param(
9+
[string]$sha = 'HEAD'
10+
)
11+
12+
Set-StrictMode -Version Latest
13+
14+
$self = Split-Path -Leaf $MyInvocation.MyCommand.Path
15+
$projectDirectory = Split-Path $MyInvocation.MyCommand.Path
16+
$libgit2Directory = Join-Path $projectDirectory "libgit2"
17+
18+
function Run-Command([scriptblock]$Command, [switch]$Fatal, [switch]$Quiet) {
19+
$output = ""
20+
if ($Quiet) {
21+
$output = & $Command 2>&1
22+
} else {
23+
& $Command
24+
}
25+
26+
if (!$Fatal) {
27+
return
28+
}
29+
30+
$exitCode = 0
31+
if ($LastExitCode -ne 0) {
32+
$exitCode = $LastExitCode
33+
} elseif (!$?) {
34+
$exitCode = 1
35+
} else {
36+
return
37+
}
38+
39+
$error = "``$Command`` failed"
40+
if ($output) {
41+
Write-Host -ForegroundColor yellow $output
42+
$error += ". See output above."
43+
}
44+
Throw $error
45+
}
46+
47+
function Find-Git {
48+
$git = @(Get-Command git)[0] 2>$null
49+
if ($git) {
50+
$git = $git.Definition
51+
Write-Host -ForegroundColor Gray "Using git: $git"
52+
& $git --version | write-host -ForegroundColor Gray
53+
return $git
54+
}
55+
throw "Error: Can't find git"
56+
}
57+
58+
Push-Location $libgit2Directory
59+
60+
& {
61+
trap {
62+
Pop-Location
63+
break
64+
}
65+
66+
$git = Find-Git
67+
68+
Write-Output "Fetching..."
69+
Run-Command -Quiet { & $git fetch }
70+
71+
Write-Output "Verifying $sha..."
72+
$sha = & $git rev-parse $sha
73+
if ($LASTEXITCODE -ne 0) {
74+
write-host -foregroundcolor red "Error: invalid SHA. USAGE: $self <SHA>"
75+
popd
76+
break
77+
}
78+
79+
Write-Output "Checking out $sha..."
80+
Run-Command -Quiet -Fatal { & $git checkout $sha }
81+
82+
Pop-Location
83+
84+
sc -Encoding ASCII (Join-Path $projectDirectory "nuget.package\libgit2\libgit2_hash.txt") $sha
85+
86+
$binaryFilename = "git2-" + $sha.Substring(0,7)
87+
88+
$buildProperties = @"
89+
<?xml version="1.0" encoding="utf-8"?>
90+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
91+
<ItemGroup>
92+
<EmbeddedResource Include="`$(MSBuildThisFileDirectory)\..\libgit2\libgit2_hash.txt" />
93+
</ItemGroup>
94+
<ItemGroup Condition=" '`$(OS)' == 'Windows_NT' ">
95+
<None Include="`$(MSBuildThisFileDirectory)\..\libgit2\windows\amd64\$binaryFilename.dll">
96+
<Link>NativeBinaries\amd64\$binaryFilename.dll</Link>
97+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
98+
</None>
99+
<None Include="`$(MSBuildThisFileDirectory)\..\libgit2\windows\amd64\$binaryFilename.pdb">
100+
<Link>NativeBinaries\amd64\$binaryFilename.pdb</Link>
101+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
102+
</None>
103+
<None Include="`$(MSBuildThisFileDirectory)\..\libgit2\windows\x86\$binaryFilename.dll">
104+
<Link>NativeBinaries\x86\$binaryFilename.dll</Link>
105+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
106+
</None>
107+
<None Include="`$(MSBuildThisFileDirectory)\..\libgit2\windows\x86\$binaryFilename.pdb">
108+
<Link>NativeBinaries\x86\$binaryFilename.pdb</Link>
109+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
110+
</None>
111+
</ItemGroup>
112+
<ItemGroup Condition=" '`$(OS)' == 'Unix' And Exists('/Library/Frameworks') ">
113+
<None Include="`$(MSBuildThisFileDirectory)\..\libgit2\osx\lib$binaryFilename.dylib">
114+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
115+
</None>
116+
</ItemGroup>
117+
<ItemGroup Condition=" '`$(OS)' == 'Unix' And !Exists('/Library/Frameworks') ">
118+
<None Include="`$(MSBuildThisFileDirectory)\..\libgit2\linux\amd64\lib$binaryFilename.so">
119+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
120+
</None>
121+
</ItemGroup>
122+
</Project>
123+
"@
124+
125+
sc -Encoding UTF8 (Join-Path $projectDirectory "nuget.package\build\LibGit2Sharp.NativeBinaries.props") $buildProperties
126+
127+
Write-Output "Done!"
128+
}
129+
exit

appveyor.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: 1.0.{build}
2+
3+
skip_tags: true
4+
5+
install:
6+
- git submodule update --init --recursive
7+
8+
build_script:
9+
- ps: .\build.libgit2.ps1 -vs 12
10+
11+
after_build:
12+
- ps: |
13+
$pre = $true
14+
if (($env:APPVEYOR_PULL_REQUEST_NUMBER -eq $null) -and ($env:APPVEYOR_REPO_BRANCH -eq "master"))
15+
{
16+
$pre = $false
17+
}
18+
.\buildpackage.ps1 $env:APPVEYOR_BUILD_VERSION -pre:$pre
19+
20+
test: off
21+
22+
artifacts:
23+
- path: '*.nupkg'

build.libgit2.ps1

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<#
2+
.SYNOPSIS
3+
Builds a version of libgit2 and copies it to the nuget packaging directory.
4+
.PARAMETER vs
5+
Version of Visual Studio project files to generate. Cmake supports "10" (default), "11" and "12".
6+
.PARAMETER test
7+
If set, run the libgit2 tests on the desired version.
8+
.PARAMETER debug
9+
If set, build the "Debug" configuration of libgit2, rather than "RelWithDebInfo" (default).
10+
#>
11+
12+
Param(
13+
[string]$vs = '10',
14+
[switch]$test,
15+
[switch]$debug
16+
)
17+
18+
Set-StrictMode -Version Latest
19+
20+
$projectDirectory = Split-Path $MyInvocation.MyCommand.Path
21+
$libgit2Directory = Join-Path $projectDirectory "libgit2"
22+
$x86Directory = Join-Path $projectDirectory "nuget.package\libgit2\windows\x86"
23+
$x64Directory = Join-Path $projectDirectory "nuget.package\libgit2\windows\amd64"
24+
$hashFile = Join-Path $projectDirectory "nuget.package\libgit2\libgit2_hash.txt"
25+
$sha = Get-Content $hashFile
26+
$binaryFilename = "git2-" + $sha.Substring(0,7)
27+
28+
$build_clar = 'OFF'
29+
if ($test.IsPresent) { $build_clar = 'ON' }
30+
31+
$configuration = "RelWithDebInfo"
32+
if ($debug.IsPresent) { $configuration = "Debug" }
33+
34+
function Run-Command([scriptblock]$Command, [switch]$Fatal, [switch]$Quiet) {
35+
$output = ""
36+
if ($Quiet) {
37+
$output = & $Command 2>&1
38+
} else {
39+
& $Command
40+
}
41+
42+
if (!$Fatal) {
43+
return
44+
}
45+
46+
$exitCode = 0
47+
if ($LastExitCode -ne 0) {
48+
$exitCode = $LastExitCode
49+
} elseif (!$?) {
50+
$exitCode = 1
51+
} else {
52+
return
53+
}
54+
55+
$error = "``$Command`` failed"
56+
if ($output) {
57+
Write-Host -ForegroundColor yellow $output
58+
$error += ". See output above."
59+
}
60+
Throw $error
61+
}
62+
63+
function Find-CMake {
64+
# Look for cmake.exe in $Env:PATH.
65+
$cmake = @(Get-Command cmake.exe)[0] 2>$null
66+
if ($cmake) {
67+
$cmake = $cmake.Definition
68+
} else {
69+
# Look for the highest-versioned cmake.exe in its default location.
70+
$cmake = @(Resolve-Path (Join-Path ${Env:ProgramFiles(x86)} "CMake *\bin\cmake.exe"))
71+
if ($cmake) {
72+
$cmake = $cmake[-1].Path
73+
}
74+
}
75+
if (!$cmake) {
76+
throw "Error: Can't find cmake.exe"
77+
}
78+
$cmake
79+
}
80+
81+
function Ensure-Property($expected, $propertyValue, $propertyName, $path) {
82+
if ($propertyValue -eq $expected) {
83+
return
84+
}
85+
86+
throw "Error: Invalid '$propertyName' property in generated '$path' (Expected: $expected - Actual: $propertyValue)"
87+
}
88+
89+
function Assert-Consistent-Naming($expected, $path) {
90+
$dll = get-item $path
91+
92+
Ensure-Property $expected $dll.Name "Name" $dll.Fullname
93+
Ensure-Property $expected $dll.VersionInfo.InternalName "VersionInfo.InternalName" $dll.Fullname
94+
Ensure-Property $expected $dll.VersionInfo.OriginalFilename "VersionInfo.OriginalFilename" $dll.Fullname
95+
}
96+
97+
try {
98+
Push-Location $libgit2Directory
99+
100+
$cmake = Find-CMake
101+
$ctest = Join-Path (Split-Path -Parent $cmake) "ctest.exe"
102+
103+
Write-Output "Building 32-bit..."
104+
Run-Command -Quiet { & remove-item build -recurse -force }
105+
Run-Command -Quiet { & mkdir build }
106+
cd build
107+
Run-Command -Quiet -Fatal { & $cmake -G "Visual Studio $vs" -D ENABLE_TRACE=ON -D "BUILD_CLAR=$build_clar" -D "LIBGIT2_FILENAME=$binaryFilename" -DSTDCALL=ON .. }
108+
Run-Command -Quiet -Fatal { & $cmake --build . --config $configuration }
109+
if ($test.IsPresent) { Run-Command -Quiet -Fatal { & $ctest -V . } }
110+
cd $configuration
111+
Assert-Consistent-Naming "$binaryFilename.dll" "*.dll"
112+
Run-Command -Quiet { & rm *.exp }
113+
Run-Command -Quiet { & rm $x86Directory\* }
114+
Run-Command -Quiet { & mkdir -fo $x86Directory }
115+
Run-Command -Quiet -Fatal { & copy -fo * $x86Directory -Exclude *.lib }
116+
117+
Write-Output "Building 64-bit..."
118+
cd ..
119+
Run-Command -Quiet { & mkdir build64 }
120+
cd build64
121+
Run-Command -Quiet -Fatal { & $cmake -G "Visual Studio $vs Win64" -D THREADSAFE=ON -D ENABLE_TRACE=ON -D "BUILD_CLAR=$build_clar" -D "LIBGIT2_FILENAME=$binaryFilename" -DSTDCALL=ON ../.. }
122+
Run-Command -Quiet -Fatal { & $cmake --build . --config $configuration }
123+
if ($test.IsPresent) { Run-Command -Quiet -Fatal { & $ctest -V . } }
124+
cd $configuration
125+
Assert-Consistent-Naming "$binaryFilename.dll" "*.dll"
126+
Run-Command -Quiet { & rm *.exp }
127+
Run-Command -Quiet { & rm $x64Directory\* }
128+
Run-Command -Quiet { & mkdir -fo $x64Directory }
129+
Run-Command -Quiet -Fatal { & copy -fo * $x64Directory -Exclude *.lib }
130+
131+
Write-Output "Done!"
132+
}
133+
finally {
134+
Pop-Location
135+
}

build.libgit2.sh

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
LIBGIT2SHA=`cat ./nuget.package/libgit2/libgit2_hash.txt`
4+
SHORTSHA=${LIBGIT2SHA:0:7}
5+
6+
rm -rf libgit2/build
7+
mkdir libgit2/build
8+
pushd libgit2/build
9+
10+
export _BINPATH=`pwd`
11+
12+
cmake -DCMAKE_BUILD_TYPE:STRING=Release \
13+
-DBUILD_CLAR:BOOL=OFF \
14+
-DUSE_SSH=OFF \
15+
-DENABLE_TRACE=ON \
16+
-DLIBGIT2_FILENAME=git2-$SHORTSHA \
17+
-DCMAKE_OSX_ARCHITECTURES="i386;x86_64" \
18+
..
19+
cmake --build .
20+
21+
popd
22+
23+
OS=`uname`
24+
ARCH=`uname -m`
25+
26+
PACKAGEPATH="nuget.package/libgit2"
27+
LIBEXT="so"
28+
29+
if [ $OS == "Linux" ]; then
30+
OSPATH="/linux"
31+
if [ $ARCH == "x86_64" ]; then
32+
ARCHPATH="/amd64"
33+
fi
34+
elif [ $OS == "Darwin" ]; then
35+
OSPATH="/osx"
36+
LIBEXT="dylib"
37+
else
38+
OSPATH="/unix"
39+
fi
40+
41+
rm -rf $PACKAGEPATH$OSPATH
42+
mkdir -p $PACKAGEPATH$OSPATH$ARCHPATH
43+
44+
cp libgit2/build/libgit2-$SHORTSHA.$LIBEXT $PACKAGEPATH$OSPATH$ARCHPATH
45+
46+
exit $?

0 commit comments

Comments
 (0)