blob: f403e6ae21f9ea4e43b891cd118fca79ece2543f (
plain)
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
|
# PowerShell script to fetch, build, and install LLVM for Slang
# Set script to fail on errors
$ErrorActionPreference = "Stop"
function Show-Help {
Write-Host "Fetch, build and install LLVM for Slang
Options:
--repo: The source git repo, default: $repo
--branch: The branch (or tag) to fetch, default: $branch
--source-dir: Unpack and build in this directory: default $source_dir
--config: The configuration to build, default $config
--install-prefix: Install under this prefix
--: Any following arguments will be passed to the CMake configuration command
"
}
function Msg {
Write-Host "$args" -ForegroundColor Yellow
}
function Fail {
Msg "$args"
exit 1
}
function New-TemporaryDirectory {
$tmp = [System.IO.Path]::GetTempPath() # Not $env:TEMP, see https://stackoverflow.com/a/946017
$name = (New-Guid).ToString("N")
New-Item -ItemType Directory -Path (Join-Path $tmp $name)
}
# Check if required programs are available
$requiredPrograms = "cmake", "git", "ninja"
foreach ($prog in $requiredPrograms) {
if (-not (Get-Command $prog -ErrorAction SilentlyContinue)) {
Msg "This script needs $prog, but it isn't in PATH"
$missingBin = $true
}
}
if ($missingBin) {
exit 1
}
# Temp directory with cleanup on exit
$tempDir = New-TemporaryDirectory
$cleanup = {
if ($tempDir) {
Remove-Item -Recurse -Force $tempDir
}
exit $lastExitCode
}
$null = Register-EngineEvent PowerShell.Exiting -Action $cleanup
# Default values
$repo = "https://github.com/llvm/llvm-project"
$branch = "llvmorg-14.0.6"
$sourceDir = $tempDir.FullName
$installPrefix = ""
$config = "Release"
$extraArguments = @()
# Argument parsing
for ($i = 0; $i -lt $args.Length; $i++) {
switch ($args[$i]) {
"--help" {
Show-Help
exit
}
"--repo" {
$repo = $args[++$i]
}
"--branch" {
$branch = $args[++$i]
}
"--source-dir" {
$sourceDir = $args[++$i]
}
"--config" {
$config = $args[++$i]
}
"--install-prefix" {
$installPrefix = $args[++$i]
}
"--" {
$extraArguments = $args[$i + 1..$args.Length]
break
}
default {
Msg "Unknown parameter passed: $($args[$i])"
Show-Help
exit 1
}
}
}
if (-not $repo) { Fail "please set --repo" }
if (-not $branch) { Fail "please set --branch" }
if (-not $sourceDir) { Fail "please set --source-dir" }
if (-not $config) { Fail "please set --config" }
if (-not $installPrefix) { Fail "please set --install-prefix" }
# Fetch LLVM from the repo
Msg "##########################################################"
Msg "# Fetching LLVM from $repo at $branch"
Msg "##########################################################"
git clone --depth 1 --branch $branch $repo $sourceDir
# Configure LLVM with CMake
Msg "##########################################################"
Msg "# Configuring LLVM in $sourceDir"
Msg "##########################################################"
$msvcRuntimeLib = "MultiThreaded"
if ($config -eq 'Debug')
{
$msvcRuntimeLib = "MultiThreadedDebug"
}
$cmakeArgumentsForSlang = @(
"-DLLVM_BUILD_LLVM_C_DYLIB=0"
"-DLLVM_INCLUDE_BENCHMARKS=0"
"-DLLVM_INCLUDE_DOCS=0"
"-DLLVM_INCLUDE_EXAMPLES=0"
"-DLLVM_INCLUDE_TESTS=0"
"-DLLVM_ENABLE_TERMINFO=0"
"-DCLANG_BUILD_TOOLS=0"
"-DCLANG_ENABLE_STATIC_ANALYZER=0"
"-DCLANG_ENABLE_ARCMT=0"
"-DCLANG_INCLUDE_DOCS=0"
"-DCLANG_INCLUDE_TESTS=0"
"-DLLVM_ENABLE_PROJECTS=clang"
"-DLLVM_TARGETS_TO_BUILD=X86;ARM;AArch64"
"-DLLVM_BUILD_TOOLS=0"
"-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded$<$<CONFIG:Debug>:Debug>"
"-DLLVM_USE_CRT_RELEASE=MT"
"-DLLVM_USE_CRT_DEBUG=MTd"
)
$buildDir = Join-Path $sourceDir "build"
New-Item -Path $buildDir -ItemType Directory -Force
$myScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$toolchainFile = Join-Path $myScriptDir "WindowsToolchain\Windows.MSVC.toolchain.cmake"
cmake -S $sourceDir\llvm -B $buildDir $cmakeArgumentsForSlang + $extraArguments -G "Ninja" --toolchain $toolchainFile
# Build LLVM
Msg "##########################################################"
Msg "# Building LLVM in $buildDir"
Msg "##########################################################"
cmake --build $buildDir -j --config $config
# Install LLVM
Msg "##########################################################"
Msg "# Installing LLVM to $installPrefix"
Msg "##########################################################"
cmake --install $buildDir --prefix $installPrefix --config $config
Msg "##########################################################"
Msg "LLVM installed in $installPrefix"
Msg "Please add $installPrefix to CMAKE_PREFIX_PATH"
Msg "##########################################################"
|