mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Update microsoft_craziness.h to work correctly with the rest of the codebase (and not use WIN32_LEAN_AND_MEAN)
This commit is contained in:
@@ -7,6 +7,13 @@
|
|||||||
#include <intrin.h>
|
#include <intrin.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(GB_SYSTEM_WINDOWS)
|
||||||
|
#define NOMINMAX 1
|
||||||
|
#include <windows.h>
|
||||||
|
#undef NOMINMAX
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define GB_WINDOWS_H_INCLUDED
|
||||||
#define GB_IMPLEMENTATION
|
#define GB_IMPLEMENTATION
|
||||||
#include "gb/gb.h"
|
#include "gb/gb.h"
|
||||||
|
|
||||||
|
|||||||
@@ -291,14 +291,18 @@ extern "C" {
|
|||||||
#if defined(GB_SYSTEM_WINDOWS)
|
#if defined(GB_SYSTEM_WINDOWS)
|
||||||
#if !defined(GB_NO_WINDOWS_H)
|
#if !defined(GB_NO_WINDOWS_H)
|
||||||
#define NOMINMAX 1
|
#define NOMINMAX 1
|
||||||
|
#if !defined(GB_WINDOWS_H_INCLUDED)
|
||||||
#define WIN32_LEAN_AND_MEAN 1
|
#define WIN32_LEAN_AND_MEAN 1
|
||||||
#define WIN32_MEAN_AND_LEAN 1
|
#define WIN32_MEAN_AND_LEAN 1
|
||||||
#define VC_EXTRALEAN 1
|
#define VC_EXTRALEAN 1
|
||||||
|
#endif
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#undef NOMINMAX
|
#undef NOMINMAX
|
||||||
|
#if !defined(GB_WINDOWS_H_INCLUDED)
|
||||||
#undef WIN32_LEAN_AND_MEAN
|
#undef WIN32_LEAN_AND_MEAN
|
||||||
#undef WIN32_MEAN_AND_LEAN
|
#undef WIN32_MEAN_AND_LEAN
|
||||||
#undef VC_EXTRALEAN
|
#undef VC_EXTRALEAN
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <malloc.h> // NOTE(bill): _aligned_*()
|
#include <malloc.h> // NOTE(bill): _aligned_*()
|
||||||
|
|||||||
+18
-13
@@ -25,7 +25,7 @@ gb_global Timings global_timings = {0};
|
|||||||
#if defined(GB_SYSTEM_WINDOWS)
|
#if defined(GB_SYSTEM_WINDOWS)
|
||||||
// NOTE(IC): In order to find Visual C++ paths without relying on environment variables.
|
// NOTE(IC): In order to find Visual C++ paths without relying on environment variables.
|
||||||
#include "microsoft_craziness.h"
|
#include "microsoft_craziness.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// NOTE(bill): 'name' is used in debugging and profiling modes
|
// NOTE(bill): 'name' is used in debugging and profiling modes
|
||||||
@@ -1179,25 +1179,30 @@ int main(int arg_count, char **arg_ptr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NOTE(ic): It would be nice to extend this so that we could specify the Visual Studio version that we want instead of defaulting to the latest.
|
// NOTE(ic): It would be nice to extend this so that we could specify the Visual Studio version that we want instead of defaulting to the latest.
|
||||||
Find_Result_Utf8 result = find_visual_studio_and_windows_sdk_utf8();
|
Find_Result_Utf8 find_result = find_visual_studio_and_windows_sdk_utf8();
|
||||||
defer(free_resources(&result));
|
// defer(free_resources(&find_result));
|
||||||
|
|
||||||
if (result.windows_sdk_version == 0) {
|
if (find_result.windows_sdk_version == 0) {
|
||||||
gb_printf_err("Windows SDK not found.\n");
|
gb_printf_err("Windows SDK not found.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add library search paths.
|
// Add library search paths.
|
||||||
link_settings = gb_string_append_fmt(link_settings, " /LIBPATH:\"%s\"", result.windows_sdk_um_library_path);
|
if (find_result.vs_library_path.len > 0) {
|
||||||
link_settings = gb_string_append_fmt(link_settings, " /LIBPATH:\"%s\"", result.windows_sdk_ucrt_library_path);
|
GB_ASSERT(find_result.windows_sdk_um_library_path.len > 0);
|
||||||
link_settings = gb_string_append_fmt(link_settings, " /LIBPATH:\"%s\"", result.vs_library_path);
|
GB_ASSERT(find_result.windows_sdk_ucrt_library_path.len > 0);
|
||||||
|
|
||||||
|
link_settings = gb_string_append_fmt(link_settings, " /LIBPATH:\"%.*s\"", LIT(find_result.vs_library_path));
|
||||||
|
link_settings = gb_string_append_fmt(link_settings, " /LIBPATH:\"%.*s\"", LIT(find_result.windows_sdk_um_library_path));
|
||||||
|
link_settings = gb_string_append_fmt(link_settings, " /LIBPATH:\"%.*s\"", LIT(find_result.windows_sdk_ucrt_library_path));
|
||||||
|
}
|
||||||
|
|
||||||
if (!build_context.use_lld) { // msvc
|
if (!build_context.use_lld) { // msvc
|
||||||
|
|
||||||
if (build_context.has_resource) {
|
if (build_context.has_resource) {
|
||||||
exit_code = system_exec_command_line_app("msvc-link",
|
exit_code = system_exec_command_line_app("msvc-link",
|
||||||
"\"%s\\rc.exe\" /nologo /fo \"%.*s.res\" \"%.*s.rc\"",
|
"\"%.*src.exe\" /nologo /fo \"%.*s.res\" \"%.*s.rc\"",
|
||||||
result.vs_exe_path,
|
LIT(find_result.vs_exe_path),
|
||||||
LIT(output_base),
|
LIT(output_base),
|
||||||
LIT(build_context.resource_filepath)
|
LIT(build_context.resource_filepath)
|
||||||
);
|
);
|
||||||
@@ -1207,23 +1212,23 @@ int main(int arg_count, char **arg_ptr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit_code = system_exec_command_line_app("msvc-link",
|
exit_code = system_exec_command_line_app("msvc-link",
|
||||||
"\"%s\\link.exe\" \"%.*s.obj\" \"%.*s.res\" -OUT:\"%.*s.%s\" %s "
|
"\"%.*slink.exe\" \"%.*s.obj\" \"%.*s.res\" -OUT:\"%.*s.%s\" %s "
|
||||||
"/nologo /incremental:no /opt:ref /subsystem:CONSOLE "
|
"/nologo /incremental:no /opt:ref /subsystem:CONSOLE "
|
||||||
" %.*s "
|
" %.*s "
|
||||||
" %s "
|
" %s "
|
||||||
"",
|
"",
|
||||||
result.vs_exe_path, LIT(output_base), LIT(output_base), LIT(output_base), output_ext,
|
LIT(find_result.vs_exe_path), LIT(output_base), LIT(output_base), LIT(output_base), output_ext,
|
||||||
lib_str, LIT(build_context.link_flags),
|
lib_str, LIT(build_context.link_flags),
|
||||||
link_settings
|
link_settings
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
exit_code = system_exec_command_line_app("msvc-link",
|
exit_code = system_exec_command_line_app("msvc-link",
|
||||||
"\"%s\\link.exe\" \"%.*s.obj\" -OUT:\"%.*s.%s\" %s "
|
"\"%.*slink.exe\" \"%.*s.obj\" -OUT:\"%.*s.%s\" %s "
|
||||||
"/nologo /incremental:no /opt:ref /subsystem:CONSOLE "
|
"/nologo /incremental:no /opt:ref /subsystem:CONSOLE "
|
||||||
" %.*s "
|
" %.*s "
|
||||||
" %s "
|
" %s "
|
||||||
"",
|
"",
|
||||||
result.vs_exe_path, LIT(output_base), LIT(output_base), output_ext,
|
LIT(find_result.vs_exe_path), LIT(output_base), LIT(output_base), output_ext,
|
||||||
lib_str, LIT(build_context.link_flags),
|
lib_str, LIT(build_context.link_flags),
|
||||||
link_settings
|
link_settings
|
||||||
);
|
);
|
||||||
|
|||||||
+112
-117
@@ -13,14 +13,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
//#include <windows.h>
|
#include <wtypesbase.h>
|
||||||
//#include <stdlib.h>
|
|
||||||
//#include <string.h>
|
|
||||||
//#include <assert.h>
|
|
||||||
//#include <stdio.h>
|
|
||||||
//#include <sys/stat.h>
|
|
||||||
|
|
||||||
//#include <stdint.h>
|
|
||||||
#include <io.h> // For _get_osfhandle
|
#include <io.h> // For _get_osfhandle
|
||||||
|
|
||||||
#pragma comment(lib, "Advapi32.lib")
|
#pragma comment(lib, "Advapi32.lib")
|
||||||
@@ -53,26 +46,29 @@
|
|||||||
// Here is the API you need to know about:
|
// Here is the API you need to know about:
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
|
gb_global gbAllocator mc_allocator = heap_allocator();
|
||||||
|
|
||||||
struct Find_Result {
|
struct Find_Result {
|
||||||
int windows_sdk_version; // Zero if no Windows SDK found.
|
int windows_sdk_version; // Zero if no Windows SDK found.
|
||||||
|
|
||||||
wchar_t *windows_sdk_root = NULL;
|
wchar_t *windows_sdk_root;
|
||||||
wchar_t *windows_sdk_um_library_path = NULL;
|
wchar_t *windows_sdk_um_library_path;
|
||||||
wchar_t *windows_sdk_ucrt_library_path = NULL;
|
wchar_t *windows_sdk_ucrt_library_path;
|
||||||
|
|
||||||
wchar_t *vs_exe_path = NULL;
|
wchar_t *vs_exe_path;
|
||||||
wchar_t *vs_library_path = NULL;
|
wchar_t *vs_library_path;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Find_Result_Utf8 {
|
struct Find_Result_Utf8 {
|
||||||
int windows_sdk_version; // Zero if no Windows SDK found.
|
int windows_sdk_version; // Zero if no Windows SDK found.
|
||||||
|
|
||||||
char *windows_sdk_root = NULL;
|
String windows_sdk_root;
|
||||||
char *windows_sdk_um_library_path = NULL;
|
String windows_sdk_um_library_path;
|
||||||
char *windows_sdk_ucrt_library_path = NULL;
|
String windows_sdk_ucrt_library_path;
|
||||||
|
|
||||||
char *vs_exe_path = NULL;
|
String vs_exe_path;
|
||||||
char *vs_library_path = NULL;
|
String vs_library_path;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -80,19 +76,20 @@ Find_Result find_visual_studio_and_windows_sdk();
|
|||||||
Find_Result_Utf8 find_visual_studio_and_windows_sdk_utf8();
|
Find_Result_Utf8 find_visual_studio_and_windows_sdk_utf8();
|
||||||
|
|
||||||
void free_resources(Find_Result *result) {
|
void free_resources(Find_Result *result) {
|
||||||
free(result->windows_sdk_root);
|
// free(result->windows_sdk_root);
|
||||||
free(result->windows_sdk_um_library_path);
|
// free(result->windows_sdk_um_library_path);
|
||||||
free(result->windows_sdk_ucrt_library_path);
|
// free(result->windows_sdk_ucrt_library_path);
|
||||||
free(result->vs_exe_path);
|
// free(result->vs_exe_path);
|
||||||
free(result->vs_library_path);
|
// free(result->vs_library_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_resources(Find_Result_Utf8 *result) {
|
void free_resources(Find_Result_Utf8 *result) {
|
||||||
free(result->windows_sdk_root);
|
// gbAllocator a = heap_allocator();
|
||||||
free(result->windows_sdk_um_library_path);
|
// gb_free(a, result->windows_sdk_root.text);
|
||||||
free(result->windows_sdk_ucrt_library_path);
|
// gb_free(a, result->windows_sdk_um_library_path.text);
|
||||||
free(result->vs_exe_path);
|
// gb_free(a, result->windows_sdk_ucrt_library_path.text);
|
||||||
free(result->vs_library_path);
|
// gb_free(a, result->vs_exe_path.text);
|
||||||
|
// gb_free(a, result->vs_library_path.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -115,10 +112,10 @@ void free_resources(Find_Result_Utf8 *result) {
|
|||||||
// I am not making this up: https://github.com/Microsoft/vswhere
|
// I am not making this up: https://github.com/Microsoft/vswhere
|
||||||
//
|
//
|
||||||
// Several people have therefore found the need to solve this problem
|
// Several people have therefore found the need to solve this problem
|
||||||
// themselves. We referred to some of these other solutions when
|
// themselves. We referred to some of these other solutions when
|
||||||
// figuring out what to do, most prominently ziglang's version,
|
// figuring out what to do, most prominently ziglang's version,
|
||||||
// by Ryan Saunderson.
|
// by Ryan Saunderson.
|
||||||
//
|
//
|
||||||
// I hate this kind of code. The fact that we have to do this at all
|
// I hate this kind of code. The fact that we have to do this at all
|
||||||
// is stupid, and the actual maneuvers we need to go through
|
// is stupid, and the actual maneuvers we need to go through
|
||||||
// are just painful. If programming were like this all the time,
|
// are just painful. If programming were like this all the time,
|
||||||
@@ -150,18 +147,6 @@ typedef WCHAR* BSTR;
|
|||||||
typedef const WCHAR* LPCOLESTR;
|
typedef const WCHAR* LPCOLESTR;
|
||||||
|
|
||||||
|
|
||||||
struct DECLSPEC_UUID("00000000-0000-0000-C000-000000000046") IUnknown
|
|
||||||
{
|
|
||||||
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) = 0;
|
|
||||||
virtual ULONG STDMETHODCALLTYPE AddRef(void) = 0;
|
|
||||||
virtual ULONG STDMETHODCALLTYPE Release(void) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern "C" HRESULT STDAPICALLTYPE CoInitialize(LPVOID pvReserved);
|
|
||||||
extern "C" HRESULT STDAPICALLTYPE CoCreateInstance(REFCLSID rclsid, IUnknown * pUnkOuter, DWORD dwClsContext, REFIID riid, LPVOID * ppv);
|
|
||||||
extern "C" void STDAPICALLTYPE SysFreeString(BSTR bstrString);
|
|
||||||
|
|
||||||
|
|
||||||
struct DECLSPEC_UUID("B41463C3-8866-43B5-BC33-2B0676F7F42E") DECLSPEC_NOVTABLE ISetupInstance : public IUnknown
|
struct DECLSPEC_UUID("B41463C3-8866-43B5-BC33-2B0676F7F42E") DECLSPEC_NOVTABLE ISetupInstance : public IUnknown
|
||||||
{
|
{
|
||||||
virtual HRESULT STDMETHODCALLTYPE GetInstanceId(BSTR* pbstrInstanceId) = 0;
|
virtual HRESULT STDMETHODCALLTYPE GetInstanceId(BSTR* pbstrInstanceId) = 0;
|
||||||
@@ -193,13 +178,13 @@ struct DECLSPEC_UUID("42843719-DB4C-46C2-8E7C-64F1816EFD5B") DECLSPEC_NOVTABLE I
|
|||||||
// The beginning of the actual code that does things.
|
// The beginning of the actual code that does things.
|
||||||
|
|
||||||
struct Version_Data {
|
struct Version_Data {
|
||||||
int32_t best_version[4]; // For Windows 8 versions, only two of these numbers are used.
|
i32 best_version[4]; // For Windows 8 versions, only two of these numbers are used.
|
||||||
wchar_t *best_name;
|
wchar_t *best_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool os_file_exists(wchar_t *name) {
|
bool os_file_exists(wchar_t *name) {
|
||||||
// @Robustness: What flags do we really want to check here?
|
// @Robustness: What flags do we really want to check here?
|
||||||
|
|
||||||
auto attrib = GetFileAttributesW(name);
|
auto attrib = GetFileAttributesW(name);
|
||||||
if (attrib == INVALID_FILE_ATTRIBUTES) return false;
|
if (attrib == INVALID_FILE_ATTRIBUTES) return false;
|
||||||
if (attrib & FILE_ATTRIBUTE_DIRECTORY) return false;
|
if (attrib & FILE_ATTRIBUTE_DIRECTORY) return false;
|
||||||
@@ -211,23 +196,19 @@ wchar_t *concat(wchar_t *a, wchar_t *b, wchar_t *c = nullptr, wchar_t *d = nullp
|
|||||||
// Concatenate up to 4 wide strings together. Allocated with malloc.
|
// Concatenate up to 4 wide strings together. Allocated with malloc.
|
||||||
// If you don't like that, use a programming language that actually
|
// If you don't like that, use a programming language that actually
|
||||||
// helps you with using custom allocators. Or just edit the code.
|
// helps you with using custom allocators. Or just edit the code.
|
||||||
|
|
||||||
auto len_a = wcslen(a);
|
|
||||||
auto len_b = wcslen(b);
|
|
||||||
|
|
||||||
size_t len_c = 0;
|
isize len_a = string16_len(a);
|
||||||
if (c) len_c = wcslen(c);
|
isize len_b = string16_len(b);
|
||||||
|
isize len_c = string16_len(c);
|
||||||
size_t len_d = 0;
|
isize len_d = string16_len(d);
|
||||||
if (d) len_d = wcslen(d);
|
|
||||||
|
|
||||||
wchar_t *result = (wchar_t *)malloc((len_a + len_b + len_c + len_d + 1) * 2);
|
wchar_t *result = (wchar_t *)malloc((len_a + len_b + len_c + len_d + 1) * 2);
|
||||||
memcpy(result, a, len_a*2);
|
gb_memmove(result, a, len_a*2);
|
||||||
memcpy(result + len_a, b, len_b*2);
|
gb_memmove(result + len_a, b, len_b*2);
|
||||||
|
|
||||||
|
if (c) gb_memmove(result + len_a + len_b, c, len_c * 2);
|
||||||
|
if (d) gb_memmove(result + len_a + len_b + len_c, d, len_d * 2);
|
||||||
|
|
||||||
if (c) memcpy(result + len_a + len_b, c, len_c * 2);
|
|
||||||
if (d) memcpy(result + len_a + len_b + len_c, d, len_d * 2);
|
|
||||||
|
|
||||||
result[len_a + len_b + len_c + len_d] = 0;
|
result[len_a + len_b + len_c + len_d] = 0;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -242,7 +223,7 @@ bool visit_files_w(wchar_t *dir_name, Version_Data *data, Visit_Proc_W proc) {
|
|||||||
|
|
||||||
auto wildcard_name = concat(dir_name, L"\\*");
|
auto wildcard_name = concat(dir_name, L"\\*");
|
||||||
defer (free(wildcard_name));
|
defer (free(wildcard_name));
|
||||||
|
|
||||||
WIN32_FIND_DATAW find_data;
|
WIN32_FIND_DATAW find_data;
|
||||||
auto handle = FindFirstFileW(wildcard_name, &find_data);
|
auto handle = FindFirstFileW(wildcard_name, &find_data);
|
||||||
if (handle == INVALID_HANDLE_VALUE) return false;
|
if (handle == INVALID_HANDLE_VALUE) return false;
|
||||||
@@ -251,16 +232,16 @@ bool visit_files_w(wchar_t *dir_name, Version_Data *data, Visit_Proc_W proc) {
|
|||||||
if ((find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (find_data.cFileName[0] != '.')) {
|
if ((find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (find_data.cFileName[0] != '.')) {
|
||||||
auto full_name = concat(dir_name, L"\\", find_data.cFileName);
|
auto full_name = concat(dir_name, L"\\", find_data.cFileName);
|
||||||
defer (free(full_name));
|
defer (free(full_name));
|
||||||
|
|
||||||
proc(find_data.cFileName, full_name, data);
|
proc(find_data.cFileName, full_name, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto success = FindNextFileW(handle, &find_data);
|
auto success = FindNextFileW(handle, &find_data);
|
||||||
if (!success) break;
|
if (!success) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
FindClose(handle);
|
FindClose(handle);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,7 +250,7 @@ wchar_t *find_windows_kit_root(HKEY key, wchar_t *version) {
|
|||||||
// Given a key to an already opened registry entry,
|
// Given a key to an already opened registry entry,
|
||||||
// get the value stored under the 'version' subkey.
|
// get the value stored under the 'version' subkey.
|
||||||
// If that's not the right terminology, hey, I never do registry stuff.
|
// If that's not the right terminology, hey, I never do registry stuff.
|
||||||
|
|
||||||
DWORD required_length;
|
DWORD required_length;
|
||||||
auto rc = RegQueryValueExW(key, version, NULL, NULL, NULL, &required_length);
|
auto rc = RegQueryValueExW(key, version, NULL, NULL, NULL, &required_length);
|
||||||
if (rc != 0) return NULL;
|
if (rc != 0) return NULL;
|
||||||
@@ -287,13 +268,13 @@ wchar_t *find_windows_kit_root(HKEY key, wchar_t *version) {
|
|||||||
if (value[length]) {
|
if (value[length]) {
|
||||||
value[length+1] = 0;
|
value[length+1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void win10_best(wchar_t *short_name, wchar_t *full_name, Version_Data *data) {
|
void win10_best(wchar_t *short_name, wchar_t *full_name, Version_Data *data) {
|
||||||
// Find the Windows 10 subdirectory with the highest version number.
|
// Find the Windows 10 subdirectory with the highest version number.
|
||||||
|
|
||||||
int i0, i1, i2, i3;
|
int i0, i1, i2, i3;
|
||||||
auto success = swscanf_s(short_name, L"%d.%d.%d.%d", &i0, &i1, &i2, &i3);
|
auto success = swscanf_s(short_name, L"%d.%d.%d.%d", &i0, &i1, &i2, &i3);
|
||||||
if (success < 4) return;
|
if (success < 4) return;
|
||||||
@@ -313,7 +294,7 @@ void win10_best(wchar_t *short_name, wchar_t *full_name, Version_Data *data) {
|
|||||||
// after we execute this function, so Win*_Data would contain an invalid pointer.
|
// after we execute this function, so Win*_Data would contain an invalid pointer.
|
||||||
if (data->best_name) free(data->best_name);
|
if (data->best_name) free(data->best_name);
|
||||||
data->best_name = _wcsdup(full_name);
|
data->best_name = _wcsdup(full_name);
|
||||||
|
|
||||||
if (data->best_name) {
|
if (data->best_name) {
|
||||||
data->best_version[0] = i0;
|
data->best_version[0] = i0;
|
||||||
data->best_version[1] = i1;
|
data->best_version[1] = i1;
|
||||||
@@ -350,7 +331,7 @@ void find_windows_kit_root(Find_Result *result) {
|
|||||||
// is stored in the same place in the registry. We open a key
|
// is stored in the same place in the registry. We open a key
|
||||||
// to that place, first checking preferntially for a Windows 10 kit,
|
// to that place, first checking preferntially for a Windows 10 kit,
|
||||||
// then, if that's not found, a Windows 8 kit.
|
// then, if that's not found, a Windows 8 kit.
|
||||||
|
|
||||||
HKEY main_key;
|
HKEY main_key;
|
||||||
|
|
||||||
auto rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots",
|
auto rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots",
|
||||||
@@ -361,16 +342,20 @@ void find_windows_kit_root(Find_Result *result) {
|
|||||||
// Look for a Windows 10 entry.
|
// Look for a Windows 10 entry.
|
||||||
auto windows10_root = find_windows_kit_root(main_key, L"KitsRoot10");
|
auto windows10_root = find_windows_kit_root(main_key, L"KitsRoot10");
|
||||||
|
|
||||||
|
|
||||||
if (windows10_root) {
|
if (windows10_root) {
|
||||||
defer (free(windows10_root));
|
defer (free(windows10_root));
|
||||||
|
|
||||||
|
|
||||||
Version_Data data = {0};
|
Version_Data data = {0};
|
||||||
auto windows10_lib = concat(windows10_root, L"Lib");
|
auto windows10_lib = concat(windows10_root, L"Lib");
|
||||||
defer (free(windows10_lib));
|
defer (free(windows10_lib));
|
||||||
|
|
||||||
|
|
||||||
visit_files_w(windows10_lib, &data, win10_best);
|
visit_files_w(windows10_lib, &data, win10_best);
|
||||||
if (data.best_name) {
|
if (data.best_name) {
|
||||||
result->windows_sdk_version = 10;
|
result->windows_sdk_version = 10;
|
||||||
result->windows_sdk_root = data.best_name;
|
result->windows_sdk_root = concat(data.best_name, L"\\");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -380,7 +365,7 @@ void find_windows_kit_root(Find_Result *result) {
|
|||||||
|
|
||||||
if (windows8_root) {
|
if (windows8_root) {
|
||||||
defer (free(windows8_root));
|
defer (free(windows8_root));
|
||||||
|
|
||||||
auto windows8_lib = concat(windows8_root, L"Lib");
|
auto windows8_lib = concat(windows8_root, L"Lib");
|
||||||
defer (free(windows8_lib));
|
defer (free(windows8_lib));
|
||||||
|
|
||||||
@@ -388,7 +373,7 @@ void find_windows_kit_root(Find_Result *result) {
|
|||||||
visit_files_w(windows8_lib, &data, win8_best);
|
visit_files_w(windows8_lib, &data, win8_best);
|
||||||
if (data.best_name) {
|
if (data.best_name) {
|
||||||
result->windows_sdk_version = 8;
|
result->windows_sdk_version = 8;
|
||||||
result->windows_sdk_root = data.best_name;
|
result->windows_sdk_root = concat(data.best_name, L"\\");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -397,7 +382,7 @@ void find_windows_kit_root(Find_Result *result) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *result) {
|
bool find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *result) {
|
||||||
// The name of this procedure is kind of cryptic. Its purpose is
|
// The name of this procedure is kind of cryptic. Its purpose is
|
||||||
// to fight through Microsoft craziness. The things that the fine
|
// to fight through Microsoft craziness. The things that the fine
|
||||||
// Visual Studio team want you to do, JUST TO FIND A SINGLE FOLDER
|
// Visual Studio team want you to do, JUST TO FIND A SINGLE FOLDER
|
||||||
@@ -412,39 +397,40 @@ void find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *res
|
|||||||
//
|
//
|
||||||
// If all this COM object instantiation, enumeration, and querying doesn't give us
|
// If all this COM object instantiation, enumeration, and querying doesn't give us
|
||||||
// a useful result, we drop back to the registry-checking method.
|
// a useful result, we drop back to the registry-checking method.
|
||||||
|
|
||||||
auto rc = CoInitialize(NULL);
|
auto rc = CoInitialize(NULL);
|
||||||
// "Subsequent valid calls return false." So ignore false.
|
// "Subsequent valid calls return false." So ignore false.
|
||||||
// if rc != S_OK return false;
|
if (rc != S_OK) return false;
|
||||||
|
|
||||||
GUID my_uid = {0x42843719, 0xDB4C, 0x46C2, {0x8E, 0x7C, 0x64, 0xF1, 0x81, 0x6E, 0xFD, 0x5B}};
|
GUID my_uid = {0x42843719, 0xDB4C, 0x46C2, {0x8E, 0x7C, 0x64, 0xF1, 0x81, 0x6E, 0xFD, 0x5B}};
|
||||||
GUID CLSID_SetupConfiguration = {0x177F0C4A, 0x1CD3, 0x4DE7, {0xA3, 0x2C, 0x71, 0xDB, 0xBB, 0x9F, 0xA3, 0x6D}};
|
GUID CLSID_SetupConfiguration = {0x177F0C4A, 0x1CD3, 0x4DE7, {0xA3, 0x2C, 0x71, 0xDB, 0xBB, 0x9F, 0xA3, 0x6D}};
|
||||||
DWORD CLSCTX_INPROC_SERVER = 0x1;
|
|
||||||
|
|
||||||
ISetupConfiguration *config = NULL;
|
ISetupConfiguration *config = NULL;
|
||||||
auto hr = CoCreateInstance(CLSID_SetupConfiguration, NULL, CLSCTX_INPROC_SERVER, my_uid, (void **)&config);
|
HRESULT hr = 0;
|
||||||
if (hr != 0) return;
|
hr = CoCreateInstance(CLSID_SetupConfiguration, NULL, CLSCTX_INPROC_SERVER, my_uid, (void **)&config);
|
||||||
|
if (hr != 0) return false;
|
||||||
defer (config->Release());
|
defer (config->Release());
|
||||||
|
|
||||||
IEnumSetupInstances *instances = NULL;
|
IEnumSetupInstances *instances = NULL;
|
||||||
hr = config->EnumInstances(&instances);
|
hr = config->EnumInstances(&instances);
|
||||||
if (hr != 0) return;
|
if (hr != 0) return false;
|
||||||
if (!instances) return;
|
if (!instances) return false;
|
||||||
defer (instances->Release());
|
defer (instances->Release());
|
||||||
|
|
||||||
while (1) {
|
|
||||||
|
for (;;) {
|
||||||
ULONG found = 0;
|
ULONG found = 0;
|
||||||
ISetupInstance *instance = NULL;
|
ISetupInstance *instance = NULL;
|
||||||
auto hr = instances->Next(1, &instance, &found);
|
auto hr = instances->Next(1, &instance, &found);
|
||||||
if (hr != S_OK) break;
|
if (hr != S_OK) break;
|
||||||
|
|
||||||
defer (instance->Release());
|
defer (instance->Release());
|
||||||
|
|
||||||
BSTR bstr_inst_path;
|
BSTR bstr_inst_path;
|
||||||
hr = instance->GetInstallationPath(&bstr_inst_path);
|
hr = instance->GetInstallationPath(&bstr_inst_path);
|
||||||
if (hr != S_OK) continue;
|
if (hr != S_OK) continue;
|
||||||
defer (SysFreeString(bstr_inst_path));
|
defer (SysFreeString(bstr_inst_path));
|
||||||
|
|
||||||
auto tools_filename = concat(bstr_inst_path, L"\\VC\\Auxiliary\\Build\\Microsoft.VCToolsVersion.default.txt");
|
auto tools_filename = concat(bstr_inst_path, L"\\VC\\Auxiliary\\Build\\Microsoft.VCToolsVersion.default.txt");
|
||||||
defer (free(tools_filename));
|
defer (free(tools_filename));
|
||||||
|
|
||||||
@@ -471,31 +457,31 @@ void find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *res
|
|||||||
auto version_tail = wcschr(version, '\n');
|
auto version_tail = wcschr(version, '\n');
|
||||||
if (version_tail) *version_tail = 0; // Stomp the data, because nobody cares about it.
|
if (version_tail) *version_tail = 0; // Stomp the data, because nobody cares about it.
|
||||||
|
|
||||||
auto library_path = concat(bstr_inst_path, L"\\VC\\Tools\\MSVC\\", version, L"\\lib\\x64");
|
auto library_path = concat(bstr_inst_path, L"\\VC\\Tools\\MSVC\\", version, L"\\lib\\x64\\");
|
||||||
auto library_file = concat(library_path, L"\\vcruntime.lib"); // @Speed: Could have library_path point to this string, with a smaller count, to save on memory flailing!
|
auto library_file = concat(library_path, L"vcruntime.lib"); // @Speed: Could have library_path point to this string, with a smaller count, to save on memory flailing!
|
||||||
|
|
||||||
if (os_file_exists(library_file)) {
|
if (os_file_exists(library_file)) {
|
||||||
auto link_exe_path = concat(bstr_inst_path, L"\\VC\\Tools\\MSVC\\", version, L"\\bin\\Hostx64\\x64");
|
auto link_exe_path = concat(bstr_inst_path, L"\\VC\\Tools\\MSVC\\", version, L"\\bin\\Hostx64\\x64\\");
|
||||||
result->vs_exe_path = link_exe_path;
|
result->vs_exe_path = link_exe_path;
|
||||||
result->vs_library_path = library_path;
|
result->vs_library_path = library_path;
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Ryan Saunderson said:
|
Ryan Saunderson said:
|
||||||
"Clang uses the 'SetupInstance->GetInstallationVersion' / ISetupHelper->ParseVersion to find the newest version
|
"Clang uses the 'SetupInstance->GetInstallationVersion' / ISetupHelper->ParseVersion to find the newest version
|
||||||
and then reads the tools file to define the tools path - which is definitely better than what i did."
|
and then reads the tools file to define the tools path - which is definitely better than what i did."
|
||||||
|
|
||||||
So... @Incomplete: Should probably pick the newest version...
|
So... @Incomplete: Should probably pick the newest version...
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we get here, we didn't find Visual Studio 2017. Try earlier versions.
|
// If we get here, we didn't find Visual Studio 2017. Try earlier versions.
|
||||||
|
|
||||||
HKEY vs7_key;
|
HKEY vs7_key;
|
||||||
rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7", 0, KEY_QUERY_VALUE | KEY_WOW64_32KEY, &vs7_key);
|
rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7", 0, KEY_QUERY_VALUE | KEY_WOW64_32KEY, &vs7_key);
|
||||||
|
|
||||||
if (rc != S_OK) return;
|
if (rc != S_OK) return false;
|
||||||
defer (RegCloseKey(vs7_key));
|
defer (RegCloseKey(vs7_key));
|
||||||
|
|
||||||
// Hardcoded search for 4 prior Visual Studio versions. Is there something better to do here?
|
// Hardcoded search for 4 prior Visual Studio versions. Is there something better to do here?
|
||||||
@@ -514,14 +500,14 @@ void find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *res
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto buffer = (wchar_t *)malloc(cb_data);
|
auto buffer = (wchar_t *)malloc(cb_data);
|
||||||
if (!buffer) return;
|
if (!buffer) return false;
|
||||||
defer (free(buffer));
|
defer (free(buffer));
|
||||||
|
|
||||||
rc = RegQueryValueExW(vs7_key, v, NULL, NULL, (LPBYTE)buffer, &cb_data);
|
rc = RegQueryValueExW(vs7_key, v, NULL, NULL, (LPBYTE)buffer, &cb_data);
|
||||||
if (rc != 0) continue;
|
if (rc != 0) continue;
|
||||||
|
|
||||||
// @Robustness: Do the zero-termination thing suggested in the RegQueryValue docs?
|
// @Robustness: Do the zero-termination thing suggested in the RegQueryValue docs?
|
||||||
|
|
||||||
auto lib_path = concat(buffer, L"VC\\Lib\\amd64");
|
auto lib_path = concat(buffer, L"VC\\Lib\\amd64");
|
||||||
|
|
||||||
// Check to see whether a vcruntime.lib actually exists here.
|
// Check to see whether a vcruntime.lib actually exists here.
|
||||||
@@ -531,55 +517,64 @@ void find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *res
|
|||||||
if (os_file_exists(vcruntime_filename)) {
|
if (os_file_exists(vcruntime_filename)) {
|
||||||
result->vs_exe_path = concat(buffer, L"VC\\bin");
|
result->vs_exe_path = concat(buffer, L"VC\\bin");
|
||||||
result->vs_library_path = lib_path;
|
result->vs_library_path = lib_path;
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(lib_path);
|
free(lib_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we get here, we failed to find anything.
|
// If we get here, we failed to find anything.
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Find_Result find_visual_studio_and_windows_sdk() {
|
Find_Result find_visual_studio_and_windows_sdk() {
|
||||||
Find_Result result;
|
Find_Result result = {};
|
||||||
|
|
||||||
find_windows_kit_root(&result);
|
find_windows_kit_root(&result);
|
||||||
|
|
||||||
|
|
||||||
if (result.windows_sdk_root) {
|
if (result.windows_sdk_root) {
|
||||||
result.windows_sdk_um_library_path = concat(result.windows_sdk_root, L"\\um\\x64");
|
result.windows_sdk_um_library_path = concat(result.windows_sdk_root, L"um\\x64\\");
|
||||||
result.windows_sdk_ucrt_library_path = concat(result.windows_sdk_root, L"\\ucrt\\x64");
|
result.windows_sdk_ucrt_library_path = concat(result.windows_sdk_root, L"ucrt\\x64\\");
|
||||||
}
|
}
|
||||||
|
|
||||||
find_visual_studio_by_fighting_through_microsoft_craziness(&result);
|
bool ok = find_visual_studio_by_fighting_through_microsoft_craziness(&result);
|
||||||
|
|
||||||
|
if (!ok) {
|
||||||
|
result.vs_exe_path = concat(L"", L"");
|
||||||
|
result.vs_library_path = concat(L"", L"");
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char * ucs2_to_utf8(wchar_t * wstr) {
|
String mc_wstring_to_string(wchar_t *str) {
|
||||||
|
return string16_to_string(mc_allocator, make_string16_c(str));
|
||||||
int len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL) + 1;
|
|
||||||
|
|
||||||
char * str = (char*)malloc(len);
|
|
||||||
|
|
||||||
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL);
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Find_Result_Utf8 find_visual_studio_and_windows_sdk_utf8() {
|
|
||||||
|
|
||||||
|
Find_Result_Utf8 find_visual_studio_and_windows_sdk_utf8() {
|
||||||
Find_Result result = find_visual_studio_and_windows_sdk();
|
Find_Result result = find_visual_studio_and_windows_sdk();
|
||||||
defer (free_resources(&result));
|
defer (free_resources(&result));
|
||||||
|
|
||||||
Find_Result_Utf8 r;
|
Find_Result_Utf8 r = {};
|
||||||
r.windows_sdk_version = result.windows_sdk_version;
|
r.windows_sdk_version = result.windows_sdk_version;
|
||||||
|
|
||||||
r.windows_sdk_root = ucs2_to_utf8(result.windows_sdk_root);
|
r.windows_sdk_root = mc_wstring_to_string(result.windows_sdk_root);
|
||||||
r.windows_sdk_um_library_path = ucs2_to_utf8(result.windows_sdk_um_library_path);
|
r.windows_sdk_um_library_path = mc_wstring_to_string(result.windows_sdk_um_library_path);
|
||||||
r.windows_sdk_ucrt_library_path = ucs2_to_utf8(result.windows_sdk_ucrt_library_path);
|
r.windows_sdk_ucrt_library_path = mc_wstring_to_string(result.windows_sdk_ucrt_library_path);
|
||||||
r.vs_exe_path = ucs2_to_utf8(result.vs_exe_path);
|
r.vs_exe_path = mc_wstring_to_string(result.vs_exe_path);
|
||||||
r.vs_library_path = ucs2_to_utf8(result.vs_library_path);
|
r.vs_library_path = mc_wstring_to_string(result.vs_library_path);
|
||||||
|
|
||||||
|
// gb_printf("%.*s\n", LIT(r.windows_sdk_root));
|
||||||
|
// gb_printf("%.*s\n", LIT(r.windows_sdk_um_library_path));
|
||||||
|
// gb_printf("%.*s\n", LIT(r.windows_sdk_ucrt_library_path));
|
||||||
|
// gb_printf("%.*s\n", LIT(r.vs_exe_path));
|
||||||
|
// gb_printf("%.*s\n", LIT(r.vs_library_path));
|
||||||
|
|
||||||
|
// gb_exit(1);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -207,6 +207,23 @@ gb_inline bool string_ends_with(String const &s, String const &suffix) {
|
|||||||
return substring(s, s.len-suffix.len, s.len) == suffix;
|
return substring(s, s.len-suffix.len, s.len) == suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gb_inline bool string_starts_with(String const &s, u8 prefix) {
|
||||||
|
if (1 > s.len) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return s[0] == prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gb_inline bool string_ends_with(String const &s, u8 suffix) {
|
||||||
|
if (1 > s.len) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return s[s.len-1] == suffix;
|
||||||
|
}
|
||||||
|
|
||||||
gb_inline isize string_extension_position(String const &str) {
|
gb_inline isize string_extension_position(String const &str) {
|
||||||
isize dot_pos = -1;
|
isize dot_pos = -1;
|
||||||
isize i = str.len;
|
isize i = str.len;
|
||||||
|
|||||||
Reference in New Issue
Block a user