Skip to content

Build for Alpine arm64 and arm32 #72

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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 20 additions & 4 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ function Start-BuildNativeUnixBinaries {
param (
[switch] $BuildLinuxArm,
[switch] $BuildLinuxArm64,
[switch] $BuildAlpineArm64
[switch] $BuildAlpineArm64,
[switch] $BuildAlpineArm
)

if (-not $Environment.IsLinux -and -not $Environment.IsMacOS) {
Expand All @@ -406,8 +407,8 @@ function Start-BuildNativeUnixBinaries {
throw "Cross compiling for linux-arm/linux-arm64 are only supported on Ubuntu environment"
}

if ($BuildAlpineArm64 -and -not $Environment.IsAlpine) {
throw "Cross compiling for linux-musl-arm64 are only supported on Alpine environment"
if ($BuildAlpineArm64 -or $BuildAlpineArm -and -not $Environment.IsAlpine) {
throw "Cross compiling for linux-musl-arm linux-musl-arm64 are only supported on Alpine environment"
}

# Verify we have all tools in place to do the build
Expand Down Expand Up @@ -476,6 +477,10 @@ function Start-BuildNativeUnixBinaries {
Start-NativeExecution { cmake -DCMAKE_TOOLCHAIN_FILE="./alpine.arm64.toolchain.cmake" . }
Start-NativeExecution { make -j }
}
elseif ($BuildAlpineArm) {
Start-NativeExecution { cmake -DCMAKE_TOOLCHAIN_FILE="./alpine.arm.toolchain.cmake" . }
Start-NativeExecution { make -j }
}
else {
Start-NativeExecution { cmake -DCMAKE_BUILD_TYPE=Debug . }
Start-NativeExecution { make -j }
Expand Down Expand Up @@ -536,6 +541,10 @@ function Start-BuildPowerShellNativePackage
[ValidateScript({Test-Path $_ -PathType Leaf})]
[string] $LinuxAlpineZipPath,

[Parameter(Mandatory = $true)]
[ValidateScript({Test-Path $_ -PathType Leaf})]
[string] $LinuxAlpineArmZipPath,

[Parameter(Mandatory = $true)]
[ValidateScript({Test-Path $_ -PathType Leaf})]
[string] $LinuxAlpineArm64ZipPath,
Expand Down Expand Up @@ -581,6 +590,7 @@ function Start-BuildPowerShellNativePackage
Expand-Archive -Path $WindowsARM64ZipPath -DestinationPath $BinFolderARM64 -Force
Expand-Archive -Path $LinuxZipPath -DestinationPath $BinFolderLinux -Force
Expand-Archive -Path $LinuxAlpineZipPath -DestinationPath $BinFolderLinuxAlpine -Force
Expand-Archive -Path $LinuxAlpineArmZipPath -DestinationPath $BinFolderLinuxAlpineArm -Force
Expand-Archive -Path $LinuxAlpineArm64ZipPath -DestinationPath $BinFolderLinuxAlpineArm64 -Force
Expand-Archive -Path $LinuxARMZipPath -DestinationPath $BinFolderLinuxARM -Force
Expand-Archive -Path $LinuxARM64ZipPath -DestinationPath $BinFolderLinuxARM64 -Force
Expand All @@ -589,7 +599,7 @@ function Start-BuildPowerShellNativePackage

PlaceWindowsNativeBinaries -PackageRoot $PackageRoot -BinFolderX64 $BinFolderX64 -BinFolderX86 $BinFolderX86 -BinFolderARM $BinFolderARM -BinFolderARM64 $BinFolderARM64

PlaceUnixBinaries -PackageRoot $PackageRoot -BinFolderLinux $BinFolderLinux -BinFolderLinuxARM $BinFolderLinuxARM -BinFolderLinuxARM64 $BinFolderLinuxARM64 -BinFolderOSX $BinFolderMacOS -BinFolderPSRP $BinFolderPSRP -BinFolderLinuxAlpine $BinFolderLinuxAlpine -BinFolderLinuxAlpineArm64 $BinFolderLinuxAlpineArm64
PlaceUnixBinaries -PackageRoot $PackageRoot -BinFolderLinux $BinFolderLinux -BinFolderLinuxARM $BinFolderLinuxARM -BinFolderLinuxARM64 $BinFolderLinuxARM64 -BinFolderOSX $BinFolderMacOS -BinFolderPSRP $BinFolderPSRP -BinFolderLinuxAlpine $BinFolderLinuxAlpine -BinFolderLinuxAlpineArm64 $BinFolderLinuxAlpineArm64 -BinFolderLinuxAlpineArm $BinFolderLinuxAlpineArm

$Nuspec = @'
<?xml version="1.0" encoding="utf-8"?>
Expand Down Expand Up @@ -667,6 +677,10 @@ function PlaceUnixBinaries
[ValidateScript({Test-Path $_ -PathType Container})]
$BinFolderLinuxAlpine,

[Parameter(Mandatory = $true)]
[ValidateScript({Test-Path $_ -PathType Container})]
$BinFolderLinuxAlpineArm,

[Parameter(Mandatory = $true)]
[ValidateScript({Test-Path $_ -PathType Container})]
$BinFolderLinuxAlpineArm64,
Expand All @@ -684,13 +698,15 @@ function PlaceUnixBinaries
$RuntimePathLinuxARM = New-Item -ItemType Directory -Path (Join-Path $PackageRoot -ChildPath 'runtimes/linux-arm/native') -Force
$RuntimePathLinuxARM64 = New-Item -ItemType Directory -Path (Join-Path $PackageRoot -ChildPath 'runtimes/linux-arm64/native') -Force
$RuntimePathLinuxAlpine = New-Item -ItemType Directory -Path (Join-Path $PackageRoot -ChildPath 'runtimes/linux-musl-x64/native') -Force
$RuntimePathLinuxAlpineArm = New-Item -ItemType Directory -Path (Join-Path $PackageRoot -ChildPath 'runtimes/linux-musl-arm/native') -Force
$RuntimePathLinuxAlpineArm64 = New-Item -ItemType Directory -Path (Join-Path $PackageRoot -ChildPath 'runtimes/linux-musl-arm64/native') -Force
$RuntimePathOSX = New-Item -ItemType Directory -Path (Join-Path $PackageRoot -ChildPath 'runtimes/osx/native') -Force

Copy-Item "$BinFolderLinux\*" -Destination $RuntimePathLinux -Verbose
Copy-Item "$BinFolderLinuxARM\*" -Destination $RuntimePathLinuxARM -Verbose
Copy-Item "$BinFolderLinuxARM64\*" -Destination $RuntimePathLinuxARM64 -Verbose
Copy-Item "$BinFolderLinuxAlpine\*" -Destination $RuntimePathLinuxAlpine -Verbose
Copy-Item "$BinFolderLinuxAlpineArm\*" -Destination $RuntimePathLinuxAlpineArm -Verbose
Copy-Item "$BinFolderLinuxAlpineArm64\*" -Destination $RuntimePathLinuxAlpineArm64 -Verbose
Copy-Item "$BinFolderOSX\*" -Destination $RuntimePathOSX -Verbose

Expand Down
17 changes: 17 additions & 0 deletions src/libpsl-native/alpine.arm.toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR armv71)
set(CMAKE_CXX_COMPILER g++ -fstack-protector-strong -fpie -DFORTIFY_SOURCE=2 -O2)
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-z,relro,-z,now")
set(CMAKE_C_COMPILER gcc)

add_compile_options(-g)

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CROSS_LINK_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CROSS_LINK_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${CROSS_LINK_FLAGS}" CACHE STRING "" FORCE)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
9 changes: 8 additions & 1 deletion tools/releaseBuild/PowershellNative.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
param (

[Parameter(Mandatory, ParameterSetName = 'Build')]
[ValidateSet('x64', 'x86', 'x64_arm', 'x64_arm64', 'linux-x64', 'osx', 'linux-arm', 'linux-arm64', 'linux-musl-x64', 'linux-musl-arm64')]
[ValidateSet('x64', 'x86', 'x64_arm', 'x64_arm64', 'linux-x64', 'osx', 'linux-arm', 'linux-arm64', 'linux-musl-x64', 'linux-musl-arm64', 'linux-musl-arm')]
[string]
$Arch,

Expand Down Expand Up @@ -68,6 +68,13 @@ end {
$buildOutputPath = Join-Path $RepoRoot "src/powershell-unix"
Compress-Archive -Path $buildOutputPath/libpsl-native.* -DestinationPath "$TargetLocation/$Arch-symbols.zip" -Verbose
}
elseif ($Arch -eq 'linux-musl-arm') {
Start-PSBootstrap
Start-BuildNativeUnixBinaries -BuildAlpineArm

$buildOutputPath = Join-Path $RepoRoot "src/powershell-unix"
Compress-Archive -Path $buildOutputPath/libpsl-native.* -DestinationPath "$TargetLocation/$Arch-symbols.zip" -Verbose
}
else {
Write-Verbose "Starting Start-PSBootstrap" -Verbose
Start-PSBootstrap -BuildWindowsNative
Expand Down
12 changes: 12 additions & 0 deletions tools/releaseBuild/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@
"DockerImageName": "ps-alpine-arm64",
"BinaryBucket": "release",
"EnableFeature": [ "ArtifactAsFolder" ]
},
{
"Name": "alpine-arm",
"RepoDestinationPath": "/PowerShellNative",
"BuildCommand": "/PowerShellNative/tools/releaseBuild/PowershellNative.ps1 -RepoRoot _RepoDestinationPath_ -TargetLocation _DockerVolume_ -Arch linux-musl-arm -Configuration Release",
"AdditionalContextFiles": [
"./tools/releaseBuild/PowershellNative.ps1"
],
"DockerFile": "./tools/releaseBuild/images/Alpine/Dockerfile",
"DockerImageName": "ps-alpine-arm",
"BinaryBucket": "release",
"EnableFeature": [ "ArtifactAsFolder" ]
}
]
}
3 changes: 2 additions & 1 deletion tools/releaseBuild/yaml/nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ steps:
$LinuxARMZipPath = Join-Path "$(System.ArtifactsDirectory)/release" 'linux-arm-symbols.zip'
$LinuxARM64ZipPath = Join-Path "$(System.ArtifactsDirectory)/release" 'linux-arm64-symbols.zip'
$LinuxAlpineZipPath = Join-Path "$(System.ArtifactsDirectory)/release" 'linux-musl-x64-symbols.zip'
$LinuxAlpineArmZipPath = Join-Path "$(System.ArtifactsDirectory)/release" 'linux-musl-arm-symbols.zip'
$LinuxAlpineArm64ZipPath = Join-Path "$(System.ArtifactsDirectory)/release" 'linux-musl-arm64-symbols.zip'
$macOSZipPath = Join-Path "$(System.ArtifactsDirectory)/release" 'osx-symbols.zip'
$psrpZipPath = Join-Path "$(System.ArtifactsDirectory)/release" 'psrp.zip'

Start-BuildPowerShellNativePackage -PackageRoot $PackageRoot -Version $(PackageVersion) -WindowsX64ZipPath $WindowsX64ZipPath -WindowsX86ZipPath $WindowsX86ZipPath -WindowsARMZipPath $WindowsARMZipPath -WindowsARM64ZipPath $WindowsARM64ZipPath -LinuxZipPath $LinuxZipPath -LinuxARMZipPath $LinuxARMZipPath -LinuxARM64ZipPath $LinuxARM64ZipPath -LinuxAlpineZipPath $LinuxAlpineZipPath -LinuxAlpineArm64ZipPath $LinuxAlpineArm64ZipPath -macOSZipPath $macOSZipPath -psrpZipPath $psrpZipPath -NuGetOutputPath $(NuGetPackagePath)
Start-BuildPowerShellNativePackage -PackageRoot $PackageRoot -Version $(PackageVersion) -WindowsX64ZipPath $WindowsX64ZipPath -WindowsX86ZipPath $WindowsX86ZipPath -WindowsARMZipPath $WindowsARMZipPath -WindowsARM64ZipPath $WindowsARM64ZipPath -LinuxZipPath $LinuxZipPath -LinuxARMZipPath $LinuxARMZipPath -LinuxARM64ZipPath $LinuxARM64ZipPath -LinuxAlpineZipPath $LinuxAlpineZipPath -LinuxAlpineArm64ZipPath $LinuxAlpineArm64ZipPath -LinuxAlpineArmZipPath $LinuxAlpineArmZipPath -macOSZipPath $macOSZipPath -psrpZipPath $psrpZipPath -NuGetOutputPath $(NuGetPackagePath)

displayName: 'Build NuGet package'

Expand Down
2 changes: 2 additions & 0 deletions tools/releaseBuild/yaml/releaseBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ stages:
LINUX_BUILDNAME: 'ubuntu.16.04-arm64'
AlpineArm64:
LINUX_BUILDNAME: 'alpine-arm64'
AlpineArm64:
LINUX_BUILDNAME: 'alpine-arm'
steps:
- template: linux.yml

Expand Down