-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuild-windows-static.ps1
More file actions
177 lines (154 loc) · 5.6 KB
/
build-windows-static.ps1
File metadata and controls
177 lines (154 loc) · 5.6 KB
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
param(
[ValidateSet('Release', 'RelWithDebInfo', 'Debug')]
[string]$BuildType = 'Release',
# Optional: set a proxy for git/pip/cargo, e.g. "http://127.0.0.1:6789"
[string]$Proxy = ''
)
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
function Resolve-VsDevCmd {
$vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
if (Test-Path $vswhere) {
$installationPath = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
$installationPath = ($installationPath | Select-Object -First 1).Trim()
if ($installationPath) {
$vsDevCmd = Join-Path $installationPath 'Common7\Tools\VsDevCmd.bat'
if (Test-Path $vsDevCmd) {
return $vsDevCmd
}
}
}
$fallback = @(
'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat',
'C:\Program Files\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\VsDevCmd.bat',
'C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\Tools\VsDevCmd.bat'
) | Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $fallback) {
throw 'VsDevCmd.bat not found. Install Visual Studio (C++ tools) or VS Build Tools.'
}
return $fallback
}
function Resolve-ToolPath {
param(
[Parameter(Mandatory = $true)]
[string]$Tool,
[Parameter(Mandatory = $true)]
[string[]]$Fallbacks
)
$cmd = Get-Command $Tool -ErrorAction SilentlyContinue
if ($cmd -and $cmd.Source) {
return $cmd.Source
}
foreach ($p in $Fallbacks) {
if (Test-Path $p) {
return $p
}
}
throw "Tool not found: $Tool"
}
function Ensure-Junction {
param(
[Parameter(Mandatory = $true)]
[string]$LinkPath,
[Parameter(Mandatory = $true)]
[string]$TargetPath
)
$linkFull = (Resolve-Path -Path (Split-Path -Parent $LinkPath)).Path | Join-Path -ChildPath (Split-Path -Leaf $LinkPath)
$targetFull = (Resolve-Path $TargetPath).Path
if (Test-Path $LinkPath) {
$item = Get-Item -Force $LinkPath
if ($item.PSIsContainer -and $item.LinkType) {
return
}
if (-not $item.PSIsContainer) {
# Git on Windows may checkout symlinks as small files containing the link target.
try {
Remove-Item -LiteralPath $LinkPath -Force
} catch {
$cmdPath = ($LinkPath -replace '/', '\\')
cmd /c "del /f /q `"$cmdPath`""
}
} else {
throw "Path exists and is not a link placeholder: $LinkPath"
}
}
New-Item -ItemType Junction -Path $LinkPath -Target $targetFull | Out-Null
}
if ($Proxy) {
$env:HTTP_PROXY = $Proxy
$env:HTTPS_PROXY = $Proxy
$env:http_proxy = $Proxy
$env:https_proxy = $Proxy
}
$vsDevCmd = Resolve-VsDevCmd
$cmake = Resolve-ToolPath -Tool 'cmake' -Fallbacks @(
'C:\Program Files\CMake\bin\cmake.exe',
'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe'
)
$ninja = Resolve-ToolPath -Tool 'ninja' -Fallbacks @(
'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.exe'
)
Write-Host "VS DevCmd: $vsDevCmd"
Write-Host "CMake: $cmake"
Write-Host "Ninja: $ninja"
Write-Host '==> Fixing 3rdparty junctions'
Ensure-Junction -LinkPath '3rdparty/tilelang/3rdparty/tvm' -TargetPath '3rdparty/tvm'
Ensure-Junction -LinkPath '3rdparty/tvm/3rdparty/tvm-ffi' -TargetPath '3rdparty/tvm-ffi'
Write-Host '==> Updating nested submodules (tvm-ffi)'
git -C 3rdparty/tvm-ffi submodule update --init --recursive
Write-Host '==> Creating Python venv (.venv) and installing build deps'
if (-not (Test-Path '.venv/Scripts/python.exe')) {
python -m venv .venv
}
& .venv/Scripts/python.exe -m pip install --upgrade pip wheel setuptools
& .venv/Scripts/python.exe -m pip install Cython
$py = (Resolve-Path '.venv/Scripts/python.exe').Path
Write-Host '==> Configuring TileLang static build'
$tilelangBuildDir = '3rdparty\\tilelang\\build-static'
$cmakeArgs = @(
"`"$vsDevCmd`" -arch=x64 -host_arch=x64 >nul",
"&&",
"`"$cmake`"",
"-S 3rdparty\\tilelang",
"-B $tilelangBuildDir",
"-G Ninja",
"-DCMAKE_BUILD_TYPE=$BuildType",
"-DPython_EXECUTABLE=`"$py`"",
"-DUSE_CUDA=ON",
"-DUSE_Z3=OFF",
"-DUSE_PYPI_Z3=OFF",
"-DBUILD_STATIC=ON",
"-DBUILD_STATIC_TVM=ON",
"-DBUILD_STATIC_RUNTIME=ON",
"-DTVM_FFI_USE_LIBBACKTRACE=OFF",
"-DHIDE_PRIVATE_SYMBOLS=OFF",
"-DUSE_LLVM=OFF",
"-DUSE_METAL=OFF",
"-DUSE_ROCM=OFF",
"-DUSE_OPENCL=OFF",
"-DUSE_VULKAN=OFF",
"-DUSE_RPC=OFF",
"-DUSE_THREADS=ON"
) -join ' '
cmd /c $cmakeArgs
Write-Host '==> Building TileLang static libraries (tvm_static, tvm_ffi_static, tilelang_module_static)'
$ninjaArgs = @(
"`"$vsDevCmd`" -arch=x64 -host_arch=x64 >nul",
"&&",
"`"$ninja`"",
"-C $tilelangBuildDir",
"-j %NUMBER_OF_PROCESSORS%",
"tvm_static tvm_ffi_static tilelang_module_static"
) -join ' '
cmd /c $ninjaArgs
$tilelangLibDir = (Resolve-Path '3rdparty/tilelang/build-static/lib').Path
Write-Host "==> Building flashtile (static-link) with FLASHTILE_TILELANG_LIB_DIR=$tilelangLibDir"
$cargoArgs = @(
"`"$vsDevCmd`" -arch=x64 -host_arch=x64 >nul",
"&&",
"set `"FLASHTILE_TILELANG_LIB_DIR=$tilelangLibDir`"",
"&&",
"cargo build --release --features static-link"
) -join ' '
cmd /c $cargoArgs
Write-Host '==> Done'