From 4946c72dab997fd2a80a6723bd4bfa1db71f57a0 Mon Sep 17 00:00:00 2001
From: John Luo <johluo@microsoft.com>
Date: Tue, 14 May 2019 15:44:52 -0700
Subject: [PATCH] Add build for linux-musl-arm64 (#10155)

* Add build for linux-musl-arm64

* Remove redundant apk installs
---
 .azure/pipelines/ci.yml                       | 28 +++++++++++++++++++
 Directory.Build.props                         |  1 +
 build/docker/ubuntu-alpine37.Dockerfile       | 18 ++++++++++++
 eng/Dependencies.props                        |  1 +
 .../Microsoft.AspNetCore.App.Runtime.csproj   |  2 +-
 5 files changed, 49 insertions(+), 1 deletion(-)
 create mode 100644 build/docker/ubuntu-alpine37.Dockerfile

diff --git a/.azure/pipelines/ci.yml b/.azure/pipelines/ci.yml
index 2d305a7e03e..5fab3f3a16d 100644
--- a/.azure/pipelines/ci.yml
+++ b/.azure/pipelines/ci.yml
@@ -288,6 +288,34 @@ jobs:
   parameters:
     inputName: Linux_musl_x64
 
+# Build Linux Musl arm64
+- template: jobs/default-build.yml
+  parameters:
+    jobName: Linux_musl_arm64_build
+    jobDisplayName: "Build: Linux Musl ARM64"
+    agentOs: Linux
+    buildScript: ./dockerbuild.sh ubuntu-alpine37
+    buildArgs: --ci --pack --all -e KOREBUILD_SKIP_INSTALL_NETFX=0 --arch arm64 --os-name linux-musl --no-build-nodejs --no-build-java /bl:artifacts/logs/build.musl.binlog
+    installNodeJs: false
+    afterBuild:
+    # Remove packages that are not rid-specific.
+    # TODO add a flag so macOS/Linux builds only produce runtime packages
+    - script: if [ -d 'artifacts/packages' ]; then find artifacts/packages/ -type f -not -name 'runtime.*' -not -name 'Microsoft.AspNetCore.App.Runtime.*' -delete; fi
+      condition: always()
+    artifacts:
+    - name: Linux_musl_arm64_Packages
+      path: artifacts/packages/
+    - name: Linux_musl_arm64_Manifests
+      path: artifacts/manifests/
+    - name: Linux_musl_arm64_Installers
+      path: artifacts/installers/
+    - name: Linux_musl_arm64_Logs
+      path: artifacts/logs/
+      publishOnError: true
+- template: jobs/codesign-xplat.yml
+  parameters:
+    inputName: Linux_musl_arm64
+
 # Test jobs
 - template: jobs/default-build.yml
   parameters:
diff --git a/Directory.Build.props b/Directory.Build.props
index da12b272ad8..3113a74709d 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -101,6 +101,7 @@
       win-arm;
       osx-x64;
       linux-musl-x64;
+      linux-musl-arm64;
       linux-x64;
       linux-arm;
       linux-arm64
diff --git a/build/docker/ubuntu-alpine37.Dockerfile b/build/docker/ubuntu-alpine37.Dockerfile
new file mode 100644
index 00000000000..fcce8aab56d
--- /dev/null
+++ b/build/docker/ubuntu-alpine37.Dockerfile
@@ -0,0 +1,18 @@
+FROM mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-16.04-cross-arm64-alpine10fcdcf-20190208200917
+ARG USER
+ARG USER_ID
+ARG GROUP_ID
+
+WORKDIR /code/build
+RUN mkdir -p "/home/$USER" && chown "${USER_ID}:${GROUP_ID}" "/home/$USER"
+ENV HOME "/home/$USER"
+
+USER $USER_ID:$GROUP_ID
+
+# Disable the invariant mode (set in base image)
+ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT false
+ENV LC_ALL en_US.UTF-8
+ENV LANG en_US.UTF-8
+
+# Skip package initilization
+ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
diff --git a/eng/Dependencies.props b/eng/Dependencies.props
index 5efe5cced57..623fd62c5ac 100644
--- a/eng/Dependencies.props
+++ b/eng/Dependencies.props
@@ -177,6 +177,7 @@ and are generated based on the last package release.
     <LatestPackageReference Include="runtime.linux-arm.microsoft.netcore.app" Version="$(MicrosoftNETCoreAppPackageVersion)" />
     <LatestPackageReference Include="runtime.linux-arm64.microsoft.netcore.app" Version="$(MicrosoftNETCoreAppPackageVersion)" />
     <LatestPackageReference Include="runtime.linux-musl-x64.microsoft.netcore.app" Version="$(MicrosoftNETCoreAppPackageVersion)" />
+    <LatestPackageReference Include="runtime.linux-musl-arm64.microsoft.netcore.app" Version="$(MicrosoftNETCoreAppPackageVersion)" />
   </ItemGroup>
 
 </Project>
diff --git a/src/Framework/src/Microsoft.AspNetCore.App.Runtime.csproj b/src/Framework/src/Microsoft.AspNetCore.App.Runtime.csproj
index 7af695b6c20..e81541b1de3 100644
--- a/src/Framework/src/Microsoft.AspNetCore.App.Runtime.csproj
+++ b/src/Framework/src/Microsoft.AspNetCore.App.Runtime.csproj
@@ -109,7 +109,7 @@ This package is an internal implementation of the .NET Core SDK and is not meant
     <CrossgenToolPackagePath>$(CrossgenToolFileName)</CrossgenToolPackagePath>
     <!-- Disambiguated RID-specific crossgen executable relative path -->
     <CrossgenToolPackagePath Condition=" '$(TargetRuntimeIdentifier)' == 'linux-arm' ">x64_arm\$(CrossgenToolPackagePath)</CrossgenToolPackagePath>
-    <CrossgenToolPackagePath Condition=" '$(TargetRuntimeIdentifier)' == 'linux-arm64' ">x64_arm64\$(CrossgenToolPackagePath)</CrossgenToolPackagePath>
+    <CrossgenToolPackagePath Condition=" '$(TargetRuntimeIdentifier)' == 'linux-arm64' OR '$(TargetRuntimeIdentifier)' == 'linux-musl-arm64' ">x64_arm64\$(CrossgenToolPackagePath)</CrossgenToolPackagePath>
     <CrossgenToolPackagePath Condition=" '$(TargetRuntimeIdentifier)' == 'win-arm' ">x86_arm\$(CrossgenToolPackagePath)</CrossgenToolPackagePath>
 
     <RuntimePackageRoot>$([System.IO.Path]::Combine('$(NuGetPackageRoot)', 'runtime.$(RuntimeIdentifier).microsoft.netcore.app', '$(MicrosoftNETCoreAppPackageVersion)'))</RuntimePackageRoot>
-- 
GitLab