Skip to content

Commit f618d24

Browse files
committed
Add ssh support and scripts for compilation
1 parent 9deb8d8 commit f618d24

23 files changed

+510
-48
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.git/**/*

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
*.dylib
55
*.so
66
*.zip
7+
deps/

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
[submodule "libgit2"]
22
path = libgit2
33
url = https://github.com/libgit2/libgit2.git
4+
[submodule "zlib"]
5+
path = zlib
6+
url = https://github.com/madler/zlib.git
7+
[submodule "libssh2"]
8+
path = libssh2
9+
url = https://github.com/libssh2/libssh2.git

Dockerfile.linux

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
FROM bording/crossbuild
21
ARG ARCH='amd64'
2+
FROM ${ARCH}/debian
33
ENV CROSS_TRIPLE=${ARCH}
4-
RUN apt update && apt -y install pkg-config
4+
RUN apt update && apt -y install cmake gcc libcurl4-openssl-dev libssl-dev pkg-config zlib1g-dev
55

66
WORKDIR /nativebinaries
77
COPY . /nativebinaries/

Dockerfile.linux-musl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ARG ARCH='amd64'
22
FROM multiarch/alpine:${ARCH}-v3.13
3-
RUN apk add --no-cache bash build-base cmake
3+
RUN apk add --no-cache bash build-base cmake openssl-dev zlib-dev
44

55
WORKDIR /nativebinaries
66
COPY . /nativebinaries/

UpdateAllLibsToSha.ps1

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
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 libgit2sha
5+
Desired libgit2 version. This is run through `git rev-parse`, so branch names are okay too.
6+
.PARAMETER libssh2sha
7+
Desired libssh2 version. This is run through `git rev-parse`, so branch names are okay too.
8+
.PARAMETER zlibsha
9+
Desired zlib version. This is run through `git rev-parse`, so branch names are okay too.
10+
#>
11+
12+
Param(
13+
[string]$libgit2sha = 'HEAD',
14+
[string]$libssh2sha = 'HEAD',
15+
[string]$zlibsha = 'HEAD'
16+
)
17+
18+
Set-StrictMode -Version Latest
19+
20+
$self = Split-Path -Leaf $MyInvocation.MyCommand.Path
21+
$projectDirectory = Split-Path $MyInvocation.MyCommand.Path
22+
$libgit2Directory = Join-Path $projectDirectory "libgit2"
23+
$libssh2Directory = Join-Path $projectDirectory "libssh2"
24+
$zlibDirectory = Join-Path $projectDirectory "zlib"
25+
26+
function Invoke-Command([scriptblock]$Command, [switch]$Fatal, [switch]$Quiet) {
27+
$output = ""
28+
if ($Quiet) {
29+
$output = & $Command 2>&1
30+
} else {
31+
& $Command
32+
}
33+
34+
if (!$Fatal) {
35+
return
36+
}
37+
38+
$exitCode = 0
39+
if ($LastExitCode -ne 0) {
40+
$exitCode = $LastExitCode
41+
} elseif (!$?) {
42+
$exitCode = 1
43+
} else {
44+
return
45+
}
46+
47+
$error = "``$Command`` failed"
48+
if ($output) {
49+
Write-Host -ForegroundColor yellow $output
50+
$error += ". See output above."
51+
}
52+
Throw $error
53+
}
54+
55+
function Find-Git {
56+
$git = @(Get-Command git)[0] 2>$null
57+
if ($git) {
58+
$git = $git.Definition
59+
Write-Host -ForegroundColor Gray "Using git: $git"
60+
& $git --version | write-host -ForegroundColor Gray
61+
return $git
62+
}
63+
throw "Error: Can't find git"
64+
}
65+
66+
function Update-Lib($git, $lib, $directory, [ref]$sha) {
67+
Push-Location $directory
68+
69+
Write-Output "$lib -> Fetching..."
70+
Invoke-Command -Quiet { & $git fetch }
71+
72+
Write-Output "$lib -> Verifying $($sha.value)..."
73+
$sha.value = & $git rev-parse $sha.value
74+
if ($LASTEXITCODE -ne 0) {
75+
write-host -foregroundcolor red "Error: invalid SHA. USAGE: $self <SHA>"
76+
popd
77+
break
78+
}
79+
80+
Write-Output "$lib -> Checking out $($sha.value)..."
81+
Invoke-Command -Quiet -Fatal { & $git checkout $sha.value }
82+
83+
Pop-Location
84+
}
85+
86+
Push-Location $libgit2Directory
87+
88+
& {
89+
trap {
90+
Pop-Location
91+
break
92+
}
93+
94+
$git = Find-Git
95+
96+
97+
Update-Lib $git "libgit2" $libgit2Directory ([ref]$libgit2sha)
98+
Update-Lib $git "libssh2" $libssh2Directory ([ref]$libssh2sha)
99+
Update-Lib $git "zlib" $zlibDirectory ([ref]$zlibsha)
100+
101+
# Write-Output "Fetching..."
102+
# Invoke-Command -Quiet { & $git fetch }
103+
104+
# Write-Output "Verifying $sha..."
105+
# $sha = & $git rev-parse $sha
106+
# if ($LASTEXITCODE -ne 0) {
107+
# write-host -foregroundcolor red "Error: invalid SHA. USAGE: $self <SHA>"
108+
# Pop-Location
109+
# break
110+
# }
111+
112+
# Write-Output "Checking out $sha..."
113+
# Invoke-Command -Quiet -Fatal { & $git checkout $sha }
114+
115+
# Pop-Location
116+
117+
# $binaryFilename = "git2-" + $sha.Substring(0,7)
118+
$libgit2binaryFilename = "git2-ssh-net-" + $libgit2sha.Substring(0,7)
119+
$libssh2binaryFilename = "libssh2-" + $libssh2sha.Substring(0,7)
120+
$zlibbinaryFilename = "zlib-" + $zlibsha.Substring(0,7)
121+
122+
Set-Content -Encoding ASCII (Join-Path $projectDirectory "nuget.package\libgit2\libgit2_hash.txt") $libgit2sha
123+
Set-Content -Encoding ASCII (Join-Path $projectDirectory "nuget.package\libgit2\libssh2_hash.txt") $libssh2sha
124+
Set-Content -Encoding ASCII (Join-Path $projectDirectory "nuget.package\libgit2\zlib_hash.txt") $zlibsha
125+
126+
Copy-Item -Path (Join-Path $libgit2Directory "COPYING") -Destination (Join-Path $projectDirectory "nuget.package\libgit2\libgit2.license.txt")
127+
128+
$buildProperties = @"
129+
<Project>
130+
<PropertyGroup>
131+
<libgit2_propsfile>`$(MSBuildThisFileFullPath)</libgit2_propsfile>
132+
<libgit2_hash>$libgit2sha</libgit2_hash>
133+
<libgit2_filename>$libgit2binaryFilename</libgit2_filename>
134+
</PropertyGroup>
135+
</Project>
136+
"@
137+
138+
Set-Content -Encoding UTF8 (Join-Path $projectDirectory "nuget.package\build\LibGit2Sharp-ssh-net.NativeBinaries.props") $buildProperties
139+
140+
$net46BuildProperties = @"
141+
<Project>
142+
<PropertyGroup>
143+
<libgit2_propsfile>`$(MSBuildThisFileFullPath)</libgit2_propsfile>
144+
<libgit2_hash>$libgit2sha</libgit2_hash>
145+
<libgit2_filename>$libgit2binaryFilename</libgit2_filename>
146+
</PropertyGroup>
147+
<ItemGroup>
148+
<ContentWithTargetPath Include="`$(MSBuildThisFileDirectory)\..\..\runtimes\win-x86\native\*" TargetPath="lib\win32\x86\%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
149+
<ContentWithTargetPath Include="`$(MSBuildThisFileDirectory)\..\..\runtimes\win-x64\native\*" TargetPath="lib\win32\x64\%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
150+
<ContentWithTargetPath Include="`$(MSBuildThisFileDirectory)\..\..\runtimes\win-arm64\native\*" TargetPath="lib\win32\arm64\%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
151+
<ContentWithTargetPath Include="`$(MSBuildThisFileDirectory)\..\..\runtimes\**\*`" Exclude="`$(MSBuildThisFileDirectory)\..\..\runtimes\win-*\**\*" TargetPath="lib\%(RecursiveDir)..\%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
152+
<ContentWithTargetPath Include="`$(MSBuildThisFileDirectory)\..\..\libgit2\LibGit2Sharp.dll.config" TargetPath="LibGit2Sharp.dll.config" CopyToOutputDirectory="PreserveNewest" />
153+
</ItemGroup>
154+
</Project>
155+
"@
156+
157+
Set-Content -Encoding UTF8 (Join-Path $projectDirectory "nuget.package\build\net46\LibGit2Sharp-ssh-net.NativeBinaries.props") $net46BuildProperties
158+
159+
$netBuildProperties = @"
160+
<Project>
161+
<PropertyGroup>
162+
<libgit2_propsfile>`$(MSBuildThisFileFullPath)</libgit2_propsfile>
163+
<libgit2_hash>$libgit2sha</libgit2_hash>
164+
<libgit2_filename>$libgit2binaryFilename</libgit2_filename>
165+
</PropertyGroup>
166+
<ItemGroup>
167+
<ContentWithTargetPath Include="`$(MSBuildThisFileDirectory)\..\..\runtimes\win-x86\native\*.dll" TargetPath="lib\win32\x86\%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
168+
<ContentWithTargetPath Include="`$(MSBuildThisFileDirectory)\..\..\runtimes\win-x64\native\*.dll" TargetPath="lib\win32\x64\%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
169+
<ContentWithTargetPath Include="`$(MSBuildThisFileDirectory)\..\..\runtimes\win-arm64\native\*" TargetPath="lib\win32\arm64\%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
170+
<ContentWithTargetPath Include="`$(MSBuildThisFileDirectory)\..\..\runtimes\**\*`" Exclude="`$(MSBuildThisFileDirectory)\..\..\runtimes\win-*\**\*" TargetPath="lib\%(RecursiveDir)..\%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
171+
</ItemGroup>
172+
</Project>
173+
"@
174+
Set-Content -Encoding UTF8 (Join-Path $projectDirectory "nuget.package\build\net6.0\LibGit2Sharp-ssh-net.NativeBinaries.props") $netBuildProperties
175+
Set-Content -Encoding UTF8 (Join-Path $projectDirectory "nuget.package\build\net7.0\LibGit2Sharp-ssh-net.NativeBinaries.props") $netBuildProperties
176+
Set-Content -Encoding UTF8 (Join-Path $projectDirectory "nuget.package\build\net8.0\LibGit2Sharp-ssh-net.NativeBinaries.props") $netBuildProperties
177+
178+
$dllConfig = @"
179+
<configuration>
180+
<dllmap os="linux" cpu="x86-64" wordsize="64" dll="$libgit2binaryFilename" target="lib/linux-x64/lib$libgit2binaryFilename.so" />
181+
<dllmap os="linux" cpu="arm" wordsize="32" dll="$libgit2binaryFilename" target="lib/linux-arm/lib$libgit2binaryFilename.so" />
182+
<dllmap os="linux" cpu="armv8" wordsize="64" dll="$libgit2binaryFilename" target="lib/linux-arm64/lib$libgit2binaryFilename.so" />
183+
<dllmap os="linux-musl" cpu="x86-64" wordsize="64" dll="$libgit2binaryFilename" target="lib/linux-musl-x64/lib$libgit2binaryFilename.so" />
184+
<dllmap os="linux-musl" cpu="armv8" wordsize="64" dll="$libgit2binaryFilename" target="lib/linux-musl-arm64/lib$libgit2binaryFilename.so" />
185+
<dllmap os="osx" cpu="x86-64" wordsize="64" dll="$libgit2binaryFilename" target="lib/osx-x64/lib$libgit2binaryFilename.dylib" />
186+
<dllmap os="osx" cpu="armv8" wordsize="64" dll="$libgit2binaryFilename" target="lib/osx-arm64/lib$libgit2binaryFilename.dylib" />
187+
</configuration>
188+
"@
189+
190+
Set-Content -Encoding UTF8 (Join-Path $projectDirectory "nuget.package\libgit2\LibGit2Sharp.dll.config") $dllConfig
191+
192+
Write-Output "Done!"
193+
}
194+
exit

0 commit comments

Comments
 (0)