-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This updates the nu_msvs module. There were several things that I didn't think looked proper for Windows so I changed them an hopefully made this module a tiny bit better.
- Loading branch information
Showing
1 changed file
with
107 additions
and
77 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,147 +1,177 @@ | ||
export-env { | ||
if not ("MSVS_ACTIVATED" in $env) { | ||
$env.MSVS_BASE_PATH = $env.Path | ||
|
||
let info = ( | ||
if not (which vswhere | is-empty) { | ||
(vswhere -format json | from json) | ||
} else { | ||
('{"installationPath": [""]}' | from json) | ||
} | ||
) | ||
|
||
$env.MSVS_ROOT = ($info.installationPath.0 | str replace -a '\\' '/') | ||
|
||
$env.MSVS_MSVC_ROOT = ( | ||
if not ($"($env.MSVS_ROOT)/VC/Tools/MSVC/" | path exists) { | ||
"" | ||
} else if (ls ($"($env.MSVS_ROOT)/VC/Tools/MSVC/*" | into glob) | is-empty) { | ||
"" | ||
} else { | ||
((ls ($"($env.MSVS_ROOT)/VC/Tools/MSVC/*" | into glob)).name.0 | str replace -a '\\' '/') | ||
}) | ||
|
||
$env.MSVS_MSDK_ROOT = (registry query --hklm 'SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0' InstallationFolder | get value) | ||
|
||
$env.MSVS_MSDK_VER = (registry query --hklm 'SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0' ProductVersion | get value) + ".0" | ||
|
||
$env.MSVS_INCLUDE_PATH = ([ | ||
$"($env.MSVS_ROOT)/Include/($env.MSVS_MSDK_VER)/cppwinrt/winrt", | ||
$"($env.MSVS_MSVC_ROOT)/include", | ||
$"($env.MSVS_MSDK_ROOT)Include/($env.MSVS_MSDK_VER)/cppwinrt/winrt", | ||
$"($env.MSVS_MSDK_ROOT)Include/($env.MSVS_MSDK_VER)/shared", | ||
$"($env.MSVS_MSDK_ROOT)Include/($env.MSVS_MSDK_VER)/ucrt", | ||
$"($env.MSVS_MSDK_ROOT)Include/($env.MSVS_MSDK_VER)/um", | ||
$"($env.MSVS_MSDK_ROOT)Include/($env.MSVS_MSDK_VER)/winrt" | ||
] | str join ";") | ||
|
||
$env.MSVS_ACTIVATED = false | ||
$env.MSVS_BASE_PATH = $env.Path | ||
$env.PATH_VAR = (if "Path" in $env { "Path" } else { "PATH" }) | ||
|
||
let info = ( | ||
if not (which vswhere | is-empty) { | ||
(vswhere -format json | from json) | ||
} else { | ||
('{"installationPath": [""]}' | from json) | ||
} | ||
) | ||
|
||
$env.MSVS_ROOT = $info.installationPath.0 | ||
|
||
$env.MSVS_MSVC_ROOT = ( | ||
if not ($'($env.MSVS_ROOT)\VC\Tools\MSVC\' | path exists) { | ||
"" | ||
} else if (ls ($'($env.MSVS_ROOT)\VC\Tools\MSVC\*' | into glob) | is-empty) { | ||
"" | ||
} else { | ||
((ls ($'($env.MSVS_ROOT)\VC\Tools\MSVC\*' | into glob)).name.0) | ||
}) | ||
|
||
$env.MSVS_MSDK_ROOT = (registry query --hklm 'SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0' InstallationFolder | get value) | ||
|
||
$env.MSVS_MSDK_VER = (registry query --hklm 'SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0' ProductVersion | get value) + '.0' | ||
|
||
$env.MSVS_INCLUDE_PATH = ([ | ||
$'($env.MSVS_ROOT)\Include\($env.MSVS_MSDK_VER)\cppwinrt\winrt', | ||
$'($env.MSVS_MSVC_ROOT)\Include', | ||
$'($env.MSVS_MSDK_ROOT)Include\($env.MSVS_MSDK_VER)\cppwinrt\winrt', | ||
$'($env.MSVS_MSDK_ROOT)Include\($env.MSVS_MSDK_VER)\shared', | ||
$'($env.MSVS_MSDK_ROOT)Include\($env.MSVS_MSDK_VER)\ucrt', | ||
$'($env.MSVS_MSDK_ROOT)Include\($env.MSVS_MSDK_VER)\um', | ||
$'($env.MSVS_MSDK_ROOT)Include\($env.MSVS_MSDK_VER)\winrt' | ||
] | str join (char esep)) | ||
|
||
let esep_path_converter = { | ||
from_string: { |s| $s | split row (char esep) } | ||
to_string: { |v| $v | path expand | str join (char esep) } | ||
} | ||
|
||
$env.ENV_CONVERSIONS = { | ||
Path: $esep_path_converter | ||
DYLD_FALLBACK_LIBRARY_PATH: $esep_path_converter | ||
PSModulePath: $esep_path_converter | ||
MSVS_BASE_PATH: $esep_path_converter | ||
MSVS_INCLUDE_PATH: $esep_path_converter | ||
INCLUDE: $esep_path_converter | ||
LIB: $esep_path_converter | ||
} | ||
|
||
# Debugging Info | ||
# print $"MSVS_BASE_PATH: ($env.MSVS_BASE_PATH)" | ||
# print $"PATH_VAR: ($env.PATH_VAR)" | ||
# print $"MSVS_ROOT: ($env.MSVS_ROOT)" | ||
# print $"MSVS_MSVC_ROOT: ($env.MSVS_MSVC_ROOT)" | ||
# print $"MSVS_MSDK_ROOT: ($env.MSVS_MSDK_ROOT)" | ||
# print $"MSVS_MSDK_VER: ($env.MSVS_MSDK_VER)" | ||
# print $"MSVS_INCLUDE_PATH: ($env.MSVS_INCLUDE_PATH)" | ||
} | ||
|
||
export def --env activate [ | ||
--host (-h): string = "x64", # Host architecture, must be x64 or x86 (case insensitive) | ||
--target (-t): string = "x64", # Target architecture, must be x64 or x86 (case insensitive) | ||
--sdk (-s): string = "latest" # Version of Windows SDK, must be "latest" or a valid version string | ||
--host (-h): string = x64, # Host architecture, must be x64 or x86 (case insensitive) | ||
--target (-t): string = x64, # Target architecture, must be x64 or x86 (case insensitive) | ||
--sdk (-s): string = latest # Version of Windows SDK, must be "latest" or a valid version string | ||
] { | ||
if (($env.MSVS_ROOT | is-empty) or ($env.MSVS_MSVC_ROOT | is-empty)) { | ||
print "Neither Microsoft Visual Studio nor MSVC is available." | ||
print "Either Microsoft Visual Studio or MSVC is valid." | ||
return | ||
} | ||
|
||
let fh = ($host | str downcase) | ||
let ft = ($target | str downcase) | ||
let fs = ( | ||
if ($sdk != "latest") { | ||
if ($sdk != latest) { | ||
$sdk | ||
} else { | ||
$env.MSVS_MSDK_VER | ||
}) | ||
|
||
if (($fh != "x64") and ($fh != "x86")) { | ||
if (($fh != x64) and ($fh != x86)) { | ||
print $"Wrong host architecture specified: ($fh)." | ||
help n_msvc activate | ||
return | ||
} | ||
|
||
if (($ft != "x64") and ($ft != "x86")) { | ||
if (($ft != x64) and ($ft != x86)) { | ||
print $"Wrong target architecture specified: ($ft)." | ||
help n_msvc activate | ||
return | ||
} | ||
|
||
if not ($"($env.MSVS_MSDK_ROOT)bin/($fs)" | path exists) { | ||
if not ($'($env.MSVS_MSDK_ROOT)bin\($fs)' | path exists) { | ||
print $"Invalid Windows SDK version specified: ($fs)." | ||
return | ||
} | ||
|
||
let env_path = [ | ||
$"($env.MSVS_ROOT)/../Shared/Common/VSPerfCollectionTools/vs2019", | ||
$"($env.MSVS_ROOT)/Common7/IDE", | ||
$"($env.MSVS_ROOT)/Common7/IDE/CommonExtensions/Microsoft/TestWindow", | ||
$"($env.MSVS_ROOT)/Common7/IDE/CommonExtensions/Microsoft/TeamFoundation/Team Explorer", | ||
$"($env.MSVS_ROOT)/Common7/IDE/Extensions/Microsoft/IntelliCode/CLI", | ||
$"($env.MSVS_ROOT)/Common7/IDE/Tools", | ||
$"($env.MSVS_ROOT)/Common7/IDE/VC/VCPackages", | ||
$"($env.MSVS_ROOT)/Common7/Tools/devinit", | ||
$"($env.MSVS_ROOT)/MSBuild/Current/bin", | ||
$"($env.MSVS_ROOT)/MSBuild/Current/bin/Roslyn", | ||
$"($env.MSVS_ROOT)/Team Tools/DiagnosticsHub/Collector", | ||
$"($env.MSVS_ROOT)/Team Tools/Performance Tools", | ||
$"($env.MSVS_MSVC_ROOT)/bin/Host($fh)/($ft)", | ||
$"($env.MSVS_MSDK_ROOT)bin/($ft)", | ||
$"($env.MSVS_MSDK_ROOT)bin/($fs)/($ft)" | ||
($'($env.MSVS_ROOT)\..\Shared\Common\VSPerfCollectionTools\vs2019' | path expand), | ||
$'($env.MSVS_ROOT)\Common7\IDE', | ||
$'($env.MSVS_ROOT)\Common7\IDE\CommonExtensions\Microsoft\TestWindow', | ||
$'($env.MSVS_ROOT)\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer', | ||
$'($env.MSVS_ROOT)\Common7\IDE\Extensions\Microsoft\IntelliCode\CLI', | ||
$'($env.MSVS_ROOT)\Common7\IDE\Tools', | ||
$'($env.MSVS_ROOT)\Common7\IDE\VC\VCPackages', | ||
$'($env.MSVS_ROOT)\Common7\Tools\devinit', | ||
$'($env.MSVS_ROOT)\MSBuild\Current\bin', | ||
$'($env.MSVS_ROOT)\MSBuild\Current\bin\Roslyn', | ||
$'($env.MSVS_ROOT)\Team Tools\DiagnosticsHub\Collector', | ||
$'($env.MSVS_ROOT)\Team Tools\Performance Tools', | ||
$'($env.MSVS_MSVC_ROOT)\bin\Host($fh)\($ft)', | ||
$'($env.MSVS_MSDK_ROOT)bin\($ft)', | ||
$'($env.MSVS_MSDK_ROOT)bin\($fs)\($ft)' | ||
] | ||
|
||
let env_path = ( | ||
if ($ft == "x64") { | ||
($env_path | prepend $"($env.MSVS_ROOT)/../Shared/Common/VSPerfCollectionTools/vs2019/x64") | ||
if ($ft == x64) { | ||
($env_path | prepend ($'($env.MSVS_ROOT)\..\Shared\Common\VSPerfCollectionTools\vs2019\x64' | path expand)) | ||
} else { | ||
$env_path | ||
}) | ||
|
||
let env_path = ( | ||
if ($ft == "x64") { | ||
($env_path | prepend $"($env.MSVS_ROOT)/Team Tools/Performance Tools/x64") | ||
if ($ft == x64) { | ||
($env_path | prepend $'($env.MSVS_ROOT)\Team Tools\Performance Tools\x64') | ||
} else { | ||
$env_path | ||
}) | ||
|
||
let env_path = ( | ||
if ($ft != $fh) { | ||
($env_path | prepend $"($env.MSVS_MSVC_ROOT)/bin/Host($fh)/($fh)") | ||
($env_path | prepend $'($env.MSVS_MSVC_ROOT)\bin\Host($fh)\($fh)') | ||
} else { | ||
$env_path | ||
}) | ||
|
||
let env_path = ($env.MSVS_BASE_PATH | prepend $env_path) | ||
|
||
let lib_path = ([ | ||
$"($env.MSVS_MSDK_ROOT)Lib/($env.MSVS_MSDK_VER)/ucrt/($ft)", | ||
$"($env.MSVS_MSDK_ROOT)Lib/($env.MSVS_MSDK_VER)/um/($ft)", | ||
$"($env.MSVS_MSVC_ROOT)/lib/($ft)", | ||
] | str join ";") | ||
$'($env.MSVS_MSDK_ROOT)Lib\($env.MSVS_MSDK_VER)\ucrt\($ft)', | ||
$'($env.MSVS_MSDK_ROOT)Lib\($env.MSVS_MSDK_VER)\um\($ft)', | ||
$'($env.MSVS_MSVC_ROOT)\lib\($ft)', | ||
] | str join (char esep)) | ||
|
||
print "Activating Microsoft Visual Studio environment." | ||
load-env { | ||
Path: $env_path, | ||
PATH: $env_path, | ||
$env.PATH_VAR: $env_path, | ||
INCLUDE: $env.MSVS_INCLUDE_PATH, | ||
LIB: $lib_path | ||
} | ||
|
||
$env.MSVS_ACTIVATED = true | ||
# Debug Information | ||
# print $"PATH_VAR: ($env.PATH_VAR)" | ||
# print $"INCLUDE: ($env.INCLUDE)" | ||
# print $"LIB: ($env.LIB)" | ||
} | ||
|
||
export def --env deactivate [] { | ||
if (($env.MSVS_ROOT? | is-empty) or ($env.MSVS_MSVC_ROOT? | is-empty)) { | ||
print "Neither Microsoft Visual Studio nor MSVC is available." | ||
if (($env.MSVS_ROOT | is-empty) or ($env.MSVS_MSVC_ROOT | is-empty)) { | ||
print "Either Microsoft Visual Studio or MSVC is valid." | ||
return | ||
} | ||
|
||
load-env { | ||
Path: $env.MSVS_BASE_PATH, | ||
PATH: $env.MSVS_BASE_PATH | ||
$env.PATH_VAR: $env.MSVS_BASE_PATH, | ||
} | ||
|
||
$env.MSVS_ACTIVATED = false | ||
hide-env INCLUDE | ||
hide-env LIB | ||
hide-env MSVS_BASE_PATH | ||
hide-env MSVS_ROOT | ||
hide-env MSVS_MSVC_ROOT | ||
hide-env MSVS_MSDK_ROOT | ||
hide-env MSVS_MSDK_VER | ||
hide-env MSVS_INCLUDE_PATH | ||
} |