[vcpkg] Improve handling of external toolchain files
MODIFY
include/vcpkg/base/cofffilereader.h
include/vcpkg/base/cofffilereader.h
@@ -17,7 +17,9 @@ namespace vcpkg::CoffFileReader
std::vector<MachineType> machine_types;
};
+#if defined(_WIN32)
DllInfo read_dll(const fs::path& path);
LibInfo read_lib(const fs::path& path);
+#endif
}

MODIFY
src/vcpkg/base/cofffilereader.cpp
src/vcpkg/base/cofffilereader.cpp
@@ -306,8 +306,5 @@ namespace vcpkg::CoffFileReader
return {std::vector<MachineType>(machine_types.cbegin(), machine_types.cend())};
}
-#else
- DllInfo read_dll(const fs::path& path) { exit(-1); }
- LibInfo read_lib(const fs::path& path) { exit(-1); }
#endif
}

MODIFY
src/vcpkg/build.cpp
src/vcpkg/build.cpp
@@ -208,9 +208,7 @@ 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));
+ if (pre_build_info.external_toolchain_file.has_value()) return "";
const char* tonull = " >nul";
if (GlobalState::debugging)
@@ -479,8 +477,9 @@ namespace vcpkg::Build
{"ALL_FEATURES", all_features},
});
- const auto cmd_set_environment = make_build_env_cmd(pre_build_info, toolset);
- const std::string command = Strings::format(R"(%s && %s)", cmd_set_environment, cmd_launch_cmake);
+ auto command = make_build_env_cmd(pre_build_info, toolset);
+ if (!command.empty()) command.append(" && ");
+ command.append(cmd_launch_cmake);
const auto timer = Chrono::ElapsedTimer::create_started();

MODIFY
src/vcpkg/commands.env.cpp
src/vcpkg/commands.env.cpp
@@ -21,7 +21,11 @@ namespace vcpkg::Commands::Env
const auto pre_build_info = Build::PreBuildInfo::from_triplet_file(paths, default_triplet);
const Toolset& toolset = paths.get_toolset(pre_build_info);
- System::cmd_execute_clean(Build::make_build_env_cmd(pre_build_info, toolset) + " && cmd");
+ auto env_cmd = Build::make_build_env_cmd(pre_build_info, toolset);
+ if (env_cmd.empty())
+ System::cmd_execute_clean("cmd");
+ else
+ System::cmd_execute_clean(env_cmd + " && cmd");
Checks::exit_success(VCPKG_LINE_INFO);
}

MODIFY
src/vcpkg/postbuildlint.cpp
src/vcpkg/postbuildlint.cpp
@@ -391,6 +391,7 @@ namespace vcpkg::PostBuildLint
static LintStatus check_dll_architecture(const std::string& expected_architecture,
const std::vector<fs::path>& files)
{
+#if defined(_WIN32)
std::vector<FileAndArch> binaries_with_invalid_architecture;
for (const fs::path& file : files)
@@ -413,6 +414,7 @@ namespace vcpkg::PostBuildLint
print_invalid_architecture_files(expected_architecture, binaries_with_invalid_architecture);
return LintStatus::ERROR_DETECTED;
}
+#endif
return LintStatus::SUCCESS;
}
@@ -420,6 +422,7 @@ namespace vcpkg::PostBuildLint
static LintStatus check_lib_architecture(const std::string& expected_architecture,
const std::vector<fs::path>& files)
{
+#if defined(_WIN32)
std::vector<FileAndArch> binaries_with_invalid_architecture;
for (const fs::path& file : files)
@@ -451,6 +454,7 @@ namespace vcpkg::PostBuildLint
print_invalid_architecture_files(expected_architecture, binaries_with_invalid_architecture);
return LintStatus::ERROR_DETECTED;
}
+#endif
return LintStatus::SUCCESS;
}
@@ -790,11 +794,15 @@ namespace vcpkg::PostBuildLint
dlls.insert(dlls.cend(), debug_dlls.cbegin(), debug_dlls.cend());
dlls.insert(dlls.cend(), release_dlls.cbegin(), release_dlls.cend());
+ if (!toolset.dumpbin.empty())
+ {
error_count += check_exports_of_dlls(dlls, toolset.dumpbin);
error_count += check_uwp_bit_of_dlls(pre_build_info.cmake_system_name, dlls, toolset.dumpbin);
- error_count += check_dll_architecture(pre_build_info.target_architecture, dlls);
+ error_count +=
+ check_outdated_crt_linkage_of_dlls(dlls, toolset.dumpbin, build_info, pre_build_info);
+ }
- error_count += check_outdated_crt_linkage_of_dlls(dlls, toolset.dumpbin, build_info, pre_build_info);
+ error_count += check_dll_architecture(pre_build_info.target_architecture, dlls);
break;
}
case Build::LinkageType::STATIC:
@@ -805,6 +813,8 @@ namespace vcpkg::PostBuildLint
error_count += check_bin_folders_are_not_present_in_static_build(fs, package_dir);
+ if (!toolset.dumpbin.empty())
+ {
if (!build_info.policies.is_enabled(BuildPolicy::ONLY_RELEASE_CRT))
{
error_count += check_crt_linkage_of_libs(
@@ -816,6 +826,7 @@ namespace vcpkg::PostBuildLint
BuildType::value_of(Build::ConfigurationType::RELEASE, build_info.crt_linkage),
release_libs,
toolset.dumpbin);
+ }
break;
}
default: Checks::unreachable(VCPKG_LINE_INFO);

MODIFY
src/vcpkg/vcpkgpaths.cpp
src/vcpkg/vcpkgpaths.cpp
@@ -628,13 +628,8 @@ namespace vcpkg
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 = "";
ret.vcvarsall_options = {};
-#endif
ret.version = "external";
ret.visual_studio_root_path = "";
return ret;

[vcpkg] Improve handling of external toolchain files