Skip to content

Commit

Permalink
Enable ARM64 builds in CI (dotnet#738)
Browse files Browse the repository at this point in the history
Also enable cross-building and publishing Windows ARM64-hosted objwriter.dll. Use Release build type with debug information enabled.
  • Loading branch information
AntonLapounov authored Mar 2, 2021
1 parent 848031f commit 6ea4413
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 128 deletions.
2 changes: 2 additions & 0 deletions eng/pipelines/runtimelab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ stages:
buildConfig: Release
platforms:
- Linux_x64
- Linux_arm64
- windows_x64
- windows_arm64
- OSX_x64
jobParameters:
isOfficialBuild: ${{ variables.isOfficialBuild }}
Expand Down
1 change: 1 addition & 0 deletions eng/pipelines/runtimelab/runtimelab-post-build-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ parameters:
uploadIntermediateArtifacts: false

steps:
- ${{ if ne(parameters.archType, 'arm64') }}:
# Build coreclr native test output
- ${{ if eq(parameters.osGroup, 'windows') }}:
- script: $(Build.SourcesDirectory)/src/tests/build$(scriptExt) nativeaot $(buildConfigUpper) ${{ parameters.archType }} /p:NativeAotMultimodule=true /p:SmokeTestsOnly=${{ parameters.smokeTestsOnly }}
Expand Down
34 changes: 7 additions & 27 deletions src/coreclr/nativeaot/Runtime/Full/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ if (CLR_CMAKE_TARGET_WIN32)
include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
preprocess_files(RUNTIME_SOURCES_ARCH_ASM ${RUNTIME_SOURCES_ARCH_ASM})
if (CMAKE_GENERATOR MATCHES "Visual Studio")
# Replaces .asm files in RUNTIME_SOURCES_ARCH_ASM with the corresponding .obj files
compile_asm(TARGET Runtime ASM_FILES ${RUNTIME_SOURCES_ARCH_ASM} OUTPUT_OBJECTS RUNTIME_SOURCES_ARCH_ASM)
endif()
endif()
Expand All @@ -25,7 +26,6 @@ add_library(Runtime.ServerGC STATIC ${COMMON_RUNTIME_SOURCES} ${FULL_RUNTIME_SOU

target_compile_definitions(Runtime.ServerGC PRIVATE -DFEATURE_SVR_GC)


# Get the current list of definitions
get_compile_definitions(DEFINITIONS)

Expand Down Expand Up @@ -57,35 +57,15 @@ add_custom_command(

set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/AsmOffsets.inc" PROPERTIES GENERATED TRUE)

# Runtime and Runtime.ServerGC share AsmOffsets.inc and assembler helpers (for Windows ARM/ARM64).
# Avoid a race condition by adding this target as a dependency for both libraries.
add_custom_target(
AsmOffsets
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/AsmOffsets.inc"
RuntimeAsmHelpers
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/AsmOffsets.inc" "${RUNTIME_SOURCES_ARCH_ASM}"
)

# The AsmOffsets.inc will be built as a dependency of the Runtime
add_dependencies(Runtime AsmOffsets)
add_dependencies(Runtime.ServerGC AsmOffsets)

# Extract the definitions for the ASM code. Since there is a bug in the cmake that prevents us from
# using the generator expressions, we split the definitions into lists based on the configuration.
foreach(DEFINITION IN LISTS COMPILE_DEFINITIONS_LIST)
if (${DEFINITION} MATCHES "^\\$<\\$<CONFIG:([^>]+)>:([^>]+)>$")
# The entry contains generator expression, so insert the definition into a definitions list
# corresponding to the config
string(TOUPPER ${CMAKE_MATCH_1} CONFIG)
set(ASM_DEFINITIONS_${CONFIG} ${ASM_DEFINITIONS_${CONFIG}} ${CMAKE_MATCH_2})
else()
list(APPEND ASM_DEFINITIONS ${DEFINITION})
endif()
endforeach()

# Add defines for the ASM. Unfortunately setting it on the target is ignored for asm by the cmake, so we have
# to set it on the sources.
set_property(SOURCE ${RUNTIME_SOURCES_ARCH_ASM} PROPERTY COMPILE_DEFINITIONS ${ASM_DEFINITIONS})
foreach(CONFIG IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER ${CONFIG} CONFIG)
set_property(SOURCE ${RUNTIME_SOURCES_ARCH_ASM} PROPERTY COMPILE_DEFINITIONS_${CONFIG} ${ASM_DEFINITIONS_${CONFIG}})
endforeach()
add_dependencies(Runtime RuntimeAsmHelpers)
add_dependencies(Runtime.ServerGC RuntimeAsmHelpers)

# Install the static Runtime library
install (TARGETS Runtime Runtime.ServerGC DESTINATION aotsdk)
Expand Down
24 changes: 11 additions & 13 deletions src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,33 @@
<PropertyGroup>
<ILCompilerVersion>6.0.0-preview.2.21122.4</ILCompilerVersion>

<ObjWriterArtifactPath Condition="'$(TargetsWindows)' == 'true'">$(ArtifactsDir)llvm\build\bin\RelWithDebInfo\$(LibPrefix)objwriter$(LibSuffix)</ObjWriterArtifactPath>
<ObjWriterArtifactPath Condition="'$(TargetsWindows)' != 'true'">$(ArtifactsDir)llvm\build\lib\$(LibPrefix)objwriter$(LibSuffix)</ObjWriterArtifactPath>
<ObjWriterArtifactPath Condition="'$(TargetsWindows)' == 'true'">$(ArtifactsDir)llvm\build\$(TargetArchitecture)\bin\Release\$(LibPrefix)objwriter$(LibSuffix)</ObjWriterArtifactPath>
<ObjWriterArtifactPath Condition="'$(TargetsWindows)' != 'true'">$(ArtifactsDir)llvm\build\$(TargetArchitecture)\lib\$(LibPrefix)objwriter$(LibSuffix)</ObjWriterArtifactPath>

<!-- CoreDisTools are used in debugging visualizers. -->
<IncludeCoreDisTools Condition="'$(Configuration)' != 'Release'">true</IncludeCoreDisTools>
</PropertyGroup>

<Import Project="$(RepositoryEngineeringDir)coredistools.targets" Condition="'$(DotNetBuildFromSource)' != 'true' and '$(IncludeCoreDisTools)' == 'true'" />

<ItemGroup Condition="'$(TargetArchitecture)' != 'arm64'">
<PackageReference Condition="!Exists('$(ObjWriterArtifactPath)')" Include="Microsoft.DotNet.ILCompiler">
<Version>$(ILCompilerVersion)</Version>
</PackageReference>
</ItemGroup>

<ItemGroup Condition="'$(TargetArchitecture)' != 'arm64'">
<Content Condition="Exists('$(ObjWriterArtifactPath)')" Include="$(ObjWriterArtifactPath)">
<ItemGroup Condition="Exists('$(ObjWriterArtifactPath)')">
<Content Include="$(ObjWriterArtifactPath)">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
<Pack>false</Pack>
</Content>
</ItemGroup>

<Content Condition="!Exists('$(ObjWriterArtifactPath)')"
Include="$(NuGetPackageRoot)runtime.$(ILCompilerRuntimeIdentifier).microsoft.dotnet.ilcompiler\$(ILCompilerVersion)\tools\$(LibPrefix)objwriter$(LibSuffix)">
<ItemGroup Condition="!Exists('$(ObjWriterArtifactPath)') and '$(TargetArchitecture)' != 'arm64'">
<PackageReference Include="Microsoft.DotNet.ILCompiler">
<Version>$(ILCompilerVersion)</Version>
</PackageReference>

<Content Include="$(NuGetPackageRoot)runtime.$(ILCompilerRuntimeIdentifier).microsoft.dotnet.ilcompiler\$(ILCompilerVersion)\tools\$(LibPrefix)objwriter$(LibSuffix)">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
<Pack>false</Pack>
</Content>

</ItemGroup>

<ItemGroup>
Expand Down
114 changes: 86 additions & 28 deletions src/coreclr/tools/aot/ObjWriter/build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,99 @@ setlocal
set "ScriptDir=%~dp0"
set "ArtifactsDir=%~1"
set "RepoRoot=%~2"
set "BuildType=%~3"
if "%BuildType%"=="" set "BuildType=RelWithDebInfo"
set "BuildArch=%~3"
set "TargetArch=%~4"
set "BuildType=%~5"
if "%BuildType%"=="" set "BuildType=Release"

:: Check that we have enough arguments
if "%TargetArch%"=="" (
echo Usage: %~nx0 ArtifactsDir RepoRoot BuildArch TargetArch [BuildType]
goto Error
)

cd "%ArtifactsDir%" || goto Error

:: Clone the LLVM repo
pushd "%ArtifactsDir%" || exit /b 1
if not exist llvm (
git clone --depth 1 -b release_50 https://github.com/llvm-mirror/llvm.git || exit /b 1
rem Clone the LLVM repo
git clone --depth 1 -b release_50 https://github.com/llvm-mirror/llvm.git || goto Error
cd llvm || goto Error
goto ApplyPatch
)

:: Check whether the current diff is the same as the patch
cd llvm || goto Error
if not exist build mkdir build
set "DiffFile=build\llvm_%RANDOM%.patch"
git diff --full-index >"%DiffFile%" || goto Error
fc "%DiffFile%" "%ScriptDir%llvm.patch"
if %ErrorLevel% == 0 (
rem The current diff is the same as the patch
del "%DiffFile%"
goto PatchApplied
) else (
echo LLVM changes are saved to %CD%/%DiffFile% and overwritten with %ScriptDir%llvm.patch
)

:ApplyPatch

:: Clean the tree and apply the patch
cd llvm && git restore . || exit /b 1
git apply "%ScriptDir%llvm.patch" || exit /b 1
git restore . || goto Error
git apply "%ScriptDir%llvm.patch" || goto Error

:PatchApplied

:: Set CMakePath by evaluating the output from set-cmake-path.ps1
call "%RepoRoot%src\coreclr\setup_vs_tools.cmd" || exit /b 1
call "%RepoRoot%src\coreclr\setup_vs_tools.cmd" || goto Error
for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "& ""%RepoRoot%eng\native\set-cmake-path.ps1"""') do %%a
echo Using CMake at "%CMakePath%"

:: Configure and build
if not exist build mkdir build
cd build || exit /b 1

"%CMakePath%" ../ ^
-DCMAKE_BUILD_TYPE=%BuildType% ^
-DCMAKE_INSTALL_PREFIX=install ^
-DLLVM_BUILD_TOOLS=0 ^
-DLLVM_ENABLE_TERMINFO=0 ^
-DLLVM_INCLUDE_UTILS=0 ^
-DLLVM_INCLUDE_RUNTIMES=0 ^
-DLLVM_INCLUDE_EXAMPLES=0 ^
-DLLVM_INCLUDE_TESTS=0 ^
-DLLVM_INCLUDE_DOCS=0 ^
-DLLVM_TARGETS_TO_BUILD="AArch64;ARM;X86" ^
-DLLVM_EXTERNAL_OBJWRITER_SOURCE_DIR="%ScriptDir%\" ^
-DCORECLR_INCLUDE_DIR="%RepoRoot%src\coreclr\inc" ^
|| exit /b 1

"%CMakePath%" --build . --config %BuildType% --target objwriter -j 10 || exit /b 1
:: Configure and build objwriter
if /i "%BuildArch%"=="%TargetArch%" (
call :BuildLlvmTarget objwriter "%TargetArch%" || goto Error
exit /b 0
)

rem Cross-build: first build llvm-tblgen.exe for the build architecture
set "TableGen=%CD%\build\%BuildArch%\%BuildType%\bin\llvm-tblgen.exe"

if not exist "%TableGen%" (
echo Building llvm-tablegen.exe
call :BuildLlvmTarget llvm-tblgen "%BuildArch%" || goto Error
if not exist "%TableGen%" goto Error
)

rem Now use llvm-tblgen.exe to build objwriter for the target architecture
set "CMakeArch=%TargetArch%"
if /i "%TargetArch%"=="x86" set "CMakeArch=Win32"

call :BuildLlvmTarget objwriter "%TargetArch%" "-A %CMakeArch% -DLLVM_TABLEGEN=%TableGen%" || goto Error
exit /b 0

:BuildLlvmTarget
set "Target=%~1"
set "Arch=%~2"
set "ExtraCMakeArgs=%~3"

"%CMakePath%" -S . -B "build\%Arch%" ^
%ExtraCMakeArgs% ^
-DCMAKE_TOOLCHAIN_FILE="%ScriptDir%toolchain.cmake" ^
-DCMAKE_BUILD_TYPE=%BuildType% ^
-DCMAKE_INSTALL_PREFIX=install ^
-DLLVM_BUILD_TOOLS=0 ^
-DLLVM_ENABLE_TERMINFO=0 ^
-DLLVM_INCLUDE_UTILS=0 ^
-DLLVM_INCLUDE_RUNTIMES=0 ^
-DLLVM_INCLUDE_EXAMPLES=0 ^
-DLLVM_INCLUDE_TESTS=0 ^
-DLLVM_INCLUDE_DOCS=0 ^
-DLLVM_TARGETS_TO_BUILD="AArch64;ARM;X86" ^
-DLLVM_EXTERNAL_OBJWRITER_SOURCE_DIR="%ScriptDir%\" ^
-DCORECLR_INCLUDE_DIR="%RepoRoot%src\coreclr\inc" ^
|| goto Error

"%CMakePath%" --build "build\%Arch%" --config %BuildType% --target %Target% -j 10 || goto Error
exit /b 0

:Error
exit /b 1
86 changes: 60 additions & 26 deletions src/coreclr/tools/aot/ObjWriter/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,69 @@
ScriptDir="$(cd "$(dirname "$0")"; pwd -P)"
ArtifactsDir="$1"
RepoRoot="$2"
BuildType="${3:-Release}"
BuildArch="$3"
TargetArch="$4"
BuildType="${5:-Release}"

# Check that we have enough arguments
if [ $# -lt 4 ]; then
echo "Usage: $(basename $0) ArtifactsDir RepoRoot BuildArch TargetArch [BuildType]"
exit 1
fi

if [ "$TargetArch" != "$BuildArch" ]; then
echo "Error: Cross-building of objwriter is not supported"
exit 1
fi

cd "$ArtifactsDir" || exit 1
PatchApplied=0

# Clone the LLVM repo
pushd "$ArtifactsDir" || exit 1
if [ ! -d llvm ]; then
git clone --depth 1 -b release_50 https://github.com/llvm-mirror/llvm.git || exit 1
# Clone the LLVM repo
git clone --depth 1 -b release_50 https://github.com/llvm-mirror/llvm.git || exit 1
cd llvm || exit 1
else
# Check whether the current diff is the same as the patch
cd llvm || exit 1
mkdir -p build
DiffFile="build/llvm_$RANDOM.patch"
git diff --full-index >"$DiffFile" || exit 1
cmp -s "$DiffFile" "$ScriptDir/llvm.patch"
if [ $? -eq 0 ]; then
# The current diff is the same as the patch
rm "$DiffFile"
PatchApplied=1
else
echo "LLVM changes are saved to $PWD/$DiffFile and overwritten with $ScriptDir/llvm.patch"
fi
fi

if [ "$PatchApplied" -ne 1 ]; then
# Clean the tree and apply the patch
git checkout -- . || exit 1
git apply "$ScriptDir/llvm.patch" || exit 1
fi

# Clean the tree and apply the patch
cd llvm && git checkout -- . || exit 1
git apply "$ScriptDir/llvm.patch" || exit 1

# Configure and build
[ -d build ] || mkdir build
cd build || exit 1

cmake ../ \
-DCMAKE_BUILD_TYPE="$BuildType" \
-DCMAKE_INSTALL_PREFIX=install \
-DLLVM_BUILD_TOOLS=0 \
-DLLVM_ENABLE_TERMINFO=0 \
-DLLVM_INCLUDE_UTILS=0 \
-DLLVM_INCLUDE_RUNTIMES=0 \
-DLLVM_INCLUDE_EXAMPLES=0 \
-DLLVM_INCLUDE_TESTS=0 \
-DLLVM_INCLUDE_DOCS=0 \
-DLLVM_TARGETS_TO_BUILD="AArch64;ARM;X86" \
-DLLVM_EXTERNAL_OBJWRITER_SOURCE_DIR="$ScriptDir" \
-DCORECLR_INCLUDE_DIR="${RepoRoot}src/coreclr/inc" \
|| exit 1
# Configure and build objwriter
mkdir -p "build/$TargetArch"
cd "build/$TargetArch" || exit 1

# Do not use the -S and -B options to support older CMake versions
cmake ../../ \
-DCMAKE_TOOLCHAIN_FILE="$ScriptDir/toolchain.cmake" \
-DCMAKE_BUILD_TYPE="$BuildType" \
-DCMAKE_INSTALL_PREFIX=install \
-DLLVM_BUILD_TOOLS=0 \
-DLLVM_ENABLE_TERMINFO=0 \
-DLLVM_INCLUDE_UTILS=0 \
-DLLVM_INCLUDE_RUNTIMES=0 \
-DLLVM_INCLUDE_EXAMPLES=0 \
-DLLVM_INCLUDE_TESTS=0 \
-DLLVM_INCLUDE_DOCS=0 \
-DLLVM_TARGETS_TO_BUILD="AArch64;ARM;X86" \
-DLLVM_EXTERNAL_OBJWRITER_SOURCE_DIR="$ScriptDir" \
-DCORECLR_INCLUDE_DIR="${RepoRoot}src/coreclr/inc" \
|| exit 1

cmake --build . --config "$BuildType" --target objwriter -j 10 || exit 1
Loading

0 comments on commit 6ea4413

Please sign in to comment.