diff --git a/.vsts-ci/linux.yml b/.vsts-ci/linux.yml index 886f748..476fe93 100644 --- a/.vsts-ci/linux.yml +++ b/.vsts-ci/linux.yml @@ -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 @@ -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: | diff --git a/build.psm1 b/build.psm1 index 3c759c8..8f6df08 100644 --- a/build.psm1 +++ b/build.psm1 @@ -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) { @@ -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++') { @@ -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 } @@ -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, @@ -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" @@ -567,6 +591,8 @@ 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 @@ -574,7 +600,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 + PlaceUnixBinaries -PackageRoot $PackageRoot -BinFolderLinux $BinFolderLinux -BinFolderLinuxARM $BinFolderLinuxARM -BinFolderLinuxARM64 $BinFolderLinuxARM64 -BinFolderOSX $BinFolderMacOS -BinFolderPSRP $BinFolderPSRP -BinFolderLinuxAlpine $BinFolderLinuxAlpine -BinFolderLinuxAlpineARM $BinFolderLinuxAlpineARM -BinFolderLinuxAlpineARM64 $BinFolderLinuxAlpineARM64 $Nuspec = @' @@ -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, @@ -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 @@ -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 } diff --git a/src/libpsl-native/alpine.arm.toolchain.cmake b/src/libpsl-native/alpine.arm.toolchain.cmake new file mode 100644 index 0000000..81bdacd --- /dev/null +++ b/src/libpsl-native/alpine.arm.toolchain.cmake @@ -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) diff --git a/src/libpsl-native/alpine.arm64.toolchain.cmake b/src/libpsl-native/alpine.arm64.toolchain.cmake new file mode 100644 index 0000000..029a24a --- /dev/null +++ b/src/libpsl-native/alpine.arm64.toolchain.cmake @@ -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) diff --git a/tools/releaseBuild/PowershellNative.ps1 b/tools/releaseBuild/PowershellNative.ps1 index 1bb9beb..38e0864 100644 --- a/tools/releaseBuild/PowershellNative.ps1 +++ b/tools/releaseBuild/PowershellNative.ps1 @@ -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, @@ -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 @@ -76,4 +90,3 @@ end { } } } - diff --git a/tools/releaseBuild/build.json b/tools/releaseBuild/build.json index 8188770..6c57122 100644 --- a/tools/releaseBuild/build.json +++ b/tools/releaseBuild/build.json @@ -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" ] } ] } diff --git a/tools/releaseBuild/images/Alpine/Dockerfile b/tools/releaseBuild/images/Alpine/Dockerfile index 64279c1..c1e6db1 100644 --- a/tools/releaseBuild/images/Alpine/Dockerfile +++ b/tools/releaseBuild/images/Alpine/Dockerfile @@ -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" ] diff --git a/tools/releaseBuild/yaml/nuget.yml b/tools/releaseBuild/yaml/nuget.yml index 2e011ad..26b867c 100644 --- a/tools/releaseBuild/yaml/nuget.yml +++ b/tools/releaseBuild/yaml/nuget.yml @@ -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' diff --git a/tools/releaseBuild/yaml/releaseBuild.yml b/tools/releaseBuild/yaml/releaseBuild.yml index fa6eeed..aeb9565 100644 --- a/tools/releaseBuild/yaml/releaseBuild.yml +++ b/tools/releaseBuild/yaml/releaseBuild.yml @@ -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