-
Notifications
You must be signed in to change notification settings - Fork 74
Pin MSVC toolchain and add automatic min version check #2296
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| #pragma comment(lib, "Version.lib") | ||
|
|
||
| #include <Windows.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include "c4Log.h" | ||
|
|
||
| typedef struct { | ||
| WORD major; | ||
| WORD minor; | ||
| WORD build; | ||
| WORD revision; | ||
| } Version; | ||
|
|
||
| static int GetDllVersion(const wchar_t* path, Version* out_version) { | ||
| DWORD dummy; | ||
| DWORD size = GetFileVersionInfoSizeW(path, &dummy); | ||
| if ( size == 0 ) { return 0; } | ||
|
|
||
| BYTE* buffer = (BYTE*)malloc(size); | ||
| if ( !buffer ) { return 0; } | ||
| if ( !GetFileVersionInfoW(path, 0, size, buffer) ) { | ||
| c4log(kC4DefaultLog, kC4LogVerbose, "GetFileVersionInfoW failed: %lu", GetLastError()); | ||
| free(buffer); | ||
| return 0; | ||
| } | ||
|
|
||
| VS_FIXEDFILEINFO* fileInfo; | ||
| UINT len = 0; | ||
| if ( !VerQueryValueA(buffer, "\\", (LPVOID*)&fileInfo, &len) ) { | ||
| c4log(kC4DefaultLog, kC4LogVerbose, "VerQueryValueA failed: %lu", GetLastError()); | ||
| free(buffer); | ||
| return 0; | ||
| } | ||
|
|
||
| if ( fileInfo ) { | ||
| out_version->major = HIWORD(fileInfo->dwFileVersionMS); | ||
| out_version->minor = LOWORD(fileInfo->dwFileVersionMS); | ||
| out_version->build = HIWORD(fileInfo->dwFileVersionLS); | ||
| out_version->revision = LOWORD(fileInfo->dwFileVersionLS); | ||
| free(buffer); | ||
| return 1; | ||
| } | ||
|
|
||
| c4log(kC4DefaultLog, kC4LogVerbose, "VerQueryValueA returned NULL"); | ||
| free(buffer); | ||
| return 0; | ||
| } | ||
|
|
||
| static int CompareVersions(const Version* a, const Version* b) { | ||
| if ( a->major != b->major ) return a->major < b->major ? -1 : 1; | ||
| if ( a->minor != b->minor ) return a->minor < b->minor ? -1 : 1; | ||
| if ( a->build != b->build ) return a->build < b->build ? -1 : 1; | ||
| if ( a->revision != b->revision ) return a->revision < b->revision ? -1 : 1; | ||
| return 0; | ||
| } | ||
|
|
||
| void CheckCppRuntime() { | ||
| HMODULE hMod = GetModuleHandleA("msvcp140.dll"); | ||
| if ( !hMod ) { hMod = LoadLibraryA("msvcp140d.dll"); } | ||
|
|
||
| if ( !hMod ) { | ||
| c4log(kC4DefaultLog, kC4LogWarning, "msvcp140.dll not loaded yet, unable to check version..."); | ||
| return; | ||
| } | ||
|
|
||
| wchar_t path[MAX_PATH]; | ||
| if ( GetModuleFileNameW(hMod, path, MAX_PATH) == 0 ) { | ||
| c4log(kC4DefaultLog, kC4LogWarning, "Unable to determine msvcp140.dll filename to check version..."); | ||
| return; | ||
| } | ||
|
|
||
| Version loaded = {0}; | ||
| if ( !GetDllVersion(path, &loaded) ) { | ||
| c4log(kC4DefaultLog, kC4LogWarning, "Unable to get version of msvcp140.dll to check..."); | ||
| return; | ||
| } | ||
|
|
||
| Version expected = {14, 36, 32457, 0}; | ||
| int cmp = CompareVersions(&loaded, &expected); | ||
| if ( cmp < 0 ) { | ||
| c4log(kC4DefaultLog, kC4LogWarning, "msvcp140.dll version is older than expected: %u.%u.%u.%u < %u.%u.%u.%u", | ||
| loaded.major, loaded.minor, loaded.revision, loaded.build, expected.major, expected.minor, | ||
| expected.revision, expected.build); | ||
| c4log(kC4DefaultLog, kC4LogWarning, "This may cause instability in your application"); | ||
| } | ||
| } | ||
|
|
||
| BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { | ||
| switch ( ul_reason_for_call ) { | ||
| case DLL_PROCESS_ATTACH: | ||
| CheckCppRuntime(); | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| return TRUE; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The order of version numbers is inconsistent with the defined version structure; the 'build' value should be printed before the 'revision' to correctly reflect the version as major.minor.build.revision.