forked from zerotier/libzt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
241 lines (212 loc) · 9.29 KB
/
build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
function Build-Host([string]$BuildType, [string]$Arch)
{
$Artifact="host"
$Variant="-DBUILD_HOST=1"
# Directory for CMake to build and store intermediate files
$env:BuildDir="cache\win-$Arch-$Artifact-"+$BuildType.ToLower()
md $env:BuildDir -ErrorAction:'silentlycontinue'
# Directory where we plan to store the resultant libraries
$env:OutputDir="dist\win-$Arch-$Artifact-"+$BuildType.ToLower()
md $env:OutputDir -ErrorAction:'silentlycontinue'
pushd -Path $env:BuildDir
cmake $Variant -G "Visual Studio 16 2019" -A $Arch ../../
cmake --build . --config $BuildType
ctest -C debug
popd
#
md $env:OutputDir\lib\ -ErrorAction:'silentlycontinue'
md $env:OutputDir\bin\ -ErrorAction:'silentlycontinue'
cp $env:BuildDir\lib\$BuildType\zt.lib $env:OutputDir\lib\libzt.lib
cp $env:BuildDir\bin\$BuildType\*.exe $env:OutputDir\bin
cp $env:BuildDir\lib\$BuildType\zt-shared.dll $env:OutputDir\lib\libzt.dll
cp $env:BuildDir\lib\$BuildType\zt-shared.pdb $env:OutputDir\lib\libzt.pdb -ErrorAction:'silentlycontinue'
tree /F $env:OutputDir
}
function Build-Library([string]$BuildType, [string]$Arch, [string]$LangBinding)
{
$OptLangBinding=""
if ($LangBinding -eq "csharp") {
$OptLangBinding="-DZTS_ENABLE_PINVOKE=1"
$LangBindingPostfix="pinvoke"
}
if ($LangBinding -eq "java") {
$OptLangBinding="-DZTS_ENABLE_JAVA=1"
$LangBindingPostfix="jni"
}
$archAlias = ""
$bitCount = ""
if ($Arch -eq "Win32") {
$bitCount="32"
$archAlias="win-x86"
}
if ($Arch -eq "x64") {
$bitCount="64"
$archAlias="win-x64"
}
#if ($Arch -eq "ARM32") {
# $bitCount="32"
# $archAlias="win-arm"
#}
if ($Arch -eq "ARM") {
$bitCount="64"
$archAlias="win-arm64"
}
if ($archAlias -eq "" -or $bitCount -eq "") {
echo "No valid architecture specified. Breaking."
break
}
# Directory for CMake to build and store intermediate files
$env:BuildDir="cache\win-$Arch-$LangBindingPostfix-"+$BuildType.ToLower()
md $env:BuildDir -ErrorAction:'silentlycontinue'
# Directory where we plan to store the resultant libraries
$env:OutputDir="dist\win-$Arch-$LangBindingPostfix-"+$BuildType.ToLower()
md $env:OutputDir -ErrorAction:'silentlycontinue'
pushd -Path $env:BuildDir
cmake ${OptLangBinding} -G "Visual Studio 16 2019" -A $Arch ../../
cmake --build . --config $BuildType
popd
md $env:OutputDir\lib\ -ErrorAction:'silentlycontinue'
#cp $env:BuildDir\lib\$BuildType\zt.lib $env:OutputDir\lib\libzt.lib
cp $env:BuildDir\lib\$BuildType\zt-shared.dll $env:OutputDir\lib\libzt.dll
cp $env:BuildDir\lib\$BuildType\zt-shared.pdb $env:OutputDir\lib\libzt.pdb -ErrorAction:'silentlycontinue'
}
function Build-All
{
# Win32
Build-Library -BuildType "Release" -Arch "Win32" -LangBinding ""
Build-Library -BuildType "Release" -Arch "Win32" -LangBinding "csharp"
Build-Library -BuildType "Debug" -Arch "Win32" -LangBinding ""
Build-Library -BuildType "Debug" -Arch "Win32" -LangBinding "csharp"
# x64
Build-Library -BuildType "Release" -Arch "x64" -LangBinding ""
Build-Library -BuildType "Release" -Arch "x64" -LangBinding "csharp"
Build-Library -BuildType "Debug" -Arch "x64" -LangBinding ""
Build-Library -BuildType "Debug" -Arch "x64" -LangBinding "csharp"
}
function BuildNuGetPackages([string]$Version)
{
BuildNuGetPackage -BuildType "Release" -Arch "x64" -Version $Version
BuildNuGetPackage -BuildType "Debug" -Arch "x64" -Version $Version
BuildNuGetPackage -BuildType "Release" -Arch "Win32" -Version $Version
BuildNuGetPackage -BuildType "Debug" -Arch "Win32" -Version $Version
}
function BuildNuGetPackage([string]$BuildType, [string]$Arch, [string]$Version)
{
$archAlias = $Arch
if ($Arch -eq "Win32") {
$archAlias="x86"
}
$TargetTuple = "win-"+$archAlias+"-nuget-"+$($BuildType.ToLower())
# Where we plan to output *.nupkg(s)
md pkg\nuget\ZeroTier.Sockets\bin\ -Force
md dist\$TargetTuple -Force
del dist\$TargetTuple\*.nupkg -ErrorAction:'silentlycontinue'
# licenses
md pkg\nuget\ZeroTier.Sockets\licenses -Force
cp LICENSE.txt pkg\nuget\ZeroTier.Sockets\licenses
# contentFiles (sources)
md pkg\nuget\ZeroTier.Sockets\contentFiles -Force
cp src\bindings\csharp\*.cs pkg\nuget\ZeroTier.Sockets\contentFiles
cp examples\csharp\*.cs pkg\nuget\ZeroTier.Sockets\contentFiles
# runtimes
md pkg\nuget\ZeroTier.Sockets\runtimes\win10-$archAlias\native -Force
md pkg\nuget\ZeroTier.Sockets\runtimes\win10-$archAlias\lib\uap10.0 -Force
#md pkg\nuget\ZeroTier.Sockets\runtimes\win10-arm\native -Force
# Build wrapper library for C# ZeroTier.Sockets abstraction
#csc -target:library -debug:pdbonly `
# -pdb:pkg\nuget\ZeroTier.Sockets\bin\ZeroTier.Sockets.pdb `
# -out:pkg\nuget\ZeroTier.Sockets\bin\ZeroTier.Sockets.dll `
# .\src\bindings\csharp\*.cs
# Copy sources into bindings library project
cp .\src\bindings\csharp\*.cs .\pkg\nuget\bindings\ZeroTier.Sockets\
# Build bindings library
pushd ./pkg/nuget/bindings/
dotnet build --configuration Release
popd
# Build unmanaged native libzt.dll with exported P/INVOKE symbols
Build-Library -BuildType $BuildType -Arch $Arch -LangBinding "csharp"
# Copy native libzt.dll into package tree
cp .\dist\win-$archAlias-pinvoke-$($BuildType.ToLower())\lib\*.dll `
pkg\nuget\ZeroTier.Sockets\bin\libzt.dll
# .NET Framework
md pkg\nuget\ZeroTier.Sockets\lib\net40 -Force
md pkg\nuget\ZeroTier.Sockets\lib\net45 -Force
md pkg\nuget\ZeroTier.Sockets\lib\net451 -Force
md pkg\nuget\ZeroTier.Sockets\lib\net452 -Force
md pkg\nuget\ZeroTier.Sockets\lib\net46 -Force
md pkg\nuget\ZeroTier.Sockets\lib\net461 -Force
md pkg\nuget\ZeroTier.Sockets\lib\net462 -Force
md pkg\nuget\ZeroTier.Sockets\lib\net47 -Force
md pkg\nuget\ZeroTier.Sockets\lib\net471 -Force
md pkg\nuget\ZeroTier.Sockets\lib\net472 -Force
md pkg\nuget\ZeroTier.Sockets\lib\net48 -Force
md pkg\nuget\ZeroTier.Sockets\lib\netstandard1.3 -Force
md pkg\nuget\ZeroTier.Sockets\lib\netstandard1.4 -Force
md pkg\nuget\ZeroTier.Sockets\lib\netstandard1.5 -Force
md pkg\nuget\ZeroTier.Sockets\lib\netstandard1.6 -Force
md pkg\nuget\ZeroTier.Sockets\lib\netstandard2.0 -Force
md pkg\nuget\ZeroTier.Sockets\lib\netstandard2.1 -Force
md pkg\nuget\ZeroTier.Sockets\lib\netcoreapp1.0 -Force
md pkg\nuget\ZeroTier.Sockets\lib\netcoreapp1.1 -Force
md pkg\nuget\ZeroTier.Sockets\lib\netcoreapp2.0 -Force
md pkg\nuget\ZeroTier.Sockets\lib\netcoreapp2.1 -Force
md pkg\nuget\ZeroTier.Sockets\lib\netcoreapp2.2 -Force
md pkg\nuget\ZeroTier.Sockets\lib\netcoreapp3.0 -Force
md pkg\nuget\ZeroTier.Sockets\lib\netcoreapp3.1 -Force
# .NET "Core" 5.0 (moniker missing from microsoft documentation?)
md pkg\nuget\ZeroTier.Sockets\lib\net5.0 -Force
# Copy assemblies into framework-specific directories.
$folders = Get-ChildItem pkg\nuget\ZeroTier.Sockets\lib\
foreach ($folder in $folders.name){
cp -Path "pkg\nuget\ZeroTier.Sockets\bin\*.*" `
-Destination "pkg\nuget\ZeroTier.Sockets\lib\$folder" -Recurse
}
# Copy bindings library "ZeroTier.Sockets.dll"
$folders = Get-ChildItem .\pkg\nuget\bindings\ZeroTier.Sockets\bin\Release
foreach ($folder in $folders.name){
cp -Path ".\pkg\nuget\bindings\ZeroTier.Sockets\bin\Release\$folder\*.dll" `
-Destination "pkg\nuget\ZeroTier.Sockets\lib\$folder" -Recurse
}
# Native DLL placement
cp .\dist\win-$archAlias-pinvoke-$($BuildType.ToLower())\lib\*.dll `
pkg\nuget\ZeroTier.Sockets\runtimes\win10-$archAlias\lib\uap10.0\libzt.dll
cp .\dist\win-$archAlias-pinvoke-$($BuildType.ToLower())\lib\*.dll `
pkg\nuget\ZeroTier.Sockets\lib\net40\libzt.dll
cp .\dist\win-$archAlias-pinvoke-$($BuildType.ToLower())\lib\*.dll `
pkg\nuget\ZeroTier.Sockets\runtimes\win10-$archAlias\native\libzt.dll
cp .\dist\win-$archAlias-pinvoke-$($BuildType.ToLower())\lib\*.pdb `
pkg\nuget\ZeroTier.Sockets\runtimes\win10-$archAlias\lib\uap10.0\libzt.pdb
# Package
pushd -Path pkg\nuget\ZeroTier.Sockets
nuget pack ZeroTier.Sockets.$archAlias.nuspec `
-Version $Version -OutputDirectory ..\..\..\dist\$TargetTuple\
popd
}
function Clean-PackageDirectory
{
rm pkg\nuget\ZeroTier.Sockets\lib `
-Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue'
rm pkg\nuget\ZeroTier.Sockets\contentFiles `
-Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue'
rm pkg\nuget\ZeroTier.Sockets\licenses `
-Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue'
rm pkg\nuget\ZeroTier.Sockets\runtimes `
-Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue'
rm pkg\nuget\ZeroTier.Sockets\bin `
-Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue'
}
function Clean
{
rm cache -Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue'
rm dist -Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue'
#rm pkg\nuget\bindings\ZeroTier.Sockets\*.cs -Force -Confirm:$false -ErrorAction:'silentlycontinue'
#rm pkg\nuget\bindings\ZeroTier.Sockets\bin -Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue'
#rm pkg\nuget\bindings\ZeroTier.Sockets\obj -Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue'
#rm pkg\nuget\ZeroTier.Sockets\contentFiles -Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue'
rm pkg\nuget\ZeroTier.Sockets\lib -Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue'
rm pkg\nuget\ZeroTier.Sockets\bin -Recurse -Force -Confirm:$false -ErrorAction:'silentlycontinue'
rm 'pkg\nuget\*' -Recurse -Include *.pdb
rm 'pkg\nuget\*' -Recurse -Include *.cs
rm 'pkg\nuget\*' -Recurse -Include *.dll
rm 'pkg\nuget\*' -Recurse -Include LICENSE.*
}