1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

msvc: detect x86 host and use x86 build tools

This commit is contained in:
vitalyster 2019-10-16 02:54:35 +03:00 committed by Alexander Medvednikov
parent c3e1ada405
commit 9b38f59184
2 changed files with 34 additions and 16 deletions

View File

@ -51,13 +51,19 @@ goto :success
:msvcstrap :msvcstrap
echo Attempting to build v.c with MSVC... echo Attempting to build v.c with MSVC...
set VsWhereDir=%ProgramFiles(x86)%
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do ( set HostArch=x64
if "%PROCESSOR_ARCHITECTURE%" == "x86" (
echo Using x86 Build Tools...
set VsWhereDir=%ProgramFiles%
set HostArch=x86
)
for /f "usebackq tokens=*" %%i in (`"%VsWhereDir%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do (
set InstallDir=%%i set InstallDir=%%i
) )
if exist "%InstallDir%\Common7\Tools\vsdevcmd.bat" ( if exist "%InstallDir%\Common7\Tools\vsdevcmd.bat" (
call "%InstallDir%\Common7\Tools\vsdevcmd.bat" -arch=x64 -host_arch=x64 -no_logo call "%InstallDir%\Common7\Tools\vsdevcmd.bat" -arch=%HostArch% -host_arch=%HostArch% -no_logo
) else ( ) else (
goto :nocompiler goto :nocompiler
) )

View File

@ -37,7 +37,7 @@ fn find_windows_kit_internal(key RegKey, versions []string) ?string {
$if windows { $if windows {
for version in versions { for version in versions {
required_bytes := 0 // TODO mut required_bytes := 0 // TODO mut
result := C.RegQueryValueExW(key, version.to_wide(), 0, 0, 0, &required_bytes) result := C.RegQueryValueEx(key, version.to_wide(), 0, 0, 0, &required_bytes)
length := required_bytes / 2 length := required_bytes / 2
@ -52,7 +52,7 @@ fn find_windows_kit_internal(key RegKey, versions []string) ?string {
continue continue
} }
result2 := C.RegQueryValueExW(key, version.to_wide(), 0, 0, value, &alloc_length) result2 := C.RegQueryValueEx(key, version.to_wide(), 0, 0, value, &alloc_length)
if result2 != 0 { if result2 != 0 {
continue continue
@ -80,11 +80,11 @@ 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() ?WindowsKit { fn find_windows_kit_root(host_arch string) ?WindowsKit {
$if windows { $if windows {
root_key := RegKey(0) root_key := RegKey(0)
rc := C.RegOpenKeyExA( rc := C.RegOpenKeyEx(
HKEY_LOCAL_MACHINE, 'SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots', 0, KEY_QUERY_VALUE | KEY_WOW64_32KEY | KEY_ENUMERATE_SUB_KEYS, &root_key) HKEY_LOCAL_MACHINE, 'SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots'.to_wide(), 0, KEY_QUERY_VALUE | KEY_WOW64_32KEY | KEY_ENUMERATE_SUB_KEYS, &root_key)
defer {C.RegCloseKey(root_key)} defer {C.RegCloseKey(root_key)}
@ -119,8 +119,8 @@ fn find_windows_kit_root() ?WindowsKit {
// println('$kit_lib_highest $kit_include_highest') // println('$kit_lib_highest $kit_include_highest')
return WindowsKit { return WindowsKit {
um_lib_path: kit_lib_highest + '\\um\\x64' um_lib_path: kit_lib_highest + '\\um\\$host_arch'
ucrt_lib_path: kit_lib_highest + '\\ucrt\\x64' ucrt_lib_path: kit_lib_highest + '\\ucrt\\$host_arch'
um_include_path: kit_include_highest + '\\um' um_include_path: kit_include_highest + '\\um'
ucrt_include_path: kit_include_highest + '\\ucrt' ucrt_include_path: kit_include_highest + '\\ucrt'
@ -136,7 +136,7 @@ struct VsInstallation {
exe_path string exe_path string
} }
fn find_vs() ?VsInstallation { fn find_vs(vswhere_dir string, host_arch string) ?VsInstallation {
$if !windows { $if !windows {
return error('Host OS does not support finding a Vs installation') return error('Host OS does not support finding a Vs installation')
} }
@ -144,7 +144,8 @@ fn find_vs() ?VsInstallation {
// 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
// installation! // installation!
res := os.exec('""%ProgramFiles(x86)%\\Microsoft Visual Studio\\Installer\\vswhere.exe" -latest -prerelease -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath"') or {
res := os.exec('""$vswhere_dir\\Microsoft Visual Studio\\Installer\\vswhere.exe" -latest -prerelease -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath"') or {
return error(err) return error(err)
} }
// println('res: "$res"') // println('res: "$res"')
@ -162,11 +163,11 @@ fn find_vs() ?VsInstallation {
version version
} }
lib_path := '$res.output\\VC\\Tools\\MSVC\\$v\\lib\\x64' lib_path := '$res.output\\VC\\Tools\\MSVC\\$v\\lib\\$host_arch'
include_path := '$res.output\\VC\\Tools\\MSVC\\$v\\include' include_path := '$res.output\\VC\\Tools\\MSVC\\$v\\include'
if os.file_exists('$lib_path\\vcruntime.lib') { if os.file_exists('$lib_path\\vcruntime.lib') {
p := '$res.output\\VC\\Tools\\MSVC\\$v\\bin\\Hostx64\\x64' p := '$res.output\\VC\\Tools\\MSVC\\$v\\bin\\Host$host_arch\\$host_arch'
// println('$lib_path $include_path') // println('$lib_path $include_path')
@ -183,10 +184,21 @@ fn find_vs() ?VsInstallation {
fn find_msvc() ?MsvcResult { fn find_msvc() ?MsvcResult {
$if windows { $if windows {
wk := find_windows_kit_root() or { processor_architecture := os.getenv('PROCESSOR_ARCHITECTURE')
vswhere_dir := if processor_architecture == 'x86' {
'%ProgramFiles%'
} else {
'%ProgramFiles(x86)%'
}
host_arch := if processor_architecture == 'x86' {
'X86'
} else {
'X64'
}
wk := find_windows_kit_root(host_arch) or {
return error('Unable to find windows sdk') return error('Unable to find windows sdk')
} }
vs := find_vs() or { vs := find_vs(vswhere_dir, host_arch) or {
return error('Unable to find visual studio') return error('Unable to find visual studio')
} }