Skip to content

Commit 6e452da

Browse files
jtschusterCopilotAaronRobinsonMSFT
authored
Fix hard-coded Hostx64 path to support arm64 and x86 hosts (#215)
* Fix hard-coded Hostx64 path to support arm64 and x86 hosts Agent-Logs-Url: https://github.com/jtschuster/DNNE/sessions/ac4821f0-b6bc-44e7-b8b0-8c2916804889 Co-authored-by: jtschuster <36744439+jtschuster@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
1 parent 2a810d0 commit 6e452da

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

src/msbuild/DNNE.BuildTasks/Windows.cs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ public static void ConstructCommandLine(CreateCompileCommand export, out string
5353
var vcIncDir = Path.Combine(vcToolDir, "include");
5454
var libDir = Path.Combine(vcToolDir, "lib", archDir);
5555

56-
// For now we assume building always happens on a x64 machine.
57-
var binDir = Path.Combine(vcToolDir, "bin\\Hostx64", archDir);
56+
var binDir = GetVCHostBinDir(vcToolDir, archDir);
5857

5958
string compileAsFlag;
6059
string hostLib;
@@ -174,6 +173,52 @@ public static void ConstructCommandLine(CreateCompileCommand export, out string
174173
commandArguments = $"{compilerFlags} \"{export.Source}\" \"{platformTU}\" /link {linkerFlags}";
175174
}
176175

176+
private static string GetVCHostBinDir(string vcToolDir, string archDir)
177+
{
178+
// Determine the preferred host directory based on the current process architecture.
179+
string preferredHostDir = HostSubDirectory(RuntimeInformation.ProcessArchitecture);
180+
if (preferredHostDir != null)
181+
{
182+
string preferredPath = Path.Combine(vcToolDir, "bin", preferredHostDir, archDir);
183+
if (Directory.Exists(preferredPath))
184+
{
185+
return preferredPath;
186+
}
187+
}
188+
189+
// Fall back to other hosts in priority order.
190+
List<string> consideredPaths = new();
191+
var fallbackHostArchs = new[] { Architecture.Arm64, Architecture.X64, Architecture.X86 };
192+
foreach (var tgtArch in fallbackHostArchs)
193+
{
194+
// Skip the preferred host since we already tried it.
195+
if (tgtArch == RuntimeInformation.ProcessArchitecture)
196+
continue;
197+
198+
string hostDir = HostSubDirectory(tgtArch);
199+
string candidatePath = Path.Combine(vcToolDir, "bin", hostDir, archDir);
200+
if (Directory.Exists(candidatePath))
201+
{
202+
return candidatePath;
203+
}
204+
205+
consideredPaths.Add(hostDir);
206+
}
207+
208+
throw new Exception($"No VC host compiler directory found. Searched: {string.Join(", ", consideredPaths)} under '{Path.Combine(vcToolDir, "bin")}' for target '{archDir}'.");
209+
210+
static string HostSubDirectory(Architecture arch)
211+
{
212+
return arch switch
213+
{
214+
Architecture.X64 => "Hostx64",
215+
Architecture.X86 => "Hostx86",
216+
Architecture.Arm64 => "HostArm64",
217+
_ => null
218+
};
219+
}
220+
}
221+
177222
private static string ConvertToVCArchSubDir(string arch, string rid)
178223
{
179224
return arch.ToLower() switch

0 commit comments

Comments
 (0)