Skip to content
14 changes: 9 additions & 5 deletions .vsts-ci/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ variables:
resources:
- repo: self
clean: true
phases:
- phase: Build

queue:
name: Hosted Ubuntu 1604
parallel: 2
jobs:
- job: Build
pool:
vmImage: ubuntu-latest
strategy:
matrix:
Linux ARM Native:
buildName: ubuntu.16.04-arm
Expand All @@ -24,6 +24,10 @@ phases:
buildName: centos.7
Linux Alpine:
buildName: alpine
Linux Alpine ARM:
buildName: alpine-arm
Linux Alpine ARM64:
buildName: alpine-arm64

steps:
- powershell: |
Expand Down
46 changes: 42 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] $BuildAlpineArm,
[switch] $BuildAlpineArm64
)

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) {
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
$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 ($BuildAlpineArm) {
Start-NativeExecution { cmake -DCMAKE_TOOLCHAIN_FILE="./alpine.arm.toolchain.cmake" . }
Start-NativeExecution { make -j }
}
elseif ($BuildAlpineArm64) {
Start-NativeExecution { cmake -DCMAKE_TOOLCHAIN_FILE="./alpine.arm64.toolchain.cmake" . }
Start-NativeExecution { make -j }
}
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,

[Parameter(Mandatory = $true)]
[ValidateScript({Test-Path $_ -PathType Leaf})]
[string] $macOSZipPath,
Expand Down Expand Up @@ -558,6 +580,8 @@ function Start-BuildPowerShellNativePackage
$BinFolderLinuxARM = Join-Path $tempExtractionPath "LinuxARM"
$BinFolderLinuxARM64 = Join-Path $tempExtractionPath "LinuxARM64"
$BinFolderLinuxAlpine = Join-Path $tempExtractionPath "LinuxAlpine"
$BinFolderLinuxAlpineARM = Join-Path $tempExtractionPath "LinuxAlpineARM"
$BinFolderLinuxAlpineARM64 = Join-Path $tempExtractionPath "LinuxAlpineARM64"
$BinFolderMacOS = Join-Path $tempExtractionPath "MacOS"
$BinFolderPSRP = Join-Path $tempExtractionPath "PSRP"

Expand All @@ -567,14 +591,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
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 -BinFolderLinuxAlpineARM $BinFolderLinuxAlpineARM -BinFolderLinuxAlpineARM64 $BinFolderLinuxAlpineARM64

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

[Parameter(Mandatory = $true)]
[ValidateScript({Test-Path $_ -PathType Container})]
$BinFolderOSX,
Expand All @@ -665,12 +699,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
$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

## LinuxARM is not supported by PSRP
Expand Down Expand Up @@ -2065,7 +2103,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)
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)
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-arm', 'linux-musl-arm64')]
[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-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
}
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
}
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-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" ]
},
{
"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" ]
}
]
}
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'
$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 -LinuxAlpineARMZipPath $LinuxAlpineARMZipPath -LinuxAlpineARM64ZipPath $LinuxAlpineARM64ZipPath -macOSZipPath $macOSZipPath -psrpZipPath $psrpZipPath -NuGetOutputPath $(NuGetPackagePath)

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'
AlpineArm:
LINUX_BUILDNAME: 'alpine-arm'
AlpineArm64:
LINUX_BUILDNAME: 'alpine-arm64'
steps:
- template: linux.yml

Expand Down