Skip to content

Commit 6118c5a

Browse files
authored
MrBot do not stop for x86 agents (#57)
1. Simplified Template Interface (devops.yml, official.yml) - Template now only requires arch parameter instead of 5 parameters (arch, cmakeArch, vcvarsArg, platform, msbuildPath) - Architecture-specific logic moved inside the template where it belongs - Reduced duplication and potential for misconfiguration 2. Dynamic Tool Discovery (build-arch.yml) - Uses vswhere to find Visual Studio installation dynamically instead of hardcoded paths - Discovers CMake, CTest, and MSBuild paths at runtime - Works across different VS versions/installations without manual path updates 3. Architecture Mapping Centralized - Single switch statement maps arch → cmakeArch, targetPlatform, msbuildHost - MSBuild host architecture correctly set: amd64 for x64/x86 builds, arm64 for ARM64 builds 4. Removed vcvarsall Dependency - No longer relies on vcvarsall.bat to set PATH - Eliminates SysNative workarounds for ARM64 (x86 agent emulation issues) - Tools invoked via full paths discovered at runtime 5. Better ARM64 Support - Verification step reports agent architecture (but doesn't block on mismatch) - Uses native ARM64 MSBuild on ARM64 pools
1 parent 9c446df commit 6118c5a

4 files changed

Lines changed: 79 additions & 64 deletions

File tree

build/devops.yml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,11 @@ parameters:
88
type: object
99
default:
1010
- name: 'x64'
11-
cmakeArch: 'x64'
12-
vcvarsArg: 'amd64'
13-
platform: 'x64'
1411
pool: 'Azure-MessagingStore-WinBuildPoolVS2022_0'
15-
msbuildPath: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\MSBuild.exe'
1612
- name: 'x86'
17-
cmakeArch: 'Win32'
18-
vcvarsArg: 'amd64_x86'
19-
platform: 'Win32'
2013
pool: 'Azure-MessagingStore-WinBuildPoolVS2022_0'
21-
msbuildPath: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\MSBuild.exe'
2214
- name: 'arm64'
23-
cmakeArch: 'ARM64'
24-
vcvarsArg: 'arm64'
25-
platform: 'ARM64'
2615
pool: 'Azure-MessagingStore-WinBuildPoolARM'
27-
msbuildPath: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\arm64\MSBuild.exe'
2816
- name: configurations
2917
type: object
3018
default:
@@ -48,10 +36,6 @@ jobs:
4836
- template: templates/build-arch.yml
4937
parameters:
5038
arch: ${{ arch.name }}
51-
cmakeArch: ${{ arch.cmakeArch }}
52-
vcvarsArg: ${{ arch.vcvarsArg }}
53-
platform: ${{ arch.platform }}
54-
msbuildPath: ${{ arch.msbuildPath }}
5539
configuration: ${{ config }}
5640
runTests: true
5741
artifactSuffix: '-${{ config }}'

build/official.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ jobs:
9696
- template: templates/build-arch.yml
9797
parameters:
9898
arch: 'x64'
99-
cmakeArch: 'x64'
100-
vcvarsArg: 'amd64'
101-
platform: 'x64'
102-
msbuildPath: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\MSBuild.exe'
10399

104100
- job: Build_x86
105101
displayName: 'Build x86'
@@ -116,10 +112,6 @@ jobs:
116112
- template: templates/build-arch.yml
117113
parameters:
118114
arch: 'x86'
119-
cmakeArch: 'Win32'
120-
vcvarsArg: 'amd64_x86'
121-
platform: 'Win32'
122-
msbuildPath: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\MSBuild.exe'
123115

124116
- job: Build_arm64
125117
displayName: 'Build ARM64'
@@ -136,10 +128,6 @@ jobs:
136128
- template: templates/build-arch.yml
137129
parameters:
138130
arch: 'arm64'
139-
cmakeArch: 'ARM64'
140-
vcvarsArg: 'arm64'
141-
platform: 'ARM64'
142-
msbuildPath: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\arm64\MSBuild.exe'
143131

144132
- job: CreateInstaller
145133
displayName: 'Build Installer'

build/templates/build-arch.yml

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@ parameters:
55
- name: arch
66
type: string
77
values: ['x64', 'x86', 'arm64']
8-
- name: cmakeArch
9-
type: string
10-
values: ['x64', 'Win32', 'ARM64']
11-
- name: vcvarsArg
12-
type: string
13-
- name: platform
14-
type: string
15-
- name: msbuildPath
16-
type: string
178
- name: configuration
189
type: string
1910
default: 'RelWithDebInfo'
@@ -29,32 +20,79 @@ steps:
2920
- ${{ if eq(parameters.arch, 'arm64') }}:
3021
- template: verify-arm64-agent.yml
3122

32-
# Setup VC++ environment for both CMake (compiler detection) and MSBuild
33-
- task: BatchScript@1
34-
displayName: 'Setup VC++ Environment (${{ parameters.vcvarsArg }})'
23+
# Discover Visual Studio and setup build variables
24+
- task: PowerShell@2
25+
displayName: 'Discover Visual Studio (${{ parameters.arch }})'
3526
inputs:
36-
filename: '"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat"'
37-
arguments: '${{ parameters.vcvarsArg }}'
38-
modifyEnvironment: true
27+
targetType: 'inline'
28+
script: |
29+
# Map arch to cmakeArch, targetPlatform, and msbuild host folder
30+
$arch = "${{ parameters.arch }}"
31+
switch ($arch) {
32+
'x64' { $cmakeArch = 'x64'; $targetPlatform = 'x64'; $msbuildHost = 'amd64' }
33+
'x86' { $cmakeArch = 'Win32'; $targetPlatform = 'Win32'; $msbuildHost = 'amd64' }
34+
'arm64' { $cmakeArch = 'ARM64'; $targetPlatform = 'ARM64'; $msbuildHost = 'arm64' }
35+
}
36+
Write-Host "##vso[task.setvariable variable=cmakeArch]$cmakeArch"
37+
Write-Host "##vso[task.setvariable variable=targetPlatform]$targetPlatform"
38+
39+
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
40+
if (-not (Test-Path $vswhere)) {
41+
Write-Host "##[error]vswhere.exe not found at $vswhere"
42+
exit 1
43+
}
44+
45+
$vsPath = & $vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
46+
if (-not $vsPath) {
47+
Write-Host "##[error]Could not find Visual Studio installation"
48+
exit 1
49+
}
50+
Write-Host "Found Visual Studio at: $vsPath"
51+
52+
# Find CMake bundled with Visual Studio
53+
$cmakeBinDir = Join-Path $vsPath "Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin"
54+
$cmakePath = Join-Path $cmakeBinDir "cmake.exe"
55+
$ctestPath = Join-Path $cmakeBinDir "ctest.exe"
56+
if (-not (Test-Path $cmakePath)) {
57+
Write-Host "##[error]CMake not found at $cmakePath"
58+
exit 1
59+
}
60+
Write-Host "Using CMake: $cmakePath"
61+
Write-Host "Using CTest: $ctestPath"
62+
Write-Host "##vso[task.setvariable variable=cmakePath]$cmakePath"
63+
Write-Host "##vso[task.setvariable variable=ctestPath]$ctestPath"
64+
65+
# Find MSBuild for the correct host architecture
66+
$msbuildPath = Join-Path $vsPath "MSBuild\Current\Bin\$msbuildHost\MSBuild.exe"
67+
if (-not (Test-Path $msbuildPath)) {
68+
$msbuildPath = Join-Path $vsPath "MSBuild\Current\Bin\MSBuild.exe"
69+
}
70+
if (-not (Test-Path $msbuildPath)) {
71+
Write-Host "##[error]MSBuild not found"
72+
exit 1
73+
}
74+
Write-Host "Using MSBuild: $msbuildPath"
75+
Write-Host "##vso[task.setvariable variable=msbuildPath]$msbuildPath"
3976
40-
- task: CMake@1
41-
displayName: 'CMake configure -A ${{ parameters.cmakeArch }}'
77+
- task: CmdLine@2
78+
displayName: 'CMake configure'
4279
inputs:
43-
workingDirectory: 'build_${{ parameters.arch }}'
44-
cmakeArgs: '.. -DVLD_USE_MFC=OFF -A ${{ parameters.cmakeArch }}'
80+
script: |
81+
mkdir build_${{ parameters.arch }} 2>nul
82+
cd build_${{ parameters.arch }}
83+
"$(cmakePath)" .. -DVLD_USE_MFC=OFF -A $(cmakeArch)
4584
46-
# Build solution using MSBuild directly
4785
- task: CmdLine@2
4886
displayName: 'Build ${{ parameters.configuration }}'
4987
inputs:
50-
script: '"${{ parameters.msbuildPath }}" "build_${{ parameters.arch }}\VLD.sln" /t:restore /t:build /p:Platform=${{ parameters.platform }} /p:Configuration=${{ parameters.configuration }} /m'
88+
script: '"$(msbuildPath)" "build_${{ parameters.arch }}\VLD.sln" /t:restore /t:build /p:Platform=$(targetPlatform) /p:Configuration=${{ parameters.configuration }} /m'
5189

5290
# Optional: Run tests
5391
- ${{ if parameters.runTests }}:
5492
- task: CmdLine@2
5593
displayName: 'Run ctest ${{ parameters.configuration }}'
5694
inputs:
57-
script: 'ctest -C "${{ parameters.configuration }}" --output-on-failure'
95+
script: '"$(ctestPath)" -C "${{ parameters.configuration }}" --output-on-failure'
5896
workingDirectory: 'build_${{ parameters.arch }}'
5997

6098
- task: PublishPipelineArtifact@1

build/templates/verify-arm64-agent.yml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Template: Verify ARM64 Agent Architecture
2-
# Ensures the 1ES provisioning script has patched the agent to ARM64.
3-
# See build/docs/ARM64-AGENT-PATCHING.md for details.
2+
# Checks and reports the agent architecture (may be running under x86 emulation).
43

54
steps:
65
- task: PowerShell@2
@@ -15,6 +14,7 @@ steps:
1514
# Check process architecture
1615
$procArch = [System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture
1716
Write-Host "Process Architecture: $procArch"
17+
Write-Host "Process ID (PID): $PID"
1818
Write-Host "PROCESSOR_ARCHITECTURE: $env:PROCESSOR_ARCHITECTURE"
1919
2020
# Check Agent.Worker.exe PE header
@@ -33,23 +33,28 @@ steps:
3333
default { "Unknown (0x$($machine.ToString('X4')))" }
3434
}
3535
Write-Host "Agent.Worker.exe Architecture: $archName"
36+
Write-Host "Agent.Worker.exe Path: $workerExe"
3637
3738
if ($archName -ne "ARM64") {
3839
Write-Host ""
39-
Write-Host "##[error]ARM64 agent verification FAILED!"
40-
Write-Host "##[error]Expected ARM64 agent but found $archName agent."
40+
Write-Host "##[warning]============================================================"
41+
Write-Host "##[warning]ARM64 AGENT ARCHITECTURE MISMATCH"
42+
Write-Host "##[warning]============================================================"
43+
Write-Host "##[warning]"
44+
Write-Host "##[warning]Detection results:"
45+
Write-Host "##[warning] Process Architecture: $procArch"
46+
Write-Host "##[warning] Process ID (PID): $PID"
47+
Write-Host "##[warning] PROCESSOR_ARCHITECTURE: $env:PROCESSOR_ARCHITECTURE"
48+
Write-Host "##[warning] Agent.Worker.exe: $archName"
49+
Write-Host "##[warning]"
50+
Write-Host "##[warning]Expected ARM64 agent but found $archName agent."
51+
Write-Host "##[warning]"
52+
Write-Host "##[warning]Continuing build despite architecture mismatch..."
53+
Write-Host "##[warning]============================================================"
54+
} else {
4155
Write-Host ""
42-
Write-Host "The 1ES provisioning script should patch the agent to ARM64."
43-
Write-Host "Please investigate the provisioning script logs at:"
44-
Write-Host " https://winbuildpoolarm.blob.core.windows.net/insights-logs-provisioningscriptlogs"
45-
Write-Host ""
46-
Write-Host "Look for 'ARM64 Agent Provisioning Script' entries."
47-
Write-Host "See build/docs/ARM64-AGENT-PATCHING.md for troubleshooting."
48-
exit 1
56+
Write-Host "ARM64 agent verification PASSED!"
4957
}
50-
51-
Write-Host ""
52-
Write-Host "ARM64 agent verification PASSED!"
5358
} else {
5459
Write-Host "##[warning]Could not find Agent.Worker.exe at $workerExe"
5560
}

0 commit comments

Comments
 (0)