Skip to content

Commit a3c7ffc

Browse files
committed
Binary/CIL: Update the build script to support both CIL and x86.
1 parent ed50ecd commit a3c7ffc

1 file changed

Lines changed: 130 additions & 126 deletions

File tree

binary/build-win64.ps1

Lines changed: 130 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,153 +1,157 @@
11
param (
2-
[Parameter(ParameterSetName = 'InitSet')]
3-
[switch]$initlief,
4-
5-
[Parameter(ParameterSetName = 'InitSet')]
6-
[switch]$initzydis,
7-
8-
[Parameter(ParameterSetName = 'InitSet')]
9-
[switch]$initfmt,
10-
11-
[Parameter(ParameterSetName = 'InitSet')]
12-
[switch]$initboost,
13-
14-
[Parameter(ParameterSetName = 'InitSet')]
15-
[switch]$initargs,
16-
17-
[Parameter(ParameterSetName = 'InitSet')]
2+
[Parameter(ParameterSetName = 'x86')]
3+
[Parameter(ParameterSetName = 'x86Clean')]
4+
[Parameter(ParameterSetName = 'x86Init')]
5+
[switch]$x86,
6+
7+
[Parameter(ParameterSetName = 'cil')]
8+
[Parameter(ParameterSetName = 'cilClean')]
9+
[Parameter(ParameterSetName = 'cilInit')]
10+
[switch]$cil,
11+
12+
[Parameter(Mandatory=$true, ParameterSetName = 'x86Init')]
13+
[Parameter(Mandatory=$true, ParameterSetName = 'cilInit')]
1814
[switch]$init,
1915

20-
[Parameter(Mandatory=$true, ParameterSetName = 'InitSet')]
16+
[Parameter(Mandatory=$true, ParameterSetName = 'x86')]
17+
[Parameter(Mandatory=$true, ParameterSetName = 'cil')]
18+
[Parameter(Mandatory=$true, ParameterSetName = 'x86Init')]
19+
[Parameter(Mandatory=$true, ParameterSetName = 'cilInit')]
2120
[string]$cliFolder,
2221

23-
[Parameter(ParameterSetName = 'CleanSet', Mandatory = $true)]
22+
[Parameter(Mandatory = $true, ParameterSetName = 'x86Clean')]
23+
[Parameter(Mandatory = $true, ParameterSetName = 'cilClean')]
2424
[switch]$clean
2525
)
2626

27-
function init-lief {
28-
git clone https://github.com/lief-project/LIEF.git
29-
cd LIEF
30-
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded" .
31-
nmake
32-
nmake install
33-
cd ..
34-
}
35-
36-
function init-zydis {
37-
git clone https://github.com/zyantific/zydis.git --recursive
38-
cd zydis
39-
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded" .
40-
nmake
41-
nmake install
42-
cd ..
43-
}
44-
45-
function init-fmt {
46-
git clone https://github.com/fmtlib/fmt.git
47-
}
48-
49-
function init-boost-library($name) {
50-
git clone https://github.com/boostorg/$name.git
51-
xcopy /E /I /Y $name\include\boost boost-minimal\boost
52-
Remove-Item -Path $name -Recurse -Force
53-
}
54-
55-
function init-boost {
56-
if (-not (Test-Path boost-minimal)) {
57-
mkdir boost-minimal
27+
function x86 {
28+
function init-lief {
29+
git clone https://github.com/lief-project/LIEF.git
30+
cd LIEF
31+
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded" .
32+
nmake
33+
nmake install
34+
cd ..
5835
}
59-
init-boost-library algorithm
60-
init-boost-library mpl
61-
init-boost-library range
62-
init-boost-library preprocessor
63-
init-boost-library type_traits
64-
init-boost-library iterator
65-
init-boost-library assert
66-
init-boost-library mp11
67-
init-boost-library static_assert
68-
init-boost-library core
69-
init-boost-library concept_check
70-
init-boost-library utility
71-
init-boost-library function
72-
init-boost-library bind
73-
init-boost-library throw_exception
74-
init-boost-library optional
75-
init-boost-library config
76-
}
7736

78-
function init-args {
79-
git clone https://github.com/Taywee/args.git
80-
}
37+
function init-zydis {
38+
git clone https://github.com/zyantific/zydis.git --recursive
39+
cd zydis
40+
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded" .
41+
nmake
42+
nmake install
43+
cd ..
44+
}
8145

82-
if($initlief) {
83-
cd extractor
84-
init-lief
85-
cd ..
86-
}
46+
function init-fmt {
47+
git clone https://github.com/fmtlib/fmt.git
48+
}
8749

88-
if($initzydis) {
89-
cd extractor
90-
init-zydis
91-
cd ..
92-
}
50+
function init-boost-library($name) {
51+
git clone https://github.com/boostorg/$name.git
52+
xcopy /E /I /Y $name\include\boost boost-minimal\boost
53+
Remove-Item -Path $name -Recurse -Force
54+
}
9355

94-
if($initfmt) {
95-
cd extractor
96-
init-fmt
97-
cd ..
98-
}
56+
function init-boost {
57+
if (-not (Test-Path boost-minimal)) {
58+
mkdir boost-minimal
59+
}
60+
init-boost-library algorithm
61+
init-boost-library mpl
62+
init-boost-library range
63+
init-boost-library preprocessor
64+
init-boost-library type_traits
65+
init-boost-library iterator
66+
init-boost-library assert
67+
init-boost-library mp11
68+
init-boost-library static_assert
69+
init-boost-library core
70+
init-boost-library concept_check
71+
init-boost-library utility
72+
init-boost-library function
73+
init-boost-library bind
74+
init-boost-library throw_exception
75+
init-boost-library optional
76+
init-boost-library config
77+
}
9978

100-
if($initboost) {
101-
cd extractor
102-
init-boost
103-
cd ..
104-
}
79+
function init-args {
80+
git clone https://github.com/Taywee/args.git
81+
}
10582

106-
if($initargs) {
107-
cd extractor
108-
init-args
109-
cd ..
110-
}
83+
if($init) {
84+
Push-Location extractor/x86
85+
init-lief
86+
init-zydis
87+
init-fmt
88+
init-boost
89+
init-args
90+
Pop-Location
91+
}
11192

112-
if($init) {
113-
cd extractor
114-
init-lief
115-
init-zydis
116-
init-fmt
117-
init-boost
118-
init-args
119-
cd ..
93+
if($clean) {
94+
Push-Location extractor/x86
95+
if(Test-Path args) { Remove-Item -Path args -Recurse -Force }
96+
if(Test-Path boost-minimal) { Remove-Item -Path boost-minimal -Recurse -Force }
97+
if(Test-Path fmt) { Remove-Item -Path fmt -Recurse -Force }
98+
if(Test-Path LIEF) { Remove-Item -Path LIEF -Recurse -Force }
99+
if(Test-Path zydis) { Remove-Item -Path zydis -Recurse -Force }
100+
Pop-Location
101+
} else {
102+
Push-Location extractor/x86
103+
104+
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
105+
106+
if ($LASTEXITCODE -ne 0) {
107+
Write-Host "Build failed"
108+
Pop-Location
109+
exit 1
110+
}
111+
112+
Pop-Location
113+
114+
$toolsWin64Folder = Join-Path (Join-Path (Join-Path $cliFolder "binary") "tools") "win64"
115+
New-Item -ItemType Directory -Force -Path $toolsWin64Folder
116+
$binaryFolder = Join-Path -Path $cliFolder -ChildPath "binary"
117+
New-Item -ItemType Directory -Force -Path $binaryFolder
118+
Copy-Item -Path "$PSScriptRoot/extractor/x86/codeql-extractor.yml" -Destination $binaryFolder -Force
119+
Copy-Item -Path "$PSScriptRoot/downgrades" -Destination $binaryFolder -Recurse -Force
120+
$qlLibFolder = Join-Path -Path "$PSScriptRoot/ql" -ChildPath "lib"
121+
Copy-Item -Path (Join-Path $qlLibFolder "semmlecode.binary.dbscheme") -Destination $binaryFolder -Force
122+
Copy-Item -Path (Join-Path $qlLibFolder "semmlecode.binary.dbscheme.stats") -Destination $binaryFolder -Force
123+
Copy-Item -Path "$PSScriptRoot/tools/x86/*" -Destination (Join-Path $binaryFolder "tools") -Recurse -Force
124+
Copy-Item -Path "$PSScriptRoot/extractor/x86/extractor.exe" -Destination $toolsWin64Folder/extractor.exe
125+
}
120126
}
121127

122-
if($clean) {
123-
cd extractor
124-
if(Test-Path args) { Remove-Item -Path args -Recurse -Force }
125-
if(Test-Path boost-minimal) { Remove-Item -Path boost-minimal -Recurse -Force }
126-
if(Test-Path fmt) { Remove-Item -Path fmt -Recurse -Force }
127-
if(Test-Path LIEF) { Remove-Item -Path LIEF -Recurse -Force }
128-
if(Test-Path zydis) { Remove-Item -Path zydis -Recurse -Force }
129-
cd ..
130-
} else {
131-
cd extractor
132-
133-
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
134-
128+
function cil {
129+
Push-Location extractor/cil
130+
$toolsWin64Folder = Join-Path (Join-Path (Join-Path $cliFolder "cil") "tools") "win64"
131+
dotnet build Semmle.Extraction.CSharp.IL -o $toolsWin64Folder -c Release --self-contained
135132
if ($LASTEXITCODE -ne 0) {
136133
Write-Host "Build failed"
134+
Pop-Location
137135
exit 1
138136
}
139137

140-
cd ..
138+
Pop-Location
141139

142-
$toolsWin64Folder = Join-Path (Join-Path (Join-Path $cliFolder "binary") "tools") "win64"
143140
New-Item -ItemType Directory -Force -Path $toolsWin64Folder
144-
$binaryFolder = Join-Path -Path $cliFolder -ChildPath "binary"
145-
New-Item -ItemType Directory -Force -Path $binaryFolder
146-
Copy-Item -Path "$PSScriptRoot/codeql-extractor.yml" -Destination $binaryFolder -Force
147-
Copy-Item -Path "$PSScriptRoot/downgrades" -Destination $binaryFolder -Recurse -Force
141+
$cilFolder = Join-Path -Path $cliFolder -ChildPath "cil"
142+
New-Item -ItemType Directory -Force -Path $cilFolder
143+
Copy-Item -Path "$PSScriptRoot/extractor/cil/codeql-extractor.yml" -Destination $cilFolder -Force
144+
Copy-Item -Path "$PSScriptRoot/downgrades" -Destination $cilFolder -Recurse -Force
148145
$qlLibFolder = Join-Path -Path "$PSScriptRoot/ql" -ChildPath "lib"
149-
Copy-Item -Path (Join-Path $qlLibFolder "semmlecode.binary.dbscheme") -Destination $binaryFolder -Force
150-
Copy-Item -Path (Join-Path $qlLibFolder "semmlecode.binary.dbscheme.stats") -Destination $binaryFolder -Force
151-
Copy-Item -Path "$PSScriptRoot/tools" -Destination $binaryFolder -Recurse -Force
152-
Copy-Item -Path "$PSScriptRoot/extractor/extractor.exe" -Destination $toolsWin64Folder/extractor.exe
146+
Copy-Item -Path (Join-Path $qlLibFolder "semmlecode.binary.dbscheme") -Destination $cilFolder -Force
147+
Copy-Item -Path (Join-Path $qlLibFolder "semmlecode.binary.dbscheme.stats") -Destination $cilFolder -Force
148+
Copy-Item -Path "$PSScriptRoot/tools/cil/*" -Destination (Join-Path $cilFolder "tools") -Recurse -Force
149+
}
150+
151+
if($x86) {
152+
x86
153+
}
154+
155+
if($cil) {
156+
cil
153157
}

0 commit comments

Comments
 (0)