-
Notifications
You must be signed in to change notification settings - Fork 1
/
get-llvm.ps1
134 lines (108 loc) · 3.6 KB
/
get-llvm.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
function EnsureDirectory {
param (
[Parameter(Mandatory=$true)]
[string]$Path
)
$directoryName = Split-Path $Path -Leaf
if (Test-Path -Path $Path -PathType Container) {
Write-Host "The $directoryName directory already exists."
}
else {
try {
New-Item -Path $Path -ItemType Directory -ErrorAction Stop
Write-Host "The $directoryName directory has been created."
}
catch {
Write-Host "Failed to create the $directoryName directory: $($_.Exception.Message)"
}
}
}
function TryRemoveDirectory {
param (
[Parameter(Mandatory=$true)]
[string]$Path,
[switch]$Force,
[switch]$Recurse
)
$directoryName = Split-Path $Path -Leaf
if (Test-Path -Path $Path -PathType Container) {
try {
Remove-Item -Path $Path -Recurse:$Recurse -Force:$Force -ErrorAction Stop
Write-Host "The $directoryName directory has been removed."
}
catch {
Write-Host "Failed to remove the $directoryName directory: $($_.Exception.Message)"
}
}
else {
Write-Host "The $directoryName directory does not exist."
}
}
function PromptYesNoQuestion {
param (
[Parameter(Mandatory=$true)]
[string]$Question
)
$response = Read-Host -Prompt $Question
if ([string]::IsNullOrWhiteSpace($response) -or $response -eq "Y" -or $response -eq "y") {
Write-Host -NoNewline "... yes"
return $true
}
else {
Write-Host -NoNewline "... no"
return $false
}
}
$newline = [System.Environment]::NewLine
$freshRepoQuestion = "Do you want to check out a fresh repository? (Y/n)"
$shouldCheckout = PromptYesNoQuestion -Question $freshRepoQuestion
if ($shouldCheckout) {
# Code to execute if the user chooses to check out a fresh repository
TryRemoveDirectory -Path "./llvm-project" -Recurse -Force
git clone --depth 1 --config core.autocrlf=false https://github.com/llvm/llvm-project.git
Write-Host "$newline=======$newline"
Write-Host "Fresh repository checked out."
} else {
# Code to execute if the user chooses not to check out a fresh repository
Write-Host "Skipping fresh repository checkout."
}
Write-Host "$newlinePreparing LLVM for build$newline"
Set-Location llvm-project
TryRemoveDirectory -Recurse -Force -Path ./build
EnsureDirectory -Path "./build"
Set-Location build
$continuePrepareQuestion = "Do you want to prepare LLVM? (Y/n)"
$shouldPrepare = PromptYesNoQuestion -Question $continuePrepareQuestion
if ($shouldPrepare) {
# definitely just a windows thing
# -Thost=x64 `
# potentially just a windows thing
# -DLLVM_TARGETS_TO_BUILD="host" `
# potentially won't work on windows
# -DLLVM_ENABLE_LLD=ON `
# potentially just a windows thing
# -DLLVM_ENABLE_ASSERTIONS=ON
cmake `
../llvm `
-G "Visual Studio 17 2022" `
-DCMAKE_BUILD_TYPE=Release `
-Thost=x64 `
-DCMAKE_CONFIGURATION_TYPES=Release `
-DLLVM_TARGETS_TO_BUILD="host" `
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;lldb;mlir" `
-DLLVM_ENABLE_LLD=ON `
-DLLVM_CCACHE_BUILD=ON `
-DLLVM_ENABLE_ASSERTIONS=ON
} else {
Write-Host "$newlineSkipping preparation...$newline"
}
$continueBuildQuestion = "Do you want to continue? (Y/n)"
$shouldBuild = PromptYesNoQuestion -Question $continueBuildQuestion
if ($shouldBuild) {
# Code to execute if the user chooses to continue
Write-Host "Continuing..."
cmake --build . --target ALL_BUILD --parallel
} else {
# Code to execute if the user chooses not to continue
Write-Host "Exiting..."
}