[vcpkg] Use vcvars argument strings from detected toolset. Avoid c-string pointer comparison.
MODIFY
include/VcpkgPaths.h
include/VcpkgPaths.h
@@ -13,11 +13,6 @@ namespace vcpkg
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

MODIFY
src/VcpkgPaths.cpp
src/VcpkgPaths.cpp
@@ -302,25 +302,24 @@ namespace vcpkg
paths_examined.push_back(vs2015_dumpbin_exe);
const fs::path vs2015_bin_dir = vs2015_vcvarsall_bat.parent_path() / "bin";
- std::vector<ToolsetArchOption> supported_archictectures;
+ std::vector<ToolsetArchOption> supported_architectures;
if (fs.exists(vs2015_bin_dir / "vcvars32.bat"))
- supported_archictectures.push_back({L"x86", CPU::X86, CPU::X86});
+ supported_architectures.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});
+ supported_architectures.push_back({L"x64", CPU::X64, CPU::X64});
if (fs.exists(vs2015_bin_dir / "x86_amd64\\vcvarsx86_amd64.bat"))
- supported_archictectures.push_back({L"x86_amd64", CPU::X86, CPU::X64});
+ supported_architectures.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});
+ supported_architectures.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});
+ supported_architectures.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});
+ supported_architectures.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", supported_archictectures });
+ found_toolsets.push_back(
+ {vs2015_dumpbin_exe, vs2015_vcvarsall_bat, L"v140", supported_architectures});
}
}
}
@@ -337,14 +336,12 @@ namespace vcpkg
paths_examined.push_back(vcvarsall_bat);
if (!fs.exists(vcvarsall_bat)) continue;
- //Get all supported architecturs
+ // Get all supported architectures
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"))

MODIFY
src/vcpkg_Build.cpp
src/vcpkg_Build.cpp
@@ -38,33 +38,18 @@ namespace vcpkg::Build
CWStringView to_vcvarsall_toolchain(const std::string& target_architecture, const Toolset& toolset)
{
- using CPU = System::CPUArchitecture;
-
- 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 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 std::array<ToolsetArchOption, 8> VALUES = {
- X64, X64_X86, X64_ARM, X64_ARM64, X86, X86_X64, X86_ARM, X86_ARM64};
-
- auto target_arch = System::to_cpu_architecture(target_architecture);
+ auto maybe_target_arch = System::to_cpu_architecture(target_architecture);
+ Checks::check_exit(
+ VCPKG_LINE_INFO, maybe_target_arch.has_value(), "Invalid architecture string: %s", target_architecture);
+ auto target_arch = maybe_target_arch.value_or_exit(VCPKG_LINE_INFO);
auto host_architectures = System::get_supported_host_architectures();
- for (auto&& value : VALUES)
+ for (auto&& host : host_architectures)
{
- 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;
+ auto it = Util::find_if(toolset.supported_architectures, [&](const ToolsetArchOption& opt) {
+ return host == opt.host_arch && target_arch == opt.target_arch;
+ });
+ if (it != toolset.supported_architectures.end()) return it->name;
}
Checks::exit_with_message(VCPKG_LINE_INFO, "Unsupported toolchain combination %s", target_architecture);

[vcpkg] Use vcvars argument strings from detected toolset. Avoid c-string pointer comparison.