-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathbuild.cmd
More file actions
258 lines (230 loc) · 12.5 KB
/
build.cmd
File metadata and controls
258 lines (230 loc) · 12.5 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
REM Copyright (c) Microsoft Corporation
REM SPDX-License-Identifier: MIT
@echo off
SET root_path=%~dp0
set Configuration=%1
Set Target=%2
set CleanBuild=%3
set ContinueAtConvertBpfToNative=%4
set out_path=%5
if "%Configuration%"=="" (SET Configuration=debug)
echo Configuration=%Configuration%
SET eBPF_Platform="x64"
Set build_target=x86_64-pc-windows-msvc
if "%Target%"=="arm64" (
Set build_target=aarch64-pc-windows-msvc
SET eBPF_Platform="arm64"
) else (
Set build_target=x86_64-pc-windows-msvc
Set Target=amd64
)
if "%out_path%"=="" (SET out_path=%root_path%out)
SET out_dir=%out_path%\%build_target%\%Configuration%
echo out_path=%out_path%
echo out_dir=%out_dir%
REM Set the path to the eBPF-for-Windows binaries and include files,
REM We build ARM64 binaries on x64 machine, so we need to set the path to the x64 binaries
SET eBPF_for_Windows_bin_path=%root_path%packages\eBPF-for-Windows.x64.1.0.0-rc1\build\native\bin
SET eBPF_for_Windows_inc_path=%root_path%packages\eBPF-for-Windows.%eBPF_Platform%.1.0.0-rc1\build\native\include
SET bin_skim_path=%root_path%packages\Microsoft.CodeAnalysis.BinSkim.1.9.5\tools\netcoreapp3.1\win-x64
if "%CleanBuild%"=="clean" (
echo ======= delete old files
echo RD /S /Q %out_dir%
RD /S /Q %out_dir%
echo RD /S /Q %root_path%packages
RD /S /Q %root_path%packages
)
echo ======= nuget restore
call nuget restore
if %ERRORLEVEL% NEQ 0 (
echo call nuget restore with exit-code: %errorlevel%
exit /b %errorlevel%
)
if "%Target%"=="arm64" (
REM Install the latest Windows Driver Kit (WDK) NuGet packages
nuget.exe install Microsoft.Windows.WDK.arm64 -Version 10.0.26100.2454
) else (
REM Install the latest Windows Driver Kit (WDK) NuGet packages
nuget.exe install Microsoft.Windows.WDK.x64 -Version 10.0.26100.2454
)
echo ======= rustup update to a particular version of the Rust toolchain
SET rustup_version=1.92.0
call rustup update %rustup_version%
REM This command sets a specific Rust toolchain version for the current directory.
REM It means that whenever you are in this directory, Rust commands will use the specified toolchain version, regardless of the global default.
call rustup override set %rustup_version%
call rustup target add %build_target%
echo ======= create out path folder and subfolder
if not exist "%out_path%" (md "%out_path%")
if not exist "%out_dir%" (md "%out_dir%")
echo ======= Prepare out-package folder structure
SET out_package_dir=%out_dir%\package
if not exist "%out_package_dir%" (md "%out_package_dir%")
SET out_package_proxyagent_dir="%out_package_dir%"\ProxyAgent
if not exist "%out_package_proxyagent_dir%" (md "%out_package_proxyagent_dir%")
echo ======= build ebpf program
SET ebpf_path=%root_path%\ebpf
echo call clang -I"%ebpf_path%" -I "%eBPF_for_Windows_inc_path%" -target bpf -Werror -O2 -c %ebpf_path%\redirect.bpf.c -o %out_dir%\redirect.bpf.o
call clang -I"%ebpf_path%" -I "%eBPF_for_Windows_inc_path%" -target bpf -Werror -O2 -c %ebpf_path%\redirect.bpf.c -o %out_dir%\redirect.bpf.o
if %ERRORLEVEL% NEQ 0 (
echo call clang failed with exit-code: %errorlevel%
exit /b %errorlevel%
)
echo ======= copy redirect.bpf.o
xcopy /Y %out_dir%\redirect.bpf.o %out_package_proxyagent_dir%\
echo ======= convert redirect.bpf.o to redirect.bpf.sys
call %eBPF_for_Windows_bin_path%\export_program_info.exe --clear
call %eBPF_for_Windows_bin_path%\export_program_info.exe
echo call powershell.exe -ExecutionPolicy Bypass %eBPF_for_Windows_bin_path%\Convert-BpfToNative.ps1 -OutDir "%out_dir%" -FileName redirect.bpf.o -IncludeDir "%eBPF_for_Windows_inc_path%" -Platform %eBPF_Platform%
call powershell.exe -ExecutionPolicy Bypass %eBPF_for_Windows_bin_path%\Convert-BpfToNative.ps1 -OutDir "%out_dir%" -FileName redirect.bpf.o -IncludeDir "%eBPF_for_Windows_inc_path%" -Platform %eBPF_Platform%
if %ERRORLEVEL% NEQ 0 (
echo call Convert-BpfToNative.ps1 failed with exit-code: %errorlevel%
if "%ContinueAtConvertBpfToNative%"=="" (
exit /b %errorlevel%
)
echo Skip the error and continue to build other projects
)
echo ======= copy redirect.bpf.sys
xcopy /Y %out_dir%\redirect.bpf.sys %out_package_proxyagent_dir%\
xcopy /Y %out_dir%\redirect.bpf.pdb %out_package_proxyagent_dir%\
echo ======= cargo fmt and clippy
echo call rustup component add --toolchain %rustup_version%-x86_64-pc-windows-msvc rustfmt
call rustup component add --toolchain %rustup_version%-x86_64-pc-windows-msvc rustfmt
echo call cargo fmt --all
cargo fmt --all
echo call rustup component add --toolchain %rustup_version%-x86_64-pc-windows-msvc clippy
call rustup component add --toolchain %rustup_version%-x86_64-pc-windows-msvc clippy
echo call cargo clippy -- -D warnings
cargo clippy -- -D warnings
if %ERRORLEVEL% NEQ 0 (
echo cargo clippy failed with exit-code: %errorlevel%
exit /b %errorlevel%
)
echo ======= build proxy_agent_shared
set cargo_toml=%root_path%proxy_agent_shared\Cargo.toml
SET release_flag=
if "%Configuration%"=="release" (SET release_flag=--release)
echo cargo_toml=%cargo_toml%
echo call cargo build %release_flag% --manifest-path %cargo_toml% --target-dir %out_path% --target %build_target%
call cargo build %release_flag% --manifest-path %cargo_toml% --target-dir %out_path% --target %build_target%
if %ERRORLEVEL% NEQ 0 (
echo call cargo build proxy_agent_shared failed with exit-code: %errorlevel%
exit /b %errorlevel%
)
if "%Target%"=="arm64" (
echo ======= skip running proxy_agent_shared arm64 tests on amd64 machine
) else (
echo ======= copy files for run/debug proxy_agent_shared Unit test in VS Code
echo xcopy /Y /C /Q %out_dir% %out_dir%\deps\
xcopy /Y /C /Q %out_dir% %out_dir%\deps\
echo xcopy /Y /S /C /Q %out_dir% %root_path%proxy_agent_shared\target\%Configuration%\
xcopy /Y /S /C /Q %out_dir% %root_path%proxy_agent_shared\target\%Configuration%\
echo ======= run rust proxy_agent_shared tests
REM %ERRORLEVEL% inside a (...) block is expanded when the entire block is parsed, not when each line run
REM use exit /b 1 to propagate error codes inside a (...) block
echo call cargo test --all-features %release_flag% --manifest-path %cargo_toml% --target-dir %out_path% --target %build_target% -- --test-threads=1 --nocapture ^|^| exit /b 1
call cargo test --all-features %release_flag% --manifest-path %cargo_toml% --target-dir %out_path% --target %build_target% -- --test-threads=1 --nocapture || exit /b 1
)
echo ======= copy config file for windows platform
REM Adding a wildcard (*) to the end of the destination will suppress this prompt and default to copying as a file:
xcopy /Y %root_path%proxy_agent\config\GuestProxyAgent.windows.json %out_dir%\GuestProxyAgent.json*
echo ======= build proxy_agent
set cargo_toml=%root_path%proxy_agent\Cargo.toml
SET release_flag=
if "%Configuration%"=="release" (SET release_flag=--release)
echo cargo_toml=%cargo_toml%
echo call cargo build %release_flag% --manifest-path %cargo_toml% --target-dir %out_path% --target %build_target%
call cargo build %release_flag% --manifest-path %cargo_toml% --target-dir %out_path% --target %build_target%
if %ERRORLEVEL% NEQ 0 (
echo call cargo build proxy_agent failed with exit-code: %errorlevel%
exit /b %errorlevel%
)
if "%Target%"=="arm64" (
echo ======= skip running proxy_agent arm64 tests on amd64 machine
) else (
echo ======= copy files for run/debug proxy_agent Unit test
echo xcopy /Y /C /Q %out_dir% %out_dir%\deps\
xcopy /Y /C /Q %out_dir% %out_dir%\deps\
echo xcopy /Y /S /C /Q %out_dir% %root_path%proxy_agent\target\%Configuration%\
xcopy /Y /S /C /Q %out_dir% %root_path%proxy_agent\target\%Configuration%\
echo ======= run rust proxy_agent tests
REM use exit /b 1 to propagate error codes inside a (...) block
echo call cargo test --all-features %release_flag% --manifest-path %cargo_toml% --target-dir %out_path% --target %build_target% -- --test-threads=1 --nocapture ^|^| exit /b 1
call cargo test --all-features %release_flag% --manifest-path %cargo_toml% --target-dir %out_path% --target %build_target% -- --test-threads=1 --nocapture || exit /b 1
)
echo ======= build proxy_agent_extension
SET extension_root_path=%root_path%proxy_agent_extension
SET extension_src_path=%root_path%proxy_agent_extension\src\windows
set cargo_toml=%extension_root_path%\Cargo.toml
echo cargo_toml=%cargo_toml%
echo call cargo build %release_flag% --manifest-path %cargo_toml% --target-dir %out_path% --target %build_target%
call cargo build %release_flag% --manifest-path %cargo_toml% --target-dir %out_path% --target %build_target%
if %ERRORLEVEL% NEQ 0 (
echo call cargo build proxy_agent_extension failed with exit-code: %errorlevel%
exit /b %errorlevel%
)
if "%Target%"=="arm64" (
echo ======= skip running proxy_agent_extension arm64 tests on amd64 machine
) else (
echo ======= copy files for run/debug proxy_agent_extension Unit test
echo xcopy /Y /C /Q %out_dir% %out_dir%\deps\
xcopy /Y /C /Q %out_dir% %out_dir%\deps\
echo xcopy /Y /S /C /Q %out_dir% %root_path%proxy_agent_extension\target\%Configuration%\
xcopy /Y /S /C /Q %out_dir% %root_path%proxy_agent_extension\target\%Configuration%\
echo ======= run rust proxy_agent_extension tests
REM use exit /b 1 to propagate error codes inside a (...) block
echo call cargo test --all-features %release_flag% --manifest-path %cargo_toml% --target-dir %out_path% --target %build_target% -- --test-threads=1 --nocapture ^|^| exit /b 1
call cargo test --all-features %release_flag% --manifest-path %cargo_toml% --target-dir %out_path% --target %build_target% -- --test-threads=1 --nocapture || exit /b 1
)
echo ======= build proxy_agent_setup
set cargo_toml=%root_path%proxy_agent_setup\Cargo.toml
SET release_flag=
if "%Configuration%"=="release" (SET release_flag=--release)
echo cargo_toml=%cargo_toml%
echo call cargo build %release_flag% --manifest-path %cargo_toml% --target-dir %out_path% --target %build_target%
call cargo build %release_flag% --manifest-path %cargo_toml% --target-dir %out_path% --target %build_target%
if %ERRORLEVEL% NEQ 0 (
echo call cargo build proxy_agent_setup failed with exit-code: %errorlevel%
exit /b %errorlevel%
)
echo ======= restore e2e test project dependencies
echo call dotnet.exe restore %root_path%\e2etest\GuestProxyAgentTest.sln -v normal
call dotnet.exe restore %root_path%\e2etest\GuestProxyAgentTest.sln
if %ERRORLEVEL% NEQ 0 (
echo call dotnet.exe restore failed with exit-code: %errorlevel%
exit /b %errorlevel%
)
echo ======= build e2e test project
SET out_e2etest_dir=%out_dir%\e2etest
echo call dotnet.exe build %root_path%\e2etest\GuestProxyAgentTest.sln --no-restore --configuration %Configuration% -o %out_e2etest_dir%
call dotnet.exe build %root_path%\e2etest\GuestProxyAgentTest.sln --no-restore --configuration %Configuration% -o %out_e2etest_dir%
if %ERRORLEVEL% NEQ 0 (
echo call dotnet.exe build failed with exit-code: %errorlevel%
exit /b %errorlevel%
)
dir /S /B %out_e2etest_dir%\
echo ======= copy setup tool to Package folder
xcopy /Y %out_dir%\proxy_agent_setup.exe %out_package_dir%\
xcopy /Y %out_dir%\proxy_agent_setup.pdb %out_package_dir%\
echo ======= copy to ProxyAgent folder
xcopy /Y %out_dir%\azure-proxy-agent.exe %out_package_proxyagent_dir%\GuestProxyAgent.exe*
REM do NOT rename pdb file, as it is used by the debugger to load the symbols automatically
xcopy /Y %out_dir%\azure_proxy_agent.pdb %out_package_proxyagent_dir%\
xcopy /Y %out_dir%\GuestProxyAgent.json %out_package_proxyagent_dir%\
SET out_package_proxyagent_extension_dir=%out_package_dir%\ProxyAgent_Extension
if not exist "%out_package_proxyagent_extension_dir%" (md "%out_package_proxyagent_extension_dir%")
echo ======= copy ProxyAgent Extension files
xcopy /Y %extension_src_path%\HandlerManifest.json %out_package_proxyagent_extension_dir%\
for %%F in (%extension_src_path%\*.cmd) do (
echo Found file: %%F
xcopy /Y %%F %out_package_proxyagent_extension_dir%\
)
xcopy /Y %out_dir%\ProxyAgentExt.* %out_package_proxyagent_extension_dir%\
echo ======= copy e2e test project to Package folder
SET out_package_e2etest_dir=%out_package_dir%\e2etest
echo xcopy /Y /S /C /Q %out_e2etest_dir% %out_package_e2etest_dir%\
xcopy /Y /S /C /Q %out_e2etest_dir% %out_package_e2etest_dir%\
echo ======= run binskim command
call %bin_skim_path%\BinSkim.exe analyze %out_package_proxyagent_dir%\GuestProxyAgent.exe --output %out_package_proxyagent_dir%\GuestProxyAgent.exe.binskim.json --rich-return-code=true --force
echo ======= Generate build-configuration.zip file
call powershell.exe Compress-Archive -Path "%out_package_dir%" -DestinationPath "%out_dir%"\build-%Configuration%-windows-%Target%.zip" -Force