Enable cross compiling for raspberry-pi arm32 (#4742)

This commit is contained in:
Steve Lee 2017-09-11 12:16:58 -07:00 committed by Travis Plunk
parent 0dc575dbf6
commit 6f1c7a05c6
5 changed files with 78 additions and 79 deletions

View file

@ -301,7 +301,8 @@ function Start-PSBuild {
"win10-x64",
"osx.10.12-x64",
"opensuse.13.2-x64",
"opensuse.42.1-x64")]
"opensuse.42.1-x64",
"linux-arm")]
[string]$Runtime,
[ValidateSet('Linux', 'Debug', 'Release', 'CodeCoverage', '')] # We might need "Checked" as well
@ -363,6 +364,12 @@ function Start-PSBuild {
}
}
if ($RunTime -eq "linux-arm") {
foreach ($Dependency in 'arm-linux-gnueabihf-gcc', 'arm-linux-gnueabihf-g++') {
$precheck = $precheck -and (precheck $Dependency "Build dependency '$Dependency' not found. Run 'Start-PSBootstrap'.")
}
}
# Abort if any precheck failed
if (-not $precheck) {
return
@ -464,9 +471,15 @@ Fix steps:
try {
Push-Location $Native
Start-NativeExecution { cmake -DCMAKE_BUILD_TYPE=Debug . }
Start-NativeExecution { make -j }
Start-NativeExecution { ctest --verbose }
if ($Runtime -eq "linux-arm") {
Start-NativeExecution { cmake -DCMAKE_TOOLCHAIN_FILE="./arm.toolchain.cmake" . }
Start-NativeExecution { make -j }
}
else {
Start-NativeExecution { cmake -DCMAKE_BUILD_TYPE=Debug . }
Start-NativeExecution { make -j }
Start-NativeExecution { ctest --verbose }
}
} finally {
Pop-Location
}
@ -587,7 +600,8 @@ function New-PSOptions {
"win10-x64",
"osx.10.12-x64",
"opensuse.13.2-x64",
"opensuse.42.1-x64")]
"opensuse.42.1-x64",
"linux-arm")]
[string]$Runtime,
[switch]$CrossGen,
@ -651,7 +665,7 @@ function New-PSOptions {
}
}
# We plan to release packages targetting win7-x64 and win7-x86 RIDs,
# We plan to release packages targetting win7-x64 and win7-x86 RIDs,
# which supports all supported windows platforms.
# So we, will change the RID to win7-<arch>
if ($Environment.IsWindows) {
@ -937,7 +951,7 @@ function Start-PSPester {
if ($PassThru.IsPresent)
{
$passThruFile = [System.IO.Path]::GetTempFileName()
try
try
{
$Command += "|Export-Clixml -Path '$passThruFile' -Force"
Start-NativeExecution -sb {& $powershell -noprofile -c $Command} | ForEach-Object { Write-Host $_}
@ -948,7 +962,7 @@ function Start-PSPester {
Remove-Item $passThruFile -ErrorAction SilentlyContinue
}
}
else
else
{
Start-NativeExecution -sb {& $powershell -noprofile -c $Command}
}
@ -984,13 +998,13 @@ function script:Start-UnelevatedProcess
function Show-PSPesterError
{
[CmdletBinding(DefaultParameterSetName='xml')]
param (
param (
[Parameter(ParameterSetName='xml',Mandatory)]
[Xml.XmlElement]$testFailure,
[Parameter(ParameterSetName='object',Mandatory)]
[PSCustomObject]$testFailureObject
)
if ($PSCmdLet.ParameterSetName -eq 'xml')
{
$description = $testFailure.description
@ -1046,11 +1060,11 @@ function Test-PSPesterResults
{
logerror "TEST FAILURES"
# switch between methods, SelectNode is not available on dotnet core
if ( "System.Xml.XmlDocumentXPathExtensions" -as [Type] )
if ( "System.Xml.XmlDocumentXPathExtensions" -as [Type] )
{
$failures = [System.Xml.XmlDocumentXPathExtensions]::SelectNodes($x."test-results",'.//test-case[@result = "Failure"]')
}
else
else
{
$failures = $x.SelectNodes('.//test-case[@result = "Failure"]')
}
@ -1202,6 +1216,7 @@ function Start-PSBootstrap {
[switch]$Package,
[switch]$NoSudo,
[switch]$BuildWindowsNative,
[switch]$BuildLinuxArm,
[switch]$Force
)
@ -1225,12 +1240,21 @@ function Start-PSBootstrap {
Pop-Location
}
if ($BuildLinuxArm -and -not $Environment.IsUbuntu) {
Write-Error "Cross compiling for linux-arm is only supported on Ubuntu environment"
return
}
# Install ours and .NET's dependencies
$Deps = @()
if ($Environment.IsUbuntu) {
# Build tools
$Deps += "curl", "g++", "cmake", "make"
if ($BuildLinuxArm) {
$Deps += "gcc-arm-linux-gnueabihf", "g++-arm-linux-gnueabihf"
}
# .NET Core required runtime libraries
$Deps += "libunwind8"
if ($Environment.IsUbuntu14) { $Deps += "libicu52" }
@ -1837,7 +1861,8 @@ function Start-CrossGen {
"win10-x64",
"osx.10.12-x64",
"opensuse.13.2-x64",
"opensuse.42.1-x64")]
"opensuse.42.1-x64",
"linux-arm")]
[string]
$Runtime
)
@ -1894,6 +1919,8 @@ function Start-CrossGen {
} else {
"win-x64"
}
} elseif ($Runtime -eq "linux-arm") {
throw "crossgen is not available for 'linux-arm'"
} elseif ($Environment.IsLinux) {
"linux-x64"
} elseif ($Environment.IsMacOS) {

View file

@ -1,59 +0,0 @@
#!/usr/bin/env bash
set -e
if hash powershell 2>/dev/null; then
echo 'Continuing with `powershell -noprofile -c Start-PSBuild`'
powershell -noprofile -c "Import-Module ./build.psm1; Start-PSBuild"
else
echo 'Continuing with full manual build'
## Restore
dotnet restore src/powershell-unix
dotnet restore src/ResGen
dotnet restore src/TypeCatalogGen
## Setup the build target to gather dependency information
targetFile="$(pwd)/src/Microsoft.PowerShell.SDK/obj/Microsoft.PowerShell.SDK.csproj.TypeCatalog.targets"
cat > $targetFile <<-"EOF"
<Project>
<Target Name="_GetDependencies"
DependsOnTargets="ResolveAssemblyReferencesDesignTime">
<ItemGroup>
<_RefAssemblyPath Include="%(_ReferencesFromRAR.ResolvedPath)%3B" Condition=" '%(_ReferencesFromRAR.Type)' == 'assembly' And '%(_ReferencesFromRAR.PackageName)' != 'Microsoft.Management.Infrastructure' " />
</ItemGroup>
<WriteLinesToFile File="$(_DependencyFile)" Lines="@(_RefAssemblyPath)" Overwrite="true" />
</Target>
</Project>
EOF
dotnet msbuild src/Microsoft.PowerShell.SDK/Microsoft.PowerShell.SDK.csproj /t:_GetDependencies "/property:DesignTimeBuild=true;_DependencyFile=$(pwd)/src/TypeCatalogGen/powershell.inc" /nologo
## Generate 'powershell.version'
git --git-dir="$(pwd)/.git" describe --dirty --abbrev=60 > "$(pwd)/powershell.version"
## create the telemetry flag file
touch "$(pwd)/DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY"
## Generate resource binding C# files
pushd src/ResGen
dotnet run
popd
## Generate 'CorePsTypeCatalog.cs'
pushd src/TypeCatalogGen
dotnet run ../Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CorePsTypeCatalog.cs powershell.inc
popd
## Build native component
pushd src/libpsl-native
cmake -DCMAKE_BUILD_TYPE=Debug .
make -j
make test
popd
## Build powershell core
rawRid="$(dotnet --info | grep RID)"
rid=${rawRid##* } # retain the part after the last space
dotnet publish --configuration Linux src/powershell-unix/ --output bin --runtime $rid
echo 'You can run powershell from bin/, but some modules that are normally added by the Restore-PSModule step will not be available.'
fi

View file

@ -6,7 +6,13 @@ set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror")
set(LIBRARY_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/../powershell-unix")
# test in BUILD_DIR
enable_testing()
add_subdirectory(src)
add_subdirectory(test)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "arm*")
message(STATUS "Building for ARM, no tests")
add_subdirectory(src)
else ()
# test in BUILD_DIR
message(STATUS "Tests enabled")
enable_testing()
add_subdirectory(src)
add_subdirectory(test)
endif ()

View file

@ -0,0 +1,19 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR armv7l)
set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
# add_compile_options(-target armv7-linux-gnueabihf)
add_compile_options(-mthumb)
add_compile_options(-mfpu=vfpv3)
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)

View file

@ -19,13 +19,13 @@ function Start-PSPackage {
[string]$Name = "powershell",
# Ubuntu, CentOS, Fedora, macOS, and Windows packages are supported
[ValidateSet("deb", "osxpkg", "rpm", "msi", "zip", "AppImage", "nupkg")]
[ValidateSet("deb", "osxpkg", "rpm", "msi", "zip", "AppImage", "nupkg", "deb-arm")]
[string[]]$Type,
# Generate windows downlevel package
[ValidateSet("win7-x86", "win7-x64")]
[ValidateScript({$Environment.IsWindows})]
[string]$WindowsRuntime,
[string] $WindowsRuntime,
[Switch] $Force,
@ -37,6 +37,8 @@ function Start-PSPackage {
# Runtime and Configuration settings required by the package
($Runtime, $Configuration) = if ($WindowsRuntime) {
$WindowsRuntime, "Release"
} elseif ($Type -eq "deb-arm") {
New-PSOptions -Configuration "Release" -Runtime "Linux-ARM" -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration }
} else {
New-PSOptions -Configuration "Release" -WarningAction SilentlyContinue | ForEach-Object { $_.Runtime, $_.Configuration }
}
@ -54,7 +56,11 @@ function Start-PSPackage {
$Script:Options = Get-PSOptions
$crossGenCorrect = $false
if(-not $IncludeSymbols.IsPresent -and $Script:Options.CrossGen) {
if ($Type -eq "deb-arm") {
# crossgen doesn't support arm32 yet
$crossGenCorrect = $true
}
elseif(-not $IncludeSymbols.IsPresent -and $Script:Options.CrossGen) {
$crossGenCorrect = $true
}
elseif ($IncludeSymbols.IsPresent -and -not $Script:Options.CrossGen) {