From bdafe16af45a0f386168e6f38b07cca612924483 Mon Sep 17 00:00:00 2001 From: David Kale Date: Thu, 7 Nov 2019 13:04:16 -0500 Subject: [PATCH] Cross compile for win-x86, linux-arm, linux-arm64 --- azure-pipelines.yml | 104 ++++++++++++++++++ nonwindows.template.yml | 7 +- src/Directory.Build.props | 3 + src/Misc/externals.sh | 5 + src/Runner.Common/Runner.Common.csproj | 2 +- src/Runner.Listener/Runner.Listener.csproj | 2 +- .../Runner.PluginHost.csproj | 2 +- src/Runner.Plugins/Runner.Plugins.csproj | 2 +- src/Runner.Sdk/Runner.Sdk.csproj | 2 +- src/Runner.Worker/Runner.Worker.csproj | 2 +- src/Sdk/Sdk.csproj | 2 +- src/Test/Test.csproj | 2 +- src/dev.sh | 66 ++++++----- windows.template.yml | 7 +- 14 files changed, 167 insertions(+), 41 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 8706b1fb8..8fedfb19b 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -10,6 +10,52 @@ jobs: # Steps template for windows platform - template: windows.template.yml + parameters: + targetRuntime: win-x64 + + # Package dotnet core windows dependency (VC++ Redistributable) + - powershell: | + Write-Host "Downloading 'VC++ Redistributable' package." + $outDir = Join-Path -Path $env:TMP -ChildPath ([Guid]::NewGuid()) + New-Item -Path $outDir -ItemType directory + $outFile = Join-Path -Path $outDir -ChildPath "ucrt.zip" + Invoke-WebRequest -Uri https://vstsagenttools.blob.core.windows.net/tools/ucrt/ucrt_x64.zip -OutFile $outFile + Write-Host "Unzipping 'VC++ Redistributable' package to agent layout." + $unzipDir = Join-Path -Path $outDir -ChildPath "unzip" + Add-Type -AssemblyName System.IO.Compression.FileSystem + [System.IO.Compression.ZipFile]::ExtractToDirectory($outFile, $unzipDir) + $agentLayoutBin = Join-Path -Path $(Build.SourcesDirectory) -ChildPath "_layout\bin" + Copy-Item -Path $unzipDir -Destination $agentLayoutBin -Force + displayName: Package UCRT + condition: and(succeeded(), ne(variables['build.reason'], 'PullRequest')) + + # Create agent package zip + - script: dev.cmd package Release + workingDirectory: src + displayName: Package Release + condition: and(succeeded(), ne(variables['build.reason'], 'PullRequest')) + + # Upload agent package zip as build artifact + - task: PublishBuildArtifacts@1 + displayName: Publish Artifact (Windows x64) + condition: and(succeeded(), ne(variables['build.reason'], 'PullRequest')) + inputs: + pathToPublish: _package + artifactName: agent + artifactType: container + +################################################################################ +- job: build_windows_x86_agent +################################################################################ + displayName: Windows Agent (x64) + pool: + vmImage: vs2017-win2016 + steps: + + # Steps template for windows platform + - template: windows.template.yml + parameters: + targetRuntime: win-x86 # Package dotnet core windows dependency (VC++ Redistributable) - powershell: | @@ -52,6 +98,64 @@ jobs: # Steps template for non-windows platform - template: nonwindows.template.yml + parameters: + targetRuntime: linux-x64 + + # Create agent package zip + - script: ./dev.sh package Release + workingDirectory: src + displayName: Package Release + condition: and(succeeded(), ne(variables['build.reason'], 'PullRequest')) + + # Upload agent package zip as build artifact + - task: PublishBuildArtifacts@1 + displayName: Publish Artifact (Linux x64) + condition: and(succeeded(), ne(variables['build.reason'], 'PullRequest')) + inputs: + pathToPublish: _package + artifactName: agent + artifactType: container + +################################################################################ +- job: build_linux_arm64_agent +################################################################################ + displayName: Linux Agent (x64) + pool: + vmImage: ubuntu-16.04 + steps: + + # Steps template for non-windows platform + - template: nonwindows.template.yml + parameters: + targetRuntime: linux-arm64 + + # Create agent package zip + - script: ./dev.sh package Release + workingDirectory: src + displayName: Package Release + condition: and(succeeded(), ne(variables['build.reason'], 'PullRequest')) + + # Upload agent package zip as build artifact + - task: PublishBuildArtifacts@1 + displayName: Publish Artifact (Linux x64) + condition: and(succeeded(), ne(variables['build.reason'], 'PullRequest')) + inputs: + pathToPublish: _package + artifactName: agent + artifactType: container + +################################################################################ +- job: build_linux_arm32_agent +################################################################################ + displayName: Linux Agent (x64) + pool: + vmImage: ubuntu-16.04 + steps: + + # Steps template for non-windows platform + - template: nonwindows.template.yml + parameters: + targetRuntime: linux-arm # Create agent package zip - script: ./dev.sh package Release diff --git a/nonwindows.template.yml b/nonwindows.template.yml index 833bd0500..f0ce42cb1 100644 --- a/nonwindows.template.yml +++ b/nonwindows.template.yml @@ -1,9 +1,12 @@ +parameters: + targetRuntime: '' + steps: # Build agent layout -- script: ./dev.sh layout Release +- script: ./dev.sh layout Release ${{ parameters.targetRuntime }} workingDirectory: src - displayName: Build & Layout Release + displayName: Build & Layout Release ${{ parameters.targetRuntime }} # Run test - script: ./dev.sh test diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 0799b4438..01f941d99 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -41,6 +41,9 @@ $(DefineConstants);ARM + + $(DefineConstants);ARM64 + diff --git a/src/Misc/externals.sh b/src/Misc/externals.sh index 0f37cc254..b9d1cbf74 100755 --- a/src/Misc/externals.sh +++ b/src/Misc/externals.sh @@ -136,6 +136,7 @@ if [[ "$PACKAGERUNTIME" == "osx-x64" ]]; then acquireExternalTool "$NODE_URL/v${NODE12_VERSION}/node-v${NODE12_VERSION}-darwin-x64.tar.gz" node12 fix_nested_dir fi +# TODO make sure linux[x64, x84, arm64(8), arm32(7)] are listed # Download the external tools common across Linux PACKAGERUNTIMEs (excluding OSX). if [[ "$PACKAGERUNTIME" == "linux-x64" || "$PACKAGERUNTIME" == "rhel.6-x64" ]]; then acquireExternalTool "$NODE_URL/v${NODE12_VERSION}/node-v${NODE12_VERSION}-linux-x64.tar.gz" node12 fix_nested_dir @@ -143,6 +144,10 @@ if [[ "$PACKAGERUNTIME" == "linux-x64" || "$PACKAGERUNTIME" == "rhel.6-x64" ]]; acquireExternalTool "https://vstsagenttools.blob.core.windows.net/tools/nodejs/12_4_0/alpine/node-v${NODE12_VERSION}-alpine.tar.gz" node12_alpine fi +if [[ "$PACKAGERUNTIME" == "linux-arm64" ]]; then + acquireExternalTool "$NODE_URL/v${NODE12_VERSION}/node-v${NODE12_VERSION}-linux-armv64.tar.gz" node12 fix_nested_dir +fi + if [[ "$PACKAGERUNTIME" == "linux-arm" ]]; then acquireExternalTool "$NODE_URL/v${NODE12_VERSION}/node-v${NODE12_VERSION}-linux-armv7l.tar.gz" node12 fix_nested_dir fi diff --git a/src/Runner.Common/Runner.Common.csproj b/src/Runner.Common/Runner.Common.csproj index 0ebf38336..1d1b6294b 100644 --- a/src/Runner.Common/Runner.Common.csproj +++ b/src/Runner.Common/Runner.Common.csproj @@ -3,7 +3,7 @@ netcoreapp3.0 Library - win-x64;win-x86;linux-x64;linux-arm;rhel.6-x64;osx-x64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;rhel.6-x64;osx-x64 true portable-net45+win8 NU1701;NU1603 diff --git a/src/Runner.Listener/Runner.Listener.csproj b/src/Runner.Listener/Runner.Listener.csproj index 243e5911f..f83e60811 100644 --- a/src/Runner.Listener/Runner.Listener.csproj +++ b/src/Runner.Listener/Runner.Listener.csproj @@ -3,7 +3,7 @@ netcoreapp3.0 Exe - win-x64;win-x86;linux-x64;linux-arm;rhel.6-x64;osx-x64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;rhel.6-x64;osx-x64 true portable-net45+win8 NU1701;NU1603 diff --git a/src/Runner.PluginHost/Runner.PluginHost.csproj b/src/Runner.PluginHost/Runner.PluginHost.csproj index 6066911f4..cbda6006d 100644 --- a/src/Runner.PluginHost/Runner.PluginHost.csproj +++ b/src/Runner.PluginHost/Runner.PluginHost.csproj @@ -3,7 +3,7 @@ netcoreapp3.0 Exe - win-x64;win-x86;linux-x64;linux-arm;rhel.6-x64;osx-x64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;rhel.6-x64;osx-x64 true portable-net45+win8 NU1701;NU1603 diff --git a/src/Runner.Plugins/Runner.Plugins.csproj b/src/Runner.Plugins/Runner.Plugins.csproj index da5d92f9b..77057f843 100644 --- a/src/Runner.Plugins/Runner.Plugins.csproj +++ b/src/Runner.Plugins/Runner.Plugins.csproj @@ -3,7 +3,7 @@ netcoreapp3.0 Library - win-x64;win-x86;linux-x64;linux-arm;rhel.6-x64;osx-x64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;rhel.6-x64;osx-x64 true portable-net45+win8 NU1701;NU1603 diff --git a/src/Runner.Sdk/Runner.Sdk.csproj b/src/Runner.Sdk/Runner.Sdk.csproj index ba5caa935..647e988b0 100644 --- a/src/Runner.Sdk/Runner.Sdk.csproj +++ b/src/Runner.Sdk/Runner.Sdk.csproj @@ -3,7 +3,7 @@ netcoreapp3.0 Library - win-x64;win-x86;linux-x64;linux-arm;rhel.6-x64;osx-x64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;rhel.6-x64;osx-x64 true portable-net45+win8 NU1701;NU1603 diff --git a/src/Runner.Worker/Runner.Worker.csproj b/src/Runner.Worker/Runner.Worker.csproj index 1b25f492a..cbefbef38 100644 --- a/src/Runner.Worker/Runner.Worker.csproj +++ b/src/Runner.Worker/Runner.Worker.csproj @@ -3,7 +3,7 @@ netcoreapp3.0 Exe - win-x64;win-x86;linux-x64;linux-arm;rhel.6-x64;osx-x64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;rhel.6-x64;osx-x64 true portable-net45+win8 NU1701;NU1603 diff --git a/src/Sdk/Sdk.csproj b/src/Sdk/Sdk.csproj index e9f110a92..64e973482 100644 --- a/src/Sdk/Sdk.csproj +++ b/src/Sdk/Sdk.csproj @@ -3,7 +3,7 @@ netcoreapp3.0 Library - win-x64;win-x86;linux-x64;linux-arm;rhel.6-x64;osx-x64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;rhel.6-x64;osx-x64 true portable-net45+win8 NU1701;NU1603 diff --git a/src/Test/Test.csproj b/src/Test/Test.csproj index 0b8ec45a3..12bea3cf3 100644 --- a/src/Test/Test.csproj +++ b/src/Test/Test.csproj @@ -1,7 +1,7 @@  netcoreapp3.0 - win-x64;win-x86;linux-x64;linux-arm;rhel.6-x64;osx-x64 + win-x64;win-x86;linux-x64;linux-arm64;linux-arm;rhel.6-x64;osx-x64 true portable-net45+win8 NU1701;NU1603;NU1603;xUnit2013; diff --git a/src/dev.sh b/src/dev.sh index 8e7858ccf..2000e6250 100755 --- a/src/dev.sh +++ b/src/dev.sh @@ -10,6 +10,7 @@ set -e DEV_CMD=$1 DEV_CONFIG=$2 +DEV_TARGET_RUNTIME=$3 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" LAYOUT_DIR="$SCRIPT_DIR/../_layout" @@ -27,36 +28,43 @@ if [[ "$DEV_CONFIG" == "Release" ]]; then BUILD_CONFIG="Release" fi -CURRENT_PLATFORM="windows" -if [[ ($(uname) == "Linux") || ($(uname) == "Darwin") ]]; then - CURRENT_PLATFORM=$(uname | awk '{print tolower($0)}') +if [[ -n "$DEV_TARGET_RUNTIME" ]]; then + RUNTIME_ID="$DEV_TARGET_RUNTIME" +else + echo "Automatically determining target runtime" + CURRENT_PLATFORM="windows" + if [[ ($(uname) == "Linux") || ($(uname) == "Darwin") ]]; then + CURRENT_PLATFORM=$(uname | awk '{print tolower($0)}') + fi + + if [[ "$CURRENT_PLATFORM" == 'windows' ]]; then + RUNTIME_ID='win-x64' + if [[ "$PROCESSOR_ARCHITECTURE" == 'x86' ]]; then + RUNTIME_ID='win-x86' + fi + elif [[ "$CURRENT_PLATFORM" == 'linux' ]]; then + RUNTIME_ID="linux-x64" + if command -v uname > /dev/null; then + CPU_NAME=$(uname -m) + case $CPU_NAME in + armv7l) RUNTIME_ID="linux-arm";; + aarch64) RUNTIME_ID="linux-arm64";; + esac + fi + + if [ -e /etc/redhat-release ]; then + redhatRelease=$( /dev/null; then - CPU_NAME=$(uname -m) - case $CPU_NAME in - armv7l) RUNTIME_ID="linux-arm";; - aarch64) RUNTIME_ID="linux-arm";; - esac - fi - - if [ -e /etc/redhat-release ]; then - redhatRelease=$(&2 exit 1 fi diff --git a/windows.template.yml b/windows.template.yml index 6e003cc67..aea500107 100644 --- a/windows.template.yml +++ b/windows.template.yml @@ -1,9 +1,12 @@ +parameters: + targetRuntime: '' + steps: # Build agent layout -- script: dev.cmd layout Release +- script: dev.cmd layout Release ${{ parameters.targetRuntime }} workingDirectory: src - displayName: Build & Layout Release + displayName: Build & Layout Release ${{ parameters.targetRuntime }} # Run test - script: dev.cmd test