Repository navigation
Expand file tree
/
Copy pathBuild.bat
More file actions
407 lines (367 loc) · 13.5 KB
/
Copy pathBuild.bat
File metadata and controls
407 lines (367 loc) · 13.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
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
@echo off
setlocal EnableDelayedExpansion
pushd "%~dp0"
set "CONFIG=Release"
set "NO_PAUSE="
if not defined PLATFORM_TOOLSET set "PLATFORM_TOOLSET=v145"
:parse_args
if "%~1"=="" goto args_done
if /i "%~1"=="Debug" (
set "CONFIG=Debug"
shift
goto parse_args
)
if /i "%~1"=="Release" (
set "CONFIG=Release"
shift
goto parse_args
)
if /i "%~1"=="--no-pause" (
set "NO_PAUSE=1"
shift
goto parse_args
)
if /i "%~1"=="--toolset" goto parse_toolset
echo [Error] Unknown argument: %~1
echo Usage: Build.bat [Debug^|Release] [--toolset v145] [--no-pause]
goto fail
:parse_toolset
shift
if "%~1"=="" (
echo [Error] --toolset requires a value, e.g. v145 / v143
goto fail
)
set "TOOLSET_VALUE=%~1"
if /i "%TOOLSET_VALUE:~0,1%" NEQ "v" (
echo [Error] Invalid platform toolset: %TOOLSET_VALUE%
echo [Error] Expected a value such as v145 or v143.
goto fail
)
for /f "delims=0123456789" %%C in ("%TOOLSET_VALUE:~1%") do (
echo [Error] Invalid platform toolset: %TOOLSET_VALUE%
echo [Error] Expected a value such as v145 or v143.
goto fail
)
if "%TOOLSET_VALUE:~1%"=="" (
echo [Error] Invalid platform toolset: %TOOLSET_VALUE%
goto fail
)
set "PLATFORM_TOOLSET=%TOOLSET_VALUE%"
shift
goto parse_args
:args_done
if not defined PLATFORM_TOOLSET (
echo [Error] PlatformToolset is empty.
goto fail
)
echo ==========================================
echo XBase Builder
echo ==========================================
echo Configuration: %CONFIG%
echo Platform: Win32
echo PlatformToolset: %PLATFORM_TOOLSET%
echo.
call :find_premake
if not defined PREMAKE_EXE (
echo [Error] premake5 executable not found.
goto fail
)
call :detect_plugin_sdk
if not defined PLUGIN_SDK_DIR (
echo [Error] PLUGIN_SDK_DIR is required for all XBase targets.
goto fail
)
call :find_msbuild
if not defined MSBUILD_EXE (
echo [Error] MSBuild.exe not found.
goto fail
)
call :build_plugin_sdk
if errorlevel 1 goto fail
if not exist "build" mkdir "build"
echo Removing stale generated project files...
del /Q "build\*.sln" "build\*.vcxproj" "build\*.vcxproj.filters" "build\*.vcxproj.user" >nul 2>nul
echo Generating Visual Studio 2022 project files...
"!PREMAKE_EXE!" vs2022
if errorlevel 1 (
echo [Error] Project generation failed.
goto fail
)
if not exist "build\XBase.sln" (
echo [Error] build\XBase.sln not found.
goto fail
)
for %%T in (XBaseBootstrap XBasePayloadEntry XBaseRuntimeEntry XBaseModEntry XBaseSA XBaseVC XBaseIII) do (
if not exist "build\%%T.vcxproj" (
echo [Error] build\%%T.vcxproj was not generated.
goto fail
)
)
call :find_msbuild
if not defined MSBUILD_EXE (
echo [Error] MSBuild.exe not found.
goto fail
)
echo.
echo Using premake: !PREMAKE_EXE!
echo Using MSBuild: !MSBUILD_EXE!
"!MSBUILD_EXE!" "build\XBase.sln" /m /t:XBaseBootstrap /p:Configuration=%CONFIG% /p:Platform=Win32 /p:PlatformToolset=%PLATFORM_TOOLSET% /verbosity:minimal
if errorlevel 1 (
echo.
echo [Error] XBaseBootstrap build failed.
goto fail
)
"!MSBUILD_EXE!" "build\XBase.sln" /m /t:XBasePayloadEntry /p:Configuration=%CONFIG% /p:Platform=Win32 /p:PlatformToolset=%PLATFORM_TOOLSET% /verbosity:minimal
if errorlevel 1 (
echo.
echo [Error] XBasePayloadEntry build failed.
goto fail
)
"!MSBUILD_EXE!" "build\XBase.sln" /m /t:XBaseRuntimeEntry /p:Configuration=%CONFIG% /p:Platform=Win32 /p:PlatformToolset=%PLATFORM_TOOLSET% /verbosity:minimal
if errorlevel 1 (
echo.
echo [Error] XBaseRuntimeEntry build failed.
goto fail
)
"!MSBUILD_EXE!" "build\XBase.sln" /m /t:XBaseModEntry /p:Configuration=%CONFIG% /p:Platform=Win32 /p:PlatformToolset=%PLATFORM_TOOLSET% /verbosity:minimal
if errorlevel 1 (
echo.
echo [Error] XBaseModEntry build failed.
goto fail
)
"!MSBUILD_EXE!" "build\XBase.sln" /m /t:XBaseSA /p:Configuration=%CONFIG% /p:Platform=Win32 /p:PlatformToolset=%PLATFORM_TOOLSET% /verbosity:minimal
if errorlevel 1 (
echo.
echo [Error] XBaseSA build failed.
goto fail
)
"!MSBUILD_EXE!" "build\XBase.sln" /m /t:XBaseVC /p:Configuration=%CONFIG% /p:Platform=Win32 /p:PlatformToolset=%PLATFORM_TOOLSET% /verbosity:minimal
if errorlevel 1 (
echo.
echo [Error] XBaseVC build failed.
goto fail
)
"!MSBUILD_EXE!" "build\XBase.sln" /m /t:XBaseIII /p:Configuration=%CONFIG% /p:Platform=Win32 /p:PlatformToolset=%PLATFORM_TOOLSET% /verbosity:minimal
if errorlevel 1 (
echo.
echo [Error] XBaseIII build failed.
goto fail
)
for %%T in (XBaseBootstrap XBasePayloadEntry XBaseRuntimeEntry XBaseModEntry XBaseSA XBaseVC XBaseIII) do (
if not exist "build\bin\%CONFIG%\%%T.lib" (
echo [Error] build\bin\%CONFIG%\%%T.lib was not produced.
goto fail
)
)
if /i "%CONFIG%"=="Release" (
rem 共享运行时只出 Release:plugin-sdk 的 output/lib 只有 Release 库,
rem Debug 链接会因运行库与迭代器调试级别不匹配而失败
"!MSBUILD_EXE!" "build\XBase.sln" /m /t:XBaseRuntimeSA /p:Configuration=%CONFIG% /p:Platform=Win32 /p:PlatformToolset=%PLATFORM_TOOLSET% /verbosity:minimal
if errorlevel 1 (
echo.
echo [Error] XBaseRuntimeSA build failed.
goto fail
)
"!MSBUILD_EXE!" "build\XBase.sln" /m /t:XBaseRuntimeVC /p:Configuration=%CONFIG% /p:Platform=Win32 /p:PlatformToolset=%PLATFORM_TOOLSET% /verbosity:minimal
if errorlevel 1 (
echo.
echo [Error] XBaseRuntimeVC build failed.
goto fail
)
"!MSBUILD_EXE!" "build\XBase.sln" /m /t:XBaseRuntimeIII /p:Configuration=%CONFIG% /p:Platform=Win32 /p:PlatformToolset=%PLATFORM_TOOLSET% /verbosity:minimal
if errorlevel 1 (
echo.
echo [Error] XBaseRuntimeIII build failed.
goto fail
)
for %%T in (XBaseSA XBaseVC XBaseIII) do (
if not exist "build\bin\%CONFIG%\XBase\Library\%%T.dll" (
echo [Error] build\bin\%CONFIG%\XBase\Library\%%T.dll was not produced.
goto fail
)
)
call :stage_sdk "..\XMenu"
call :stage_sdk "..\III.VC.SA.WebView2"
rem example 是 XBase 自己的子目录,不是兄弟工程,路径不带上级
call :stage_sdk "example"
call :stage_panel
)
rem 查看器与 SDK 一起构建,产物落在 viewer\build\bin\XBase.exe
call :build_viewer "%CONFIG%"
echo.
echo Build completed successfully.
echo Outputs: XBaseBootstrap.lib, XBasePayloadEntry.lib, XBaseSA.lib, XBaseVC.lib, XBaseIII.lib
echo XBaseRuntimeEntry.lib, XBaseModEntry.lib
echo XBase\Library\XBaseSA.dll, XBaseVC.dll, XBaseIII.dll
goto success
rem ============================================================
rem 构建 XBase 日志与配置查看器
rem ============================================================
:build_viewer
if not exist "viewer\Build.bat" (
echo [Warning] viewer\Build.bat not found; viewer was not built.
exit /b 0
)
if not exist "viewer\src\main.cpp" (
echo [Warning] viewer\src\main.cpp not found; viewer was not built.
exit /b 0
)
echo Building XBase viewer...
call "viewer\Build.bat" "%~1" --no-pause
if errorlevel 1 (
echo [Warning] XBase viewer build failed; continuing without it.
exit /b 0
)
if exist "viewer\build\bin\XBase.exe" (
echo [Info] XBase viewer built: viewer\build\bin\XBase.exe
) else (
echo [Warning] XBase viewer executable was not produced.
)
exit /b 0
rem ============================================================
rem Stage the Release SDK for every sibling host that consumes it.
rem ============================================================
:stage_sdk
set "SDK_TARGET=%~1"
if not exist "%SDK_TARGET%\" exit /b 0
if not exist "%SDK_TARGET%\include\XBase" mkdir "%SDK_TARGET%\include\XBase"
if not exist "%SDK_TARGET%\lib" mkdir "%SDK_TARGET%\lib"
xcopy "include\XBase\*.h" "%SDK_TARGET%\include\XBase\" /Y /Q >nul
if errorlevel 1 (
echo [Error] Failed to stage XBase public headers into %SDK_TARGET%.
exit /b 1
)
for %%T in (XBaseBootstrap XBasePayloadEntry XBaseRuntimeEntry XBaseModEntry XBaseSA XBaseVC XBaseIII) do (
copy /Y "build\bin\%CONFIG%\%%T.lib" "%SDK_TARGET%\lib\%%T.lib" >nul
if errorlevel 1 (
echo [Error] Failed to stage %%T.lib into %SDK_TARGET%.
exit /b 1
)
)
for %%P in (Plugin Plugin_VC Plugin_III) do (
set "P_STAGE_NAME=%%P"
set "P_SOURCE=%%P"
if /i "%%P"=="Plugin" set "P_STAGE_NAME=PluginSA"
if /i "%%P"=="Plugin_VC" set "P_STAGE_NAME=PluginVC"
if /i "%%P"=="Plugin_III" set "P_STAGE_NAME=PluginIII"
if not exist "%PLUGIN_SDK_DIR%\output\lib\!P_SOURCE!.lib" (
echo [Error] Missing plugin-sdk game symbol library: !P_SOURCE!.lib
exit /b 1
)
copy /Y "%PLUGIN_SDK_DIR%\output\lib\!P_SOURCE!.lib" "%SDK_TARGET%\lib\!P_STAGE_NAME!.lib" >nul
if errorlevel 1 (
echo [Error] Failed to stage !P_STAGE_NAME!.lib into %SDK_TARGET%.
exit /b 1
)
)
if exist "include\webview2\x86\WebView2Loader.dll" (
copy /Y "include\webview2\x86\WebView2Loader.dll" "%SDK_TARGET%\lib\WebView2Loader.dll" >nul
if errorlevel 1 (
echo [Error] Failed to stage WebView2Loader.dll into %SDK_TARGET%.
exit /b 1
)
) else (
echo [Warning] include\webview2\x86\WebView2Loader.dll not found; WebView feature will be unavailable.
)
echo [Info] Staged Release SDK to %SDK_TARGET%\include\XBase and %SDK_TARGET%\lib
exit /b 0
rem ============================================================
rem Stage the built React panel into the runtime library folder.
rem The panel ships with XBase, mods only mount into it.
rem ============================================================
:stage_panel
set "PANEL_DIST=%~dp0panel\dist"
if not exist "%PANEL_DIST%\index.html" (
echo [Warning] panel\dist\index.html not found; run "npm install" and "npm run build" inside panel first.
exit /b 0
)
if not exist "build\bin\%CONFIG%\XBase\Library\panel" mkdir "build\bin\%CONFIG%\XBase\Library\panel"
xcopy "%PANEL_DIST%\*" "build\bin\%CONFIG%\XBase\Library\panel\" /Y /Q /E >nul
if errorlevel 1 (
echo [Error] Failed to stage the React panel.
exit /b 1
)
echo [Info] Staged React panel to build\bin\%CONFIG%\XBase\Library\panel
exit /b 0
:find_premake
set "PREMAKE_EXE="
if exist "tools\premake5.exe" set "PREMAKE_EXE=%~dp0tools\premake5.exe" & goto :eof
if exist "..\XMenu\tools\premake5.exe" set "PREMAKE_EXE=%~dp0..\XMenu\tools\premake5.exe" & goto :eof
for /f "tokens=*" %%i in ('where premake5.exe 2^>nul') do if not defined PREMAKE_EXE set "PREMAKE_EXE=%%i"
if not defined PREMAKE_EXE (
for /f "tokens=*" %%i in ('where premake5 2^>nul') do if not defined PREMAKE_EXE set "PREMAKE_EXE=%%i"
)
exit /b 0
:detect_plugin_sdk
if "%PLUGIN_SDK_DIR%"=="" (
if exist "..\plugin-sdk\" (
set "PLUGIN_SDK_DIR=%~dp0..\plugin-sdk"
echo [Info] Auto-detected PLUGIN_SDK_DIR=!PLUGIN_SDK_DIR!
) else if exist "..\..\plugin-sdk\" (
set "PLUGIN_SDK_DIR=%~dp0..\..\plugin-sdk"
echo [Info] Auto-detected PLUGIN_SDK_DIR=!PLUGIN_SDK_DIR!
) else (
echo [Error] plugin-sdk not found. Three-version backends require PLUGIN_SDK_DIR.
)
)
if not "%PLUGIN_SDK_DIR%"=="" (
if exist "%PLUGIN_SDK_DIR%" (
echo [Info] Using plugin-sdk directory: %PLUGIN_SDK_DIR%
) else (
echo [Warning] Ignoring invalid PLUGIN_SDK_DIR: %PLUGIN_SDK_DIR%
set "PLUGIN_SDK_DIR="
echo [Error] Three-version backends cannot be generated without plugin-sdk.
)
)
exit /b 0
:build_plugin_sdk
rem XBase links plugin-sdk game symbols; build missing static libs before premake.
set "PSDK_LIB_DIR=!PLUGIN_SDK_DIR!\output\lib"
set "PSDK_NEED_BUILD="
if not exist "!PSDK_LIB_DIR!\Plugin.lib" set "PSDK_NEED_BUILD=1"
if not exist "!PSDK_LIB_DIR!\Plugin_VC.lib" set "PSDK_NEED_BUILD=1"
if not exist "!PSDK_LIB_DIR!\Plugin_III.lib" set "PSDK_NEED_BUILD=1"
if not defined PSDK_NEED_BUILD exit /b 0
echo Building plugin-sdk game symbol libraries...
if not exist "!PSDK_LIB_DIR!" mkdir "!PSDK_LIB_DIR!"
for %%P in ("plugin_sa\Plugin_SA" "plugin_vc\Plugin_VC" "plugin_III\Plugin_III") do (
echo Building %%~P...
"!MSBUILD_EXE!" "!PLUGIN_SDK_DIR!\%%~P.vcxproj" /m /p:Configuration=Release /p:Platform=Win32 /p:PlatformToolset=!PLATFORM_TOOLSET! /p:PLUGIN_SDK_DIR=!PLUGIN_SDK_DIR! /verbosity:minimal
if errorlevel 1 (
echo [Error] plugin-sdk build failed: %%~P
exit /b 1
)
)
exit /b 0
:find_msbuild
if defined MSBUILD_EXE if exist "!MSBUILD_EXE!" exit /b 0
set "MSBUILD_EXE="
if defined VSINSTALLDIR if exist "%VSINSTALLDIR%MSBuild\Current\Bin\MSBuild.exe" set "MSBUILD_EXE=%VSINSTALLDIR%MSBuild\Current\Bin\MSBuild.exe"
if not defined MSBUILD_EXE (
set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
if exist "!VSWHERE!" (
for /f "usebackq tokens=*" %%i in (`"!VSWHERE!" -latest -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe`) do (
if not defined MSBUILD_EXE set "MSBUILD_EXE=%%i"
)
)
)
if not defined MSBUILD_EXE (
for %%i in (
"%ProgramFiles%\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe"
"%ProgramFiles%\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe"
"%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe"
"%ProgramFiles(x86)%\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe"
) do if exist %%~si if not defined MSBUILD_EXE set "MSBUILD_EXE=%%~si"
)
if not defined MSBUILD_EXE (
for /f "tokens=*" %%i in ('where MSBuild.exe 2^>nul') do if not defined MSBUILD_EXE set "MSBUILD_EXE=%%i"
)
exit /b 0
:success
popd
if not defined NO_PAUSE pause
exit /b 0
:fail
popd
if not defined NO_PAUSE pause
exit /b 1