Skip to content

Commit b5f7d9f

Browse files
slideadityapatwardhan
authored andcommitted
Add option to build ARM64 on Linux (#16)
1 parent a45c6de commit b5f7d9f

File tree

6 files changed

+83
-12
lines changed

6 files changed

+83
-12
lines changed

.vsts-ci/linux.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ phases:
1717
parallel: 2
1818
matrix:
1919
Linux ARM Native:
20-
buildName: ubuntu.16.04
20+
buildName: ubuntu.16.04-arm
21+
Linux ARM64 Native:
22+
buildName: ubuntu.16.04-arm64
2123
Linux Native:
2224
buildName: centos.7
2325
Linux Alpine:

.vsts-ci/windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ phases:
3636
condition: succeeded()
3737
- powershell: |
3838
Invoke-WebRequest "https://aka.ms/vs/15/release/vs_BuildTools.exe" -OutFile vs_BuildTools.exe -UseBasicParsing
39-
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
39+
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
4040
Remove-Item .\vs_BuildTools.exe
4141
Remove-Item -Force -Recurse 'C:\Program Files (x86)\Microsoft Visual Studio\Installer'
4242
$vsPath = ${Env:ProgramFiles(x86)} + '\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin'

build.psm1

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -392,16 +392,17 @@ cmd.exe /C cd /d "$location" "&" "$vcvarsallbatPath" "$Arch" "&" "$cmakePath" "$
392392

393393
function Start-BuildNativeUnixBinaries {
394394
param (
395-
[switch] $BuildLinuxArm
395+
[switch] $BuildLinuxArm,
396+
[switch] $BuildLinuxArm64
396397
)
397398

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

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

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

419424
# Abort if any precheck failed
@@ -440,6 +445,10 @@ function Start-BuildNativeUnixBinaries {
440445
Start-NativeExecution { cmake -DCMAKE_TOOLCHAIN_FILE="./arm.toolchain.cmake" . }
441446
Start-NativeExecution { make -j }
442447
}
448+
elseif ($BuildLinuxArm64) {
449+
Start-NativeExecution { cmake -DCMAKE_TOOLCHAIN_FILE="./arm64.toolchain.cmake" . }
450+
Start-NativeExecution { make -j }
451+
}
443452
else {
444453
Start-NativeExecution { cmake -DCMAKE_BUILD_TYPE=Debug . }
445454
Start-NativeExecution { make -j }
@@ -492,6 +501,10 @@ function Start-BuildPowerShellNativePackage
492501
[ValidateScript({Test-Path $_ -PathType Leaf})]
493502
[string] $LinuxARMZipPath,
494503

504+
[Parameter(Mandatory = $true)]
505+
[ValidateScript({Test-Path $_ -PathType Leaf})]
506+
[string] $LinuxARM64ZipPath,
507+
495508
[Parameter(Mandatory = $true)]
496509
[ValidateScript({Test-Path $_ -PathType Leaf})]
497510
[string] $LinuxAlpineZipPath,
@@ -525,6 +538,7 @@ function Start-BuildPowerShellNativePackage
525538
$BinFolderARM64 = Join-Path $tempExtractionPath "ARM64"
526539
$BinFolderLinux = Join-Path $tempExtractionPath "Linux"
527540
$BinFolderLinuxARM = Join-Path $tempExtractionPath "LinuxARM"
541+
$BinFolderLinuxARM64 = Join-Path $tempExtractionPath "LinuxARM64"
528542
$BinFolderLinuxAlpine = Join-Path $tempExtractionPath "LinuxAlpine"
529543
$BinFolderMacOS = Join-Path $tempExtractionPath "MacOS"
530544
$BinFolderPSRP = Join-Path $tempExtractionPath "PSRP"
@@ -536,12 +550,13 @@ function Start-BuildPowerShellNativePackage
536550
Expand-Archive -Path $LinuxZipPath -DestinationPath $BinFolderLinux -Force
537551
Expand-Archive -Path $LinuxAlpineZipPath -DestinationPath $BinFolderLinuxAlpine -Force
538552
Expand-Archive -Path $LinuxARMZipPath -DestinationPath $BinFolderLinuxARM -Force
553+
Expand-Archive -Path $LinuxARM64ZipPath -DestinationPath $BinFolderLinuxARM64 -Force
539554
Expand-Archive -Path $macOSZipPath -DestinationPath $BinFolderMacOS -Force
540555
Expand-Archive -Path $psrpZipPath -DestinationPath $BinFolderPSRP -Force
541556

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

544-
PlaceUnixBinaries -PackageRoot $PackageRoot -BinFolderLinux $BinFolderLinux -BinFolderLinuxARM $BinFolderLinuxARM -BinFolderOSX $BinFolderMacOS -BinFolderPSRP $BinFolderPSRP -BinFolderLinuxAlpine $BinFolderLinuxAlpine
559+
PlaceUnixBinaries -PackageRoot $PackageRoot -BinFolderLinux $BinFolderLinux -BinFolderLinuxARM $BinFolderLinuxARM -BinFolderLinuxARM64 $BinFolderLinuxARM64 -BinFolderOSX $BinFolderMacOS -BinFolderPSRP $BinFolderPSRP -BinFolderLinuxAlpine $BinFolderLinuxAlpine
545560

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

624+
[Parameter(Mandatory = $true)]
625+
[ValidateScript({Test-Path $_ -PathType Container})]
626+
$BinFolderLinuxARM64,
627+
609628
[Parameter(Mandatory = $true)]
610629
[ValidateScript({Test-Path $_ -PathType Container})]
611630
$BinFolderLinuxAlpine,
@@ -621,11 +640,13 @@ function PlaceUnixBinaries
621640

622641
$RuntimePathLinux = New-Item -ItemType Directory -Path (Join-Path $PackageRoot -ChildPath 'runtimes/linux-x64/native') -Force
623642
$RuntimePathLinuxARM = New-Item -ItemType Directory -Path (Join-Path $PackageRoot -ChildPath 'runtimes/linux-arm/native') -Force
643+
$RuntimePathLinuxARM64 = New-Item -ItemType Directory -Path (Join-Path $PackageRoot -ChildPath 'runtimes/linux-arm64/native') -Force
624644
$RuntimePathLinuxAlpine = New-Item -ItemType Directory -Path (Join-Path $PackageRoot -ChildPath 'runtimes/linux-musl-x64/native') -Force
625645
$RuntimePathOSX = New-Item -ItemType Directory -Path (Join-Path $PackageRoot -ChildPath 'runtimes/osx/native') -Force
626646

627647
Copy-Item "$BinFolderLinux\*" -Destination $RuntimePathLinux -Verbose
628648
Copy-Item "$BinFolderLinuxARM\*" -Destination $RuntimePathLinuxARM -Verbose
649+
Copy-Item "$BinFolderLinuxARM64\*" -Destination $RuntimePathLinuxARM64 -Verbose
629650
Copy-Item "$BinFolderLinuxAlpine\*" -Destination $RuntimePathLinuxAlpine -Verbose
630651
Copy-Item "$BinFolderOSX\*" -Destination $RuntimePathOSX -Verbose
631652

@@ -738,6 +759,7 @@ function Start-PSBuild {
738759
"osx-x64",
739760
"linux-x64",
740761
"linux-arm",
762+
"linux-arm64",
741763
"win-arm",
742764
"win-arm64")]
743765
[string]$Runtime,
@@ -752,8 +774,8 @@ function Start-PSBuild {
752774
[string]$ReleaseTag
753775
)
754776

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

759781
if ("win-arm","win-arm64" -contains $Runtime -and -not $Environment.IsWindows) {
@@ -1050,6 +1072,7 @@ function New-PSOptions {
10501072
"osx-x64",
10511073
"linux-x64",
10521074
"linux-arm",
1075+
"linux-arm64",
10531076
"win-arm",
10541077
"win-arm64")]
10551078
[string]$Runtime,
@@ -1873,6 +1896,7 @@ function Start-PSBootstrap {
18731896
[switch]$NoSudo,
18741897
[switch]$BuildWindowsNative,
18751898
[switch]$BuildLinuxArm,
1899+
[switch]$BuildLinuxArm64,
18761900
[switch]$Force
18771901
)
18781902

@@ -1896,8 +1920,8 @@ function Start-PSBootstrap {
18961920
Pop-Location
18971921
}
18981922

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

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

19101934
if ($BuildLinuxArm) {
19111935
$Deps += "gcc-arm-linux-gnueabihf", "g++-arm-linux-gnueabihf"
1936+
} elseif ($BuildLinuxArm64) {
1937+
$Deps += "gcc-aarch64-linux-gnu", "g++-aarch64-linux-gnu"
19121938
}
19131939

19141940
# .NET Core required runtime libraries
@@ -2483,6 +2509,7 @@ function Start-CrossGen {
24832509
"osx-x64",
24842510
"linux-x64",
24852511
"linux-arm",
2512+
"linux-arm64",
24862513
"win-arm",
24872514
"win-arm64")]
24882515
[string]
@@ -2545,6 +2572,8 @@ function Start-CrossGen {
25452572
}
25462573
} elseif ($Runtime -eq "linux-arm") {
25472574
throw "crossgen is not available for 'linux-arm'"
2575+
} elseif ($Runtime -eq "linux-arm64") {
2576+
throw "crossgen is not available for 'linux-arm64'"
25482577
} elseif ($Environment.IsLinux) {
25492578
"linux-x64"
25502579
} elseif ($Environment.IsMacOS) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
set(CMAKE_SYSTEM_NAME Linux)
2+
set(CMAKE_SYSTEM_VERSION 1)
3+
set(CMAKE_SYSTEM_PROCESSOR aarch64)
4+
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++ -fstack-protector-strong -fpie -DFORTIFY_SOURCE=2 -O2)
5+
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-z,relro,-z,now")
6+
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
7+
8+
add_compile_options(-g)
9+
10+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CROSS_LINK_FLAGS}" CACHE STRING "" FORCE)
11+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CROSS_LINK_FLAGS}" CACHE STRING "" FORCE)
12+
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${CROSS_LINK_FLAGS}" CACHE STRING "" FORCE)
13+
14+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
15+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
16+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
17+
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

tools/releaseBuild/PowershellNative.ps1

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
param (
77

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

@@ -62,6 +62,17 @@ end {
6262
Write-Verbose -Verbose "Skipping artifact upload since this is a PR."
6363
}
6464
}
65+
elseif ($Arch -eq 'linux-arm64') {
66+
Start-PSBootstrap -BuildLinuxArm64
67+
Start-BuildNativeUnixBinaries -BuildLinuxArm64
68+
69+
if ($env:BUILD_REASON -ne 'PullRequest') {
70+
$buildOutputPath = Join-Path $RepoRoot "src/powershell-unix"
71+
Compress-Archive -Path $buildOutputPath/libpsl-native.* -DestinationPath "$TargetLocation/$Arch-symbols.zip" -Verbose
72+
} else {
73+
Write-Verbose -Verbose "Skipping artifact upload since this is a PR."
74+
}
75+
}
6576
else {
6677
Write-Verbose "Starting Start-PSBootstrap" -Verbose
6778
Start-PSBootstrap -BuildWindowsNative

tools/releaseBuild/build.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
],
7676
"Linux": [
7777
{
78-
"Name": "ubuntu.16.04",
78+
"Name": "ubuntu.16.04-arm",
7979
"RepoDestinationPath": "/PowerShellNative",
8080
"BuildCommand": "/PowerShellNative/tools/releaseBuild/PowershellNative.ps1 -RepoRoot _RepoDestinationPath_ -TargetLocation _DockerVolume_ -Arch linux-arm -Configuration Release",
8181
"AdditionalContextFiles": [
@@ -86,6 +86,18 @@
8686
"BinaryBucket": "release",
8787
"EnableFeature": [ "ArtifactAsFolder" ]
8888
},
89+
{
90+
"Name": "ubuntu.16.04-arm64",
91+
"RepoDestinationPath": "/PowerShellNative",
92+
"BuildCommand": "/PowerShellNative/tools/releaseBuild/PowershellNative.ps1 -RepoRoot _RepoDestinationPath_ -TargetLocation _DockerVolume_ -Arch linux-arm64 -Configuration Release",
93+
"AdditionalContextFiles": [
94+
"./tools/releaseBuild/PowershellNative.ps1"
95+
],
96+
"DockerFile": "./tools/releaseBuild/images/Ubuntu16.04/Dockerfile",
97+
"DockerImageName": "ps-ubunutu-16-04",
98+
"BinaryBucket": "release",
99+
"EnableFeature": [ "ArtifactAsFolder" ]
100+
},
89101
{
90102
"Name": "centos.7",
91103
"RepoDestinationPath": "/PowerShellNative",

0 commit comments

Comments
 (0)