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

Build self-contained minimal size package for Guest Config team #14976

Merged
merged 22 commits into from
Mar 12, 2021

Conversation

daxian-dbw
Copy link
Member

@daxian-dbw daxian-dbw commented Mar 9, 2021

PR Summary

This PR includes changes in Build.psm1, packaging.psm1 and the release build template files.

  • For Build.psm1, -ForMinimalSize is added to Start-PSBuild to build self-contained application for "linux-x64", "win7-x64", or "osx-x64" runtimes. It reduces the size of package by:

    • Avoid CrossGen PowerShell and all other library assemblies.
    • Not include the Graphical Host and the WPF/WinForm stuff it pulls in.
    • Remove symbol files (.pdb) and XML document files (.xml)
  • For packaging.psm1, min-size is added as a new value for -Type parameter of Start-PSPackage.

  • For Windows release build, a new build configuration minSize is added, to build and packaging the min-size package.
    For Linux release build, -TarMinSize is added to PowerShellPackage.ps1 as well as build.json to build and package for the min-size package.

The min-size package has the -gc suffix to indicate that it's for the Guest Config team. In the Azure Blob, the min-size packages are uploaded to the container with the -gc suffix, not in the main package maintainer (e.g. v7-2-0-preview-4), so that they don't get uploaded to the GitHub release page.

Here is the release build run: https://dev.azure.com/mscodehub/PowerShellCore/_build/results?buildId=175764&view=results

The package size is reduced:

  • Windows (x64-zip): from 97mb to 45.3mb
  • Linux (x64-tar.gz): from 63.4mb to 40.6mb

PR Context

PR Checklist

@adityapatwardhan
Copy link
Member

@daxian-dbw - seems like there are some merge conflicts. please have a look.

build.psm1 Outdated Show resolved Hide resolved
tools/packaging/packaging.psm1 Show resolved Hide resolved
$file = $_.FullName
Write-Verbose "Copying $file to $itemDestination" -Verbose
Copy-Item -Path $file -Destination "$itemDestination\" -Force
$projectAssetsCounter++
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where does this get used?

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'm not sure. This was existing code, see below:

Write-Verbose "Exporting project.assets files ..." -Verbose
$projectAssetsCounter = 1
$projectAssetsFolder = Join-Path -Path $destination -ChildPath 'projectAssets'
$projectAssetsZip = Join-Path -Path $destination -ChildPath 'windowsProjectAssetssymbols.zip'
Get-ChildItem $location\project.assets.json -Recurse | ForEach-Object {
$subfolder = $_.FullName.Replace($location,'')
$subfolder.Replace('project.assets.json','')
$itemDestination = Join-Path -Path $projectAssetsFolder -ChildPath $subfolder
New-Item -Path $itemDestination -ItemType Directory -Force
$file = $_.FullName
Write-Verbose "Copying $file to $itemDestination" -Verbose
Copy-Item -Path $file -Destination "$itemDestination\" -Force
$projectAssetsCounter++

@TravisEz13, shall we remove $projectAssetsCounter?

build.psm1 Show resolved Hide resolved
@@ -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.

@kilasuit
Copy link
Collaborator

kilasuit commented Mar 9, 2021

Would this PR address this issue #5681 ?

@daxian-dbw
Copy link
Member Author

@kilasuit This is considered to be one step toward that goal, but doesn't resolve that issue. This package is produced mainly for using PowerShell in a service, where startup perf is not a concern (thus no R2R/Crossgen) and GUI won't work (thus no WPF/WinForm).

@daxian-dbw
Copy link
Member Author

daxian-dbw commented Mar 9, 2021

@adityapatwardhan and @rjmholt Thanks for the review! I have addressed or replied to your comments, please take another look.

Here is the new release build run: https://dev.azure.com/mscodehub/PowerShellCore/_build/results?buildId=175764&view=results

@iSazonov
Copy link
Collaborator

Avoid CrossGen PowerShell and all other library assemblies.

After that why do you build self-contained application? With shared framework you could significantly reduce a size of the packages.

@daxian-dbw
Copy link
Member Author

After that why do you build self-contained application? With shared framework you could significantly reduce a size of the packages.

This is a requirement from the Azure Guest Configuration service. There is no shared framework available and the service depends on PS package to bring in the .NET runtime.
For scenarios that have the shared framework available, the existing fx-depended packages can meet the needs.

@anmenaga
Copy link
Contributor

@adityapatwardhan please take another look; thank you.

@anmenaga anmenaga added the CL-BuildPackaging Indicates that a PR should be marked as a build or packaging change in the Change Log label Mar 12, 2021
@anmenaga anmenaga merged commit b636396 into PowerShell:master Mar 12, 2021
@daxian-dbw daxian-dbw deleted the size branch March 15, 2021 22:53
@ghost
Copy link

ghost commented Mar 16, 2021

🎉v7.2.0-preview.4 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-BuildPackaging Indicates that a PR should be marked as a build or packaging change in the Change Log
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants