From 8449e791349297d9f945cd80d1dc7d43bc87418c Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Mar 2024 05:29:57 -0700 Subject: [PATCH 01/28] Drop the PsExec dance, but keep the PowerShell 7.4.1 upgrade. --- azure-devops/create-1es-hosted-pool.ps1 | 3 +- azure-devops/provision-image.ps1 | 43 ++++--------------------- 2 files changed, 8 insertions(+), 38 deletions(-) diff --git a/azure-devops/create-1es-hosted-pool.ps1 b/azure-devops/create-1es-hosted-pool.ps1 index bba0c57a831..dbb95797b9d 100644 --- a/azure-devops/create-1es-hosted-pool.ps1 +++ b/azure-devops/create-1es-hosted-pool.ps1 @@ -231,8 +231,7 @@ $ProvisionImageResult = Invoke-AzVMRunCommand ` -ResourceGroupName $ResourceGroupName ` -VMName $ProtoVMName ` -CommandId 'RunPowerShellScript' ` - -ScriptPath "$PSScriptRoot\provision-image.ps1" ` - -Parameter @{ 'AdminUserPassword' = $AdminPW; } + -ScriptPath "$PSScriptRoot\provision-image.ps1" Write-Host "provision-image.ps1 output: $($ProvisionImageResult.value.Message)" diff --git a/azure-devops/provision-image.ps1 b/azure-devops/provision-image.ps1 index e68adf909cb..6ea9fb5b831 100644 --- a/azure-devops/provision-image.ps1 +++ b/azure-devops/provision-image.ps1 @@ -10,18 +10,7 @@ provision-image.ps1 runs on an existing, freshly provisioned virtual machine, and sets up that virtual machine as a build machine. After this is done, (outside of this script), we take that machine and make it an image to be copied for setting up new VMs in the scale set. - -This script must either be run as admin, or one must pass AdminUserPassword; -if the script is run with AdminUserPassword, it runs itself again as an -administrator. - -.PARAMETER AdminUserPassword -The administrator user's password; if this is $null, or not passed, then the -script assumes it's running on an administrator account. #> -param( - [string]$AdminUserPassword = $null -) $ErrorActionPreference = 'Stop' @@ -79,16 +68,8 @@ Function DownloadAndExtractZip { $TranscriptPath = 'C:\provision-image-transcript.txt' -if ([string]::IsNullOrEmpty($AdminUserPassword)) { - Start-Transcript -Path $TranscriptPath -UseMinimalHeader -} else { - Write-Host 'AdminUser password supplied; switching to AdminUser.' - - # https://learn.microsoft.com/en-us/sysinternals/downloads/psexec - $PsToolsZipUrl = 'https://download.sysinternals.com/files/PSTools.zip' - Write-Host "Downloading: $PsToolsZipUrl" - $ExtractedPsToolsPath = DownloadAndExtractZip -Url $PsToolsZipUrl - $PsExecPath = Join-Path $ExtractedPsToolsPath 'PsExec64.exe' +if ($PSVersionTable.PSVersion -lt [Version]::new('7.4.1')) { + Write-Host "Old PowerShell version: $($PSVersionTable.PSVersion)" # https://github.com/PowerShell/PowerShell/releases/latest $PowerShellZipUrl = 'https://github.com/PowerShell/PowerShell/releases/download/v7.4.1/PowerShell-7.4.1-win-x64.zip' @@ -96,32 +77,24 @@ if ([string]::IsNullOrEmpty($AdminUserPassword)) { $ExtractedPowerShellPath = DownloadAndExtractZip -Url $PowerShellZipUrl $PwshPath = Join-Path $ExtractedPowerShellPath 'pwsh.exe' - $PsExecArgs = @( - '-u', - 'AdminUser', - '-p', - 'AdminUserPassword_REDACTED', - '-accepteula', - '-i', - '-h', - $PwshPath, + $PwshArgs = @( '-ExecutionPolicy', 'Unrestricted', '-File', $PSCommandPath ) - Write-Host "Executing: $PsExecPath $PsExecArgs" - $PsExecArgs[3] = $AdminUserPassword + Write-Host "Executing: $PwshPath $PwshArgs" - $proc = Start-Process -FilePath $PsExecPath -ArgumentList $PsExecArgs -Wait -PassThru + $proc = Start-Process -FilePath $PwshPath -ArgumentList $PwshArgs -Wait -PassThru Write-Host 'Reading transcript...' Get-Content -Path $TranscriptPath Write-Host 'Cleaning up...' - Remove-Item -Recurse -Path $ExtractedPsToolsPath Remove-Item -Recurse -Path $ExtractedPowerShellPath exit $proc.ExitCode } +Start-Transcript -Path $TranscriptPath -UseMinimalHeader + $Workloads = @( 'Microsoft.VisualStudio.Component.VC.ASAN', 'Microsoft.VisualStudio.Component.VC.CLI.Support', @@ -297,8 +270,6 @@ Function PipInstall { } } -Write-Host 'AdminUser password not supplied; assuming already running as AdminUser.' - # Print the Windows version, so we can verify whether Patch Tuesday has been picked up. cmd /c ver From 754f7a5a9d1bb437a066b71015792f493e526ce0 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Mar 2024 06:19:31 -0700 Subject: [PATCH 02/28] Add `exit` to improve the transcript. This eliminates weird lines: ``` PS>$global:? True ``` --- azure-devops/provision-image.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/azure-devops/provision-image.ps1 b/azure-devops/provision-image.ps1 index 6ea9fb5b831..4c671d96449 100644 --- a/azure-devops/provision-image.ps1 +++ b/azure-devops/provision-image.ps1 @@ -307,3 +307,5 @@ Write-Host 'Setting other environment variables...' Write-Host 'Finished setting other environment variables!' Write-Host 'Done!' + +exit From e4c6caf22859b309d71fe1ac026732b4ef9ce2fe Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Mar 2024 06:39:55 -0700 Subject: [PATCH 03/28] We don't need the PowerShell call operator when invoking curl.exe. This was the only affected invocation. --- azure-devops/provision-image.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-devops/provision-image.ps1 b/azure-devops/provision-image.ps1 index 4c671d96449..d1af883332b 100644 --- a/azure-devops/provision-image.ps1 +++ b/azure-devops/provision-image.ps1 @@ -59,7 +59,7 @@ Function DownloadAndExtractZip { } $ZipPath = Get-TempFilePath -Extension 'zip' - & curl.exe -L -o $ZipPath -s -S $Url + curl.exe -L -o $ZipPath -s -S $Url $TempSubdirPath = Get-TempFilePath -Extension 'dir' Expand-Archive -Path $ZipPath -DestinationPath $TempSubdirPath -Force From b94a6b2c9aeb58bf324789ebb9cc8c5d03721faf Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Mar 2024 06:36:41 -0700 Subject: [PATCH 04/28] Cleanup the transcript and all downloaded files. --- azure-devops/provision-image.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/azure-devops/provision-image.ps1 b/azure-devops/provision-image.ps1 index d1af883332b..fcd5dcc1dc7 100644 --- a/azure-devops/provision-image.ps1 +++ b/azure-devops/provision-image.ps1 @@ -62,6 +62,7 @@ Function DownloadAndExtractZip { curl.exe -L -o $ZipPath -s -S $Url $TempSubdirPath = Get-TempFilePath -Extension 'dir' Expand-Archive -Path $ZipPath -DestinationPath $TempSubdirPath -Force + Remove-Item -Path $ZipPath return $TempSubdirPath } @@ -90,6 +91,7 @@ if ($PSVersionTable.PSVersion -lt [Version]::new('7.4.1')) { Get-Content -Path $TranscriptPath Write-Host 'Cleaning up...' Remove-Item -Recurse -Path $ExtractedPowerShellPath + Remove-Item -Path $TranscriptPath exit $proc.ExitCode } @@ -175,6 +177,7 @@ Function InstallVisualStudio { $proc = Start-Process -FilePath cmd.exe -ArgumentList $args -Wait -PassThru PrintMsiExitCodeMessage $proc.ExitCode + Remove-Item -Path $bootstrapperExe } catch { Write-Error "Failed to install Visual Studio! $($_.Exception.Message)" @@ -209,6 +212,7 @@ Function InstallPython { else { Write-Error "Installation failed! Exited with $exitCode." } + Remove-Item -Path $installerPath } <# @@ -239,6 +243,7 @@ Function InstallCuda { else { Write-Error "Installation failed! Exited with $exitCode." } + Remove-Item -Path $installerPath } catch { Write-Error "Failed to install CUDA! $($_.Exception.Message)" From 92e5680ed2002e518ede7f344e388e8af483d556 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Mar 2024 07:31:47 -0700 Subject: [PATCH 05/28] Extract Python args. --- azure-devops/provision-image.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-devops/provision-image.ps1 b/azure-devops/provision-image.ps1 index fcd5dcc1dc7..ab3726fbd4e 100644 --- a/azure-devops/provision-image.ps1 +++ b/azure-devops/provision-image.ps1 @@ -203,8 +203,8 @@ Function InstallPython { [string]$installerPath = Get-TempFilePath -Extension 'exe' curl.exe -L -o $installerPath -s -S $Url Write-Host 'Installing Python...' - $proc = Start-Process -FilePath $installerPath -ArgumentList ` - @('/passive', 'InstallAllUsers=1', 'PrependPath=1', 'CompileAll=1') -Wait -PassThru + $args = @('/passive', 'InstallAllUsers=1', 'PrependPath=1', 'CompileAll=1') + $proc = Start-Process -FilePath $installerPath -ArgumentList $args -Wait -PassThru $exitCode = $proc.ExitCode if ($exitCode -eq 0) { Write-Host 'Installation successful!' From f383096f60483d934b18e83ccf642669b1e166b4 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Mar 2024 07:35:37 -0700 Subject: [PATCH 06/28] Wrap Python installation in try-catch. --- azure-devops/provision-image.ps1 | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/azure-devops/provision-image.ps1 b/azure-devops/provision-image.ps1 index ab3726fbd4e..ba0b7b2d786 100644 --- a/azure-devops/provision-image.ps1 +++ b/azure-devops/provision-image.ps1 @@ -199,20 +199,25 @@ Function InstallPython { [String]$Url ) - Write-Host 'Downloading Python...' - [string]$installerPath = Get-TempFilePath -Extension 'exe' - curl.exe -L -o $installerPath -s -S $Url - Write-Host 'Installing Python...' - $args = @('/passive', 'InstallAllUsers=1', 'PrependPath=1', 'CompileAll=1') - $proc = Start-Process -FilePath $installerPath -ArgumentList $args -Wait -PassThru - $exitCode = $proc.ExitCode - if ($exitCode -eq 0) { - Write-Host 'Installation successful!' + try { + Write-Host 'Downloading Python...' + [string]$installerPath = Get-TempFilePath -Extension 'exe' + curl.exe -L -o $installerPath -s -S $Url + Write-Host 'Installing Python...' + $args = @('/passive', 'InstallAllUsers=1', 'PrependPath=1', 'CompileAll=1') + $proc = Start-Process -FilePath $installerPath -ArgumentList $args -Wait -PassThru + $exitCode = $proc.ExitCode + if ($exitCode -eq 0) { + Write-Host 'Installation successful!' + } + else { + Write-Error "Installation failed! Exited with $exitCode." + } + Remove-Item -Path $installerPath } - else { - Write-Error "Installation failed! Exited with $exitCode." + catch { + Write-Error "Failed to install Python! $($_.Exception.Message)" } - Remove-Item -Path $installerPath } <# From 58c359ed21337f18f6a12e72a44e21f9da4f1fae Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Mar 2024 07:48:22 -0700 Subject: [PATCH 07/28] For Python, use `/quiet` instead of `/passive`, and don't install docs. This should save 50 MB. See: https://docs.python.org/3/using/windows.html --- azure-devops/provision-image.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-devops/provision-image.ps1 b/azure-devops/provision-image.ps1 index ba0b7b2d786..04fbb58876e 100644 --- a/azure-devops/provision-image.ps1 +++ b/azure-devops/provision-image.ps1 @@ -204,7 +204,7 @@ Function InstallPython { [string]$installerPath = Get-TempFilePath -Extension 'exe' curl.exe -L -o $installerPath -s -S $Url Write-Host 'Installing Python...' - $args = @('/passive', 'InstallAllUsers=1', 'PrependPath=1', 'CompileAll=1') + $args = @('/quiet', 'InstallAllUsers=1', 'PrependPath=1', 'CompileAll=1', 'Include_doc=0') $proc = Start-Process -FilePath $installerPath -ArgumentList $args -Wait -PassThru $exitCode = $proc.ExitCode if ($exitCode -eq 0) { From b3fa19d5ccfb16f0acce6cd42a4af723ef18ee30 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Mar 2024 07:56:24 -0700 Subject: [PATCH 08/28] Move `$ProgressPreference` to the top, drop duplicate `$ErrorActionPreference`. --- azure-devops/provision-image.ps1 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/azure-devops/provision-image.ps1 b/azure-devops/provision-image.ps1 index 04fbb58876e..dc5f21ee9ed 100644 --- a/azure-devops/provision-image.ps1 +++ b/azure-devops/provision-image.ps1 @@ -13,6 +13,7 @@ for setting up new VMs in the scale set. #> $ErrorActionPreference = 'Stop' +$ProgressPreference = 'SilentlyContinue' <# .SYNOPSIS @@ -115,9 +116,6 @@ $PythonUrl = 'https://www.python.org/ftp/python/3.12.2/python-3.12.2-amd64.exe' $CudaUrl = 'https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda_12.4.0_551.61_windows.exe' -$ErrorActionPreference = 'Stop' -$ProgressPreference = 'SilentlyContinue' - <# .SYNOPSIS Writes a message to the screen depending on ExitCode. From 75e04766c786d9458dd4b30e9c0afaf4f907b7f4 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Mar 2024 08:11:24 -0700 Subject: [PATCH 09/28] We can directly invoke pwsh, no need for a transcript. --- azure-devops/provision-image.ps1 | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/azure-devops/provision-image.ps1 b/azure-devops/provision-image.ps1 index dc5f21ee9ed..e618fb036cb 100644 --- a/azure-devops/provision-image.ps1 +++ b/azure-devops/provision-image.ps1 @@ -68,8 +68,6 @@ Function DownloadAndExtractZip { return $TempSubdirPath } -$TranscriptPath = 'C:\provision-image-transcript.txt' - if ($PSVersionTable.PSVersion -lt [Version]::new('7.4.1')) { Write-Host "Old PowerShell version: $($PSVersionTable.PSVersion)" @@ -86,18 +84,13 @@ if ($PSVersionTable.PSVersion -lt [Version]::new('7.4.1')) { $PSCommandPath ) Write-Host "Executing: $PwshPath $PwshArgs" + & $PwshPath $PwshArgs - $proc = Start-Process -FilePath $PwshPath -ArgumentList $PwshArgs -Wait -PassThru - Write-Host 'Reading transcript...' - Get-Content -Path $TranscriptPath Write-Host 'Cleaning up...' Remove-Item -Recurse -Path $ExtractedPowerShellPath - Remove-Item -Path $TranscriptPath - exit $proc.ExitCode + exit } -Start-Transcript -Path $TranscriptPath -UseMinimalHeader - $Workloads = @( 'Microsoft.VisualStudio.Component.VC.ASAN', 'Microsoft.VisualStudio.Component.VC.CLI.Support', From d840dc82058dcc7678616963c26a8292fae99341 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Mar 2024 08:57:14 -0700 Subject: [PATCH 10/28] Dramatically simplify code with `Get-SecureRandom`. This uses the exact same `System.Security.Cryptography.RandomNumberGenerator` machinery: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-securerandom?view=powershell-7.4 It was added in PowerShell 7.4, released 2023-11-16: https://learn.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-74?view=powershell-7.4 --- azure-devops/create-1es-hosted-pool.ps1 | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/azure-devops/create-1es-hosted-pool.ps1 b/azure-devops/create-1es-hosted-pool.ps1 index dbb95797b9d..43a5bb5623d 100644 --- a/azure-devops/create-1es-hosted-pool.ps1 +++ b/azure-devops/create-1es-hosted-pool.ps1 @@ -60,28 +60,11 @@ function New-Password { Param([int]$Length = 32) # This 64-character alphabet generates 6 bits of entropy per character. - # The power-of-2 alphabet size allows us to select a character by masking a random Byte with bitwise-AND. - $alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-' - $mask = 63 - if ($alphabet.Length -ne 64) { - throw 'Bad alphabet length' - } - - [Byte[]]$randomData = [Byte[]]::new($Length) - $rng = $null - try { - $rng = [System.Security.Cryptography.RandomNumberGenerator]::Create() - $rng.GetBytes($randomData) - } - finally { - if ($null -ne $rng) { - $rng.Dispose() - } - } + $alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-'.ToCharArray() [SecureString] $result = [SecureString]::new() for ($idx = 0; $idx -lt $Length; $idx++) { - $result.AppendChar($alphabet[$randomData[$idx] -band $mask]) + $result.AppendChar((Get-SecureRandom -InputObject $alphabet)) } return $result From 349488d5a02efb302d4ccad9620ae9511265d030 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Mar 2024 09:06:57 -0700 Subject: [PATCH 11/28] Suppress breaking change warnings from `Update-AzConfig` itself. I had removed this environment variable technique in GH 3651, saying "The previous method stopped working.", but it clearly works here now. Let's keep both. --- azure-devops/create-1es-hosted-pool.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/azure-devops/create-1es-hosted-pool.ps1 b/azure-devops/create-1es-hosted-pool.ps1 index 43a5bb5623d..17edf0a1c98 100644 --- a/azure-devops/create-1es-hosted-pool.ps1 +++ b/azure-devops/create-1es-hosted-pool.ps1 @@ -104,6 +104,8 @@ function Wait-Shutdown { Display-ProgressBar -Status 'Silencing breaking change warnings' # https://aka.ms/azps-changewarnings +$Env:SuppressAzurePowerShellBreakingChangeWarnings = 'true' + Update-AzConfig ` -DisplayBreakingChangeWarning $false ` -Scope 'Process' | Out-Null From 179fba4f7b28377342d1d5281b46b5c87003147b Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Mar 2024 09:24:31 -0700 Subject: [PATCH 12/28] Simply inline `PrintMsiExitCodeMessage`. --- azure-devops/provision-image.ps1 | 37 +++++++++----------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/azure-devops/provision-image.ps1 b/azure-devops/provision-image.ps1 index e618fb036cb..7ae698b6d4c 100644 --- a/azure-devops/provision-image.ps1 +++ b/azure-devops/provision-image.ps1 @@ -109,32 +109,6 @@ $PythonUrl = 'https://www.python.org/ftp/python/3.12.2/python-3.12.2-amd64.exe' $CudaUrl = 'https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda_12.4.0_551.61_windows.exe' -<# -.SYNOPSIS -Writes a message to the screen depending on ExitCode. - -.DESCRIPTION -Since msiexec can return either 0 or 3010 successfully, in both cases -we write that installation succeeded, and which exit code it exited with. -If msiexec returns anything else, we write an error. - -.PARAMETER ExitCode -The exit code that msiexec returned. -#> -Function PrintMsiExitCodeMessage { - Param( - $ExitCode - ) - - # 3010 is probably ERROR_SUCCESS_REBOOT_REQUIRED - if ($ExitCode -eq 0 -or $ExitCode -eq 3010) { - Write-Host "Installation successful! Exited with $ExitCode." - } - else { - Write-Error "Installation failed! Exited with $ExitCode." - } -} - <# .SYNOPSIS Install Visual Studio. @@ -167,7 +141,16 @@ Function InstallVisualStudio { } $proc = Start-Process -FilePath cmd.exe -ArgumentList $args -Wait -PassThru - PrintMsiExitCodeMessage $proc.ExitCode + $exitCode = $proc.ExitCode + + # 3010 is probably ERROR_SUCCESS_REBOOT_REQUIRED + if ($exitCode -eq 0 -or $exitCode -eq 3010) { + Write-Host "Installation successful! Exited with $exitCode." + } + else { + Write-Error "Installation failed! Exited with $exitCode." + } + Remove-Item -Path $bootstrapperExe } catch { From e86c0c42b8f14234de74883f2bd577d4ff7225b6 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Mar 2024 10:15:15 -0700 Subject: [PATCH 13/28] Simplify script output. --- azure-devops/create-1es-hosted-pool.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-devops/create-1es-hosted-pool.ps1 b/azure-devops/create-1es-hosted-pool.ps1 index 17edf0a1c98..6aebfad04e1 100644 --- a/azure-devops/create-1es-hosted-pool.ps1 +++ b/azure-devops/create-1es-hosted-pool.ps1 @@ -218,7 +218,7 @@ $ProvisionImageResult = Invoke-AzVMRunCommand ` -CommandId 'RunPowerShellScript' ` -ScriptPath "$PSScriptRoot\provision-image.ps1" -Write-Host "provision-image.ps1 output: $($ProvisionImageResult.value.Message)" +Write-Host $ProvisionImageResult.value.Message #################################################################################################### Display-ProgressBar -Status 'Restarting VM' From 7b21e5b6e4afa4d8a8ba7493246a19716ab84880 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Mar 2024 10:35:13 -0700 Subject: [PATCH 14/28] Directly invoke the VS installer without `cmd.exe /c`. --- azure-devops/provision-image.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-devops/provision-image.ps1 b/azure-devops/provision-image.ps1 index 7ae698b6d4c..644bc2d3915 100644 --- a/azure-devops/provision-image.ps1 +++ b/azure-devops/provision-image.ps1 @@ -134,13 +134,13 @@ Function InstallVisualStudio { [string]$bootstrapperExe = Get-TempFilePath -Extension 'exe' curl.exe -L -o $bootstrapperExe -s -S $BootstrapperUrl Write-Host 'Installing Visual Studio...' - $args = @('/c', $bootstrapperExe, '--quiet', '--norestart', '--wait', '--nocache') + $args = @('--quiet', '--norestart', '--wait', '--nocache') foreach ($workload in $Workloads) { $args += '--add' $args += $workload } - $proc = Start-Process -FilePath cmd.exe -ArgumentList $args -Wait -PassThru + $proc = Start-Process -FilePath $bootstrapperExe -ArgumentList $args -Wait -PassThru $exitCode = $proc.ExitCode # 3010 is probably ERROR_SUCCESS_REBOOT_REQUIRED From cfc5baecc3c4dd9cfa93de67d15d5dac62bca103 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Mar 2024 12:37:01 -0700 Subject: [PATCH 15/28] Grand unified `DownloadAndInstall`. --- azure-devops/provision-image.ps1 | 131 ++++++++----------------------- 1 file changed, 34 insertions(+), 97 deletions(-) diff --git a/azure-devops/provision-image.ps1 b/azure-devops/provision-image.ps1 index 644bc2d3915..3c786cc387e 100644 --- a/azure-devops/provision-image.ps1 +++ b/azure-devops/provision-image.ps1 @@ -91,7 +91,7 @@ if ($PSVersionTable.PSVersion -lt [Version]::new('7.4.1')) { exit } -$Workloads = @( +$VisualStudioWorkloads = @( 'Microsoft.VisualStudio.Component.VC.ASAN', 'Microsoft.VisualStudio.Component.VC.CLI.Support', 'Microsoft.VisualStudio.Component.VC.CMake.Project', @@ -104,128 +104,65 @@ $Workloads = @( 'Microsoft.VisualStudio.Component.Windows11SDK.22621' ) -$VisualStudioBootstrapperUrl = 'https://aka.ms/vs/17/pre/vs_enterprise.exe' +$VisualStudioUrl = 'https://aka.ms/vs/17/pre/vs_enterprise.exe' +$VisualStudioArgs = @('--quiet', '--norestart', '--wait', '--nocache') +foreach ($workload in $VisualStudioWorkloads) { + $VisualStudioArgs += '--add' + $VisualStudioArgs += $workload +} + $PythonUrl = 'https://www.python.org/ftp/python/3.12.2/python-3.12.2-amd64.exe' +$PythonArgs = @('/quiet', 'InstallAllUsers=1', 'PrependPath=1', 'CompileAll=1', 'Include_doc=0') $CudaUrl = 'https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda_12.4.0_551.61_windows.exe' +$CudaArgs = @('-s') <# .SYNOPSIS -Install Visual Studio. +Download and install a component. .DESCRIPTION -InstallVisualStudio takes the $Workloads array, and installs it with the -installer that's pointed at by $BootstrapperUrl. +DownloadAndInstall downloads an executable from the given URL, and runs it with the given command-line arguments. -.PARAMETER Workloads -The set of VS workloads to install. - -.PARAMETER BootstrapperUrl -The URL of the Visual Studio installer, i.e. one of vs_*.exe. -#> -Function InstallVisualStudio { - Param( - [String[]]$Workloads, - [String]$BootstrapperUrl - ) - - try { - Write-Host 'Downloading Visual Studio...' - [string]$bootstrapperExe = Get-TempFilePath -Extension 'exe' - curl.exe -L -o $bootstrapperExe -s -S $BootstrapperUrl - Write-Host 'Installing Visual Studio...' - $args = @('--quiet', '--norestart', '--wait', '--nocache') - foreach ($workload in $Workloads) { - $args += '--add' - $args += $workload - } - - $proc = Start-Process -FilePath $bootstrapperExe -ArgumentList $args -Wait -PassThru - $exitCode = $proc.ExitCode - - # 3010 is probably ERROR_SUCCESS_REBOOT_REQUIRED - if ($exitCode -eq 0 -or $exitCode -eq 3010) { - Write-Host "Installation successful! Exited with $exitCode." - } - else { - Write-Error "Installation failed! Exited with $exitCode." - } - - Remove-Item -Path $bootstrapperExe - } - catch { - Write-Error "Failed to install Visual Studio! $($_.Exception.Message)" - } -} - -<# -.SYNOPSIS -Installs Python. - -.DESCRIPTION -InstallPython installs Python from the supplied URL. +.PARAMETER Name +The name of the component, to be displayed in logging messages. .PARAMETER Url -The URL of the Python installer. -#> -Function InstallPython { - Param( - [String]$Url - ) - - try { - Write-Host 'Downloading Python...' - [string]$installerPath = Get-TempFilePath -Extension 'exe' - curl.exe -L -o $installerPath -s -S $Url - Write-Host 'Installing Python...' - $args = @('/quiet', 'InstallAllUsers=1', 'PrependPath=1', 'CompileAll=1', 'Include_doc=0') - $proc = Start-Process -FilePath $installerPath -ArgumentList $args -Wait -PassThru - $exitCode = $proc.ExitCode - if ($exitCode -eq 0) { - Write-Host 'Installation successful!' - } - else { - Write-Error "Installation failed! Exited with $exitCode." - } - Remove-Item -Path $installerPath - } - catch { - Write-Error "Failed to install Python! $($_.Exception.Message)" - } -} - -<# -.SYNOPSIS -Installs NVIDIA's CUDA Toolkit. - -.DESCRIPTION -InstallCuda installs the CUDA Toolkit. +The URL of the installer. -.PARAMETER Url -The URL of the CUDA installer. +.PARAMETER Args +The command-line arguments to pass to the installer. #> -Function InstallCuda { +Function DownloadAndInstall { Param( - [String]$Url + [String]$Name, + [String]$Url, + [String[]]$Args ) try { - Write-Host 'Downloading CUDA...' + Write-Host "Downloading $Name..." [string]$installerPath = Get-TempFilePath -Extension 'exe' curl.exe -L -o $installerPath -s -S $Url - Write-Host 'Installing CUDA...' - $proc = Start-Process -FilePath $installerPath -ArgumentList @('-s') -Wait -PassThru + + Write-Host "Installing $Name..." + $proc = Start-Process -FilePath $installerPath -ArgumentList $Args -Wait -PassThru $exitCode = $proc.ExitCode + if ($exitCode -eq 0) { Write-Host 'Installation successful!' } + elseif ($exitCode -eq 3010) { + Write-Host 'Installation successful! Exited with 3010 (ERROR_SUCCESS_REBOOT_REQUIRED).' + } else { Write-Error "Installation failed! Exited with $exitCode." } + Remove-Item -Path $installerPath } catch { - Write-Error "Failed to install CUDA! $($_.Exception.Message)" + Write-Error "Installation failed! Exception: $($_.Exception.Message)" } } @@ -257,9 +194,9 @@ Function PipInstall { # Print the Windows version, so we can verify whether Patch Tuesday has been picked up. cmd /c ver -InstallPython $PythonUrl -InstallVisualStudio -Workloads $Workloads -BootstrapperUrl $VisualStudioBootstrapperUrl -InstallCuda -Url $CudaUrl +DownloadAndInstall -Name 'Python' -Url $PythonUrl -Args $PythonArgs +DownloadAndInstall -Name 'Visual Studio' -Url $VisualStudioUrl -Args $VisualStudioArgs +DownloadAndInstall -Name 'CUDA' -Url $CudaUrl -Args $CudaArgs Write-Host 'Updating PATH...' From 21b2703c8cc96cc9608bc7304cde306853685768 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Mar 2024 12:46:33 -0700 Subject: [PATCH 16/28] Always disable positional binding, make all parameters mandatory. --- azure-devops/provision-image.ps1 | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/azure-devops/provision-image.ps1 b/azure-devops/provision-image.ps1 index 3c786cc387e..5039b3c28c9 100644 --- a/azure-devops/provision-image.ps1 +++ b/azure-devops/provision-image.ps1 @@ -27,14 +27,11 @@ filename component in the temporary directory with that extension. The extension to use for the path. #> Function Get-TempFilePath { + [CmdletBinding(PositionalBinding=$false)] Param( - [String]$Extension + [Parameter(Mandatory)][String]$Extension ) - if ([String]::IsNullOrWhiteSpace($Extension)) { - throw 'Missing Extension' - } - $tempPath = [System.IO.Path]::GetTempPath() $tempName = [System.IO.Path]::GetRandomFileName() + '.' + $Extension return Join-Path $tempPath $tempName @@ -51,14 +48,11 @@ DownloadAndExtractZip returns a path containing the extracted contents. The URL of the ZIP file to download. #> Function DownloadAndExtractZip { + [CmdletBinding(PositionalBinding=$false)] Param( - [String]$Url + [Parameter(Mandatory)][String]$Url ) - if ([String]::IsNullOrWhiteSpace($Url)) { - throw 'Missing Url' - } - $ZipPath = Get-TempFilePath -Extension 'zip' curl.exe -L -o $ZipPath -s -S $Url $TempSubdirPath = Get-TempFilePath -Extension 'dir' @@ -134,10 +128,11 @@ The URL of the installer. The command-line arguments to pass to the installer. #> Function DownloadAndInstall { + [CmdletBinding(PositionalBinding=$false)] Param( - [String]$Name, - [String]$Url, - [String[]]$Args + [Parameter(Mandatory)][String]$Name, + [Parameter(Mandatory)][String]$Url, + [Parameter(Mandatory)][String[]]$Args ) try { @@ -177,8 +172,9 @@ Installs or upgrades a pip package specified in $Package. The name of the package to be installed or upgraded. #> Function PipInstall { + [CmdletBinding(PositionalBinding=$false)] Param( - [String]$Package + [Parameter(Mandatory)][String]$Package ) try { @@ -215,8 +211,8 @@ Write-Host 'Finished updating PATH!' Write-Host 'Running PipInstall...' -PipInstall pip -PipInstall psutil +PipInstall -Package pip +PipInstall -Package psutil Write-Host 'Finished running PipInstall!' From acbf5f6ab6391ed4dac9d3e68054be9d8c1c8efe Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Mar 2024 12:59:40 -0700 Subject: [PATCH 17/28] Fix VSO-1784520 by dropping `psutil` and `--timeout=240`. ``` stl-lit.py: D:\GitHub\STL\llvm-project\llvm\utils\lit\lit\main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 240 seconds was requested on the command line. Forcing timeout to be 240 seconds. stl-lit.py: D:\GitHub\STL\llvm-project\llvm\utils\lit\lit\LitConfig.py:129: fatal: Setting a timeout per test not supported. Requires the Python psutil module but it could not be found. Try installing it via pip or via your operating system's package manager. ``` --- azure-devops/cmake-configure-build.yml | 1 - azure-devops/provision-image.ps1 | 48 -------------------------- 2 files changed, 49 deletions(-) diff --git a/azure-devops/cmake-configure-build.yml b/azure-devops/cmake-configure-build.yml index 03605a85866..441be5792ab 100644 --- a/azure-devops/cmake-configure-build.yml +++ b/azure-devops/cmake-configure-build.yml @@ -19,7 +19,6 @@ parameters: - name: litFlags type: object default: - - '--timeout=240' - '-j$(testParallelism)' - '--xunit-xml-output=$(buildOutputLocation)/test-results.xml' - '--order=lexical' diff --git a/azure-devops/provision-image.ps1 b/azure-devops/provision-image.ps1 index 5039b3c28c9..805f7c7b0d4 100644 --- a/azure-devops/provision-image.ps1 +++ b/azure-devops/provision-image.ps1 @@ -161,32 +161,6 @@ Function DownloadAndInstall { } } -<# -.SYNOPSIS -Install or upgrade a pip package. - -.DESCRIPTION -Installs or upgrades a pip package specified in $Package. - -.PARAMETER Package -The name of the package to be installed or upgraded. -#> -Function PipInstall { - [CmdletBinding(PositionalBinding=$false)] - Param( - [Parameter(Mandatory)][String]$Package - ) - - try { - Write-Host "Installing or upgrading $Package..." - python.exe -m pip install --progress-bar off --upgrade $Package - Write-Host "Done installing or upgrading $Package." - } - catch { - Write-Error "Failed to install or upgrade $Package." - } -} - # Print the Windows version, so we can verify whether Patch Tuesday has been picked up. cmd /c ver @@ -194,28 +168,6 @@ DownloadAndInstall -Name 'Python' -Url $PythonUrl -Args $PythonArgs DownloadAndInstall -Name 'Visual Studio' -Url $VisualStudioUrl -Args $VisualStudioArgs DownloadAndInstall -Name 'CUDA' -Url $CudaUrl -Args $CudaArgs -Write-Host 'Updating PATH...' - -# Step 1: Read the system path, which was just updated by installing Python. -$currentSystemPath = [Environment]::GetEnvironmentVariable('Path', 'Machine') - -# Step 2: Update the local path (for this running script), so PipInstall can run python.exe. -# Additional directories can be added here (e.g. if we extracted a zip file -# or installed something that didn't update the system path). -$Env:PATH="$($currentSystemPath)" - -# Step 3: Update the system path, permanently recording any additional directories that were added in the previous step. -[Environment]::SetEnvironmentVariable('Path', "$Env:PATH", 'Machine') - -Write-Host 'Finished updating PATH!' - -Write-Host 'Running PipInstall...' - -PipInstall -Package pip -PipInstall -Package psutil - -Write-Host 'Finished running PipInstall!' - Write-Host 'Setting other environment variables...' # The STL's PR/CI builds are totally unrepresentative of customer usage. From 63128a7ff4b2e5da09288f994db0ddc258076129 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Mar 2024 13:04:02 -0700 Subject: [PATCH 18/28] Simplify output. [Tested up to here.] --- azure-devops/provision-image.ps1 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/azure-devops/provision-image.ps1 b/azure-devops/provision-image.ps1 index 805f7c7b0d4..1ad5abed26b 100644 --- a/azure-devops/provision-image.ps1 +++ b/azure-devops/provision-image.ps1 @@ -168,13 +168,11 @@ DownloadAndInstall -Name 'Python' -Url $PythonUrl -Args $PythonArgs DownloadAndInstall -Name 'Visual Studio' -Url $VisualStudioUrl -Args $VisualStudioArgs DownloadAndInstall -Name 'CUDA' -Url $CudaUrl -Args $CudaArgs -Write-Host 'Setting other environment variables...' +Write-Host 'Setting environment variables...' # The STL's PR/CI builds are totally unrepresentative of customer usage. [Environment]::SetEnvironmentVariable('VSCMD_SKIP_SENDTELEMETRY', '1', 'Machine') -Write-Host 'Finished setting other environment variables!' - Write-Host 'Done!' exit From 9cbc14ca783d518957b86f227b85517334e618b6 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 9 Apr 2024 18:28:49 -0700 Subject: [PATCH 19/28] Python 3.12.3. --- azure-devops/provision-image.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-devops/provision-image.ps1 b/azure-devops/provision-image.ps1 index 1ad5abed26b..5d582acb1f0 100644 --- a/azure-devops/provision-image.ps1 +++ b/azure-devops/provision-image.ps1 @@ -105,7 +105,7 @@ foreach ($workload in $VisualStudioWorkloads) { $VisualStudioArgs += $workload } -$PythonUrl = 'https://www.python.org/ftp/python/3.12.2/python-3.12.2-amd64.exe' +$PythonUrl = 'https://www.python.org/ftp/python/3.12.3/python-3.12.3-amd64.exe' $PythonArgs = @('/quiet', 'InstallAllUsers=1', 'PrependPath=1', 'CompileAll=1', 'Include_doc=0') $CudaUrl = 'https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda_12.4.0_551.61_windows.exe' From d40e61f8febeb7b53b236c38b382637f0f3ccfda Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 9 Apr 2024 19:38:28 -0700 Subject: [PATCH 20/28] `New-AzGalleryImageVersion` needs `-SourceImageVMId` in Azure PowerShell 11.5.0. --- azure-devops/create-1es-hosted-pool.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-devops/create-1es-hosted-pool.ps1 b/azure-devops/create-1es-hosted-pool.ps1 index 6aebfad04e1..e3e76cdf9b9 100644 --- a/azure-devops/create-1es-hosted-pool.ps1 +++ b/azure-devops/create-1es-hosted-pool.ps1 @@ -314,7 +314,7 @@ $ImageVersion = New-AzGalleryImageVersion ` -GalleryName $GalleryName ` -GalleryImageDefinitionName $ImageDefinitionName ` -Name $ImageVersionName ` - -SourceImageId $VM.ID + -SourceImageVMId $VM.ID #################################################################################################### Display-ProgressBar -Status 'Registering CloudTest resource provider' From eaab19c3005e2e106842cf70b2d06758bd83ed14 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 9 Apr 2024 20:56:34 -0700 Subject: [PATCH 21/28] VS 2022 17.10 Preview 3. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 351d7588a17..80682b0ba3d 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ Just try to follow these rules, so we can spend more time fixing bugs and implem # How To Build With The Visual Studio IDE -1. Install Visual Studio 2022 17.10 Preview 2 or later. +1. Install Visual Studio 2022 17.10 Preview 3 or later. * Select "Windows 11 SDK (10.0.22621.0)" in the VS Installer. * We recommend selecting "C++ CMake tools for Windows" in the VS Installer. This will ensure that you're using supported versions of CMake and Ninja. @@ -156,7 +156,7 @@ Just try to follow these rules, so we can spend more time fixing bugs and implem # How To Build With A Native Tools Command Prompt -1. Install Visual Studio 2022 17.10 Preview 2 or later. +1. Install Visual Studio 2022 17.10 Preview 3 or later. * Select "Windows 11 SDK (10.0.22621.0)" in the VS Installer. * We recommend selecting "C++ CMake tools for Windows" in the VS Installer. This will ensure that you're using supported versions of CMake and Ninja. From 7b36523854e9c369696585a65455e02af1955d7d Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Wed, 10 Apr 2024 10:45:45 -0700 Subject: [PATCH 22/28] Print whether pool creation was successful. --- azure-devops/create-1es-hosted-pool.ps1 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/azure-devops/create-1es-hosted-pool.ps1 b/azure-devops/create-1es-hosted-pool.ps1 index e3e76cdf9b9..9aaf950bfd2 100644 --- a/azure-devops/create-1es-hosted-pool.ps1 +++ b/azure-devops/create-1es-hosted-pool.ps1 @@ -399,4 +399,9 @@ Remove-AzNetworkSecurityGroup ` Write-Progress -Activity $ProgressActivity -Completed Write-Host "Elapsed time: $(((Get-Date) - $CurrentDate).ToString('hh\:mm\:ss'))" -Write-Host "Finished creating pool: $PoolName" + +if ((Get-AzResource -ResourceGroupName $ResourceGroupName -Name $PoolName) -ne $null) { + Write-Host "Created pool: $PoolName" +} else { + Write-Error "Failed to create pool: $PoolName" +} From 12b068b46deecef09d199526b94857351432336e Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Wed, 10 Apr 2024 10:47:51 -0700 Subject: [PATCH 23/28] Style: `} else {` --- azure-devops/provision-image.ps1 | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/azure-devops/provision-image.ps1 b/azure-devops/provision-image.ps1 index 5d582acb1f0..ee3f0ab1a6d 100644 --- a/azure-devops/provision-image.ps1 +++ b/azure-devops/provision-image.ps1 @@ -146,17 +146,14 @@ Function DownloadAndInstall { if ($exitCode -eq 0) { Write-Host 'Installation successful!' - } - elseif ($exitCode -eq 3010) { + } elseif ($exitCode -eq 3010) { Write-Host 'Installation successful! Exited with 3010 (ERROR_SUCCESS_REBOOT_REQUIRED).' - } - else { + } else { Write-Error "Installation failed! Exited with $exitCode." } Remove-Item -Path $installerPath - } - catch { + } catch { Write-Error "Installation failed! Exception: $($_.Exception.Message)" } } From fceb55fb35769a5cfe58a380f8bbe2ad01033004 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 9 Apr 2024 20:55:00 -0700 Subject: [PATCH 24/28] New pool. --- azure-devops/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-devops/config.yml b/azure-devops/config.yml index 33caf0b137a..412ac16ed21 100644 --- a/azure-devops/config.yml +++ b/azure-devops/config.yml @@ -5,7 +5,7 @@ variables: - name: poolName - value: 'StlBuild-2024-03-12T1202-Pool' + value: 'StlBuild-2024-04-10T1048-Pool' readonly: true - name: poolDemands value: 'EnableSpotVM -equals true' From 1cb6d6bd0625bda9e44745e0f98354cc08d163b7 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Wed, 10 Apr 2024 12:00:55 -0700 Subject: [PATCH 25/28] Remove `_VCRT_EXPORT_STD` workarounds. `std.ixx` was explicitly including `` for the workaround, which is no longer necessary. --- stl/inc/exception | 6 ---- stl/inc/new | 10 ------ stl/inc/typeinfo | 17 +--------- stl/modules/std.ixx | 78 --------------------------------------------- 4 files changed, 1 insertion(+), 110 deletions(-) diff --git a/stl/inc/exception b/stl/inc/exception index 3dcd5383965..fa826df924d 100644 --- a/stl/inc/exception +++ b/stl/inc/exception @@ -35,12 +35,6 @@ _STD_END _STD_BEGIN -#ifndef _VCRT_EXPORT_STD // TRANSITION, VCRuntime update expected in 17.10 Preview 3 -// Follow N4971 [module.interface]/6 by exporting aliases (a type alias is not an entity, N4971 [basic.pre]/3): -_EXPORT_STD using exception = exception; -_EXPORT_STD using bad_exception = bad_exception; -#endif // ^^^ workaround ^^^ - _EXPORT_STD using ::terminate; #ifndef _M_CEE_PURE diff --git a/stl/inc/new b/stl/inc/new index ce5517781f9..e8f28cb06e9 100644 --- a/stl/inc/new +++ b/stl/inc/new @@ -18,16 +18,6 @@ _STL_DISABLE_CLANG_WARNINGS #undef new _STD_BEGIN -#ifndef _VCRT_EXPORT_STD // TRANSITION, VCRuntime update expected in 17.10 Preview 3 -#if _HAS_EXCEPTIONS -// Follow N4971 [module.interface]/6 by exporting aliases (a type alias is not an entity, N4971 [basic.pre]/3): -_EXPORT_STD using bad_alloc = bad_alloc; -_EXPORT_STD using bad_array_new_length = bad_array_new_length; -#else // ^^^ _HAS_EXCEPTIONS / !_HAS_EXCEPTIONS vvv -// exports bad_alloc and bad_array_new_length. -#endif // ^^^ !_HAS_EXCEPTIONS ^^^ -#endif // ^^^ workaround ^^^ - #if _HAS_CXX20 _EXPORT_STD struct destroying_delete_t { explicit destroying_delete_t() = default; diff --git a/stl/inc/typeinfo b/stl/inc/typeinfo index 1f9628652e0..e7df437d17a 100644 --- a/stl/inc/typeinfo +++ b/stl/inc/typeinfo @@ -23,27 +23,12 @@ _STL_DISABLE_CLANG_WARNINGS #include #pragma pop_macro("raw_name") -#ifndef _VCRT_EXPORT_STD // TRANSITION, VCRuntime update expected in 17.10 Preview 3 -// Follow N4971 [module.interface]/6 by exporting aliases (a type alias is not an entity, N4971 [basic.pre]/3): -_EXPORT_STD using type_info = type_info; // for typeid, MSVC looks for type_info in the global namespace -#endif // ^^^ workaround ^^^ - _STD_BEGIN // size in pointers of std::function and std::any (roughly 3 pointers larger than std::string when building debug) _INLINE_VAR constexpr int _Small_object_num_ptrs = 6 + 16 / sizeof(void*); -#ifndef _VCRT_EXPORT_STD // TRANSITION, VCRuntime update expected in 17.10 Preview 3 -_EXPORT_STD using ::type_info; -#endif // ^^^ workaround ^^^ - -#if _HAS_EXCEPTIONS -#ifndef _VCRT_EXPORT_STD // TRANSITION, VCRuntime update expected in 17.10 Preview 3 -// Follow N4971 [module.interface]/6 by exporting aliases (a type alias is not an entity, N4971 [basic.pre]/3): -_EXPORT_STD using bad_cast = bad_cast; -_EXPORT_STD using bad_typeid = bad_typeid; -#endif // ^^^ workaround ^^^ -#else // ^^^ _HAS_EXCEPTIONS / !_HAS_EXCEPTIONS vvv +#if !_HAS_EXCEPTIONS _EXPORT_STD class bad_cast : public exception { // base of all bad cast exceptions public: bad_cast(const char* _Message = "bad cast") noexcept : exception(_Message) {} diff --git a/stl/modules/std.ixx b/stl/modules/std.ixx index 0aa355d9e8b..7a5fdbf7cef 100644 --- a/stl/modules/std.ixx +++ b/stl/modules/std.ixx @@ -36,84 +36,6 @@ export module std; #pragma warning(push) #pragma warning(disable : 5244) // '#include ' in the purview of module 'std' appears erroneous. -#include -#ifndef _VCRT_EXPORT_STD // TRANSITION, VCRuntime update expected in 17.10 Preview 3 - -// N4971 [module.interface]/6: "A redeclaration of an entity X is implicitly exported -// if X was introduced by an exported declaration; otherwise it shall not be exported." - -// Therefore, we need to introduce exported declarations of machinery before including it. - -#pragma pack(push, _CRT_PACKING) -#pragma warning(push, _STL_WARNING_LEVEL) -#pragma warning(disable : _STL_DISABLED_WARNINGS) -_STL_DISABLE_CLANG_WARNINGS -#pragma push_macro("new") -#undef new - -_STD_BEGIN -export extern "C++" struct nothrow_t; - -export extern "C++" const nothrow_t nothrow; - -#ifdef __cpp_aligned_new -export extern "C++" enum class align_val_t : size_t; -#endif // ^^^ defined(__cpp_aligned_new) ^^^ -_STD_END - -export extern "C++" _NODISCARD _Ret_notnull_ _Post_writable_byte_size_(_Size) -_VCRT_ALLOCATOR void* __CRTDECL operator new(size_t _Size); -export extern "C++" _NODISCARD _Ret_maybenull_ _Success_(return != NULL) - _Post_writable_byte_size_(_Size) _VCRT_ALLOCATOR void* __CRTDECL - operator new(size_t _Size, const _STD nothrow_t&) noexcept; -export extern "C++" _NODISCARD _Ret_notnull_ _Post_writable_byte_size_(_Size) -_VCRT_ALLOCATOR void* __CRTDECL operator new[](size_t _Size); -export extern "C++" _NODISCARD _Ret_maybenull_ _Success_(return != NULL) - _Post_writable_byte_size_(_Size) _VCRT_ALLOCATOR void* __CRTDECL - operator new[](size_t _Size, const _STD nothrow_t&) noexcept; -export extern "C++" void __CRTDECL operator delete(void* _Block) noexcept; -export extern "C++" void __CRTDECL operator delete(void* _Block, size_t _Size) noexcept; -export extern "C++" void __CRTDECL operator delete(void* _Block, const _STD nothrow_t&) noexcept; -export extern "C++" void __CRTDECL operator delete[](void* _Block) noexcept; -export extern "C++" void __CRTDECL operator delete[](void* _Block, size_t _Size) noexcept; -export extern "C++" void __CRTDECL operator delete[](void* _Block, const _STD nothrow_t&) noexcept; - -#ifdef __cpp_aligned_new -export extern "C++" _NODISCARD _Ret_notnull_ _Post_writable_byte_size_(_Size) -_VCRT_ALLOCATOR void* __CRTDECL operator new(size_t _Size, _STD align_val_t _Al); -export extern "C++" _NODISCARD _Ret_maybenull_ _Success_(return != NULL) - _Post_writable_byte_size_(_Size) _VCRT_ALLOCATOR void* __CRTDECL - operator new(size_t _Size, _STD align_val_t _Al, const _STD nothrow_t&) noexcept; -export extern "C++" _NODISCARD _Ret_notnull_ _Post_writable_byte_size_(_Size) -_VCRT_ALLOCATOR void* __CRTDECL operator new[](size_t _Size, _STD align_val_t _Al); -export extern "C++" _NODISCARD _Ret_maybenull_ _Success_(return != NULL) - _Post_writable_byte_size_(_Size) _VCRT_ALLOCATOR void* __CRTDECL - operator new[](size_t _Size, _STD align_val_t _Al, const _STD nothrow_t&) noexcept; -export extern "C++" void __CRTDECL operator delete(void* _Block, _STD align_val_t _Al) noexcept; -export extern "C++" void __CRTDECL operator delete(void* _Block, size_t _Size, _STD align_val_t _Al) noexcept; -export extern "C++" void __CRTDECL operator delete(void* _Block, _STD align_val_t _Al, const _STD nothrow_t&) noexcept; -export extern "C++" void __CRTDECL operator delete[](void* _Block, _STD align_val_t _Al) noexcept; -export extern "C++" void __CRTDECL operator delete[](void* _Block, size_t _Size, _STD align_val_t _Al) noexcept; -export extern "C++" void __CRTDECL operator delete[]( - void* _Block, _STD align_val_t _Al, const _STD nothrow_t&) noexcept; -#endif // ^^^ defined(__cpp_aligned_new) ^^^ - -export extern "C++" _NODISCARD _MSVC_CONSTEXPR _Ret_notnull_ _Post_writable_byte_size_(_Size) - _Post_satisfies_(return == _Where) void* __CRTDECL - operator new(size_t _Size, _Writable_bytes_(_Size) void* _Where) noexcept; -export extern "C++" _NODISCARD _Ret_notnull_ _Post_writable_byte_size_(_Size) - _Post_satisfies_(return == _Where) void* __CRTDECL - operator new[](size_t _Size, _Writable_bytes_(_Size) void* _Where) noexcept; -export extern "C++" void __CRTDECL operator delete(void*, void*) noexcept; -export extern "C++" void __CRTDECL operator delete[](void*, void*) noexcept; - -#pragma pop_macro("new") -_STL_RESTORE_CLANG_WARNINGS -#pragma warning(pop) -#pragma pack(pop) - -#endif // ^^^ workaround ^^^ - // "C++ library headers" [tab:headers.cpp] #include #if _HAS_STATIC_RTTI From 2746fe0073b09924fcfb624b06cb80733a699223 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Wed, 10 Apr 2024 12:03:59 -0700 Subject: [PATCH 26/28] Remove workaround for VSO-1975579. VSO-1975579 "Standard Library Modules: fatal error C1116: unrecoverable error importing module 'std'. Specialization of 'std::invoke_result_t' with arguments '_Fn, _Ty...'". --- stl/inc/ranges | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/stl/inc/ranges b/stl/inc/ranges index 6ceaec735d5..1407c82e45a 100644 --- a/stl/inc/ranges +++ b/stl/inc/ranges @@ -8979,7 +8979,6 @@ namespace ranges { concept _Regular_invocable_with_repeated_type = _Regular_invocable_with_repeated_type_impl<_Fn, _Ty, make_index_sequence<_Nx>>; -#if defined(__clang__) || defined(__EDG__) // TRANSITION, VSO-1975579 template struct _Invoke_result_with_repeated_type_impl; @@ -8991,19 +8990,6 @@ namespace ranges { template using _Invoke_result_with_repeated_type = _Invoke_result_with_repeated_type_impl<_Fn, _Ty, make_index_sequence<_Nx>>::type; -#else // ^^^ no workaround / workaround vvv - template - struct _Invoke_result_with_repeated_type_impl - : _Invoke_result_with_repeated_type_impl<_Fn, _Ty, _Nx - 1, _Ty, _Types...> {}; - - template - struct _Invoke_result_with_repeated_type_impl<_Fn, _Ty, 0, _Types...> { - using type = invoke_result_t<_Fn, _Types...>; - }; - - template - using _Invoke_result_with_repeated_type = _Invoke_result_with_repeated_type_impl<_Fn, _Ty, _Nx>::type; -#endif // ^^^ workaround ^^^ template concept _Adjacent_transform_constraints = From 514d0aeb7de33e74a51248a1ff15e05b9eaa8f64 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Wed, 10 Apr 2024 12:08:39 -0700 Subject: [PATCH 27/28] Fix DevCom-1586179 VSO-1439353 by removing workarounds for VSO-119526 (fixed) and LLVM-41915 (still active). VSO-119526 "Multiple versions of special member function should be allowed" was fixed after 11 years. LLVM-41915 "Implement CWG 1496" is still active, but implementing `is_trivial` with `__is_trivially_constructible(_Ty) && __is_trivially_copyable(_Ty)` isn't a transparent workaround - it causes DevCom-1586179 VSO-1439353 "std::is_trivial incorrectly fails because of protected defaulted default constructor". Let's just use the dedicated compiler builtin, and blame the compiler if it goes wrong - we've moved away from attempting to compensate for compiler deficiencies in type traits. --- stl/inc/type_traits | 10 ---------- tests/std/tests/P0898R3_concepts/test.cpp | 2 -- 2 files changed, 12 deletions(-) diff --git a/stl/inc/type_traits b/stl/inc/type_traits index 4a93f007b28..43e2ca6a37f 100644 --- a/stl/inc/type_traits +++ b/stl/inc/type_traits @@ -686,21 +686,11 @@ _EXPORT_STD template _CXX17_DEPRECATE_IS_LITERAL_TYPE constexpr bool is_literal_type_v = __is_literal_type(_Ty); #endif // _HAS_DEPRECATED_IS_LITERAL_TYPE -#if 1 // TRANSITION, VSO-119526 and LLVM-41915 -_EXPORT_STD template -struct is_trivial : bool_constant<__is_trivially_constructible(_Ty) && __is_trivially_copyable(_Ty)> { - // determine whether _Ty is a trivial type -}; - -_EXPORT_STD template -constexpr bool is_trivial_v = __is_trivially_constructible(_Ty) && __is_trivially_copyable(_Ty); -#else // ^^^ workaround / no workaround vvv _EXPORT_STD template struct is_trivial : bool_constant<__is_trivial(_Ty)> {}; // determine whether _Ty is a trivial type _EXPORT_STD template constexpr bool is_trivial_v = __is_trivial(_Ty); -#endif // ^^^ no workaround ^^^ _EXPORT_STD template struct is_trivially_copyable : bool_constant<__is_trivially_copyable(_Ty)> { diff --git a/tests/std/tests/P0898R3_concepts/test.cpp b/tests/std/tests/P0898R3_concepts/test.cpp index 7a1f6a4ab60..25d325f814c 100644 --- a/tests/std/tests/P0898R3_concepts/test.cpp +++ b/tests/std/tests/P0898R3_concepts/test.cpp @@ -2223,7 +2223,6 @@ namespace test_copy_constructible { STATIC_ASSERT(test()); STATIC_ASSERT(!test()); -#if defined(__clang__) || defined(__EDG__) // TRANSITION, VSO-119526 // https://github.com/ericniebler/stl2/issues/301 struct NotMutableRef { NotMutableRef() = default; @@ -2240,7 +2239,6 @@ namespace test_copy_constructible { STATIC_ASSERT(!copy_constructible); STATIC_ASSERT(!copy_constructible); -#endif // ^^^ no workaround ^^^ struct UserProvidedCopy { UserProvidedCopy(UserProvidedCopy const&); From 9b5fc60b2ec9b7680eaaf141815dbe6ab29c77e7 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Wed, 10 Apr 2024 13:58:32 -0700 Subject: [PATCH 28/28] Fix test: `ranges::dangling` is non-trivial (properly detected by Clang), but (portably) trivially default constructible. --- .../P0896R4_ranges_algorithm_machinery/test.compile.pass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/P0896R4_ranges_algorithm_machinery/test.compile.pass.cpp b/tests/std/tests/P0896R4_ranges_algorithm_machinery/test.compile.pass.cpp index 42755c4908d..e91f8837942 100644 --- a/tests/std/tests/P0896R4_ranges_algorithm_machinery/test.compile.pass.cpp +++ b/tests/std/tests/P0896R4_ranges_algorithm_machinery/test.compile.pass.cpp @@ -522,7 +522,7 @@ namespace dangling_test { STATIC_ASSERT(std::is_class_v); STATIC_ASSERT(std::semiregular); - STATIC_ASSERT(std::is_trivial_v); // not guaranteed, but likely portable nonetheless + STATIC_ASSERT(std::is_trivially_default_constructible_v); // dangling is constructible from any sequence of arguments without throwing STATIC_ASSERT(is_nothrow_constructible_v);