Skip to content

Commit bb3a840

Browse files
daxian-dbwTravisEz13
authored andcommitted
Create generic Linux-x64 packages that are portable to all supported Linux distros (PowerShell#4902)
1 parent 65415c3 commit bb3a840

File tree

3 files changed

+94
-123
lines changed

3 files changed

+94
-123
lines changed

build.psm1

Lines changed: 69 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,70 @@ cmd.exe /C cd /d "$location" "&" "$($vcPath)\vcvarsall.bat" "$Arch" "&" cmake "$
262262
}
263263
}
264264

265+
function Start-BuildNativeUnixBinaries {
266+
param (
267+
[switch] $BuildLinuxArm
268+
)
269+
270+
if (-not $Environment.IsLinux -and -not $Environment.IsMacOS) {
271+
Write-Warning -Message "'Start-BuildNativeUnixBinaries' is only supported on Linux/macOS platforms"
272+
return
273+
}
274+
275+
if ($BuildLinuxArm -and -not $Environment.IsUbuntu) {
276+
throw "Cross compiling for linux-arm is only supported on Ubuntu environment"
277+
}
278+
279+
# Verify we have all tools in place to do the build
280+
$precheck = $true
281+
foreach ($Dependency in 'cmake', 'make', 'g++') {
282+
$precheck = $precheck -and (precheck $Dependency "Build dependency '$Dependency' not found. Run 'Start-PSBootstrap'.")
283+
}
284+
285+
if ($BuildLinuxArm) {
286+
foreach ($Dependency in 'arm-linux-gnueabihf-gcc', 'arm-linux-gnueabihf-g++') {
287+
$precheck = $precheck -and (precheck $Dependency "Build dependency '$Dependency' not found. Run 'Start-PSBootstrap'.")
288+
}
289+
}
290+
291+
# Abort if any precheck failed
292+
if (-not $precheck) {
293+
return
294+
}
295+
296+
# Build native components
297+
$Ext = if ($Environment.IsLinux) {
298+
"so"
299+
} elseif ($Environment.IsMacOS) {
300+
"dylib"
301+
}
302+
303+
$Native = "$PSScriptRoot/src/libpsl-native"
304+
$Lib = "$PSScriptRoot/src/powershell-unix/libpsl-native.$Ext"
305+
log "Start building $Lib"
306+
307+
git clean -qfdX $Native
308+
309+
try {
310+
Push-Location $Native
311+
if ($BuildLinuxArm) {
312+
Start-NativeExecution { cmake -DCMAKE_TOOLCHAIN_FILE="./arm.toolchain.cmake" . }
313+
Start-NativeExecution { make -j }
314+
}
315+
else {
316+
Start-NativeExecution { cmake -DCMAKE_BUILD_TYPE=Debug . }
317+
Start-NativeExecution { make -j }
318+
Start-NativeExecution { ctest --verbose }
319+
}
320+
} finally {
321+
Pop-Location
322+
}
323+
324+
if (-not (Test-Path $Lib)) {
325+
throw "Compilation of $Lib failed"
326+
}
327+
}
328+
265329
function Start-PSBuild {
266330
[CmdletBinding()]
267331
param(
@@ -299,6 +363,10 @@ function Start-PSBuild {
299363
[string]$ReleaseTag
300364
)
301365

366+
if ($Runtime -eq "linux-arm" -and -not $Environment.IsUbuntu) {
367+
throw "Cross compiling for linux-arm is only supported on Ubuntu environment"
368+
}
369+
302370
function Stop-DevPowerShell {
303371
Get-Process powershell* |
304372
Where-Object {
@@ -339,22 +407,8 @@ function Start-PSBuild {
339407
# Add .NET CLI tools to PATH
340408
Find-Dotnet
341409

342-
# Verify we have all tools in place to do the build
410+
# Verify we have .NET SDK in place to do the build, and abort if the precheck failed
343411
$precheck = precheck 'dotnet' "Build dependency 'dotnet' not found in PATH. Run Start-PSBootstrap. Also see: https://dotnet.github.io/getting-started/"
344-
345-
if ($Environment.IsLinux -or $Environment.IsMacOS) {
346-
foreach ($Dependency in 'cmake', 'make', 'g++') {
347-
$precheck = $precheck -and (precheck $Dependency "Build dependency '$Dependency' not found. Run 'Start-PSBootstrap'.")
348-
}
349-
}
350-
351-
if ($RunTime -eq "linux-arm") {
352-
foreach ($Dependency in 'arm-linux-gnueabihf-gcc', 'arm-linux-gnueabihf-g++') {
353-
$precheck = $precheck -and (precheck $Dependency "Build dependency '$Dependency' not found. Run 'Start-PSBootstrap'.")
354-
}
355-
}
356-
357-
# Abort if any precheck failed
358412
if (-not $precheck) {
359413
return
360414
}
@@ -441,38 +495,6 @@ Fix steps:
441495
Start-ResGen
442496
}
443497

444-
# Build native components
445-
if (($Environment.IsLinux -or $Environment.IsMacOS) -and -not $SMAOnly) {
446-
$Ext = if ($Environment.IsLinux) {
447-
"so"
448-
} elseif ($Environment.IsMacOS) {
449-
"dylib"
450-
}
451-
452-
$Native = "$PSScriptRoot/src/libpsl-native"
453-
$Lib = "$($Options.Top)/libpsl-native.$Ext"
454-
log "Start building $Lib"
455-
456-
try {
457-
Push-Location $Native
458-
if ($Runtime -eq "linux-arm") {
459-
Start-NativeExecution { cmake -DCMAKE_TOOLCHAIN_FILE="./arm.toolchain.cmake" . }
460-
Start-NativeExecution { make -j }
461-
}
462-
else {
463-
Start-NativeExecution { cmake -DCMAKE_BUILD_TYPE=Debug . }
464-
Start-NativeExecution { make -j }
465-
Start-NativeExecution { ctest --verbose }
466-
}
467-
} finally {
468-
Pop-Location
469-
}
470-
471-
if (-not (Test-Path $Lib)) {
472-
throw "Compilation of $Lib failed"
473-
}
474-
}
475-
476498
# handle TypeGen
477499
if ($TypeGen -or -not (Test-Path "$PSScriptRoot/src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CorePsTypeCatalog.cs")) {
478500
log "Run TypeGen (generating CorePsTypeCatalog.cs)"

src/powershell-unix/powershell-unix.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1717
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
1818
</Content>
19-
<Content Include="*.so;*.dylib;..\..\license_thirdparty_proprietary.txt;..\..\powershell.version;..\..\DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY">
19+
<Content Include="..\..\license_thirdparty_proprietary.txt;..\..\powershell.version;..\..\DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY">
2020
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2121
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
2222
</Content>
@@ -28,6 +28,7 @@
2828
</ItemGroup>
2929

3030
<ItemGroup>
31+
<PackageReference Include="libpsl" Version="6.0.0-*" />
3132
<PackageReference Include="psrp" Version="1.1.0-*" />
3233
<PackageReference Include="PSDesiredStateConfiguration" Version="1.0.0-alpha01" />
3334
<PackageReference Include="PowerShellHelpFiles" Version="1.0.0-alpha01" />

tools/packaging/packaging.psm1

Lines changed: 23 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function Start-PSPackage {
3030
[Switch] $Force,
3131

3232
[Switch] $IncludeSymbols,
33-
33+
3434
[Switch] $SkipReleaseChecks
3535
)
3636

@@ -43,11 +43,9 @@ function Start-PSPackage {
4343
New-PSOptions -Configuration "Release" -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration }
4444
}
4545

46-
# We convert the runtime to win7-x64 or win7-x86 to build the universal windows package.
4746
if($Environment.IsWindows) {
48-
$Runtime = $Runtime -replace "win\d+", "win7"
49-
50-
# Build the name suffix for win-plat packages
47+
# Runtime will always be win7-x64 or win7-x86 on Windows.
48+
# Build the name suffix for universal win-plat packages.
5149
$NameSuffix = $Runtime -replace 'win\d+', 'win'
5250
}
5351

@@ -134,7 +132,7 @@ function Start-PSPackage {
134132
}
135133
log "Packaging Type: $Type"
136134

137-
# Add the symbols to the suffix
135+
# Add the symbols to the suffix
138136
# if symbols are specified to be included
139137
if($IncludeSymbols.IsPresent -and $NameSuffix) {
140138
$NameSuffix = "symbols-$NameSuffix"
@@ -186,7 +184,7 @@ function Start-PSPackage {
186184
{
187185
throw "AppImage does not support packaging '-IncludeSymbols'"
188186
}
189-
187+
190188
if ($Environment.IsUbuntu14) {
191189
$null = Start-NativeExecution { bash -iex "$PSScriptRoot/../appimage.sh" }
192190
$appImage = Get-Item PowerShell-*.AppImage
@@ -248,10 +246,6 @@ function New-UnixPackage {
248246
[Parameter(Mandatory)]
249247
[string]$Version,
250248

251-
# Package iteration version (rarely changed)
252-
# This is a string because strings are appended to it
253-
[string]$Iteration = "1",
254-
255249
[Switch]
256250
$Force
257251
)
@@ -260,14 +254,14 @@ function New-UnixPackage {
260254
$ErrorMessage = "Must be on {0} to build '$Type' packages!"
261255
switch ($Type) {
262256
"deb" {
263-
$WarningMessage = "Building for Ubuntu {0}.04!"
257+
$verboseMsg = "Building for Ubuntu {0}.04!"
264258
if (!$Environment.IsUbuntu) {
265-
throw ($ErrorMessage -f "Ubuntu")
266-
} elseif ($Environment.IsUbuntu14) {
267-
Write-Warning ($WarningMessage -f "14")
268-
} elseif ($Environment.IsUbuntu16) {
269-
Write-Warning ($WarningMessage -f "16")
270-
}
259+
throw ($ErrorMessage -f "Ubuntu")
260+
} elseif ($Environment.IsUbuntu14) {
261+
Write-Verbose ($verboseMsg -f "14")
262+
} elseif ($Environment.IsUbuntu16) {
263+
Write-Verbose ($verboseMsg -f "16")
264+
}
271265
}
272266
"rpm" {
273267
if (!$Environment.IsRedHatFamily) {
@@ -309,7 +303,7 @@ function New-UnixPackage {
309303
# Suffix is used for side-by-side package installation
310304
$Suffix = $Name -replace "^powershell"
311305
if (!$Suffix) {
312-
Write-Warning "Suffix not given, building primary PowerShell package!"
306+
Write-Verbose "Suffix not given, building primary PowerShell package!"
313307
$Suffix = $Version
314308
}
315309

@@ -408,73 +402,28 @@ function New-UnixPackage {
408402
"libc6",
409403
"libcurl3",
410404
"libgcc1",
411-
"libssl1.0.0",
405+
"libgssapi-krb5-2",
406+
"liblttng-ust0",
412407
"libstdc++6",
413-
"libtinfo5",
414408
"libunwind8",
415409
"libuuid1",
416-
"zlib1g"
410+
"zlib1g",
411+
"libssl1.0.0",
412+
"libicu-dev"
417413
)
418-
# Please note the different libicu package dependency!
419-
if ($Environment.IsUbuntu14) {
420-
$Dependencies += "libicu52"
421-
} elseif ($Environment.IsUbuntu16) {
422-
$Dependencies += "libicu55"
423-
}
424414
} elseif ($Environment.IsRedHatFamily) {
425415
$Dependencies = @(
426-
"glibc",
427-
"libicu",
428-
"openssl",
429416
"libunwind",
430-
"uuid",
431-
"zlib"
417+
"libcurl",
418+
"openssl-libs",
419+
"libicu"
432420
)
433-
434-
if($Environment.IsFedora -or $Environment.IsCentOS)
435-
{
436-
$Dependencies += "libcurl"
437-
$Dependencies += "libgcc"
438-
$Dependencies += "libstdc++"
439-
$Dependencies += "ncurses-base"
440-
}
441-
442-
if($Environment.IsOpenSUSE)
443-
{
444-
$Dependencies += "libgcc_s1"
445-
$Dependencies += "libstdc++6"
446-
}
447-
}
448-
449-
# iteration is "debian_revision"
450-
# usage of this to differentiate distributions is allowed by non-standard
451-
if ($Environment.IsUbuntu14) {
452-
$Iteration += "ubuntu1.14.04.1"
453-
} elseif ($Environment.IsUbuntu16) {
454-
$Iteration += "ubuntu1.16.04.1"
455-
}
456-
457-
# We currently only support:
458-
# CentOS 7
459-
# Fedora 24+
460-
# OpenSUSE 42.1 (13.2 might build but is EOL)
461-
# Also SEE: https://fedoraproject.org/wiki/Packaging:DistTag
462-
if ($Environment.IsCentOS) {
463-
$rpm_dist = "el7"
464-
} elseif ($Environment.IsFedora) {
465-
$version_id = $Environment.LinuxInfo.VERSION_ID
466-
$rpm_dist = "fedora.$version_id"
467-
} elseif ($Environment.IsOpenSUSE) {
468-
$version_id = $Environment.LinuxInfo.VERSION_ID
469-
$rpm_dist = "suse.$version_id"
470421
}
471422

472-
473423
$Arguments = @(
474424
"--force", "--verbose",
475425
"--name", $Name,
476426
"--version", $Version,
477-
"--iteration", $Iteration,
478427
"--maintainer", "PowerShell Team <[email protected]>",
479428
"--vendor", "Microsoft Corporation",
480429
"--url", "https://microsoft.com/powershell",
@@ -485,7 +434,7 @@ function New-UnixPackage {
485434
"-s", "dir"
486435
)
487436
if ($Environment.IsRedHatFamily) {
488-
$Arguments += @("--rpm-dist", $rpm_dist)
437+
$Arguments += @("--rpm-dist", "rhel.7")
489438
$Arguments += @("--rpm-os", "linux")
490439
}
491440
foreach ($Dependency in $Dependencies) {
@@ -504,8 +453,7 @@ function New-UnixPackage {
504453
)
505454
# Build package
506455
try {
507-
if($pscmdlet.ShouldProcess("Create $type package"))
508-
{
456+
if($pscmdlet.ShouldProcess("Create $type package")) {
509457
$Output = Start-NativeExecution { fpm $Arguments }
510458
}
511459
} finally {

0 commit comments

Comments
 (0)