v.builder: try finding msvc from env variables, when not found from registry (#10072)
parent
e9c84ce154
commit
28a22e5a84
|
@ -80,15 +80,28 @@ struct WindowsKit {
|
||||||
|
|
||||||
// Try and find the root key for installed windows kits
|
// Try and find the root key for installed windows kits
|
||||||
fn find_windows_kit_root(target_arch string) ?WindowsKit {
|
fn find_windows_kit_root(target_arch string) ?WindowsKit {
|
||||||
|
$if windows {
|
||||||
|
wkroot := find_windows_kit_root_by_reg(target_arch) or {
|
||||||
|
if wkroot := find_windows_kit_root_by_env(target_arch) {
|
||||||
|
return wkroot
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return wkroot
|
||||||
|
} $else {
|
||||||
|
return error('Host OS does not support finding a windows kit')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to find the root key for installed windows kits from registry
|
||||||
|
fn find_windows_kit_root_by_reg(target_arch string) ?WindowsKit {
|
||||||
$if windows {
|
$if windows {
|
||||||
root_key := RegKey(0)
|
root_key := RegKey(0)
|
||||||
path := 'SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots'
|
path := 'SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots'
|
||||||
rc := C.RegOpenKeyEx(builder.hkey_local_machine, path.to_wide(), 0, builder.key_query_value | builder.key_wow64_32key | builder.key_enumerate_sub_keys,
|
rc := C.RegOpenKeyEx(builder.hkey_local_machine, path.to_wide(), 0, builder.key_query_value | builder.key_wow64_32key | builder.key_enumerate_sub_keys,
|
||||||
&root_key)
|
&root_key)
|
||||||
// TODO: Fix defer inside ifs
|
|
||||||
// defer {
|
|
||||||
// C.RegCloseKey(root_key)
|
|
||||||
// }
|
|
||||||
if rc != 0 {
|
if rc != 0 {
|
||||||
return error('Unable to open root key')
|
return error('Unable to open root key')
|
||||||
}
|
}
|
||||||
|
@ -97,6 +110,14 @@ fn find_windows_kit_root(target_arch string) ?WindowsKit {
|
||||||
C.RegCloseKey(root_key)
|
C.RegCloseKey(root_key)
|
||||||
return error('Unable to find a windows kit')
|
return error('Unable to find a windows kit')
|
||||||
}
|
}
|
||||||
|
C.RegCloseKey(root_key)
|
||||||
|
return new_windows_kit(kit_root, target_arch)
|
||||||
|
} $else {
|
||||||
|
return error('Host OS does not support finding a windows kit')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new_windows_kit(kit_root string, target_arch string) ?WindowsKit {
|
||||||
kit_lib := kit_root + 'Lib'
|
kit_lib := kit_root + 'Lib'
|
||||||
files := os.ls(kit_lib) ?
|
files := os.ls(kit_lib) ?
|
||||||
mut highest_path := ''
|
mut highest_path := ''
|
||||||
|
@ -111,7 +132,6 @@ fn find_windows_kit_root(target_arch string) ?WindowsKit {
|
||||||
}
|
}
|
||||||
kit_lib_highest := kit_lib + '\\$highest_path'
|
kit_lib_highest := kit_lib + '\\$highest_path'
|
||||||
kit_include_highest := kit_lib_highest.replace('Lib', 'Include')
|
kit_include_highest := kit_lib_highest.replace('Lib', 'Include')
|
||||||
C.RegCloseKey(root_key)
|
|
||||||
return WindowsKit{
|
return WindowsKit{
|
||||||
um_lib_path: kit_lib_highest + '\\um\\$target_arch'
|
um_lib_path: kit_lib_highest + '\\um\\$target_arch'
|
||||||
ucrt_lib_path: kit_lib_highest + '\\ucrt\\$target_arch'
|
ucrt_lib_path: kit_lib_highest + '\\ucrt\\$target_arch'
|
||||||
|
@ -119,8 +139,15 @@ fn find_windows_kit_root(target_arch string) ?WindowsKit {
|
||||||
ucrt_include_path: kit_include_highest + '\\ucrt'
|
ucrt_include_path: kit_include_highest + '\\ucrt'
|
||||||
shared_include_path: kit_include_highest + '\\shared'
|
shared_include_path: kit_include_highest + '\\shared'
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_windows_kit_root_by_env(target_arch string) ?WindowsKit {
|
||||||
|
kit_root := os.getenv('WindowsSdkDir')
|
||||||
|
if kit_root == '' {
|
||||||
|
return none
|
||||||
}
|
}
|
||||||
return error('Host OS does not support finding a windows kit')
|
|
||||||
|
return new_windows_kit(kit_root, target_arch)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct VsInstallation {
|
struct VsInstallation {
|
||||||
|
@ -130,9 +157,21 @@ struct VsInstallation {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_vs(vswhere_dir string, host_arch string, target_arch string) ?VsInstallation {
|
fn find_vs(vswhere_dir string, host_arch string, target_arch string) ?VsInstallation {
|
||||||
$if !windows {
|
$if windows {
|
||||||
|
vsinst := find_vs_by_reg(vswhere_dir, host_arch, target_arch) or {
|
||||||
|
if vsinst := find_vs_by_env(host_arch, target_arch) {
|
||||||
|
return vsinst
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return vsinst
|
||||||
|
} $else {
|
||||||
return error('Host OS does not support finding a Visual Studio installation')
|
return error('Host OS does not support finding a Visual Studio installation')
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_vs_by_reg(vswhere_dir string, host_arch string, target_arch string) ?VsInstallation {
|
||||||
|
$if windows {
|
||||||
// Emily:
|
// Emily:
|
||||||
// VSWhere is guaranteed to be installed at this location now
|
// VSWhere is guaranteed to be installed at this location now
|
||||||
// If its not there then end user needs to update their visual studio
|
// If its not there then end user needs to update their visual studio
|
||||||
|
@ -163,6 +202,31 @@ fn find_vs(vswhere_dir string, host_arch string, target_arch string) ?VsInstalla
|
||||||
}
|
}
|
||||||
println('Unable to find vs installation (attempted to use lib path "$lib_path")')
|
println('Unable to find vs installation (attempted to use lib path "$lib_path")')
|
||||||
return error('Unable to find vs exe folder')
|
return error('Unable to find vs exe folder')
|
||||||
|
} $else {
|
||||||
|
return error('Host OS does not support finding a Visual Studio installation')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_vs_by_env(host_arch string, target_arch string) ?VsInstallation {
|
||||||
|
vs_dir := os.getenv('VSINSTALLDIR')
|
||||||
|
if vs_dir == '' {
|
||||||
|
return none
|
||||||
|
}
|
||||||
|
|
||||||
|
vc_tools_dir := os.getenv('VCToolsInstallDir')
|
||||||
|
if vc_tools_dir == '' {
|
||||||
|
return none
|
||||||
|
}
|
||||||
|
|
||||||
|
bin_dir := '${vc_tools_dir}bin\\Host$host_arch\\$target_arch'
|
||||||
|
lib_path := '${vc_tools_dir}lib\\$target_arch'
|
||||||
|
include_path := '${vc_tools_dir}include'
|
||||||
|
|
||||||
|
return VsInstallation{
|
||||||
|
exe_path: bin_dir
|
||||||
|
lib_path: lib_path
|
||||||
|
include_path: include_path
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_msvc(m64_target bool) ?MsvcResult {
|
fn find_msvc(m64_target bool) ?MsvcResult {
|
||||||
|
|
Loading…
Reference in New Issue