Create generic Linux-x64 packages that are portable to all supported Linux distros (#4902)

This commit is contained in:
Dongbo Wang 2017-09-25 12:49:43 -07:00 committed by Travis Plunk
parent 65415c3b9e
commit bb3a840e76
3 changed files with 94 additions and 123 deletions

View File

@ -262,6 +262,70 @@ cmd.exe /C cd /d "$location" "&" "$($vcPath)\vcvarsall.bat" "$Arch" "&" cmake "$
}
}
function Start-BuildNativeUnixBinaries {
param (
[switch] $BuildLinuxArm
)
if (-not $Environment.IsLinux -and -not $Environment.IsMacOS) {
Write-Warning -Message "'Start-BuildNativeUnixBinaries' is only supported on Linux/macOS platforms"
return
}
if ($BuildLinuxArm -and -not $Environment.IsUbuntu) {
throw "Cross compiling for linux-arm is only supported on Ubuntu environment"
}
# Verify we have all tools in place to do the build
$precheck = $true
foreach ($Dependency in 'cmake', 'make', 'g++') {
$precheck = $precheck -and (precheck $Dependency "Build dependency '$Dependency' not found. Run 'Start-PSBootstrap'.")
}
if ($BuildLinuxArm) {
foreach ($Dependency in 'arm-linux-gnueabihf-gcc', 'arm-linux-gnueabihf-g++') {
$precheck = $precheck -and (precheck $Dependency "Build dependency '$Dependency' not found. Run 'Start-PSBootstrap'.")
}
}
# Abort if any precheck failed
if (-not $precheck) {
return
}
# Build native components
$Ext = if ($Environment.IsLinux) {
"so"
} elseif ($Environment.IsMacOS) {
"dylib"
}
$Native = "$PSScriptRoot/src/libpsl-native"
$Lib = "$PSScriptRoot/src/powershell-unix/libpsl-native.$Ext"
log "Start building $Lib"
git clean -qfdX $Native
try {
Push-Location $Native
if ($BuildLinuxArm) {
Start-NativeExecution { cmake -DCMAKE_TOOLCHAIN_FILE="./arm.toolchain.cmake" . }
Start-NativeExecution { make -j }
}
else {
Start-NativeExecution { cmake -DCMAKE_BUILD_TYPE=Debug . }
Start-NativeExecution { make -j }
Start-NativeExecution { ctest --verbose }
}
} finally {
Pop-Location
}
if (-not (Test-Path $Lib)) {
throw "Compilation of $Lib failed"
}
}
function Start-PSBuild {
[CmdletBinding()]
param(
@ -299,6 +363,10 @@ function Start-PSBuild {
[string]$ReleaseTag
)
if ($Runtime -eq "linux-arm" -and -not $Environment.IsUbuntu) {
throw "Cross compiling for linux-arm is only supported on Ubuntu environment"
}
function Stop-DevPowerShell {
Get-Process powershell* |
Where-Object {
@ -339,22 +407,8 @@ function Start-PSBuild {
# Add .NET CLI tools to PATH
Find-Dotnet
# Verify we have all tools in place to do the build
# Verify we have .NET SDK in place to do the build, and abort if the precheck failed
$precheck = precheck 'dotnet' "Build dependency 'dotnet' not found in PATH. Run Start-PSBootstrap. Also see: https://dotnet.github.io/getting-started/"
if ($Environment.IsLinux -or $Environment.IsMacOS) {
foreach ($Dependency in 'cmake', 'make', 'g++') {
$precheck = $precheck -and (precheck $Dependency "Build dependency '$Dependency' not found. Run 'Start-PSBootstrap'.")
}
}
if ($RunTime -eq "linux-arm") {
foreach ($Dependency in 'arm-linux-gnueabihf-gcc', 'arm-linux-gnueabihf-g++') {
$precheck = $precheck -and (precheck $Dependency "Build dependency '$Dependency' not found. Run 'Start-PSBootstrap'.")
}
}
# Abort if any precheck failed
if (-not $precheck) {
return
}
@ -441,38 +495,6 @@ Fix steps:
Start-ResGen
}
# Build native components
if (($Environment.IsLinux -or $Environment.IsMacOS) -and -not $SMAOnly) {
$Ext = if ($Environment.IsLinux) {
"so"
} elseif ($Environment.IsMacOS) {
"dylib"
}
$Native = "$PSScriptRoot/src/libpsl-native"
$Lib = "$($Options.Top)/libpsl-native.$Ext"
log "Start building $Lib"
try {
Push-Location $Native
if ($Runtime -eq "linux-arm") {
Start-NativeExecution { cmake -DCMAKE_TOOLCHAIN_FILE="./arm.toolchain.cmake" . }
Start-NativeExecution { make -j }
}
else {
Start-NativeExecution { cmake -DCMAKE_BUILD_TYPE=Debug . }
Start-NativeExecution { make -j }
Start-NativeExecution { ctest --verbose }
}
} finally {
Pop-Location
}
if (-not (Test-Path $Lib)) {
throw "Compilation of $Lib failed"
}
}
# handle TypeGen
if ($TypeGen -or -not (Test-Path "$PSScriptRoot/src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CorePsTypeCatalog.cs")) {
log "Run TypeGen (generating CorePsTypeCatalog.cs)"

View File

@ -16,7 +16,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="*.so;*.dylib;..\..\license_thirdparty_proprietary.txt;..\..\powershell.version;..\..\DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY">
<Content Include="..\..\license_thirdparty_proprietary.txt;..\..\powershell.version;..\..\DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
@ -28,6 +28,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="libpsl" Version="6.0.0-*" />
<PackageReference Include="psrp" Version="1.1.0-*" />
<PackageReference Include="PSDesiredStateConfiguration" Version="1.0.0-alpha01" />
<PackageReference Include="PowerShellHelpFiles" Version="1.0.0-alpha01" />

View File

@ -30,7 +30,7 @@ function Start-PSPackage {
[Switch] $Force,
[Switch] $IncludeSymbols,
[Switch] $SkipReleaseChecks
)
@ -43,11 +43,9 @@ function Start-PSPackage {
New-PSOptions -Configuration "Release" -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration }
}
# We convert the runtime to win7-x64 or win7-x86 to build the universal windows package.
if($Environment.IsWindows) {
$Runtime = $Runtime -replace "win\d+", "win7"
# Build the name suffix for win-plat packages
# Runtime will always be win7-x64 or win7-x86 on Windows.
# Build the name suffix for universal win-plat packages.
$NameSuffix = $Runtime -replace 'win\d+', 'win'
}
@ -134,7 +132,7 @@ function Start-PSPackage {
}
log "Packaging Type: $Type"
# Add the symbols to the suffix
# Add the symbols to the suffix
# if symbols are specified to be included
if($IncludeSymbols.IsPresent -and $NameSuffix) {
$NameSuffix = "symbols-$NameSuffix"
@ -186,7 +184,7 @@ function Start-PSPackage {
{
throw "AppImage does not support packaging '-IncludeSymbols'"
}
if ($Environment.IsUbuntu14) {
$null = Start-NativeExecution { bash -iex "$PSScriptRoot/../appimage.sh" }
$appImage = Get-Item PowerShell-*.AppImage
@ -248,10 +246,6 @@ function New-UnixPackage {
[Parameter(Mandatory)]
[string]$Version,
# Package iteration version (rarely changed)
# This is a string because strings are appended to it
[string]$Iteration = "1",
[Switch]
$Force
)
@ -260,14 +254,14 @@ function New-UnixPackage {
$ErrorMessage = "Must be on {0} to build '$Type' packages!"
switch ($Type) {
"deb" {
$WarningMessage = "Building for Ubuntu {0}.04!"
$verboseMsg = "Building for Ubuntu {0}.04!"
if (!$Environment.IsUbuntu) {
throw ($ErrorMessage -f "Ubuntu")
} elseif ($Environment.IsUbuntu14) {
Write-Warning ($WarningMessage -f "14")
} elseif ($Environment.IsUbuntu16) {
Write-Warning ($WarningMessage -f "16")
}
throw ($ErrorMessage -f "Ubuntu")
} elseif ($Environment.IsUbuntu14) {
Write-Verbose ($verboseMsg -f "14")
} elseif ($Environment.IsUbuntu16) {
Write-Verbose ($verboseMsg -f "16")
}
}
"rpm" {
if (!$Environment.IsRedHatFamily) {
@ -309,7 +303,7 @@ function New-UnixPackage {
# Suffix is used for side-by-side package installation
$Suffix = $Name -replace "^powershell"
if (!$Suffix) {
Write-Warning "Suffix not given, building primary PowerShell package!"
Write-Verbose "Suffix not given, building primary PowerShell package!"
$Suffix = $Version
}
@ -408,73 +402,28 @@ function New-UnixPackage {
"libc6",
"libcurl3",
"libgcc1",
"libssl1.0.0",
"libgssapi-krb5-2",
"liblttng-ust0",
"libstdc++6",
"libtinfo5",
"libunwind8",
"libuuid1",
"zlib1g"
"zlib1g",
"libssl1.0.0",
"libicu-dev"
)
# Please note the different libicu package dependency!
if ($Environment.IsUbuntu14) {
$Dependencies += "libicu52"
} elseif ($Environment.IsUbuntu16) {
$Dependencies += "libicu55"
}
} elseif ($Environment.IsRedHatFamily) {
$Dependencies = @(
"glibc",
"libicu",
"openssl",
"libunwind",
"uuid",
"zlib"
"libcurl",
"openssl-libs",
"libicu"
)
if($Environment.IsFedora -or $Environment.IsCentOS)
{
$Dependencies += "libcurl"
$Dependencies += "libgcc"
$Dependencies += "libstdc++"
$Dependencies += "ncurses-base"
}
if($Environment.IsOpenSUSE)
{
$Dependencies += "libgcc_s1"
$Dependencies += "libstdc++6"
}
}
# iteration is "debian_revision"
# usage of this to differentiate distributions is allowed by non-standard
if ($Environment.IsUbuntu14) {
$Iteration += "ubuntu1.14.04.1"
} elseif ($Environment.IsUbuntu16) {
$Iteration += "ubuntu1.16.04.1"
}
# We currently only support:
# CentOS 7
# Fedora 24+
# OpenSUSE 42.1 (13.2 might build but is EOL)
# Also SEE: https://fedoraproject.org/wiki/Packaging:DistTag
if ($Environment.IsCentOS) {
$rpm_dist = "el7"
} elseif ($Environment.IsFedora) {
$version_id = $Environment.LinuxInfo.VERSION_ID
$rpm_dist = "fedora.$version_id"
} elseif ($Environment.IsOpenSUSE) {
$version_id = $Environment.LinuxInfo.VERSION_ID
$rpm_dist = "suse.$version_id"
}
$Arguments = @(
"--force", "--verbose",
"--name", $Name,
"--version", $Version,
"--iteration", $Iteration,
"--maintainer", "PowerShell Team <PowerShellTeam@hotmail.com>",
"--vendor", "Microsoft Corporation",
"--url", "https://microsoft.com/powershell",
@ -485,7 +434,7 @@ function New-UnixPackage {
"-s", "dir"
)
if ($Environment.IsRedHatFamily) {
$Arguments += @("--rpm-dist", $rpm_dist)
$Arguments += @("--rpm-dist", "rhel.7")
$Arguments += @("--rpm-os", "linux")
}
foreach ($Dependency in $Dependencies) {
@ -504,8 +453,7 @@ function New-UnixPackage {
)
# Build package
try {
if($pscmdlet.ShouldProcess("Create $type package"))
{
if($pscmdlet.ShouldProcess("Create $type package")) {
$Output = Start-NativeExecution { fpm $Arguments }
}
} finally {