[vcpkg] Improve external toolchain handling.
MODIFY
include/vcpkg/build.h
include/vcpkg/build.h
@@ -89,6 +89,7 @@ namespace vcpkg::Build
std::string cmake_system_version;
Optional<std::string> platform_toolset;
Optional<fs::path> visual_studio_path;
+ Optional<std::string> external_toolchain_file;
};
std::string make_build_env_cmd(const PreBuildInfo& pre_build_info, const Toolset& toolset);

MODIFY
include/vcpkg/vcpkgpaths.h
include/vcpkg/vcpkgpaths.h
@@ -26,6 +26,11 @@ namespace vcpkg
std::vector<ToolsetArchOption> supported_architectures;
};
+ namespace Build
+ {
+ struct PreBuildInfo;
+ }
+
struct VcpkgPaths
{
static Expected<VcpkgPaths> create(const fs::path& vcpkg_root_dir);
@@ -69,8 +74,7 @@ namespace vcpkg
/// <remarks>
/// Valid version strings are "v120", "v140", "v141", and "". Empty string gets the latest.
/// </remarks>
- const Toolset& get_toolset(const Optional<std::string>& toolset_version,
- const Optional<fs::path>& visual_studio_path) const;
+ const Toolset& get_toolset(const Build::PreBuildInfo& prebuildinfo) const;
Files::Filesystem& get_filesystem() const;

MODIFY
src/vcpkg/base/files.cpp
src/vcpkg/base/files.cpp
@@ -72,7 +72,8 @@ namespace vcpkg::Files
{
std::vector<fs::path> ret;
- fs::stdfs::recursive_directory_iterator b(dir), e{};
+ std::error_code ec;
+ fs::stdfs::recursive_directory_iterator b(dir, ec), e{};
for (; b != e; ++b)
{
ret.push_back(b->path());

MODIFY
src/vcpkg/base/system.cpp
src/vcpkg/base/system.cpp
@@ -51,11 +51,21 @@ namespace vcpkg::System
CPUArchitecture get_host_processor()
{
+#if defined(_WIN32)
auto w6432 = get_environment_variable("PROCESSOR_ARCHITEW6432");
if (const auto p = w6432.get()) return to_cpu_architecture(*p).value_or_exit(VCPKG_LINE_INFO);
const auto procarch = get_environment_variable("PROCESSOR_ARCHITECTURE").value_or_exit(VCPKG_LINE_INFO);
return to_cpu_architecture(procarch).value_or_exit(VCPKG_LINE_INFO);
+#else
+#if defined(__x86_64__) || defined(_M_X64)
+ return CPUArchitecture::X64;
+#elif defined(__x86__) || defined(_M_X86)
+ return CPUArchitecture::X86;
+#else
+#error "Unknown host architecture"
+#endif
+#endif
}
std::vector<CPUArchitecture> get_supported_host_architectures()

MODIFY
src/vcpkg/build.cpp
src/vcpkg/build.cpp
@@ -203,6 +203,10 @@ namespace vcpkg::Build
std::string make_build_env_cmd(const PreBuildInfo& pre_build_info, const Toolset& toolset)
{
+ if (pre_build_info.external_toolchain_file)
+ return Strings::format(
+ R"("%s" %s 2>&1)", toolset.vcvarsall.u8string(), Strings::join(" ", toolset.vcvarsall_options));
+
const char* tonull = " >nul";
if (GlobalState::debugging)
{
@@ -299,8 +303,7 @@ namespace vcpkg::Build
}
}
- const Toolset& toolset = paths.get_toolset(pre_build_info.platform_toolset, pre_build_info.visual_studio_path);
-
+ const Toolset& toolset = paths.get_toolset(pre_build_info);
const std::string cmd_launch_cmake = System::make_cmake_cmd(
cmake_exe_path,
ports_cmake_script_path,
@@ -555,6 +558,13 @@ namespace vcpkg::Build
continue;
}
+ if (variable_name == "VCPKG_CHAINLOAD_TOOLCHAIN_FILE")
+ {
+ pre_build_info.external_toolchain_file =
+ variable_value.empty() ? nullopt : Optional<std::string>{variable_value};
+ continue;
+ }
+
Checks::exit_with_message(VCPKG_LINE_INFO, "Unknown variable name %s", line);
}

MODIFY
src/vcpkg/commands.env.cpp
src/vcpkg/commands.env.cpp
@@ -20,7 +20,7 @@ namespace vcpkg::Commands::Env
args.parse_arguments(COMMAND_STRUCTURE);
const auto pre_build_info = Build::PreBuildInfo::from_triplet_file(paths, default_triplet);
- const Toolset& toolset = paths.get_toolset(pre_build_info.platform_toolset, pre_build_info.visual_studio_path);
+ const Toolset& toolset = paths.get_toolset(pre_build_info);
System::cmd_execute_clean(Build::make_build_env_cmd(pre_build_info, toolset) + " && cmd");
Checks::exit_success(VCPKG_LINE_INFO);

MODIFY
src/vcpkg/export.cpp
src/vcpkg/export.cpp
@@ -290,7 +290,7 @@ namespace vcpkg::Export
{OPTION_IFW_INSTALLER_FILE_PATH, "Specify the file path for the exported installer"},
}};
- const CommandStructure vcpkg::Export::COMMAND_STRUCTURE = {
+ const CommandStructure COMMAND_STRUCTURE = {
Help::create_example_string("export zlib zlib:x64-windows boost --nuget"),
0,
SIZE_MAX,

MODIFY
src/vcpkg/install.cpp
src/vcpkg/install.cpp
@@ -561,7 +561,7 @@ namespace vcpkg::Install
static void print_cmake_information(const BinaryParagraph& bpgh, const VcpkgPaths& paths)
{
- static const std::regex cmake_library_regex("^add_library\\(([^\\s\\$\\)]+)\\s");
+ static const std::regex cmake_library_regex(R"(\badd_library\(([^\s\)]+)\s)", std::regex_constants::ECMAScript);
auto& fs = paths.get_filesystem();

MODIFY
src/vcpkg/postbuildlint.cpp
src/vcpkg/postbuildlint.cpp
@@ -726,7 +726,7 @@ namespace vcpkg::PostBuildLint
const auto& fs = paths.get_filesystem();
// for dumpbin
- const Toolset& toolset = paths.get_toolset(pre_build_info.platform_toolset, pre_build_info.visual_studio_path);
+ const Toolset& toolset = paths.get_toolset(pre_build_info);
const fs::path package_dir = paths.package_dir(spec);
size_t error_count = 0;

MODIFY
src/vcpkg/vcpkgpaths.cpp
src/vcpkg/vcpkgpaths.cpp
#include <vcpkg/base/files.h>
#include <vcpkg/base/system.h>
#include <vcpkg/base/util.h>
+#include <vcpkg/build.h>
#include <vcpkg/metrics.h>
#include <vcpkg/packagespec.h>
#include <vcpkg/vcpkgpaths.h>
@@ -115,11 +116,13 @@ namespace vcpkg
static constexpr std::array<int, 3> EXPECTED_VERSION = {3, 9, 5};
static const std::string VERSION_CHECK_ARGUMENTS = "--version";
- const fs::path downloaded_copy = downloads_folder / "cmake-3.9.5-win32-x86" / "bin" / "cmake.exe";
const std::vector<fs::path> from_path = Files::find_from_PATH("cmake");
std::vector<fs::path> candidate_paths;
+ const fs::path downloaded_copy = downloads_folder / "cmake-3.9.5-win32-x86" / "bin" / "cmake.exe";
+#if defined(_WIN32)
candidate_paths.push_back(downloaded_copy);
+#endif
candidate_paths.insert(candidate_paths.end(), from_path.cbegin(), from_path.cend());
#if defined(_WIN32)
candidate_paths.push_back(System::get_program_files_platform_bitness() / "CMake" / "bin" / "cmake.exe");
@@ -161,11 +164,13 @@ namespace vcpkg
static constexpr std::array<int, 3> EXPECTED_VERSION = {2, 15, 0};
static const std::string VERSION_CHECK_ARGUMENTS = "--version";
- const fs::path downloaded_copy = downloads_folder / "MinGit-2.15.0-32-bit" / "cmd" / "git.exe";
const std::vector<fs::path> from_path = Files::find_from_PATH("git");
+ const fs::path downloaded_copy = downloads_folder / "MinGit-2.15.0-32-bit" / "cmd" / "git.exe";
std::vector<fs::path> candidate_paths;
+#if defined(_WIN32)
candidate_paths.push_back(downloaded_copy);
+#endif
candidate_paths.insert(candidate_paths.end(), from_path.cbegin(), from_path.cend());
#if defined(_WIN32)
candidate_paths.push_back(System::get_program_files_platform_bitness() / "git" / "cmd" / "git.exe");
@@ -499,16 +504,36 @@ namespace vcpkg
return found_toolsets;
}
- const Toolset& VcpkgPaths::get_toolset(const Optional<std::string>& toolset_version,
- const Optional<fs::path>& visual_studio_path) const
+ const Toolset& VcpkgPaths::get_toolset(const Build::PreBuildInfo& prebuildinfo) const
+ {
+ if (prebuildinfo.external_toolchain_file)
{
+ static Toolset external_toolset = []() -> Toolset {
+ Toolset ret;
+ ret.dumpbin = "";
+ ret.supported_architectures = {
+ ToolsetArchOption{"", System::get_host_processor(), System::get_host_processor()}};
+#if defined(_WIN32)
+ ret.vcvarsall = "cmd";
+ ret.vcvarsall_options = {"/c", "echo done"};
+#else
+ ret.vcvarsall = "true";
+ ret.vcvarsall_options = {};
+#endif
+ ret.version = "external";
+ ret.visual_studio_root_path = "";
+ return ret;
+ }();
+ return external_toolset;
+ }
+
// Invariant: toolsets are non-empty and sorted with newest at back()
const std::vector<Toolset>& vs_toolsets =
this->toolsets.get_lazy([this]() { return find_toolset_instances(*this); });
std::vector<const Toolset*> candidates = Util::element_pointers(vs_toolsets);
- const auto tsv = toolset_version.get();
- const auto vsp = visual_studio_path.get();
+ const auto tsv = prebuildinfo.platform_toolset.get();
+ const auto vsp = prebuildinfo.visual_studio_path.get();
if (tsv && vsp)
{

MODIFY
vcpkg.sln
vcpkg.sln
@@ -11,6 +11,51 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vcpkgmetricsuploader", "vcp
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vcpkgtest", "vcpkgtest\vcpkgtest.vcxproj", "{F27B8DB0-1279-4AF8-A2E3-1D49C4F0220D}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{F5893B21-EA71-4432-84D6-5FB0E0461A2A}"
+ ProjectSection(SolutionItems) = preProject
+ ..\scripts\bootstrap.ps1 = ..\scripts\bootstrap.ps1
+ ..\scripts\fetchDependency.ps1 = ..\scripts\fetchDependency.ps1
+ ..\scripts\findAnyMSBuildWithCppPlatformToolset.ps1 = ..\scripts\findAnyMSBuildWithCppPlatformToolset.ps1
+ ..\scripts\findFileRecursivelyUp.ps1 = ..\scripts\findFileRecursivelyUp.ps1
+ ..\scripts\findVisualStudioInstallationInstances.ps1 = ..\scripts\findVisualStudioInstallationInstances.ps1
+ ..\scripts\get_triplet_environment.cmake = ..\scripts\get_triplet_environment.cmake
+ ..\scripts\getProgramFiles32bit.ps1 = ..\scripts\getProgramFiles32bit.ps1
+ ..\scripts\getProgramFilesPlatformBitness.ps1 = ..\scripts\getProgramFilesPlatformBitness.ps1
+ ..\scripts\getWindowsSDK.ps1 = ..\scripts\getWindowsSDK.ps1
+ ..\scripts\internalCI.ps1 = ..\scripts\internalCI.ps1
+ ..\scripts\ports.cmake = ..\scripts\ports.cmake
+ ..\scripts\SHA256Hash.ps1 = ..\scripts\SHA256Hash.ps1
+ ..\scripts\VcpkgPowershellUtils.ps1 = ..\scripts\VcpkgPowershellUtils.ps1
+ EndProjectSection
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cmake", "cmake", "{A0122231-04D5-420B-81CA-7960946E5E65}"
+ ProjectSection(SolutionItems) = preProject
+ ..\scripts\cmake\vcpkg_acquire_msys.cmake = ..\scripts\cmake\vcpkg_acquire_msys.cmake
+ ..\scripts\cmake\vcpkg_apply_patches.cmake = ..\scripts\cmake\vcpkg_apply_patches.cmake
+ ..\scripts\cmake\vcpkg_build_cmake.cmake = ..\scripts\cmake\vcpkg_build_cmake.cmake
+ ..\scripts\cmake\vcpkg_build_msbuild.cmake = ..\scripts\cmake\vcpkg_build_msbuild.cmake
+ ..\scripts\cmake\vcpkg_build_qmake.cmake = ..\scripts\cmake\vcpkg_build_qmake.cmake
+ ..\scripts\cmake\vcpkg_common_functions.cmake = ..\scripts\cmake\vcpkg_common_functions.cmake
+ ..\scripts\cmake\vcpkg_configure_cmake.cmake = ..\scripts\cmake\vcpkg_configure_cmake.cmake
+ ..\scripts\cmake\vcpkg_configure_meson.cmake = ..\scripts\cmake\vcpkg_configure_meson.cmake
+ ..\scripts\cmake\vcpkg_configure_qmake.cmake = ..\scripts\cmake\vcpkg_configure_qmake.cmake
+ ..\scripts\cmake\vcpkg_copy_pdbs.cmake = ..\scripts\cmake\vcpkg_copy_pdbs.cmake
+ ..\scripts\cmake\vcpkg_copy_tool_dependencies.cmake = ..\scripts\cmake\vcpkg_copy_tool_dependencies.cmake
+ ..\scripts\cmake\vcpkg_download_distfile.cmake = ..\scripts\cmake\vcpkg_download_distfile.cmake
+ ..\scripts\cmake\vcpkg_execute_required_process.cmake = ..\scripts\cmake\vcpkg_execute_required_process.cmake
+ ..\scripts\cmake\vcpkg_execute_required_process_repeat.cmake = ..\scripts\cmake\vcpkg_execute_required_process_repeat.cmake
+ ..\scripts\cmake\vcpkg_extract_source_archive.cmake = ..\scripts\cmake\vcpkg_extract_source_archive.cmake
+ ..\scripts\cmake\vcpkg_find_acquire_program.cmake = ..\scripts\cmake\vcpkg_find_acquire_program.cmake
+ ..\scripts\cmake\vcpkg_fixup_cmake_targets.cmake = ..\scripts\cmake\vcpkg_fixup_cmake_targets.cmake
+ ..\scripts\cmake\vcpkg_from_bitbucket.cmake = ..\scripts\cmake\vcpkg_from_bitbucket.cmake
+ ..\scripts\cmake\vcpkg_from_github.cmake = ..\scripts\cmake\vcpkg_from_github.cmake
+ ..\scripts\cmake\vcpkg_get_program_files_32_bit.cmake = ..\scripts\cmake\vcpkg_get_program_files_32_bit.cmake
+ ..\scripts\cmake\vcpkg_get_program_files_platform_bitness.cmake = ..\scripts\cmake\vcpkg_get_program_files_platform_bitness.cmake
+ ..\scripts\cmake\vcpkg_get_windows_sdk.cmake = ..\scripts\cmake\vcpkg_get_windows_sdk.cmake
+ ..\scripts\cmake\vcpkg_install_cmake.cmake = ..\scripts\cmake\vcpkg_install_cmake.cmake
+ ..\scripts\cmake\vcpkg_install_meson.cmake = ..\scripts\cmake\vcpkg_install_meson.cmake
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@@ -55,4 +100,10 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
+ GlobalSection(NestedProjects) = preSolution
+ {A0122231-04D5-420B-81CA-7960946E5E65} = {F5893B21-EA71-4432-84D6-5FB0E0461A2A}
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {DEDCC7AF-0FE6-4387-9FFE-495D6C1AEE1B}
+ EndGlobalSection
EndGlobal

[vcpkg] Improve external toolchain handling.