-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathbuild.bat
More file actions
319 lines (297 loc) · 14 KB
/
Copy pathbuild.bat
File metadata and controls
319 lines (297 loc) · 14 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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
@echo off
setlocal enabledelayedexpansion
:: Defaults
set "BUILD_CONFIG=release"
set "BUILD_ARCH="
set "BUILD_ALL=0"
set "WITH_NANVIX=0"
set "WITH_WSLC=0"
set "WITH_ISOLATION_SESSION=0"
set "WITH_HYPERLIGHT=0"
:: Parse arguments
:parse_args
if "%~1"=="" goto :args_done
if /i "%~1"=="--debug" ( set "BUILD_CONFIG=debug" & shift & goto :parse_args )
if /i "%~1"=="--release" ( set "BUILD_CONFIG=release" & shift & goto :parse_args )
if /i "%~1"=="--x64" ( set "BUILD_ARCH=x86_64-pc-windows-msvc" & shift & goto :parse_args )
if /i "%~1"=="--arm64" ( set "BUILD_ARCH=aarch64-pc-windows-msvc" & shift & goto :parse_args )
if /i "%~1"=="--all" ( set "BUILD_ALL=1" & shift & goto :parse_args )
if /i "%~1"=="--with-microvm" ( set "WITH_NANVIX=1" & shift & goto :parse_args )
if /i "%~1"=="--with-wslc" ( set "WITH_WSLC=1" & shift & goto :parse_args )
if /i "%~1"=="--with-isolation-session" ( set "WITH_ISOLATION_SESSION=1" & shift & goto :parse_args )
if /i "%~1"=="--with-hyperlight" ( set "WITH_HYPERLIGHT=1" & shift & goto :parse_args )
if /i "%~1"=="--help" ( goto :usage )
if /i "%~1"=="-h" ( goto :usage )
echo Unknown argument: %~1
goto :usage
:args_done
:: Detect native architecture if not specified and not --all
if "%BUILD_ALL%"=="0" if "%BUILD_ARCH%"=="" (
if /i "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
set "BUILD_ARCH=aarch64-pc-windows-msvc"
) else (
set "BUILD_ARCH=x86_64-pc-windows-msvc"
)
)
:: Build flags
set "CARGO_FLAGS=--target"
if "%BUILD_CONFIG%"=="release" set "CARGO_FLAGS=--release --target"
:: plm is a standalone Windows-only binary that does not consume any of the
:: workspace feature flags above, so it uses its own profile/target-only flags.
set "PLM_FLAGS=--target"
if "%BUILD_CONFIG%"=="release" set "PLM_FLAGS=--release --target"
if "%WITH_NANVIX%"=="1" set "CARGO_FLAGS=--features microvm %CARGO_FLAGS%"
if "%WITH_WSLC%"=="1" set "CARGO_FLAGS=--features wslc %CARGO_FLAGS%"
if "%WITH_ISOLATION_SESSION%"=="1" set "CARGO_FLAGS=--features isolation_session %CARGO_FLAGS%"
if "%WITH_HYPERLIGHT%"=="1" set "CARGO_FLAGS=--features hyperlight %CARGO_FLAGS%"
set "DOTNET_CONFIG=Release"
if "%BUILD_CONFIG%"=="debug" set "DOTNET_CONFIG=Debug"
set "DOTNET_BUILD_PROPERTIES="
if "%WITH_ISOLATION_SESSION%"=="1" set "DOTNET_BUILD_PROPERTIES=!DOTNET_BUILD_PROPERTIES! -p:MxcWithIsolationSession=true"
if "%WITH_WSLC%"=="1" set "DOTNET_BUILD_PROPERTIES=!DOTNET_BUILD_PROPERTIES! -p:MxcWithWslc=true"
:: Build Rust
echo.
echo Building WXC (Rust) [%BUILD_CONFIG%]...
pushd src
:: Ensure the rustup targets are installed for the pinned toolchain
:: (src\rust-toolchain.toml). No-op if rustup is missing or the target
:: is already present.
where rustup >nul 2>&1
if not errorlevel 1 (
if "%BUILD_ALL%"=="1" (
rustup target add x86_64-pc-windows-msvc >nul 2>&1
rustup target add aarch64-pc-windows-msvc >nul 2>&1
) else (
rustup target add %BUILD_ARCH% >nul 2>&1
)
)
if "%BUILD_ALL%"=="1" (
echo Target: x86_64-pc-windows-msvc
cargo build %CARGO_FLAGS% x86_64-pc-windows-msvc || goto :error
cargo build -p plm %PLM_FLAGS% x86_64-pc-windows-msvc || goto :error
echo Target: aarch64-pc-windows-msvc
cargo build %CARGO_FLAGS% aarch64-pc-windows-msvc || goto :error
cargo build -p plm %PLM_FLAGS% aarch64-pc-windows-msvc || goto :error
) else (
echo Target: %BUILD_ARCH%
cargo build %CARGO_FLAGS% %BUILD_ARCH% || goto :error
cargo build -p plm %PLM_FLAGS% %BUILD_ARCH% || goto :error
)
echo Check formatting
cargo fmt --all -- --check || goto :error
echo Check linting
cargo clippy --workspace --all-targets -- -D warnings || goto :error
popd
:: Copy binaries into SDK package
echo.
echo Copying binaries into SDK package...
for %%T in (x86_64-pc-windows-msvc aarch64-pc-windows-msvc) do (
set "BIN_DIR=src\target\%%T\%BUILD_CONFIG%"
if "%%T"=="x86_64-pc-windows-msvc" (set "SDK_ARCH=x64") else (set "SDK_ARCH=arm64")
set "COPY_WSLC_RUNTIME=0"
if "%BUILD_ALL%"=="1" set "COPY_WSLC_RUNTIME=1"
if "%%T"=="%BUILD_ARCH%" set "COPY_WSLC_RUNTIME=1"
if exist "!BIN_DIR!\wxc-exec.exe" (
if not exist "sdk\node\bin\!SDK_ARCH!" mkdir "sdk\node\bin\!SDK_ARCH!"
copy /Y "!BIN_DIR!\wxc-exec.exe" "sdk\node\bin\!SDK_ARCH!\" >nul
echo Copied !SDK_ARCH!\wxc-exec.exe
if exist "!BIN_DIR!\wxc-windows-sandbox-guest.exe" (
copy /Y "!BIN_DIR!\wxc-windows-sandbox-guest.exe" "sdk\node\bin\!SDK_ARCH!\" >nul
echo Copied !SDK_ARCH!\wxc-windows-sandbox-guest.exe
)
if exist "!BIN_DIR!\wxc-windows-sandbox-daemon.exe" (
copy /Y "!BIN_DIR!\wxc-windows-sandbox-daemon.exe" "sdk\node\bin\!SDK_ARCH!\" >nul
echo Copied !SDK_ARCH!\wxc-windows-sandbox-daemon.exe
)
if exist "!BIN_DIR!\winhttp-proxy-shim.exe" (
copy /Y "!BIN_DIR!\winhttp-proxy-shim.exe" "sdk\node\bin\!SDK_ARCH!\" >nul
echo Copied !SDK_ARCH!\winhttp-proxy-shim.exe
)
if exist "!BIN_DIR!\wxc-test-proxy.exe" (
copy /Y "!BIN_DIR!\wxc-test-proxy.exe" "sdk\node\bin\!SDK_ARCH!\" >nul
echo Copied !SDK_ARCH!\wxc-test-proxy.exe
)
if exist "!BIN_DIR!\wxc-host-prep.exe" (
copy /Y "!BIN_DIR!\wxc-host-prep.exe" "sdk\node\bin\!SDK_ARCH!\" >nul
echo Copied !SDK_ARCH!\wxc-host-prep.exe
)
if exist "!BIN_DIR!\plm.exe" (
copy /Y "!BIN_DIR!\plm.exe" "sdk\node\bin\!SDK_ARCH!\" >nul
echo Copied !SDK_ARCH!\plm.exe
)
if exist "!BIN_DIR!\mxc_ffi.dll" (
copy /Y "!BIN_DIR!\mxc_ffi.dll" "sdk\node\bin\!SDK_ARCH!\" >nul
echo Copied !SDK_ARCH!\mxc_ffi.dll
)
if "%WITH_NANVIX%"=="1" (
for %%B in (nanvixd.exe nanvix_rootfs.img python3.initrd) do (
if exist "!BIN_DIR!\%%B" (
copy /Y "!BIN_DIR!\%%B" "sdk\node\bin\!SDK_ARCH!\" >nul
echo Copied !SDK_ARCH!\%%B
)
)
if exist "!BIN_DIR!\bin\kernel.elf" (
if not exist "sdk\node\bin\!SDK_ARCH!\bin" mkdir "sdk\node\bin\!SDK_ARCH!\bin"
copy /Y "!BIN_DIR!\bin\kernel.elf" "sdk\node\bin\!SDK_ARCH!\bin\" >nul
echo Copied !SDK_ARCH!\bin\kernel.elf
)
for %%S in (kernel.vmem kernel.whp.cbor) do (
if exist "!BIN_DIR!\snapshots\%%S" (
if not exist "sdk\node\bin\!SDK_ARCH!\snapshots" mkdir "sdk\node\bin\!SDK_ARCH!\snapshots"
copy /Y "!BIN_DIR!\snapshots\%%S" "sdk\node\bin\!SDK_ARCH!\snapshots\" >nul
echo Copied !SDK_ARCH!\snapshots\%%S
)
)
)
if "!COPY_WSLC_RUNTIME!"=="1" (
if "%WITH_WSLC%"=="1" (
for %%B in (wxc-wslc-daemon.exe wslcsdk.dll) do (
if not exist "!BIN_DIR!\%%B" (
echo ERROR: WSLC-enabled Node runtime is missing !BIN_DIR!\%%B
exit /b 1
)
copy /Y "!BIN_DIR!\%%B" "sdk\node\bin\!SDK_ARCH!\" >nul
echo Copied !SDK_ARCH!\%%B
)
) else (
if exist "sdk\node\bin\!SDK_ARCH!\wxc-wslc-daemon.exe" del /Q "sdk\node\bin\!SDK_ARCH!\wxc-wslc-daemon.exe"
if exist "sdk\node\bin\!SDK_ARCH!\wslcsdk.dll" del /Q "sdk\node\bin\!SDK_ARCH!\wslcsdk.dll"
)
)
)
:: Copy the C# SDK's native library (mxc_ffi) into its runtime assets so a
:: NuGet pack picks it up as runtimes/<rid>/native/mxc_ffi.dll.
if "%%T"=="x86_64-pc-windows-msvc" (set "RID=win-x64") else (set "RID=win-arm64")
if "!COPY_WSLC_RUNTIME!"=="1" if not "%WITH_WSLC%"=="1" (
if exist "sdk\dotnet\Microsoft.Mxc.Sdk\runtimes\!RID!\native\wxc-wslc-daemon.exe" del /Q "sdk\dotnet\Microsoft.Mxc.Sdk\runtimes\!RID!\native\wxc-wslc-daemon.exe"
if exist "sdk\dotnet\Microsoft.Mxc.Sdk\runtimes\!RID!\native\wslcsdk.dll" del /Q "sdk\dotnet\Microsoft.Mxc.Sdk\runtimes\!RID!\native\wslcsdk.dll"
)
if exist "!BIN_DIR!\mxc_ffi.dll" (
if not exist "sdk\dotnet\Microsoft.Mxc.Sdk\runtimes\!RID!\native" mkdir "sdk\dotnet\Microsoft.Mxc.Sdk\runtimes\!RID!\native"
copy /Y "!BIN_DIR!\mxc_ffi.dll" "sdk\dotnet\Microsoft.Mxc.Sdk\runtimes\!RID!\native\" >nul
echo Copied !RID!\native\mxc_ffi.dll
if exist "!BIN_DIR!\plm.exe" (
copy /Y "!BIN_DIR!\plm.exe" "sdk\dotnet\Microsoft.Mxc.Sdk\runtimes\!RID!\native\" >nul
echo Copied !RID!\native\plm.exe
)
if "%WITH_WSLC%"=="1" if "!COPY_WSLC_RUNTIME!"=="1" (
for %%B in (wxc-wslc-daemon.exe wslcsdk.dll) do (
if not exist "!BIN_DIR!\%%B" (
echo ERROR: WSLC-enabled C# runtime unit is missing !BIN_DIR!\%%B
exit /b 1
)
copy /Y "!BIN_DIR!\%%B" "sdk\dotnet\Microsoft.Mxc.Sdk\runtimes\!RID!\native\" >nul
echo Copied !RID!\native\%%B
)
)
if "!COPY_WSLC_RUNTIME!"=="1" (
>"sdk\dotnet\Microsoft.Mxc.Sdk\runtimes\!RID!\mxc-build-features.txt" echo isolation_session=%WITH_ISOLATION_SESSION%
>>"sdk\dotnet\Microsoft.Mxc.Sdk\runtimes\!RID!\mxc-build-features.txt" echo wslc=%WITH_WSLC%
)
)
)
:: Build the managed .NET SDK. Native runtime assets are staged above for
:: local execution and architecture-specific local packages. The governed
:: pipeline assembles the cross-platform package.
echo.
echo Building .NET SDK...
call dotnet restore sdk\dotnet\Microsoft.Mxc.Sdk\Microsoft.Mxc.Sdk.csproj --nologo || goto :error_root
call dotnet build sdk\dotnet\Microsoft.Mxc.Sdk\Microsoft.Mxc.Sdk.csproj --configuration !DOTNET_CONFIG! --no-restore --nologo !DOTNET_BUILD_PROPERTIES! || goto :error_root
echo.
echo Packaging architecture-specific Microsoft.Mxc.Sdk NuGet package...
if not exist "output\packages" mkdir "output\packages"
for /f "usebackq delims=" %%V in (`powershell -NoProfile -Command "[xml]$p = Get-Content 'sdk\dotnet\Microsoft.Mxc.Sdk\Microsoft.Mxc.Sdk.csproj'; $p.Project.PropertyGroup.Version"`) do set "DOTNET_PACKAGE_VERSION=%%V"
set "DOTNET_PACKAGE_TARGETS=%BUILD_ARCH%"
if "%BUILD_ALL%"=="1" set "DOTNET_PACKAGE_TARGETS=x86_64-pc-windows-msvc aarch64-pc-windows-msvc"
for %%T in (!DOTNET_PACKAGE_TARGETS!) do (
if "%%T"=="x86_64-pc-windows-msvc" (set "PACKAGE_RID=win-x64") else (set "PACKAGE_RID=win-arm64")
set "PACKAGE_NATIVE_DIR=%CD%\sdk\dotnet\Microsoft.Mxc.Sdk\runtimes\!PACKAGE_RID!\native"
call dotnet pack sdk\dotnet\Microsoft.Mxc.Sdk\Microsoft.Mxc.Sdk.csproj --configuration !DOTNET_CONFIG! --no-restore --no-build --output output\packages --nologo ^
-p:PackageVersion=!DOTNET_PACKAGE_VERSION!-local-!PACKAGE_RID! ^
-p:MxcPrebuiltNativeDir="!PACKAGE_NATIVE_DIR!" ^
-p:MxcPackageRid=!PACKAGE_RID! ^
-p:MxcPackSingleRid=true ^
!DOTNET_BUILD_PROPERTIES! || goto :error_root
echo Created output\packages\Microsoft.Mxc.Sdk.!DOTNET_PACKAGE_VERSION!-local-!PACKAGE_RID!.nupkg
)
:: Build npm packages
echo.
echo Building npm SDK package...
pushd sdk\node
call npm install & call npm run build
popd
echo.
echo Building SDK integration tests...
pushd sdk\node\tests\integration
:: npm caches `file:` deps by package.json version. The local SDK version
:: rarely bumps between builds, so a plain `npm install` keeps reusing the
:: stale packed copy. Force a refresh of the @microsoft/mxc-sdk link so
:: type-checking sees the dist we just rebuilt above.
if exist node_modules\@microsoft\mxc-sdk rmdir /s /q node_modules\@microsoft\mxc-sdk
call npm install & call npm run build
popd
echo.
echo Build complete.
:: Non-blocking prerequisite check for E2E tests.
:: We check whether the *first* python.exe in PATH is the user's App Execution
:: Alias reparse point at %LOCALAPPDATA%\Microsoft\WindowsApps\python.exe.
:: When that alias resolves first, sandbox containers cannot launch python.exe
:: (CreateProcessW returns 0x80070057).
echo.
echo === Checking E2E test prerequisites ===
set "PREREQ_WARN=0"
:: Check Python is available and first match is not the App Execution Alias
where python.exe >nul 2>&1
if errorlevel 1 (
echo WARNING: python.exe not found. E2E tests require a system-wide Python install.
set "PREREQ_WARN=1"
) else (
for /f "tokens=*" %%P in ('where python.exe') do (
if /i "%%P"=="%LOCALAPPDATA%\Microsoft\WindowsApps\python.exe" (
echo WARNING: python.exe first resolves to an App Execution Alias.
echo The alias reparse point cannot be launched inside sandbox containers.
set "PREREQ_WARN=1"
)
goto :python_check_done
)
)
:python_check_done
:: Check pwsh.exe exists at the expected path used by test configs
if not exist "C:\Program Files\PowerShell\7\pwsh.exe" (
echo WARNING: PowerShell 7 not found at C:\Program Files\PowerShell\7\pwsh.exe.
echo pwsh sandbox tests will fail.
set "PREREQ_WARN=1"
)
if "%PREREQ_WARN%"=="0" (
echo All E2E test prerequisites met.
) else (
echo.
echo To install Python and disable the alias, run from an elevated PowerShell prompt:
echo .\scripts\setup-test-prereqs.ps1
)
:done
exit /b 0
:error
popd
:error_root
echo.
echo Build failed.
exit /b 1
:usage
echo.
echo Usage: build.bat [options]
echo.
echo Options:
echo --debug Build debug configuration (default: release)
echo --release Build release configuration
echo --x64 Build for x64 only
echo --arm64 Build for ARM64 only
echo --all Build both Windows architectures and create the .NET NuGet package
echo --with-microvm Download and include NanVix micro-VM binaries
echo --with-wslc Build with WSL Container (WSLC SDK) support
echo --with-isolation-session Build with IsolationSession backend (IsoEnvBroker)
echo --with-hyperlight Build with Hyperlight (micro-VM) backend (x86_64 only)
echo -h, --help Show this help
echo.
echo Default: builds release for the current machine architecture.
exit /b 0