Skip to content

Add option to build ARM64 on Linux #16

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

Merged
merged 7 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion .vsts-ci/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ phases:
parallel: 2
matrix:
Linux ARM Native:
buildName: ubuntu.16.04
buildName: ubuntu.16.04-arm
Linux ARM64 Native:
buildName: ubuntu.16.04-arm64
Linux Native:
buildName: centos.7
Linux Alpine:
Expand Down
2 changes: 1 addition & 1 deletion .vsts-ci/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ phases:
condition: succeeded()
- powershell: |
Invoke-WebRequest "https://aka.ms/vs/15/release/vs_BuildTools.exe" -OutFile vs_BuildTools.exe -UseBasicParsing
Start-Process -FilePath 'vs_BuildTools.exe' -ArgumentList '--quiet', '--norestart', '--locale en-US', '--add Microsoft.VisualStudio.Component.VC.Tools.ARM', '--add Microsoft.VisualStudio.Component.VC.Tools.ARM64', '--includeRecommended', '--add Microsoft.VisualStudio.Workload.VCTools', '--add Microsoft.VisualStudio.Component.Windows10SDK.16299.Desktop.arm', '--add Microsoft.VisualStudio.Component.VC.ATL', '--add Microsoft.VisualStudio.Component.VC.ATLMFC', '--add Microsoft.VisualStudio.Component.VC.ATL.ARM', '--add Microsoft.VisualStudio.Component.VC.ATL.ARM64' -Wait
Start-Process -FilePath 'vs_BuildTools.exe' -ArgumentList '--quiet', '--norestart', '--locale en-US', '--add Microsoft.VisualStudio.Component.VC.Tools.ARM', '--add Microsoft.VisualStudio.Component.VC.Tools.ARM64', '--includeRecommended', '--add Microsoft.VisualStudio.Workload.VCTools', '--add Microsoft.VisualStudio.Component.Windows10SDK.16299.Desktop.arm', '--add Microsoft.VisualStudio.Component.VC.ATL.Spectre', '--add Microsoft.VisualStudio.Component.VC.ATLMFC.Spectre', '--add Microsoft.VisualStudio.Component.VC.ATL.ARM.Spectre', '--add Microsoft.VisualStudio.Component.VC.ATL.ARM64.Spectre', '--add Microsoft.VisualStudio.Component.VC.Runtimes.ARM.Spectre', '--add Microsoft.VisualStudio.Component.VC.Runtimes.ARM64.Spectre', '--add Microsoft.VisualStudio.Component.VC.Runtimes.x86.x64.Spectre' -Wait
Remove-Item .\vs_BuildTools.exe
Remove-Item -Force -Recurse 'C:\Program Files (x86)\Microsoft Visual Studio\Installer'
$vsPath = ${Env:ProgramFiles(x86)} + '\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin'
Expand Down
45 changes: 37 additions & 8 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -392,16 +392,17 @@ cmd.exe /C cd /d "$location" "&" "$vcvarsallbatPath" "$Arch" "&" "$cmakePath" "$

function Start-BuildNativeUnixBinaries {
param (
[switch] $BuildLinuxArm
[switch] $BuildLinuxArm,
[switch] $BuildLinuxArm64
)

if (-not $Environment.IsLinux -and -not $Environment.IsMacOS) {
Write-Warning -Message "'Start-BuildNativeUnixBinaries' is only supported on Linux/macOS platforms"
return
}

if ($BuildLinuxArm -and -not $Environment.IsUbuntu) {
throw "Cross compiling for linux-arm is only supported on Ubuntu environment"
if (($BuildLinuxArm -or $BuildLinuxArm64) -and -not $Environment.IsUbuntu) {
throw "Cross compiling for linux-arm/linux-arm64 are only supported on Ubuntu environment"
}

# Verify we have all tools in place to do the build
Expand All @@ -414,6 +415,10 @@ function Start-BuildNativeUnixBinaries {
foreach ($Dependency in 'arm-linux-gnueabihf-gcc', 'arm-linux-gnueabihf-g++') {
$precheck = $precheck -and (precheck $Dependency "Build dependency '$Dependency' not found. Run 'Start-PSBootstrap'.")
}
} elseif ($BuildLinuxArm64) {
foreach ($Dependency in 'aarch64-linux-gnu-gcc', 'aarch64-linux-gnu-g++') {
$precheck = $precheck -and (precheck $Dependency "Build dependency '$Dependency' not found. Run 'Start-PSBootstrap'.")
}
}

# Abort if any precheck failed
Expand All @@ -440,6 +445,10 @@ function Start-BuildNativeUnixBinaries {
Start-NativeExecution { cmake -DCMAKE_TOOLCHAIN_FILE="./arm.toolchain.cmake" . }
Start-NativeExecution { make -j }
}
elseif ($BuildLinuxArm64) {
Start-NativeExecution { cmake -DCMAKE_TOOLCHAIN_FILE="./arm64.toolchain.cmake" . }
Start-NativeExecution { make -j }
}
else {
Start-NativeExecution { cmake -DCMAKE_BUILD_TYPE=Debug . }
Start-NativeExecution { make -j }
Expand Down Expand Up @@ -492,6 +501,10 @@ function Start-BuildPowerShellNativePackage
[ValidateScript({Test-Path $_ -PathType Leaf})]
[string] $LinuxARMZipPath,

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

[Parameter(Mandatory = $true)]
[ValidateScript({Test-Path $_ -PathType Leaf})]
[string] $LinuxAlpineZipPath,
Expand Down Expand Up @@ -525,6 +538,7 @@ function Start-BuildPowerShellNativePackage
$BinFolderARM64 = Join-Path $tempExtractionPath "ARM64"
$BinFolderLinux = Join-Path $tempExtractionPath "Linux"
$BinFolderLinuxARM = Join-Path $tempExtractionPath "LinuxARM"
$BinFolderLinuxARM64 = Join-Path $tempExtractionPath "LinuxARM64"
$BinFolderLinuxAlpine = Join-Path $tempExtractionPath "LinuxAlpine"
$BinFolderMacOS = Join-Path $tempExtractionPath "MacOS"
$BinFolderPSRP = Join-Path $tempExtractionPath "PSRP"
Expand All @@ -536,12 +550,13 @@ function Start-BuildPowerShellNativePackage
Expand-Archive -Path $LinuxZipPath -DestinationPath $BinFolderLinux -Force
Expand-Archive -Path $LinuxAlpineZipPath -DestinationPath $BinFolderLinuxAlpine -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 -BinFolderOSX $BinFolderMacOS -BinFolderPSRP $BinFolderPSRP -BinFolderLinuxAlpine $BinFolderLinuxAlpine
PlaceUnixBinaries -PackageRoot $PackageRoot -BinFolderLinux $BinFolderLinux -BinFolderLinuxARM $BinFolderLinuxARM -BinFolderLinuxARM64 $BinFolderLinuxARM64 -BinFolderOSX $BinFolderMacOS -BinFolderPSRP $BinFolderPSRP -BinFolderLinuxAlpine $BinFolderLinuxAlpine

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

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

[Parameter(Mandatory = $true)]
[ValidateScript({Test-Path $_ -PathType Container})]
$BinFolderLinuxAlpine,
Expand All @@ -621,11 +640,13 @@ function PlaceUnixBinaries

$RuntimePathLinux = New-Item -ItemType Directory -Path (Join-Path $PackageRoot -ChildPath 'runtimes/linux-x64/native') -Force
$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
$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 "$BinFolderOSX\*" -Destination $RuntimePathOSX -Verbose

Expand Down Expand Up @@ -738,6 +759,7 @@ function Start-PSBuild {
"osx-x64",
"linux-x64",
"linux-arm",
"linux-arm64",
"win-arm",
"win-arm64")]
[string]$Runtime,
Expand All @@ -752,8 +774,8 @@ function Start-PSBuild {
[string]$ReleaseTag
)

if ($Runtime -eq "linux-arm" -and -not $Environment.IsUbuntu) {
throw "Cross compiling for linux-arm is only supported on Ubuntu environment"
if (($Runtime -eq "linux-arm" -or $Runtime -eq "linux-arm64") -and -not $Environment.IsUbuntu) {
throw "Cross compiling for linux-arm/linux-arm64 are only supported on Ubuntu environment"
}

if ("win-arm","win-arm64" -contains $Runtime -and -not $Environment.IsWindows) {
Expand Down Expand Up @@ -1050,6 +1072,7 @@ function New-PSOptions {
"osx-x64",
"linux-x64",
"linux-arm",
"linux-arm64",
"win-arm",
"win-arm64")]
[string]$Runtime,
Expand Down Expand Up @@ -1873,6 +1896,7 @@ function Start-PSBootstrap {
[switch]$NoSudo,
[switch]$BuildWindowsNative,
[switch]$BuildLinuxArm,
[switch]$BuildLinuxArm64,
[switch]$Force
)

Expand All @@ -1896,8 +1920,8 @@ function Start-PSBootstrap {
Pop-Location
}

if ($BuildLinuxArm -and -not $Environment.IsUbuntu) {
Write-Error "Cross compiling for linux-arm is only supported on Ubuntu environment"
if (($BuildLinuxArm -or $BuildLinuxArm64) -and -not $Environment.IsUbuntu) {
Write-Error "Cross compiling for linux-arm/linux-arm64 are only supported on Ubuntu environment"
return
}

Expand All @@ -1909,6 +1933,8 @@ function Start-PSBootstrap {

if ($BuildLinuxArm) {
$Deps += "gcc-arm-linux-gnueabihf", "g++-arm-linux-gnueabihf"
} elseif ($BuildLinuxArm64) {
$Deps += "gcc-aarch64-linux-gnu", "g++-aarch64-linux-gnu"
}

# .NET Core required runtime libraries
Expand Down Expand Up @@ -2483,6 +2509,7 @@ function Start-CrossGen {
"osx-x64",
"linux-x64",
"linux-arm",
"linux-arm64",
"win-arm",
"win-arm64")]
[string]
Expand Down Expand Up @@ -2545,6 +2572,8 @@ function Start-CrossGen {
}
} elseif ($Runtime -eq "linux-arm") {
throw "crossgen is not available for 'linux-arm'"
} elseif ($Runtime -eq "linux-arm64") {
throw "crossgen is not available for 'linux-arm64'"
} elseif ($Environment.IsLinux) {
"linux-x64"
} elseif ($Environment.IsMacOS) {
Expand Down
17 changes: 17 additions & 0 deletions src/libpsl-native/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 aarch64)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++ -fstack-protector-strong -fpie -DFORTIFY_SOURCE=2 -O2)
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-z,relro,-z,now")
set(CMAKE_C_COMPILER aarch64-linux-gnu-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)
13 changes: 12 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-musl-x64')]
[ValidateSet('x64', 'x86', 'x64_arm', 'x64_arm64', 'linux-x64', 'osx', 'linux-arm', 'linux-arm64', 'linux-musl-x64')]
[string]
$Arch,

Expand Down Expand Up @@ -62,6 +62,17 @@ end {
Write-Verbose -Verbose "Skipping artifact upload since this is a PR."
}
}
elseif ($Arch -eq 'linux-arm64') {
Start-PSBootstrap -BuildLinuxArm64
Start-BuildNativeUnixBinaries -BuildLinuxArm64

if ($env:BUILD_REASON -ne 'PullRequest') {
$buildOutputPath = Join-Path $RepoRoot "src/powershell-unix"
Compress-Archive -Path $buildOutputPath/libpsl-native.* -DestinationPath "$TargetLocation/$Arch-symbols.zip" -Verbose
} else {
Write-Verbose -Verbose "Skipping artifact upload since this is a PR."
}
}
else {
Write-Verbose "Starting Start-PSBootstrap" -Verbose
Start-PSBootstrap -BuildWindowsNative
Expand Down
14 changes: 13 additions & 1 deletion tools/releaseBuild/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
],
"Linux": [
{
"Name": "ubuntu.16.04",
"Name": "ubuntu.16.04-arm",
"RepoDestinationPath": "/PowerShellNative",
"BuildCommand": "/PowerShellNative/tools/releaseBuild/PowershellNative.ps1 -RepoRoot _RepoDestinationPath_ -TargetLocation _DockerVolume_ -Arch linux-arm -Configuration Release",
"AdditionalContextFiles": [
Expand All @@ -86,6 +86,18 @@
"BinaryBucket": "release",
"EnableFeature": [ "ArtifactAsFolder" ]
},
{
"Name": "ubuntu.16.04-arm64",
"RepoDestinationPath": "/PowerShellNative",
"BuildCommand": "/PowerShellNative/tools/releaseBuild/PowershellNative.ps1 -RepoRoot _RepoDestinationPath_ -TargetLocation _DockerVolume_ -Arch linux-arm64 -Configuration Release",
"AdditionalContextFiles": [
"./tools/releaseBuild/PowershellNative.ps1"
],
"DockerFile": "./tools/releaseBuild/images/Ubuntu16.04/Dockerfile",
"DockerImageName": "ps-ubunutu-16-04",
"BinaryBucket": "release",
"EnableFeature": [ "ArtifactAsFolder" ]
},
{
"Name": "centos.7",
"RepoDestinationPath": "/PowerShellNative",
Expand Down