Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/vcpkg/base/message-data.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,7 @@ DECLARE_MESSAGE(HelpTxtOptManifestFeature,
(),
"",
"Additional features from the top-level manifest to install (manifest mode)")
DECLARE_MESSAGE(HelpTxtBuildType, (), "", "Build type (debug, release or both if not specified) (manifest mode)")
DECLARE_MESSAGE(HelpTxtOptManifestNoDefault,
(),
"",
Expand Down
4 changes: 3 additions & 1 deletion include/vcpkg/cmakevars.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <vcpkg/fwd/build.h>
#include <vcpkg/fwd/dependencies.h>
#include <vcpkg/fwd/portfileprovider.h>
#include <vcpkg/fwd/vcpkgpaths.h>
Expand Down Expand Up @@ -35,5 +36,6 @@ namespace vcpkg::CMakeVars
virtual void load_tag_vars(const ActionPlan& action_plan, Triplet host_triplet) const = 0;
};

std::unique_ptr<CMakeVarProvider> make_triplet_cmake_var_provider(const VcpkgPaths& paths);
std::unique_ptr<CMakeVarProvider> make_triplet_cmake_var_provider(
const VcpkgPaths& paths, ConfigurationType default_build_type = ConfigurationType::BOTH);
}
8 changes: 7 additions & 1 deletion include/vcpkg/commands.build.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ namespace vcpkg
StringLiteral to_string_view(DownloadTool tool);
std::string to_string(DownloadTool tool);

StringLiteral to_string_view(ConfigurationType config_type);
std::string to_string(ConfigurationType config_type);

struct BuildPackageOptions
{
BuildMissing build_missing;
Expand All @@ -74,6 +77,7 @@ namespace vcpkg
Editable editable;
BackcompatFeatures backcompat_features;
PrintUsage print_usage;
ConfigurationType build_type;
};

static constexpr BuildPackageOptions default_build_package_options{
Expand All @@ -89,6 +93,7 @@ namespace vcpkg
Editable::NO,
BackcompatFeatures::ALLOW,
PrintUsage::YES,
ConfigurationType::BOTH,
};

static constexpr BuildPackageOptions backcompat_prohibiting_package_options{
Expand All @@ -104,6 +109,7 @@ namespace vcpkg
Editable::NO,
BackcompatFeatures::PROHIBIT,
PrintUsage::YES,
ConfigurationType::BOTH,
};

struct BuildResultCounts
Expand Down Expand Up @@ -157,7 +163,7 @@ namespace vcpkg
Optional<std::string> platform_toolset_version;
Optional<Path> visual_studio_path;
Optional<std::string> external_toolchain_file;
Optional<ConfigurationType> build_type;
ConfigurationType build_type;
Optional<std::string> public_abi_override;
std::vector<std::string> passthrough_env_vars;
std::vector<std::string> passthrough_env_vars_tracked;
Expand Down
1 change: 1 addition & 0 deletions include/vcpkg/fwd/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace vcpkg

enum class ConfigurationType
{
BOTH,
DEBUG,
RELEASE,
};
Expand Down
1 change: 1 addition & 0 deletions locales/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@
"HelpTextOptFullDesc": "Does not truncate long text",
"HelpTopicCommand": "Displays specific help topic",
"HelpTopicsCommand": "Displays full list of help topics",
"HelpTxtBuildType": "Build type (debug, release or both if not specified) (manifest mode)",
"HelpTxtOptAllowUnsupportedPort": "Continues with a warning on unsupported ports, rather than failing",
"HelpTxtOptCleanAfterBuild": "Cleans buildtrees, packages and downloads after building each package",
"HelpTxtOptCleanBuildTreesAfterBuild": "Cleans buildtrees after building each package",
Expand Down
27 changes: 18 additions & 9 deletions src/vcpkg/cmakevars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ namespace vcpkg::CMakeVars
{
struct TripletCMakeVarProvider : CMakeVarProvider
{
explicit TripletCMakeVarProvider(const vcpkg::VcpkgPaths& paths) : paths(paths) { }
explicit TripletCMakeVarProvider(const vcpkg::VcpkgPaths& paths, ConfigurationType default_build_type)
: paths(paths), default_build_type(default_build_type)
{
}
TripletCMakeVarProvider(const TripletCMakeVarProvider&) = delete;
TripletCMakeVarProvider& operator=(const TripletCMakeVarProvider&) = delete;

Expand Down Expand Up @@ -60,26 +63,32 @@ namespace vcpkg::CMakeVars
std::vector<std::vector<std::pair<std::string, std::string>>>& vars) const;

const VcpkgPaths& paths;
const ConfigurationType default_build_type;
mutable std::unordered_map<PackageSpec, std::unordered_map<std::string, std::string>> dep_resolution_vars;
mutable std::unordered_map<PackageSpec, std::unordered_map<std::string, std::string>> tag_vars;
mutable std::unordered_map<Triplet, std::unordered_map<std::string, std::string>> generic_triplet_vars;
};
}

std::unique_ptr<CMakeVarProvider> make_triplet_cmake_var_provider(const vcpkg::VcpkgPaths& paths)
std::unique_ptr<CMakeVarProvider> make_triplet_cmake_var_provider(const vcpkg::VcpkgPaths& paths,
ConfigurationType default_build_type)
{
return std::make_unique<TripletCMakeVarProvider>(paths);
return std::make_unique<TripletCMakeVarProvider>(paths, default_build_type);
}

static std::string create_extraction_file_prelude(const VcpkgPaths& paths,
const std::map<Triplet, int>& emitted_triplets)
const std::map<Triplet, int>& emitted_triplets,
ConfigurationType default_build_type)
{
const auto& fs = paths.get_filesystem();
std::string extraction_file;

extraction_file.append("cmake_minimum_required(VERSION 3.5)\n"
"macro(vcpkg_triplet_file VCPKG_TRIPLET_ID)\n"
"set(_vcpkg_triplet_file_BACKUP_CURRENT_LIST_FILE \"${CMAKE_CURRENT_LIST_FILE}\")\n");
fmt::format_to(std::back_inserter(extraction_file),
"cmake_minimum_required(VERSION 3.5)\n"
"macro(vcpkg_triplet_file VCPKG_TRIPLET_ID)\n"
"set(VCPKG_BUILD_TYPE \"{}\")\n"
"set(_vcpkg_triplet_file_BACKUP_CURRENT_LIST_FILE \"${{CMAKE_CURRENT_LIST_FILE}}\")\n",
to_string(default_build_type));

for (auto&& p : emitted_triplets)
{
Expand Down Expand Up @@ -116,7 +125,7 @@ endmacro()
{
emitted_triplets[spec_abi_setting.first.package_spec.triplet()] = emitted_triplet_id++;
}
std::string extraction_file = create_extraction_file_prelude(paths, emitted_triplets);
std::string extraction_file = create_extraction_file_prelude(paths, emitted_triplets, default_build_type);

// The variables collected here are those necessary to perform builds.
extraction_file.append(R"(
Expand Down Expand Up @@ -196,7 +205,7 @@ endfunction()
emitted_triplets[spec.triplet()] = emitted_triplet_id++;
}

std::string extraction_file = create_extraction_file_prelude(paths, emitted_triplets);
std::string extraction_file = create_extraction_file_prelude(paths, emitted_triplets, default_build_type);

// The variables collected here are those necessary to perform dependency resolution.
// If a value affects platform expressions, it must be here.
Expand Down
23 changes: 22 additions & 1 deletion src/vcpkg/commands.build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,18 @@ namespace vcpkg

std::string to_string(DownloadTool tool) { return to_string_view(tool).to_string(); }

StringLiteral to_string_view(ConfigurationType config_type)
{
switch (config_type)
{
case ConfigurationType::DEBUG: return "debug";
case ConfigurationType::RELEASE: return "release";
default: return "";
}
}

std::string to_string(ConfigurationType config_type) { return to_string_view(config_type).to_string(); }

Optional<LinkageType> to_linkage_type(StringView str)
{
if (str == "dynamic") return LinkageType::DYNAMIC;
Expand Down Expand Up @@ -777,6 +789,11 @@ namespace vcpkg
variables.emplace_back("ARIA2", paths.get_tool_exe(Tools::ARIA2, stdout_sink));
}

if (action.build_options.build_type != ConfigurationType::BOTH)
{
variables.emplace_back("VCPKG_DEFAULT_BUILD_TYPE", to_string(action.build_options.build_type));
}

if (auto cmake_debug = args.cmake_debug.get())
{
if (cmake_debug->is_port_affected(scf.core_paragraph->name))
Expand Down Expand Up @@ -1166,6 +1183,10 @@ namespace vcpkg
const auto& triplet_canonical_name = action.spec.triplet().canonical_name();
abi_tag_entries.emplace_back("triplet", triplet_canonical_name);
abi_tag_entries.emplace_back("triplet_abi", triplet_abi);
if (action.build_options.build_type != ConfigurationType::BOTH)
{
abi_tag_entries.emplace_back("build_type", to_string(action.build_options.build_type));
}
auto& fs = paths.get_filesystem();
abi_entries_from_pre_build_info(fs, grdk_cache, pre_build_info, abi_tag_entries);

Expand Down Expand Up @@ -1789,7 +1810,7 @@ namespace vcpkg
break;
case VcpkgTripletVar::BUILD_TYPE:
if (variable_value.empty())
build_type = nullopt;
build_type = ConfigurationType::BOTH;
else if (Strings::case_insensitive_ascii_equals(variable_value, "debug"))
build_type = ConfigurationType::DEBUG;
else if (Strings::case_insensitive_ascii_equals(variable_value, "release"))
Expand Down
34 changes: 32 additions & 2 deletions src/vcpkg/commands.install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ namespace vcpkg
static constexpr StringLiteral OPTION_ENFORCE_PORT_CHECKS = "enforce-port-checks";
static constexpr StringLiteral OPTION_ALLOW_UNSUPPORTED_PORT = "allow-unsupported";
static constexpr StringLiteral OPTION_NO_PRINT_USAGE = "no-print-usage";
static constexpr StringLiteral OPTION_DEFAULT_BUILD_TYPE = "x-build-type";

static constexpr CommandSwitch INSTALL_SWITCHES[] = {
{OPTION_DRY_RUN, msgHelpTxtOptDryRun},
Expand All @@ -643,6 +644,7 @@ namespace vcpkg
static constexpr CommandSetting INSTALL_SETTINGS[] = {
{OPTION_XUNIT, {}}, // internal use
{OPTION_WRITE_PACKAGES_CONFIG, msgHelpTxtOptWritePkgConfig},
{OPTION_DEFAULT_BUILD_TYPE, msgHelpTxtBuildType},
};

static constexpr CommandMultiSetting INSTALL_MULTISETTINGS[] = {
Expand Down Expand Up @@ -1017,6 +1019,7 @@ namespace vcpkg
: UnsupportedPortAction::Error;
const PrintUsage print_cmake_usage =
Util::Sets::contains(options.switches, OPTION_NO_PRINT_USAGE) ? PrintUsage::NO : PrintUsage::YES;
ConfigurationType build_type = ConfigurationType::BOTH;

get_global_metrics_collector().track_bool(BoolMetric::InstallManifestMode, paths.manifest_mode_enabled());

Expand All @@ -1039,6 +1042,27 @@ namespace vcpkg
msg::println_error(msgErrorInvalidManifestModeOption, msg::option = OPTION_EDITABLE);
failure = true;
}
if (auto it = options.settings.find(OPTION_DEFAULT_BUILD_TYPE); it != options.settings.end())
{
auto& str = it->second;
if (str.empty())
{
build_type = ConfigurationType::BOTH;
}
else if (Strings::case_insensitive_ascii_equals(str, "debug"))
{
build_type = ConfigurationType::DEBUG;
}
else if (Strings::case_insensitive_ascii_equals(str, "release"))
{
build_type = ConfigurationType::RELEASE;
}
else
{
msg::println_error(msgUnknownSettingForBuildType, msg::option = str);
failure = true;
}
}
if (failure)
{
msg::println(msgUsingManifestAt, msg::path = p->path);
Expand Down Expand Up @@ -1066,6 +1090,11 @@ namespace vcpkg
msg::println_error(msgErrorInvalidClassicModeOption, msg::option = OPTION_MANIFEST_FEATURE);
failure = true;
}
if (Util::Sets::contains(options.settings, OPTION_DEFAULT_BUILD_TYPE))
{
msg::println_error(msgErrorInvalidClassicModeOption, msg::option = OPTION_DEFAULT_BUILD_TYPE);
failure = true;
}
if (failure)
{
print_usage(CommandInstallMetadataClassic);
Expand All @@ -1090,9 +1119,10 @@ namespace vcpkg
PurgeDecompressFailure::NO,
Util::Enum::to_enum<Editable>(is_editable),
prohibit_backcompat_features ? BackcompatFeatures::PROHIBIT : BackcompatFeatures::ALLOW,
print_cmake_usage};
print_cmake_usage,
build_type};

auto var_provider_storage = CMakeVars::make_triplet_cmake_var_provider(paths);
auto var_provider_storage = CMakeVars::make_triplet_cmake_var_provider(paths, build_type);
auto& var_provider = *var_provider_storage;

const CreateInstallPlanOptions create_options{host_triplet, paths.packages(), unsupported_port_action};
Expand Down
5 changes: 3 additions & 2 deletions src/vcpkg/postbuildlint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,8 @@ namespace vcpkg
std::vector<Path> release_libs = fs.get_regular_files_recursive(release_lib_dir, IgnoreErrors{});
Util::erase_remove_if(release_libs, lib_filter);

if (!pre_build_info.build_type && !build_info.policies.is_enabled(BuildPolicy::MISMATCHED_NUMBER_OF_BINARIES))
if (pre_build_info.build_type == ConfigurationType::BOTH &&
!build_info.policies.is_enabled(BuildPolicy::MISMATCHED_NUMBER_OF_BINARIES))
{
error_count += check_matching_debug_and_release_binaries(debug_libs, release_libs, msg_sink);
}
Expand Down Expand Up @@ -1424,7 +1425,7 @@ namespace vcpkg
{
case LinkageType::DYNAMIC:
{
if (!pre_build_info.build_type &&
if (pre_build_info.build_type == ConfigurationType::BOTH &&
!build_info.policies.is_enabled(BuildPolicy::MISMATCHED_NUMBER_OF_BINARIES))
error_count += check_matching_debug_and_release_binaries(debug_dlls, release_dlls, msg_sink);

Expand Down