mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-12-31 05:03:22 +08:00
[vcpkg] testing for architectures supported by toolset
This commit is contained in:
parent
bed70f54bc
commit
7dd082cad7
@ -8,11 +8,24 @@
|
||||
|
||||
namespace vcpkg
|
||||
{
|
||||
struct ToolsetArchOption
|
||||
{
|
||||
CWStringView name;
|
||||
System::CPUArchitecture host_arch;
|
||||
System::CPUArchitecture target_arch;
|
||||
|
||||
bool operator==(const ToolsetArchOption& a) const
|
||||
{
|
||||
return (name == a.name && host_arch == a.host_arch && target_arch == a.target_arch);
|
||||
}
|
||||
};
|
||||
|
||||
struct Toolset
|
||||
{
|
||||
fs::path dumpbin;
|
||||
fs::path vcvarsall;
|
||||
CWStringView version;
|
||||
std::vector<ToolsetArchOption> supported_architectures;
|
||||
};
|
||||
|
||||
struct VcpkgPaths
|
||||
|
@ -77,6 +77,8 @@ namespace vcpkg::System
|
||||
|
||||
CPUArchitecture get_host_processor();
|
||||
|
||||
std::vector<CPUArchitecture> get_supported_host_architectures();
|
||||
|
||||
const fs::path& get_ProgramFiles_32_bit();
|
||||
|
||||
const fs::path& get_ProgramFiles_platform_bitness();
|
||||
|
@ -279,6 +279,8 @@ namespace vcpkg
|
||||
|
||||
static std::vector<Toolset> find_toolset_instances(const VcpkgPaths& paths)
|
||||
{
|
||||
using CPU = System::CPUArchitecture;
|
||||
|
||||
const auto& fs = paths.get_filesystem();
|
||||
|
||||
const std::vector<std::string> vs2017_installation_instances = get_VS2017_installation_instances(paths);
|
||||
@ -298,9 +300,27 @@ namespace vcpkg
|
||||
{
|
||||
const fs::path vs2015_dumpbin_exe = *v / "VC" / "bin" / "dumpbin.exe";
|
||||
paths_examined.push_back(vs2015_dumpbin_exe);
|
||||
|
||||
const fs::path vs2015_bin_dir = vs2015_vcvarsall_bat.parent_path() / "bin";
|
||||
std::vector<ToolsetArchOption> supported_archictectures;
|
||||
if(fs.exists(vs2015_bin_dir / "vcvars32.bat"))
|
||||
supported_archictectures.push_back({L"x86", CPU::X86, CPU::X86});
|
||||
if (fs.exists(vs2015_bin_dir / "amd64\\vcvars64.bat"))
|
||||
supported_archictectures.push_back({L"x64", CPU::X64, CPU::X64});
|
||||
if (fs.exists(vs2015_bin_dir / "arm\\vcvarsarm.bat"))
|
||||
supported_archictectures.push_back({L"arm", CPU::ARM, CPU::ARM});
|
||||
if (fs.exists(vs2015_bin_dir / "x86_amd64\\vcvarsx86_amd64.bat"))
|
||||
supported_archictectures.push_back({L"x86_amd64", CPU::X86, CPU::X64});
|
||||
if (fs.exists(vs2015_bin_dir / "x86_arm\\vcvarsx86_arm.bat"))
|
||||
supported_archictectures.push_back({L"x86_arm" , CPU::X86, CPU::ARM});
|
||||
if (fs.exists(vs2015_bin_dir / "amd64_x86\\vcvarsamd64_x86.bat"))
|
||||
supported_archictectures.push_back({L"amd64_x86", CPU::X64, CPU::X86});
|
||||
if (fs.exists(vs2015_bin_dir / "amd64_arm\\vcvarsamd64_arm.bat"))
|
||||
supported_archictectures.push_back({L"amd64_arm", CPU::X64, CPU::ARM});
|
||||
|
||||
if (fs.exists(vs2015_dumpbin_exe))
|
||||
{
|
||||
found_toolsets.push_back({vs2015_dumpbin_exe, vs2015_vcvarsall_bat, L"v140"});
|
||||
found_toolsets.push_back({vs2015_dumpbin_exe, vs2015_vcvarsall_bat, L"v140", supported_archictectures });
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -312,10 +332,28 @@ namespace vcpkg
|
||||
const fs::path vc_dir = instance / "VC";
|
||||
|
||||
// Skip any instances that do not have vcvarsall.
|
||||
const fs::path vcvarsall_bat = vc_dir / "Auxiliary" / "Build" / "vcvarsall.bat";
|
||||
const fs::path vcvarsall_dir = vc_dir / "Auxiliary" / "Build";
|
||||
const fs::path vcvarsall_bat = vcvarsall_dir / "vcvarsall.bat";
|
||||
paths_examined.push_back(vcvarsall_bat);
|
||||
if (!fs.exists(vcvarsall_bat)) continue;
|
||||
|
||||
//Get all supported architecturs
|
||||
std::vector<ToolsetArchOption> supported_architectures;
|
||||
if (fs.exists(vcvarsall_dir / "vcvars32.bat"))
|
||||
supported_architectures.push_back({L"x86", CPU::X86,CPU::X86 });
|
||||
if (fs.exists(vcvarsall_dir / "vcvars64.bat"))
|
||||
supported_architectures.push_back({L"amd64", CPU::X64,CPU::X64 });
|
||||
if (fs.exists(vcvarsall_dir / "vcvarsarm.bat"))
|
||||
supported_architectures.push_back({L"arm", CPU::ARM,CPU::ARM });
|
||||
if (fs.exists(vcvarsall_dir / "vcvarsx86_amd64.bat"))
|
||||
supported_architectures.push_back({L"x86_amd64",CPU::X86,CPU::X64 });
|
||||
if (fs.exists(vcvarsall_dir / "vcvarsx86_arm.bat"))
|
||||
supported_architectures.push_back({L"x86_arm", CPU::X86,CPU::ARM });
|
||||
if (fs.exists(vcvarsall_dir / "vcvarsamd64_x86.bat"))
|
||||
supported_architectures.push_back({L"amd64_x86", CPU::X64,CPU::X86 });
|
||||
if (fs.exists(vcvarsall_dir / "vcvarsamd64_arm.bat"))
|
||||
supported_architectures.push_back({L"amd64_arm", CPU::X64,CPU::ARM });
|
||||
|
||||
// Locate the "best" MSVC toolchain version
|
||||
const fs::path msvc_path = vc_dir / "Tools" / "MSVC";
|
||||
std::vector<fs::path> msvc_subdirectories = fs.get_files_non_recursive(msvc_path);
|
||||
@ -332,7 +370,7 @@ namespace vcpkg
|
||||
paths_examined.push_back(dumpbin_path);
|
||||
if (fs.exists(dumpbin_path))
|
||||
{
|
||||
vs2017_toolset = Toolset{dumpbin_path, vcvarsall_bat, L"v141"};
|
||||
vs2017_toolset = Toolset{dumpbin_path, vcvarsall_bat, L"v141", supported_architectures};
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -36,39 +36,35 @@ namespace vcpkg::Build
|
||||
Checks::exit_with_message(VCPKG_LINE_INFO, "Unsupported vcvarsall target %s", cmake_system_name);
|
||||
}
|
||||
|
||||
CWStringView to_vcvarsall_toolchain(const std::string& target_architecture)
|
||||
CWStringView to_vcvarsall_toolchain(const std::string& target_architecture, const Toolset& toolset)
|
||||
{
|
||||
using CPU = System::CPUArchitecture;
|
||||
|
||||
struct ArchOption
|
||||
{
|
||||
CWStringView name;
|
||||
CPU host_arch;
|
||||
CPU target_arch;
|
||||
};
|
||||
static constexpr ToolsetArchOption X86 = {L"x86", CPU::X86, CPU::X86};
|
||||
static constexpr ToolsetArchOption X86_X64 = {L"x86_x64", CPU::X86, CPU::X64};
|
||||
static constexpr ToolsetArchOption X86_ARM = {L"x86_arm", CPU::X86, CPU::ARM};
|
||||
static constexpr ToolsetArchOption X86_ARM64 = {L"x86_arm64", CPU::X86, CPU::ARM64};
|
||||
|
||||
static constexpr ArchOption X86 = {L"x86", CPU::X86, CPU::X86};
|
||||
static constexpr ArchOption X86_X64 = {L"x86_x64", CPU::X86, CPU::X64};
|
||||
static constexpr ArchOption X86_ARM = {L"x86_arm", CPU::X86, CPU::ARM};
|
||||
static constexpr ArchOption X86_ARM64 = {L"x86_arm64", CPU::X86, CPU::ARM64};
|
||||
static constexpr ToolsetArchOption X64 = {L"amd64", CPU::X64, CPU::X64};
|
||||
static constexpr ToolsetArchOption X64_X86 = {L"amd64_x86", CPU::X64, CPU::X86};
|
||||
static constexpr ToolsetArchOption X64_ARM = {L"amd64_arm", CPU::X64, CPU::ARM};
|
||||
static constexpr ToolsetArchOption X64_ARM64 = {L"amd64_arm64", CPU::X64, CPU::ARM64};
|
||||
|
||||
static constexpr ArchOption X64 = {L"amd64", CPU::X64, CPU::X64};
|
||||
static constexpr ArchOption X64_X86 = {L"amd64_x86", CPU::X64, CPU::X86};
|
||||
static constexpr ArchOption X64_ARM = {L"amd64_arm", CPU::X64, CPU::ARM};
|
||||
static constexpr ArchOption X64_ARM64 = {L"amd64_arm64", CPU::X64, CPU::ARM64};
|
||||
|
||||
static constexpr std::array<ArchOption, 8> VALUES = {
|
||||
static constexpr std::array<ToolsetArchOption, 8> VALUES = {
|
||||
X86, X86_X64, X86_ARM, X86_ARM64, X64, X64_X86, X64_ARM, X64_ARM64};
|
||||
|
||||
auto target_arch = System::to_cpu_architecture(target_architecture);
|
||||
auto host_arch = System::get_host_processor();
|
||||
auto host_architectures = System::get_supported_host_architectures();
|
||||
|
||||
for (auto&& value : VALUES)
|
||||
{
|
||||
if (target_arch == value.target_arch && host_arch == value.host_arch)
|
||||
{
|
||||
return value.name;
|
||||
}
|
||||
if (target_arch != value.target_arch ||
|
||||
std::find(host_architectures.begin(), host_architectures.end(), value.host_arch) == host_architectures.end() ||
|
||||
std::find(toolset.supported_architectures.begin(), toolset.supported_architectures.end(), value) == toolset.supported_architectures.end()
|
||||
)
|
||||
continue;
|
||||
|
||||
return value.name;
|
||||
}
|
||||
|
||||
Checks::exit_with_message(VCPKG_LINE_INFO, "Unsupported toolchain combination %s", target_architecture);
|
||||
@ -82,7 +78,7 @@ namespace vcpkg::Build
|
||||
tonull = L"";
|
||||
}
|
||||
|
||||
auto arch = to_vcvarsall_toolchain(pre_build_info.target_architecture);
|
||||
auto arch = to_vcvarsall_toolchain(pre_build_info.target_architecture, toolset);
|
||||
auto target = to_vcvarsall_target(pre_build_info.cmake_system_name);
|
||||
|
||||
return Strings::wformat(LR"("%s" %s %s %s 2>&1)", toolset.vcvarsall.native(), arch, target, tonull);
|
||||
|
@ -42,6 +42,20 @@ namespace vcpkg::System
|
||||
return to_cpu_architecture(Strings::to_utf8(procarch)).value_or_exit(VCPKG_LINE_INFO);
|
||||
}
|
||||
|
||||
std::vector<CPUArchitecture> get_supported_host_architectures()
|
||||
{
|
||||
std::vector<CPUArchitecture> supported_architectures;
|
||||
supported_architectures.push_back(get_host_processor());
|
||||
|
||||
//AMD64 machines support to run x86 applications
|
||||
if(supported_architectures.back()==CPUArchitecture::X64)
|
||||
{
|
||||
supported_architectures.push_back(CPUArchitecture::X86);
|
||||
}
|
||||
|
||||
return supported_architectures;
|
||||
}
|
||||
|
||||
int cmd_execute_clean(const CWStringView cmd_line)
|
||||
{
|
||||
static const std::wstring system_root = get_environment_variable(L"SystemRoot").value_or_exit(VCPKG_LINE_INFO);
|
||||
|
Loading…
x
Reference in New Issue
Block a user