Update repo SDK and build authoring (#942)

* Bump 5.0 SDK and runtimes to 6.0

* Make it very clear that Powershell 7 is required

The new `#Requires` line makes the DoAll script fail fast with a helpful error:

> .\DoAll.ps1 : The script 'DoAll.ps1' cannot be run because it contained a "#requires" statement for Windows PowerShell 7.0. The version of Windows PowerShell that is required by the script does not match the currently running version of Windows PowerShell 5.1.22000.653.

Before this, the user may get some weird error about `Select-String -Raw` not working.

* Fix BuildSdk.proj default build

It doesn't like to be *built*. It only likes to be packed.

* Improve discovery of VS installations

* Install the .NET 5 runtime for ClangSharpPInvokeGenerator
This commit is contained in:
Andrew Arnott 2022-06-01 16:16:12 -06:00 коммит произвёл GitHub
Родитель 1985a6ec15
Коммит b286d8956c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
29 изменённых файлов: 175 добавлений и 42 удалений

Просмотреть файл

@ -178,6 +178,8 @@ Language projections can use the context provided by attributes to improve the d
### Full builds
The ps1 scripts prescribed below must be run in a PowerShell 7+ terminal. You'll get syntax errors from the scripts if you try to run them from Windows Powershell.
Run `./DoAll.ps1 -Clean` to run a full build, then inspect the reported winmd diff to ensure all changes were intentional. A full build can take 25-30 minutes.
If you encounter errors processing .zip or .winmd files, make sure that Git LFS is installed and configured properly per [set up your development environment](#Set-up-your-development-environment).

Просмотреть файл

@ -15,7 +15,7 @@
<OutputPath>$(RepoRootPath)bin\$(Configuration)</OutputPath>
<PackageOutputPath>$(MSBuildThisFileDirectory)bin\Packages\$(Configuration)\NuGet\</PackageOutputPath>
<LocalTaskBinDir>$(RepoRootPath)bin\$(Configuration)\net5.0\</LocalTaskBinDir>
<LocalTaskBinDir>$(RepoRootPath)bin\$(Configuration)\net6.0\</LocalTaskBinDir>
<LangVersion>9</LangVersion>

Просмотреть файл

@ -1,3 +1,5 @@
#Requires -Version 7.0
param
(
[switch]$Clean,

Просмотреть файл

@ -23,7 +23,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ScrapeDocs\ScrapeDocs.csproj" ReferenceOutputAssembly="false" OutputItemType="ScraperTool" SetTargetFramework="TargetFramework=net5.0" />
<ProjectReference Include="..\ScrapeDocs\ScrapeDocs.csproj" ReferenceOutputAssembly="false" OutputItemType="ScraperTool" SetTargetFramework="TargetFramework=net6.0" />
</ItemGroup>
<Import Project="Microsoft.Windows.SDK.Win32Docs.targets" />

Просмотреть файл

@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<!-- Use plural TargetFrameworks here because we set the singular as a global property in a referencing project. -->
<TargetFrameworks>net5.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

Просмотреть файл

@ -26,6 +26,12 @@ jobs:
inputs:
packageType: sdk
useGlobalJson: true
# ClangSharpPInvokeGenerator.exe requires .NET 5.0
- task: UseDotNet@2
displayName: ⚙ Install .NET 5.0
inputs:
packageType: runtime
version: 5.0.x
- task: PowerShell@2
displayName: Set build version
@ -65,6 +71,12 @@ jobs:
inputs:
packageType: sdk
useGlobalJson: true
# ClangSharpPInvokeGenerator.exe requires .NET 5.0
- task: UseDotNet@2
displayName: ⚙ Install .NET 5.0
inputs:
packageType: runtime
version: 5.0.x
- task: PowerShell@2
displayName: GenerateMetadataSource.ps1 - x86
@ -93,6 +105,12 @@ jobs:
inputs:
packageType: sdk
useGlobalJson: true
# ClangSharpPInvokeGenerator.exe requires .NET 5.0
- task: UseDotNet@2
displayName: ⚙ Install .NET 5.0
inputs:
packageType: runtime
version: 5.0.x
- task: PowerShell@2
displayName: GenerateMetadataSource.ps1 - arm64
@ -131,6 +149,12 @@ jobs:
packageType: sdk
useGlobalJson: true
# ClangSharpPInvokeGenerator.exe requires .NET 5.0
- task: UseDotNet@2
displayName: ⚙ Install .NET 5.0
inputs:
packageType: runtime
version: 5.0.x
# ESRP Authenticode sign package DLLs
- task: UseDotNet@2
displayName: Install DotNet 2.1.x for signing tasks
@ -216,10 +240,10 @@ jobs:
condition: and(succeeded(), eq(variables['SignFiles'], 'true'), ne(variables['Build.Reason'], 'PullRequest'))
- task: EsrpCodeSigning@1
displayName: Authenticode sign net5.0 binaries in Generator SDK package
displayName: Authenticode sign net6.0 binaries in Generator SDK package
inputs:
ConnectedServiceName: 'Xlang Code Signing'
FolderPath: '$(Build.SourcesDirectory)\bin\$(BuildConfiguration)\net5.0'
FolderPath: '$(Build.SourcesDirectory)\bin\$(BuildConfiguration)\net6.0'
Pattern: 'ClangSharpSourceToWinmd.dll,ConstantsScraper.dll,MetadataUtils.dll,WinmdUtils.dll,MetadataTasks.dll'
signConfigType: 'inlineSignParams'
inlineOperation: |

Просмотреть файл

@ -5,7 +5,7 @@
<!-- These are for debugging purposes only. A normal project wouldn't set these -->
<PropertyGroup>
<ToolsBinDir>$(RepoRootPath)bin\$(Configuration)\net5.0</ToolsBinDir>
<ToolsBinDir>$(RepoRootPath)bin\$(Configuration)\net6.0</ToolsBinDir>
<LibToolsBinDir>$(RepoRootPath)tools</LibToolsBinDir>
<ScriptsDir>$(RepoRootPath)scripts</ScriptsDir>
<Win32MetadataAssetsDir>$(RepoRootPath)sources\GeneratorSdk\tools\assets</Win32MetadataAssetsDir>
@ -35,7 +35,7 @@
</ItemGroup>
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputWinmd Condition="'$(OutputWinmd)' == ''">..\..\bin\Windows.Win32.winmd</OutputWinmd>
<WinmdVersion Condition="'$(WinmdVersion)' == ''">1.0.0.0</WinmdVersion>
<GenerateAssemblyVersionInfo>false</GenerateAssemblyVersionInfo>

Просмотреть файл

@ -1,6 +1,6 @@
{
"sdk": {
"version": "5.0.400",
"version": "6.0.300",
"allowPrerelease": false,
"rollForward": "feature"
},

Просмотреть файл

@ -6,7 +6,7 @@ $sdkApiPath = "$rootDir\ext\sdk-api"
$windowsWin32ProjectRoot = "$rootDir\generation\WinSDK"
$sdkGeneratedSourceDir = "$windowsWin32ProjectRoot\obj\generated"
$recompiledIdlHeadersDir = "$windowsWin32ProjectRoot\RecompiledIdlHeaders"
$metadataToolsBin = "$binDir\release\net5.0"
$metadataToolsBin = "$binDir\release\net6.0"
# [VS 1673159]
# Temporarily disable strict mode to address bug introduced
@ -171,9 +171,8 @@ function Get-VcDirPath
{
param ($Arch = 'x64', $HostArch = 'x64')
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$installDir = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
if ($installDir)
$installDir = & "$PSScriptRoot\Get-VSPath.ps1"
try
{
$path = join-path $installDir 'VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt'
if (test-path $path)
@ -186,9 +185,14 @@ function Get-VcDirPath
return $path
}
}
}
return $null
return $null
}
finally
{
# This doesn't need anything, but putting the script in a try block leads to it aborting
# when a child script throws.
}
}
function Install-VsDevShell
@ -196,9 +200,7 @@ function Install-VsDevShell
if (!$env:VSINSTALLDIR)
{
$currentDir = Get-Location
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$installDir = & $vswhere -latest -property installationPath
$installDir = & "$PSScriptRoot\Get-VSPath.ps1"
$vsInstallScript = Join-Path $installDir "Common7\Tools\Launch-VsDevShell.ps1"
& $vsInstallScript

Просмотреть файл

@ -0,0 +1,6 @@
# Get IDs from https://docs.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-enterprise
# Please keep this list sorted.
'Microsoft.VisualStudio.Component.VC.Tools.x86.x64'
'Microsoft.VisualStudio.Component.VC.Tools.ARM64'

26
scripts/Get-VSPath.ps1 Normal file
Просмотреть файл

@ -0,0 +1,26 @@
$vswherePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if (-not (Test-Path $vswherePath)) {
throw "Unable to find vswhere.exe. Is VS 2017 15.3 or later installed? Use $PSScriptRoot\Install-VS.ps1 to acquire VS with the required components."
exit 1
}
$workloadsRequired = & "$PSScriptRoot\Get-RequiredWorkloads.ps1"
$vswhereArgs = & "$PSScriptRoot\Get-VSWhereBaseArgs.ps1"
$vswhereArgs += '-latest'
$workloadsRequired |% {
$vswhereArgs += '-requires',$_
}
Write-Verbose "`"$vswherePath`" $vswhereArgs"
$output = & $vswherePath $vswhereArgs
if ($lastexitcode -eq 87) {
$vswhere = [xml]'<instances />'
} else {
$vswhere = [xml]$output
}
if ($vswhere.instances.length -eq 0) {
throw "No VS installation detected that has all the required workloads installed ($workloadsRequired). Use $PSScriptRoot\Install-VS.ps1 to acquire VS with the required components."
exit 2
}
Write-Output $vswhere.instances.instance.installationPath

Просмотреть файл

@ -0,0 +1,5 @@
'-prerelease'
'-format'
'xml'
'-version'
'[17.0,18.0)'

Просмотреть файл

@ -1,9 +1,7 @@
param ($Arch = 'x64', $HostArch = 'x64')
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$installDir = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
if ($installDir)
{
try {
$installDir = & "$PSScriptRoot\Get-VSPath.ps1"
$path = join-path $installDir 'VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt'
if (test-path $path)
{
@ -15,6 +13,9 @@ if ($installDir)
return $path
}
}
}
return $null
return $null
} finally {
# This doesn't need anything, but putting the script in a try block leads to it aborting
# when a child script throws.
}

65
scripts/Install-VS.ps1 Normal file
Просмотреть файл

@ -0,0 +1,65 @@
<#
.SYNOPSIS
Installs VS or modifies an existing installation such that it includes all the required components to build this repo.
.PARAMETER VSInstallPath
The path to the VS install to modify. This should be the root path (not including the Common7 directory).
Should not be used in combination with -Nickname. If neither is specified, the 'latest' install of VS is modified.
.PARAMETER Nickname
The nickname of the install to modify.
Should not be used in combination with -VSInstallPath. If neither is specified, the 'latest' install of VS is modified.
#>
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='Low')]
Param(
[Parameter()]
[string]$VSInstallPath,
[Parameter()]
[string]$Nickname
)
if ($VSInstallPath -and $Nickname) {
throw "Do not specify both -VSInstallPath and -Nickname parameters."
}
# PowerShell completion likes to add a trailing backslash, but this breaks what we do later.
$VSInstallPath = $VSInstallPath.TrimEnd('\')
# Docs for VS installer command line: https://docs.microsoft.com/en-us/visualstudio/install/use-command-line-parameters-to-install-visual-studio
$installerArgs = @()
$vsInstallerPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vs_installer.exe"
if (!(Test-Path $vsInstallerPath)) {
$vsInstallerPath = "$env:TEMP\vs_enterprise.exe"
(New-Object System.Net.WebClient).DownloadFile("https://aka.ms/vs/17/release/vs_enterprise.exe", $vsInstallerPath)
}
$vswherePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if (Test-Path $vswherePath) {
$vswhereArgs = & "$PSScriptRoot\Get-VSWhereBaseArgs.ps1"
if (-not ($VSInstallPath -or $Nickname)) {
$vswhereArgs += '-latest'
}
$installs = [xml](& $vswherePath $vswhereArgs)
if ($VSInstallPath) {
$vsInstallInstance = $installs.instances.instance |? { $_.installationPath -eq $VSInstallPath }
if (!$vsInstallInstance) { throw "No VS instance found with path `"$VSInstallPath`"." }
} elseif ($Nickname) {
$vsInstallInstance = $installs.instances.instance |? { $_.properties.nickname -eq $Nickname }
if (!$vsInstallInstance) { throw "No VS instance found with nickname `"$NickName`"." }
} else {
$vsInstallInstance = $installs.instances.instance
}
$vsInstallPath = $vsInstallInstance.installationPath
}
if ($vsInstallPath) {
# Modify an existing install
$installerArgs += 'modify'
$installerArgs += '--installPath',$vsInstallPath
}
$workloadsRequired = & "$PSScriptRoot\Get-RequiredWorkloads.ps1"
$installerArgs += $workloadsRequired |% { '--add', $_ }
& $vsInstallerPath $installerArgs

Просмотреть файл

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

Просмотреть файл

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>

Просмотреть файл

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<WarningLevel>5</WarningLevel>
<NoWarn>1701;1702;</NoWarn>
</PropertyGroup>

Просмотреть файл

@ -22,9 +22,9 @@
<file src="sources\GeneratorSdk\sdk\sdk.stamped.props" target="sdk\sdk.props"/>
<file src="sources\GeneratorSdk\sdk\sdk.targets" target="sdk"/>
<file src="bin\release\net5.0\*.deps.json" target="tools\net5.0"/>
<file src="bin\release\net5.0\*.runtimeconfig.json" target="tools\net5.0"/>
<file src="bin\release\net5.0\*.dll" target="tools\net5.0" />
<file src="bin\release\net6.0\*.deps.json" target="tools\net6.0"/>
<file src="bin\release\net6.0\*.runtimeconfig.json" target="tools\net6.0"/>
<file src="bin\release\net6.0\*.dll" target="tools\net6.0" />
<file src="scripts\InstallTools.ps1" target="scripts"/>
<file src="scripts\ConvertMidlAttributesToSalAnnotations.ps1" target="scripts"/>
<file src="scripts\GetVcDirPath.ps1" target="scripts"/>

Просмотреть файл

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Pack">
<PropertyGroup>
<PowerShell># 2>nul || type %~df0|find /v "setlocal"|find /v "errorlevel"|powershell.exe -noninteractive -&amp; exit %errorlevel% || #</PowerShell>
</PropertyGroup>

Просмотреть файл

@ -3,7 +3,7 @@
<!-- These are for debugging purposes only. A normal project wouldn't set these -->
<PropertyGroup>
<ToolsBinDir>$(RepoRootPath)bin\$(Configuration)\net5.0</ToolsBinDir>
<ToolsBinDir>$(RepoRootPath)bin\$(Configuration)\net6.0</ToolsBinDir>
<LibToolsBinDir>$(RepoRootPath)tools</LibToolsBinDir>
<ScriptsDir>$(RepoRootPath)scripts</ScriptsDir>
<Win32MetadataAssetsDir>$(RepoRootPath)sources\GeneratorSdk\tools\assets</Win32MetadataAssetsDir>

Просмотреть файл

@ -7,7 +7,7 @@
<Import Condition="'$(UsingMicrosoftNoTargetsSdk)' != 'true'" Sdk="Microsoft.Build.NoTargets" Version="3.0.4" Project="sdk.props"/>
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<TargetPlatformIdentifier>Windows</TargetPlatformIdentifier>
<ScanArch>crossarch</ScanArch>
</PropertyGroup>
@ -22,8 +22,8 @@
<PropertyGroup>
<Win32MetadataSdkRoot>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..'))</Win32MetadataSdkRoot>
<TaskBinDir Condition="'$(TaskBinDir)' == ''">$(Win32MetadataSdkRoot)\tools\net5.0</TaskBinDir>
<ToolsBinDir Condition="'$(ToolsBinDir)' == ''">$(Win32MetadataSdkRoot)\tools\net5.0</ToolsBinDir>
<TaskBinDir Condition="'$(TaskBinDir)' == ''">$(Win32MetadataSdkRoot)\tools\net6.0</TaskBinDir>
<ToolsBinDir Condition="'$(ToolsBinDir)' == ''">$(Win32MetadataSdkRoot)\tools\net6.0</ToolsBinDir>
<LibToolsBinDir Condition="'$(LibToolsBinDir)' == ''">$(Win32MetadataSdkRoot)\tools</LibToolsBinDir>
<ScriptsDir Condition="'$(ScriptsDir)' == ''">$(Win32MetadataSdkRoot)\scripts</ScriptsDir>
<ObjDir Condition="'$(ObjDir)' == ''">$(MSBuildProjectDirectory)\obj</ObjDir>

Просмотреть файл

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">

Просмотреть файл

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>

Просмотреть файл

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>

Просмотреть файл

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

Просмотреть файл

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Просмотреть файл

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>

Просмотреть файл

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>

Просмотреть файл

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>