Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement building the repo for multiple configurations and architectures with a single command on Windows. #33295

Merged
merged 6 commits into from
Mar 11, 2020
24 changes: 17 additions & 7 deletions eng/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ Param(
[switch][Alias('b')]$build,
[switch][Alias('t')]$test,
[switch]$buildtests,
[string][Alias('c')]$configuration = "Debug",
[string[]][Alias('c')]$configuration = @("Debug"),
[string][Alias('f')]$framework,
[string]$vs,
[string]$os,
[switch]$allconfigurations,
[switch]$coverage,
[string]$testscope,
[string]$arch = [System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString().ToLowerInvariant(),
[string[]]$arch = @([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString().ToLowerInvariant()),
[string]$subsetCategory,
[string]$subset,
[ValidateSet("Debug","Release","Checked")][string]$runtimeConfiguration,
Expand Down Expand Up @@ -141,18 +141,28 @@ foreach ($argument in $PSBoundParameters.Keys)
"build" { $arguments += " -build" }
"buildtests" { if ($build -eq $true) { $arguments += " /p:BuildTests=true" } else { $arguments += " -build /p:BuildTests=only" } }
"test" { $arguments += " -test" }
"configuration" { $arguments += " -configuration $((Get-Culture).TextInfo.ToTitleCase($($PSBoundParameters[$argument])))" }
"runtimeConfiguration" { $arguments += " /p:RuntimeConfiguration=$((Get-Culture).TextInfo.ToTitleCase($($PSBoundParameters[$argument])))" }
"framework" { $arguments += " /p:BuildTargetFramework=$($PSBoundParameters[$argument].ToLowerInvariant())" }
"os" { $arguments += " /p:TargetOS=$($PSBoundParameters[$argument])" }
"allconfigurations" { $arguments += " /p:BuildAllConfigurations=true" }
"arch" { $arch = $PSBoundParameters[$argument]; $arguments += " /p:ArchGroup=$arch /p:TargetArchitecture=$arch" }
"properties" { $arguments += " " + $properties }
# configuration and arch can be specified multiple times, so they should be no-ops here
"configuration" {}
"arch" {}
default { $arguments += " /p:$argument=$($PSBoundParameters[$argument])" }
}
}

$env:__DistroRid="win-$arch"
foreach ($config in $configuration) {
$argumentsWithConfig = $arguments + " -configuration $((Get-Culture).TextInfo.ToTitleCase($config))";
foreach ($singleArch in $arch) {
$argumentsWithArch = $argumentsWithConfig + " /p:ArchGroup=$singleArch /p:TargetArchitecture=$singleArch"
$env:__DistroRid="win-$singleArch"
Invoke-Expression "& `"$PSScriptRoot/common/build.ps1`" $argumentsWithArch"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking nit: would it be possible, at least optionally, to somehow run these in parallel?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ll check to see if Windows PowerShell supports that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, this should be a follow-on change, if done.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there's ways to make it run in parallel, but I'm pretty sure that the restore process doesn't support being run in parallel so we'd likely end up with file locking issues during restore (since we'd have multiple different MSBuild processes running in parallel doing the same work).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm certainly not asking for implementing it in this PR, I'm just curious. I can easily imagine it's a more complex piece of work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably the build process is already using maximum machine parallelism, right? At least the compile step is.

if ($lastExitCode -ne 0) {
exit $lastExitCode
}
}
}

Invoke-Expression "& `"$PSScriptRoot/common/build.ps1`" $arguments"
exit $lastExitCode
exit 0