Produce arm64-native Mono LLVM runtime packs (#38562)
authorJo Shields <directhex@apebox.org>
Fri, 10 Jul 2020 17:37:37 +0000 (13:37 -0400)
committerGitHub <noreply@github.com>
Fri, 10 Jul 2020 17:37:37 +0000 (13:37 -0400)
Produce arm64-native Mono LLVM runtime packs (i.e. for running the SDK on ARM64, not publishing to ARM64 from x64)

eng/Version.Details.xml
eng/Versions.props
eng/pipelines/common/global-build-job.yml
eng/pipelines/runtime-official.yml
eng/pipelines/runtime.yml
src/mono/llvm/build_llvm_config.sh
src/mono/llvm/llvm-init.proj
src/mono/mono.proj

index 94bac49..46f4d5a 100644 (file)
       <Uri>https://github.com/dotnet/icu</Uri>
       <Sha />
     </Dependency>
+    <Dependency Name="runtime.linux-arm64.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk" Version="9.0.1-alpha.1.20356.1">
+      <Uri>https://github.com/dotnet/llvm-project</Uri>
+      <Sha>266c9f5b5c1e94333e01ca77fa74d76563969842</Sha>
+    </Dependency>
+    <Dependency Name="runtime.linux-arm64.Microsoft.NETCore.Runtime.Mono.LLVM.Tools" Version="9.0.1-alpha.1.20356.1">
+      <Uri>https://github.com/dotnet/llvm-project</Uri>
+      <Sha>266c9f5b5c1e94333e01ca77fa74d76563969842</Sha>
+    </Dependency>
     <Dependency Name="runtime.linux-x64.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk" Version="9.0.1-alpha.1.20356.1">
       <Uri>https://github.com/dotnet/llvm-project</Uri>
       <Sha>266c9f5b5c1e94333e01ca77fa74d76563969842</Sha>
index aa56ba0..0aa4eb4 100644 (file)
     <!-- ICU -->
     <MicrosoftNETCoreRuntimeICUTransportVersion>5.0.0-preview.8.20359.5</MicrosoftNETCoreRuntimeICUTransportVersion>
     <!-- Mono LLVM -->
+    <runtimelinuxarm64MicrosoftNETCoreRuntimeMonoLLVMSdkVersion>9.0.1-alpha.1.20356.1</runtimelinuxarm64MicrosoftNETCoreRuntimeMonoLLVMSdkVersion>
+    <runtimelinuxarm64MicrosoftNETCoreRuntimeMonoLLVMToolsVersion>9.0.1-alpha.1.20356.1</runtimelinuxarm64MicrosoftNETCoreRuntimeMonoLLVMToolsVersion>
     <runtimelinuxx64MicrosoftNETCoreRuntimeMonoLLVMSdkVersion>9.0.1-alpha.1.20356.1</runtimelinuxx64MicrosoftNETCoreRuntimeMonoLLVMSdkVersion>
     <runtimelinuxx64MicrosoftNETCoreRuntimeMonoLLVMToolsVersion>9.0.1-alpha.1.20356.1</runtimelinuxx64MicrosoftNETCoreRuntimeMonoLLVMToolsVersion>
     <runtimewinx64MicrosoftNETCoreRuntimeMonoLLVMSdkVersion>9.0.1-alpha.1.20356.1</runtimewinx64MicrosoftNETCoreRuntimeMonoLLVMSdkVersion>
index d55570b..8f02954 100644 (file)
@@ -42,6 +42,12 @@ jobs:
       - name: _crossBuildPropertyArg
         value: /p:CrossBuild=${{ ne(parameters.crossrootfsDir, '') }}
 
+      - name: _cxx11Parameter
+        ${{ if and(eq(parameters.osGroup, 'Linux'), eq(parameters.archType, 'arm64')) }}:
+          value: /p:MonoLLVMUseCxx11Abi=true
+        ${{ if and(eq(parameters.osGroup, 'Linux'), not(eq(parameters.archType, 'arm64'))) }}:
+          value: /p:MonoLLVMUseCxx11Abi=false
+
       - name: _officialBuildParameter
         ${{ if eq(parameters.isOfficialBuild, true) }}:
           value: /p:OfficialBuildId=$(Build.BuildNumber)
@@ -66,7 +72,7 @@ jobs:
         displayName: Disk Usage before Build
 
     # Build
-    - script: $(Build.SourcesDirectory)$(dir)build$(scriptExt) -ci -arch ${{ parameters.archType }} $(_osParameter) ${{ parameters.buildArgs }} $(_officialBuildParameter) $(_crossBuildPropertyArg)
+    - script: $(Build.SourcesDirectory)$(dir)build$(scriptExt) -ci -arch ${{ parameters.archType }} $(_osParameter) ${{ parameters.buildArgs }} $(_officialBuildParameter) $(_crossBuildPropertyArg) $(_cxx11Parameter)
       displayName: Build product
 
     - ${{ if in(parameters.osGroup, 'OSX', 'iOS','tvOS') }}: 
index 0874ab6..3d335e1 100644 (file)
@@ -108,7 +108,7 @@ stages:
       - OSX_x64
       - Linux_x64
       # - Linux_arm
-      - Linux_arm64
+      - Linux_arm64
       # - Linux_musl_x64
       # - Linux_musl_arm64
       # - Windows_NT_x64
index d86dd42..32d7dc0 100644 (file)
@@ -356,6 +356,7 @@ jobs:
     runtimeFlavor: mono
     platforms:
     - Linux_x64
+    - Linux_arm64
     jobParameters:
       testGroup: innerloop
       nameSuffix: AllSubsets_Mono_LLVMJIT
@@ -378,6 +379,7 @@ jobs:
     runtimeFlavor: mono
     platforms:
     - Linux_x64
+    - Linux_arm64
     jobParameters:
       testGroup: innerloop
       nameSuffix: AllSubsets_Mono_LLVMAOT
index 7880d84..293de69 100755 (executable)
@@ -39,6 +39,16 @@ if [[ $llvm_config = *".exe" ]]; then
        esac
 fi
 
+local_osname="$(uname -s)"
+if [ "x$local_osname" == "xLinux" ]; then
+       local_arch="$(file /bin/bash | cut -f2 -d',')"
+       llvm_config_arch="$(file $llvm_config | cut -f2 -d',')"
+       if [ "x$llvm_config_arch" != "x$local_arch" ]; then
+               use_llvm_config=0
+               linux_cross_llvm=1
+       fi
+fi
+
 if [[ $llvm_host_win32 = 1 ]]; then
        llvm_config=$(win32_format_path "$llvm_config")
 fi
@@ -67,6 +77,51 @@ if [[ $use_llvm_config = 1 ]]; then
        fi
 fi
 
+# If building for one architecture, but running on a different architecture, we cannot execute that arch's llvm-config
+# e.g. building an ARM64 build from x64.
+if [[ $linux_cross_llvm = 1 ]] && [[ $use_llvm_config = 0 ]]; then
+       # Assume we have llvm-config sitting in llvm-install-root/bin directory, get llvm-install-root directory.
+       with_llvm="$(dirname $llvm_config)"
+       with_llvm="$(dirname $with_llvm)"
+       llvm_config_path=$with_llvm/include/llvm/Config/llvm-config.h
+
+       # llvm-config --mono-api-version
+       llvm_api_version=`awk '/MONO_API_VERSION/ { print $3 }' $llvm_config_path`
+
+       # llvm-config --cflags, returned information currently not used.
+       llvm_config_cflags=
+
+       # llvm-config --system-libs
+       llvm_system="-lz -lrt -ldl -lpthread -lm"
+
+       # llvm-config --libs analysis core bitwriter
+       llvm_core_components="-lLLVMBitWriter -lLLVMAnalysis -lLLVMProfileData -lLLVMObject -lLLVMMCParser -lLLVMMC -lLLVMDebugInfoCodeView -lLLVMDebugInfoMSF -lLLVMBitReader -lLLVMBitstreamReader -lLLVMCore -lLLVMRemarks -lLLVMBinaryFormat -lLLVMSupport -lLLVMDemangle"
+
+       # llvm-config --libs mcjit
+       llvm_old_jit="-lLLVMMCJIT -lLLVMExecutionEngine -lLLVMTarget -lLLVMAnalysis -lLLVMProfileData -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMBitstreamReader -lLLVMMC -lLLVMDebugInfoCodeView -lLLVMDebugInfoMSF -lLLVMCore -lLLVMRemarks -lLLVMBinaryFormat -lLLVMSupport -lLLVMDemangle"
+
+       # llvm-config --libs orcjit
+       llvm_new_jit="-lLLVMOrcJIT -lLLVMTransformUtils -lLLVMJITLink -lLLVMExecutionEngine -lLLVMTarget -lLLVMAnalysis -lLLVMProfileData -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMBitstreamReader -lLLVMMC -lLLVMDebugInfoCodeView -lLLVMDebugInfoMSF -lLLVMCore -lLLVMRemarks -lLLVMBinaryFormat -lLLVMSupport -lLLVMDemangle"
+
+       # Check codegen libs and add needed libraries.
+       case "$llvm_codegen_libs" in
+               *x86codegen*)
+                       # llvm-config --libs x86codegen
+                       llvm_extra="-lLLVMX86CodeGen -lLLVMGlobalISel -lLLVMX86Desc -lLLVMX86Utils -lLLVMX86Info -lLLVMMCDisassembler -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMDebugInfoDWARF -lLLVMCodeGen -lLLVMTarget -lLLVMScalarOpts -lLLVMInstCombine -lLLVMAggressiveInstCombine -lLLVMTransformUtils -lLLVMBitWriter -lLLVMAnalysis -lLLVMProfileData -lLLVMObject -lLLVMMCParser -lLLVMMC -lLLVMDebugInfoCodeView -lLLVMDebugInfoMSF -lLLVMBitReader -lLLVMBitstreamReader -lLLVMCore -lLLVMRemarks -lLLVMBinaryFormat -lLLVMSupport -lLLVMDemangle"
+                       ;;
+               *armcodegen*)
+                       # llvm-config --libs armcodegen
+                       llvm_extra="-lLLVMARMCodeGen -lLLVMGlobalISel -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMDebugInfoDWARF -lLLVMCodeGen -lLLVMTarget -lLLVMScalarOpts -lLLVMInstCombine -lLLVMAggressiveInstCombine -lLLVMTransformUtils -lLLVMBitWriter -lLLVMAnalysis -lLLVMProfileData -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMBitstreamReader -lLLVMCore -lLLVMRemarks -lLLVMARMDesc -lLLVMMCDisassembler -lLLVMMC -lLLVMDebugInfoCodeView -lLLVMDebugInfoMSF -lLLVMBinaryFormat -lLLVMARMUtils -lLLVMARMInfo -lLLVMSupport -lLLVMDemangle"
+                       ;;
+               *aarch64codegen*)
+                       # llvm-config --libs aarch64codegen
+                       llvm_extra="-lLLVMAArch64CodeGen -lLLVMGlobalISel -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMDebugInfoDWARF -lLLVMCodeGen -lLLVMTarget -lLLVMScalarOpts -lLLVMInstCombine -lLLVMAggressiveInstCombine -lLLVMTransformUtils -lLLVMBitWriter -lLLVMAnalysis -lLLVMProfileData -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMBitstreamReader -lLLVMCore -lLLVMRemarks -lLLVMAArch64Desc -lLLVMMC -lLLVMDebugInfoCodeView -lLLVMDebugInfoMSF -lLLVMBinaryFormat -lLLVMAArch64Utils -lLLVMAArch64Info -lLLVMSupport -lLLVMDemangle"
+                       ;;
+               *)
+                       llvm_extra=$llvm_codegen_libs
+       esac
+fi
+
 # When cross compiling for Windows on system not capable of running Windows binaries, llvm-config.exe can't be used to query for
 # LLVM parameters. In that scenario we will need to fallback to default values.
 if [[ $llvm_host_win32 = 1 ]] && [[ $use_llvm_config = 0 ]]; then
index 52227cc..3286a3b 100644 (file)
        <MonoLLVMToolsVersion Condition="'$(MonoLLVMHostOS)' == 'osx.10.12'">$(runtimeosx1012x64MicrosoftNETCoreRuntimeMonoLLVMToolsVersion)</MonoLLVMToolsVersion>
   </PropertyGroup>
 
+  <!-- On Linux, we need to treat the target arch as the host arch, i.e. treat arm64 Linux as a desktop platform -->
+  <PropertyGroup>
+      <MonoLLVMTargetArchitecture Condition="'$(MonoLLVMHostOS)' == 'linux' and '$(TargetArchitecture)' != 'wasm'">$(TargetArchitecture)</MonoLLVMTargetArchitecture>
+      <MonoLLVMTargetArchitecture Condition="'$(MonoLLVMHostOS)' != 'linux' or '$(TargetArchitecture)' == 'wasm'">$(HostArch)</MonoLLVMTargetArchitecture>
+  </PropertyGroup>
+
   <ItemGroup>
-    <PackageReference Include="runtime.$(MonoLLVMHostOS)-$(HostArch).Microsoft.NETCore.Runtime.Mono.LLVM.Sdk" Version="$(MonoLLVMSDKVersion)"/>
-    <PackageReference Include="runtime.$(MonoLLVMHostOS)-$(HostArch).Microsoft.NETCore.Runtime.Mono.LLVM.Tools" Version="$(MonoLLVMToolsVersion)"/>
+    <PackageReference Include="runtime.$(MonoLLVMHostOS)-$(MonoLLVMTargetArchitecture).Microsoft.NETCore.Runtime.Mono.LLVM.Sdk" Version="$(MonoLLVMSDKVersion)"/>
+    <PackageReference Include="runtime.$(MonoLLVMHostOS)-$(MonoLLVMTargetArchitecture).Microsoft.NETCore.Runtime.Mono.LLVM.Tools" Version="$(MonoLLVMToolsVersion)"/>
   </ItemGroup>
 
   <Target Name="CopyLLVMToTree" AfterTargets="Build">
     <ItemGroup>
-      <LLVMFiles Include="$(NuGetPackageRoot)\runtime.$(MonoLLVMHostOS)-$(HostArch).microsoft.netcore.runtime.mono.llvm.sdk\$(MonoLLVMSDKVersion)\tools\$(MonoLLVMHostOS)-$(HostArch)\**" />
-      <LLVMFiles Include="$(NuGetPackageRoot)\runtime.$(MonoLLVMHostOS)-$(HostArch).microsoft.netcore.runtime.mono.llvm.tools\$(MonoLLVMSDKVersion)\tools\$(MonoLLVMHostOS)-$(HostArch)\**" />
+      <LLVMFiles Include="$(NuGetPackageRoot)\runtime.$(MonoLLVMHostOS)-$(MonoLLVMTargetArchitecture).microsoft.netcore.runtime.mono.llvm.sdk\$(MonoLLVMSDKVersion)\tools\$(MonoLLVMHostOS)-$(MonoLLVMTargetArchitecture)\**" />
+      <LLVMFiles Include="$(NuGetPackageRoot)\runtime.$(MonoLLVMHostOS)-$(MonoLLVMTargetArchitecture).microsoft.netcore.runtime.mono.llvm.tools\$(MonoLLVMSDKVersion)\tools\$(MonoLLVMHostOS)-$(MonoLLVMTargetArchitecture)\**" />
     </ItemGroup>
 
     <Copy SourceFiles="@(LLVMFiles)" DestinationFolder="$(MonoLLVMDir)\%(RecursiveDir)">
index 4fef851..6a7027e 100644 (file)
       <_MonoCXXFLAGS Include="-g" />
     </ItemGroup>
 
-    <!-- We build LLVM bits for x64 without C++11 ABI -->
-    <ItemGroup Condition="'$(HostArch)' == 'x64' and '$(MonoEnableLLVM)' == 'true' and '$(MonoLLVMUseCxx11Abi)' != 'true'">
+    <!-- We build LLVM bits for x64 Linux without C++11 ABI (CentOS 7 has libstdc++ < 5.1) -->
+    <ItemGroup Condition="'$(TargetOS)' == 'Linux' and '$(MonoEnableLLVM)' == 'true' and '$(MonoLLVMUseCxx11Abi)' != 'true'">
       <_MonoCXXFLAGS Include="-D_GLIBCXX_USE_CXX11_ABI=0" />
     </ItemGroup>
 
+    <!-- We build LLVM bits for ARM64 Linux with C++11 ABI (Ubuntu 16.04 has libstdc++ > 5.1)-->
+    <ItemGroup Condition="'$(TargetOS)' == 'Linux' and '$(MonoEnableLLVM)' == 'true' and '$(MonoLLVMUseCxx11Abi)' == 'true'">
+      <_MonoCXXFLAGS Include="-D_GLIBCXX_USE_CXX11_ABI=1" />
+    </ItemGroup>
+
     <!-- tvOS device specific options -->
     <ItemGroup Condition="'$(TargetstvOS)' == 'true' and '$(TargetstvOSSimulator)' != 'true'">
       <_MonoConfigureParams Condition="'$(Platform)' == 'arm64'" Include="--host=aarch64-apple-darwin10" />