-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathbuild.bat
More file actions
249 lines (229 loc) · 9.75 KB
/
Copy pathbuild.bat
File metadata and controls
249 lines (229 loc) · 9.75 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
@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%"
:: 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")
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 "%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 "%WITH_WSLC%"=="1" (
if exist "!BIN_DIR!\wslcsdk.dll" (
copy /Y "!BIN_DIR!\wslcsdk.dll" "sdk\node\bin\!SDK_ARCH!\" >nul
echo Copied !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 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
)
)
:: 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
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 for both x64 and ARM64
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