Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset PROCESSOR_ARCHITECTURE on start #1297

Merged
merged 1 commit into from
Dec 11, 2023
Merged
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
4 changes: 4 additions & 0 deletions include/vcpkg/base/message-data.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2705,6 +2705,10 @@ DECLARE_MESSAGE(UnexpectedToolOutput,
(msg::tool_name, msg::path),
"The actual command line output will be appended after this message.",
"{tool_name} ({path}) produced unexpected output when attempting to determine the version:")
DECLARE_MESSAGE(UnexpectedWindowsArchitecture,
(msg::actual),
"{actual} is the CPU kind we observed like ARM or MIPS",
"unexpected Windows host architecture: {actual}")
DECLARE_MESSAGE(UnknownBaselineFileContent,
(),
"",
Expand Down
2 changes: 2 additions & 0 deletions include/vcpkg/base/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ namespace vcpkg
ExpectedL<std::string> get_registry_string(void* base_hkey, StringView subkey, StringView valuename);

ExpectedL<std::uint32_t> get_registry_dword(void* base_hkey, StringView subkey, StringView valuename);

void reset_processor_architecture_environment_variable();
#endif

long get_process_id();
Expand Down
2 changes: 2 additions & 0 deletions locales/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,8 @@
"_UnexpectedSwitch.comment": "Switch is a command line switch like --switch An example of {option} is editable.",
"UnexpectedToolOutput": "{tool_name} ({path}) produced unexpected output when attempting to determine the version:",
"_UnexpectedToolOutput.comment": "The actual command line output will be appended after this message. An example of {tool_name} is aria2. An example of {path} is /foo/bar.",
"UnexpectedWindowsArchitecture": "unexpected Windows host architecture: {actual}",
"_UnexpectedWindowsArchitecture.comment": "{actual} is the CPU kind we observed like ARM or MIPS",
"UnknownBaselineFileContent": "unrecognizable baseline entry; expected 'port:triplet=(fail|skip|pass)'",
"UnknownBinaryProviderType": "unknown binary provider type: valid providers are 'clear', 'default', 'nuget', 'nugetconfig','nugettimeout', 'interactive', 'x-azblob', 'x-gcs', 'x-aws', 'x-aws-config', 'http', and 'files'",
"UnknownBooleanSetting": "unknown boolean setting for {option}: \"{value}\". Valid values are '', '1', '0', 'ON', 'OFF', 'TRUE', and 'FALSE'.",
Expand Down
2 changes: 2 additions & 0 deletions src/vcpkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ int main(const int argc, const char* const* const argv)
SetConsoleOutputCP(CP_UTF8);

initialize_global_job_object();

reset_processor_architecture_environment_variable();
#else
static const char* const utf8_locales[] = {
"C.UTF-8",
Expand Down
22 changes: 22 additions & 0 deletions src/vcpkg/base/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,28 @@ namespace vcpkg

return std::move(maybe_k).error();
}

void reset_processor_architecture_environment_variable()
{
// sometimes we get launched with incorrectly set %PROCESSOR_ARCHITECTURE%; this
// corrects that as we launch a lot of bits like CMake that expect it to be correctly set:
// https://cmake.org/cmake/help/latest/variable/CMAKE_HOST_SYSTEM_PROCESSOR.html#windows-platforms
const wchar_t* value;
const auto proc = get_host_processor();
switch (proc)
{
case CPUArchitecture::X86: value = L"X86"; break;
case CPUArchitecture::X64: value = L"AMD64"; break;
case CPUArchitecture::ARM: value = L"ARM"; break;
case CPUArchitecture::ARM64: value = L"ARM64"; break;
default:
Checks::msg_exit_with_error(
VCPKG_LINE_INFO, msgUnexpectedWindowsArchitecture, msg::actual = to_zstring_view(proc));
break;
}

Checks::check_exit(VCPKG_LINE_INFO, SetEnvironmentVariableW(L"PROCESSOR_ARCHITECTURE", value) != 0);
}
#endif

static const Optional<Path>& get_program_files()
Expand Down