forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathbuild-win64.ps1
More file actions
157 lines (136 loc) · 5.4 KB
/
build-win64.ps1
File metadata and controls
157 lines (136 loc) · 5.4 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
param (
[Parameter(ParameterSetName = 'x86')]
[Parameter(ParameterSetName = 'x86Clean')]
[Parameter(ParameterSetName = 'x86Init')]
[switch]$x86,
[Parameter(ParameterSetName = 'cil')]
[Parameter(ParameterSetName = 'cilClean')]
[Parameter(ParameterSetName = 'cilInit')]
[switch]$cil,
[Parameter(Mandatory=$true, ParameterSetName = 'x86Init')]
[Parameter(Mandatory=$true, ParameterSetName = 'cilInit')]
[switch]$init,
[Parameter(Mandatory=$true, ParameterSetName = 'x86')]
[Parameter(Mandatory=$true, ParameterSetName = 'cil')]
[Parameter(Mandatory=$true, ParameterSetName = 'x86Init')]
[Parameter(Mandatory=$true, ParameterSetName = 'cilInit')]
[string]$cliFolder,
[Parameter(Mandatory = $true, ParameterSetName = 'x86Clean')]
[Parameter(Mandatory = $true, ParameterSetName = 'cilClean')]
[switch]$clean
)
function x86 {
function init-lief {
git clone https://github.com/lief-project/LIEF.git
cd LIEF
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded" .
nmake
nmake install
cd ..
}
function init-zydis {
git clone https://github.com/zyantific/zydis.git --recursive
cd zydis
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded" .
nmake
nmake install
cd ..
}
function init-fmt {
git clone https://github.com/fmtlib/fmt.git
}
function init-boost-library($name) {
git clone https://github.com/boostorg/$name.git
xcopy /E /I /Y $name\include\boost boost-minimal\boost
Remove-Item -Path $name -Recurse -Force
}
function init-boost {
if (-not (Test-Path boost-minimal)) {
mkdir boost-minimal
}
init-boost-library algorithm
init-boost-library mpl
init-boost-library range
init-boost-library preprocessor
init-boost-library type_traits
init-boost-library iterator
init-boost-library assert
init-boost-library mp11
init-boost-library static_assert
init-boost-library core
init-boost-library concept_check
init-boost-library utility
init-boost-library function
init-boost-library bind
init-boost-library throw_exception
init-boost-library optional
init-boost-library config
}
function init-args {
git clone https://github.com/Taywee/args.git
}
if($init) {
Push-Location extractor/x86
init-lief
init-zydis
init-fmt
init-boost
init-args
Pop-Location
}
if($clean) {
Push-Location extractor/x86
if(Test-Path args) { Remove-Item -Path args -Recurse -Force }
if(Test-Path boost-minimal) { Remove-Item -Path boost-minimal -Recurse -Force }
if(Test-Path fmt) { Remove-Item -Path fmt -Recurse -Force }
if(Test-Path LIEF) { Remove-Item -Path LIEF -Recurse -Force }
if(Test-Path zydis) { Remove-Item -Path zydis -Recurse -Force }
Pop-Location
} else {
Push-Location extractor/x86
cl.exe /DFMT_HEADER_ONLY /DZYDIS_STATIC_BUILD /I zydis\include /I zydis\dependencies\zycore\include /I LIEF/include /I fmt/include /I boost-minimal /I args /utf-8 src/main.cpp zydis\Zydis.lib zydis/zycore/zycore.lib LIEF/LIEF.lib /EHsc /std:c++17 /link /out:extractor.exe
if ($LASTEXITCODE -ne 0) {
Write-Host "Build failed"
Pop-Location
exit 1
}
Pop-Location
$toolsWin64Folder = Join-Path (Join-Path (Join-Path $cliFolder "binary") "tools") "win64"
New-Item -ItemType Directory -Force -Path $toolsWin64Folder
$binaryFolder = Join-Path -Path $cliFolder -ChildPath "binary"
New-Item -ItemType Directory -Force -Path $binaryFolder
Copy-Item -Path "$PSScriptRoot/extractor/x86/codeql-extractor.yml" -Destination $binaryFolder -Force
Copy-Item -Path "$PSScriptRoot/downgrades" -Destination $binaryFolder -Recurse -Force
$qlLibFolder = Join-Path -Path "$PSScriptRoot/ql" -ChildPath "lib"
Copy-Item -Path (Join-Path $qlLibFolder "semmlecode.binary.dbscheme") -Destination $binaryFolder -Force
Copy-Item -Path (Join-Path $qlLibFolder "semmlecode.binary.dbscheme.stats") -Destination $binaryFolder -Force
Copy-Item -Path "$PSScriptRoot/tools/x86/*" -Destination (Join-Path $binaryFolder "tools") -Recurse -Force
Copy-Item -Path "$PSScriptRoot/extractor/x86/extractor.exe" -Destination $toolsWin64Folder/extractor.exe
}
}
function cil {
Push-Location extractor/cil
$toolsWin64Folder = Join-Path (Join-Path (Join-Path $cliFolder "cil") "tools") "win64"
dotnet build Semmle.Extraction.CSharp.IL -o $toolsWin64Folder -c Release --self-contained
if ($LASTEXITCODE -ne 0) {
Write-Host "Build failed"
Pop-Location
exit 1
}
Pop-Location
New-Item -ItemType Directory -Force -Path $toolsWin64Folder
$cilFolder = Join-Path -Path $cliFolder -ChildPath "cil"
New-Item -ItemType Directory -Force -Path $cilFolder
Copy-Item -Path "$PSScriptRoot/extractor/cil/codeql-extractor.yml" -Destination $cilFolder -Force
Copy-Item -Path "$PSScriptRoot/downgrades" -Destination $cilFolder -Recurse -Force
$qlLibFolder = Join-Path -Path "$PSScriptRoot/ql" -ChildPath "lib"
Copy-Item -Path (Join-Path $qlLibFolder "semmlecode.binary.dbscheme") -Destination $cilFolder -Force
Copy-Item -Path (Join-Path $qlLibFolder "semmlecode.binary.dbscheme.stats") -Destination $cilFolder -Force
Copy-Item -Path "$PSScriptRoot/tools/cil/*" -Destination (Join-Path $cilFolder "tools") -Recurse -Force
}
if($x86) {
x86
}
if($cil) {
cil
}