diff --git a/Source/Tools/Flax.Build/Platforms/GDK/GDKToolchain.cs b/Source/Tools/Flax.Build/Platforms/GDK/GDKToolchain.cs
index 8e56950e7..c8e0dff11 100644
--- a/Source/Tools/Flax.Build/Platforms/GDK/GDKToolchain.cs
+++ b/Source/Tools/Flax.Build/Platforms/GDK/GDKToolchain.cs
@@ -47,7 +47,7 @@ namespace Flax.Build.Platforms
options.LinkEnv.InputLibraries.Add($"Microsoft.Xbox.Services.{(int)xboxServicesToolset}.GDK.C.lib");
var toolsetPath = WindowsPlatformBase.GetToolsets()[Toolset];
- var toolsPath = WindowsPlatformBase.GetVCToolPath64(Toolset);
+ var toolsPath = WindowsPlatformBase.GetVCToolPath(Toolset, TargetArchitecture.x64, Architecture);
if (options.CompileEnv.UseDebugCRT)
throw new Exception("Don't use debug CRT on GDK.");
var name = Path.GetFileName(toolsetPath);
diff --git a/Source/Tools/Flax.Build/Platforms/Windows/WindowsPlatformBase.cs b/Source/Tools/Flax.Build/Platforms/Windows/WindowsPlatformBase.cs
index f038b1e6e..d2b490704 100644
--- a/Source/Tools/Flax.Build/Platforms/Windows/WindowsPlatformBase.cs
+++ b/Source/Tools/Flax.Build/Platforms/Windows/WindowsPlatformBase.cs
@@ -409,101 +409,68 @@ namespace Flax.Build.Platforms
}
///
- /// Gets the path to the 32-bit tool binaries.
+ /// Gets the path to the VC++ tool binaries for specified host and target architectures.
///
/// The version of the toolset to use.
- /// The directory containing the 64-bit toolchain binaries.
- public static string GetVCToolPath32(WindowsPlatformToolset toolset)
+ /// The host architecture for native binaries.
+ /// The target architecture to build for.
+ /// The directory containing the toolchain binaries.
+ public static string GetVCToolPath(WindowsPlatformToolset toolset, TargetArchitecture hostArchitecture, TargetArchitecture architecture)
{
+ if (architecture == TargetArchitecture.AnyCPU)
+ architecture = hostArchitecture;
var toolsets = GetToolsets();
var vcToolChainDir = toolsets[toolset];
switch (toolset)
{
- case WindowsPlatformToolset.v140:
- {
- string compilerPath = Path.Combine(vcToolChainDir, "bin", "cl.exe");
- if (File.Exists(compilerPath))
+ case WindowsPlatformToolset.v140:
{
- return Path.GetDirectoryName(compilerPath);
- }
+ if (hostArchitecture != TargetArchitecture.x86)
+ {
+ string nativeCompilerPath = Path.Combine(vcToolChainDir, "bin", "amd64", "cl.exe");
+ if (File.Exists(nativeCompilerPath))
+ {
+ return Path.GetDirectoryName(nativeCompilerPath);
+ }
- throw new Exception(string.Format("No 32-bit compiler toolchain found in {0}", compilerPath));
- }
- case WindowsPlatformToolset.v141:
- case WindowsPlatformToolset.v142:
- case WindowsPlatformToolset.v143:
- case WindowsPlatformToolset.v144:
- {
- /*
- string crossCompilerPath = Path.Combine(vcToolChainDir, "bin", "HostX64", "x86", "cl.exe");
- if (File.Exists(crossCompilerPath))
+ string crossCompilerPath = Path.Combine(vcToolChainDir, "bin", "x86_amd64", "cl.exe");
+ if (File.Exists(crossCompilerPath))
+ {
+ return Path.GetDirectoryName(crossCompilerPath);
+ }
+ throw new Exception(string.Format("No {0} host compiler toolchain found in {1} or {2}", hostArchitecture.ToString(), nativeCompilerPath, crossCompilerPath));
+ }
+ else
+ {
+ string compilerPath = Path.Combine(vcToolChainDir, "bin", "cl.exe");
+ if (File.Exists(compilerPath))
+ {
+ return Path.GetDirectoryName(compilerPath);
+ }
+ throw new Exception(string.Format("No {0} host compiler toolchain found in {1}", hostArchitecture.ToString()));
+ }
+ }
+ case WindowsPlatformToolset.v141:
+ case WindowsPlatformToolset.v142:
+ case WindowsPlatformToolset.v143:
+ case WindowsPlatformToolset.v144:
{
- return Path.GetDirectoryName(crossCompilerPath);
+ string hostFolder = hostArchitecture == TargetArchitecture.x86 ? "HostX86" : $"Host{hostArchitecture.ToString().ToLower()}";
+ string nativeCompilerPath = Path.Combine(vcToolChainDir, "bin", hostFolder, architecture.ToString().ToLower(), "cl.exe");
+ if (File.Exists(nativeCompilerPath))
+ {
+ return Path.GetDirectoryName(nativeCompilerPath);
+ }
+
+ string crossCompilerPath = Path.Combine(vcToolChainDir, "bin", hostFolder, architecture.ToString().ToLower(), "cl.exe");
+ if (File.Exists(crossCompilerPath))
+ {
+ return Path.GetDirectoryName(crossCompilerPath);
+ }
+ throw new Exception(string.Format("No {0} host compiler toolchain found in {1} or {2}", hostArchitecture.ToString(), nativeCompilerPath, crossCompilerPath));
}
- */
-
- string nativeCompilerPath = Path.Combine(vcToolChainDir, "bin", "HostX86", "x86", "cl.exe");
- if (File.Exists(nativeCompilerPath))
- {
- return Path.GetDirectoryName(nativeCompilerPath);
- }
-
- //throw new Exception(string.Format("No 32-bit compiler toolchain found in {0} or {1}", crossCompilerPath, nativeCompilerPath));
- throw new Exception(string.Format("No 32-bit compiler toolchain found in {0}", nativeCompilerPath));
- }
- default: throw new ArgumentOutOfRangeException(nameof(toolset), toolset, null);
- }
- }
-
- ///
- /// Gets the path to the 64-bit tool binaries.
- ///
- /// The version of the toolset to use.
- /// The directory containing the 64-bit toolchain binaries.
- public static string GetVCToolPath64(WindowsPlatformToolset toolset)
- {
- var toolsets = GetToolsets();
- var vcToolChainDir = toolsets[toolset];
-
- switch (toolset)
- {
- case WindowsPlatformToolset.v140:
- {
- string nativeCompilerPath = Path.Combine(vcToolChainDir, "bin", "amd64", "cl.exe");
- if (File.Exists(nativeCompilerPath))
- {
- return Path.GetDirectoryName(nativeCompilerPath);
- }
-
- string crossCompilerPath = Path.Combine(vcToolChainDir, "bin", "x86_amd64", "cl.exe");
- if (File.Exists(crossCompilerPath))
- {
- return Path.GetDirectoryName(crossCompilerPath);
- }
-
- throw new Exception(string.Format("No 64-bit compiler toolchain found in {0} or {1}", nativeCompilerPath, crossCompilerPath));
- }
- case WindowsPlatformToolset.v141:
- case WindowsPlatformToolset.v142:
- case WindowsPlatformToolset.v143:
- case WindowsPlatformToolset.v144:
- {
- string nativeCompilerPath = Path.Combine(vcToolChainDir, "bin", "HostX64", "x64", "cl.exe");
- if (File.Exists(nativeCompilerPath))
- {
- return Path.GetDirectoryName(nativeCompilerPath);
- }
-
- string crossCompilerPath = Path.Combine(vcToolChainDir, "bin", "HostX86", "x64", "cl.exe");
- if (File.Exists(crossCompilerPath))
- {
- return Path.GetDirectoryName(crossCompilerPath);
- }
-
- throw new Exception(string.Format("No 64-bit compiler toolchain found in {0} or {1}", nativeCompilerPath, crossCompilerPath));
- }
- default: throw new ArgumentOutOfRangeException(nameof(toolset), toolset, null);
+ default: throw new ArgumentOutOfRangeException(nameof(toolset), toolset, null);
}
}
diff --git a/Source/Tools/Flax.Build/Platforms/Windows/WindowsToolchainBase.cs b/Source/Tools/Flax.Build/Platforms/Windows/WindowsToolchainBase.cs
index 8d5afbeae..6df1c38eb 100644
--- a/Source/Tools/Flax.Build/Platforms/Windows/WindowsToolchainBase.cs
+++ b/Source/Tools/Flax.Build/Platforms/Windows/WindowsToolchainBase.cs
@@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Runtime.InteropServices;
using System.Text;
using System.Xml;
using Flax.Build.Graph;
@@ -133,16 +134,12 @@ namespace Flax.Build.Platforms
throw new Exception(string.Format("Missing SDK {0} for platform Windows", SDK));
// Get the tools paths
- string vcToolPath;
- if (Architecture == TargetArchitecture.x64)
- vcToolPath = WindowsPlatformBase.GetVCToolPath64(Toolset);
- else
- vcToolPath = WindowsPlatformBase.GetVCToolPath32(Toolset);
- _vcToolPath = vcToolPath;
- _compilerPath = Path.Combine(vcToolPath, "cl.exe");
- _linkerPath = Path.Combine(vcToolPath, "link.exe");
- _libToolPath = Path.Combine(vcToolPath, "lib.exe");
- _xdcmakePath = Path.Combine(vcToolPath, "xdcmake.exe");
+ var hostArchitecture = Platform.BuildTargetArchitecture;
+ _vcToolPath = WindowsPlatformBase.GetVCToolPath(Toolset, hostArchitecture, Architecture);
+ _compilerPath = Path.Combine(_vcToolPath, "cl.exe");
+ _linkerPath = Path.Combine(_vcToolPath, "link.exe");
+ _libToolPath = Path.Combine(_vcToolPath, "lib.exe");
+ _xdcmakePath = Path.Combine(_vcToolPath, "xdcmake.exe");
// Add Visual C++ toolset include and library paths
var vcToolChainDir = toolsets[Toolset];
@@ -166,7 +163,7 @@ namespace Flax.Build.Platforms
case TargetArchitecture.x64:
SystemLibraryPaths.Add(Path.Combine(vcToolChainDir, "lib", "amd64"));
break;
- default: throw new InvalidArchitectureException(architecture);
+ default: throw new InvalidArchitectureException(Architecture);
}
// When using Visual Studio 2015 toolset and using pre-Windows 10 SDK, find a Windows 10 SDK and add the UCRT include paths
@@ -198,7 +195,7 @@ namespace Flax.Build.Platforms
case TargetArchitecture.x64:
SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "ucrt", "x64"));
break;
- default: throw new InvalidArchitectureException(architecture);
+ default: throw new InvalidArchitectureException(Architecture);
}
}
break;
@@ -223,7 +220,7 @@ namespace Flax.Build.Platforms
case TargetArchitecture.x64:
SystemLibraryPaths.Add(Path.Combine(vcToolChainDir, "lib", "x64"));
break;
- default: throw new InvalidArchitectureException(architecture);
+ default: throw new InvalidArchitectureException(Architecture);
}
break;
}
@@ -274,7 +271,7 @@ namespace Flax.Build.Platforms
_makepriPath = Path.Combine(binRootDir, "makepri.exe");
break;
}
- default: throw new InvalidArchitectureException(architecture);
+ default: throw new InvalidArchitectureException(Architecture);
}
break;
}
@@ -312,13 +309,16 @@ namespace Flax.Build.Platforms
{
SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "ucrt", "arm64"));
SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "um", "arm64"));
+ var binRootDir = Path.Combine(windowsSdkDir, "bin", sdkVersionName, hostArchitecture.ToString().ToLower());
+ _resourceCompilerPath = Path.Combine(binRootDir, "rc.exe");
+ _makepriPath = Path.Combine(binRootDir, "makepri.exe");
break;
}
case TargetArchitecture.x86:
{
SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "ucrt", "x86"));
SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "um", "x86"));
- var binRootDir = Path.Combine(windowsSdkDir, "bin", sdkVersionName, "x86");
+ var binRootDir = Path.Combine(windowsSdkDir, "bin", sdkVersionName, hostArchitecture.ToString().ToLower());
_resourceCompilerPath = Path.Combine(binRootDir, "rc.exe");
_makepriPath = Path.Combine(binRootDir, "makepri.exe");
break;
@@ -327,12 +327,12 @@ namespace Flax.Build.Platforms
{
SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "ucrt", "x64"));
SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "um", "x64"));
- var binRootDir = Path.Combine(windowsSdkDir, "bin", sdkVersionName, "x64");
+ var binRootDir = Path.Combine(windowsSdkDir, "bin", sdkVersionName, hostArchitecture.ToString().ToLower());
_resourceCompilerPath = Path.Combine(binRootDir, "rc.exe");
_makepriPath = Path.Combine(binRootDir, "makepri.exe");
break;
}
- default: throw new InvalidArchitectureException(architecture);
+ default: throw new InvalidArchitectureException(Architecture);
}
break;
}