Files
systeminformer/build/build_compile_commands.cmd
dmex c107a17d0d Improve clang-lld and build tooling
Add clang-lld CMake toolchains for x86/x64/ARM64 and update the shared CMake/MSVC logic to handle lld-link limitations, optional clang speculative load hardening, host-architecture tool selection, and user-mode defines that match Common.User.props.

Refresh the Windows build scripts to use the newer MSBuild invocation flags, support CI/binlog/low-priority options, allow build target overrides, switch CustomBuildTool publishing to dotnet msbuild, reorder init so tools build before third-party deps, and let build_zsign sign a single file or an entire output tree.
2026-09-24 14:32:21 +10:00

165 lines
7.1 KiB
Batchfile

@echo off
setlocal enabledelayedexpansion
cd /d "%~dp0\.."
REM -----------------------------------------------------------------------------
REM Script: build_compile_commands.cmd
REM Description: Publishes the compile-commands logger and rebuilds solutions with it.
REM -----------------------------------------------------------------------------
REM Initialize script state, tool discovery values, and output locations.
set "ExitCode=0"
set "IsCI=false"
set "TLG=auto"
set "VSINSTALLPATH="
set "VCVARS_ARCH=amd64"
set "PublishProfile="
set "CompileCommandsLogger="
set "BuildPlatform=x64"
set "MSBUILD_EXTRA_ARGS=-restore -p:RestoreUseStaticGraphEvaluation=true -p:ContinueOnError=False -p:CopyRetryCount=10 -p:CopyRetryDelayMilliseconds=500"
REM Run the main script flow and capture the final exit code.
call :DetectCi
call :ConfigureTerminalLogger
call :ConfigureMsBuildOptions
call :Main
if errorlevel 1 set "ExitCode=%errorlevel%"
:end
REM Pause only for interactive, non-CI invocations before returning.
if /i "%IsCI%"=="false" call :PauseIfInteractive
endlocal & exit /b %ExitCode%
REM -----------------------------------------------------------------------------
REM Function: Main
REM Description: Sets up the toolchain, publishes the logger, and rebuilds solutions.
REM -----------------------------------------------------------------------------
:Main
call :FindVisualStudio
if errorlevel 1 exit /b %errorlevel%
if /i "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
set "VCVARS_ARCH=arm64"
set "PublishProfile=Properties\PublishProfiles\arm64.pubxml"
set "CompileCommandsLogger=tools\CompileCommandsJson\bin\Release\arm64\CompileCommandsJson.dll"
set "BuildPlatform=ARM64"
) else (
set "PublishProfile=Properties\PublishProfiles\amd64.pubxml"
set "CompileCommandsLogger=tools\CompileCommandsJson\bin\Release\amd64\CompileCommandsJson.dll"
)
call :SetupVcVars "%VCVARS_ARCH%"
if errorlevel 1 exit /b %errorlevel%
call :RunDotnetPublish "%PublishProfile%" "%BuildPlatform%"
if errorlevel 1 exit /b %errorlevel%
if not exist "%CompileCommandsLogger%" (
echo CompileCommandsJson.dll not found.
exit /b 1
)
call :RunMsBuild "KSystemInformer\KSystemInformer.sln" "%BuildPlatform%"
if errorlevel 1 exit /b %errorlevel%
call :RunMsBuild "SystemInformer.sln" "%BuildPlatform%"
if errorlevel 1 exit /b %errorlevel%
call :RunMsBuild "Plugins\Plugins.sln" "%BuildPlatform%"
if errorlevel 1 exit /b %errorlevel%
exit /b 0
REM -----------------------------------------------------------------------------
REM Function: RunDotnetPublish
REM Description: Publishes the CompileCommandsJson project for the active architecture.
REM Parameters:
REM %~1 - Publish profile path.
REM %~2 - MSBuild Platform (x64, ARM64). Required under .NET SDK 10+ where the
REM pubxml's <Platform> no longer propagates through solution-level publish.
REM -----------------------------------------------------------------------------
:RunDotnetPublish
dotnet publish -mt -p:UseClStructuredOutput=false tools\CompileCommandsJson\CompileCommandsJson.sln -c Release /p:Platform=%~2 /p:PublishProfile=%~1
exit /b %errorlevel%
REM -----------------------------------------------------------------------------
REM Function: RunMsBuild
REM Description: Rebuilds a solution while emitting compile_commands.json data.
REM Parameters:
REM %~1 - Solution path.
REM %~2 - Platform name.
REM -----------------------------------------------------------------------------
:RunMsBuild
echo:
msbuild -mt -p:UseClStructuredOutput=false -t:rebuild -p:Configuration=Debug;Platform=%~2 -p:ContinuousIntegrationBuild=%IsCI% %MSBUILD_EXTRA_ARGS% -logger:%CompileCommandsLogger% -terminalLogger:%TLG% /m /graph %~1
exit /b %errorlevel%
REM -----------------------------------------------------------------------------
REM Function: FindVisualStudio
REM Description: Locates a Visual Studio or SDK installation with MSBuild.
REM -----------------------------------------------------------------------------
:FindVisualStudio
set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
if not exist "%VSWHERE%" set "VSWHERE=%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe"
if exist "%VSWHERE%" (
for /f "usebackq tokens=*" %%a in (`call "%VSWHERE%" -latest -prerelease -products * -requires Microsoft.Component.MSBuild -property installationPath`) do (
set "VSINSTALLPATH=%%a"
)
)
if not defined VSINSTALLPATH if defined VSINSTALLDIR set "VSINSTALLPATH=%VSINSTALLDIR%"
if not defined VSINSTALLPATH if defined VCINSTALLDIR for %%I in ("%VCINSTALLDIR%\..\..") do set "VSINSTALLPATH=%%~fI"
if not defined VSINSTALLPATH if defined WindowsSdkDir set "VSINSTALLPATH=%WindowsSdkDir%"
if defined VSINSTALLPATH exit /b 0
echo No Visual Studio installation detected.
exit /b 1
REM -----------------------------------------------------------------------------
REM Function: SetupVcVars
REM Description: Initializes the Visual C++ build environment for the requested arch.
REM Parameters:
REM %~1 - vcvarsall architecture argument.
REM -----------------------------------------------------------------------------
:SetupVcVars
if /i "%EnterpriseWDK%"=="true" (
REM EWDK has already configured INCLUDE/LIB/PATH via LaunchBuildEnv.cmd.
exit /b 0
)
if exist "%VSINSTALLPATH%\VC\Auxiliary\Build\vcvarsall.bat" (
call "%VSINSTALLPATH%\VC\Auxiliary\Build\vcvarsall.bat" %~1
exit /b !errorlevel!
)
echo vcvarsall.bat not found under %VSINSTALLPATH%.
exit /b 1
REM -----------------------------------------------------------------------------
REM Function: DetectCi
REM Description: Detects whether the script is running under CI.
REM -----------------------------------------------------------------------------
:DetectCi
if /i "%GITHUB_ACTIONS%"=="true" set "IsCI=true"
if /i "%TF_BUILD%"=="true" set "IsCI=true"
exit /b 0
REM -----------------------------------------------------------------------------
REM Function: ConfigureTerminalLogger
REM Description: Disables the terminal logger when running under CI.
REM -----------------------------------------------------------------------------
:ConfigureTerminalLogger
if /i "%IsCI%"=="true" set "TLG=off"
exit /b 0
:ConfigureMsBuildOptions
set "MSBUILD_EXTRA_ARGS=-restore -p:RestoreUseStaticGraphEvaluation=true -p:ContinueOnError=False -p:CopyRetryCount=10 -p:CopyRetryDelayMilliseconds=500"
if /i "%IsCI%"=="true" set "MSBUILD_EXTRA_ARGS=%MSBUILD_EXTRA_ARGS% -p:ContinuousIntegrationBuild=true"
if /i "%SI_MSBUILD_LOW_PRIORITY%"=="true" if /i "%IsCI%"=="false" set "MSBUILD_EXTRA_ARGS=%MSBUILD_EXTRA_ARGS% -lowPriority"
if defined SI_MSBUILD_BINLOG set "MSBUILD_EXTRA_ARGS=%MSBUILD_EXTRA_ARGS% /bl:%SI_MSBUILD_BINLOG%"
exit /b 0
REM -----------------------------------------------------------------------------
REM Function: PauseIfInteractive
REM Description: Pauses only when stdin is attached to an interactive console.
REM -----------------------------------------------------------------------------
:PauseIfInteractive
set "STDIN_REDIRECTED=False"
for /f %%i in ('powershell -NoProfile -Command "[Console]::IsInputRedirected"') do set "STDIN_REDIRECTED=%%i"
if /i not "%STDIN_REDIRECTED%"=="True" pause
exit /b 0