diff options
Diffstat (limited to 'toolsrc')
| -rw-r--r-- | toolsrc/include/vcpkg/base/system.h | 2 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/base/system.cpp | 5 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/build.cpp | 18 |
3 files changed, 25 insertions, 0 deletions
diff --git a/toolsrc/include/vcpkg/base/system.h b/toolsrc/include/vcpkg/base/system.h index 0245b684a..907a692a2 100644 --- a/toolsrc/include/vcpkg/base/system.h +++ b/toolsrc/include/vcpkg/base/system.h @@ -28,4 +28,6 @@ namespace vcpkg::System const Optional<fs::path>& get_program_files_32_bit(); const Optional<fs::path>& get_program_files_platform_bitness(); + + int get_num_logical_cores(); } diff --git a/toolsrc/src/vcpkg/base/system.cpp b/toolsrc/src/vcpkg/base/system.cpp index 48a701bfa..a11853524 100644 --- a/toolsrc/src/vcpkg/base/system.cpp +++ b/toolsrc/src/vcpkg/base/system.cpp @@ -596,6 +596,11 @@ namespace vcpkg #else void System::register_console_ctrl_handler() {} #endif + + int System::get_num_logical_cores() + { + return std::thread::hardware_concurrency(); + } } namespace vcpkg::Debug diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp index 7bd6f467b..0a7c854b5 100644 --- a/toolsrc/src/vcpkg/build.cpp +++ b/toolsrc/src/vcpkg/build.cpp @@ -334,6 +334,23 @@ namespace vcpkg::Build return ret;
}
+ static int get_concurrency()
+ {
+ static int concurrency = []{
+ auto user_defined_concurrency = System::get_environment_variable("VCPKG_MAX_CONCURRENCY");
+ if (user_defined_concurrency)
+ {
+ return std::stoi(user_defined_concurrency.value_or_exit(VCPKG_LINE_INFO));
+ }
+ else
+ {
+ return System::get_num_logical_cores() + 1;
+ }
+ }();
+
+ return concurrency;
+ }
+
static ExtendedBuildResult do_build_package(const VcpkgPaths& paths,
const PreBuildInfo& pre_build_info,
const PackageSpec& spec,
@@ -372,6 +389,7 @@ namespace vcpkg::Build {"_VCPKG_DOWNLOAD_TOOL", to_string(config.build_package_options.download_tool)},
{"FEATURES", Strings::join(";", config.feature_list)},
{"ALL_FEATURES", all_features},
+ {"VCPKG_CONCURRENCY", std::to_string(get_concurrency())},
};
if (!System::get_environment_variable("VCPKG_FORCE_SYSTEM_BINARIES").has_value())
|
