Skip to content

Commit

Permalink
Add Microsoft.MSBuildCache (#17393)
Browse files Browse the repository at this point in the history
Add Microsoft.MSBuildCache

This change adds a new pipeline which enables caching in the build. This
is added as a separate pipeline for now with the eventual goal of
enabling for PR and/or CI builds.

Documentation for Microsoft.MSBuildCache can be found in the GitHub
repo: https://github.com/microsoft/MSBuildCache

Preliminary numbers below.

*
[Baseline](https://dev.azure.com/ms/terminal/_build/results?buildId=579399&view=results):
12 min
* [0% Cache
hits](https://dev.azure.com/ms/terminal/_build/results?buildId=579419&view=results):
16 mins
* [100% cache
hits](https://dev.azure.com/ms/terminal/_build/results?buildId=579427&view=results):
3 mins
  • Loading branch information
dfederm authored Jun 20, 2024
1 parent bd116e3 commit 613a539
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 20 deletions.
4 changes: 4 additions & 0 deletions .github/actions/spelling/expect/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ HABCDEF
Hackathon
HALTCOND
HANGEUL
hardlinks
hashalg
HASSTRINGS
hbitmap
Expand Down Expand Up @@ -1080,6 +1081,7 @@ MOUSEFIRST
MOUSEHWHEEL
MOVESTART
msb
msbuildcache
msctf
msctls
msdata
Expand Down Expand Up @@ -1489,6 +1491,7 @@ reparented
reparenting
replatformed
Replymessage
reportfileaccesses
repositorypath
Requiresx
rerasterize
Expand Down Expand Up @@ -2005,6 +2008,7 @@ wincontypes
WINCORE
windbg
WINDEF
windir
windll
WINDOWALPHA
windowdpiapi
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,6 @@ MSG*.bin
profiles.json
*.metaproj
*.swp

# MSBuildCache
/MSBuildCacheLogs/
60 changes: 60 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<Project>
<!--
NOTE! This file gets written-over entirely by the release builds.
Any build logic in this file must be optional and only apply to non-release builds.
-->

<!-- MsBuildCache -->
<PropertyGroup>
<!-- Off by default -->
<MsBuildCacheEnabled Condition="'$(MsBuildCacheEnabled)' == ''">false</MsBuildCacheEnabled>

<!-- Always off during package restore -->
<MsBuildCacheEnabled Condition=" '$(ExcludeRestorePackageImports)' == 'true' ">false</MsBuildCacheEnabled>

<!-- In Azure pipelines, use Pipeline Caching as the cache storage backend. Otherwise, use the local cache. -->
<MSBuildCachePackageName Condition="'$(TF_BUILD)' != ''">Microsoft.MSBuildCache.AzurePipelines</MSBuildCachePackageName>
<MSBuildCachePackageName Condition="'$(MSBuildCachePackageName)' == ''">Microsoft.MSBuildCache.Local</MSBuildCachePackageName>
</PropertyGroup>

<PropertyGroup Condition="'$(MSBuildCacheEnabled)' == 'true'">
<!-- Change this to bust the cache -->
<MSBuildCacheCacheUniverse Condition="'$(MSBuildCacheCacheUniverse)' == ''">202310210737</MSBuildCacheCacheUniverse>

<!--
Visual Studio telemetry reads various ApplicationInsights.config files and other files after the project is finished, likely in a detached process.
This is acceptable and should not impact cache correctness.
-->
<MSBuildCacheAllowFileAccessAfterProjectFinishFilePatterns>
$(MSBuildCacheAllowFileAccessAfterProjectFinishFilePatterns);
\**\ApplicationInsights.config;
$(LocalAppData)\Microsoft\VSApplicationInsights\**;
$(LocalAppData)\Microsoft\Windows\INetCache\**;
A:\;
E:\;
$(windir)\**;
</MSBuildCacheAllowFileAccessAfterProjectFinishFilePatterns>

<!--
This repo uses a common output directory with many projects writing duplicate outputs. Allow everything, but note this costs some performance in the form of requiring
the cache to use copies instead of hardlinks when pulling from cache.
-->
<MSBuildCacheIdenticalDuplicateOutputPatterns>$(MSBuildCacheIdenticalDuplicateOutputPatterns);bin\**</MSBuildCacheIdenticalDuplicateOutputPatterns>

<!-- version of MSBuildCache is not part of the cache key -->
<PackagesConfigFile>$(MSBuildThisFileDirectory)\dep\nuget\packages.config</PackagesConfigFile>
<MSBuildCacheIgnoredInputPatterns>$(MSBuildCacheIgnoredInputPatterns);$(PackagesConfigFile)</MSBuildCacheIgnoredInputPatterns>
</PropertyGroup>

<PropertyGroup Condition="'$(MSBuildCacheEnabled)' == 'true' and '$(MSBuildCachePackageRoot)' == ''">
<PackagesConfigContents>$([System.IO.File]::ReadAllText("$(PackagesConfigFile)"))</PackagesConfigContents>
<MSBuildCachePackageVersion>$([System.Text.RegularExpressions.Regex]::Match($(PackagesConfigContents), 'Microsoft.MSBuildCache.*?version="(.*?)"').Groups[1].Value)</MSBuildCachePackageVersion>
<MSBuildCachePackageRoot>$(MSBuildThisFileDirectory)packages\$(MSBuildCachePackageName).$(MSBuildCachePackageVersion)</MSBuildCachePackageRoot>
<MSBuildCacheSharedCompilationPackageRoot>$(MSBuildThisFileDirectory)packages\Microsoft.MSBuildCache.SharedCompilation.$(MSBuildCachePackageVersion)</MSBuildCacheSharedCompilationPackageRoot>
</PropertyGroup>

<ImportGroup Condition="'$(MSBuildCacheEnabled)' == 'true'">
<Import Project="$(MSBuildCachePackageRoot)\build\$(MSBuildCachePackageName).props" />
<Import Project="$(MSBuildCacheSharedCompilationPackageRoot)\build\Microsoft.MSBuildCache.SharedCompilation.props" />
</ImportGroup>
</Project>
11 changes: 11 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project>
<!--
NOTE! This file gets written-over entirely by the release builds.
Any build logic in this file must be optional and only apply to non-release builds.
-->

<ImportGroup Condition="'$(MSBuildCacheEnabled)' == 'true'">
<Import Project="$(MSBuildCachePackageRoot)\build\$(MSBuildCachePackageName).targets" />
<Import Project="$(MSBuildCacheSharedCompilationPackageRoot)\build\Microsoft.MSBuildCache.SharedCompilation.targets" />
</ImportGroup>
</Project>
44 changes: 24 additions & 20 deletions build/pipelines/ci-caching.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
trigger:
batch: true
# branches:
# include:
# - main
# - feature/*
# - gh-readonly-queue/*
# paths:
# exclude:
# - doc/*
# - samples/*
# - tools/*
branches:
include:
- main
- feature/*
- gh-readonly-queue/*
paths:
exclude:
- doc/*
- samples/*
- tools/*

#pr:
# branches:
# include:
# - main
# - feature/*
# paths:
# exclude:
# - doc/*
# - samples/*
# - tools/*
pr:
branches:
include:
- main
- feature/*
paths:
exclude:
- doc/*
- samples/*
- tools/*

variables:
- name: runCodesignValidationInjectionBG
value: false
- name: EnablePipelineCache
value: true

# 0.0.yyMM.dd##
# 0.0.1904.0900
Expand Down Expand Up @@ -81,6 +83,8 @@ stages:
buildConfigurations: [Release]
buildEverything: true
keepAllExpensiveBuildOutputs: false
${{ if eq(variables['System.PullRequest.IsFork'], 'False') }}:
enableCaching: true

- ${{ if eq(parameters.runTests, true) }}:
- stage: Test_${{ platform }}
Expand Down
32 changes: 32 additions & 0 deletions build/pipelines/templates-v2/job-build-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ parameters:
- name: signingIdentity
type: object
default: {}
- name: enableCaching
type: boolean
default: false

jobs:
- job: ${{ parameters.jobName }}
Expand Down Expand Up @@ -95,6 +98,7 @@ jobs:
# Yup.
BuildTargetParameter: ' '
SelectedSigningFragments: ' '
MSBuildCacheParameters: ' '
# When building the unpackaged distribution, build it in portable mode if it's Canary-branded
${{ if eq(parameters.branding, 'Canary') }}:
UnpackagedBuildArguments: -PortableMode
Expand All @@ -111,6 +115,7 @@ jobs:
clean: true
submodules: true
persistCredentials: True

# This generates either nothing for BuildTargetParameter, or /t:X;Y;Z, to control targets later.
- pwsh: |-
If (-Not [bool]::Parse("${{ parameters.buildEverything }}")) {
Expand Down Expand Up @@ -139,6 +144,17 @@ jobs:
}
displayName: Prepare Build and Sign Targets
- ${{ if eq(parameters.enableCaching, true) }}:
- pwsh: |-
$MSBuildCacheParameters = ""
$MSBuildCacheParameters += " -graph"
$MSBuildCacheParameters += " -reportfileaccesses"
$MSBuildCacheParameters += " -p:MSBuildCacheEnabled=true"
$MSBuildCacheParameters += " -p:MSBuildCacheLogDirectory=$(Build.SourcesDirectory)\MSBuildCacheLogs"
Write-Host "MSBuildCacheParameters: $MSBuildCacheParameters"
Write-Host "##vso[task.setvariable variable=MSBuildCacheParameters]$MSBuildCacheParameters"
displayName: Prepare MSBuildCache variables
- pwsh: |-
.\build\scripts\Generate-ThirdPartyNotices.ps1 -MarkdownNoticePath .\NOTICE.md -OutputPath .\src\cascadia\CascadiaPackage\NOTICE.html
displayName: Generate NOTICE.html from NOTICE.md
Expand All @@ -160,21 +176,37 @@ jobs:
${{ parameters.additionalBuildOptions }}
/bl:$(Build.SourcesDirectory)\msbuild.binlog
$(BuildTargetParameter)
$(MSBuildCacheParameters)
platform: $(BuildPlatform)
configuration: $(BuildConfiguration)
msbuildArchitecture: x64
maximumCpuCount: true
${{ if eq(parameters.enableCaching, true) }}:
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)

- ${{ if eq(parameters.publishArtifacts, true) }}:
- publish: $(Build.SourcesDirectory)/msbuild.binlog
artifact: logs-$(BuildPlatform)-$(BuildConfiguration)${{ parameters.artifactStem }}
condition: always()
displayName: Publish Build Log
- ${{ if eq(parameters.enableCaching, true) }}:
- publish: $(Build.SourcesDirectory)\MSBuildCacheLogs
artifact: logs-msbuildcache-$(BuildPlatform)-$(BuildConfiguration)${{ parameters.artifactStem }}
condition: always()
displayName: Publish MSBuildCache Logs
- ${{ else }}:
- task: CopyFiles@2
displayName: Copy Build Log
inputs:
contents: $(Build.SourcesDirectory)/msbuild.binlog
TargetFolder: $(Terminal.BinDir)
- ${{ if eq(parameters.enableCaching, true) }}:
- task: CopyFiles@2
displayName: Copy MSBuildCache Logs
inputs:
contents: $(Build.SourcesDirectory)/MSBuildCacheLogs/**
TargetFolder: $(Terminal.BinDir)/MSBuildCacheLogs

# This saves ~2GiB per architecture. We won't need these later.
# Removes:
Expand Down
5 changes: 5 additions & 0 deletions dep/nuget/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net45" />
<package id="Selenium.Support" version="3.5.0" targetFramework="net45" />
<package id="Selenium.WebDriver" version="3.5.0" targetFramework="net45" />

<!-- MSBuildCache -->
<package id="Microsoft.MSBuildCache.AzurePipelines" version="0.1.273-preview" />
<package id="Microsoft.MSBuildCache.Local" version="0.1.273-preview" />
<package id="Microsoft.MSBuildCache.SharedCompilation" version="0.1.273-preview" />
</packages>

0 comments on commit 613a539

Please sign in to comment.