-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.ps1
231 lines (197 loc) · 7.76 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
# Requires -RunAsAdministrator
# This script needs to be run with administrator rights.
param (
[Parameter(Mandatory = $true)]
[string]$BazelBuildParameters,
[switch]$BuildCppAPI = $false,
[switch]$ReserveSource = $false,
<# [switch]$ReserveVenv = $false, #>
[switch]$IgnoreDepsVersionIssues = $false,
[switch]$InstallDefaultDeps = $false
)
# Set parameters for execution.
Set-StrictMode -Version latest
$ErrorActionPreference = "Stop"
# Cleaning work
<# if (Test-Path tensorflow) {
Remove-Item tensorflow -Force -Recurse
} #>
<# if (!$ReserveVenv -and (Test-Path venv)) {
Remove-Item venv -Force -Recurse
} #>
<# if (!$ReserveSource -and (Test-Path source)) {
Remove-Item source -Force -Recurse
} #>
<# # Ask the specific version of Tensorflow.
$supportedVersions = @("v1.13.1", "v1.12.0", "v1.11.0")
$options = [Array]::CreateInstance([System.Management.Automation.Host.ChoiceDescription], $supportedVersions.Count)
for ($i = 0; $i -lt $supportedVersions.Count; $i++) {
$options[$i] = [System.Management.Automation.Host.ChoiceDescription]::new("&$($i + 1) - $($supportedVersions[$i])",
"Build Tensorflow $($supportedVersions[$i]).")
}
$options += [System.Management.Automation.Host.ChoiceDescription]::new("&Select another version",
"Input the custom version tag you want to build.")
$title = "Select a Tensorflow version:"
$chosenIndex = $Host.UI.PromptForChoice($title, "", $options, 0)
if ($supportedVersions.Count -eq $chosenIndex + 1) {
$buildVersion = Read-Host "Please input the version tag (e.g. v1.11.0)"
} else {
$buildVersion = $supportedVersions[$chosenIndex]
} #>
# Functions used in installation of dependencies
function CheckInstalled {
param (
[string]$ExeName,
[Parameter(Mandatory = $false)]
[string]$RequiredVersion
)
$installed = Get-Command $ExeName -ErrorAction SilentlyContinue
if ($null -eq $installed) {
Write-Host "Unable to find $ExeName." -ForegroundColor Red
return $false
} else {
Write-Host "Found $ExeName installed." -ForegroundColor Green
if ([string]::Empty -ne $RequiredVersion -and $true -ne $IgnoreDepsVersionIssues) {
Write-Host $("Make sure you have installed same version of $ExeName $RequiredVersion.") -ForegroundColor Yellow
$confirmation = Read-Host "Are you sure you want to PROCEED? [y/n]"
while ($confirmation -ne "y") {
if ($confirmation -eq "n") {exit}
$confirmation = Read-Host "Are you sure you want to PROCEED? [y/n]"
}
}
return $true
}
}
function askForVersion {
param (
[Parameter(Mandatory = $true)]
[string]$DefaultVersion
)
if ($InstallDefaultDeps) {
return $DefaultVersion
}
$version = Read-Host "Which version would you like to install? [Default version: $DefaultVersion]"
if ($version -eq "") {
return $DefaultVersion
}
return $version
}
# Assign correct versions of dependencies.
<# if ($buildVersion -eq "v1.11.0" -or $buildVersion -eq "v1.12.0") {
$bazelVersion = "0.15.0"
} elseif ($buildVersion -eq "v1.13.1") {
$bazelVersion = "0.20.0"
} #>
# Installation of dependencies
if (!(CheckInstalled chocolatey)) {
Write-Host "Installing Chocolatey package manager."
Set-ExecutionPolicy Bypass -Scope Process -Force
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString("https://chocolatey.org/install.ps1"))
}
choco feature enable -n allowGlobalConfirmation | Out-Null # Enable global confirmation for chocolatey package installation.
if (!(CheckInstalled pacman)) {
$version = askForVersion "20180531.0.0"
choco install msys2 --version $version --params "/NoUpdate /InstallDir:C:\msys64"
}
$ENV:Path += ";C:\msys64\usr\bin"
$ENV:BAZEL_SH = "C:\msys64\usr\bin\bash.exe"
if (!(CheckInstalled patch)) {
pacman -S --noconfirm patch
}
if (!(CheckInstalled unzip)) {
pacman -S --noconfirm unzip
}
$bazelVersion = "0.21.0"
if (!(CheckInstalled bazel $bazelVersion)) {
$version = askForVersion $bazelVersion
# Bazel will also install msys2, but with an incorrect version, so we will ignore the dependencies.
choco install bazel --version $version --ignore-dependencies
}
if (!(CheckInstalled git)) {
choco install git
}
if (!(CheckInstalled python "3.6.7")) {
$version = askForVersion "3.6.7"
choco install python --version $version --params "'TARGETDIR:C:/Python36'"
}
# Get the source code of Tensorflow and checkout to the specific version.
<# if (!$ReserveSource) {
git clone https://github.com/tensorflow/tensorflow.git
Rename-Item tensorflow source
Set-Location source
} else {
Set-Location source
git fetch
git reset --hard origin/master
git checkout -f master
git pull
} #>
Set-Location source
<# git checkout -f tags/"v1.13.1"
git clean -fx #>
# Apply patches to source.
<# if ($buildVersion -eq "v1.11.0") {
# Eigen Patch for v1.11.0
git apply --ignore-space-change --ignore-white "..\patches\eigen.1.11.0.patch"
Copy-Item ..\patches\eigen_half.patch third_party\
} elseif ($buildVersion -eq "v1.12.0") {
# Eigen Patch for v1.12.0
git apply --ignore-space-change --ignore-white "..\patches\eigen.1.12.0.patch"
Copy-Item ..\patches\eigen_half.patch third_party\
} elseif ($buildVersion -eq "v1.13.1") {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
(Invoke-WebRequest https://github.com/tensorflow/tensorflow/commit/ec727016282383aacf9d26386b01f6bdbd65b14b.patch).Content | git apply -v --ignore-space-change --ignore-white
} #>
<# [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
(Invoke-WebRequest https://github.com/tensorflow/tensorflow/commit/ec727016282383aacf9d26386b01f6bdbd65b14b.patch).Content | git apply -v --ignore-space-change --ignore-white #>
git apply --ignore-space-change --ignore-white "..\patches\eigen.1.13.0.patch"
if ($BuildCppAPI) {
<# if ($buildVersion -eq "v1.11.0") {
# C++ Symbol Patch for v1.11.0
git apply --ignore-space-change --ignore-white "..\patches\cpp_symbol.1.11.0.patch"
Copy-Item ..\patches\tf_exported_symbols_msvc.lds tensorflow\
} elseif ($buildVersion -eq "v1.12.0") {
# C++ Symbol Patch for v1.12.0
git apply --ignore-space-change --ignore-white "..\patches\cpp_symbol.1.12.0.patch"
Copy-Item ..\patches\tf_exported_symbols_msvc.lds tensorflow\
} elseif ($buildVersion -eq "v1.13.1") {
# C++ Symbol Patch for v1.13.1
git apply --ignore-space-change --ignore-white "..\patches\cpp_symbol.1.13.1.patch"
Copy-Item ..\patches\tf_exported_symbols_msvc.lds tensorflow\
} #>
git apply --ignore-space-change --ignore-white "..\patches\cpp_symbol.1.13.1.patch"
Copy-Item ..\patches\tf_exported_symbols_msvc.lds tensorflow\
}
Set-Location ..
# Setup folder structure.
$rootDir = $pwd
$sourceDir = "$rootDir\source"
$venvDir = "C:\ProgramData\Anaconda3\envs\tf_test"
# Create python environment.
<# if (!$ReserveVenv) {
mkdir $venvDir | Out-Null
py -3 -m venv venv
.\venv\Scripts\Activate.ps1
pip3 install six numpy wheel
pip3 install keras_applications==1.0.5 --no-deps
pip3 install keras_preprocessing==1.0.3 --no-deps
} else {
.\venv\Scripts\Activate.ps1
} #>
pip install six numpy wheel
pip install keras_applications==1.0.5 --no-deps
pip install keras_preprocessing==1.0.3 --no-deps
Set-Location $sourceDir
if (!$ReserveSource) {
# Clean Bazel files.
bazel clean --expunge
}
# Configure
$ENV:PYTHON_BIN_PATH = "$VenvDir/python.exe" -replace "[\\]", "/"
$ENV:PYTHON_LIB_PATH = "$VenvDir/lib/site-packages" -replace "[\\]", "/"
python configure.py
# Build
Invoke-Expression ("bazel build " + $BazelBuildParameters)
# Shutdown Bazel
bazel shutdown
Set-Location $rootDir