-
-
Notifications
You must be signed in to change notification settings - Fork 87
/
windows-scripts.ps1
166 lines (134 loc) · 5.9 KB
/
windows-scripts.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
function Get-VisualStudioCMakePath() {
$vsWherePath = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
if (-not (Test-Path $vsWherePath)) {
return $null
}
$vsWhereOutput = & $vsWherePath -latest -requires Microsoft.Component.MSBuild -property installationPath
if (-not ([string]::IsNullOrEmpty($vsWhereOutput))) {
$cmakePath = Join-Path $vsWhereOutput 'Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin'
if (Test-Path $cmakePath) {
return $cmakePath
}
}
return $null
}
function Get-MSBuildPlatform($Arch) {
$platforms = @{
"x64" = "x64"
"x86" = "Win32"
"arm64" = "ARM64"
"arm" = "ARM"
}
if ($platforms.ContainsKey($Arch)) {
return $platforms[$Arch]
}
return $null
}
function BuildWindows() {
param(
[Parameter(Mandatory = $true)] [string]$Arch,
[Parameter(Mandatory = $false)] [bool]$Cuda = $false,
[Parameter(Mandatory = $false)] [bool]$Vulkan = $false,
[Parameter(Mandatory = $false)] [bool]$OpenVino = $false,
[Parameter(Mandatory = $false)] [bool]$NoAvx = $false,
[Parameter(Mandatory = $false)] [string]$Configuration = "Release"
)
#if not exist "build" create the directory
if (!(Test-Path "build")) {
New-Item -ItemType Directory -Force -Path "build"
}
Write-Host "Building Windows binaries for $Arch with cuda: $Cuda"
$platform = Get-MSBuildPlatform $Arch
if ([string]::IsNullOrEmpty($platform)) {
Write-Host "Unknown architecture $Arch"
return
}
$buildDirectory = "build/win-$Arch"
$options = @("-S", ".", "-DGGML_NATIVE=OFF");
$avxOptions = @("-DGGML_AVX=ON", "-DGGML_AVX2=ON", "-DGGML_FMA=ON", "-DGGML_F16C=ON");
$runtimePath = "./runtimes/Whisper.net.Runtime"
if ($Cuda) {
$options += "-DGGML_CUDA=1"
$buildDirectory += "-cuda"
$runtimePath += ".Cuda.Windows"
}
if ($Vulkan) {
$options += "-DGGML_VULKAN=1"
$buildDirectory += "-vulkan"
$runtimePath += ".Vulkan"
}
if ($OpenVino) {
$options += "-DWHISPER_OPENVINO=1"
$buildDirectory += "-openvino"
$runtimePath += ".OpenVino"
}
if ($NoAvx) {
$avxOptions = @("-DGGML_AVX=OFF", "-DGGML_AVX2=OFF", "-DGGML_FMA=OFF", "-DGGML_F16C=OFF");
$buildDirectory += "-noavx"
$runtimePath += ".NoAvx"
}
$options += "-B"
$options += $buildDirectory
$options += "-A"
$options += $platform
$options += $avxOptions
if ((Test-Path $buildDirectory)) {
Write-Host "Deleting old build files for $buildDirectory";
Remove-Item -Force -Recurse -Path $buildDirectory
}
$cmakePath = (Get-Command cmake -ErrorAction SilentlyContinue).Source
if ([string]::IsNullOrEmpty($cmakePath)) {
# CMake is not defined in the system's path, search for it in Visual Studio
$visualStudioPath = Get-VisualStudioCMakePath
if ([string]::IsNullOrEmpty($visualStudioPath)) {
Write-Host "CMake is not found in the system or Visual Studio."
return
}
$env:Path += ";$visualStudioPath"
}
New-Item -ItemType Directory -Force -Path $buildDirectory
# call CMake to generate the makefiles
Write-Host "Running 'cmake $options'"
cmake $options
cmake --build $buildDirectory --config $Configuration
if (-not(Test-Path $runtimePath)) {
New-Item -ItemType Directory -Force -Path $runtimePath
}
$runtimePath += "/win-$Arch"
if (-not(Test-Path $runtimePath)) {
New-Item -ItemType Directory -Force -Path $runtimePath
}
Move-Item "$buildDirectory/bin/Release/whisper.dll" "$runtimePath/whisper.dll" -Force
Move-Item "$buildDirectory/bin/Release/ggml-whisper.dll" "$runtimePath/ggml-whisper.dll" -Force
}
function BuildWindowsArm([Parameter(Mandatory = $false)] [string]$Configuration = "Release") {
BuildWindows -Arch "arm64" -Configuration $Configuration;
# BuildWindows -Arch "arm" -Configuration $Configuration;
# Arm build not working anymore with VS
}
function BuildWindowsIntel([Parameter(Mandatory = $false)] [string]$Configuration = "Release") {
BuildWindows -Arch "x64" -Configuration $Configuration;
BuildWindows -Arch "x86" -Configuration $Configuration;
}
function BuildWindowsAll([Parameter(Mandatory = $false)] [string]$Configuration = "Release") {
BuildWindows -Arch "arm64" -Configuration $Configuration;
BuildWindows -Arch "arm" -Configuration $Configuration;
BuildWindows -Arch "x64" -Cuda $true -Configuration $Configuration;
BuildWindows -Arch "x64" -Configuration $Configuration;
BuildWindows -Arch "x86" -Configuration $Configuration;
}
function PackAll([Parameter(Mandatory = $true)] [string]$Version) {
if (-not(Test-Path "nupkgs")) {
New-Item -ItemType Directory -Force -Path "nupkgs"
}
nuget pack runtimes/Whisper.net.Runtime.nuspec -Version $Version -OutputDirectory ./nupkgs
dotnet pack Whisper.net/Whisper.net.csproj -p:Version=$Version -o ./nupkgs -c Release
nuget pack runtimes/Whisper.net.Runtime.CoreML.nuspec -Version $Version -OutputDirectory ./nupkgs
nuget pack runtimes/Whisper.net.Runtime.Cuda.Linux.nuspec -Version $Version -OutputDirectory ./nupkgs
nuget pack runtimes/Whisper.net.Runtime.Cuda.Windows.nuspec -Version $Version -OutputDirectory ./nupkgs
nuget pack runtimes/Whisper.net.Runtime.Cuda.nuspec -Version $Version -OutputDirectory ./nupkgs
nuget pack runtimes/Whisper.net.Runtime.Vulkan.nuspec -Version $Version -OutputDirectory ./nupkgs
nuget pack runtimes/Whisper.net.Runtime.OpenVino.nuspec -Version $Version -OutputDirectory ./nupkgs
nuget pack runtimes/Whisper.net.Runtime.NoAvx.nuspec -Version $Version -OutputDirectory ./nupkgs
nuget pack runtimes/Whisper.net.AllRuntimes.nuspec -Version $Version -OutputDirectory ./nupkgs
}