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 for Alpine arm64 and arm32 #72

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
45 changes: 41 additions & 4 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,9 @@ cmd.exe /C cd /d "$location" "&" "$vcvarsallbatPath" "$Arch" "&" "$cmakePath" "$
function Start-BuildNativeUnixBinaries {
param (
[switch] $BuildLinuxArm,
[switch] $BuildLinuxArm64
[switch] $BuildLinuxArm64,
[switch] $BuildAlpineArm64,
[switch] $BuildAlpineArm
adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved
)

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

if ($BuildAlpineArm64 -or $BuildAlpineArm -and -not $Environment.IsAlpine) {
adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved
throw "Cross compiling for linux-musl-arm linux-musl-arm64 are only supported on Alpine environment"
adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved
}

# Verify we have all tools in place to do the build
$precheck = $true
foreach ($Dependency in 'cmake', 'make', 'g++') {
Expand Down Expand Up @@ -464,9 +470,17 @@ function Start-BuildNativeUnixBinaries {
}
elseif ($IsMacOS) {
Start-NativeExecution { cmake -DCMAKE_TOOLCHAIN_FILE="./macos.toolchain.cmake" . }
Start-NativeExecution { make -j }
Start-NativeExecution { make -j }
Start-NativeExecution { ctest --verbose }
}
elseif ($BuildAlpineArm64) {
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 }
}
adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved
else {
Start-NativeExecution { cmake -DCMAKE_BUILD_TYPE=Debug . }
Start-NativeExecution { make -j }
Expand Down Expand Up @@ -527,6 +541,14 @@ 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,

adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved
[Parameter(Mandatory = $true)]
[ValidateScript({Test-Path $_ -PathType Leaf})]
[string] $macOSZipPath,
Expand Down Expand Up @@ -558,6 +580,7 @@ function Start-BuildPowerShellNativePackage
$BinFolderLinuxARM = Join-Path $tempExtractionPath "LinuxARM"
$BinFolderLinuxARM64 = Join-Path $tempExtractionPath "LinuxARM64"
$BinFolderLinuxAlpine = Join-Path $tempExtractionPath "LinuxAlpine"
$BinFolderLinuxAlpineArm64 = Join-Path $tempExtractionPath "LinuxAlpineArm64"
adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved
$BinFolderMacOS = Join-Path $tempExtractionPath "MacOS"
$BinFolderPSRP = Join-Path $tempExtractionPath "PSRP"

Expand All @@ -567,14 +590,16 @@ 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
adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved
Expand-Archive -Path $LinuxARMZipPath -DestinationPath $BinFolderLinuxARM -Force
Expand-Archive -Path $LinuxARM64ZipPath -DestinationPath $BinFolderLinuxARM64 -Force
Expand-Archive -Path $macOSZipPath -DestinationPath $BinFolderMacOS -Force
Expand-Archive -Path $psrpZipPath -DestinationPath $BinFolderPSRP -Force

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
PlaceUnixBinaries -PackageRoot $PackageRoot -BinFolderLinux $BinFolderLinux -BinFolderLinuxARM $BinFolderLinuxARM -BinFolderLinuxARM64 $BinFolderLinuxARM64 -BinFolderOSX $BinFolderMacOS -BinFolderPSRP $BinFolderPSRP -BinFolderLinuxAlpine $BinFolderLinuxAlpine -BinFolderLinuxAlpineArm64 $BinFolderLinuxAlpineArm64 -BinFolderLinuxAlpineArm $BinFolderLinuxAlpineArm
adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved

$Nuspec = @'
<?xml version="1.0" encoding="utf-8"?>
Expand Down Expand Up @@ -652,6 +677,14 @@ 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,

adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved
[Parameter(Mandatory = $true)]
[ValidateScript({Test-Path $_ -PathType Container})]
$BinFolderOSX,
Expand All @@ -665,12 +698,16 @@ 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
adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved
$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
adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved
Copy-Item "$BinFolderOSX\*" -Destination $RuntimePathOSX -Verbose

## LinuxARM is not supported by PSRP
Expand Down Expand Up @@ -2065,7 +2102,7 @@ function Start-PSBootstrap {
# Install patched version of curl
Start-NativeExecution { brew install curl --with-openssl --with-gssapi } -IgnoreExitcode
} elseif ($Environment.IsAlpine) {
$Deps += "build-base", "gcc", "abuild", "binutils", "git", "python", "bash", "cmake"
$Deps += "build-base", "gcc", "abuild", "binutils", "git", "python3", "bash", "cmake"

# Install dependencies
Start-NativeExecution { apk update }
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)
adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved
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)
17 changes: 17 additions & 0 deletions src/libpsl-native/alpine.arm64.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 armv8)
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)
adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved
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)
17 changes: 15 additions & 2 deletions 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')]
[ValidateSet('x64', 'x86', 'x64_arm', 'x64_arm64', 'linux-x64', 'osx', 'linux-arm', 'linux-arm64', 'linux-musl-x64', 'linux-musl-arm64', 'linux-musl-arm')]
adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved
[string]
$Arch,

Expand Down Expand Up @@ -61,6 +61,20 @@ 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-arm64') {
Start-PSBootstrap
Start-BuildNativeUnixBinaries -BuildAlpineArm64

$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
}
adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved
else {
Write-Verbose "Starting Start-PSBootstrap" -Verbose
Start-PSBootstrap -BuildWindowsNative
Expand All @@ -76,4 +90,3 @@ end {
}
}
}

24 changes: 24 additions & 0 deletions tools/releaseBuild/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,30 @@
"DockerImageName": "ps-alpine",
"BinaryBucket": "release",
"EnableFeature": [ "ArtifactAsFolder" ]
},
{
"Name": "alpine-arm64",
"RepoDestinationPath": "/PowerShellNative",
"BuildCommand": "/PowerShellNative/tools/releaseBuild/PowershellNative.ps1 -RepoRoot _RepoDestinationPath_ -TargetLocation _DockerVolume_ -Arch linux-musl-arm64 -Configuration Release",
"AdditionalContextFiles": [
"./tools/releaseBuild/PowershellNative.ps1"
],
"DockerFile": "./tools/releaseBuild/images/Alpine/Dockerfile",
"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" ]
adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved
}
]
}
4 changes: 2 additions & 2 deletions tools/releaseBuild/images/Alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM mcr.microsoft.com/powershell:6.1.0-alpine-3.8
FROM mcr.microsoft.com/powershell:alpine-3.12

RUN apk update \
&& apk add build-base gcc abuild binutils git python bash cmake
&& apk add build-base gcc abuild binutils git python3 bash cmake

ENTRYPOINT [ "pwsh" ]
4 changes: 3 additions & 1 deletion tools/releaseBuild/yaml/nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +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'
adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved
$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 -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)
adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved

displayName: 'Build NuGet package'

Expand Down
4 changes: 4 additions & 0 deletions tools/releaseBuild/yaml/releaseBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ stages:
LINUX_BUILDNAME: 'alpine'
UbuntuArm64:
LINUX_BUILDNAME: 'ubuntu.16.04-arm64'
AlpineArm64:
LINUX_BUILDNAME: 'alpine-arm64'
AlpineArm64:
LINUX_BUILDNAME: 'alpine-arm'
adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved
steps:
- template: linux.yml

Expand Down