Last active
September 1, 2022 14:54
-
-
Save hsupu/004ee2c620e37ef8b70530c3ef181375 to your computer and use it in GitHub Desktop.
Call cl.exe in ad-hoc way
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
# param ( | |
# [Parameter(ValueFromRemainingArguments)] | |
# [AllowEmptyCollection()] | |
# [string[]]$Params | |
# ) | |
param() | |
$ErrorActionPreference = 'Stop' | |
trap { throw $Error[0]; } | |
if ($env:PROCESSOR_ARCHITECTURE -ine "amd64") { | |
# x64 in %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe | |
# x86 in %SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe | |
Write-Error "Not in a x64 shell, please open a x64 pwsh instead." | |
exit(1) | |
} | |
if (-not (Test-Path env:VCINSTALLDIR)) { | |
# not work by now | |
# see: https://github.com/dotnet/msbuild/issues/1596 | |
$env:DOTNET_CLI_UI_LANGUAGE = "en-US" | |
$env:VSLANG = "1033" | |
# chcp 65001 | |
$vsInstance = Get-VSSetupInstance | Select-Object -First 1 | |
if ($null -eq $vsInstance) { | |
Write-Error "VSSetupInstance not found" | |
exit(1) | |
} | |
# https://docs.microsoft.com/en-us/visualstudio/ide/reference/command-prompt-powershell?view=vs-2022 | |
Import-Module (Join-Path $vsInstance.InstallationPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll") | |
$shParams = @{ | |
VsInstanceId = $vsInstance.InstanceId; | |
Arch = "amd64"; | |
HostArch = "amd64"; | |
SkipAutomaticLocation = $true; | |
# DevCmdArguments = "-arch=amd64"; | |
} | |
Enter-VsDevShell @shParams | |
} | |
# Push-Location $PSScriptRoot | |
# try { | |
# & cl @Params | |
# } | |
# finally { | |
# Pop-Location | |
# } | |
Write-Debug "cl $args" | |
& cl @args |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
CL options: https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=msvc-170
LINK options: https://docs.microsoft.com/en-us/cpp/build/reference/linker-options?view=msvc-170