Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 42 additions & 17 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ function Start-PSBuild {
[Parameter(ParameterSetName="Default")]
[switch]$NoPSModuleRestore,
[switch]$CI,
[switch]$ForMinimalSize,

# Skips the step where the pwsh that's been built is used to create a configuration
# Useful when changing parsing/compilation, since bugs there can mean we can't get past this step
Expand Down Expand Up @@ -320,6 +321,17 @@ function Start-PSBuild {
if ("win-arm","win-arm64" -contains $Runtime -and -not $environment.IsWindows) {
throw "Cross compiling for win-arm or win-arm64 is only supported on Windows environment"
}

if ($ForMinimalSize) {
if ($CrossGen) {
throw "Build for the minimal size requires the minimal disk footprint, so `CrossGen` is not allowed"
}

if ($Runtime -and "linux-x64", "win7-x64", "osx-x64" -notcontains $Runtime) {
throw "Build for the minimal size is enabled only for following runtimes: 'linux-x64', 'win7-x64', 'osx-x64'"
}
}

function Stop-DevPowerShell {
Get-Process pwsh* |
Where-Object {
Expand Down Expand Up @@ -389,6 +401,7 @@ Fix steps:
Verbose=$true
SMAOnly=[bool]$SMAOnly
PSModuleRestore=$PSModuleRestore
ForMinimalSize=$ForMinimalSize
}
$script:Options = New-PSOptions @OptionsArguments

Expand All @@ -413,7 +426,7 @@ Fix steps:
# Framework Dependent builds do not support ReadyToRun as it needs a specific runtime to optimize for.
# The property is set in Powershell.Common.props file.
# We override the property through the build command line.
if($Options.Runtime -like 'fxdependent*') {
if($Options.Runtime -like 'fxdependent*' -or $ForMinimalSize) {
$Arguments += "/property:PublishReadyToRun=false"
}

Expand Down Expand Up @@ -466,18 +479,21 @@ Fix steps:
Push-Location $Options.Top

if ($Options.Runtime -notlike 'fxdependent*') {
if ($Options.Runtime -like 'win-arm*') {
$Arguments += "/property:SDKToUse=Microsoft.NET.Sdk"
} else {
$Arguments += "/property:SDKToUse=Microsoft.NET.Sdk.WindowsDesktop"
$sdkToUse = 'Microsoft.NET.Sdk'
if ($Options.Runtime -like 'win7-*' -and !$ForMinimalSize) {
## WPF/WinForm and the PowerShell GraphicalHost assemblies are included
## when 'Microsoft.NET.Sdk.WindowsDesktop' is used.
$sdkToUse = 'Microsoft.NET.Sdk.WindowsDesktop'
}

$Arguments += "/property:SDKToUse=$sdkToUse"

Write-Log -message "Run dotnet $Arguments from $PWD"
Start-NativeExecution { dotnet $Arguments }
Write-Log -message "PowerShell output: $($Options.Output)"

if ($CrossGen) {
## fxdependent package cannot be CrossGen'ed
# fxdependent package cannot be CrossGen'ed
Start-CrossGen -PublishPath $publishPath -Runtime $script:Options.Runtime
Write-Log -message "pwsh.exe with ngen binaries is available at: $($Options.Output)"
}
Expand Down Expand Up @@ -650,14 +666,14 @@ function Restore-PSPackage

if ($Force -or (-not (Test-Path "$($Options.Top)/obj/project.assets.json"))) {

$sdkToUse = if (($Options.Runtime -eq 'fxdependent-win-desktop' -or $Options.Runtime -like 'win*')) { # this is fxd or some windows runtime
if ($Options.Runtime -like 'win-arm*') {
'Microsoft.NET.Sdk'
} else {
'Microsoft.NET.Sdk.WindowsDesktop'
if ($Options.Runtime -eq 'fxdependent-win-desktop') {
$sdkToUse = 'Microsoft.NET.Sdk.WindowsDesktop'
}
else {
$sdkToUse = 'Microsoft.NET.Sdk'
if ($Options.Runtime -like 'win7-*' -and !$Options.ForMinimalSize) {
$sdkToUse = 'Microsoft.NET.Sdk.WindowsDesktop'
}
} else {
'Microsoft.NET.Sdk'
}

if ($PSModule.IsPresent) {
Expand Down Expand Up @@ -782,7 +798,9 @@ function New-PSOptions {

[switch]$SMAOnly,

[switch]$PSModuleRestore
[switch]$PSModuleRestore,

[switch]$ForMinimalSize
)

# Add .NET CLI tools to PATH
Expand Down Expand Up @@ -876,7 +894,8 @@ function New-PSOptions {
-Configuration $Configuration `
-PSModuleRestore $PSModuleRestore.IsPresent `
-Framework $Framework `
-Output $Output
-Output $Output `
-ForMinimalSize $ForMinimalSize
}

# Get the Options of the last build
Expand Down Expand Up @@ -3009,7 +3028,8 @@ function Restore-PSOptions {
-Configuration $options.Configuration `
-PSModuleRestore $options.PSModuleRestore `
-Framework $options.Framework `
-Output $options.Output
-Output $options.Output `
-ForMinimalSize $options.ForMinimalSize

Set-PSOptions -Options $newOptions
}
Expand Down Expand Up @@ -3046,7 +3066,11 @@ function New-PSOptionsObject

[Parameter(Mandatory)]
[String]
$Output
$Output,

[Parameter(Mandatory)]
[Bool]
$ForMinimalSize
)

return @{
Expand All @@ -3058,6 +3082,7 @@ function New-PSOptionsObject
Output = $Output
CrossGen = $CrossGen
PSModuleRestore = $PSModuleRestore
ForMinimalSize = $ForMinimalSize
}
}

Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "6.0.100-preview.1.21104.4"
Copy link
Member

Choose a reason for hiding this comment

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

This should not change in this PR right?

Copy link
Member Author

Choose a reason for hiding this comment

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

The 21104.4 is not the official .NET 6 preview.1 SDK version. The nuget package versions are all correct, so this is the only place we need to change to make it use the official 6-preview.1 sdk.

"version": "6.0.100-preview.1.21103.13"
}
}
41 changes: 36 additions & 5 deletions tools/packaging/packaging.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Start-PSPackage {
[string]$Name = "powershell",

# Ubuntu, CentOS, Fedora, macOS, and Windows packages are supported
[ValidateSet("msix", "deb", "osxpkg", "rpm", "msi", "zip", "zip-pdb", "nupkg", "tar", "tar-arm", "tar-arm64", "tar-alpine", "fxdependent", "fxdependent-win-desktop")]
[ValidateSet("msix", "deb", "osxpkg", "rpm", "msi", "zip", "zip-pdb", "nupkg", "tar", "tar-arm", "tar-arm64", "tar-alpine", "fxdependent", "fxdependent-win-desktop", "min-size")]
[string[]]$Type,

# Generate windows downlevel package
Expand All @@ -47,7 +47,7 @@ function Start-PSPackage {
)

DynamicParam {
if ("zip" -eq $Type -or "fxdependent" -eq $Type -or "fxdependent-win-desktop" -eq $Type) {
if ($Type -in ('zip', 'min-size') -or $Type -like 'fxdependent*') {
# Add a dynamic parameter '-IncludeSymbols' when the specified package type is 'zip' only.
# The '-IncludeSymbols' parameter can be used to indicate that the package should only contain powershell binaries and symbols.
$ParameterAttr = New-Object "System.Management.Automation.ParameterAttribute"
Expand Down Expand Up @@ -105,8 +105,9 @@ function Start-PSPackage {
$actualParams = @()

$crossGenCorrect = $false
if ($Runtime -match "arm") {
# crossgen doesn't support arm32/64
if ($Runtime -match "arm" -or $Type -eq 'min-size') {
## crossgen doesn't support arm32/64;
## For the min-size package, we intentionally avoid crossgen.
$crossGenCorrect = $true
}
elseif ($Script:Options.CrossGen) {
Expand Down Expand Up @@ -299,7 +300,37 @@ function Start-PSPackage {
New-PdbZipPackage @Arguments
}
}
"min-size" {
# Remove symbol files, xml document files.
Remove-Item "$Source\*.pdb", "$Source\*.xml" -Force

# Add suffix '-gc' because this package is for the Guest Config team.
if ($Environment.IsWindows) {
$Arguments = @{
PackageNameSuffix = "$NameSuffix-gc"
PackageSourcePath = $Source
PackageVersion = $Version
Force = $Force
}

if ($PSCmdlet.ShouldProcess("Create Zip Package")) {
New-ZipPackage @Arguments
}
}
elseif ($Environment.IsLinux) {
$Arguments = @{
PackageSourcePath = $Source
Name = $Name
PackageNameSuffix = 'gc'
Version = $Version
Force = $Force
}

if ($PSCmdlet.ShouldProcess("Create tar.gz Package")) {
New-TarballPackage @Arguments
}
}
}
{ $_ -like "fxdependent*" } {
## Remove PDBs from package to reduce size.
if(-not $IncludeSymbols.IsPresent) {
Expand All @@ -317,7 +348,7 @@ function Start-PSPackage {
if ($PSCmdlet.ShouldProcess("Create Zip Package")) {
New-ZipPackage @Arguments
}
} elseif ($IsLinux) {
} elseif ($Environment.IsLinux) {
$Arguments = @{
PackageSourcePath = $Source
Name = $Name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ param (
[switch]$TarX64,
[switch]$TarArm,
[switch]$TarArm64,
[switch]$TarMinSize,
[switch]$FxDependent,
[switch]$Alpine
)
Expand Down Expand Up @@ -66,6 +67,7 @@ function BuildPackages {
}

Start-PSBuild @buildParams @releaseTagParam
$options = Get-PSOptions

if ($FxDependent) {
Start-PSPackage -Type 'fxdependent' @releaseTagParam -LTS:$LTS
Expand All @@ -77,6 +79,22 @@ function BuildPackages {

if ($TarX64) { Start-PSPackage -Type tar @releaseTagParam -LTS:$LTS }

if ($TarMinSize) {
Write-Verbose -Verbose "---- Min-Size ----"
Write-Verbose -Verbose "options.Output: $($options.Output)"
Write-Verbose -Verbose "options.Top $($options.Top)"

$binDir = Join-Path -Path $options.Top -ChildPath 'bin'
Write-Verbose -Verbose "Remove $binDir, to get a clean build for min-size package"
Remove-Item -Path $binDir -Recurse -Force

## Build 'min-size' and create 'tar.gz' package for it.
$buildParams['Crossgen'] = $false
$buildParams['ForMinimalSize'] = $true
Start-PSBuild @buildParams @releaseTagParam
Start-PSPackage -Type min-size @releaseTagParam -LTS:$LTS
}

if ($TarArm) {
## Build 'linux-arm' and create 'tar.gz' package for it.
## Note that 'linux-arm' can only be built on Ubuntu environment.
Expand Down
Loading