diff --git a/.config/tsaoptions.json b/.config/tsaoptions.json new file mode 100644 index 0000000000000..179942118a9ea --- /dev/null +++ b/.config/tsaoptions.json @@ -0,0 +1,10 @@ +{ + "instanceUrl": "https://devdiv.visualstudio.com/", + "template": "TFSDEVDIV", + "projectName": "DEVDIV", + "areaPath": "DevDiv\\mono", + "iterationPath": "DevDiv", + "notificationAliases": [ "runtimerepo-infra@microsoft.com" ], + "repositoryName": "llvm-project", + "codebaseName": "llvm-project" +} \ No newline at end of file diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a3d33bdb4d438..0000000000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,5 +0,0 @@ -# **DO NOT FILE A PULL REQUEST** - -This repository does not accept pull requests. Please follow http://llvm.org/docs/Contributing.html#how-to-submit-a-patch for contribution to LLVM. - -# **DO NOT FILE A PULL REQUEST** diff --git a/.gitignore b/.gitignore index b33fbbf932379..d032e90fc4679 100644 --- a/.gitignore +++ b/.gitignore @@ -24,9 +24,6 @@ # Ignore the user specified CMake presets in subproject directories. /*/CMakeUserPresets.json -# Nested build directory -/build* - #==============================================================================# # Explicit files to ignore (only matches one). #==============================================================================# @@ -68,3 +65,7 @@ pythonenv* /clang/utils/analyzer/projects/*/RefScanBuildResults # automodapi puts generated documentation files here. /lldb/docs/python_api/ + +/artifacts +/.dotnet +/.packages diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000000000..3014b766801b9 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,5 @@ + + + + + diff --git a/Directory.Build.targets b/Directory.Build.targets new file mode 100644 index 0000000000000..177d64c47ad11 --- /dev/null +++ b/Directory.Build.targets @@ -0,0 +1,4 @@ + + + + diff --git a/NuGet.config b/NuGet.config new file mode 100644 index 0000000000000..6082e261d277e --- /dev/null +++ b/NuGet.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + diff --git a/bolt/utils/docker/Dockerfile b/bolt/utils/docker/Dockerfile deleted file mode 100644 index 722a07e46f9e4..0000000000000 --- a/bolt/utils/docker/Dockerfile +++ /dev/null @@ -1,31 +0,0 @@ -FROM ubuntu:20.04 AS builder - -ARG DEBIAN_FRONTEND=noninteractive -ENV TZ=UTC - -RUN apt-get update && \ - apt-get install -y --no-install-recommends ca-certificates git \ - build-essential cmake ninja-build python3 libjemalloc-dev \ - python3-psutil && \ - rm -rf /var/lib/apt/lists - -WORKDIR /home/bolt - -RUN git clone --depth 1 https://github.com/llvm/llvm-project - -RUN mkdir build && \ - cd build && \ - cmake -G Ninja ../llvm-project/llvm \ - -DLLVM_ENABLE_PROJECTS="bolt;clang;lld" \ - -DLLVM_TARGETS_TO_BUILD="X86;AArch64" \ - -DCMAKE_BUILD_TYPE=Release \ - -DLLVM_ENABLE_ASSERTIONS=ON \ - -DCMAKE_EXE_LINKER_FLAGS="-Wl,--push-state -Wl,-whole-archive -ljemalloc_pic -Wl,--pop-state -lpthread -lstdc++ -lm -ldl" \ - -DCMAKE_INSTALL_PREFIX=/home/bolt/install && \ - ninja check-bolt && \ - ninja install-llvm-bolt install-perf2bolt install-merge-fdata \ - install-llvm-boltdiff install-bolt_rt - -FROM ubuntu:20.04 - -COPY --from=builder /home/bolt/install /usr/local diff --git a/build.cmd b/build.cmd new file mode 100644 index 0000000000000..1ba69afd9cc77 --- /dev/null +++ b/build.cmd @@ -0,0 +1,8 @@ +@echo off +setlocal + +set _args=%* +if "%~1"=="-?" set _args=-help + +powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0eng\build.ps1" %_args% +exit /b %ERRORLEVEL% diff --git a/build.sh b/build.sh new file mode 100755 index 0000000000000..da2ba1a158ec1 --- /dev/null +++ b/build.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +source="${BASH_SOURCE[0]}" + +function is_cygwin_or_mingw() +{ + case $(uname -s) in + CYGWIN*) return 0;; + MINGW*) return 0;; + *) return 1;; + esac +} + +# resolve $SOURCE until the file is no longer a symlink +while [[ -h $source ]]; do + scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + source="$(readlink "$source")" + + # if $source was a relative symlink, we need to resolve it relative to the path where the + # symlink file was located + [[ $source != /* ]] && source="$scriptroot/$source" +done + +scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + +if is_cygwin_or_mingw; then + # if bash shell running on Windows (not WSL), + # pass control to powershell build script. + scriptroot=$(cygpath -d "$scriptroot") + powershell -c "$scriptroot\\build.cmd" $@ +else + "$scriptroot/eng/build.sh" $@ +fi diff --git a/clang/tools/clang-fuzzer/Dockerfile b/clang/tools/clang-fuzzer/Dockerfile deleted file mode 100644 index 1ddf82954e219..0000000000000 --- a/clang/tools/clang-fuzzer/Dockerfile +++ /dev/null @@ -1,41 +0,0 @@ -#===- llvm/tools/clang/tools/clang-fuzzer ---------------------------------===// -# -# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# -#===----------------------------------------------------------------------===// -# Produces an image that builds clang-proto-fuzzer -FROM ubuntu:16.04 -RUN apt-get update -y -RUN apt-get install -y autoconf automake libtool curl make g++ unzip wget git \ - binutils liblzma-dev libz-dev python-all cmake ninja-build subversion \ - pkg-config docbook2x - -WORKDIR /root - -# Get protobuf -RUN wget -qO- https://github.com/google/protobuf/releases/download/v3.3.0/protobuf-cpp-3.3.0.tar.gz | tar zxf - -RUN cd protobuf-3.3.0 && ./autogen.sh && ./configure && make -j $(nproc) && make check -j $(nproc) && make install && ldconfig -# Get LLVM -RUN svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm -RUN cd llvm/tools && svn co http://llvm.org/svn/llvm-project/cfe/trunk clang -r $(cd ../ && svn info | grep Revision | awk '{print $2}') -RUN cd llvm/projects && svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt -r $(cd ../ && svn info | grep Revision | awk '{print $2}') -# Build plain LLVM (stage 0) -RUN mkdir build0 && cd build0 && cmake -GNinja -DCMAKE_BUILD_TYPE=Release ../llvm && ninja -# Configure instrumented LLVM (stage 1) -RUN mkdir build1 && cd build1 && cmake -GNinja -DCMAKE_BUILD_TYPE=Release ../llvm \ - -DLLVM_ENABLE_ASSERTIONS=ON \ - -DCMAKE_C_COMPILER=`pwd`/../build0/bin/clang \ - -DCMAKE_CXX_COMPILER=`pwd`/../build0/bin/clang++ \ - -DLLVM_USE_SANITIZE_COVERAGE=YES \ - -DLLVM_USE_SANITIZER=Address -DCLANG_ENABLE_PROTO_FUZZER=ON -# Build the fuzzers -RUN cd build1 && ninja clang-fuzzer -RUN cd build1 && ninja clang-objc-fuzzer -RUN cd build1 && ninja clang-proto-fuzzer -RUN cd build1 && ninja clang-proto-to-cxx -RUN cd build1 && ninja clang-loop-proto-to-cxx -RUN cd build1 && ninja clang-loop-proto-to-llvm -RUN cd build1 && ninja clang-loop-proto-fuzzer -RUN cd build1 && ninja clang-llvm-proto-fuzzer diff --git a/clang/utils/analyzer/Dockerfile b/clang/utils/analyzer/Dockerfile deleted file mode 100644 index bb1dd60eeb9b8..0000000000000 --- a/clang/utils/analyzer/Dockerfile +++ /dev/null @@ -1,70 +0,0 @@ -FROM ubuntu:bionic - -RUN apt-get update && apt-get install -y \ - apt-transport-https \ - ca-certificates \ - gnupg \ - software-properties-common \ - wget - -# newer CMake is required by LLVM -RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null -RUN apt-add-repository -y 'deb https://apt.kitware.com/ubuntu/ bionic main' - -# test system dependencies -RUN apt-get update && apt-get install -y \ - git=1:2.17.1* \ - gettext=0.19.8.1* \ - python3=3.6.7-1~18.04 \ - python3-pip=9.0.1-2.3* \ - cmake=3.20.5* \ - ninja-build=1.8.2-1 - -# box2d dependencies -RUN apt-get install -y \ - libx11-dev=2:1.6.4-3* \ - libxrandr-dev=2:1.5.1-1 \ - libxinerama-dev=2:1.1.3-1 \ - libxcursor-dev=1:1.1.15-1 \ - libxi-dev=2:1.7.9-1 - -# symengine dependencies -RUN apt-get install -y \ - libgmp10=2:6.1.2+dfsg-2 \ - libgmp-dev=2:6.1.2+dfsg-2 - -# simbody dependencies -RUN apt-get install -y \ - liblapack-dev=3.7.1-4* - -# drogon dependencies -RUN apt-get install -y \ - libjsonrpccpp-dev=0.7.0-1* \ - uuid-dev=2.31.1-0.4* - -# tmux dependencies -RUN apt-get install -y \ - autotools-dev=20180224.1 \ - automake=1:1.15.1-3* \ - libncurses5-dev=6.1-1* \ - libevent-dev=2.1.8* \ - pkg-config=0.29.1-0* \ - flex=2.6.4-6 \ - bison=2:3.0.4.* - -RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1 - -VOLUME /analyzer -VOLUME /projects -VOLUME /llvm-project -VOLUME /build -VOLUME /scripts - -ENV PATH="/analyzer/bin:${PATH}" - -ADD entrypoint.py /entrypoint.py - -ADD requirements.txt /requirements.txt -RUN pip3 install -r /requirements.txt - -ENTRYPOINT ["python", "/entrypoint.py"] diff --git a/dir.common.props b/dir.common.props new file mode 100644 index 0000000000000..16a9c0c363235 --- /dev/null +++ b/dir.common.props @@ -0,0 +1,80 @@ + + + + + $(__BuildArch) + x64 + x64 + + $(__BuildType) + Debug + Debug + Release + Checked + + $(__BuildOS) + Windows_NT + Linux + OSX + + + <__BuildOS>$(BuildOS) + <__BuildArch>$(BuildArch) + + $(BuildType) + $(BuildArch) + + $(BuildOS).$(BuildArch).$(BuildType) + + + + + + + <__ProjectDir Condition="'$(__ProjectDir)'==''">$(MSBuildThisFileDirectory) + $(__ProjectDir)\ + $(ProjectDir)\..\..\ + $(MSBuildThisFileDirectory) + + $(RootRepoDir)artifacts\obj\llvm\$(MSBuildProjectName)\ + + $(__SourceDir)\ + $(ProjectDir)src\ + + $(__RootBinDir)\ + $(RootRepoDir)artifacts\ + + $(__BinDir)\ + $(RootBinDir)bin\llvm\$(PlatformConfigPathPart)\ + + <_LLVMSourceDir Condition="'$(_LLVMSourceDir)'==''">$(MSBuildThisFileDirectory)/llvm + <_LLVMBuildDir Condition="'$(_LLVMBuildDir)'==''">$(MSBuildThisFileDirectory)/artifacts/obj/BuildRoot-$(TargetArchitecture) + <_LLVMInstallDir Condition="'$(_LLVMInstallDir)'==''">$(MSBuildThisFileDirectory)/artifacts/obj/InstallRoot-$(TargetArchitecture) + + + + + + 1.0.0 + $([System.IO.File]::ReadAllText('$(_LLVMBuildDir)\version.txt')) + + + false + $(PackageVersion) + + preview8 + + + + + true + true + true + true + true + + true + + + + diff --git a/eng/Build.props b/eng/Build.props new file mode 100644 index 0000000000000..a884f3c0863de --- /dev/null +++ b/eng/Build.props @@ -0,0 +1,6 @@ + + + + + + diff --git a/eng/Publishing.props b/eng/Publishing.props new file mode 100644 index 0000000000000..10bc8c8684de3 --- /dev/null +++ b/eng/Publishing.props @@ -0,0 +1,6 @@ + + + + 3 + + diff --git a/eng/Tools.props b/eng/Tools.props new file mode 100644 index 0000000000000..112543dc80edb --- /dev/null +++ b/eng/Tools.props @@ -0,0 +1,11 @@ + + + false + + + + + + + + diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml new file mode 100644 index 0000000000000..a21d57e1e56c4 --- /dev/null +++ b/eng/Version.Details.xml @@ -0,0 +1,19 @@ + + + + + + + https://github.com/dotnet/arcade + 38d3196e1596eb525367ec8d65fcc1f30a58261c + + + https://github.com/dotnet/arcade + 38d3196e1596eb525367ec8d65fcc1f30a58261c + + + https://github.com/dotnet/arcade + 38d3196e1596eb525367ec8d65fcc1f30a58261c + + + diff --git a/eng/Versions.props b/eng/Versions.props new file mode 100644 index 0000000000000..6d51d7ef46eae --- /dev/null +++ b/eng/Versions.props @@ -0,0 +1,11 @@ + + + + 1.0.0 + alpha + 1 + + + 8.0.0-beta.23118.1 + + diff --git a/eng/azure-pipelines-codeql.yml b/eng/azure-pipelines-codeql.yml new file mode 100644 index 0000000000000..8ad59f7c160f1 --- /dev/null +++ b/eng/azure-pipelines-codeql.yml @@ -0,0 +1,102 @@ +trigger: + none + +schedules: + - cron: 0 12 * * 1 + displayName: Weekly Monday CodeQL/Semmle run + branches: + include: + - dotnet/main + - objwriter/12.x + always: true + +variables: + - template: /eng/common-variables.yml + - name: Codeql.Enabled + value: True + - name: Codeql.Cadence + value: 0 + - name: Codeql.TSAEnabled + value: True + - name: Codeql.BuildIdentifier + value: $(System.JobDisplayName) + +stages: +- stage: Build + jobs: + - template: /eng/common/templates/jobs/jobs.yml + parameters: + jobs: + + ############ LINUX BUILD ############ + - job: Build_Linux + displayName: Linux + timeoutInMinutes: 480 + variables: + - _BuildConfig: Release + strategy: + matrix: + x64: + imagename: mcr.microsoft.com/dotnet-buildtools/prereqs:centos-7-20220716123527-d0bc8ed + archflag: --arch x64 + Devtoolset7Arg: /p:ForceDevtoolset7=true + pool: + ${{ if eq(variables['System.TeamProject'], 'public') }}: + vmImage: ubuntu-20.04 + ${{ if eq(variables['System.TeamProject'], 'internal') }}: + name: NetCore1ESPool-Internal + demands: ImageOverride -equals Build.Ubuntu.1804.Amd64 + container: + image: $(imagename) + steps: + - bash: | + set -ex + git clean -ffdx + git reset --hard HEAD + displayName: 'Clean up working directory' + + - task: CodeQL3000Init@0 + displayName: Initialize CodeQL (manually-injected) + + - bash: | + ./build.sh --ci --restore --build $(archflag) --configuration $(_BuildConfig) $(_InternalBuildArgs) $(Devtoolset7Arg) + displayName: 'Build' + + - task: CodeQL3000Finalize@0 + displayName: Finalize CodeQL (manually-injected) + + ############ WINDOWS BUILD ############ + - job: Build_Windows + displayName: Windows + timeoutInMinutes: 600 + strategy: + matrix: + # Release + x64_release: + _BuildConfig: Release + archflag: -arch x64 + pool: + ${{ if eq(variables['System.TeamProject'], 'public') }}: + name: NetCore-Public + demands: ImageOverride -equals windows.vs2022.amd64.open + ${{ if eq(variables['System.TeamProject'], 'internal') }}: + name: NetCore1ESPool-Internal + demands: ImageOverride -equals windows.vs2022.amd64 + steps: + - checkout: self + clean: true + fetchDepth: 2 + + - script: | + git clean -ffdx + git reset --hard HEAD + displayName: 'Clean up working directory' + + - task: CodeQL3000Init@0 + displayName: Initialize CodeQL (manually-injected) + + - powershell: eng\build.ps1 -ci -restore -build $(archflag) -configuration $(_BuildConfig) $(_InternalBuildArgs) + displayName: 'Build' + + - task: CodeQL3000Finalize@0 + displayName: Finalize CodeQL (manually-injected) diff --git a/eng/azure-pipelines.yml b/eng/azure-pipelines.yml new file mode 100644 index 0000000000000..e28e2678aebd4 --- /dev/null +++ b/eng/azure-pipelines.yml @@ -0,0 +1,291 @@ +trigger: + batch: true + branches: + include: + - dotnet/main + - dotnet/release/* + +pr: + branches: + include: + - dotnet/main + - dotnet/release/* + +variables: +- template: /eng/common-variables.yml +- template: /eng/common/templates/variables/pool-providers.yml + +stages: +- stage: build + displayName: Build + jobs: + - template: /eng/common/templates/jobs/jobs.yml + parameters: + enablePublishBuildArtifacts: true + enablePublishBuildAssets: true + enablePublishUsingPipelines: true + jobs: + + ############ LINUX BUILD ############ + - job: Build_Linux + displayName: Linux + timeoutInMinutes: 210 + variables: + - _BuildConfig: Release + strategy: + matrix: + x64: + assetManifestOS: linux + assetManifestPlatform: x64 + imagename: mcr.microsoft.com/dotnet-buildtools/prereqs:centos-7 + rootfs: + ClangTargetArg: + archflag: --arch x64 + LLVMTableGenArg: + ClangTableGenArg: + Devtoolset7Arg: /p:ForceDevtoolset7=true + ClangVersionArg: /p:ClangVersion=clang-9 /p:ClangPlusVersion=clang++-9 + arm64: + assetManifestOS: linux + assetManifestPlatform: arm64 + imagename: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-16.04-cross-arm64-cfdd435-20200121150126 + rootfs: /crossrootfs/arm64 + ClangTargetArg: /p:ClangTarget=aarch64-linux-gnu + archflag: --arch arm64 + LLVMTableGenArg: /p:LLVMTableGenPath=$(Build.SourcesDirectory)/artifacts/obj/BuildRoot-x64/bin/llvm-tblgen + ClangTableGenArg: /p:ClangTableGenPath=$(Build.SourcesDirectory)/artifacts/obj/BuildRoot-x64/bin/clang-tblgen + Devtoolset7Arg: + ClangVersionArg: /p:ClangVersion=clang-9 /p:ClangPlusVersion=clang++-9 + arm: + assetManifestOS: linux + assetManifestPlatform: arm + imagename: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-16.04-cross-09ec757-20200320131433 + rootfs: /crossrootfs/arm + ClangTargetArg: /p:ClangTarget=arm-linux-gnueabihf + archflag: --arch arm + LLVMTableGenArg: /p:LLVMTableGenPath=$(Build.SourcesDirectory)/artifacts/obj/BuildRoot-x64/bin/llvm-tblgen + ClangTableGenArg: /p:ClangTableGenPath=$(Build.SourcesDirectory)/artifacts/obj/BuildRoot-x64/bin/clang-tblgen + Devtoolset7Arg: + ClangVersionArg: /p:ClangVersion=clang-9 /p:ClangPlusVersion=clang++-9 + pool: + ${{ if eq(variables['System.TeamProject'], 'public') }}: + name: $(DncEngPublicBuildPool) + demands: ImageOverride -equals build.ubuntu.2204.amd64.open + ${{ if eq(variables['System.TeamProject'], 'internal') }}: + name: $(DncEngInternalBuildPool) + demands: ImageOverride -equals build.ubuntu.2204.amd64 + container: + image: $(imagename) + steps: + - bash: | + set -ex + git clean -ffdx + git reset --hard HEAD + displayName: 'Clean up working directory' + + - bash: | + ./build.sh --ci --restore --build --arch x64 -configuration $(_BuildConfig) $(_InternalBuildArgs) /p:BuildLLVMTableGenOnly=true $(ClangVersionArg) + displayName: 'Build host llvm-tblgen for cross-compiling' + condition: and(succeeded(), ne(variables['assetManifestPlatform'], 'x64')) + + - bash: | + ./build.sh --ci --restore --build --pack $(archflag) --configuration $(_BuildConfig) $(_InternalBuildArgs) $(LLVMTableGenArg) $(ClangTableGenArg) $(Devtoolset7Arg) $(ClangVersionArg) $(ClangTargetArg) + displayName: 'Build and package' + env: + ROOTFS_DIR: $(rootfs) + + - bash: | + ./eng/common/build.sh --ci --restore --publish --configuration $(_BuildConfig) $(_InternalBuildArgs) /p:AssetManifestOS=$(assetManifestOS) /p:PlatformName=$(assetManifestPlatform) $(ClangVersionArg) --projects $(Build.SourcesDirectory)/llvm.proj + displayName: Publish packages + condition: and(succeeded(), ne(variables['System.TeamProject'], 'public'), ne(variables['Build.Reason'], 'PullRequest')) + + ############ LINUX MUSL BUILD ############ + - job: Build_Linux_musl + displayName: Linux_musl + timeoutInMinutes: 210 + variables: + - _BuildConfig: Release + strategy: + matrix: + x64: + assetManifestOS: linux-musl + assetManifestPlatform: x64 + imagename: mcr.microsoft.com/dotnet-buildtools/prereqs:alpine-3.13-WithNode + rootfs: + ClangTargetArg: + archflag: --arch x64 + LLVMTableGenArg: + ClangTableGenArg: + ClangVersionArg: /p:ClangVersion=clang-9 /p:ClangPlusVersion=clang++-9 + arm64: + assetManifestOS: linux-musl + assetManifestPlatform: arm64 + imagename: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-22.04-cross-arm64-alpine + rootfs: /crossrootfs/arm64 + ClangTargetArg: /p:ClangTarget=aarch64-alpine-linux-musl + archflag: --arch arm64 + LLVMTableGenArg: /p:LLVMTableGenPath=$(Build.SourcesDirectory)/artifacts/obj/BuildRoot-x64/bin/llvm-tblgen + ClangTableGenArg: /p:ClangTableGenPath=$(Build.SourcesDirectory)/artifacts/obj/BuildRoot-x64/bin/clang-tblgen + ClangVersionArg: /p:ClangVersion=clang-15 /p:ClangPlusVersion=clang++-15 + pool: + ${{ if eq(variables['System.TeamProject'], 'public') }}: + name: $(DncEngPublicBuildPool) + demands: ImageOverride -equals build.ubuntu.2204.amd64.open + ${{ if eq(variables['System.TeamProject'], 'internal') }}: + name: $(DncEngInternalBuildPool) + demands: ImageOverride -equals build.ubuntu.2204.amd64 + container: + image: $(imagename) + steps: + - bash: | + set -ex + git clean -ffdx + git reset --hard HEAD + displayName: 'Clean up working directory' + + - bash: | + ./build.sh --ci --restore --build --arch x64 -configuration $(_BuildConfig) $(_InternalBuildArgs) /p:BuildLLVMTableGenOnly=true $(ClangVersionArg) + displayName: 'Build host llvm-tblgen for cross-compiling' + condition: and(succeeded(), ne(variables['assetManifestPlatform'], 'x64')) + + - bash: | + ./build.sh --ci --restore --build --pack $(archflag) --configuration $(_BuildConfig) $(_InternalBuildArgs) $(LLVMTableGenArg) $(ClangTableGenArg) /p:OutputRid=linux-musl-$(assetManifestPlatform) $(ClangVersionArg) $(ClangTargetArg) + displayName: 'Build and package' + env: + ROOTFS_DIR: $(rootfs) + + - bash: | + ./eng/common/build.sh --ci --restore --publish --configuration $(_BuildConfig) $(_InternalBuildArgs) /p:AssetManifestOS=$(assetManifestOS) /p:PlatformName=$(assetManifestPlatform) $(ClangVersionArg) --projects $(Build.SourcesDirectory)/llvm.proj + displayName: Publish packages + condition: and(succeeded(), ne(variables['System.TeamProject'], 'public'), ne(variables['Build.Reason'], 'PullRequest')) + + ############ MACOS BUILD ############ + - job: Build_macOS + displayName: macOS + timeoutInMinutes: 210 + variables: + - _BuildConfig: Release + strategy: + matrix: + x64: + assetManifestOS: osx + assetManifestPlatform: x64 + archflag: --arch x64 + LLVMTableGenArg: + ClangTableGenArg: + arm64: + assetManifestOS: osx + assetManifestPlatform: arm64 + archflag: --arch arm64 + LLVMTableGenArg: /p:LLVMTableGenPath=$(Build.SourcesDirectory)/artifacts/obj/BuildRoot-x64/bin/llvm-tblgen + ClangTableGenArg: /p:ClangTableGenPath=$(Build.SourcesDirectory)/artifacts/obj/BuildRoot-x64/bin/clang-tblgen + pool: + vmImage: macos-11 + steps: + - bash: | + set -ex + git clean -ffdx + git reset --hard HEAD + displayName: 'Clean up working directory' + + - bash: | + ./build.sh --ci --restore --build --arch x64 -configuration $(_BuildConfig) $(_InternalBuildArgs) /p:BuildLLVMTableGenOnly=true + displayName: 'Build host llvm-tblgen for cross-compiling' + condition: and(succeeded(), ne(variables['assetManifestPlatform'], 'x64')) + + - bash: | + ./build.sh --ci --restore --build --pack $(archflag) --configuration $(_BuildConfig) $(_InternalBuildArgs) $(LLVMTableGenArg) $(ClangTableGenArg) + displayName: 'Build and package' + + - bash: + ./eng/common/build.sh --ci --restore --publish --configuration $(_BuildConfig) $(_InternalBuildArgs) /p:AssetManifestOS=$(assetManifestOS) /p:PlatformName=$(assetManifestPlatform) --projects $(Build.SourcesDirectory)/llvm.proj + displayName: Publish packages + condition: and(succeeded(), ne(variables['System.TeamProject'], 'public'), ne(variables['Build.Reason'], 'PullRequest')) + + ############ WINDOWS BUILD ############ + - job: Build_Windows + displayName: Windows + timeoutInMinutes: 210 + strategy: + matrix: + # Release + x64_release: + _BuildConfig: Release + assetManifestOS: win + assetManifestPlatform: x64 + archflag: -arch x64 + LLVMTableGenArg: + ClangTableGenArg: + arm64_release: + _BuildConfig: Release + assetManifestOS: win + assetManifestPlatform: arm64 + archflag: -arch arm64 + LLVMTableGenArg: /p:LLVMTableGenPath=$(Build.SourcesDirectory)\artifacts\obj\BuildRoot-x64\bin\llvm-tblgen.exe + ClangTableGenArg: /p:ClangTableGenPath=$(Build.SourcesDirectory)\artifacts\obj\BuildRoot-x64\bin\clang-tblgen.exe + arm_release: + _BuildConfig: Release + assetManifestOS: win + assetManifestPlatform: arm + archflag: -arch arm + LLVMTableGenArg: /p:LLVMTableGenPath=$(Build.SourcesDirectory)\artifacts\obj\BuildRoot-x64\bin\llvm-tblgen.exe + ClangTableGenArg: /p:ClangTableGenPath=$(Build.SourcesDirectory)\artifacts\obj\BuildRoot-x64\bin\clang-tblgen.exe + # Debug + x64_debug: + _BuildConfig: Debug + assetManifestOS: win + assetManifestPlatform: x64 + archflag: -arch x64 + LLVMTableGenArg: + ClangTableGenArg: + arm64_debug: + _BuildConfig: Debug + assetManifestOS: win + assetManifestPlatform: arm64 + archflag: -arch arm64 + LLVMTableGenArg: /p:LLVMTableGenPath=$(Build.SourcesDirectory)\artifacts\obj\BuildRoot-x64\bin\llvm-tblgen.exe + ClangTableGenArg: /p:ClangTableGenPath=$(Build.SourcesDirectory)\artifacts\obj\BuildRoot-x64\bin\clang-tblgen.exe + arm_debug: + _BuildConfig: Debug + assetManifestOS: win + assetManifestPlatform: arm + archflag: -arch arm + LLVMTableGenArg: /p:LLVMTableGenPath=$(Build.SourcesDirectory)\artifacts\obj\BuildRoot-x64\bin\llvm-tblgen.exe + ClangTableGenArg: /p:ClangTableGenPath=$(Build.SourcesDirectory)\artifacts\obj\BuildRoot-x64\bin\clang-tblgen.exe + pool: + ${{ if eq(variables['System.TeamProject'], 'public') }}: + name: $(DncEngPublicBuildPool) + demands: ImageOverride -equals windows.vs2022.amd64.open + ${{ if eq(variables['System.TeamProject'], 'internal') }}: + name: $(DncEngInternalBuildPool) + demands: ImageOverride -equals windows.vs2022.amd64 + steps: + - checkout: self + clean: true + fetchDepth: 2 + + - script: | + git clean -ffdx + git reset --hard HEAD + displayName: 'Clean up working directory' + + - powershell: eng\build.ps1 -ci -restore -build -arch x64 -configuration $(_BuildConfig) $(_InternalBuildArgs) /p:BuildLLVMTableGenOnly=true + displayName: 'Build host llvm-tblgen for cross-compiling' + condition: and(succeeded(), ne(variables['assetManifestPlatform'], 'x64')) + + - powershell: eng\build.ps1 -ci -restore -build -pack $(archflag) -configuration $(_BuildConfig) $(_InternalBuildArgs) $(LLVMTableGenArg) $(ClangTableGenArg) + displayName: 'Build and package' + + - powershell: eng\common\build.ps1 -ci -restore -publish -configuration $(_BuildConfig) $(_InternalBuildArgs) /p:AssetManifestOS=$(_BuildConfig)-$(assetManifestOS) /p:PlatformName=$(assetManifestPlatform) -projects $(Build.SourcesDirectory)\llvm.proj + displayName: Publish packages + condition: and(succeeded(), ne(variables['System.TeamProject'], 'public'), ne(variables['Build.Reason'], 'PullRequest')) + +############ POST BUILD ARCADE LOGIC ############ +- ${{ if and(ne(variables['System.TeamProject'], 'public'), ne(variables['Build.Reason'], 'PullRequest')) }}: + - template: /eng/common/templates/post-build/post-build.yml + parameters: + publishingInfraVersion: 3 + enableSourceLinkValidation: false + enableSigningValidation: false + enableSymbolValidation: false + enableNugetValidation: true diff --git a/eng/build.ps1 b/eng/build.ps1 new file mode 100644 index 0000000000000..bc12cebbdcbd1 --- /dev/null +++ b/eng/build.ps1 @@ -0,0 +1,132 @@ +[CmdletBinding(PositionalBinding=$false)] +Param( + [switch][Alias('h')]$help, + [switch][Alias('b')]$build, + [switch][Alias('t')]$test, + [switch]$buildtests, + [string][Alias('c')]$configuration = "Debug", + [string][Alias('f')]$framework, + [string]$vs, + [string]$os, + [switch]$allconfigurations, + [switch]$coverage, + [string]$testscope, + [string]$arch, + [string]$runtimeConfiguration, + [string]$librariesConfiguration, + [Parameter(ValueFromRemainingArguments=$true)][String[]]$properties +) + +function Get-Help() { + Write-Host "Common settings:" + Write-Host " -os Build operating system: Windows_NT or Unix" + Write-Host " -arch Build platform: x86, x64, arm or arm64" + Write-Host " -configuration Build configuration: Debug or Release (short: -c)" + Write-Host " -verbosity MSBuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)" + Write-Host " -binaryLog Output binary log (short: -bl)" + Write-Host " -help Print help and exit (short: -h)" + Write-Host "" + + Write-Host "Actions (defaults to -restore -build):" + Write-Host " -restore Restore dependencies (short: -r)" + Write-Host " -build Build all source projects (short: -b)" + Write-Host " -buildtests Build all test projects" + Write-Host " -rebuild Rebuild all source projects" + Write-Host " -test Run all unit tests (short: -t)" + Write-Host " -pack Package build outputs into NuGet packages" + Write-Host " -sign Sign build outputs" + Write-Host " -publish Publish artifacts (e.g. symbols)" + Write-Host " -clean Clean the solution" + Write-Host "" + + Write-Host "Libraries settings:" + Write-Host " -vs Open the solution with VS for Test Explorer support. Path or solution name (ie -vs Microsoft.CSharp)" + Write-Host " -framework Build framework: netcoreapp5.0 or net472 (short: -f)" + Write-Host " -coverage Collect code coverage when testing" + Write-Host " -testscope Scope tests, allowed values: innerloop, outerloop, all" + Write-Host " -allconfigurations Build packages for all build configurations" + Write-Host "" + + Write-Host "Command-line arguments not listed above are passed thru to msbuild." + Write-Host "The above arguments can be shortened as much as to be unambiguous (e.g. -con for configuration, -t for test, etc.)." +} + +if ($help -or (($null -ne $properties) -and ($properties.Contains('/help') -or $properties.Contains('/?')))) { + Get-Help + exit 0 +} + +# VS Test Explorer support for libraries +if ($vs) { + . $PSScriptRoot\common\tools.ps1 + + # Microsoft.DotNet.CoreSetup.sln is special - hosting tests are currently meant to run on the + # bootstrapped .NET Core, not on the live-built runtime. + if ([System.IO.Path]::GetFileName($vs) -ieq "Microsoft.DotNet.CoreSetup.sln") { + if (-Not (Test-Path $vs)) { + $vs = Join-Path "$PSScriptRoot\..\src\installer" $vs + } + + # This tells .NET Core to use the bootstrapped runtime to run the tests + $env:DOTNET_ROOT=InitializeDotNetCli -install:$false + } + else { + if (-Not (Test-Path $vs)) { + $vs = Join-Path "$PSScriptRoot\..\src\libraries" $vs | Join-Path -ChildPath "$vs.sln" + } + + $archTestHost = if ($arch) { $arch } else { "x64" } + + # This tells .NET Core to use the same dotnet.exe that build scripts use + $env:DOTNET_ROOT="$PSScriptRoot\..\artifacts\bin\testhost\netcoreapp5.0-Windows_NT-$configuration-$archTestHost"; + $env:DEVPATH="$PSScriptRoot\..\artifacts\bin\testhost\net472-Windows_NT-$configuration-$archTestHost"; + } + + # This tells MSBuild to load the SDK from the directory of the bootstrapped SDK + $env:DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR=InitializeDotNetCli -install:$false + + # This tells .NET Core not to go looking for .NET Core in other places + $env:DOTNET_MULTILEVEL_LOOKUP=0; + + # Put our local dotnet.exe on PATH first so Visual Studio knows which one to use + $env:PATH=($env:DOTNET_ROOT + ";" + $env:PATH); + + # Launch Visual Studio with the locally defined environment variables + ."$vs" + + exit 0 +} + +# Check if an action is passed in +$actions = "r","restore","b","build","buildtests","rebuild","t","test","pack","sign","publish","clean" +$actionPassedIn = @(Compare-Object -ReferenceObject @($PSBoundParameters.Keys) -DifferenceObject $actions -ExcludeDifferent -IncludeEqual).Length -ne 0 +if ($null -ne $properties -and $actionPassedIn -ne $true) { + $actionPassedIn = @(Compare-Object -ReferenceObject $properties -DifferenceObject $actions.ForEach({ "-" + $_ }) -ExcludeDifferent -IncludeEqual).Length -ne 0 +} + +if (!$actionPassedIn) { + $arguments = "-restore -build" +} + +$possibleDirToBuild = if($properties.Length -gt 0) { $properties[0]; } else { $null } + +foreach ($argument in $PSBoundParameters.Keys) +{ + switch($argument) + { + "build" { $arguments += " -build" } + "buildtests" { if ($build -eq $true) { $arguments += " /p:BuildTests=true" } else { $arguments += " -build /p:BuildTests=only" } } + "test" { $arguments += " -test" } + "configuration" { $configuration = (Get-Culture).TextInfo.ToTitleCase($($PSBoundParameters[$argument])); $arguments += " /p:ConfigurationGroup=$configuration -configuration $configuration" } + "runtimeConfiguration" { $arguments += " /p:RuntimeConfiguration=$((Get-Culture).TextInfo.ToTitleCase($($PSBoundParameters[$argument])))" } + "framework" { $arguments += " /p:BuildTargetFramework=$($PSBoundParameters[$argument].ToLowerInvariant())" } + "os" { $arguments += " /p:OSGroup=$($PSBoundParameters[$argument])" } + "allconfigurations" { $arguments += " /p:BuildAllConfigurations=true" } + "arch" { $arguments += " /p:ArchGroup=$($PSBoundParameters[$argument]) /p:TargetArchitecture=$($PSBoundParameters[$argument])" } + "properties" { $arguments += " " + $properties } + default { $arguments += " /p:$argument=$($PSBoundParameters[$argument])" } + } +} + +Invoke-Expression "& `"$PSScriptRoot/common/build.ps1`" $arguments" +exit $lastExitCode diff --git a/eng/build.sh b/eng/build.sh new file mode 100755 index 0000000000000..becb206742183 --- /dev/null +++ b/eng/build.sh @@ -0,0 +1,170 @@ +#!/usr/bin/env bash + +set -ue + +source="${BASH_SOURCE[0]}" + +# resolve $source until the file is no longer a symlink +while [[ -h "$source" ]]; do + scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + source="$(readlink "$source")" + # if $source was a relative symlink, we need to resolve it relative to the path where the + # symlink file was located + [[ $source != /* ]] && source="$scriptroot/$source" +done +scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + +usage() +{ + echo "Common settings:" + echo " --os Build operating system: Windows_NT or Unix" + echo " --arch Build platform: x86, x64, arm or arm64" + echo " --configuration Build configuration: Debug or Release (short: -c)" + echo " --verbosity MSBuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)" + echo " --binaryLog Output binary log (short: -bl)" + echo " --cross Optional argument to signify cross compilation" + echo " --help Print help and exit (short: -h)" + echo "" + + echo "Actions (defaults to --restore --build):" + echo " --restore Restore dependencies (short: -r)" + echo " --build Build all source projects (short: -b)" + echo " --buildtests Build all test projects" + echo " --rebuild Rebuild all source projects" + echo " --test Run all unit tests (short: -t)" + echo " --pack Package build outputs into NuGet packages" + echo " --sign Sign build outputs" + echo " --publish Publish artifacts (e.g. symbols)" + echo " --clean Clean the solution" + echo "" + + echo "Libraries settings:" + echo " --framework Build framework: netcoreapp or net472 (short: -f)" + echo " --coverage Collect code coverage when testing" + echo " --testscope Test scope, allowed values: innerloop, outerloop, all" + echo " --allconfigurations Build packages for all build configurations" + echo "" + + echo "Native build settings:" + echo " --clang Optional argument to build using clang in PATH (default)" + echo " --clangx.y Optional argument to build using clang version x.y" + echo " --cmakeargs User-settable additional arguments passed to CMake." + echo " --gcc Optional argument to build using gcc in PATH (default)" + echo " --gccx.y Optional argument to build using gcc version x.y" + + echo "Command line arguments starting with '/p:' are passed through to MSBuild." + echo "Arguments can also be passed in with a single hyphen." +} + +arguments='' +cmakeargs='' +extraargs='' +build=false +buildtests=false +checkedPossibleDirectoryToBuild=false + +# Check if an action is passed in +declare -a actions=("r" "restore" "b" "build" "buildtests" "rebuild" "t" "test" "pack" "sign" "publish" "clean") +actInt=($(comm -12 <(printf '%s\n' "${actions[@]/#/-}" | sort) <(printf '%s\n' "${@/#--/-}" | sort))) + +while [[ $# > 0 ]]; do + opt="$(echo "${1/#--/-}" | awk '{print tolower($0)}')" + case "$opt" in + -help|-h) + usage + exit 0 + ;; + -arch) + arguments="$arguments /p:ArchGroup=$2 /p:TargetArchitecture=$2" + shift 2 + ;; + -configuration|-c) + val="$(tr '[:lower:]' '[:upper:]' <<< ${2:0:1})${2:1}" + arguments="$arguments /p:ConfigurationGroup=$val -configuration $val" + shift 2 + ;; + -framework|-f) + val="$(echo "$2" | awk '{print tolower($0)}')" + arguments="$arguments /p:BuildTargetFramework=$val" + shift 2 + ;; + -os) + arguments="$arguments /p:OSGroup=$2" + shift 2 + ;; + -allconfigurations) + arguments="$arguments /p:BuildAllConfigurations=true" + shift 1 + ;; + -build) + build=true + arguments="$arguments -build" + shift 1 + ;; + -buildtests) + buildtests=true + shift 1 + ;; + -testscope) + arguments="$arguments /p:TestScope=$2" + shift 2 + ;; + -coverage) + arguments="$arguments /p:Coverage=true" + shift 1 + ;; + -stripsymbols) + arguments="$arguments /p:BuildNativeStripSymbols=true" + shift 1 + ;; + -runtimeconfiguration) + val="$(tr '[:lower:]' '[:upper:]' <<< ${2:0:1})${2:1}" + arguments="$arguments /p:RuntimeConfiguration=$val" + shift 2 + ;; + -librariesconfiguration) + arguments="$arguments /p:LibrariesConfiguration=$2" + shift 2 + ;; + -cross) + arguments="$arguments /p:CrossBuild=True" + shift 1 + ;; + -clang*) + arguments="$arguments /p:Compiler=$opt" + shift 1 + ;; + -cmakeargs) + cmakeargs="${cmakeargs} ${opt} $2" + shift 2 + ;; + -gcc*) + arguments="$arguments /p:Compiler=$opt" + shift 1 + ;; + *) + ea=$1 + + extraargs="$extraargs $ea" + shift 1 + ;; + esac +done + +if [[ "$buildtests" == true ]]; then + if [[ "$build" == true ]]; then + arguments="$arguments /p:BuildTests=true" + else + arguments="$arguments -build /p:BuildTests=only" + fi +fi + +if [ ${#actInt[@]} -eq 0 ]; then + arguments="-restore -build $arguments" +fi + +# URL-encode space (%20) to avoid quoting issues until the msbuild call in /eng/common/tools.sh. +# In *proj files (XML docs), URL-encoded string are rendered in their decoded form. +cmakeargs="${cmakeargs// /%20}" +arguments="$arguments /p:CMakeArgs=\"$cmakeargs\" $extraargs" +"$scriptroot/common/build.sh" $arguments diff --git a/eng/common-variables.yml b/eng/common-variables.yml new file mode 100644 index 0000000000000..1901c728e063e --- /dev/null +++ b/eng/common-variables.yml @@ -0,0 +1,40 @@ + +variables: + # Cannot use key:value syntax in root defined variables + - name: _TeamName + value: DotNetCore + - name: _DotNetArtifactsCategory + value: .NETCore + - name: _DotNetValidationArtifactsCategory + value: .NETCore + - name: HelixApiAccessToken + value: '' + - name: _RunAsPublic + value: True + - name: _RunAsInternal + value: False + - name: _InternalBuildArgs + value: '' + + - ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: + - name: _RunAsPublic + value: False + - name: _RunAsInternal + value: True + - name: _SignType + value: real + # DotNet-Blob-Feed provides: dotnetfeed-storage-access-key-1 + # Publish-Build-Assets provides: MaestroAccessToken, BotAccount-dotnet-maestro-bot-PAT + # DotNet-HelixApi-Access provides: HelixApiAccessToken + - group: DotNet-Blob-Feed + - group: Publish-Build-Assets + - group: DotNet-VSTS-Bot + - group: DotNet-HelixApi-Access + - name: _InternalBuildArgs + value: /p:DotNetSignType=$(_SignType) /p:TeamName=$(_TeamName) + /p:DotNetPublishBlobFeedKey=$(dotnetfeed-storage-access-key-1) + /p:DotNetPublishBlobFeedUrl=https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json + /p:DotNetPublishToBlobFeed=true + /p:DotNetPublishUsingPipelines=true + /p:DotNetArtifactsCategory=$(_DotNetArtifactsCategory) + /p:OfficialBuildId=$(BUILD.BUILDNUMBER) diff --git a/eng/common/BuildConfiguration/build-configuration.json b/eng/common/BuildConfiguration/build-configuration.json new file mode 100644 index 0000000000000..3d1cc89894c94 --- /dev/null +++ b/eng/common/BuildConfiguration/build-configuration.json @@ -0,0 +1,4 @@ +{ + "RetryCountLimit": 1, + "RetryByAnyError": false +} diff --git a/eng/common/CIBuild.cmd b/eng/common/CIBuild.cmd new file mode 100644 index 0000000000000..56c2f25ac22ff --- /dev/null +++ b/eng/common/CIBuild.cmd @@ -0,0 +1,2 @@ +@echo off +powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0Build.ps1""" -restore -build -test -sign -pack -publish -ci %*" \ No newline at end of file diff --git a/eng/common/PSScriptAnalyzerSettings.psd1 b/eng/common/PSScriptAnalyzerSettings.psd1 new file mode 100644 index 0000000000000..4c1ea7c98ea4d --- /dev/null +++ b/eng/common/PSScriptAnalyzerSettings.psd1 @@ -0,0 +1,11 @@ +@{ + IncludeRules=@('PSAvoidUsingCmdletAliases', + 'PSAvoidUsingWMICmdlet', + 'PSAvoidUsingPositionalParameters', + 'PSAvoidUsingInvokeExpression', + 'PSUseDeclaredVarsMoreThanAssignments', + 'PSUseCmdletCorrectly', + 'PSStandardDSCFunctionsInResource', + 'PSUseIdenticalMandatoryParametersForDSC', + 'PSUseIdenticalParametersForDSC') +} \ No newline at end of file diff --git a/eng/common/README.md b/eng/common/README.md new file mode 100644 index 0000000000000..ff49c371527a0 --- /dev/null +++ b/eng/common/README.md @@ -0,0 +1,28 @@ +# Don't touch this folder + + uuuuuuuuuuuuuuuuuuuu + u" uuuuuuuuuuuuuuuuuu "u + u" u$$$$$$$$$$$$$$$$$$$$u "u + u" u$$$$$$$$$$$$$$$$$$$$$$$$u "u + u" u$$$$$$$$$$$$$$$$$$$$$$$$$$$$u "u + u" u$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$u "u + u" u$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$u "u + $ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $ + $ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $ + $ $$$" ... "$... ...$" ... "$$$ ... "$$$ $ + $ $$$u `"$$$$$$$ $$$ $$$$$ $$ $$$ $$$ $ + $ $$$$$$uu "$$$$ $$$ $$$$$ $$ """ u$$$ $ + $ $$$""$$$ $$$$ $$$u "$$$" u$$ $$$$$$$$ $ + $ $$$$....,$$$$$..$$$$$....,$$$$..$$$$$$$$ $ + $ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $ + "u "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" u" + "u "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" u" + "u "$$$$$$$$$$$$$$$$$$$$$$$$$$$$" u" + "u "$$$$$$$$$$$$$$$$$$$$$$$$" u" + "u "$$$$$$$$$$$$$$$$$$$$" u" + "u """""""""""""""""" u" + """""""""""""""""""" + +!!! Changes made in this directory are subject to being overwritten by automation !!! + +The files in this directory are shared by all Arcade repos and managed by automation. If you need to make changes to these files, open an issue or submit a pull request to https://github.com/dotnet/arcade first. diff --git a/eng/common/SetupNugetSources.ps1 b/eng/common/SetupNugetSources.ps1 new file mode 100644 index 0000000000000..6e99723945183 --- /dev/null +++ b/eng/common/SetupNugetSources.ps1 @@ -0,0 +1,167 @@ +# This file is a temporary workaround for internal builds to be able to restore from private AzDO feeds. +# This file should be removed as part of this issue: https://github.com/dotnet/arcade/issues/4080 +# +# What the script does is iterate over all package sources in the pointed NuGet.config and add a credential entry +# under for each Maestro managed private feed. Two additional credential +# entries are also added for the two private static internal feeds: dotnet3-internal and dotnet3-internal-transport. +# +# This script needs to be called in every job that will restore packages and which the base repo has +# private AzDO feeds in the NuGet.config. +# +# See example YAML call for this script below. Note the use of the variable `$(dn-bot-dnceng-artifact-feeds-rw)` +# from the AzureDevOps-Artifact-Feeds-Pats variable group. +# +# Any disabledPackageSources entries which start with "darc-int" will be re-enabled as part of this script executing +# +# - task: PowerShell@2 +# displayName: Setup Private Feeds Credentials +# condition: eq(variables['Agent.OS'], 'Windows_NT') +# inputs: +# filePath: $(Build.SourcesDirectory)/eng/common/SetupNugetSources.ps1 +# arguments: -ConfigFile $(Build.SourcesDirectory)/NuGet.config -Password $Env:Token +# env: +# Token: $(dn-bot-dnceng-artifact-feeds-rw) + +[CmdletBinding()] +param ( + [Parameter(Mandatory = $true)][string]$ConfigFile, + [Parameter(Mandatory = $true)][string]$Password +) + +$ErrorActionPreference = "Stop" +Set-StrictMode -Version 2.0 +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + +. $PSScriptRoot\tools.ps1 + +# Add source entry to PackageSources +function AddPackageSource($sources, $SourceName, $SourceEndPoint, $creds, $Username, $Password) { + $packageSource = $sources.SelectSingleNode("add[@key='$SourceName']") + + if ($packageSource -eq $null) + { + $packageSource = $doc.CreateElement("add") + $packageSource.SetAttribute("key", $SourceName) + $packageSource.SetAttribute("value", $SourceEndPoint) + $sources.AppendChild($packageSource) | Out-Null + } + else { + Write-Host "Package source $SourceName already present." + } + + AddCredential -Creds $creds -Source $SourceName -Username $Username -Password $Password +} + +# Add a credential node for the specified source +function AddCredential($creds, $source, $username, $password) { + # Looks for credential configuration for the given SourceName. Create it if none is found. + $sourceElement = $creds.SelectSingleNode($Source) + if ($sourceElement -eq $null) + { + $sourceElement = $doc.CreateElement($Source) + $creds.AppendChild($sourceElement) | Out-Null + } + + # Add the node to the credential if none is found. + $usernameElement = $sourceElement.SelectSingleNode("add[@key='Username']") + if ($usernameElement -eq $null) + { + $usernameElement = $doc.CreateElement("add") + $usernameElement.SetAttribute("key", "Username") + $sourceElement.AppendChild($usernameElement) | Out-Null + } + $usernameElement.SetAttribute("value", $Username) + + # Add the to the credential if none is found. + # Add it as a clear text because there is no support for encrypted ones in non-windows .Net SDKs. + # -> https://github.com/NuGet/Home/issues/5526 + $passwordElement = $sourceElement.SelectSingleNode("add[@key='ClearTextPassword']") + if ($passwordElement -eq $null) + { + $passwordElement = $doc.CreateElement("add") + $passwordElement.SetAttribute("key", "ClearTextPassword") + $sourceElement.AppendChild($passwordElement) | Out-Null + } + $passwordElement.SetAttribute("value", $Password) +} + +function InsertMaestroPrivateFeedCredentials($Sources, $Creds, $Username, $Password) { + $maestroPrivateSources = $Sources.SelectNodes("add[contains(@key,'darc-int')]") + + Write-Host "Inserting credentials for $($maestroPrivateSources.Count) Maestro's private feeds." + + ForEach ($PackageSource in $maestroPrivateSources) { + Write-Host "`tInserting credential for Maestro's feed:" $PackageSource.Key + AddCredential -Creds $creds -Source $PackageSource.Key -Username $Username -Password $Password + } +} + +function EnablePrivatePackageSources($DisabledPackageSources) { + $maestroPrivateSources = $DisabledPackageSources.SelectNodes("add[contains(@key,'darc-int')]") + ForEach ($DisabledPackageSource in $maestroPrivateSources) { + Write-Host "`tEnsuring private source '$($DisabledPackageSource.key)' is enabled by deleting it from disabledPackageSource" + # Due to https://github.com/NuGet/Home/issues/10291, we must actually remove the disabled entries + $DisabledPackageSources.RemoveChild($DisabledPackageSource) + } +} + +if (!(Test-Path $ConfigFile -PathType Leaf)) { + Write-PipelineTelemetryError -Category 'Build' -Message "Eng/common/SetupNugetSources.ps1 returned a non-zero exit code. Couldn't find the NuGet config file: $ConfigFile" + ExitWithExitCode 1 +} + +if (!$Password) { + Write-PipelineTelemetryError -Category 'Build' -Message 'Eng/common/SetupNugetSources.ps1 returned a non-zero exit code. Please supply a valid PAT' + ExitWithExitCode 1 +} + +# Load NuGet.config +$doc = New-Object System.Xml.XmlDocument +$filename = (Get-Item $ConfigFile).FullName +$doc.Load($filename) + +# Get reference to or create one if none exist already +$sources = $doc.DocumentElement.SelectSingleNode("packageSources") +if ($sources -eq $null) { + $sources = $doc.CreateElement("packageSources") + $doc.DocumentElement.AppendChild($sources) | Out-Null +} + +# Looks for a node. Create it if none is found. +$creds = $doc.DocumentElement.SelectSingleNode("packageSourceCredentials") +if ($creds -eq $null) { + $creds = $doc.CreateElement("packageSourceCredentials") + $doc.DocumentElement.AppendChild($creds) | Out-Null +} + +# Check for disabledPackageSources; we'll enable any darc-int ones we find there +$disabledSources = $doc.DocumentElement.SelectSingleNode("disabledPackageSources") +if ($disabledSources -ne $null) { + Write-Host "Checking for any darc-int disabled package sources in the disabledPackageSources node" + EnablePrivatePackageSources -DisabledPackageSources $disabledSources +} + +$userName = "dn-bot" + +# Insert credential nodes for Maestro's private feeds +InsertMaestroPrivateFeedCredentials -Sources $sources -Creds $creds -Username $userName -Password $Password + +# 3.1 uses a different feed url format so it's handled differently here +$dotnet31Source = $sources.SelectSingleNode("add[@key='dotnet3.1']") +if ($dotnet31Source -ne $null) { + AddPackageSource -Sources $sources -SourceName "dotnet3.1-internal" -SourceEndPoint "https://pkgs.dev.azure.com/dnceng/_packaging/dotnet3.1-internal/nuget/v2" -Creds $creds -Username $userName -Password $Password + AddPackageSource -Sources $sources -SourceName "dotnet3.1-internal-transport" -SourceEndPoint "https://pkgs.dev.azure.com/dnceng/_packaging/dotnet3.1-internal-transport/nuget/v2" -Creds $creds -Username $userName -Password $Password +} + +$dotnetVersions = @('5','6','7') + +foreach ($dotnetVersion in $dotnetVersions) { + $feedPrefix = "dotnet" + $dotnetVersion; + $dotnetSource = $sources.SelectSingleNode("add[@key='$feedPrefix']") + if ($dotnetSource -ne $null) { + AddPackageSource -Sources $sources -SourceName "$feedPrefix-internal" -SourceEndPoint "https://pkgs.dev.azure.com/dnceng/internal/_packaging/$feedPrefix-internal/nuget/v2" -Creds $creds -Username $userName -Password $Password + AddPackageSource -Sources $sources -SourceName "$feedPrefix-internal-transport" -SourceEndPoint "https://pkgs.dev.azure.com/dnceng/internal/_packaging/$feedPrefix-internal-transport/nuget/v2" -Creds $creds -Username $userName -Password $Password + } +} + +$doc.Save($filename) diff --git a/eng/common/SetupNugetSources.sh b/eng/common/SetupNugetSources.sh new file mode 100644 index 0000000000000..8af7d899db121 --- /dev/null +++ b/eng/common/SetupNugetSources.sh @@ -0,0 +1,171 @@ +#!/usr/bin/env bash + +# This file is a temporary workaround for internal builds to be able to restore from private AzDO feeds. +# This file should be removed as part of this issue: https://github.com/dotnet/arcade/issues/4080 +# +# What the script does is iterate over all package sources in the pointed NuGet.config and add a credential entry +# under for each Maestro's managed private feed. Two additional credential +# entries are also added for the two private static internal feeds: dotnet3-internal and dotnet3-internal-transport. +# +# This script needs to be called in every job that will restore packages and which the base repo has +# private AzDO feeds in the NuGet.config. +# +# See example YAML call for this script below. Note the use of the variable `$(dn-bot-dnceng-artifact-feeds-rw)` +# from the AzureDevOps-Artifact-Feeds-Pats variable group. +# +# Any disabledPackageSources entries which start with "darc-int" will be re-enabled as part of this script executing. +# +# - task: Bash@3 +# displayName: Setup Private Feeds Credentials +# inputs: +# filePath: $(Build.SourcesDirectory)/eng/common/SetupNugetSources.sh +# arguments: $(Build.SourcesDirectory)/NuGet.config $Token +# condition: ne(variables['Agent.OS'], 'Windows_NT') +# env: +# Token: $(dn-bot-dnceng-artifact-feeds-rw) + +ConfigFile=$1 +CredToken=$2 +NL='\n' +TB=' ' + +source="${BASH_SOURCE[0]}" + +# resolve $source until the file is no longer a symlink +while [[ -h "$source" ]]; do + scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + source="$(readlink "$source")" + # if $source was a relative symlink, we need to resolve it relative to the path where the + # symlink file was located + [[ $source != /* ]] && source="$scriptroot/$source" +done +scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + +. "$scriptroot/tools.sh" + +if [ ! -f "$ConfigFile" ]; then + Write-PipelineTelemetryError -Category 'Build' "Error: Eng/common/SetupNugetSources.sh returned a non-zero exit code. Couldn't find the NuGet config file: $ConfigFile" + ExitWithExitCode 1 +fi + +if [ -z "$CredToken" ]; then + Write-PipelineTelemetryError -category 'Build' "Error: Eng/common/SetupNugetSources.sh returned a non-zero exit code. Please supply a valid PAT" + ExitWithExitCode 1 +fi + +if [[ `uname -s` == "Darwin" ]]; then + NL=$'\\\n' + TB='' +fi + +# Ensure there is a ... section. +grep -i "" $ConfigFile +if [ "$?" != "0" ]; then + echo "Adding ... section." + ConfigNodeHeader="" + PackageSourcesTemplate="${TB}${NL}${TB}" + + sed -i.bak "s|$ConfigNodeHeader|$ConfigNodeHeader${NL}$PackageSourcesTemplate|" $ConfigFile +fi + +# Ensure there is a ... section. +grep -i "" $ConfigFile +if [ "$?" != "0" ]; then + echo "Adding ... section." + + PackageSourcesNodeFooter="" + PackageSourceCredentialsTemplate="${TB}${NL}${TB}" + + sed -i.bak "s|$PackageSourcesNodeFooter|$PackageSourcesNodeFooter${NL}$PackageSourceCredentialsTemplate|" $ConfigFile +fi + +PackageSources=() + +# Ensure dotnet3.1-internal and dotnet3.1-internal-transport are in the packageSources if the public dotnet3.1 feeds are present +grep -i "" + + sed -i.bak "s|$PackageSourcesNodeFooter|$PackageSourceTemplate${NL}$PackageSourcesNodeFooter|" $ConfigFile + fi + PackageSources+=('dotnet3.1-internal') + + grep -i "" $ConfigFile + if [ "$?" != "0" ]; then + echo "Adding dotnet3.1-internal-transport to the packageSources." + PackageSourcesNodeFooter="" + PackageSourceTemplate="${TB}" + + sed -i.bak "s|$PackageSourcesNodeFooter|$PackageSourceTemplate${NL}$PackageSourcesNodeFooter|" $ConfigFile + fi + PackageSources+=('dotnet3.1-internal-transport') +fi + +DotNetVersions=('5' '6' '7') + +for DotNetVersion in ${DotNetVersions[@]} ; do + FeedPrefix="dotnet${DotNetVersion}"; + grep -i "" + + sed -i.bak "s|$PackageSourcesNodeFooter|$PackageSourceTemplate${NL}$PackageSourcesNodeFooter|" $ConfigFile + fi + PackageSources+=("$FeedPrefix-internal") + + grep -i "" $ConfigFile + if [ "$?" != "0" ]; then + echo "Adding $FeedPrefix-internal-transport to the packageSources." + PackageSourcesNodeFooter="" + PackageSourceTemplate="${TB}" + + sed -i.bak "s|$PackageSourcesNodeFooter|$PackageSourceTemplate${NL}$PackageSourcesNodeFooter|" $ConfigFile + fi + PackageSources+=("$FeedPrefix-internal-transport") + fi +done + +# I want things split line by line +PrevIFS=$IFS +IFS=$'\n' +PackageSources+="$IFS" +PackageSources+=$(grep -oh '"darc-int-[^"]*"' $ConfigFile | tr -d '"') +IFS=$PrevIFS + +for FeedName in ${PackageSources[@]} ; do + # Check if there is no existing credential for this FeedName + grep -i "<$FeedName>" $ConfigFile + if [ "$?" != "0" ]; then + echo "Adding credentials for $FeedName." + + PackageSourceCredentialsNodeFooter="" + NewCredential="${TB}${TB}<$FeedName>${NL}${NL}${NL}" + + sed -i.bak "s|$PackageSourceCredentialsNodeFooter|$NewCredential${NL}$PackageSourceCredentialsNodeFooter|" $ConfigFile + fi +done + +# Re-enable any entries in disabledPackageSources where the feed name contains darc-int +grep -i "" $ConfigFile +if [ "$?" == "0" ]; then + DisabledDarcIntSources=() + echo "Re-enabling any disabled \"darc-int\" package sources in $ConfigFile" + DisabledDarcIntSources+=$(grep -oh '"darc-int-[^"]*" value="true"' $ConfigFile | tr -d '"') + for DisabledSourceName in ${DisabledDarcIntSources[@]} ; do + if [[ $DisabledSourceName == darc-int* ]] + then + OldDisableValue="" + NewDisableValue="" + sed -i.bak "s|$OldDisableValue|$NewDisableValue|" $ConfigFile + echo "Neutralized disablePackageSources entry for '$DisabledSourceName'" + fi + done +fi diff --git a/eng/common/build.ps1 b/eng/common/build.ps1 new file mode 100644 index 0000000000000..33a6f2d0e2481 --- /dev/null +++ b/eng/common/build.ps1 @@ -0,0 +1,166 @@ +[CmdletBinding(PositionalBinding=$false)] +Param( + [string][Alias('c')]$configuration = "Debug", + [string]$platform = $null, + [string] $projects, + [string][Alias('v')]$verbosity = "minimal", + [string] $msbuildEngine = $null, + [bool] $warnAsError = $true, + [bool] $nodeReuse = $true, + [switch][Alias('r')]$restore, + [switch] $deployDeps, + [switch][Alias('b')]$build, + [switch] $rebuild, + [switch] $deploy, + [switch][Alias('t')]$test, + [switch] $integrationTest, + [switch] $performanceTest, + [switch] $sign, + [switch] $pack, + [switch] $publish, + [switch] $clean, + [switch][Alias('bl')]$binaryLog, + [switch][Alias('nobl')]$excludeCIBinarylog, + [switch] $ci, + [switch] $prepareMachine, + [string] $runtimeSourceFeed = '', + [string] $runtimeSourceFeedKey = '', + [switch] $excludePrereleaseVS, + [switch] $nativeToolsOnMachine, + [switch] $help, + [Parameter(ValueFromRemainingArguments=$true)][String[]]$properties +) + +# Unset 'Platform' environment variable to avoid unwanted collision in InstallDotNetCore.targets file +# some computer has this env var defined (e.g. Some HP) +if($env:Platform) { + $env:Platform="" +} +function Print-Usage() { + Write-Host "Common settings:" + Write-Host " -configuration Build configuration: 'Debug' or 'Release' (short: -c)" + Write-Host " -platform Platform configuration: 'x86', 'x64' or any valid Platform value to pass to msbuild" + Write-Host " -verbosity Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)" + Write-Host " -binaryLog Output binary log (short: -bl)" + Write-Host " -help Print help and exit" + Write-Host "" + + Write-Host "Actions:" + Write-Host " -restore Restore dependencies (short: -r)" + Write-Host " -build Build solution (short: -b)" + Write-Host " -rebuild Rebuild solution" + Write-Host " -deploy Deploy built VSIXes" + Write-Host " -deployDeps Deploy dependencies (e.g. VSIXes for integration tests)" + Write-Host " -test Run all unit tests in the solution (short: -t)" + Write-Host " -integrationTest Run all integration tests in the solution" + Write-Host " -performanceTest Run all performance tests in the solution" + Write-Host " -pack Package build outputs into NuGet packages and Willow components" + Write-Host " -sign Sign build outputs" + Write-Host " -publish Publish artifacts (e.g. symbols)" + Write-Host " -clean Clean the solution" + Write-Host "" + + Write-Host "Advanced settings:" + Write-Host " -projects Semi-colon delimited list of sln/proj's to build. Globbing is supported (*.sln)" + Write-Host " -ci Set when running on CI server" + Write-Host " -excludeCIBinarylog Don't output binary log (short: -nobl)" + Write-Host " -prepareMachine Prepare machine for CI run, clean up processes after build" + Write-Host " -warnAsError Sets warnaserror msbuild parameter ('true' or 'false')" + Write-Host " -msbuildEngine Msbuild engine to use to run build ('dotnet', 'vs', or unspecified)." + Write-Host " -excludePrereleaseVS Set to exclude build engines in prerelease versions of Visual Studio" + Write-Host " -nativeToolsOnMachine Sets the native tools on machine environment variable (indicating that the script should use native tools on machine)" + Write-Host "" + + Write-Host "Command line arguments not listed above are passed thru to msbuild." + Write-Host "The above arguments can be shortened as much as to be unambiguous (e.g. -co for configuration, -t for test, etc.)." +} + +. $PSScriptRoot\tools.ps1 + +function InitializeCustomToolset { + if (-not $restore) { + return + } + + $script = Join-Path $EngRoot 'restore-toolset.ps1' + + if (Test-Path $script) { + . $script + } +} + +function Build { + $toolsetBuildProj = InitializeToolset + InitializeCustomToolset + + $bl = if ($binaryLog) { '/bl:' + (Join-Path $LogDir 'Build.binlog') } else { '' } + $platformArg = if ($platform) { "/p:Platform=$platform" } else { '' } + + if ($projects) { + # Re-assign properties to a new variable because PowerShell doesn't let us append properties directly for unclear reasons. + # Explicitly set the type as string[] because otherwise PowerShell would make this char[] if $properties is empty. + [string[]] $msbuildArgs = $properties + + # Resolve relative project paths into full paths + $projects = ($projects.Split(';').ForEach({Resolve-Path $_}) -join ';') + + $msbuildArgs += "/p:Projects=$projects" + $properties = $msbuildArgs + } + + MSBuild $toolsetBuildProj ` + $bl ` + $platformArg ` + /p:Configuration=$configuration ` + /p:RepoRoot=$RepoRoot ` + /p:Restore=$restore ` + /p:DeployDeps=$deployDeps ` + /p:Build=$build ` + /p:Rebuild=$rebuild ` + /p:Deploy=$deploy ` + /p:Test=$test ` + /p:Pack=$pack ` + /p:IntegrationTest=$integrationTest ` + /p:PerformanceTest=$performanceTest ` + /p:Sign=$sign ` + /p:Publish=$publish ` + @properties +} + +try { + if ($clean) { + if (Test-Path $ArtifactsDir) { + Remove-Item -Recurse -Force $ArtifactsDir + Write-Host 'Artifacts directory deleted.' + } + exit 0 + } + + if ($help -or (($null -ne $properties) -and ($properties.Contains('/help') -or $properties.Contains('/?')))) { + Print-Usage + exit 0 + } + + if ($ci) { + if (-not $excludeCIBinarylog) { + $binaryLog = $true + } + $nodeReuse = $false + } + + if ($nativeToolsOnMachine) { + $env:NativeToolsOnMachine = $true + } + if ($restore) { + InitializeNativeTools + } + + Build +} +catch { + Write-Host $_.ScriptStackTrace + Write-PipelineTelemetryError -Category 'InitializeToolset' -Message $_ + ExitWithExitCode 1 +} + +ExitWithExitCode 0 diff --git a/eng/common/build.sh b/eng/common/build.sh new file mode 100755 index 0000000000000..50af40cdd2ce6 --- /dev/null +++ b/eng/common/build.sh @@ -0,0 +1,247 @@ +#!/usr/bin/env bash + +# Stop script if unbound variable found (use ${var:-} if intentional) +set -u + +# Stop script if command returns non-zero exit code. +# Prevents hidden errors caused by missing error code propagation. +set -e + +usage() +{ + echo "Common settings:" + echo " --configuration Build configuration: 'Debug' or 'Release' (short: -c)" + echo " --verbosity Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)" + echo " --binaryLog Create MSBuild binary log (short: -bl)" + echo " --help Print help and exit (short: -h)" + echo "" + + echo "Actions:" + echo " --restore Restore dependencies (short: -r)" + echo " --build Build solution (short: -b)" + echo " --sourceBuild Source-build the solution (short: -sb)" + echo " Will additionally trigger the following actions: --restore, --build, --pack" + echo " If --configuration is not set explicitly, will also set it to 'Release'" + echo " --rebuild Rebuild solution" + echo " --test Run all unit tests in the solution (short: -t)" + echo " --integrationTest Run all integration tests in the solution" + echo " --performanceTest Run all performance tests in the solution" + echo " --pack Package build outputs into NuGet packages and Willow components" + echo " --sign Sign build outputs" + echo " --publish Publish artifacts (e.g. symbols)" + echo " --clean Clean the solution" + echo "" + + echo "Advanced settings:" + echo " --projects Project or solution file(s) to build" + echo " --ci Set when running on CI server" + echo " --excludeCIBinarylog Don't output binary log (short: -nobl)" + echo " --prepareMachine Prepare machine for CI run, clean up processes after build" + echo " --nodeReuse Sets nodereuse msbuild parameter ('true' or 'false')" + echo " --warnAsError Sets warnaserror msbuild parameter ('true' or 'false')" + echo "" + echo "Command line arguments not listed above are passed thru to msbuild." + echo "Arguments can also be passed in with a single hyphen." +} + +source="${BASH_SOURCE[0]}" + +# resolve $source until the file is no longer a symlink +while [[ -h "$source" ]]; do + scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + source="$(readlink "$source")" + # if $source was a relative symlink, we need to resolve it relative to the path where the + # symlink file was located + [[ $source != /* ]] && source="$scriptroot/$source" +done +scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + +restore=false +build=false +source_build=false +rebuild=false +test=false +integration_test=false +performance_test=false +pack=false +publish=false +sign=false +public=false +ci=false +clean=false + +warn_as_error=true +node_reuse=true +binary_log=false +exclude_ci_binary_log=false +pipelines_log=false + +projects='' +configuration='' +prepare_machine=false +verbosity='minimal' +runtime_source_feed='' +runtime_source_feed_key='' + +properties='' +while [[ $# > 0 ]]; do + opt="$(echo "${1/#--/-}" | tr "[:upper:]" "[:lower:]")" + case "$opt" in + -help|-h) + usage + exit 0 + ;; + -clean) + clean=true + ;; + -configuration|-c) + configuration=$2 + shift + ;; + -verbosity|-v) + verbosity=$2 + shift + ;; + -binarylog|-bl) + binary_log=true + ;; + -excludeCIBinarylog|-nobl) + exclude_ci_binary_log=true + ;; + -pipelineslog|-pl) + pipelines_log=true + ;; + -restore|-r) + restore=true + ;; + -build|-b) + build=true + ;; + -rebuild) + rebuild=true + ;; + -pack) + pack=true + ;; + -sourcebuild|-sb) + build=true + source_build=true + restore=true + pack=true + ;; + -test|-t) + test=true + ;; + -integrationtest) + integration_test=true + ;; + -performancetest) + performance_test=true + ;; + -sign) + sign=true + ;; + -publish) + publish=true + ;; + -preparemachine) + prepare_machine=true + ;; + -projects) + projects=$2 + shift + ;; + -ci) + ci=true + ;; + -warnaserror) + warn_as_error=$2 + shift + ;; + -nodereuse) + node_reuse=$2 + shift + ;; + -runtimesourcefeed) + runtime_source_feed=$2 + shift + ;; + -runtimesourcefeedkey) + runtime_source_feed_key=$2 + shift + ;; + *) + properties="$properties $1" + ;; + esac + + shift +done + +if [[ -z "$configuration" ]]; then + if [[ "$source_build" = true ]]; then configuration="Release"; else configuration="Debug"; fi +fi + +if [[ "$ci" == true ]]; then + pipelines_log=true + node_reuse=false + if [[ "$exclude_ci_binary_log" == false ]]; then + binary_log=true + fi +fi + +. "$scriptroot/tools.sh" + +function InitializeCustomToolset { + local script="$eng_root/restore-toolset.sh" + + if [[ -a "$script" ]]; then + . "$script" + fi +} + +function Build { + InitializeToolset + InitializeCustomToolset + + if [[ ! -z "$projects" ]]; then + properties="$properties /p:Projects=$projects" + fi + + local bl="" + if [[ "$binary_log" == true ]]; then + bl="/bl:\"$log_dir/Build.binlog\"" + fi + + MSBuild $_InitializeToolset \ + $bl \ + /p:Configuration=$configuration \ + /p:RepoRoot="$repo_root" \ + /p:Restore=$restore \ + /p:Build=$build \ + /p:ArcadeBuildFromSource=$source_build \ + /p:Rebuild=$rebuild \ + /p:Test=$test \ + /p:Pack=$pack \ + /p:IntegrationTest=$integration_test \ + /p:PerformanceTest=$performance_test \ + /p:Sign=$sign \ + /p:Publish=$publish \ + $properties + + ExitWithExitCode 0 +} + +if [[ "$clean" == true ]]; then + if [ -d "$artifacts_dir" ]; then + rm -rf $artifacts_dir + echo "Artifacts directory deleted." + fi + exit 0 +fi + +if [[ "$restore" == true ]]; then + InitializeNativeTools +fi + +Build diff --git a/eng/common/cibuild.sh b/eng/common/cibuild.sh new file mode 100755 index 0000000000000..1a02c0dec8fd7 --- /dev/null +++ b/eng/common/cibuild.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +source="${BASH_SOURCE[0]}" + +# resolve $SOURCE until the file is no longer a symlink +while [[ -h $source ]]; do + scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + source="$(readlink "$source")" + + # if $source was a relative symlink, we need to resolve it relative to the path where + # the symlink file was located + [[ $source != /* ]] && source="$scriptroot/$source" +done +scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + +. "$scriptroot/build.sh" --restore --build --test --pack --publish --ci $@ \ No newline at end of file diff --git a/eng/common/cross/arm/sources.list.bionic b/eng/common/cross/arm/sources.list.bionic new file mode 100644 index 0000000000000..2109557409576 --- /dev/null +++ b/eng/common/cross/arm/sources.list.bionic @@ -0,0 +1,11 @@ +deb http://ports.ubuntu.com/ubuntu-ports/ bionic main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted +deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted + +deb http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted universe multiverse +deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted universe multiverse diff --git a/eng/common/cross/arm/sources.list.focal b/eng/common/cross/arm/sources.list.focal new file mode 100644 index 0000000000000..4de2600c17478 --- /dev/null +++ b/eng/common/cross/arm/sources.list.focal @@ -0,0 +1,11 @@ +deb http://ports.ubuntu.com/ubuntu-ports/ focal main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ focal main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ focal-updates main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ focal-updates main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ focal-backports main restricted +deb-src http://ports.ubuntu.com/ubuntu-ports/ focal-backports main restricted + +deb http://ports.ubuntu.com/ubuntu-ports/ focal-security main restricted universe multiverse +deb-src http://ports.ubuntu.com/ubuntu-ports/ focal-security main restricted universe multiverse diff --git a/eng/common/cross/arm/sources.list.jammy b/eng/common/cross/arm/sources.list.jammy new file mode 100644 index 0000000000000..6bb0453029cc4 --- /dev/null +++ b/eng/common/cross/arm/sources.list.jammy @@ -0,0 +1,11 @@ +deb http://ports.ubuntu.com/ubuntu-ports/ jammy main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ jammy-updates main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-updates main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ jammy-backports main restricted +deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-backports main restricted + +deb http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse +deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse diff --git a/eng/common/cross/arm/sources.list.jessie b/eng/common/cross/arm/sources.list.jessie new file mode 100644 index 0000000000000..4d142ac9b1089 --- /dev/null +++ b/eng/common/cross/arm/sources.list.jessie @@ -0,0 +1,3 @@ +# Debian (sid) # UNSTABLE +deb http://ftp.debian.org/debian/ sid main contrib non-free +deb-src http://ftp.debian.org/debian/ sid main contrib non-free diff --git a/eng/common/cross/arm/sources.list.xenial b/eng/common/cross/arm/sources.list.xenial new file mode 100644 index 0000000000000..eacd86b7df3c1 --- /dev/null +++ b/eng/common/cross/arm/sources.list.xenial @@ -0,0 +1,11 @@ +deb http://ports.ubuntu.com/ubuntu-ports/ xenial main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ xenial-backports main restricted +deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-backports main restricted + +deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security main restricted universe multiverse +deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-security main restricted universe multiverse \ No newline at end of file diff --git a/eng/common/cross/arm/sources.list.zesty b/eng/common/cross/arm/sources.list.zesty new file mode 100644 index 0000000000000..ea2c14a787473 --- /dev/null +++ b/eng/common/cross/arm/sources.list.zesty @@ -0,0 +1,11 @@ +deb http://ports.ubuntu.com/ubuntu-ports/ zesty main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ zesty main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ zesty-updates main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ zesty-updates main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ zesty-backports main restricted +deb-src http://ports.ubuntu.com/ubuntu-ports/ zesty-backports main restricted + +deb http://ports.ubuntu.com/ubuntu-ports/ zesty-security main restricted universe multiverse +deb-src http://ports.ubuntu.com/ubuntu-ports/ zesty-security main restricted universe multiverse diff --git a/eng/common/cross/arm/tizen/tizen.patch b/eng/common/cross/arm/tizen/tizen.patch new file mode 100644 index 0000000000000..fb12ade7250ae --- /dev/null +++ b/eng/common/cross/arm/tizen/tizen.patch @@ -0,0 +1,9 @@ +diff -u -r a/usr/lib/libc.so b/usr/lib/libc.so +--- a/usr/lib/libc.so 2016-12-30 23:00:08.284951863 +0900 ++++ b/usr/lib/libc.so 2016-12-30 23:00:32.140951815 +0900 +@@ -2,4 +2,4 @@ + Use the shared library, but some functions are only in + the static library, so try that secondarily. */ + OUTPUT_FORMAT(elf32-littlearm) +-GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a AS_NEEDED ( /lib/ld-linux-armhf.so.3 ) ) ++GROUP ( libc.so.6 libc_nonshared.a AS_NEEDED ( ld-linux-armhf.so.3 ) ) diff --git a/eng/common/cross/arm64/sources.list.bionic b/eng/common/cross/arm64/sources.list.bionic new file mode 100644 index 0000000000000..2109557409576 --- /dev/null +++ b/eng/common/cross/arm64/sources.list.bionic @@ -0,0 +1,11 @@ +deb http://ports.ubuntu.com/ubuntu-ports/ bionic main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted +deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted + +deb http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted universe multiverse +deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted universe multiverse diff --git a/eng/common/cross/arm64/sources.list.buster b/eng/common/cross/arm64/sources.list.buster new file mode 100644 index 0000000000000..7194ac64a9602 --- /dev/null +++ b/eng/common/cross/arm64/sources.list.buster @@ -0,0 +1,11 @@ +deb http://deb.debian.org/debian buster main +deb-src http://deb.debian.org/debian buster main + +deb http://deb.debian.org/debian-security/ buster/updates main +deb-src http://deb.debian.org/debian-security/ buster/updates main + +deb http://deb.debian.org/debian buster-updates main +deb-src http://deb.debian.org/debian buster-updates main + +deb http://deb.debian.org/debian buster-backports main contrib non-free +deb-src http://deb.debian.org/debian buster-backports main contrib non-free diff --git a/eng/common/cross/arm64/sources.list.focal b/eng/common/cross/arm64/sources.list.focal new file mode 100644 index 0000000000000..4de2600c17478 --- /dev/null +++ b/eng/common/cross/arm64/sources.list.focal @@ -0,0 +1,11 @@ +deb http://ports.ubuntu.com/ubuntu-ports/ focal main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ focal main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ focal-updates main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ focal-updates main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ focal-backports main restricted +deb-src http://ports.ubuntu.com/ubuntu-ports/ focal-backports main restricted + +deb http://ports.ubuntu.com/ubuntu-ports/ focal-security main restricted universe multiverse +deb-src http://ports.ubuntu.com/ubuntu-ports/ focal-security main restricted universe multiverse diff --git a/eng/common/cross/arm64/sources.list.jammy b/eng/common/cross/arm64/sources.list.jammy new file mode 100644 index 0000000000000..6bb0453029cc4 --- /dev/null +++ b/eng/common/cross/arm64/sources.list.jammy @@ -0,0 +1,11 @@ +deb http://ports.ubuntu.com/ubuntu-ports/ jammy main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ jammy-updates main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-updates main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ jammy-backports main restricted +deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-backports main restricted + +deb http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse +deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse diff --git a/eng/common/cross/arm64/sources.list.stretch b/eng/common/cross/arm64/sources.list.stretch new file mode 100644 index 0000000000000..0e1215774368a --- /dev/null +++ b/eng/common/cross/arm64/sources.list.stretch @@ -0,0 +1,12 @@ +deb http://deb.debian.org/debian stretch main +deb-src http://deb.debian.org/debian stretch main + +deb http://deb.debian.org/debian-security/ stretch/updates main +deb-src http://deb.debian.org/debian-security/ stretch/updates main + +deb http://deb.debian.org/debian stretch-updates main +deb-src http://deb.debian.org/debian stretch-updates main + +deb http://deb.debian.org/debian stretch-backports main contrib non-free +deb-src http://deb.debian.org/debian stretch-backports main contrib non-free + diff --git a/eng/common/cross/arm64/sources.list.xenial b/eng/common/cross/arm64/sources.list.xenial new file mode 100644 index 0000000000000..eacd86b7df3c1 --- /dev/null +++ b/eng/common/cross/arm64/sources.list.xenial @@ -0,0 +1,11 @@ +deb http://ports.ubuntu.com/ubuntu-ports/ xenial main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ xenial-backports main restricted +deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-backports main restricted + +deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security main restricted universe multiverse +deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-security main restricted universe multiverse \ No newline at end of file diff --git a/eng/common/cross/arm64/sources.list.zesty b/eng/common/cross/arm64/sources.list.zesty new file mode 100644 index 0000000000000..ea2c14a787473 --- /dev/null +++ b/eng/common/cross/arm64/sources.list.zesty @@ -0,0 +1,11 @@ +deb http://ports.ubuntu.com/ubuntu-ports/ zesty main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ zesty main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ zesty-updates main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ zesty-updates main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ zesty-backports main restricted +deb-src http://ports.ubuntu.com/ubuntu-ports/ zesty-backports main restricted + +deb http://ports.ubuntu.com/ubuntu-ports/ zesty-security main restricted universe multiverse +deb-src http://ports.ubuntu.com/ubuntu-ports/ zesty-security main restricted universe multiverse diff --git a/eng/common/cross/arm64/tizen/tizen.patch b/eng/common/cross/arm64/tizen/tizen.patch new file mode 100644 index 0000000000000..af7c8be059068 --- /dev/null +++ b/eng/common/cross/arm64/tizen/tizen.patch @@ -0,0 +1,9 @@ +diff -u -r a/usr/lib/libc.so b/usr/lib/libc.so +--- a/usr/lib64/libc.so 2016-12-30 23:00:08.284951863 +0900 ++++ b/usr/lib64/libc.so 2016-12-30 23:00:32.140951815 +0900 +@@ -2,4 +2,4 @@ + Use the shared library, but some functions are only in + the static library, so try that secondarily. */ + OUTPUT_FORMAT(elf64-littleaarch64) +-GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a AS_NEEDED ( /lib/ld-linux-aarch64.so.1 ) ) ++GROUP ( libc.so.6 libc_nonshared.a AS_NEEDED ( ld-linux-aarch64.so.1 ) ) diff --git a/eng/common/cross/armel/armel.jessie.patch b/eng/common/cross/armel/armel.jessie.patch new file mode 100644 index 0000000000000..2d2615619351f --- /dev/null +++ b/eng/common/cross/armel/armel.jessie.patch @@ -0,0 +1,43 @@ +diff -u -r a/usr/include/urcu/uatomic/generic.h b/usr/include/urcu/uatomic/generic.h +--- a/usr/include/urcu/uatomic/generic.h 2014-10-22 15:00:58.000000000 -0700 ++++ b/usr/include/urcu/uatomic/generic.h 2020-10-30 21:38:28.550000000 -0700 +@@ -69,10 +69,10 @@ + #endif + #ifdef UATOMIC_HAS_ATOMIC_SHORT + case 2: +- return __sync_val_compare_and_swap_2(addr, old, _new); ++ return __sync_val_compare_and_swap_2((uint16_t*) addr, old, _new); + #endif + case 4: +- return __sync_val_compare_and_swap_4(addr, old, _new); ++ return __sync_val_compare_and_swap_4((uint32_t*) addr, old, _new); + #if (CAA_BITS_PER_LONG == 64) + case 8: + return __sync_val_compare_and_swap_8(addr, old, _new); +@@ -109,7 +109,7 @@ + return; + #endif + case 4: +- __sync_and_and_fetch_4(addr, val); ++ __sync_and_and_fetch_4((uint32_t*) addr, val); + return; + #if (CAA_BITS_PER_LONG == 64) + case 8: +@@ -148,7 +148,7 @@ + return; + #endif + case 4: +- __sync_or_and_fetch_4(addr, val); ++ __sync_or_and_fetch_4((uint32_t*) addr, val); + return; + #if (CAA_BITS_PER_LONG == 64) + case 8: +@@ -187,7 +187,7 @@ + return __sync_add_and_fetch_2(addr, val); + #endif + case 4: +- return __sync_add_and_fetch_4(addr, val); ++ return __sync_add_and_fetch_4((uint32_t*) addr, val); + #if (CAA_BITS_PER_LONG == 64) + case 8: + return __sync_add_and_fetch_8(addr, val); diff --git a/eng/common/cross/armel/sources.list.jessie b/eng/common/cross/armel/sources.list.jessie new file mode 100644 index 0000000000000..3d9c3059d8970 --- /dev/null +++ b/eng/common/cross/armel/sources.list.jessie @@ -0,0 +1,3 @@ +# Debian (jessie) # Stable +deb http://ftp.debian.org/debian/ jessie main contrib non-free +deb-src http://ftp.debian.org/debian/ jessie main contrib non-free diff --git a/eng/common/cross/armel/tizen/tizen.patch b/eng/common/cross/armel/tizen/tizen.patch new file mode 100644 index 0000000000000..ca7c7c1ff751f --- /dev/null +++ b/eng/common/cross/armel/tizen/tizen.patch @@ -0,0 +1,9 @@ +diff -u -r a/usr/lib/libc.so b/usr/lib/libc.so +--- a/usr/lib/libc.so 2016-12-30 23:00:08.284951863 +0900 ++++ b/usr/lib/libc.so 2016-12-30 23:00:32.140951815 +0900 +@@ -2,4 +2,4 @@ + Use the shared library, but some functions are only in + the static library, so try that secondarily. */ + OUTPUT_FORMAT(elf32-littlearm) +-GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a AS_NEEDED ( /lib/ld-linux.so.3 ) ) ++GROUP ( libc.so.6 libc_nonshared.a AS_NEEDED ( ld-linux.so.3 ) ) diff --git a/eng/common/cross/armv6/sources.list.buster b/eng/common/cross/armv6/sources.list.buster new file mode 100644 index 0000000000000..f27fc4fb346b6 --- /dev/null +++ b/eng/common/cross/armv6/sources.list.buster @@ -0,0 +1,2 @@ +deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi +deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi diff --git a/eng/common/cross/build-android-rootfs.sh b/eng/common/cross/build-android-rootfs.sh new file mode 100755 index 0000000000000..f163fb9dae966 --- /dev/null +++ b/eng/common/cross/build-android-rootfs.sh @@ -0,0 +1,131 @@ +#!/usr/bin/env bash +set -e +__NDK_Version=r21 + +usage() +{ + echo "Creates a toolchain and sysroot used for cross-compiling for Android." + echo. + echo "Usage: $0 [BuildArch] [ApiLevel]" + echo. + echo "BuildArch is the target architecture of Android. Currently only arm64 is supported." + echo "ApiLevel is the target Android API level. API levels usually match to Android releases. See https://source.android.com/source/build-numbers.html" + echo. + echo "By default, the toolchain and sysroot will be generated in cross/android-rootfs/toolchain/[BuildArch]. You can change this behavior" + echo "by setting the TOOLCHAIN_DIR environment variable" + echo. + echo "By default, the NDK will be downloaded into the cross/android-rootfs/android-ndk-$__NDK_Version directory. If you already have an NDK installation," + echo "you can set the NDK_DIR environment variable to have this script use that installation of the NDK." + echo "By default, this script will generate a file, android_platform, in the root of the ROOTFS_DIR directory that contains the RID for the supported and tested Android build: android.28-arm64. This file is to replace '/etc/os-release', which is not available for Android." + exit 1 +} + +__ApiLevel=28 # The minimum platform for arm64 is API level 21 but the minimum version that support glob(3) is 28. See $ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/glob.h +__BuildArch=arm64 +__AndroidArch=aarch64 +__AndroidToolchain=aarch64-linux-android + +for i in "$@" + do + lowerI="$(echo $i | tr "[:upper:]" "[:lower:]")" + case $lowerI in + -?|-h|--help) + usage + exit 1 + ;; + arm64) + __BuildArch=arm64 + __AndroidArch=aarch64 + __AndroidToolchain=aarch64-linux-android + ;; + arm) + __BuildArch=arm + __AndroidArch=arm + __AndroidToolchain=arm-linux-androideabi + ;; + *[0-9]) + __ApiLevel=$i + ;; + *) + __UnprocessedBuildArgs="$__UnprocessedBuildArgs $i" + ;; + esac +done + +# Obtain the location of the bash script to figure out where the root of the repo is. +__ScriptBaseDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +__CrossDir="$__ScriptBaseDir/../../../.tools/android-rootfs" + +if [[ ! -f "$__CrossDir" ]]; then + mkdir -p "$__CrossDir" +fi + +# Resolve absolute path to avoid `../` in build logs +__CrossDir="$( cd "$__CrossDir" && pwd )" + +__NDK_Dir="$__CrossDir/android-ndk-$__NDK_Version" +__lldb_Dir="$__CrossDir/lldb" +__ToolchainDir="$__CrossDir/android-ndk-$__NDK_Version" + +if [[ -n "$TOOLCHAIN_DIR" ]]; then + __ToolchainDir=$TOOLCHAIN_DIR +fi + +if [[ -n "$NDK_DIR" ]]; then + __NDK_Dir=$NDK_DIR +fi + +echo "Target API level: $__ApiLevel" +echo "Target architecture: $__BuildArch" +echo "NDK location: $__NDK_Dir" +echo "Target Toolchain location: $__ToolchainDir" + +# Download the NDK if required +if [ ! -d $__NDK_Dir ]; then + echo Downloading the NDK into $__NDK_Dir + mkdir -p $__NDK_Dir + wget -q --progress=bar:force:noscroll --show-progress https://dl.google.com/android/repository/android-ndk-$__NDK_Version-linux-x86_64.zip -O $__CrossDir/android-ndk-$__NDK_Version-linux-x86_64.zip + unzip -q $__CrossDir/android-ndk-$__NDK_Version-linux-x86_64.zip -d $__CrossDir +fi + +if [ ! -d $__lldb_Dir ]; then + mkdir -p $__lldb_Dir + echo Downloading LLDB into $__lldb_Dir + wget -q --progress=bar:force:noscroll --show-progress https://dl.google.com/android/repository/lldb-2.3.3614996-linux-x86_64.zip -O $__CrossDir/lldb-2.3.3614996-linux-x86_64.zip + unzip -q $__CrossDir/lldb-2.3.3614996-linux-x86_64.zip -d $__lldb_Dir +fi + +echo "Download dependencies..." +__TmpDir=$__CrossDir/tmp/$__BuildArch/ +mkdir -p "$__TmpDir" + +# combined dependencies for coreclr, installer and libraries +__AndroidPackages="libicu" +__AndroidPackages+=" libandroid-glob" +__AndroidPackages+=" liblzma" +__AndroidPackages+=" krb5" +__AndroidPackages+=" openssl" + +for path in $(wget -qO- https://packages.termux.dev/termux-main-21/dists/stable/main/binary-$__AndroidArch/Packages |\ + grep -A15 "Package: \(${__AndroidPackages// /\\|}\)" | grep -v "static\|tool" | grep Filename); do + + if [[ "$path" != "Filename:" ]]; then + echo "Working on: $path" + wget -qO- https://packages.termux.dev/termux-main-21/$path | dpkg -x - "$__TmpDir" + fi +done + +cp -R "$__TmpDir/data/data/com.termux/files/usr/"* "$__ToolchainDir/sysroot/usr/" + +# Generate platform file for build.sh script to assign to __DistroRid +echo "Generating platform file..." +echo "RID=android.${__ApiLevel}-${__BuildArch}" > $__ToolchainDir/sysroot/android_platform + +echo "Now to build coreclr, libraries and installers; run:" +echo ROOTFS_DIR=\$\(realpath $__ToolchainDir/sysroot\) ./build.sh --cross --arch $__BuildArch \ + --subsetCategory coreclr +echo ROOTFS_DIR=\$\(realpath $__ToolchainDir/sysroot\) ./build.sh --cross --arch $__BuildArch \ + --subsetCategory libraries +echo ROOTFS_DIR=\$\(realpath $__ToolchainDir/sysroot\) ./build.sh --cross --arch $__BuildArch \ + --subsetCategory installer diff --git a/eng/common/cross/build-rootfs.sh b/eng/common/cross/build-rootfs.sh new file mode 100755 index 0000000000000..1ebf454f3cf28 --- /dev/null +++ b/eng/common/cross/build-rootfs.sh @@ -0,0 +1,513 @@ +#!/usr/bin/env bash + +set -e + +usage() +{ + echo "Usage: $0 [BuildArch] [CodeName] [lldbx.y] [llvmx[.y]] [--skipunmount] --rootfsdir ]" + echo "BuildArch can be: arm(default), arm64, armel, armv6, ppc64le, riscv64, s390x, x64, x86" + echo "CodeName - optional, Code name for Linux, can be: xenial(default), zesty, bionic, alpine, alpine3.13 or alpine3.14. If BuildArch is armel, LinuxCodeName is jessie(default) or tizen." + echo " for FreeBSD can be: freebsd12, freebsd13" + echo " for illumos can be: illumos" + echo " for Haiku can be: haiku." + echo "lldbx.y - optional, LLDB version, can be: lldb3.9(default), lldb4.0, lldb5.0, lldb6.0 no-lldb. Ignored for alpine and FreeBSD" + echo "llvmx[.y] - optional, LLVM version for LLVM related packages." + echo "--skipunmount - optional, will skip the unmount of rootfs folder." + echo "--use-mirror - optional, use mirror URL to fetch resources, when available." + echo "--jobs N - optional, restrict to N jobs." + exit 1 +} + +__CodeName=xenial +__CrossDir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +__BuildArch=arm +__AlpineArch=armv7 +__FreeBSDArch=arm +__FreeBSDMachineArch=armv7 +__IllumosArch=arm7 +__QEMUArch=arm +__UbuntuArch=armhf +__UbuntuRepo="http://ports.ubuntu.com/" +__LLDB_Package="liblldb-3.9-dev" +__SkipUnmount=0 + +# base development support +__UbuntuPackages="build-essential" + +__AlpinePackages="alpine-base" +__AlpinePackages+=" build-base" +__AlpinePackages+=" linux-headers" +__AlpinePackages+=" lldb-dev" +__AlpinePackages+=" python3" +__AlpinePackages+=" libedit" + +# symlinks fixer +__UbuntuPackages+=" symlinks" + +# runtime dependencies +__UbuntuPackages+=" libicu-dev" +__UbuntuPackages+=" liblttng-ust-dev" +__UbuntuPackages+=" libunwind8-dev" +__UbuntuPackages+=" libnuma-dev" + +__AlpinePackages+=" gettext-dev" +__AlpinePackages+=" icu-dev" +__AlpinePackages+=" libunwind-dev" +__AlpinePackages+=" lttng-ust-dev" +__AlpinePackages+=" compiler-rt-static" +__AlpinePackages+=" numactl-dev" + +# runtime libraries' dependencies +__UbuntuPackages+=" libcurl4-openssl-dev" +__UbuntuPackages+=" libkrb5-dev" +__UbuntuPackages+=" libssl-dev" +__UbuntuPackages+=" zlib1g-dev" + +__AlpinePackages+=" curl-dev" +__AlpinePackages+=" krb5-dev" +__AlpinePackages+=" openssl-dev" +__AlpinePackages+=" zlib-dev" + +__FreeBSDBase="12.3-RELEASE" +__FreeBSDPkg="1.17.0" +__FreeBSDABI="12" +__FreeBSDPackages="libunwind" +__FreeBSDPackages+=" icu" +__FreeBSDPackages+=" libinotify" +__FreeBSDPackages+=" openssl" +__FreeBSDPackages+=" krb5" +__FreeBSDPackages+=" terminfo-db" + +__IllumosPackages="icu" +__IllumosPackages+=" mit-krb5" +__IllumosPackages+=" openssl" +__IllumosPackages+=" zlib" + +__HaikuPackages="gmp" +__HaikuPackages+=" gmp_devel" +__HaikuPackages+=" krb5" +__HaikuPackages+=" krb5_devel" +__HaikuPackages+=" libiconv" +__HaikuPackages+=" libiconv_devel" +__HaikuPackages+=" llvm12_libunwind" +__HaikuPackages+=" llvm12_libunwind_devel" +__HaikuPackages+=" mpfr" +__HaikuPackages+=" mpfr_devel" + +# ML.NET dependencies +__UbuntuPackages+=" libomp5" +__UbuntuPackages+=" libomp-dev" + +__Keyring= +__UseMirror=0 + +__UnprocessedBuildArgs= +while :; do + if [[ "$#" -le 0 ]]; then + break + fi + + lowerI="$(echo "$1" | tr "[:upper:]" "[:lower:]")" + case $lowerI in + -\?|-h|--help) + usage + exit 1 + ;; + arm) + __BuildArch=arm + __UbuntuArch=armhf + __AlpineArch=armv7 + __QEMUArch=arm + ;; + arm64) + __BuildArch=arm64 + __UbuntuArch=arm64 + __AlpineArch=aarch64 + __QEMUArch=aarch64 + __FreeBSDArch=arm64 + __FreeBSDMachineArch=aarch64 + ;; + armel) + __BuildArch=armel + __UbuntuArch=armel + __UbuntuRepo="http://ftp.debian.org/debian/" + __CodeName=jessie + ;; + armv6) + __BuildArch=armv6 + __UbuntuArch=armhf + __QEMUArch=arm + __UbuntuRepo="http://raspbian.raspberrypi.org/raspbian/" + __CodeName=buster + __LLDB_Package="liblldb-6.0-dev" + + if [[ -e "/usr/share/keyrings/raspbian-archive-keyring.gpg" ]]; then + __Keyring="--keyring /usr/share/keyrings/raspbian-archive-keyring.gpg" + fi + ;; + ppc64le) + __BuildArch=ppc64le + __UbuntuArch=ppc64el + __UbuntuRepo="http://ports.ubuntu.com/ubuntu-ports/" + __UbuntuPackages="${__UbuntuPackages// libunwind8-dev/}" + __UbuntuPackages="${__UbuntuPackages// libomp-dev/}" + __UbuntuPackages="${__UbuntuPackages// libomp5/}" + unset __LLDB_Package + ;; + riscv64) + __BuildArch=riscv64 + __UbuntuArch=riscv64 + __UbuntuRepo="http://deb.debian.org/debian-ports" + __CodeName=sid + __UbuntuPackages="${__UbuntuPackages// libunwind8-dev/}" + unset __LLDB_Package + + if [[ -e "/usr/share/keyrings/debian-ports-archive-keyring.gpg" ]]; then + __Keyring="--keyring /usr/share/keyrings/debian-ports-archive-keyring.gpg --include=debian-ports-archive-keyring" + fi + ;; + s390x) + __BuildArch=s390x + __UbuntuArch=s390x + __UbuntuRepo="http://ports.ubuntu.com/ubuntu-ports/" + __UbuntuPackages="${__UbuntuPackages// libunwind8-dev/}" + __UbuntuPackages="${__UbuntuPackages// libomp-dev/}" + __UbuntuPackages="${__UbuntuPackages// libomp5/}" + unset __LLDB_Package + ;; + x64) + __BuildArch=x64 + __UbuntuArch=amd64 + __FreeBSDArch=amd64 + __FreeBSDMachineArch=amd64 + __illumosArch=x86_64 + __UbuntuRepo= + ;; + x86) + __BuildArch=x86 + __UbuntuArch=i386 + __UbuntuRepo="http://archive.ubuntu.com/ubuntu/" + ;; + lldb*) + version="${lowerI/lldb/}" + parts=(${version//./ }) + + # for versions > 6.0, lldb has dropped the minor version + if [[ "${parts[0]}" -gt 6 ]]; then + version="${parts[0]}" + fi + + __LLDB_Package="liblldb-${version}-dev" + ;; + no-lldb) + unset __LLDB_Package + ;; + llvm*) + version="${lowerI/llvm/}" + parts=(${version//./ }) + __LLVM_MajorVersion="${parts[0]}" + __LLVM_MinorVersion="${parts[1]}" + + # for versions > 6.0, llvm has dropped the minor version + if [[ -z "$__LLVM_MinorVersion" && "$__LLVM_MajorVersion" -le 6 ]]; then + __LLVM_MinorVersion=0; + fi + ;; + xenial) # Ubuntu 16.04 + if [[ "$__CodeName" != "jessie" ]]; then + __CodeName=xenial + fi + ;; + zesty) # Ubuntu 17.04 + if [[ "$__CodeName" != "jessie" ]]; then + __CodeName=zesty + fi + ;; + bionic) # Ubuntu 18.04 + if [[ "$__CodeName" != "jessie" ]]; then + __CodeName=bionic + fi + ;; + focal) # Ubuntu 20.04 + if [[ "$__CodeName" != "jessie" ]]; then + __CodeName=focal + fi + ;; + jammy) # Ubuntu 22.04 + if [[ "$__CodeName" != "jessie" ]]; then + __CodeName=jammy + fi + ;; + jessie) # Debian 8 + __CodeName=jessie + __UbuntuRepo="http://ftp.debian.org/debian/" + ;; + stretch) # Debian 9 + __CodeName=stretch + __UbuntuRepo="http://ftp.debian.org/debian/" + __LLDB_Package="liblldb-6.0-dev" + ;; + buster) # Debian 10 + __CodeName=buster + __UbuntuRepo="http://ftp.debian.org/debian/" + __LLDB_Package="liblldb-6.0-dev" + ;; + tizen) + __CodeName= + __UbuntuRepo= + __Tizen=tizen + ;; + alpine|alpine3.13) + __CodeName=alpine + __UbuntuRepo= + __AlpineVersion=3.13 + __AlpinePackages+=" llvm10-libs" + ;; + alpine3.14) + __CodeName=alpine + __UbuntuRepo= + __AlpineVersion=3.14 + __AlpinePackages+=" llvm11-libs" + ;; + freebsd12) + __CodeName=freebsd + __SkipUnmount=1 + ;; + freebsd13) + __CodeName=freebsd + __FreeBSDBase="13.0-RELEASE" + __FreeBSDABI="13" + __SkipUnmount=1 + ;; + illumos) + __CodeName=illumos + __SkipUnmount=1 + ;; + haiku) + __CodeName=haiku + __BuildArch=x64 + __SkipUnmount=1 + ;; + --skipunmount) + __SkipUnmount=1 + ;; + --rootfsdir|-rootfsdir) + shift + __RootfsDir="$1" + ;; + --use-mirror) + __UseMirror=1 + ;; + --use-jobs) + shift + MAXJOBS=$1 + ;; + *) + __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1" + ;; + esac + + shift +done + +if [[ "$__BuildArch" == "armel" ]]; then + __LLDB_Package="lldb-3.5-dev" +elif [[ "$__BuildArch" == "arm" && "$__AlpineVersion" == "3.13" ]]; then + __AlpinePackages="${__AlpinePackages//numactl-dev/}" +fi + +__UbuntuPackages+=" ${__LLDB_Package:-}" + +if [[ -n "$__LLVM_MajorVersion" ]]; then + __UbuntuPackages+=" libclang-common-${__LLVM_MajorVersion}${__LLVM_MinorVersion:+.$__LLVM_MinorVersion}-dev" +fi + +if [[ -z "$__RootfsDir" && -n "$ROOTFS_DIR" ]]; then + __RootfsDir="$ROOTFS_DIR" +fi + +if [[ -z "$__RootfsDir" ]]; then + __RootfsDir="$__CrossDir/../../../.tools/rootfs/$__BuildArch" +fi + +if [[ -d "$__RootfsDir" ]]; then + if [[ "$__SkipUnmount" == "0" ]]; then + umount "$__RootfsDir"/* || true + fi + rm -rf "$__RootfsDir" +fi + +mkdir -p "$__RootfsDir" +__RootfsDir="$( cd "$__RootfsDir" && pwd )" + +if [[ "$__CodeName" == "alpine" ]]; then + __ApkToolsVersion=2.9.1 + __ApkToolsDir="$(mktemp -d)" + wget "https://github.com/alpinelinux/apk-tools/releases/download/v$__ApkToolsVersion/apk-tools-$__ApkToolsVersion-x86_64-linux.tar.gz" -P "$__ApkToolsDir" + tar -xf "$__ApkToolsDir/apk-tools-$__ApkToolsVersion-x86_64-linux.tar.gz" -C "$__ApkToolsDir" + mkdir -p "$__RootfsDir"/usr/bin + cp -v "/usr/bin/qemu-$__QEMUArch-static" "$__RootfsDir/usr/bin" + + "$__ApkToolsDir/apk-tools-$__ApkToolsVersion/apk" \ + -X "http://dl-cdn.alpinelinux.org/alpine/v$__AlpineVersion/main" \ + -X "http://dl-cdn.alpinelinux.org/alpine/v$__AlpineVersion/community" \ + -U --allow-untrusted --root "$__RootfsDir" --arch "$__AlpineArch" --initdb \ + add $__AlpinePackages + + rm -r "$__ApkToolsDir" +elif [[ "$__CodeName" == "freebsd" ]]; then + mkdir -p "$__RootfsDir"/usr/local/etc + JOBS=${MAXJOBS:="$(getconf _NPROCESSORS_ONLN)"} + wget -O - "https://download.freebsd.org/ftp/releases/${__FreeBSDArch}/${__FreeBSDMachineArch}/${__FreeBSDBase}/base.txz" | tar -C "$__RootfsDir" -Jxf - ./lib ./usr/lib ./usr/libdata ./usr/include ./usr/share/keys ./etc ./bin/freebsd-version + echo "ABI = \"FreeBSD:${__FreeBSDABI}:${__FreeBSDMachineArch}\"; FINGERPRINTS = \"${__RootfsDir}/usr/share/keys\"; REPOS_DIR = [\"${__RootfsDir}/etc/pkg\"]; REPO_AUTOUPDATE = NO; RUN_SCRIPTS = NO;" > "${__RootfsDir}"/usr/local/etc/pkg.conf + echo "FreeBSD: { url: \"pkg+http://pkg.FreeBSD.org/\${ABI}/quarterly\", mirror_type: \"srv\", signature_type: \"fingerprints\", fingerprints: \"${__RootfsDir}/usr/share/keys/pkg\", enabled: yes }" > "${__RootfsDir}"/etc/pkg/FreeBSD.conf + mkdir -p "$__RootfsDir"/tmp + # get and build package manager + wget -O - "https://github.com/freebsd/pkg/archive/${__FreeBSDPkg}.tar.gz" | tar -C "$__RootfsDir"/tmp -zxf - + cd "$__RootfsDir/tmp/pkg-${__FreeBSDPkg}" + # needed for install to succeed + mkdir -p "$__RootfsDir"/host/etc + ./autogen.sh && ./configure --prefix="$__RootfsDir"/host && make -j "$JOBS" && make install + rm -rf "$__RootfsDir/tmp/pkg-${__FreeBSDPkg}" + # install packages we need. + INSTALL_AS_USER=$(whoami) "$__RootfsDir"/host/sbin/pkg -r "$__RootfsDir" -C "$__RootfsDir"/usr/local/etc/pkg.conf update + INSTALL_AS_USER=$(whoami) "$__RootfsDir"/host/sbin/pkg -r "$__RootfsDir" -C "$__RootfsDir"/usr/local/etc/pkg.conf install --yes $__FreeBSDPackages +elif [[ "$__CodeName" == "illumos" ]]; then + mkdir "$__RootfsDir/tmp" + pushd "$__RootfsDir/tmp" + JOBS=${MAXJOBS:="$(getconf _NPROCESSORS_ONLN)"} + echo "Downloading sysroot." + wget -O - https://github.com/illumos/sysroot/releases/download/20181213-de6af22ae73b-v1/illumos-sysroot-i386-20181213-de6af22ae73b-v1.tar.gz | tar -C "$__RootfsDir" -xzf - + echo "Building binutils. Please wait.." + wget -O - https://ftp.gnu.org/gnu/binutils/binutils-2.33.1.tar.bz2 | tar -xjf - + mkdir build-binutils && cd build-binutils + ../binutils-2.33.1/configure --prefix="$__RootfsDir" --target="${__illumosArch}-sun-solaris2.10" --program-prefix="${__illumosArch}-illumos-" --with-sysroot="$__RootfsDir" + make -j "$JOBS" && make install && cd .. + echo "Building gcc. Please wait.." + wget -O - https://ftp.gnu.org/gnu/gcc/gcc-8.4.0/gcc-8.4.0.tar.xz | tar -xJf - + CFLAGS="-fPIC" + CXXFLAGS="-fPIC" + CXXFLAGS_FOR_TARGET="-fPIC" + CFLAGS_FOR_TARGET="-fPIC" + export CFLAGS CXXFLAGS CXXFLAGS_FOR_TARGET CFLAGS_FOR_TARGET + mkdir build-gcc && cd build-gcc + ../gcc-8.4.0/configure --prefix="$__RootfsDir" --target="${__illumosArch}-sun-solaris2.10" --program-prefix="${__illumosArch}-illumos-" --with-sysroot="$__RootfsDir" --with-gnu-as \ + --with-gnu-ld --disable-nls --disable-libgomp --disable-libquadmath --disable-libssp --disable-libvtv --disable-libcilkrts --disable-libada --disable-libsanitizer \ + --disable-libquadmath-support --disable-shared --enable-tls + make -j "$JOBS" && make install && cd .. + BaseUrl=https://pkgsrc.smartos.org + if [[ "$__UseMirror" == 1 ]]; then + BaseUrl=https://pkgsrc.smartos.skylime.net + fi + BaseUrl="$BaseUrl/packages/SmartOS/trunk/${__illumosArch}/All" + echo "Downloading manifest" + wget "$BaseUrl" + echo "Downloading dependencies." + read -ra array <<<"$__IllumosPackages" + for package in "${array[@]}"; do + echo "Installing '$package'" + # find last occurrence of package in listing and extract its name + package="$(sed -En '/.*href="('"$package"'-[0-9].*).tgz".*/h;$!d;g;s//\1/p' All)" + echo "Resolved name '$package'" + wget "$BaseUrl"/"$package".tgz + ar -x "$package".tgz + tar --skip-old-files -xzf "$package".tmp.tg* -C "$__RootfsDir" 2>/dev/null + done + echo "Cleaning up temporary files." + popd + rm -rf "$__RootfsDir"/{tmp,+*} + mkdir -p "$__RootfsDir"/usr/include/net + mkdir -p "$__RootfsDir"/usr/include/netpacket + wget -P "$__RootfsDir"/usr/include/net https://raw.githubusercontent.com/illumos/illumos-gate/master/usr/src/uts/common/io/bpf/net/bpf.h + wget -P "$__RootfsDir"/usr/include/net https://raw.githubusercontent.com/illumos/illumos-gate/master/usr/src/uts/common/io/bpf/net/dlt.h + wget -P "$__RootfsDir"/usr/include/netpacket https://raw.githubusercontent.com/illumos/illumos-gate/master/usr/src/uts/common/inet/sockmods/netpacket/packet.h + wget -P "$__RootfsDir"/usr/include/sys https://raw.githubusercontent.com/illumos/illumos-gate/master/usr/src/uts/common/sys/sdt.h +elif [[ "$__CodeName" == "haiku" ]]; then + JOBS=${MAXJOBS:="$(getconf _NPROCESSORS_ONLN)"} + + echo "Building Haiku sysroot for x86_64" + mkdir -p "$__RootfsDir/tmp" + cd "$__RootfsDir/tmp" + git clone -b hrev56235 https://review.haiku-os.org/haiku + git clone -b btrev43195 https://review.haiku-os.org/buildtools + cd "$__RootfsDir/tmp/buildtools" && git checkout 7487388f5110021d400b9f3b88e1a7f310dc066d + + # Fetch some unmerged patches + cd "$__RootfsDir/tmp/haiku" + ## Add development build profile (slimmer than nightly) + git fetch origin refs/changes/64/4164/1 && git -c commit.gpgsign=false cherry-pick FETCH_HEAD + + # Build jam + cd "$__RootfsDir/tmp/buildtools/jam" + make + + # Configure cross tools + echo "Building cross-compiler" + mkdir -p "$__RootfsDir/generated" + cd "$__RootfsDir/generated" + "$__RootfsDir/tmp/haiku/configure" -j"$JOBS" --sysroot "$__RootfsDir" --cross-tools-source "$__RootfsDir/tmp/buildtools" --build-cross-tools x86_64 + + # Build Haiku packages + echo "Building Haiku" + echo 'HAIKU_BUILD_PROFILE = "development-raw" ;' > UserProfileConfig + "$__RootfsDir/tmp/buildtools/jam/jam0" -j"$JOBS" -q 'package' 'Haiku' + + BaseUrl="https://depot.haiku-os.org/__api/v2/pkg/get-pkg" + + # Download additional packages + echo "Downloading additional required packages" + read -ra array <<<"$__HaikuPackages" + for package in "${array[@]}"; do + echo "Downloading $package..." + # API documented here: https://github.com/haiku/haikudepotserver/blob/master/haikudepotserver-api2/src/main/resources/api2/pkg.yaml#L60 + # The schema here: https://github.com/haiku/haikudepotserver/blob/master/haikudepotserver-api2/src/main/resources/api2/pkg.yaml#L598 + hpkgDownloadUrl="$(wget -qO- --post-data='{"name":"'"$package"'","repositorySourceCode":"haikuports_x86_64","versionType":"LATEST","naturalLanguageCode":"en"}' \ + --header='Content-Type:application/json' "$BaseUrl" | jq -r '.result.versions[].hpkgDownloadURL')" + wget -P "$__RootfsDir/generated/download" "$hpkgDownloadUrl" + done + + # Setup the sysroot + echo "Setting up sysroot and extracting needed packages" + mkdir -p "$__RootfsDir/boot/system" + for file in "$__RootfsDir/generated/objects/haiku/x86_64/packaging/packages/"*.hpkg; do + "$__RootfsDir/generated/objects/linux/x86_64/release/tools/package/package" extract -C "$__RootfsDir/boot/system" "$file" + done + for file in "$__RootfsDir/generated/download/"*.hpkg; do + "$__RootfsDir/generated/objects/linux/x86_64/release/tools/package/package" extract -C "$__RootfsDir/boot/system" "$file" + done + + # Cleaning up temporary files + echo "Cleaning up temporary files" + rm -rf "$__RootfsDir/tmp" + for name in "$__RootfsDir/generated/"*; do + if [[ "$name" =~ "cross-tools-" ]]; then + : # Keep the cross-compiler + else + rm -rf "$name" + fi + done +elif [[ -n "$__CodeName" ]]; then + qemu-debootstrap $__Keyring --arch "$__UbuntuArch" "$__CodeName" "$__RootfsDir" "$__UbuntuRepo" + cp "$__CrossDir/$__BuildArch/sources.list.$__CodeName" "$__RootfsDir/etc/apt/sources.list" + chroot "$__RootfsDir" apt-get update + chroot "$__RootfsDir" apt-get -f -y install + chroot "$__RootfsDir" apt-get -y install $__UbuntuPackages + chroot "$__RootfsDir" symlinks -cr /usr + chroot "$__RootfsDir" apt-get clean + + if [[ "$__SkipUnmount" == "0" ]]; then + umount "$__RootfsDir"/* || true + fi + + if [[ "$__BuildArch" == "armel" && "$__CodeName" == "jessie" ]]; then + pushd "$__RootfsDir" + patch -p1 < "$__CrossDir/$__BuildArch/armel.jessie.patch" + popd + fi +elif [[ "$__Tizen" == "tizen" ]]; then + ROOTFS_DIR="$__RootfsDir" "$__CrossDir/tizen-build-rootfs.sh" "$__BuildArch" +else + echo "Unsupported target platform." + usage; + exit 1 +fi diff --git a/eng/common/cross/ppc64le/sources.list.bionic b/eng/common/cross/ppc64le/sources.list.bionic new file mode 100644 index 0000000000000..2109557409576 --- /dev/null +++ b/eng/common/cross/ppc64le/sources.list.bionic @@ -0,0 +1,11 @@ +deb http://ports.ubuntu.com/ubuntu-ports/ bionic main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted +deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted + +deb http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted universe multiverse +deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted universe multiverse diff --git a/eng/common/cross/riscv64/sources.list.sid b/eng/common/cross/riscv64/sources.list.sid new file mode 100644 index 0000000000000..65f730d224caa --- /dev/null +++ b/eng/common/cross/riscv64/sources.list.sid @@ -0,0 +1 @@ +deb http://deb.debian.org/debian-ports sid main diff --git a/eng/common/cross/s390x/sources.list.bionic b/eng/common/cross/s390x/sources.list.bionic new file mode 100644 index 0000000000000..2109557409576 --- /dev/null +++ b/eng/common/cross/s390x/sources.list.bionic @@ -0,0 +1,11 @@ +deb http://ports.ubuntu.com/ubuntu-ports/ bionic main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted universe + +deb http://ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted +deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted + +deb http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted universe multiverse +deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted universe multiverse diff --git a/eng/common/cross/tizen-build-rootfs.sh b/eng/common/cross/tizen-build-rootfs.sh new file mode 100644 index 0000000000000..ac84173d44fc3 --- /dev/null +++ b/eng/common/cross/tizen-build-rootfs.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +set -e + +ARCH=$1 +LINK_ARCH=$ARCH + +case "$ARCH" in + arm) + TIZEN_ARCH="armv7hl" + ;; + armel) + TIZEN_ARCH="armv7l" + LINK_ARCH="arm" + ;; + arm64) + TIZEN_ARCH="aarch64" + ;; + x86) + TIZEN_ARCH="i686" + ;; + x64) + TIZEN_ARCH="x86_64" + LINK_ARCH="x86" + ;; + *) + echo "Unsupported architecture for tizen: $ARCH" + exit 1 +esac + +__CrossDir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +__TIZEN_CROSSDIR="$__CrossDir/${ARCH}/tizen" + +if [[ -z "$ROOTFS_DIR" ]]; then + echo "ROOTFS_DIR is not defined." + exit 1; +fi + +TIZEN_TMP_DIR=$ROOTFS_DIR/tizen_tmp +mkdir -p $TIZEN_TMP_DIR + +# Download files +echo ">>Start downloading files" +VERBOSE=1 $__CrossDir/tizen-fetch.sh $TIZEN_TMP_DIR $TIZEN_ARCH +echo "<>Start constructing Tizen rootfs" +TIZEN_RPM_FILES=`ls $TIZEN_TMP_DIR/*.rpm` +cd $ROOTFS_DIR +for f in $TIZEN_RPM_FILES; do + rpm2cpio $f | cpio -idm --quiet +done +echo "<>Start configuring Tizen rootfs" +ln -sfn asm-${LINK_ARCH} ./usr/include/asm +patch -p1 < $__TIZEN_CROSSDIR/tizen.patch +echo "</dev/null; then + VERBOSE=0 +fi + +Log() +{ + if [ $VERBOSE -ge $1 ]; then + echo ${@:2} + fi +} + +Inform() +{ + Log 1 -e "\x1B[0;34m$@\x1B[m" +} + +Debug() +{ + Log 2 -e "\x1B[0;32m$@\x1B[m" +} + +Error() +{ + >&2 Log 0 -e "\x1B[0;31m$@\x1B[m" +} + +Fetch() +{ + URL=$1 + FILE=$2 + PROGRESS=$3 + if [ $VERBOSE -ge 1 ] && [ $PROGRESS ]; then + CURL_OPT="--progress-bar" + else + CURL_OPT="--silent" + fi + curl $CURL_OPT $URL > $FILE +} + +hash curl 2> /dev/null || { Error "Require 'curl' Aborting."; exit 1; } +hash xmllint 2> /dev/null || { Error "Require 'xmllint' Aborting."; exit 1; } +hash sha256sum 2> /dev/null || { Error "Require 'sha256sum' Aborting."; exit 1; } + +TMPDIR=$1 +if [ ! -d $TMPDIR ]; then + TMPDIR=./tizen_tmp + Debug "Create temporary directory : $TMPDIR" + mkdir -p $TMPDIR +fi + +TIZEN_ARCH=$2 + +TIZEN_URL=http://download.tizen.org/snapshots/TIZEN/Tizen +BUILD_XML=build.xml +REPOMD_XML=repomd.xml +PRIMARY_XML=primary.xml +TARGET_URL="http://__not_initialized" + +Xpath_get() +{ + XPATH_RESULT='' + XPATH=$1 + XML_FILE=$2 + RESULT=$(xmllint --xpath $XPATH $XML_FILE) + if [[ -z ${RESULT// } ]]; then + Error "Can not find target from $XML_FILE" + Debug "Xpath = $XPATH" + exit 1 + fi + XPATH_RESULT=$RESULT +} + +fetch_tizen_pkgs_init() +{ + TARGET=$1 + PROFILE=$2 + Debug "Initialize TARGET=$TARGET, PROFILE=$PROFILE" + + TMP_PKG_DIR=$TMPDIR/tizen_${PROFILE}_pkgs + if [ -d $TMP_PKG_DIR ]; then rm -rf $TMP_PKG_DIR; fi + mkdir -p $TMP_PKG_DIR + + PKG_URL=$TIZEN_URL/$PROFILE/latest + + BUILD_XML_URL=$PKG_URL/$BUILD_XML + TMP_BUILD=$TMP_PKG_DIR/$BUILD_XML + TMP_REPOMD=$TMP_PKG_DIR/$REPOMD_XML + TMP_PRIMARY=$TMP_PKG_DIR/$PRIMARY_XML + TMP_PRIMARYGZ=${TMP_PRIMARY}.gz + + Fetch $BUILD_XML_URL $TMP_BUILD + + Debug "fetch $BUILD_XML_URL to $TMP_BUILD" + + TARGET_XPATH="//build/buildtargets/buildtarget[@name=\"$TARGET\"]/repo[@type=\"binary\"]/text()" + Xpath_get $TARGET_XPATH $TMP_BUILD + TARGET_PATH=$XPATH_RESULT + TARGET_URL=$PKG_URL/$TARGET_PATH + + REPOMD_URL=$TARGET_URL/repodata/repomd.xml + PRIMARY_XPATH='string(//*[local-name()="data"][@type="primary"]/*[local-name()="location"]/@href)' + + Fetch $REPOMD_URL $TMP_REPOMD + + Debug "fetch $REPOMD_URL to $TMP_REPOMD" + + Xpath_get $PRIMARY_XPATH $TMP_REPOMD + PRIMARY_XML_PATH=$XPATH_RESULT + PRIMARY_URL=$TARGET_URL/$PRIMARY_XML_PATH + + Fetch $PRIMARY_URL $TMP_PRIMARYGZ + + Debug "fetch $PRIMARY_URL to $TMP_PRIMARYGZ" + + gunzip $TMP_PRIMARYGZ + + Debug "unzip $TMP_PRIMARYGZ to $TMP_PRIMARY" +} + +fetch_tizen_pkgs() +{ + ARCH=$1 + PACKAGE_XPATH_TPL='string(//*[local-name()="metadata"]/*[local-name()="package"][*[local-name()="name"][text()="_PKG_"]][*[local-name()="arch"][text()="_ARCH_"]]/*[local-name()="location"]/@href)' + + PACKAGE_CHECKSUM_XPATH_TPL='string(//*[local-name()="metadata"]/*[local-name()="package"][*[local-name()="name"][text()="_PKG_"]][*[local-name()="arch"][text()="_ARCH_"]]/*[local-name()="checksum"]/text())' + + for pkg in ${@:2} + do + Inform "Fetching... $pkg" + XPATH=${PACKAGE_XPATH_TPL/_PKG_/$pkg} + XPATH=${XPATH/_ARCH_/$ARCH} + Xpath_get $XPATH $TMP_PRIMARY + PKG_PATH=$XPATH_RESULT + + XPATH=${PACKAGE_CHECKSUM_XPATH_TPL/_PKG_/$pkg} + XPATH=${XPATH/_ARCH_/$ARCH} + Xpath_get $XPATH $TMP_PRIMARY + CHECKSUM=$XPATH_RESULT + + PKG_URL=$TARGET_URL/$PKG_PATH + PKG_FILE=$(basename $PKG_PATH) + PKG_PATH=$TMPDIR/$PKG_FILE + + Debug "Download $PKG_URL to $PKG_PATH" + Fetch $PKG_URL $PKG_PATH true + + echo "$CHECKSUM $PKG_PATH" | sha256sum -c - > /dev/null + if [ $? -ne 0 ]; then + Error "Fail to fetch $PKG_URL to $PKG_PATH" + Debug "Checksum = $CHECKSUM" + exit 1 + fi + done +} + +Inform "Initialize ${TIZEN_ARCH} base" +fetch_tizen_pkgs_init standard Tizen-Base +Inform "fetch common packages" +fetch_tizen_pkgs ${TIZEN_ARCH} gcc gcc-devel-static glibc glibc-devel libicu libicu-devel libatomic linux-glibc-devel keyutils keyutils-devel libkeyutils +Inform "fetch coreclr packages" +fetch_tizen_pkgs ${TIZEN_ARCH} lldb lldb-devel libgcc libstdc++ libstdc++-devel libunwind libunwind-devel lttng-ust-devel lttng-ust userspace-rcu-devel userspace-rcu +Inform "fetch corefx packages" +fetch_tizen_pkgs ${TIZEN_ARCH} libcom_err libcom_err-devel zlib zlib-devel libopenssl11 libopenssl1.1-devel krb5 krb5-devel + +Inform "Initialize standard unified" +fetch_tizen_pkgs_init standard Tizen-Unified +Inform "fetch corefx packages" +fetch_tizen_pkgs ${TIZEN_ARCH} gssdp gssdp-devel tizen-release + diff --git a/eng/common/cross/toolchain.cmake b/eng/common/cross/toolchain.cmake new file mode 100644 index 0000000000000..ccfb9951a52cb --- /dev/null +++ b/eng/common/cross/toolchain.cmake @@ -0,0 +1,347 @@ +set(CROSS_ROOTFS $ENV{ROOTFS_DIR}) + +# reset platform variables (e.g. cmake 3.25 sets LINUX=1) +unset(LINUX) +unset(FREEBSD) +unset(ILLUMOS) +unset(ANDROID) +unset(TIZEN) + +set(TARGET_ARCH_NAME $ENV{TARGET_BUILD_ARCH}) +if(EXISTS ${CROSS_ROOTFS}/bin/freebsd-version) + set(CMAKE_SYSTEM_NAME FreeBSD) + set(FREEBSD 1) +elseif(EXISTS ${CROSS_ROOTFS}/usr/platform/i86pc) + set(CMAKE_SYSTEM_NAME SunOS) + set(ILLUMOS 1) +elseif(EXISTS ${CROSS_ROOTFS}/boot/system/develop/headers/config/HaikuConfig.h) + set(CMAKE_SYSTEM_NAME Haiku) +else() + set(CMAKE_SYSTEM_NAME Linux) + set(LINUX 1) +endif() +set(CMAKE_SYSTEM_VERSION 1) + +if(EXISTS ${CROSS_ROOTFS}/etc/tizen-release) + set(TIZEN 1) +elseif(EXISTS ${CROSS_ROOTFS}/android_platform) + set(ANDROID 1) +endif() + +if(TARGET_ARCH_NAME STREQUAL "arm") + set(CMAKE_SYSTEM_PROCESSOR armv7l) + if(EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/armv7-alpine-linux-musleabihf) + set(TOOLCHAIN "armv7-alpine-linux-musleabihf") + elseif(EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/armv6-alpine-linux-musleabihf) + set(TOOLCHAIN "armv6-alpine-linux-musleabihf") + else() + set(TOOLCHAIN "arm-linux-gnueabihf") + endif() + if(TIZEN) + set(TIZEN_TOOLCHAIN "armv7hl-tizen-linux-gnueabihf/9.2.0") + endif() +elseif(TARGET_ARCH_NAME STREQUAL "arm64") + set(CMAKE_SYSTEM_PROCESSOR aarch64) + if(EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/aarch64-alpine-linux-musl) + set(TOOLCHAIN "aarch64-alpine-linux-musl") + elseif(LINUX) + set(TOOLCHAIN "aarch64-linux-gnu") + if(TIZEN) + set(TIZEN_TOOLCHAIN "aarch64-tizen-linux-gnu/9.2.0") + endif() + elseif(FREEBSD) + set(triple "aarch64-unknown-freebsd12") + endif() +elseif(TARGET_ARCH_NAME STREQUAL "armel") + set(CMAKE_SYSTEM_PROCESSOR armv7l) + set(TOOLCHAIN "arm-linux-gnueabi") + if(TIZEN) + set(TIZEN_TOOLCHAIN "armv7l-tizen-linux-gnueabi/9.2.0") + endif() +elseif(TARGET_ARCH_NAME STREQUAL "armv6") + set(CMAKE_SYSTEM_PROCESSOR armv6l) + if(EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/armv6-alpine-linux-musleabihf) + set(TOOLCHAIN "armv6-alpine-linux-musleabihf") + else() + set(TOOLCHAIN "arm-linux-gnueabihf") + endif() +elseif(TARGET_ARCH_NAME STREQUAL "ppc64le") + set(CMAKE_SYSTEM_PROCESSOR ppc64le) + set(TOOLCHAIN "powerpc64le-linux-gnu") +elseif(TARGET_ARCH_NAME STREQUAL "riscv64") + set(CMAKE_SYSTEM_PROCESSOR riscv64) + set(TOOLCHAIN "riscv64-linux-gnu") +elseif(TARGET_ARCH_NAME STREQUAL "s390x") + set(CMAKE_SYSTEM_PROCESSOR s390x) + set(TOOLCHAIN "s390x-linux-gnu") +elseif(TARGET_ARCH_NAME STREQUAL "x64") + set(CMAKE_SYSTEM_PROCESSOR x86_64) + if(LINUX) + set(TOOLCHAIN "x86_64-linux-gnu") + if(TIZEN) + set(TIZEN_TOOLCHAIN "x86_64-tizen-linux-gnu/9.2.0") + endif() + elseif(FREEBSD) + set(triple "x86_64-unknown-freebsd12") + elseif(ILLUMOS) + set(TOOLCHAIN "x86_64-illumos") + elseif(HAIKU) + set(TOOLCHAIN "x64_64-unknown-haiku") + endif() +elseif(TARGET_ARCH_NAME STREQUAL "x86") + set(CMAKE_SYSTEM_PROCESSOR i686) + set(TOOLCHAIN "i686-linux-gnu") + if(TIZEN) + set(TIZEN_TOOLCHAIN "i586-tizen-linux-gnu/9.2.0") + endif() +else() + message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only arm, arm64, armel, armv6, ppc64le, riscv64, s390x, x64 and x86 are supported!") +endif() + +if(DEFINED ENV{TOOLCHAIN}) + set(TOOLCHAIN $ENV{TOOLCHAIN}) +endif() + +# Specify include paths +if(TIZEN) + if(TARGET_ARCH_NAME STREQUAL "arm") + include_directories(SYSTEM ${CROSS_ROOTFS}/usr/lib/gcc/${TIZEN_TOOLCHAIN}/include/c++/) + include_directories(SYSTEM ${CROSS_ROOTFS}/usr/lib/gcc/${TIZEN_TOOLCHAIN}/include/c++/armv7hl-tizen-linux-gnueabihf) + endif() + if(TARGET_ARCH_NAME STREQUAL "armel") + include_directories(SYSTEM ${CROSS_ROOTFS}/usr/lib/gcc/${TIZEN_TOOLCHAIN}/include/c++/) + include_directories(SYSTEM ${CROSS_ROOTFS}/usr/lib/gcc/${TIZEN_TOOLCHAIN}/include/c++/armv7l-tizen-linux-gnueabi) + endif() + if(TARGET_ARCH_NAME STREQUAL "arm64") + include_directories(SYSTEM ${CROSS_ROOTFS}/usr/lib64/gcc/${TIZEN_TOOLCHAIN}/include/c++/) + include_directories(SYSTEM ${CROSS_ROOTFS}/usr/lib64/gcc/${TIZEN_TOOLCHAIN}/include/c++/aarch64-tizen-linux-gnu) + endif() + if(TARGET_ARCH_NAME STREQUAL "x86") + include_directories(SYSTEM ${CROSS_ROOTFS}/usr/lib/gcc/${TIZEN_TOOLCHAIN}/include/c++/) + include_directories(SYSTEM ${CROSS_ROOTFS}/usr/lib/gcc/${TIZEN_TOOLCHAIN}/include/c++/i586-tizen-linux-gnu) + endif() + if(TARGET_ARCH_NAME STREQUAL "x64") + include_directories(SYSTEM ${CROSS_ROOTFS}/usr/lib64/gcc/${TIZEN_TOOLCHAIN}/include/c++/) + include_directories(SYSTEM ${CROSS_ROOTFS}/usr/lib64/gcc/${TIZEN_TOOLCHAIN}/include/c++/x86_64-tizen-linux-gnu) + endif() +endif() + +if(ANDROID) + if(TARGET_ARCH_NAME STREQUAL "arm") + set(ANDROID_ABI armeabi-v7a) + elseif(TARGET_ARCH_NAME STREQUAL "arm64") + set(ANDROID_ABI arm64-v8a) + endif() + + # extract platform number required by the NDK's toolchain + file(READ "${CROSS_ROOTFS}/android_platform" RID_FILE_CONTENTS) + string(REPLACE "RID=" "" ANDROID_RID "${RID_FILE_CONTENTS}") + string(REGEX REPLACE ".*\\.([0-9]+)-.*" "\\1" ANDROID_PLATFORM "${ANDROID_RID}") + + set(ANDROID_TOOLCHAIN clang) + set(FEATURE_EVENT_TRACE 0) # disable event trace as there is no lttng-ust package in termux repository + set(CMAKE_SYSTEM_LIBRARY_PATH "${CROSS_ROOTFS}/usr/lib") + set(CMAKE_SYSTEM_INCLUDE_PATH "${CROSS_ROOTFS}/usr/include") + + # include official NDK toolchain script + include(${CROSS_ROOTFS}/../build/cmake/android.toolchain.cmake) +elseif(FREEBSD) + # we cross-compile by instructing clang + set(CMAKE_C_COMPILER_TARGET ${triple}) + set(CMAKE_CXX_COMPILER_TARGET ${triple}) + set(CMAKE_ASM_COMPILER_TARGET ${triple}) + set(CMAKE_SYSROOT "${CROSS_ROOTFS}") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fuse-ld=lld") +elseif(ILLUMOS) + set(CMAKE_SYSROOT "${CROSS_ROOTFS}") + + include_directories(SYSTEM ${CROSS_ROOTFS}/include) + + set(TOOLSET_PREFIX ${TOOLCHAIN}-) + function(locate_toolchain_exec exec var) + string(TOUPPER ${exec} EXEC_UPPERCASE) + if(NOT "$ENV{CLR_${EXEC_UPPERCASE}}" STREQUAL "") + set(${var} "$ENV{CLR_${EXEC_UPPERCASE}}" PARENT_SCOPE) + return() + endif() + + find_program(EXEC_LOCATION_${exec} + NAMES + "${TOOLSET_PREFIX}${exec}${CLR_CMAKE_COMPILER_FILE_NAME_VERSION}" + "${TOOLSET_PREFIX}${exec}") + + if (EXEC_LOCATION_${exec} STREQUAL "EXEC_LOCATION_${exec}-NOTFOUND") + message(FATAL_ERROR "Unable to find toolchain executable. Name: ${exec}, Prefix: ${TOOLSET_PREFIX}.") + endif() + set(${var} ${EXEC_LOCATION_${exec}} PARENT_SCOPE) + endfunction() + + set(CMAKE_SYSTEM_PREFIX_PATH "${CROSS_ROOTFS}") + + locate_toolchain_exec(gcc CMAKE_C_COMPILER) + locate_toolchain_exec(g++ CMAKE_CXX_COMPILER) + + set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} -lssp") + set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -lssp") +elseif(HAIKU) + set(CMAKE_SYSROOT "${CROSS_ROOTFS}") + + set(TOOLSET_PREFIX ${TOOLCHAIN}-) + function(locate_toolchain_exec exec var) + string(TOUPPER ${exec} EXEC_UPPERCASE) + if(NOT "$ENV{CLR_${EXEC_UPPERCASE}}" STREQUAL "") + set(${var} "$ENV{CLR_${EXEC_UPPERCASE}}" PARENT_SCOPE) + return() + endif() + + set(SEARCH_PATH "${CROSS_ROOTFS}/generated/cross-tools-x86_64/bin") + + find_program(EXEC_LOCATION_${exec} + PATHS ${SEARCH_PATH} + NAMES + "${TOOLSET_PREFIX}${exec}${CLR_CMAKE_COMPILER_FILE_NAME_VERSION}" + "${TOOLSET_PREFIX}${exec}") + + if (EXEC_LOCATION_${exec} STREQUAL "EXEC_LOCATION_${exec}-NOTFOUND") + message(FATAL_ERROR "Unable to find toolchain executable. Name: ${exec}, Prefix: ${TOOLSET_PREFIX}.") + endif() + set(${var} ${EXEC_LOCATION_${exec}} PARENT_SCOPE) + endfunction() + + set(CMAKE_SYSTEM_PREFIX_PATH "${CROSS_ROOTFS}") + + locate_toolchain_exec(gcc CMAKE_C_COMPILER) + locate_toolchain_exec(g++ CMAKE_CXX_COMPILER) + + set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} -lssp") + set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -lssp") + + # let CMake set up the correct search paths + include(Platform/Haiku) +else() + set(CMAKE_SYSROOT "${CROSS_ROOTFS}") + + set(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN "${CROSS_ROOTFS}/usr") + set(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN "${CROSS_ROOTFS}/usr") + set(CMAKE_ASM_COMPILER_EXTERNAL_TOOLCHAIN "${CROSS_ROOTFS}/usr") +endif() + +# Specify link flags + +function(add_toolchain_linker_flag Flag) + set(Config "${ARGV1}") + set(CONFIG_SUFFIX "") + if (NOT Config STREQUAL "") + set(CONFIG_SUFFIX "_${Config}") + endif() + set("CMAKE_EXE_LINKER_FLAGS${CONFIG_SUFFIX}_INIT" "${CMAKE_EXE_LINKER_FLAGS${CONFIG_SUFFIX}_INIT} ${Flag}" PARENT_SCOPE) + set("CMAKE_SHARED_LINKER_FLAGS${CONFIG_SUFFIX}_INIT" "${CMAKE_SHARED_LINKER_FLAGS${CONFIG_SUFFIX}_INIT} ${Flag}" PARENT_SCOPE) +endfunction() + +if(LINUX) + add_toolchain_linker_flag("-Wl,--rpath-link=${CROSS_ROOTFS}/lib/${TOOLCHAIN}") + add_toolchain_linker_flag("-Wl,--rpath-link=${CROSS_ROOTFS}/usr/lib/${TOOLCHAIN}") +endif() + +if(TARGET_ARCH_NAME MATCHES "^(arm|armel)$") + if(TIZEN) + add_toolchain_linker_flag("-B${CROSS_ROOTFS}/usr/lib/gcc/${TIZEN_TOOLCHAIN}") + add_toolchain_linker_flag("-L${CROSS_ROOTFS}/lib") + add_toolchain_linker_flag("-L${CROSS_ROOTFS}/usr/lib") + add_toolchain_linker_flag("-L${CROSS_ROOTFS}/usr/lib/gcc/${TIZEN_TOOLCHAIN}") + endif() +elseif(TARGET_ARCH_NAME MATCHES "^(arm64|x64)$") + if(TIZEN) + add_toolchain_linker_flag("-B${CROSS_ROOTFS}/usr/lib64/gcc/${TIZEN_TOOLCHAIN}") + add_toolchain_linker_flag("-L${CROSS_ROOTFS}/lib64") + add_toolchain_linker_flag("-L${CROSS_ROOTFS}/usr/lib64") + add_toolchain_linker_flag("-L${CROSS_ROOTFS}/usr/lib64/gcc/${TIZEN_TOOLCHAIN}") + + add_toolchain_linker_flag("-Wl,--rpath-link=${CROSS_ROOTFS}/lib64") + add_toolchain_linker_flag("-Wl,--rpath-link=${CROSS_ROOTFS}/usr/lib64") + add_toolchain_linker_flag("-Wl,--rpath-link=${CROSS_ROOTFS}/usr/lib64/gcc/${TIZEN_TOOLCHAIN}") + endif() +elseif(TARGET_ARCH_NAME STREQUAL "x86") + add_toolchain_linker_flag(-m32) + + if(TIZEN) + add_toolchain_linker_flag("-B${CROSS_ROOTFS}/usr/lib/gcc/${TIZEN_TOOLCHAIN}") + add_toolchain_linker_flag("-L${CROSS_ROOTFS}/lib") + add_toolchain_linker_flag("-L${CROSS_ROOTFS}/usr/lib") + add_toolchain_linker_flag("-L${CROSS_ROOTFS}/usr/lib/gcc/${TIZEN_TOOLCHAIN}") + endif() +elseif(ILLUMOS) + add_toolchain_linker_flag("-L${CROSS_ROOTFS}/lib/amd64") + add_toolchain_linker_flag("-L${CROSS_ROOTFS}/usr/amd64/lib") +endif() + +# Specify compile options + +if((TARGET_ARCH_NAME MATCHES "^(arm|arm64|armel|armv6|ppc64le|riscv64|s390x)$" AND NOT ANDROID AND NOT FREEBSD) OR ILLUMOS OR HAIKU) + set(CMAKE_C_COMPILER_TARGET ${TOOLCHAIN}) + set(CMAKE_CXX_COMPILER_TARGET ${TOOLCHAIN}) + set(CMAKE_ASM_COMPILER_TARGET ${TOOLCHAIN}) +endif() + +if(TARGET_ARCH_NAME MATCHES "^(arm|armel)$") + add_compile_options(-mthumb) + if (NOT DEFINED CLR_ARM_FPU_TYPE) + set (CLR_ARM_FPU_TYPE vfpv3) + endif (NOT DEFINED CLR_ARM_FPU_TYPE) + + add_compile_options (-mfpu=${CLR_ARM_FPU_TYPE}) + if (NOT DEFINED CLR_ARM_FPU_CAPABILITY) + set (CLR_ARM_FPU_CAPABILITY 0x7) + endif (NOT DEFINED CLR_ARM_FPU_CAPABILITY) + + add_definitions (-DCLR_ARM_FPU_CAPABILITY=${CLR_ARM_FPU_CAPABILITY}) + + if(TARGET_ARCH_NAME STREQUAL "armel") + add_compile_options(-mfloat-abi=softfp) + endif() +elseif(TARGET_ARCH_NAME STREQUAL "x86") + add_compile_options(-m32) + add_compile_options(-Wno-error=unused-command-line-argument) +endif() + +if(TIZEN) + if(TARGET_ARCH_NAME MATCHES "^(arm|armel|arm64|x86)$") + add_compile_options(-Wno-deprecated-declarations) # compile-time option + add_compile_options(-D__extern_always_inline=inline) # compile-time option + endif() +endif() + +# Set LLDB include and library paths for builds that need lldb. +if(TARGET_ARCH_NAME MATCHES "^(arm|armel|x86)$") + if(TARGET_ARCH_NAME STREQUAL "x86") + set(LLVM_CROSS_DIR "$ENV{LLVM_CROSS_HOME}") + else() # arm/armel case + set(LLVM_CROSS_DIR "$ENV{LLVM_ARM_HOME}") + endif() + if(LLVM_CROSS_DIR) + set(WITH_LLDB_LIBS "${LLVM_CROSS_DIR}/lib/" CACHE STRING "") + set(WITH_LLDB_INCLUDES "${LLVM_CROSS_DIR}/include" CACHE STRING "") + set(LLDB_H "${WITH_LLDB_INCLUDES}" CACHE STRING "") + set(LLDB "${LLVM_CROSS_DIR}/lib/liblldb.so" CACHE STRING "") + else() + if(TARGET_ARCH_NAME STREQUAL "x86") + set(WITH_LLDB_LIBS "${CROSS_ROOTFS}/usr/lib/i386-linux-gnu" CACHE STRING "") + set(CHECK_LLVM_DIR "${CROSS_ROOTFS}/usr/lib/llvm-3.8/include") + if(EXISTS "${CHECK_LLVM_DIR}" AND IS_DIRECTORY "${CHECK_LLVM_DIR}") + set(WITH_LLDB_INCLUDES "${CHECK_LLVM_DIR}") + else() + set(WITH_LLDB_INCLUDES "${CROSS_ROOTFS}/usr/lib/llvm-3.6/include") + endif() + else() # arm/armel case + set(WITH_LLDB_LIBS "${CROSS_ROOTFS}/usr/lib/${TOOLCHAIN}" CACHE STRING "") + set(WITH_LLDB_INCLUDES "${CROSS_ROOTFS}/usr/lib/llvm-3.6/include" CACHE STRING "") + endif() + endif() +endif() + +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) diff --git a/eng/common/cross/x64/tizen/tizen.patch b/eng/common/cross/x64/tizen/tizen.patch new file mode 100644 index 0000000000000..56fbc881095b3 --- /dev/null +++ b/eng/common/cross/x64/tizen/tizen.patch @@ -0,0 +1,9 @@ +diff -u -r a/usr/lib64/libc.so b/usr/lib64/libc.so +--- a/usr/lib64/libc.so 2016-12-30 23:00:08.284951863 +0900 ++++ b/usr/lib64/libc.so 2016-12-30 23:00:32.140951815 +0900 +@@ -2,4 +2,4 @@ + Use the shared library, but some functions are only in + the static library, so try that secondarily. */ + OUTPUT_FORMAT(elf64-x86-64) +-GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) ) ++GROUP ( libc.so.6 libc_nonshared.a AS_NEEDED ( ld-linux-x86-64.so.2 ) ) diff --git a/eng/common/cross/x86/sources.list.bionic b/eng/common/cross/x86/sources.list.bionic new file mode 100644 index 0000000000000..a71ccadcffaf8 --- /dev/null +++ b/eng/common/cross/x86/sources.list.bionic @@ -0,0 +1,11 @@ +deb http://archive.ubuntu.com/ubuntu/ bionic main restricted universe +deb-src http://archive.ubuntu.com/ubuntu/ bionic main restricted universe + +deb http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe +deb-src http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe + +deb http://archive.ubuntu.com/ubuntu/ bionic-backports main restricted +deb-src http://archive.ubuntu.com/ubuntu/ bionic-backports main restricted + +deb http://archive.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse +deb-src http://archive.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse diff --git a/eng/common/cross/x86/sources.list.focal b/eng/common/cross/x86/sources.list.focal new file mode 100644 index 0000000000000..99d5731330e79 --- /dev/null +++ b/eng/common/cross/x86/sources.list.focal @@ -0,0 +1,11 @@ +deb http://archive.ubuntu.com/ubuntu/ focal main restricted universe +deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted universe + +deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe +deb-src http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe + +deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted +deb-src http://archive.ubuntu.com/ubuntu/ focal-backports main restricted + +deb http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse +deb-src http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse diff --git a/eng/common/cross/x86/sources.list.jammy b/eng/common/cross/x86/sources.list.jammy new file mode 100644 index 0000000000000..af1c1feaeac1b --- /dev/null +++ b/eng/common/cross/x86/sources.list.jammy @@ -0,0 +1,11 @@ +deb http://archive.ubuntu.com/ubuntu/ jammy main restricted universe +deb-src http://archive.ubuntu.com/ubuntu/ jammy main restricted universe + +deb http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted universe +deb-src http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted universe + +deb http://archive.ubuntu.com/ubuntu/ jammy-backports main restricted +deb-src http://archive.ubuntu.com/ubuntu/ jammy-backports main restricted + +deb http://archive.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse +deb-src http://archive.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse diff --git a/eng/common/cross/x86/sources.list.xenial b/eng/common/cross/x86/sources.list.xenial new file mode 100644 index 0000000000000..ad9c5a0144ef0 --- /dev/null +++ b/eng/common/cross/x86/sources.list.xenial @@ -0,0 +1,11 @@ +deb http://archive.ubuntu.com/ubuntu/ xenial main restricted universe +deb-src http://archive.ubuntu.com/ubuntu/ xenial main restricted universe + +deb http://archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe +deb-src http://archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe + +deb http://archive.ubuntu.com/ubuntu/ xenial-backports main restricted +deb-src http://archive.ubuntu.com/ubuntu/ xenial-backports main restricted + +deb http://archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse +deb-src http://archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse diff --git a/eng/common/cross/x86/tizen/tizen.patch b/eng/common/cross/x86/tizen/tizen.patch new file mode 100644 index 0000000000000..f4fe8838ad668 --- /dev/null +++ b/eng/common/cross/x86/tizen/tizen.patch @@ -0,0 +1,9 @@ +diff -u -r a/usr/lib/libc.so b/usr/lib/libc.so +--- a/usr/lib/libc.so 2016-12-30 23:00:08.284951863 +0900 ++++ b/usr/lib/libc.so 2016-12-30 23:00:32.140951815 +0900 +@@ -2,4 +2,4 @@ + Use the shared library, but some functions are only in + the static library, so try that secondarily. */ + OUTPUT_FORMAT(elf32-i386) +-GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a AS_NEEDED ( /lib/ld-linux.so.2 ) ) ++GROUP ( libc.so.6 libc_nonshared.a AS_NEEDED ( ld-linux.so.2 ) ) diff --git a/eng/common/darc-init.ps1 b/eng/common/darc-init.ps1 new file mode 100644 index 0000000000000..435e7641341b1 --- /dev/null +++ b/eng/common/darc-init.ps1 @@ -0,0 +1,47 @@ +param ( + $darcVersion = $null, + $versionEndpoint = 'https://maestro-prod.westus2.cloudapp.azure.com/api/assets/darc-version?api-version=2019-01-16', + $verbosity = 'minimal', + $toolpath = $null +) + +. $PSScriptRoot\tools.ps1 + +function InstallDarcCli ($darcVersion, $toolpath) { + $darcCliPackageName = 'microsoft.dotnet.darc' + + $dotnetRoot = InitializeDotNetCli -install:$true + $dotnet = "$dotnetRoot\dotnet.exe" + $toolList = & "$dotnet" tool list -g + + if ($toolList -like "*$darcCliPackageName*") { + & "$dotnet" tool uninstall $darcCliPackageName -g + } + + # If the user didn't explicitly specify the darc version, + # query the Maestro API for the correct version of darc to install. + if (-not $darcVersion) { + $darcVersion = $(Invoke-WebRequest -Uri $versionEndpoint -UseBasicParsing).Content + } + + $arcadeServicesSource = 'https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json' + + Write-Host "Installing Darc CLI version $darcVersion..." + Write-Host 'You may need to restart your command window if this is the first dotnet tool you have installed.' + if (-not $toolpath) { + Write-Host "'$dotnet' tool install $darcCliPackageName --version $darcVersion --add-source '$arcadeServicesSource' -v $verbosity -g" + & "$dotnet" tool install $darcCliPackageName --version $darcVersion --add-source "$arcadeServicesSource" -v $verbosity -g + }else { + Write-Host "'$dotnet' tool install $darcCliPackageName --version $darcVersion --add-source '$arcadeServicesSource' -v $verbosity --tool-path '$toolpath'" + & "$dotnet" tool install $darcCliPackageName --version $darcVersion --add-source "$arcadeServicesSource" -v $verbosity --tool-path "$toolpath" + } +} + +try { + InstallDarcCli $darcVersion $toolpath +} +catch { + Write-Host $_.ScriptStackTrace + Write-PipelineTelemetryError -Category 'Darc' -Message $_ + ExitWithExitCode 1 +} \ No newline at end of file diff --git a/eng/common/darc-init.sh b/eng/common/darc-init.sh new file mode 100755 index 0000000000000..84c1d0cc2e75a --- /dev/null +++ b/eng/common/darc-init.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash + +source="${BASH_SOURCE[0]}" +darcVersion='' +versionEndpoint='https://maestro-prod.westus2.cloudapp.azure.com/api/assets/darc-version?api-version=2019-01-16' +verbosity='minimal' + +while [[ $# > 0 ]]; do + opt="$(echo "$1" | tr "[:upper:]" "[:lower:]")" + case "$opt" in + --darcversion) + darcVersion=$2 + shift + ;; + --versionendpoint) + versionEndpoint=$2 + shift + ;; + --verbosity) + verbosity=$2 + shift + ;; + --toolpath) + toolpath=$2 + shift + ;; + *) + echo "Invalid argument: $1" + usage + exit 1 + ;; + esac + + shift +done + +# resolve $source until the file is no longer a symlink +while [[ -h "$source" ]]; do + scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + source="$(readlink "$source")" + # if $source was a relative symlink, we need to resolve it relative to the path where the + # symlink file was located + [[ $source != /* ]] && source="$scriptroot/$source" +done +scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + +. "$scriptroot/tools.sh" + +if [ -z "$darcVersion" ]; then + darcVersion=$(curl -X GET "$versionEndpoint" -H "accept: text/plain") +fi + +function InstallDarcCli { + local darc_cli_package_name="microsoft.dotnet.darc" + + InitializeDotNetCli true + local dotnet_root=$_InitializeDotNetCli + + if [ -z "$toolpath" ]; then + local tool_list=$($dotnet_root/dotnet tool list -g) + if [[ $tool_list = *$darc_cli_package_name* ]]; then + echo $($dotnet_root/dotnet tool uninstall $darc_cli_package_name -g) + fi + else + local tool_list=$($dotnet_root/dotnet tool list --tool-path "$toolpath") + if [[ $tool_list = *$darc_cli_package_name* ]]; then + echo $($dotnet_root/dotnet tool uninstall $darc_cli_package_name --tool-path "$toolpath") + fi + fi + + local arcadeServicesSource="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" + + echo "Installing Darc CLI version $darcVersion..." + echo "You may need to restart your command shell if this is the first dotnet tool you have installed." + if [ -z "$toolpath" ]; then + echo $($dotnet_root/dotnet tool install $darc_cli_package_name --version $darcVersion --add-source "$arcadeServicesSource" -v $verbosity -g) + else + echo $($dotnet_root/dotnet tool install $darc_cli_package_name --version $darcVersion --add-source "$arcadeServicesSource" -v $verbosity --tool-path "$toolpath") + fi +} + +InstallDarcCli diff --git a/eng/common/dotnet-install.cmd b/eng/common/dotnet-install.cmd new file mode 100644 index 0000000000000..b1c2642e76f72 --- /dev/null +++ b/eng/common/dotnet-install.cmd @@ -0,0 +1,2 @@ +@echo off +powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0dotnet-install.ps1""" %*" \ No newline at end of file diff --git a/eng/common/dotnet-install.ps1 b/eng/common/dotnet-install.ps1 new file mode 100644 index 0000000000000..811f0f717f736 --- /dev/null +++ b/eng/common/dotnet-install.ps1 @@ -0,0 +1,28 @@ +[CmdletBinding(PositionalBinding=$false)] +Param( + [string] $verbosity = 'minimal', + [string] $architecture = '', + [string] $version = 'Latest', + [string] $runtime = 'dotnet', + [string] $RuntimeSourceFeed = '', + [string] $RuntimeSourceFeedKey = '' +) + +. $PSScriptRoot\tools.ps1 + +$dotnetRoot = Join-Path $RepoRoot '.dotnet' + +$installdir = $dotnetRoot +try { + if ($architecture -and $architecture.Trim() -eq 'x86') { + $installdir = Join-Path $installdir 'x86' + } + InstallDotNet $installdir $version $architecture $runtime $true -RuntimeSourceFeed $RuntimeSourceFeed -RuntimeSourceFeedKey $RuntimeSourceFeedKey +} +catch { + Write-Host $_.ScriptStackTrace + Write-PipelineTelemetryError -Category 'InitializeToolset' -Message $_ + ExitWithExitCode 1 +} + +ExitWithExitCode 0 diff --git a/eng/common/dotnet-install.sh b/eng/common/dotnet-install.sh new file mode 100755 index 0000000000000..abd045a3247f0 --- /dev/null +++ b/eng/common/dotnet-install.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash + +source="${BASH_SOURCE[0]}" +# resolve $source until the file is no longer a symlink +while [[ -h "$source" ]]; do + scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + source="$(readlink "$source")" + # if $source was a relative symlink, we need to resolve it relative to the path where the + # symlink file was located + [[ $source != /* ]] && source="$scriptroot/$source" +done +scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + +. "$scriptroot/tools.sh" + +version='Latest' +architecture='' +runtime='dotnet' +runtimeSourceFeed='' +runtimeSourceFeedKey='' +while [[ $# > 0 ]]; do + opt="$(echo "$1" | tr "[:upper:]" "[:lower:]")" + case "$opt" in + -version|-v) + shift + version="$1" + ;; + -architecture|-a) + shift + architecture="$1" + ;; + -runtime|-r) + shift + runtime="$1" + ;; + -runtimesourcefeed) + shift + runtimeSourceFeed="$1" + ;; + -runtimesourcefeedkey) + shift + runtimeSourceFeedKey="$1" + ;; + *) + Write-PipelineTelemetryError -Category 'Build' -Message "Invalid argument: $1" + exit 1 + ;; + esac + shift +done + +# Use uname to determine what the CPU is, see https://en.wikipedia.org/wiki/Uname#Examples +cpuname=$(uname -m) +case $cpuname in + arm64|aarch64) + buildarch=arm64 + ;; + loongarch64) + buildarch=loongarch64 + ;; + amd64|x86_64) + buildarch=x64 + ;; + armv*l) + buildarch=arm + ;; + i[3-6]86) + buildarch=x86 + ;; + *) + echo "Unknown CPU $cpuname detected, treating it as x64" + buildarch=x64 + ;; +esac + +dotnetRoot="${repo_root}.dotnet" +if [[ $architecture != "" ]] && [[ $architecture != $buildarch ]]; then + dotnetRoot="$dotnetRoot/$architecture" +fi + +InstallDotNet $dotnetRoot $version "$architecture" $runtime true $runtimeSourceFeed $runtimeSourceFeedKey || { + local exit_code=$? + Write-PipelineTelemetryError -Category 'InitializeToolset' -Message "dotnet-install.sh failed (exit code '$exit_code')." >&2 + ExitWithExitCode $exit_code +} + +ExitWithExitCode 0 diff --git a/eng/common/enable-cross-org-publishing.ps1 b/eng/common/enable-cross-org-publishing.ps1 new file mode 100644 index 0000000000000..da09da4f1fc44 --- /dev/null +++ b/eng/common/enable-cross-org-publishing.ps1 @@ -0,0 +1,13 @@ +param( + [string] $token +) + + +. $PSScriptRoot\pipeline-logging-functions.ps1 + +# Write-PipelineSetVariable will no-op if a variable named $ci is not defined +# Since this script is only ever called in AzDO builds, just universally set it +$ci = $true + +Write-PipelineSetVariable -Name 'VSS_NUGET_ACCESSTOKEN' -Value $token -IsMultiJobVariable $false +Write-PipelineSetVariable -Name 'VSS_NUGET_URI_PREFIXES' -Value 'https://dnceng.pkgs.visualstudio.com/;https://pkgs.dev.azure.com/dnceng/;https://devdiv.pkgs.visualstudio.com/;https://pkgs.dev.azure.com/devdiv/' -IsMultiJobVariable $false diff --git a/eng/common/generate-locproject.ps1 b/eng/common/generate-locproject.ps1 new file mode 100644 index 0000000000000..524aaa57f2b74 --- /dev/null +++ b/eng/common/generate-locproject.ps1 @@ -0,0 +1,189 @@ +Param( + [Parameter(Mandatory=$true)][string] $SourcesDirectory, # Directory where source files live; if using a Localize directory it should live in here + [string] $LanguageSet = 'VS_Main_Languages', # Language set to be used in the LocProject.json + [switch] $UseCheckedInLocProjectJson, # When set, generates a LocProject.json and compares it to one that already exists in the repo; otherwise just generates one + [switch] $CreateNeutralXlfs # Creates neutral xlf files. Only set to false when running locally +) + +# Generates LocProject.json files for the OneLocBuild task. OneLocBuildTask is described here: +# https://ceapex.visualstudio.com/CEINTL/_wiki/wikis/CEINTL.wiki/107/Localization-with-OneLocBuild-Task + +Set-StrictMode -Version 2.0 +$ErrorActionPreference = "Stop" +. $PSScriptRoot\pipeline-logging-functions.ps1 + +$exclusionsFilePath = "$SourcesDirectory\eng\Localize\LocExclusions.json" +$exclusions = @{ Exclusions = @() } +if (Test-Path -Path $exclusionsFilePath) +{ + $exclusions = Get-Content "$exclusionsFilePath" | ConvertFrom-Json +} + +Push-Location "$SourcesDirectory" # push location for Resolve-Path -Relative to work + +# Template files +$jsonFiles = @() +$jsonTemplateFiles = Get-ChildItem -Recurse -Path "$SourcesDirectory" | Where-Object { $_.FullName -Match "\.template\.config\\localize\\.+\.en\.json" } # .NET templating pattern +$jsonTemplateFiles | ForEach-Object { + $null = $_.Name -Match "(.+)\.[\w-]+\.json" # matches '[filename].[langcode].json + + $destinationFile = "$($_.Directory.FullName)\$($Matches.1).json" + $jsonFiles += Copy-Item "$($_.FullName)" -Destination $destinationFile -PassThru +} + +$jsonWinformsTemplateFiles = Get-ChildItem -Recurse -Path "$SourcesDirectory" | Where-Object { $_.FullName -Match "en\\strings\.json" } # current winforms pattern + +$wxlFiles = Get-ChildItem -Recurse -Path "$SourcesDirectory" | Where-Object { $_.FullName -Match "\\.+\.wxl" -And -Not( $_.Directory.Name -Match "\d{4}" ) } # localized files live in four digit lang ID directories; this excludes them +if (-not $wxlFiles) { + $wxlEnFiles = Get-ChildItem -Recurse -Path "$SourcesDirectory" | Where-Object { $_.FullName -Match "\\1033\\.+\.wxl" } # pick up en files (1033 = en) specifically so we can copy them to use as the neutral xlf files + if ($wxlEnFiles) { + $wxlFiles = @() + $wxlEnFiles | ForEach-Object { + $destinationFile = "$($_.Directory.Parent.FullName)\$($_.Name)" + $wxlFiles += Copy-Item "$($_.FullName)" -Destination $destinationFile -PassThru + } + } +} + +$macosHtmlEnFiles = Get-ChildItem -Recurse -Path "$SourcesDirectory" | Where-Object { $_.FullName -Match "en\.lproj\\.+\.html$" } # add installer HTML files +$macosHtmlFiles = @() +if ($macosHtmlEnFiles) { + $macosHtmlEnFiles | ForEach-Object { + $destinationFile = "$($_.Directory.Parent.FullName)\$($_.Name)" + $macosHtmlFiles += Copy-Item "$($_.FullName)" -Destination $destinationFile -PassThru + } +} + +$xlfFiles = @() + +$allXlfFiles = Get-ChildItem -Recurse -Path "$SourcesDirectory\*\*.xlf" +$langXlfFiles = @() +if ($allXlfFiles) { + $null = $allXlfFiles[0].FullName -Match "\.([\w-]+)\.xlf" # matches '[langcode].xlf' + $firstLangCode = $Matches.1 + $langXlfFiles = Get-ChildItem -Recurse -Path "$SourcesDirectory\*\*.$firstLangCode.xlf" +} +$langXlfFiles | ForEach-Object { + $null = $_.Name -Match "(.+)\.[\w-]+\.xlf" # matches '[filename].[langcode].xlf + + $destinationFile = "$($_.Directory.FullName)\$($Matches.1).xlf" + $xlfFiles += Copy-Item "$($_.FullName)" -Destination $destinationFile -PassThru +} + +$locFiles = $jsonFiles + $jsonWinformsTemplateFiles + $xlfFiles + +$locJson = @{ + Projects = @( + @{ + LanguageSet = $LanguageSet + LocItems = @( + $locFiles | ForEach-Object { + $outputPath = "$(($_.DirectoryName | Resolve-Path -Relative) + "\")" + $continue = $true + foreach ($exclusion in $exclusions.Exclusions) { + if ($_.FullName.Contains($exclusion)) + { + $continue = $false + } + } + $sourceFile = ($_.FullName | Resolve-Path -Relative) + if (!$CreateNeutralXlfs -and $_.Extension -eq '.xlf') { + Remove-Item -Path $sourceFile + } + if ($continue) + { + if ($_.Directory.Name -eq 'en' -and $_.Extension -eq '.json') { + return @{ + SourceFile = $sourceFile + CopyOption = "LangIDOnPath" + OutputPath = "$($_.Directory.Parent.FullName | Resolve-Path -Relative)\" + } + } else { + return @{ + SourceFile = $sourceFile + CopyOption = "LangIDOnName" + OutputPath = $outputPath + } + } + } + } + ) + }, + @{ + LanguageSet = $LanguageSet + CloneLanguageSet = "WiX_CloneLanguages" + LssFiles = @( "wxl_loc.lss" ) + LocItems = @( + $wxlFiles | ForEach-Object { + $outputPath = "$($_.Directory.FullName | Resolve-Path -Relative)\" + $continue = $true + foreach ($exclusion in $exclusions.Exclusions) { + if ($_.FullName.Contains($exclusion)) { + $continue = $false + } + } + $sourceFile = ($_.FullName | Resolve-Path -Relative) + if ($continue) + { + return @{ + SourceFile = $sourceFile + CopyOption = "LangIDOnPath" + OutputPath = $outputPath + } + } + } + ) + }, + @{ + LanguageSet = $LanguageSet + CloneLanguageSet = "VS_macOS_CloneLanguages" + LssFiles = @( ".\eng\common\loc\P22DotNetHtmlLocalization.lss" ) + LocItems = @( + $macosHtmlFiles | ForEach-Object { + $outputPath = "$($_.Directory.FullName | Resolve-Path -Relative)\" + $continue = $true + foreach ($exclusion in $exclusions.Exclusions) { + if ($_.FullName.Contains($exclusion)) { + $continue = $false + } + } + $sourceFile = ($_.FullName | Resolve-Path -Relative) + $lciFile = $sourceFile + ".lci" + if ($continue) { + $result = @{ + SourceFile = $sourceFile + CopyOption = "LangIDOnPath" + OutputPath = $outputPath + } + if (Test-Path $lciFile -PathType Leaf) { + $result["LciFile"] = $lciFile + } + return $result + } + } + ) + } + ) +} + +$json = ConvertTo-Json $locJson -Depth 5 +Write-Host "LocProject.json generated:`n`n$json`n`n" +Pop-Location + +if (!$UseCheckedInLocProjectJson) { + New-Item "$SourcesDirectory\eng\Localize\LocProject.json" -Force # Need this to make sure the Localize directory is created + Set-Content "$SourcesDirectory\eng\Localize\LocProject.json" $json +} +else { + New-Item "$SourcesDirectory\eng\Localize\LocProject-generated.json" -Force # Need this to make sure the Localize directory is created + Set-Content "$SourcesDirectory\eng\Localize\LocProject-generated.json" $json + + if ((Get-FileHash "$SourcesDirectory\eng\Localize\LocProject-generated.json").Hash -ne (Get-FileHash "$SourcesDirectory\eng\Localize\LocProject.json").Hash) { + Write-PipelineTelemetryError -Category "OneLocBuild" -Message "Existing LocProject.json differs from generated LocProject.json. Download LocProject-generated.json and compare them." + + exit 1 + } + else { + Write-Host "Generated LocProject.json and current LocProject.json are identical." + } +} diff --git a/eng/common/generate-sbom-prep.ps1 b/eng/common/generate-sbom-prep.ps1 new file mode 100644 index 0000000000000..3e5c1c74a1c50 --- /dev/null +++ b/eng/common/generate-sbom-prep.ps1 @@ -0,0 +1,21 @@ +Param( + [Parameter(Mandatory=$true)][string] $ManifestDirPath # Manifest directory where sbom will be placed +) + +. $PSScriptRoot\pipeline-logging-functions.ps1 + +Write-Host "Creating dir $ManifestDirPath" +# create directory for sbom manifest to be placed +if (!(Test-Path -path $ManifestDirPath)) +{ + New-Item -ItemType Directory -path $ManifestDirPath + Write-Host "Successfully created directory $ManifestDirPath" +} +else{ + Write-PipelineTelemetryError -category 'Build' "Unable to create sbom folder." +} + +Write-Host "Updating artifact name" +$artifact_name = "${env:SYSTEM_STAGENAME}_${env:AGENT_JOBNAME}_SBOM" -replace '["/:<>\\|?@*"() ]', '_' +Write-Host "Artifact name $artifact_name" +Write-Host "##vso[task.setvariable variable=ARTIFACT_NAME]$artifact_name" diff --git a/eng/common/generate-sbom-prep.sh b/eng/common/generate-sbom-prep.sh new file mode 100644 index 0000000000000..d5c76dc827b49 --- /dev/null +++ b/eng/common/generate-sbom-prep.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +source="${BASH_SOURCE[0]}" + +# resolve $SOURCE until the file is no longer a symlink +while [[ -h $source ]]; do + scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + source="$(readlink "$source")" + + # if $source was a relative symlink, we need to resolve it relative to the path where the + # symlink file was located + [[ $source != /* ]] && source="$scriptroot/$source" +done +scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" +. $scriptroot/pipeline-logging-functions.sh + +manifest_dir=$1 + +if [ ! -d "$manifest_dir" ] ; then + mkdir -p "$manifest_dir" + echo "Sbom directory created." $manifest_dir +else + Write-PipelineTelemetryError -category 'Build' "Unable to create sbom folder." +fi + +artifact_name=$SYSTEM_STAGENAME"_"$AGENT_JOBNAME"_SBOM" +echo "Artifact name before : "$artifact_name +# replace all special characters with _, some builds use special characters like : in Agent.Jobname, that is not a permissible name while uploading artifacts. +safe_artifact_name="${artifact_name//["/:<>\\|?@*$" ]/_}" +echo "Artifact name after : "$safe_artifact_name +export ARTIFACT_NAME=$safe_artifact_name +echo "##vso[task.setvariable variable=ARTIFACT_NAME]$safe_artifact_name" + +exit 0 diff --git a/eng/common/helixpublish.proj b/eng/common/helixpublish.proj new file mode 100644 index 0000000000000..d7f185856e791 --- /dev/null +++ b/eng/common/helixpublish.proj @@ -0,0 +1,26 @@ + + + + msbuild + + + + + %(Identity) + + + + + + $(WorkItemDirectory) + $(WorkItemCommand) + $(WorkItemTimeout) + + + + + + + + + diff --git a/eng/common/init-tools-native.cmd b/eng/common/init-tools-native.cmd new file mode 100644 index 0000000000000..438cd548c452c --- /dev/null +++ b/eng/common/init-tools-native.cmd @@ -0,0 +1,3 @@ +@echo off +powershell -NoProfile -NoLogo -ExecutionPolicy ByPass -command "& """%~dp0init-tools-native.ps1""" %*" +exit /b %ErrorLevel% \ No newline at end of file diff --git a/eng/common/init-tools-native.ps1 b/eng/common/init-tools-native.ps1 new file mode 100644 index 0000000000000..27ccdb9ecc951 --- /dev/null +++ b/eng/common/init-tools-native.ps1 @@ -0,0 +1,203 @@ +<# +.SYNOPSIS +Entry point script for installing native tools + +.DESCRIPTION +Reads $RepoRoot\global.json file to determine native assets to install +and executes installers for those tools + +.PARAMETER BaseUri +Base file directory or Url from which to acquire tool archives + +.PARAMETER InstallDirectory +Directory to install native toolset. This is a command-line override for the default +Install directory precedence order: +- InstallDirectory command-line override +- NETCOREENG_INSTALL_DIRECTORY environment variable +- (default) %USERPROFILE%/.netcoreeng/native + +.PARAMETER Clean +Switch specifying to not install anything, but cleanup native asset folders + +.PARAMETER Force +Clean and then install tools + +.PARAMETER DownloadRetries +Total number of retry attempts + +.PARAMETER RetryWaitTimeInSeconds +Wait time between retry attempts in seconds + +.PARAMETER GlobalJsonFile +File path to global.json file + +.PARAMETER PathPromotion +Optional switch to enable either promote native tools specified in the global.json to the path (in Azure Pipelines) +or break the build if a native tool is not found on the path (on a local dev machine) + +.NOTES +#> +[CmdletBinding(PositionalBinding=$false)] +Param ( + [string] $BaseUri = 'https://netcorenativeassets.blob.core.windows.net/resource-packages/external', + [string] $InstallDirectory, + [switch] $Clean = $False, + [switch] $Force = $False, + [int] $DownloadRetries = 5, + [int] $RetryWaitTimeInSeconds = 30, + [string] $GlobalJsonFile, + [switch] $PathPromotion +) + +if (!$GlobalJsonFile) { + $GlobalJsonFile = Join-Path (Get-Item $PSScriptRoot).Parent.Parent.FullName 'global.json' +} + +Set-StrictMode -version 2.0 +$ErrorActionPreference='Stop' + +. $PSScriptRoot\pipeline-logging-functions.ps1 +Import-Module -Name (Join-Path $PSScriptRoot 'native\CommonLibrary.psm1') + +try { + # Define verbose switch if undefined + $Verbose = $VerbosePreference -Eq 'Continue' + + $EngCommonBaseDir = Join-Path $PSScriptRoot 'native\' + $NativeBaseDir = $InstallDirectory + if (!$NativeBaseDir) { + $NativeBaseDir = CommonLibrary\Get-NativeInstallDirectory + } + $Env:CommonLibrary_NativeInstallDir = $NativeBaseDir + $InstallBin = Join-Path $NativeBaseDir 'bin' + $InstallerPath = Join-Path $EngCommonBaseDir 'install-tool.ps1' + + # Process tools list + Write-Host "Processing $GlobalJsonFile" + If (-Not (Test-Path $GlobalJsonFile)) { + Write-Host "Unable to find '$GlobalJsonFile'" + exit 0 + } + $NativeTools = Get-Content($GlobalJsonFile) -Raw | + ConvertFrom-Json | + Select-Object -Expand 'native-tools' -ErrorAction SilentlyContinue + if ($NativeTools) { + if ($PathPromotion -eq $True) { + $ArcadeToolsDirectory = "$env:SYSTEMDRIVE\arcade-tools" + if (Test-Path $ArcadeToolsDirectory) { # if this directory exists, we should use native tools on machine + $NativeTools.PSObject.Properties | ForEach-Object { + $ToolName = $_.Name + $ToolVersion = $_.Value + $InstalledTools = @{} + + if ((Get-Command "$ToolName" -ErrorAction SilentlyContinue) -eq $null) { + if ($ToolVersion -eq "latest") { + $ToolVersion = "" + } + $ToolDirectories = (Get-ChildItem -Path "$ArcadeToolsDirectory" -Filter "$ToolName-$ToolVersion*" | Sort-Object -Descending) + if ($ToolDirectories -eq $null) { + Write-Error "Unable to find directory for $ToolName $ToolVersion; please make sure the tool is installed on this image." + exit 1 + } + $ToolDirectory = $ToolDirectories[0] + $BinPathFile = "$($ToolDirectory.FullName)\binpath.txt" + if (-not (Test-Path -Path "$BinPathFile")) { + Write-Error "Unable to find binpath.txt in '$($ToolDirectory.FullName)' ($ToolName $ToolVersion); artifact is either installed incorrectly or is not a bootstrappable tool." + exit 1 + } + $BinPath = Get-Content "$BinPathFile" + $ToolPath = Convert-Path -Path $BinPath + Write-Host "Adding $ToolName to the path ($ToolPath)..." + Write-Host "##vso[task.prependpath]$ToolPath" + $env:PATH = "$ToolPath;$env:PATH" + $InstalledTools += @{ $ToolName = $ToolDirectory.FullName } + } + } + return $InstalledTools + } else { + $NativeTools.PSObject.Properties | ForEach-Object { + $ToolName = $_.Name + $ToolVersion = $_.Value + + if ((Get-Command "$ToolName" -ErrorAction SilentlyContinue) -eq $null) { + Write-PipelineTelemetryError -Category 'NativeToolsBootstrap' -Message "$ToolName not found on path. Please install $ToolName $ToolVersion before proceeding." + Write-PipelineTelemetryError -Category 'NativeToolsBootstrap' -Message "If this is running on a build machine, the arcade-tools directory was not found, which means there's an error with the image." + } + } + exit 0 + } + } else { + $NativeTools.PSObject.Properties | ForEach-Object { + $ToolName = $_.Name + $ToolVersion = $_.Value + $LocalInstallerArguments = @{ ToolName = "$ToolName" } + $LocalInstallerArguments += @{ InstallPath = "$InstallBin" } + $LocalInstallerArguments += @{ BaseUri = "$BaseUri" } + $LocalInstallerArguments += @{ CommonLibraryDirectory = "$EngCommonBaseDir" } + $LocalInstallerArguments += @{ Version = "$ToolVersion" } + + if ($Verbose) { + $LocalInstallerArguments += @{ Verbose = $True } + } + if (Get-Variable 'Force' -ErrorAction 'SilentlyContinue') { + if($Force) { + $LocalInstallerArguments += @{ Force = $True } + } + } + if ($Clean) { + $LocalInstallerArguments += @{ Clean = $True } + } + + Write-Verbose "Installing $ToolName version $ToolVersion" + Write-Verbose "Executing '$InstallerPath $($LocalInstallerArguments.Keys.ForEach({"-$_ '$($LocalInstallerArguments.$_)'"}) -join ' ')'" + & $InstallerPath @LocalInstallerArguments + if ($LASTEXITCODE -Ne "0") { + $errMsg = "$ToolName installation failed" + if ((Get-Variable 'DoNotAbortNativeToolsInstallationOnFailure' -ErrorAction 'SilentlyContinue') -and $DoNotAbortNativeToolsInstallationOnFailure) { + $showNativeToolsWarning = $true + if ((Get-Variable 'DoNotDisplayNativeToolsInstallationWarnings' -ErrorAction 'SilentlyContinue') -and $DoNotDisplayNativeToolsInstallationWarnings) { + $showNativeToolsWarning = $false + } + if ($showNativeToolsWarning) { + Write-Warning $errMsg + } + $toolInstallationFailure = $true + } else { + # We cannot change this to Write-PipelineTelemetryError because of https://github.com/dotnet/arcade/issues/4482 + Write-Host $errMsg + exit 1 + } + } + } + + if ((Get-Variable 'toolInstallationFailure' -ErrorAction 'SilentlyContinue') -and $toolInstallationFailure) { + # We cannot change this to Write-PipelineTelemetryError because of https://github.com/dotnet/arcade/issues/4482 + Write-Host 'Native tools bootstrap failed' + exit 1 + } + } + } + else { + Write-Host 'No native tools defined in global.json' + exit 0 + } + + if ($Clean) { + exit 0 + } + if (Test-Path $InstallBin) { + Write-Host 'Native tools are available from ' (Convert-Path -Path $InstallBin) + Write-Host "##vso[task.prependpath]$(Convert-Path -Path $InstallBin)" + return $InstallBin + } + elseif (-not ($PathPromotion)) { + Write-PipelineTelemetryError -Category 'NativeToolsBootstrap' -Message 'Native tools install directory does not exist, installation failed' + exit 1 + } + exit 0 +} +catch { + Write-Host $_.ScriptStackTrace + Write-PipelineTelemetryError -Category 'NativeToolsBootstrap' -Message $_ + ExitWithExitCode 1 +} diff --git a/eng/common/init-tools-native.sh b/eng/common/init-tools-native.sh new file mode 100755 index 0000000000000..3e6a8d6acf2f5 --- /dev/null +++ b/eng/common/init-tools-native.sh @@ -0,0 +1,238 @@ +#!/usr/bin/env bash + +source="${BASH_SOURCE[0]}" +scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + +base_uri='https://netcorenativeassets.blob.core.windows.net/resource-packages/external' +install_directory='' +clean=false +force=false +download_retries=5 +retry_wait_time_seconds=30 +global_json_file="$(dirname "$(dirname "${scriptroot}")")/global.json" +declare -a native_assets + +. $scriptroot/pipeline-logging-functions.sh +. $scriptroot/native/common-library.sh + +while (($# > 0)); do + lowerI="$(echo $1 | tr "[:upper:]" "[:lower:]")" + case $lowerI in + --baseuri) + base_uri=$2 + shift 2 + ;; + --installdirectory) + install_directory=$2 + shift 2 + ;; + --clean) + clean=true + shift 1 + ;; + --force) + force=true + shift 1 + ;; + --donotabortonfailure) + donotabortonfailure=true + shift 1 + ;; + --donotdisplaywarnings) + donotdisplaywarnings=true + shift 1 + ;; + --downloadretries) + download_retries=$2 + shift 2 + ;; + --retrywaittimeseconds) + retry_wait_time_seconds=$2 + shift 2 + ;; + --help) + echo "Common settings:" + echo " --installdirectory Directory to install native toolset." + echo " This is a command-line override for the default" + echo " Install directory precedence order:" + echo " - InstallDirectory command-line override" + echo " - NETCOREENG_INSTALL_DIRECTORY environment variable" + echo " - (default) %USERPROFILE%/.netcoreeng/native" + echo "" + echo " --clean Switch specifying not to install anything, but cleanup native asset folders" + echo " --donotabortonfailure Switch specifiying whether to abort native tools installation on failure" + echo " --donotdisplaywarnings Switch specifiying whether to display warnings during native tools installation on failure" + echo " --force Clean and then install tools" + echo " --help Print help and exit" + echo "" + echo "Advanced settings:" + echo " --baseuri Base URI for where to download native tools from" + echo " --downloadretries Number of times a download should be attempted" + echo " --retrywaittimeseconds Wait time between download attempts" + echo "" + exit 0 + ;; + esac +done + +function ReadGlobalJsonNativeTools { + # happy path: we have a proper JSON parsing tool `jq(1)` in PATH! + if command -v jq &> /dev/null; then + + # jq: read each key/value pair under "native-tools" entry and emit: + # KEY="" VALUE="" + # followed by a null byte. + # + # bash: read line with null byte delimeter and push to array (for later `eval`uation). + + while IFS= read -rd '' line; do + native_assets+=("$line") + done < <(jq -r '. | + select(has("native-tools")) | + ."native-tools" | + keys[] as $k | + @sh "KEY=\($k) VALUE=\(.[$k])\u0000"' "$global_json_file") + + return + fi + + # Warning: falling back to manually parsing JSON, which is not recommended. + + # Following routine matches the output and escaping logic of jq(1)'s @sh formatter used above. + # It has been tested with several weird strings with escaped characters in entries (key and value) + # and results were compared with the output of jq(1) in binary representation using xxd(1); + # just before the assignment to 'native_assets' array (above and below). + + # try to capture the section under "native-tools". + if [[ ! "$(cat "$global_json_file")" =~ \"native-tools\"[[:space:]\:\{]*([^\}]+) ]]; then + return + fi + + section="${BASH_REMATCH[1]}" + + parseStarted=0 + possibleEnd=0 + escaping=0 + escaped=0 + isKey=1 + + for (( i=0; i<${#section}; i++ )); do + char="${section:$i:1}" + if ! ((parseStarted)) && [[ "$char" =~ [[:space:],:] ]]; then continue; fi + + if ! ((escaping)) && [[ "$char" == "\\" ]]; then + escaping=1 + elif ((escaping)) && ! ((escaped)); then + escaped=1 + fi + + if ! ((parseStarted)) && [[ "$char" == "\"" ]]; then + parseStarted=1 + possibleEnd=0 + elif [[ "$char" == "'" ]]; then + token="$token'\\\''" + possibleEnd=0 + elif ((escaping)) || [[ "$char" != "\"" ]]; then + token="$token$char" + possibleEnd=1 + fi + + if ((possibleEnd)) && ! ((escaping)) && [[ "$char" == "\"" ]]; then + # Use printf to unescape token to match jq(1)'s @sh formatting rules. + # do not use 'token="$(printf "$token")"' syntax, as $() eats the trailing linefeed. + printf -v token "'$token'" + + if ((isKey)); then + KEY="$token" + isKey=0 + else + line="KEY=$KEY VALUE=$token" + native_assets+=("$line") + isKey=1 + fi + + # reset for next token + parseStarted=0 + token= + elif ((escaping)) && ((escaped)); then + escaping=0 + escaped=0 + fi + done +} + +native_base_dir=$install_directory +if [[ -z $install_directory ]]; then + native_base_dir=$(GetNativeInstallDirectory) +fi + +install_bin="${native_base_dir}/bin" +installed_any=false + +ReadGlobalJsonNativeTools + +if [[ ${#native_assets[@]} -eq 0 ]]; then + echo "No native tools defined in global.json" + exit 0; +else + native_installer_dir="$scriptroot/native" + for index in "${!native_assets[@]}"; do + eval "${native_assets["$index"]}" + + installer_path="$native_installer_dir/install-$KEY.sh" + installer_command="$installer_path" + installer_command+=" --baseuri $base_uri" + installer_command+=" --installpath $install_bin" + installer_command+=" --version $VALUE" + echo $installer_command + + if [[ $force = true ]]; then + installer_command+=" --force" + fi + + if [[ $clean = true ]]; then + installer_command+=" --clean" + fi + + if [[ -a $installer_path ]]; then + $installer_command + if [[ $? != 0 ]]; then + if [[ $donotabortonfailure = true ]]; then + if [[ $donotdisplaywarnings != true ]]; then + Write-PipelineTelemetryError -category 'NativeToolsBootstrap' "Execution Failed" + fi + else + Write-PipelineTelemetryError -category 'NativeToolsBootstrap' "Execution Failed" + exit 1 + fi + else + $installed_any = true + fi + else + if [[ $donotabortonfailure == true ]]; then + if [[ $donotdisplaywarnings != true ]]; then + Write-PipelineTelemetryError -category 'NativeToolsBootstrap' "Execution Failed: no install script" + fi + else + Write-PipelineTelemetryError -category 'NativeToolsBootstrap' "Execution Failed: no install script" + exit 1 + fi + fi + done +fi + +if [[ $clean = true ]]; then + exit 0 +fi + +if [[ -d $install_bin ]]; then + echo "Native tools are available from $install_bin" + echo "##vso[task.prependpath]$install_bin" +else + if [[ $installed_any = true ]]; then + Write-PipelineTelemetryError -category 'NativeToolsBootstrap' "Native tools install directory does not exist, installation failed" + exit 1 + fi +fi + +exit 0 diff --git a/eng/common/internal-feed-operations.ps1 b/eng/common/internal-feed-operations.ps1 new file mode 100644 index 0000000000000..92b77347d9904 --- /dev/null +++ b/eng/common/internal-feed-operations.ps1 @@ -0,0 +1,132 @@ +param( + [Parameter(Mandatory=$true)][string] $Operation, + [string] $AuthToken, + [string] $CommitSha, + [string] $RepoName, + [switch] $IsFeedPrivate +) + +$ErrorActionPreference = 'Stop' +Set-StrictMode -Version 2.0 +. $PSScriptRoot\tools.ps1 + +# Sets VSS_NUGET_EXTERNAL_FEED_ENDPOINTS based on the "darc-int-*" feeds defined in NuGet.config. This is needed +# in build agents by CredProvider to authenticate the restore requests to internal feeds as specified in +# https://github.com/microsoft/artifacts-credprovider/blob/0f53327cd12fd893d8627d7b08a2171bf5852a41/README.md#environment-variables. This should ONLY be called from identified +# internal builds +function SetupCredProvider { + param( + [string] $AuthToken + ) + + # Install the Cred Provider NuGet plugin + Write-Host 'Setting up Cred Provider NuGet plugin in the agent...' + Write-Host "Getting 'installcredprovider.ps1' from 'https://github.com/microsoft/artifacts-credprovider'..." + + $url = 'https://raw.githubusercontent.com/microsoft/artifacts-credprovider/master/helpers/installcredprovider.ps1' + + Write-Host "Writing the contents of 'installcredprovider.ps1' locally..." + Invoke-WebRequest $url -OutFile installcredprovider.ps1 + + Write-Host 'Installing plugin...' + .\installcredprovider.ps1 -Force + + Write-Host "Deleting local copy of 'installcredprovider.ps1'..." + Remove-Item .\installcredprovider.ps1 + + if (-Not("$env:USERPROFILE\.nuget\plugins\netcore")) { + Write-PipelineTelemetryError -Category 'Arcade' -Message 'CredProvider plugin was not installed correctly!' + ExitWithExitCode 1 + } + else { + Write-Host 'CredProvider plugin was installed correctly!' + } + + # Then, we set the 'VSS_NUGET_EXTERNAL_FEED_ENDPOINTS' environment variable to restore from the stable + # feeds successfully + + $nugetConfigPath = Join-Path $RepoRoot "NuGet.config" + + if (-Not (Test-Path -Path $nugetConfigPath)) { + Write-PipelineTelemetryError -Category 'Build' -Message 'NuGet.config file not found in repo root!' + ExitWithExitCode 1 + } + + $endpoints = New-Object System.Collections.ArrayList + $nugetConfigPackageSources = Select-Xml -Path $nugetConfigPath -XPath "//packageSources/add[contains(@key, 'darc-int-')]/@value" | foreach{$_.Node.Value} + + if (($nugetConfigPackageSources | Measure-Object).Count -gt 0 ) { + foreach ($stableRestoreResource in $nugetConfigPackageSources) { + $trimmedResource = ([string]$stableRestoreResource).Trim() + [void]$endpoints.Add(@{endpoint="$trimmedResource"; password="$AuthToken"}) + } + } + + if (($endpoints | Measure-Object).Count -gt 0) { + $endpointCredentials = @{endpointCredentials=$endpoints} | ConvertTo-Json -Compress + + # Create the environment variables the AzDo way + Write-LoggingCommand -Area 'task' -Event 'setvariable' -Data $endpointCredentials -Properties @{ + 'variable' = 'VSS_NUGET_EXTERNAL_FEED_ENDPOINTS' + 'issecret' = 'false' + } + + # We don't want sessions cached since we will be updating the endpoints quite frequently + Write-LoggingCommand -Area 'task' -Event 'setvariable' -Data 'False' -Properties @{ + 'variable' = 'NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED' + 'issecret' = 'false' + } + } + else + { + Write-Host 'No internal endpoints found in NuGet.config' + } +} + +#Workaround for https://github.com/microsoft/msbuild/issues/4430 +function InstallDotNetSdkAndRestoreArcade { + $dotnetTempDir = Join-Path $RepoRoot "dotnet" + $dotnetSdkVersion="2.1.507" # After experimentation we know this version works when restoring the SDK (compared to 3.0.*) + $dotnet = "$dotnetTempDir\dotnet.exe" + $restoreProjPath = "$PSScriptRoot\restore.proj" + + Write-Host "Installing dotnet SDK version $dotnetSdkVersion to restore Arcade SDK..." + InstallDotNetSdk "$dotnetTempDir" "$dotnetSdkVersion" + + '' | Out-File "$restoreProjPath" + + & $dotnet restore $restoreProjPath + + Write-Host 'Arcade SDK restored!' + + if (Test-Path -Path $restoreProjPath) { + Remove-Item $restoreProjPath + } + + if (Test-Path -Path $dotnetTempDir) { + Remove-Item $dotnetTempDir -Recurse + } +} + +try { + Push-Location $PSScriptRoot + + if ($Operation -like 'setup') { + SetupCredProvider $AuthToken + } + elseif ($Operation -like 'install-restore') { + InstallDotNetSdkAndRestoreArcade + } + else { + Write-PipelineTelemetryError -Category 'Arcade' -Message "Unknown operation '$Operation'!" + ExitWithExitCode 1 + } +} +catch { + Write-Host $_.ScriptStackTrace + Write-PipelineTelemetryError -Category 'Arcade' -Message $_ + ExitWithExitCode 1 +} +finally { + Pop-Location +} diff --git a/eng/common/internal-feed-operations.sh b/eng/common/internal-feed-operations.sh new file mode 100755 index 0000000000000..9378223ba0955 --- /dev/null +++ b/eng/common/internal-feed-operations.sh @@ -0,0 +1,141 @@ +#!/usr/bin/env bash + +set -e + +# Sets VSS_NUGET_EXTERNAL_FEED_ENDPOINTS based on the "darc-int-*" feeds defined in NuGet.config. This is needed +# in build agents by CredProvider to authenticate the restore requests to internal feeds as specified in +# https://github.com/microsoft/artifacts-credprovider/blob/0f53327cd12fd893d8627d7b08a2171bf5852a41/README.md#environment-variables. +# This should ONLY be called from identified internal builds +function SetupCredProvider { + local authToken=$1 + + # Install the Cred Provider NuGet plugin + echo "Setting up Cred Provider NuGet plugin in the agent..."... + echo "Getting 'installcredprovider.ps1' from 'https://github.com/microsoft/artifacts-credprovider'..." + + local url="https://raw.githubusercontent.com/microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh" + + echo "Writing the contents of 'installcredprovider.ps1' locally..." + local installcredproviderPath="installcredprovider.sh" + if command -v curl > /dev/null; then + curl $url > "$installcredproviderPath" + else + wget -q -O "$installcredproviderPath" "$url" + fi + + echo "Installing plugin..." + . "$installcredproviderPath" + + echo "Deleting local copy of 'installcredprovider.sh'..." + rm installcredprovider.sh + + if [ ! -d "$HOME/.nuget/plugins" ]; then + Write-PipelineTelemetryError -category 'Build' 'CredProvider plugin was not installed correctly!' + ExitWithExitCode 1 + else + echo "CredProvider plugin was installed correctly!" + fi + + # Then, we set the 'VSS_NUGET_EXTERNAL_FEED_ENDPOINTS' environment variable to restore from the stable + # feeds successfully + + local nugetConfigPath="{$repo_root}NuGet.config" + + if [ ! "$nugetConfigPath" ]; then + Write-PipelineTelemetryError -category 'Build' "NuGet.config file not found in repo's root!" + ExitWithExitCode 1 + fi + + local endpoints='[' + local nugetConfigPackageValues=`cat "$nugetConfigPath" | grep "key=\"darc-int-"` + local pattern="value=\"(.*)\"" + + for value in $nugetConfigPackageValues + do + if [[ $value =~ $pattern ]]; then + local endpoint="${BASH_REMATCH[1]}" + endpoints+="{\"endpoint\": \"$endpoint\", \"password\": \"$authToken\"}," + fi + done + + endpoints=${endpoints%?} + endpoints+=']' + + if [ ${#endpoints} -gt 2 ]; then + local endpointCredentials="{\"endpointCredentials\": "$endpoints"}" + + echo "##vso[task.setvariable variable=VSS_NUGET_EXTERNAL_FEED_ENDPOINTS]$endpointCredentials" + echo "##vso[task.setvariable variable=NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED]False" + else + echo "No internal endpoints found in NuGet.config" + fi +} + +# Workaround for https://github.com/microsoft/msbuild/issues/4430 +function InstallDotNetSdkAndRestoreArcade { + local dotnetTempDir="$repo_root/dotnet" + local dotnetSdkVersion="2.1.507" # After experimentation we know this version works when restoring the SDK (compared to 3.0.*) + local restoreProjPath="$repo_root/eng/common/restore.proj" + + echo "Installing dotnet SDK version $dotnetSdkVersion to restore Arcade SDK..." + echo "" > "$restoreProjPath" + + InstallDotNetSdk "$dotnetTempDir" "$dotnetSdkVersion" + + local res=`$dotnetTempDir/dotnet restore $restoreProjPath` + echo "Arcade SDK restored!" + + # Cleanup + if [ "$restoreProjPath" ]; then + rm "$restoreProjPath" + fi + + if [ "$dotnetTempDir" ]; then + rm -r $dotnetTempDir + fi +} + +source="${BASH_SOURCE[0]}" +operation='' +authToken='' +repoName='' + +while [[ $# > 0 ]]; do + opt="$(echo "$1" | tr "[:upper:]" "[:lower:]")" + case "$opt" in + --operation) + operation=$2 + shift + ;; + --authtoken) + authToken=$2 + shift + ;; + *) + echo "Invalid argument: $1" + usage + exit 1 + ;; + esac + + shift +done + +while [[ -h "$source" ]]; do + scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + source="$(readlink "$source")" + # if $source was a relative symlink, we need to resolve it relative to the path where the + # symlink file was located + [[ $source != /* ]] && source="$scriptroot/$source" +done +scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + +. "$scriptroot/tools.sh" + +if [ "$operation" = "setup" ]; then + SetupCredProvider $authToken +elif [ "$operation" = "install-restore" ]; then + InstallDotNetSdkAndRestoreArcade +else + echo "Unknown operation '$operation'!" +fi diff --git a/eng/common/internal/Directory.Build.props b/eng/common/internal/Directory.Build.props new file mode 100644 index 0000000000000..dbf99d82a5c2e --- /dev/null +++ b/eng/common/internal/Directory.Build.props @@ -0,0 +1,4 @@ + + + + diff --git a/eng/common/internal/NuGet.config b/eng/common/internal/NuGet.config new file mode 100644 index 0000000000000..19d3d311b166f --- /dev/null +++ b/eng/common/internal/NuGet.config @@ -0,0 +1,7 @@ + + + + + + + diff --git a/eng/common/internal/Tools.csproj b/eng/common/internal/Tools.csproj new file mode 100644 index 0000000000000..7f5ce6d608133 --- /dev/null +++ b/eng/common/internal/Tools.csproj @@ -0,0 +1,30 @@ + + + + net472 + false + false + + + + + + + + + + + + + + https://devdiv.pkgs.visualstudio.com/_packaging/dotnet-core-internal-tooling/nuget/v3/index.json; + + + $(RestoreSources); + https://devdiv.pkgs.visualstudio.com/_packaging/VS/nuget/v3/index.json; + + + + + + diff --git a/eng/common/loc/P22DotNetHtmlLocalization.lss b/eng/common/loc/P22DotNetHtmlLocalization.lss new file mode 100644 index 0000000000000..6661fed566e49 Binary files /dev/null and b/eng/common/loc/P22DotNetHtmlLocalization.lss differ diff --git a/eng/common/msbuild.ps1 b/eng/common/msbuild.ps1 new file mode 100644 index 0000000000000..f041e5ddd9589 --- /dev/null +++ b/eng/common/msbuild.ps1 @@ -0,0 +1,28 @@ +[CmdletBinding(PositionalBinding=$false)] +Param( + [string] $verbosity = 'minimal', + [bool] $warnAsError = $true, + [bool] $nodeReuse = $true, + [switch] $ci, + [switch] $prepareMachine, + [switch] $excludePrereleaseVS, + [string] $msbuildEngine = $null, + [Parameter(ValueFromRemainingArguments=$true)][String[]]$extraArgs +) + +. $PSScriptRoot\tools.ps1 + +try { + if ($ci) { + $nodeReuse = $false + } + + MSBuild @extraArgs +} +catch { + Write-Host $_.ScriptStackTrace + Write-PipelineTelemetryError -Category 'Build' -Message $_ + ExitWithExitCode 1 +} + +ExitWithExitCode 0 \ No newline at end of file diff --git a/eng/common/msbuild.sh b/eng/common/msbuild.sh new file mode 100755 index 0000000000000..20d3dad543520 --- /dev/null +++ b/eng/common/msbuild.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +source="${BASH_SOURCE[0]}" + +# resolve $source until the file is no longer a symlink +while [[ -h "$source" ]]; do + scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + source="$(readlink "$source")" + # if $source was a relative symlink, we need to resolve it relative to the path where the + # symlink file was located + [[ $source != /* ]] && source="$scriptroot/$source" +done +scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + +verbosity='minimal' +warn_as_error=true +node_reuse=true +prepare_machine=false +extra_args='' + +while (($# > 0)); do + lowerI="$(echo $1 | tr "[:upper:]" "[:lower:]")" + case $lowerI in + --verbosity) + verbosity=$2 + shift 2 + ;; + --warnaserror) + warn_as_error=$2 + shift 2 + ;; + --nodereuse) + node_reuse=$2 + shift 2 + ;; + --ci) + ci=true + shift 1 + ;; + --preparemachine) + prepare_machine=true + shift 1 + ;; + *) + extra_args="$extra_args $1" + shift 1 + ;; + esac +done + +. "$scriptroot/tools.sh" + +if [[ "$ci" == true ]]; then + node_reuse=false +fi + +MSBuild $extra_args +ExitWithExitCode 0 diff --git a/eng/common/native/CommonLibrary.psm1 b/eng/common/native/CommonLibrary.psm1 new file mode 100644 index 0000000000000..ca38268c44d83 --- /dev/null +++ b/eng/common/native/CommonLibrary.psm1 @@ -0,0 +1,400 @@ +<# +.SYNOPSIS +Helper module to install an archive to a directory + +.DESCRIPTION +Helper module to download and extract an archive to a specified directory + +.PARAMETER Uri +Uri of artifact to download + +.PARAMETER InstallDirectory +Directory to extract artifact contents to + +.PARAMETER Force +Force download / extraction if file or contents already exist. Default = False + +.PARAMETER DownloadRetries +Total number of retry attempts. Default = 5 + +.PARAMETER RetryWaitTimeInSeconds +Wait time between retry attempts in seconds. Default = 30 + +.NOTES +Returns False if download or extraction fail, True otherwise +#> +function DownloadAndExtract { + [CmdletBinding(PositionalBinding=$false)] + Param ( + [Parameter(Mandatory=$True)] + [string] $Uri, + [Parameter(Mandatory=$True)] + [string] $InstallDirectory, + [switch] $Force = $False, + [int] $DownloadRetries = 5, + [int] $RetryWaitTimeInSeconds = 30 + ) + # Define verbose switch if undefined + $Verbose = $VerbosePreference -Eq "Continue" + + $TempToolPath = CommonLibrary\Get-TempPathFilename -Path $Uri + + # Download native tool + $DownloadStatus = CommonLibrary\Get-File -Uri $Uri ` + -Path $TempToolPath ` + -DownloadRetries $DownloadRetries ` + -RetryWaitTimeInSeconds $RetryWaitTimeInSeconds ` + -Force:$Force ` + -Verbose:$Verbose + + if ($DownloadStatus -Eq $False) { + Write-Error "Download failed from $Uri" + return $False + } + + # Extract native tool + $UnzipStatus = CommonLibrary\Expand-Zip -ZipPath $TempToolPath ` + -OutputDirectory $InstallDirectory ` + -Force:$Force ` + -Verbose:$Verbose + + if ($UnzipStatus -Eq $False) { + # Retry Download one more time with Force=true + $DownloadRetryStatus = CommonLibrary\Get-File -Uri $Uri ` + -Path $TempToolPath ` + -DownloadRetries 1 ` + -RetryWaitTimeInSeconds $RetryWaitTimeInSeconds ` + -Force:$True ` + -Verbose:$Verbose + + if ($DownloadRetryStatus -Eq $False) { + Write-Error "Last attempt of download failed as well" + return $False + } + + # Retry unzip again one more time with Force=true + $UnzipRetryStatus = CommonLibrary\Expand-Zip -ZipPath $TempToolPath ` + -OutputDirectory $InstallDirectory ` + -Force:$True ` + -Verbose:$Verbose + if ($UnzipRetryStatus -Eq $False) + { + Write-Error "Last attempt of unzip failed as well" + # Clean up partial zips and extracts + if (Test-Path $TempToolPath) { + Remove-Item $TempToolPath -Force + } + if (Test-Path $InstallDirectory) { + Remove-Item $InstallDirectory -Force -Recurse + } + return $False + } + } + + return $True +} + +<# +.SYNOPSIS +Download a file, retry on failure + +.DESCRIPTION +Download specified file and retry if attempt fails + +.PARAMETER Uri +Uri of file to download. If Uri is a local path, the file will be copied instead of downloaded + +.PARAMETER Path +Path to download or copy uri file to + +.PARAMETER Force +Overwrite existing file if present. Default = False + +.PARAMETER DownloadRetries +Total number of retry attempts. Default = 5 + +.PARAMETER RetryWaitTimeInSeconds +Wait time between retry attempts in seconds Default = 30 + +#> +function Get-File { + [CmdletBinding(PositionalBinding=$false)] + Param ( + [Parameter(Mandatory=$True)] + [string] $Uri, + [Parameter(Mandatory=$True)] + [string] $Path, + [int] $DownloadRetries = 5, + [int] $RetryWaitTimeInSeconds = 30, + [switch] $Force = $False + ) + $Attempt = 0 + + if ($Force) { + if (Test-Path $Path) { + Remove-Item $Path -Force + } + } + if (Test-Path $Path) { + Write-Host "File '$Path' already exists, skipping download" + return $True + } + + $DownloadDirectory = Split-Path -ErrorAction Ignore -Path "$Path" -Parent + if (-Not (Test-Path $DownloadDirectory)) { + New-Item -path $DownloadDirectory -force -itemType "Directory" | Out-Null + } + + $TempPath = "$Path.tmp" + if (Test-Path -IsValid -Path $Uri) { + Write-Verbose "'$Uri' is a file path, copying temporarily to '$TempPath'" + Copy-Item -Path $Uri -Destination $TempPath + Write-Verbose "Moving temporary file to '$Path'" + Move-Item -Path $TempPath -Destination $Path + return $? + } + else { + Write-Verbose "Downloading $Uri" + # Don't display the console progress UI - it's a huge perf hit + $ProgressPreference = 'SilentlyContinue' + while($Attempt -Lt $DownloadRetries) + { + try { + Invoke-WebRequest -UseBasicParsing -Uri $Uri -OutFile $TempPath + Write-Verbose "Downloaded to temporary location '$TempPath'" + Move-Item -Path $TempPath -Destination $Path + Write-Verbose "Moved temporary file to '$Path'" + return $True + } + catch { + $Attempt++ + if ($Attempt -Lt $DownloadRetries) { + $AttemptsLeft = $DownloadRetries - $Attempt + Write-Warning "Download failed, $AttemptsLeft attempts remaining, will retry in $RetryWaitTimeInSeconds seconds" + Start-Sleep -Seconds $RetryWaitTimeInSeconds + } + else { + Write-Error $_ + Write-Error $_.Exception + } + } + } + } + + return $False +} + +<# +.SYNOPSIS +Generate a shim for a native tool + +.DESCRIPTION +Creates a wrapper script (shim) that passes arguments forward to native tool assembly + +.PARAMETER ShimName +The name of the shim + +.PARAMETER ShimDirectory +The directory where shims are stored + +.PARAMETER ToolFilePath +Path to file that shim forwards to + +.PARAMETER Force +Replace shim if already present. Default = False + +.NOTES +Returns $True if generating shim succeeds, $False otherwise +#> +function New-ScriptShim { + [CmdletBinding(PositionalBinding=$false)] + Param ( + [Parameter(Mandatory=$True)] + [string] $ShimName, + [Parameter(Mandatory=$True)] + [string] $ShimDirectory, + [Parameter(Mandatory=$True)] + [string] $ToolFilePath, + [Parameter(Mandatory=$True)] + [string] $BaseUri, + [switch] $Force + ) + try { + Write-Verbose "Generating '$ShimName' shim" + + if (-Not (Test-Path $ToolFilePath)){ + Write-Error "Specified tool file path '$ToolFilePath' does not exist" + return $False + } + + # WinShimmer is a small .NET Framework program that creates .exe shims to bootstrapped programs + # Many of the checks for installed programs expect a .exe extension for Windows tools, rather + # than a .bat or .cmd file. + # Source: https://github.com/dotnet/arcade/tree/master/src/WinShimmer + if (-Not (Test-Path "$ShimDirectory\WinShimmer\winshimmer.exe")) { + $InstallStatus = DownloadAndExtract -Uri "$BaseUri/windows/winshimmer/WinShimmer.zip" ` + -InstallDirectory $ShimDirectory\WinShimmer ` + -Force:$Force ` + -DownloadRetries 2 ` + -RetryWaitTimeInSeconds 5 ` + -Verbose:$Verbose + } + + if ((Test-Path (Join-Path $ShimDirectory "$ShimName.exe"))) { + Write-Host "$ShimName.exe already exists; replacing..." + Remove-Item (Join-Path $ShimDirectory "$ShimName.exe") + } + + & "$ShimDirectory\WinShimmer\winshimmer.exe" $ShimName $ToolFilePath $ShimDirectory + return $True + } + catch { + Write-Host $_ + Write-Host $_.Exception + return $False + } +} + +<# +.SYNOPSIS +Returns the machine architecture of the host machine + +.NOTES +Returns 'x64' on 64 bit machines + Returns 'x86' on 32 bit machines +#> +function Get-MachineArchitecture { + $ProcessorArchitecture = $Env:PROCESSOR_ARCHITECTURE + $ProcessorArchitectureW6432 = $Env:PROCESSOR_ARCHITEW6432 + if($ProcessorArchitecture -Eq "X86") + { + if(($ProcessorArchitectureW6432 -Eq "") -Or + ($ProcessorArchitectureW6432 -Eq "X86")) { + return "x86" + } + $ProcessorArchitecture = $ProcessorArchitectureW6432 + } + if (($ProcessorArchitecture -Eq "AMD64") -Or + ($ProcessorArchitecture -Eq "IA64") -Or + ($ProcessorArchitecture -Eq "ARM64") -Or + ($ProcessorArchitecture -Eq "LOONGARCH64")) { + return "x64" + } + return "x86" +} + +<# +.SYNOPSIS +Get the name of a temporary folder under the native install directory +#> +function Get-TempDirectory { + return Join-Path (Get-NativeInstallDirectory) "temp/" +} + +function Get-TempPathFilename { + [CmdletBinding(PositionalBinding=$false)] + Param ( + [Parameter(Mandatory=$True)] + [string] $Path + ) + $TempDir = CommonLibrary\Get-TempDirectory + $TempFilename = Split-Path $Path -leaf + $TempPath = Join-Path $TempDir $TempFilename + return $TempPath +} + +<# +.SYNOPSIS +Returns the base directory to use for native tool installation + +.NOTES +Returns the value of the NETCOREENG_INSTALL_DIRECTORY if that environment variable +is set, or otherwise returns an install directory under the %USERPROFILE% +#> +function Get-NativeInstallDirectory { + $InstallDir = $Env:NETCOREENG_INSTALL_DIRECTORY + if (!$InstallDir) { + $InstallDir = Join-Path $Env:USERPROFILE ".netcoreeng/native/" + } + return $InstallDir +} + +<# +.SYNOPSIS +Unzip an archive + +.DESCRIPTION +Powershell module to unzip an archive to a specified directory + +.PARAMETER ZipPath (Required) +Path to archive to unzip + +.PARAMETER OutputDirectory (Required) +Output directory for archive contents + +.PARAMETER Force +Overwrite output directory contents if they already exist + +.NOTES +- Returns True and does not perform an extraction if output directory already exists but Overwrite is not True. +- Returns True if unzip operation is successful +- Returns False if Overwrite is True and it is unable to remove contents of OutputDirectory +- Returns False if unable to extract zip archive +#> +function Expand-Zip { + [CmdletBinding(PositionalBinding=$false)] + Param ( + [Parameter(Mandatory=$True)] + [string] $ZipPath, + [Parameter(Mandatory=$True)] + [string] $OutputDirectory, + [switch] $Force + ) + + Write-Verbose "Extracting '$ZipPath' to '$OutputDirectory'" + try { + if ((Test-Path $OutputDirectory) -And (-Not $Force)) { + Write-Host "Directory '$OutputDirectory' already exists, skipping extract" + return $True + } + if (Test-Path $OutputDirectory) { + Write-Verbose "'Force' is 'True', but '$OutputDirectory' exists, removing directory" + Remove-Item $OutputDirectory -Force -Recurse + if ($? -Eq $False) { + Write-Error "Unable to remove '$OutputDirectory'" + return $False + } + } + + $TempOutputDirectory = Join-Path "$(Split-Path -Parent $OutputDirectory)" "$(Split-Path -Leaf $OutputDirectory).tmp" + if (Test-Path $TempOutputDirectory) { + Remove-Item $TempOutputDirectory -Force -Recurse + } + New-Item -Path $TempOutputDirectory -Force -ItemType "Directory" | Out-Null + + Add-Type -assembly "system.io.compression.filesystem" + [io.compression.zipfile]::ExtractToDirectory("$ZipPath", "$TempOutputDirectory") + if ($? -Eq $False) { + Write-Error "Unable to extract '$ZipPath'" + return $False + } + + Move-Item -Path $TempOutputDirectory -Destination $OutputDirectory + } + catch { + Write-Host $_ + Write-Host $_.Exception + + return $False + } + return $True +} + +export-modulemember -function DownloadAndExtract +export-modulemember -function Expand-Zip +export-modulemember -function Get-File +export-modulemember -function Get-MachineArchitecture +export-modulemember -function Get-NativeInstallDirectory +export-modulemember -function Get-TempDirectory +export-modulemember -function Get-TempPathFilename +export-modulemember -function New-ScriptShim diff --git a/eng/common/native/common-library.sh b/eng/common/native/common-library.sh new file mode 100755 index 0000000000000..080c2c283ae46 --- /dev/null +++ b/eng/common/native/common-library.sh @@ -0,0 +1,172 @@ +#!/usr/bin/env bash + +function GetNativeInstallDirectory { + local install_dir + + if [[ -z $NETCOREENG_INSTALL_DIRECTORY ]]; then + install_dir=$HOME/.netcoreeng/native/ + else + install_dir=$NETCOREENG_INSTALL_DIRECTORY + fi + + echo $install_dir + return 0 +} + +function GetTempDirectory { + + echo $(GetNativeInstallDirectory)temp/ + return 0 +} + +function ExpandZip { + local zip_path=$1 + local output_directory=$2 + local force=${3:-false} + + echo "Extracting $zip_path to $output_directory" + if [[ -d $output_directory ]] && [[ $force = false ]]; then + echo "Directory '$output_directory' already exists, skipping extract" + return 0 + fi + + if [[ -d $output_directory ]]; then + echo "'Force flag enabled, but '$output_directory' exists. Removing directory" + rm -rf $output_directory + if [[ $? != 0 ]]; then + Write-PipelineTelemetryError -category 'NativeToolsBootstrap' "Unable to remove '$output_directory'" + return 1 + fi + fi + + echo "Creating directory: '$output_directory'" + mkdir -p $output_directory + + echo "Extracting archive" + tar -xf $zip_path -C $output_directory + if [[ $? != 0 ]]; then + Write-PipelineTelemetryError -category 'NativeToolsBootstrap' "Unable to extract '$zip_path'" + return 1 + fi + + return 0 +} + +function GetCurrentOS { + local unameOut="$(uname -s)" + case $unameOut in + Linux*) echo "Linux";; + Darwin*) echo "MacOS";; + esac + return 0 +} + +function GetFile { + local uri=$1 + local path=$2 + local force=${3:-false} + local download_retries=${4:-5} + local retry_wait_time_seconds=${5:-30} + + if [[ -f $path ]]; then + if [[ $force = false ]]; then + echo "File '$path' already exists. Skipping download" + return 0 + else + rm -rf $path + fi + fi + + if [[ -f $uri ]]; then + echo "'$uri' is a file path, copying file to '$path'" + cp $uri $path + return $? + fi + + echo "Downloading $uri" + # Use curl if available, otherwise use wget + if command -v curl > /dev/null; then + curl "$uri" -sSL --retry $download_retries --retry-delay $retry_wait_time_seconds --create-dirs -o "$path" --fail + else + wget -q -O "$path" "$uri" --tries="$download_retries" + fi + + return $? +} + +function GetTempPathFileName { + local path=$1 + + local temp_dir=$(GetTempDirectory) + local temp_file_name=$(basename $path) + echo $temp_dir$temp_file_name + return 0 +} + +function DownloadAndExtract { + local uri=$1 + local installDir=$2 + local force=${3:-false} + local download_retries=${4:-5} + local retry_wait_time_seconds=${5:-30} + + local temp_tool_path=$(GetTempPathFileName $uri) + + echo "downloading to: $temp_tool_path" + + # Download file + GetFile "$uri" "$temp_tool_path" $force $download_retries $retry_wait_time_seconds + if [[ $? != 0 ]]; then + Write-PipelineTelemetryError -category 'NativeToolsBootstrap' "Failed to download '$uri' to '$temp_tool_path'." + return 1 + fi + + # Extract File + echo "extracting from $temp_tool_path to $installDir" + ExpandZip "$temp_tool_path" "$installDir" $force $download_retries $retry_wait_time_seconds + if [[ $? != 0 ]]; then + Write-PipelineTelemetryError -category 'NativeToolsBootstrap' "Failed to extract '$temp_tool_path' to '$installDir'." + return 1 + fi + + return 0 +} + +function NewScriptShim { + local shimpath=$1 + local tool_file_path=$2 + local force=${3:-false} + + echo "Generating '$shimpath' shim" + if [[ -f $shimpath ]]; then + if [[ $force = false ]]; then + echo "File '$shimpath' already exists." >&2 + return 1 + else + rm -rf $shimpath + fi + fi + + if [[ ! -f $tool_file_path ]]; then + # try to see if the path is lower cased + tool_file_path="$(echo $tool_file_path | tr "[:upper:]" "[:lower:]")" + if [[ ! -f $tool_file_path ]]; then + Write-PipelineTelemetryError -category 'NativeToolsBootstrap' "Specified tool file path:'$tool_file_path' does not exist" + return 1 + fi + fi + + local shim_contents=$'#!/usr/bin/env bash\n' + shim_contents+="SHIMARGS="$'$1\n' + shim_contents+="$tool_file_path"$' $SHIMARGS\n' + + # Write shim file + echo "$shim_contents" > $shimpath + + chmod +x $shimpath + + echo "Finished generating shim '$shimpath'" + + return $? +} + diff --git a/eng/common/native/init-compiler.sh b/eng/common/native/init-compiler.sh new file mode 100644 index 0000000000000..7aee4213e1b06 --- /dev/null +++ b/eng/common/native/init-compiler.sh @@ -0,0 +1,137 @@ +#!/bin/sh +# +# This file detects the C/C++ compiler and exports it to the CC/CXX environment variables +# +# NOTE: some scripts source this file and rely on stdout being empty, make sure to not output anything here! + +if [ -z "$build_arch" ] || [ -z "$compiler" ]; then + echo "Usage..." + echo "build_arch= compiler= init-compiler.sh" + echo "Specify the target architecture." + echo "Specify the name of compiler (clang or gcc)." + exit 1 +fi + +case "$compiler" in + clang*|-clang*|--clang*) + # clangx.y or clang-x.y + version="$(echo "$compiler" | tr -d '[:alpha:]-=')" + majorVersion="${version%%.*}" + [ -z "${version##*.*}" ] && minorVersion="${version#*.}" + + if [ -z "$minorVersion" ] && [ -n "$majorVersion" ] && [ "$majorVersion" -le 6 ]; then + minorVersion=0; + fi + compiler=clang + ;; + + gcc*|-gcc*|--gcc*) + # gccx.y or gcc-x.y + version="$(echo "$compiler" | tr -d '[:alpha:]-=')" + majorVersion="${version%%.*}" + [ -z "${version##*.*}" ] && minorVersion="${version#*.}" + compiler=gcc + ;; +esac + +cxxCompiler="$compiler++" + +# clear the existing CC and CXX from environment +CC= +CXX= +LDFLAGS= + +if [ "$compiler" = "gcc" ]; then cxxCompiler="g++"; fi + +check_version_exists() { + desired_version=-1 + + # Set up the environment to be used for building with the desired compiler. + if command -v "$compiler-$1.$2" > /dev/null; then + desired_version="-$1.$2" + elif command -v "$compiler$1$2" > /dev/null; then + desired_version="$1$2" + elif command -v "$compiler-$1$2" > /dev/null; then + desired_version="-$1$2" + fi + + echo "$desired_version" +} + +if [ -z "$CLR_CC" ]; then + + # Set default versions + if [ -z "$majorVersion" ]; then + # note: gcc (all versions) and clang versions higher than 6 do not have minor version in file name, if it is zero. + if [ "$compiler" = "clang" ]; then versions="16 15 14 13 12 11 10 9 8 7 6.0 5.0 4.0 3.9 3.8 3.7 3.6 3.5" + elif [ "$compiler" = "gcc" ]; then versions="12 11 10 9 8 7 6 5 4.9"; fi + + for version in $versions; do + _major="${version%%.*}" + [ -z "${version##*.*}" ] && _minor="${version#*.}" + desired_version="$(check_version_exists "$_major" "$_minor")" + if [ "$desired_version" != "-1" ]; then majorVersion="$_major"; break; fi + done + + if [ -z "$majorVersion" ]; then + if command -v "$compiler" > /dev/null; then + if [ "$(uname)" != "Darwin" ]; then + echo "Warning: Specific version of $compiler not found, falling back to use the one in PATH." + fi + CC="$(command -v "$compiler")" + CXX="$(command -v "$cxxCompiler")" + else + echo "No usable version of $compiler found." + exit 1 + fi + else + if [ "$compiler" = "clang" ] && [ "$majorVersion" -lt 5 ]; then + if [ "$build_arch" = "arm" ] || [ "$build_arch" = "armel" ]; then + if command -v "$compiler" > /dev/null; then + echo "Warning: Found clang version $majorVersion which is not supported on arm/armel architectures, falling back to use clang from PATH." + CC="$(command -v "$compiler")" + CXX="$(command -v "$cxxCompiler")" + else + echo "Found clang version $majorVersion which is not supported on arm/armel architectures, and there is no clang in PATH." + exit 1 + fi + fi + fi + fi + else + desired_version="$(check_version_exists "$majorVersion" "$minorVersion")" + if [ "$desired_version" = "-1" ]; then + echo "Could not find specific version of $compiler: $majorVersion $minorVersion." + exit 1 + fi + fi + + if [ -z "$CC" ]; then + CC="$(command -v "$compiler$desired_version")" + CXX="$(command -v "$cxxCompiler$desired_version")" + if [ -z "$CXX" ]; then CXX="$(command -v "$cxxCompiler")"; fi + fi +else + if [ ! -f "$CLR_CC" ]; then + echo "CLR_CC is set but path '$CLR_CC' does not exist" + exit 1 + fi + CC="$CLR_CC" + CXX="$CLR_CXX" +fi + +if [ -z "$CC" ]; then + echo "Unable to find $compiler." + exit 1 +fi + +# Only lld version >= 9 can be considered stable. lld doesn't support s390x. +if [ "$compiler" = "clang" ] && [ -n "$majorVersion" ] && [ "$majorVersion" -ge 9 ] && [ "$build_arch" != "s390x" ]; then + if "$CC" -fuse-ld=lld -Wl,--version >/dev/null 2>&1; then + LDFLAGS="-fuse-ld=lld" + fi +fi + +SCAN_BUILD_COMMAND="$(command -v "scan-build$desired_version")" + +export CC CXX LDFLAGS SCAN_BUILD_COMMAND diff --git a/eng/common/native/install-cmake-test.sh b/eng/common/native/install-cmake-test.sh new file mode 100755 index 0000000000000..8a5e7cf0db5a9 --- /dev/null +++ b/eng/common/native/install-cmake-test.sh @@ -0,0 +1,117 @@ +#!/usr/bin/env bash + +source="${BASH_SOURCE[0]}" +scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + +. $scriptroot/common-library.sh + +base_uri= +install_path= +version= +clean=false +force=false +download_retries=5 +retry_wait_time_seconds=30 + +while (($# > 0)); do + lowerI="$(echo $1 | tr "[:upper:]" "[:lower:]")" + case $lowerI in + --baseuri) + base_uri=$2 + shift 2 + ;; + --installpath) + install_path=$2 + shift 2 + ;; + --version) + version=$2 + shift 2 + ;; + --clean) + clean=true + shift 1 + ;; + --force) + force=true + shift 1 + ;; + --downloadretries) + download_retries=$2 + shift 2 + ;; + --retrywaittimeseconds) + retry_wait_time_seconds=$2 + shift 2 + ;; + --help) + echo "Common settings:" + echo " --baseuri Base file directory or Url wrom which to acquire tool archives" + echo " --installpath Base directory to install native tool to" + echo " --clean Don't install the tool, just clean up the current install of the tool" + echo " --force Force install of tools even if they previously exist" + echo " --help Print help and exit" + echo "" + echo "Advanced settings:" + echo " --downloadretries Total number of retry attempts" + echo " --retrywaittimeseconds Wait time between retry attempts in seconds" + echo "" + exit 0 + ;; + esac +done + +tool_name="cmake-test" +tool_os=$(GetCurrentOS) +tool_folder="$(echo $tool_os | tr "[:upper:]" "[:lower:]")" +tool_arch="x86_64" +tool_name_moniker="$tool_name-$version-$tool_os-$tool_arch" +tool_install_directory="$install_path/$tool_name/$version" +tool_file_path="$tool_install_directory/$tool_name_moniker/bin/$tool_name" +shim_path="$install_path/$tool_name.sh" +uri="${base_uri}/$tool_folder/$tool_name/$tool_name_moniker.tar.gz" + +# Clean up tool and installers +if [[ $clean = true ]]; then + echo "Cleaning $tool_install_directory" + if [[ -d $tool_install_directory ]]; then + rm -rf $tool_install_directory + fi + + echo "Cleaning $shim_path" + if [[ -f $shim_path ]]; then + rm -rf $shim_path + fi + + tool_temp_path=$(GetTempPathFileName $uri) + echo "Cleaning $tool_temp_path" + if [[ -f $tool_temp_path ]]; then + rm -rf $tool_temp_path + fi + + exit 0 +fi + +# Install tool +if [[ -f $tool_file_path ]] && [[ $force = false ]]; then + echo "$tool_name ($version) already exists, skipping install" + exit 0 +fi + +DownloadAndExtract $uri $tool_install_directory $force $download_retries $retry_wait_time_seconds + +if [[ $? != 0 ]]; then + Write-PipelineTelemetryError -category 'NativeToolsBootstrap' 'Installation failed' + exit 1 +fi + +# Generate Shim +# Always rewrite shims so that we are referencing the expected version +NewScriptShim $shim_path $tool_file_path true + +if [[ $? != 0 ]]; then + Write-PipelineTelemetryError -category 'NativeToolsBootstrap' 'Shim generation failed' + exit 1 +fi + +exit 0 diff --git a/eng/common/native/install-cmake.sh b/eng/common/native/install-cmake.sh new file mode 100755 index 0000000000000..de496beebc5ac --- /dev/null +++ b/eng/common/native/install-cmake.sh @@ -0,0 +1,117 @@ +#!/usr/bin/env bash + +source="${BASH_SOURCE[0]}" +scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + +. $scriptroot/common-library.sh + +base_uri= +install_path= +version= +clean=false +force=false +download_retries=5 +retry_wait_time_seconds=30 + +while (($# > 0)); do + lowerI="$(echo $1 | tr "[:upper:]" "[:lower:]")" + case $lowerI in + --baseuri) + base_uri=$2 + shift 2 + ;; + --installpath) + install_path=$2 + shift 2 + ;; + --version) + version=$2 + shift 2 + ;; + --clean) + clean=true + shift 1 + ;; + --force) + force=true + shift 1 + ;; + --downloadretries) + download_retries=$2 + shift 2 + ;; + --retrywaittimeseconds) + retry_wait_time_seconds=$2 + shift 2 + ;; + --help) + echo "Common settings:" + echo " --baseuri Base file directory or Url wrom which to acquire tool archives" + echo " --installpath Base directory to install native tool to" + echo " --clean Don't install the tool, just clean up the current install of the tool" + echo " --force Force install of tools even if they previously exist" + echo " --help Print help and exit" + echo "" + echo "Advanced settings:" + echo " --downloadretries Total number of retry attempts" + echo " --retrywaittimeseconds Wait time between retry attempts in seconds" + echo "" + exit 0 + ;; + esac +done + +tool_name="cmake" +tool_os=$(GetCurrentOS) +tool_folder="$(echo $tool_os | tr "[:upper:]" "[:lower:]")" +tool_arch="x86_64" +tool_name_moniker="$tool_name-$version-$tool_os-$tool_arch" +tool_install_directory="$install_path/$tool_name/$version" +tool_file_path="$tool_install_directory/$tool_name_moniker/bin/$tool_name" +shim_path="$install_path/$tool_name.sh" +uri="${base_uri}/$tool_folder/$tool_name/$tool_name_moniker.tar.gz" + +# Clean up tool and installers +if [[ $clean = true ]]; then + echo "Cleaning $tool_install_directory" + if [[ -d $tool_install_directory ]]; then + rm -rf $tool_install_directory + fi + + echo "Cleaning $shim_path" + if [[ -f $shim_path ]]; then + rm -rf $shim_path + fi + + tool_temp_path=$(GetTempPathFileName $uri) + echo "Cleaning $tool_temp_path" + if [[ -f $tool_temp_path ]]; then + rm -rf $tool_temp_path + fi + + exit 0 +fi + +# Install tool +if [[ -f $tool_file_path ]] && [[ $force = false ]]; then + echo "$tool_name ($version) already exists, skipping install" + exit 0 +fi + +DownloadAndExtract $uri $tool_install_directory $force $download_retries $retry_wait_time_seconds + +if [[ $? != 0 ]]; then + Write-PipelineTelemetryError -category 'NativeToolsBootstrap' 'Installation failed' + exit 1 +fi + +# Generate Shim +# Always rewrite shims so that we are referencing the expected version +NewScriptShim $shim_path $tool_file_path true + +if [[ $? != 0 ]]; then + Write-PipelineTelemetryError -category 'NativeToolsBootstrap' 'Shim generation failed' + exit 1 +fi + +exit 0 diff --git a/eng/common/native/install-tool.ps1 b/eng/common/native/install-tool.ps1 new file mode 100644 index 0000000000000..78f2d84a4e4b1 --- /dev/null +++ b/eng/common/native/install-tool.ps1 @@ -0,0 +1,132 @@ +<# +.SYNOPSIS +Install native tool + +.DESCRIPTION +Install cmake native tool from Azure blob storage + +.PARAMETER InstallPath +Base directory to install native tool to + +.PARAMETER BaseUri +Base file directory or Url from which to acquire tool archives + +.PARAMETER CommonLibraryDirectory +Path to folder containing common library modules + +.PARAMETER Force +Force install of tools even if they previously exist + +.PARAMETER Clean +Don't install the tool, just clean up the current install of the tool + +.PARAMETER DownloadRetries +Total number of retry attempts + +.PARAMETER RetryWaitTimeInSeconds +Wait time between retry attempts in seconds + +.NOTES +Returns 0 if install succeeds, 1 otherwise +#> +[CmdletBinding(PositionalBinding=$false)] +Param ( + [Parameter(Mandatory=$True)] + [string] $ToolName, + [Parameter(Mandatory=$True)] + [string] $InstallPath, + [Parameter(Mandatory=$True)] + [string] $BaseUri, + [Parameter(Mandatory=$True)] + [string] $Version, + [string] $CommonLibraryDirectory = $PSScriptRoot, + [switch] $Force = $False, + [switch] $Clean = $False, + [int] $DownloadRetries = 5, + [int] $RetryWaitTimeInSeconds = 30 +) + +. $PSScriptRoot\..\pipeline-logging-functions.ps1 + +# Import common library modules +Import-Module -Name (Join-Path $CommonLibraryDirectory "CommonLibrary.psm1") + +try { + # Define verbose switch if undefined + $Verbose = $VerbosePreference -Eq "Continue" + + $Arch = CommonLibrary\Get-MachineArchitecture + $ToolOs = "win64" + if($Arch -Eq "x32") { + $ToolOs = "win32" + } + $ToolNameMoniker = "$ToolName-$Version-$ToolOs-$Arch" + $ToolInstallDirectory = Join-Path $InstallPath "$ToolName\$Version\" + $Uri = "$BaseUri/windows/$ToolName/$ToolNameMoniker.zip" + $ShimPath = Join-Path $InstallPath "$ToolName.exe" + + if ($Clean) { + Write-Host "Cleaning $ToolInstallDirectory" + if (Test-Path $ToolInstallDirectory) { + Remove-Item $ToolInstallDirectory -Force -Recurse + } + Write-Host "Cleaning $ShimPath" + if (Test-Path $ShimPath) { + Remove-Item $ShimPath -Force + } + $ToolTempPath = CommonLibrary\Get-TempPathFilename -Path $Uri + Write-Host "Cleaning $ToolTempPath" + if (Test-Path $ToolTempPath) { + Remove-Item $ToolTempPath -Force + } + exit 0 + } + + # Install tool + if ((Test-Path $ToolInstallDirectory) -And (-Not $Force)) { + Write-Verbose "$ToolName ($Version) already exists, skipping install" + } + else { + $InstallStatus = CommonLibrary\DownloadAndExtract -Uri $Uri ` + -InstallDirectory $ToolInstallDirectory ` + -Force:$Force ` + -DownloadRetries $DownloadRetries ` + -RetryWaitTimeInSeconds $RetryWaitTimeInSeconds ` + -Verbose:$Verbose + + if ($InstallStatus -Eq $False) { + Write-PipelineTelemetryError "Installation failed" -Category "NativeToolsetBootstrapping" + exit 1 + } + } + + $ToolFilePath = Get-ChildItem $ToolInstallDirectory -Recurse -Filter "$ToolName.exe" | % { $_.FullName } + if (@($ToolFilePath).Length -Gt 1) { + Write-Error "There are multiple copies of $ToolName in $($ToolInstallDirectory): `n$(@($ToolFilePath | out-string))" + exit 1 + } elseif (@($ToolFilePath).Length -Lt 1) { + Write-Host "$ToolName was not found in $ToolInstallDirectory." + exit 1 + } + + # Generate shim + # Always rewrite shims so that we are referencing the expected version + $GenerateShimStatus = CommonLibrary\New-ScriptShim -ShimName $ToolName ` + -ShimDirectory $InstallPath ` + -ToolFilePath "$ToolFilePath" ` + -BaseUri $BaseUri ` + -Force:$Force ` + -Verbose:$Verbose + + if ($GenerateShimStatus -Eq $False) { + Write-PipelineTelemetryError "Generate shim failed" -Category "NativeToolsetBootstrapping" + return 1 + } + + exit 0 +} +catch { + Write-Host $_.ScriptStackTrace + Write-PipelineTelemetryError -Category "NativeToolsetBootstrapping" -Message $_ + exit 1 +} diff --git a/eng/common/pipeline-logging-functions.ps1 b/eng/common/pipeline-logging-functions.ps1 new file mode 100644 index 0000000000000..8e422c561e4bd --- /dev/null +++ b/eng/common/pipeline-logging-functions.ps1 @@ -0,0 +1,260 @@ +# Source for this file was taken from https://github.com/microsoft/azure-pipelines-task-lib/blob/11c9439d4af17e6475d9fe058e6b2e03914d17e6/powershell/VstsTaskSdk/LoggingCommandFunctions.ps1 and modified. + +# NOTE: You should not be calling these method directly as they are likely to change. Instead you should be calling the Write-Pipeline* functions defined in tools.ps1 + +$script:loggingCommandPrefix = '##vso[' +$script:loggingCommandEscapeMappings = @( # TODO: WHAT ABOUT "="? WHAT ABOUT "%"? + New-Object psobject -Property @{ Token = ';' ; Replacement = '%3B' } + New-Object psobject -Property @{ Token = "`r" ; Replacement = '%0D' } + New-Object psobject -Property @{ Token = "`n" ; Replacement = '%0A' } + New-Object psobject -Property @{ Token = "]" ; Replacement = '%5D' } +) +# TODO: BUG: Escape % ??? +# TODO: Add test to verify don't need to escape "=". + +# Specify "-Force" to force pipeline formatted output even if "$ci" is false or not set +function Write-PipelineTelemetryError { + [CmdletBinding()] + param( + [Parameter(Mandatory = $true)] + [string]$Category, + [Parameter(Mandatory = $true)] + [string]$Message, + [Parameter(Mandatory = $false)] + [string]$Type = 'error', + [string]$ErrCode, + [string]$SourcePath, + [string]$LineNumber, + [string]$ColumnNumber, + [switch]$AsOutput, + [switch]$Force) + + $PSBoundParameters.Remove('Category') | Out-Null + + if ($Force -Or ((Test-Path variable:ci) -And $ci)) { + $Message = "(NETCORE_ENGINEERING_TELEMETRY=$Category) $Message" + } + $PSBoundParameters.Remove('Message') | Out-Null + $PSBoundParameters.Add('Message', $Message) + Write-PipelineTaskError @PSBoundParameters +} + +# Specify "-Force" to force pipeline formatted output even if "$ci" is false or not set +function Write-PipelineTaskError { + [CmdletBinding()] + param( + [Parameter(Mandatory = $true)] + [string]$Message, + [Parameter(Mandatory = $false)] + [string]$Type = 'error', + [string]$ErrCode, + [string]$SourcePath, + [string]$LineNumber, + [string]$ColumnNumber, + [switch]$AsOutput, + [switch]$Force + ) + + if (!$Force -And (-Not (Test-Path variable:ci) -Or !$ci)) { + if ($Type -eq 'error') { + Write-Host $Message -ForegroundColor Red + return + } + elseif ($Type -eq 'warning') { + Write-Host $Message -ForegroundColor Yellow + return + } + } + + if (($Type -ne 'error') -and ($Type -ne 'warning')) { + Write-Host $Message + return + } + $PSBoundParameters.Remove('Force') | Out-Null + if (-not $PSBoundParameters.ContainsKey('Type')) { + $PSBoundParameters.Add('Type', 'error') + } + Write-LogIssue @PSBoundParameters +} + +function Write-PipelineSetVariable { + [CmdletBinding()] + param( + [Parameter(Mandatory = $true)] + [string]$Name, + [string]$Value, + [switch]$Secret, + [switch]$AsOutput, + [bool]$IsMultiJobVariable = $true) + + if ((Test-Path variable:ci) -And $ci) { + Write-LoggingCommand -Area 'task' -Event 'setvariable' -Data $Value -Properties @{ + 'variable' = $Name + 'isSecret' = $Secret + 'isOutput' = $IsMultiJobVariable + } -AsOutput:$AsOutput + } +} + +function Write-PipelinePrependPath { + [CmdletBinding()] + param( + [Parameter(Mandatory = $true)] + [string]$Path, + [switch]$AsOutput) + + if ((Test-Path variable:ci) -And $ci) { + Write-LoggingCommand -Area 'task' -Event 'prependpath' -Data $Path -AsOutput:$AsOutput + } +} + +function Write-PipelineSetResult { + [CmdletBinding()] + param( + [ValidateSet("Succeeded", "SucceededWithIssues", "Failed", "Cancelled", "Skipped")] + [Parameter(Mandatory = $true)] + [string]$Result, + [string]$Message) + if ((Test-Path variable:ci) -And $ci) { + Write-LoggingCommand -Area 'task' -Event 'complete' -Data $Message -Properties @{ + 'result' = $Result + } + } +} + +<######################################## +# Private functions. +########################################> +function Format-LoggingCommandData { + [CmdletBinding()] + param([string]$Value, [switch]$Reverse) + + if (!$Value) { + return '' + } + + if (!$Reverse) { + foreach ($mapping in $script:loggingCommandEscapeMappings) { + $Value = $Value.Replace($mapping.Token, $mapping.Replacement) + } + } + else { + for ($i = $script:loggingCommandEscapeMappings.Length - 1 ; $i -ge 0 ; $i--) { + $mapping = $script:loggingCommandEscapeMappings[$i] + $Value = $Value.Replace($mapping.Replacement, $mapping.Token) + } + } + + return $Value +} + +function Format-LoggingCommand { + [CmdletBinding()] + param( + [Parameter(Mandatory = $true)] + [string]$Area, + [Parameter(Mandatory = $true)] + [string]$Event, + [string]$Data, + [hashtable]$Properties) + + # Append the preamble. + [System.Text.StringBuilder]$sb = New-Object -TypeName System.Text.StringBuilder + $null = $sb.Append($script:loggingCommandPrefix).Append($Area).Append('.').Append($Event) + + # Append the properties. + if ($Properties) { + $first = $true + foreach ($key in $Properties.Keys) { + [string]$value = Format-LoggingCommandData $Properties[$key] + if ($value) { + if ($first) { + $null = $sb.Append(' ') + $first = $false + } + else { + $null = $sb.Append(';') + } + + $null = $sb.Append("$key=$value") + } + } + } + + # Append the tail and output the value. + $Data = Format-LoggingCommandData $Data + $sb.Append(']').Append($Data).ToString() +} + +function Write-LoggingCommand { + [CmdletBinding(DefaultParameterSetName = 'Parameters')] + param( + [Parameter(Mandatory = $true, ParameterSetName = 'Parameters')] + [string]$Area, + [Parameter(Mandatory = $true, ParameterSetName = 'Parameters')] + [string]$Event, + [Parameter(ParameterSetName = 'Parameters')] + [string]$Data, + [Parameter(ParameterSetName = 'Parameters')] + [hashtable]$Properties, + [Parameter(Mandatory = $true, ParameterSetName = 'Object')] + $Command, + [switch]$AsOutput) + + if ($PSCmdlet.ParameterSetName -eq 'Object') { + Write-LoggingCommand -Area $Command.Area -Event $Command.Event -Data $Command.Data -Properties $Command.Properties -AsOutput:$AsOutput + return + } + + $command = Format-LoggingCommand -Area $Area -Event $Event -Data $Data -Properties $Properties + if ($AsOutput) { + $command + } + else { + Write-Host $command + } +} + +function Write-LogIssue { + [CmdletBinding()] + param( + [ValidateSet('warning', 'error')] + [Parameter(Mandatory = $true)] + [string]$Type, + [string]$Message, + [string]$ErrCode, + [string]$SourcePath, + [string]$LineNumber, + [string]$ColumnNumber, + [switch]$AsOutput) + + $command = Format-LoggingCommand -Area 'task' -Event 'logissue' -Data $Message -Properties @{ + 'type' = $Type + 'code' = $ErrCode + 'sourcepath' = $SourcePath + 'linenumber' = $LineNumber + 'columnnumber' = $ColumnNumber + } + if ($AsOutput) { + return $command + } + + if ($Type -eq 'error') { + $foregroundColor = $host.PrivateData.ErrorForegroundColor + $backgroundColor = $host.PrivateData.ErrorBackgroundColor + if ($foregroundColor -isnot [System.ConsoleColor] -or $backgroundColor -isnot [System.ConsoleColor]) { + $foregroundColor = [System.ConsoleColor]::Red + $backgroundColor = [System.ConsoleColor]::Black + } + } + else { + $foregroundColor = $host.PrivateData.WarningForegroundColor + $backgroundColor = $host.PrivateData.WarningBackgroundColor + if ($foregroundColor -isnot [System.ConsoleColor] -or $backgroundColor -isnot [System.ConsoleColor]) { + $foregroundColor = [System.ConsoleColor]::Yellow + $backgroundColor = [System.ConsoleColor]::Black + } + } + + Write-Host $command -ForegroundColor $foregroundColor -BackgroundColor $backgroundColor +} diff --git a/eng/common/pipeline-logging-functions.sh b/eng/common/pipeline-logging-functions.sh new file mode 100755 index 0000000000000..6a0b2255e9118 --- /dev/null +++ b/eng/common/pipeline-logging-functions.sh @@ -0,0 +1,206 @@ +#!/usr/bin/env bash + +function Write-PipelineTelemetryError { + local telemetry_category='' + local force=false + local function_args=() + local message='' + while [[ $# -gt 0 ]]; do + opt="$(echo "${1/#--/-}" | tr "[:upper:]" "[:lower:]")" + case "$opt" in + -category|-c) + telemetry_category=$2 + shift + ;; + -force|-f) + force=true + ;; + -*) + function_args+=("$1 $2") + shift + ;; + *) + message=$* + ;; + esac + shift + done + + if [[ $force != true ]] && [[ "$ci" != true ]]; then + echo "$message" >&2 + return + fi + + if [[ $force == true ]]; then + function_args+=("-force") + fi + message="(NETCORE_ENGINEERING_TELEMETRY=$telemetry_category) $message" + function_args+=("$message") + Write-PipelineTaskError ${function_args[@]} +} + +function Write-PipelineTaskError { + local message_type="error" + local sourcepath='' + local linenumber='' + local columnnumber='' + local error_code='' + local force=false + + while [[ $# -gt 0 ]]; do + opt="$(echo "${1/#--/-}" | tr "[:upper:]" "[:lower:]")" + case "$opt" in + -type|-t) + message_type=$2 + shift + ;; + -sourcepath|-s) + sourcepath=$2 + shift + ;; + -linenumber|-ln) + linenumber=$2 + shift + ;; + -columnnumber|-cn) + columnnumber=$2 + shift + ;; + -errcode|-e) + error_code=$2 + shift + ;; + -force|-f) + force=true + ;; + *) + break + ;; + esac + + shift + done + + if [[ $force != true ]] && [[ "$ci" != true ]]; then + echo "$@" >&2 + return + fi + + local message="##vso[task.logissue" + + message="$message type=$message_type" + + if [ -n "$sourcepath" ]; then + message="$message;sourcepath=$sourcepath" + fi + + if [ -n "$linenumber" ]; then + message="$message;linenumber=$linenumber" + fi + + if [ -n "$columnnumber" ]; then + message="$message;columnnumber=$columnnumber" + fi + + if [ -n "$error_code" ]; then + message="$message;code=$error_code" + fi + + message="$message]$*" + echo "$message" +} + +function Write-PipelineSetVariable { + if [[ "$ci" != true ]]; then + return + fi + + local name='' + local value='' + local secret=false + local as_output=false + local is_multi_job_variable=true + + while [[ $# -gt 0 ]]; do + opt="$(echo "${1/#--/-}" | tr "[:upper:]" "[:lower:]")" + case "$opt" in + -name|-n) + name=$2 + shift + ;; + -value|-v) + value=$2 + shift + ;; + -secret|-s) + secret=true + ;; + -as_output|-a) + as_output=true + ;; + -is_multi_job_variable|-i) + is_multi_job_variable=$2 + shift + ;; + esac + shift + done + + value=${value/;/%3B} + value=${value/\\r/%0D} + value=${value/\\n/%0A} + value=${value/]/%5D} + + local message="##vso[task.setvariable variable=$name;isSecret=$secret;isOutput=$is_multi_job_variable]$value" + + if [[ "$as_output" == true ]]; then + $message + else + echo "$message" + fi +} + +function Write-PipelinePrependPath { + local prepend_path='' + + while [[ $# -gt 0 ]]; do + opt="$(echo "${1/#--/-}" | tr "[:upper:]" "[:lower:]")" + case "$opt" in + -path|-p) + prepend_path=$2 + shift + ;; + esac + shift + done + + export PATH="$prepend_path:$PATH" + + if [[ "$ci" == true ]]; then + echo "##vso[task.prependpath]$prepend_path" + fi +} + +function Write-PipelineSetResult { + local result='' + local message='' + + while [[ $# -gt 0 ]]; do + opt="$(echo "${1/#--/-}" | tr "[:upper:]" "[:lower:]")" + case "$opt" in + -result|-r) + result=$2 + shift + ;; + -message|-m) + message=$2 + shift + ;; + esac + shift + done + + if [[ "$ci" == true ]]; then + echo "##vso[task.complete result=$result;]$message" + fi +} diff --git a/eng/common/post-build/add-build-to-channel.ps1 b/eng/common/post-build/add-build-to-channel.ps1 new file mode 100644 index 0000000000000..de2d957922a65 --- /dev/null +++ b/eng/common/post-build/add-build-to-channel.ps1 @@ -0,0 +1,48 @@ +param( + [Parameter(Mandatory=$true)][int] $BuildId, + [Parameter(Mandatory=$true)][int] $ChannelId, + [Parameter(Mandatory=$true)][string] $MaestroApiAccessToken, + [Parameter(Mandatory=$false)][string] $MaestroApiEndPoint = 'https://maestro-prod.westus2.cloudapp.azure.com', + [Parameter(Mandatory=$false)][string] $MaestroApiVersion = '2019-01-16' +) + +try { + . $PSScriptRoot\post-build-utils.ps1 + + # Check that the channel we are going to promote the build to exist + $channelInfo = Get-MaestroChannel -ChannelId $ChannelId + + if (!$channelInfo) { + Write-PipelineTelemetryCategory -Category 'PromoteBuild' -Message "Channel with BAR ID $ChannelId was not found in BAR!" + ExitWithExitCode 1 + } + + # Get info about which channel(s) the build has already been promoted to + $buildInfo = Get-MaestroBuild -BuildId $BuildId + + if (!$buildInfo) { + Write-PipelineTelemetryError -Category 'PromoteBuild' -Message "Build with BAR ID $BuildId was not found in BAR!" + ExitWithExitCode 1 + } + + # Find whether the build is already assigned to the channel or not + if ($buildInfo.channels) { + foreach ($channel in $buildInfo.channels) { + if ($channel.Id -eq $ChannelId) { + Write-Host "The build with BAR ID $BuildId is already on channel $ChannelId!" + ExitWithExitCode 0 + } + } + } + + Write-Host "Promoting build '$BuildId' to channel '$ChannelId'." + + Assign-BuildToChannel -BuildId $BuildId -ChannelId $ChannelId + + Write-Host 'done.' +} +catch { + Write-Host $_ + Write-PipelineTelemetryError -Category 'PromoteBuild' -Message "There was an error while trying to promote build '$BuildId' to channel '$ChannelId'" + ExitWithExitCode 1 +} diff --git a/eng/common/post-build/check-channel-consistency.ps1 b/eng/common/post-build/check-channel-consistency.ps1 new file mode 100644 index 0000000000000..63f3464c986a7 --- /dev/null +++ b/eng/common/post-build/check-channel-consistency.ps1 @@ -0,0 +1,40 @@ +param( + [Parameter(Mandatory=$true)][string] $PromoteToChannels, # List of channels that the build should be promoted to + [Parameter(Mandatory=$true)][array] $AvailableChannelIds # List of channel IDs available in the YAML implementation +) + +try { + . $PSScriptRoot\post-build-utils.ps1 + + if ($PromoteToChannels -eq "") { + Write-PipelineTaskError -Type 'warning' -Message "This build won't publish assets as it's not configured to any Maestro channel. If that wasn't intended use Darc to configure a default channel using add-default-channel for this branch or to promote it to a channel using add-build-to-channel. See https://github.com/dotnet/arcade/blob/master/Documentation/Darc.md#assigning-an-individual-build-to-a-channel for more info." + ExitWithExitCode 0 + } + + # Check that every channel that Maestro told to promote the build to + # is available in YAML + $PromoteToChannelsIds = $PromoteToChannels -split "\D" | Where-Object { $_ } + + $hasErrors = $false + + foreach ($id in $PromoteToChannelsIds) { + if (($id -ne 0) -and ($id -notin $AvailableChannelIds)) { + Write-PipelineTaskError -Message "Channel $id is not present in the post-build YAML configuration! This is an error scenario. Please contact @dnceng." + $hasErrors = $true + } + } + + # The `Write-PipelineTaskError` doesn't error the script and we might report several errors + # in the previous lines. The check below makes sure that we return an error state from the + # script if we reported any validation error + if ($hasErrors) { + ExitWithExitCode 1 + } + + Write-Host 'done.' +} +catch { + Write-Host $_ + Write-PipelineTelemetryError -Category 'CheckChannelConsistency' -Message "There was an error while trying to check consistency of Maestro default channels for the build and post-build YAML configuration." + ExitWithExitCode 1 +} diff --git a/eng/common/post-build/nuget-validation.ps1 b/eng/common/post-build/nuget-validation.ps1 new file mode 100644 index 0000000000000..dab3534ab5389 --- /dev/null +++ b/eng/common/post-build/nuget-validation.ps1 @@ -0,0 +1,24 @@ +# This script validates NuGet package metadata information using this +# tool: https://github.com/NuGet/NuGetGallery/tree/jver-verify/src/VerifyMicrosoftPackage + +param( + [Parameter(Mandatory=$true)][string] $PackagesPath, # Path to where the packages to be validated are + [Parameter(Mandatory=$true)][string] $ToolDestinationPath # Where the validation tool should be downloaded to +) + +try { + . $PSScriptRoot\post-build-utils.ps1 + + $url = 'https://raw.githubusercontent.com/NuGet/NuGetGallery/3e25ad135146676bcab0050a516939d9958bfa5d/src/VerifyMicrosoftPackage/verify.ps1' + + New-Item -ItemType 'directory' -Path ${ToolDestinationPath} -Force + + Invoke-WebRequest $url -OutFile ${ToolDestinationPath}\verify.ps1 + + & ${ToolDestinationPath}\verify.ps1 ${PackagesPath}\*.nupkg +} +catch { + Write-Host $_.ScriptStackTrace + Write-PipelineTelemetryError -Category 'NuGetValidation' -Message $_ + ExitWithExitCode 1 +} diff --git a/eng/common/post-build/post-build-utils.ps1 b/eng/common/post-build/post-build-utils.ps1 new file mode 100644 index 0000000000000..534f6988d5b7f --- /dev/null +++ b/eng/common/post-build/post-build-utils.ps1 @@ -0,0 +1,91 @@ +# Most of the functions in this file require the variables `MaestroApiEndPoint`, +# `MaestroApiVersion` and `MaestroApiAccessToken` to be globally available. + +$ErrorActionPreference = 'Stop' +Set-StrictMode -Version 2.0 + +# `tools.ps1` checks $ci to perform some actions. Since the post-build +# scripts don't necessarily execute in the same agent that run the +# build.ps1/sh script this variable isn't automatically set. +$ci = $true +$disableConfigureToolsetImport = $true +. $PSScriptRoot\..\tools.ps1 + +function Create-MaestroApiRequestHeaders([string]$ContentType = 'application/json') { + Validate-MaestroVars + + $headers = New-Object 'System.Collections.Generic.Dictionary[[String],[String]]' + $headers.Add('Accept', $ContentType) + $headers.Add('Authorization',"Bearer $MaestroApiAccessToken") + return $headers +} + +function Get-MaestroChannel([int]$ChannelId) { + Validate-MaestroVars + + $apiHeaders = Create-MaestroApiRequestHeaders + $apiEndpoint = "$MaestroApiEndPoint/api/channels/${ChannelId}?api-version=$MaestroApiVersion" + + $result = try { Invoke-WebRequest -Method Get -Uri $apiEndpoint -Headers $apiHeaders | ConvertFrom-Json } catch { Write-Host "Error: $_" } + return $result +} + +function Get-MaestroBuild([int]$BuildId) { + Validate-MaestroVars + + $apiHeaders = Create-MaestroApiRequestHeaders -AuthToken $MaestroApiAccessToken + $apiEndpoint = "$MaestroApiEndPoint/api/builds/${BuildId}?api-version=$MaestroApiVersion" + + $result = try { return Invoke-WebRequest -Method Get -Uri $apiEndpoint -Headers $apiHeaders | ConvertFrom-Json } catch { Write-Host "Error: $_" } + return $result +} + +function Get-MaestroSubscriptions([string]$SourceRepository, [int]$ChannelId) { + Validate-MaestroVars + + $SourceRepository = [System.Web.HttpUtility]::UrlEncode($SourceRepository) + $apiHeaders = Create-MaestroApiRequestHeaders -AuthToken $MaestroApiAccessToken + $apiEndpoint = "$MaestroApiEndPoint/api/subscriptions?sourceRepository=$SourceRepository&channelId=$ChannelId&api-version=$MaestroApiVersion" + + $result = try { Invoke-WebRequest -Method Get -Uri $apiEndpoint -Headers $apiHeaders | ConvertFrom-Json } catch { Write-Host "Error: $_" } + return $result +} + +function Assign-BuildToChannel([int]$BuildId, [int]$ChannelId) { + Validate-MaestroVars + + $apiHeaders = Create-MaestroApiRequestHeaders -AuthToken $MaestroApiAccessToken + $apiEndpoint = "$MaestroApiEndPoint/api/channels/${ChannelId}/builds/${BuildId}?api-version=$MaestroApiVersion" + Invoke-WebRequest -Method Post -Uri $apiEndpoint -Headers $apiHeaders | Out-Null +} + +function Trigger-Subscription([string]$SubscriptionId) { + Validate-MaestroVars + + $apiHeaders = Create-MaestroApiRequestHeaders -AuthToken $MaestroApiAccessToken + $apiEndpoint = "$MaestroApiEndPoint/api/subscriptions/$SubscriptionId/trigger?api-version=$MaestroApiVersion" + Invoke-WebRequest -Uri $apiEndpoint -Headers $apiHeaders -Method Post | Out-Null +} + +function Validate-MaestroVars { + try { + Get-Variable MaestroApiEndPoint | Out-Null + Get-Variable MaestroApiVersion | Out-Null + Get-Variable MaestroApiAccessToken | Out-Null + + if (!($MaestroApiEndPoint -Match '^http[s]?://maestro-(int|prod).westus2.cloudapp.azure.com$')) { + Write-PipelineTelemetryError -Category 'MaestroVars' -Message "MaestroApiEndPoint is not a valid Maestro URL. '$MaestroApiEndPoint'" + ExitWithExitCode 1 + } + + if (!($MaestroApiVersion -Match '^[0-9]{4}-[0-9]{2}-[0-9]{2}$')) { + Write-PipelineTelemetryError -Category 'MaestroVars' -Message "MaestroApiVersion does not match a version string in the format yyyy-MM-DD. '$MaestroApiVersion'" + ExitWithExitCode 1 + } + } + catch { + Write-PipelineTelemetryError -Category 'MaestroVars' -Message 'Error: Variables `MaestroApiEndPoint`, `MaestroApiVersion` and `MaestroApiAccessToken` are required while using this script.' + Write-Host $_ + ExitWithExitCode 1 + } +} diff --git a/eng/common/post-build/publish-using-darc.ps1 b/eng/common/post-build/publish-using-darc.ps1 new file mode 100644 index 0000000000000..8508397d77640 --- /dev/null +++ b/eng/common/post-build/publish-using-darc.ps1 @@ -0,0 +1,54 @@ +param( + [Parameter(Mandatory=$true)][int] $BuildId, + [Parameter(Mandatory=$true)][int] $PublishingInfraVersion, + [Parameter(Mandatory=$true)][string] $AzdoToken, + [Parameter(Mandatory=$true)][string] $MaestroToken, + [Parameter(Mandatory=$false)][string] $MaestroApiEndPoint = 'https://maestro-prod.westus2.cloudapp.azure.com', + [Parameter(Mandatory=$true)][string] $WaitPublishingFinish, + [Parameter(Mandatory=$false)][string] $ArtifactsPublishingAdditionalParameters, + [Parameter(Mandatory=$false)][string] $SymbolPublishingAdditionalParameters +) + +try { + . $PSScriptRoot\post-build-utils.ps1 + + $darc = Get-Darc + + $optionalParams = [System.Collections.ArrayList]::new() + + if ("" -ne $ArtifactsPublishingAdditionalParameters) { + $optionalParams.Add("--artifact-publishing-parameters") | Out-Null + $optionalParams.Add($ArtifactsPublishingAdditionalParameters) | Out-Null + } + + if ("" -ne $SymbolPublishingAdditionalParameters) { + $optionalParams.Add("--symbol-publishing-parameters") | Out-Null + $optionalParams.Add($SymbolPublishingAdditionalParameters) | Out-Null + } + + if ("false" -eq $WaitPublishingFinish) { + $optionalParams.Add("--no-wait") | Out-Null + } + + & $darc add-build-to-channel ` + --id $buildId ` + --publishing-infra-version $PublishingInfraVersion ` + --default-channels ` + --source-branch main ` + --azdev-pat $AzdoToken ` + --bar-uri $MaestroApiEndPoint ` + --password $MaestroToken ` + @optionalParams + + if ($LastExitCode -ne 0) { + Write-Host "Problems using Darc to promote build ${buildId} to default channels. Stopping execution..." + exit 1 + } + + Write-Host 'done.' +} +catch { + Write-Host $_ + Write-PipelineTelemetryError -Category 'PromoteBuild' -Message "There was an error while trying to publish build '$BuildId' to default channels." + ExitWithExitCode 1 +} diff --git a/eng/common/post-build/sourcelink-validation.ps1 b/eng/common/post-build/sourcelink-validation.ps1 new file mode 100644 index 0000000000000..4011d324e7391 --- /dev/null +++ b/eng/common/post-build/sourcelink-validation.ps1 @@ -0,0 +1,319 @@ +param( + [Parameter(Mandatory=$true)][string] $InputPath, # Full path to directory where Symbols.NuGet packages to be checked are stored + [Parameter(Mandatory=$true)][string] $ExtractPath, # Full path to directory where the packages will be extracted during validation + [Parameter(Mandatory=$false)][string] $GHRepoName, # GitHub name of the repo including the Org. E.g., dotnet/arcade + [Parameter(Mandatory=$false)][string] $GHCommit, # GitHub commit SHA used to build the packages + [Parameter(Mandatory=$true)][string] $SourcelinkCliVersion # Version of SourceLink CLI to use +) + +. $PSScriptRoot\post-build-utils.ps1 + +# Cache/HashMap (File -> Exist flag) used to consult whether a file exist +# in the repository at a specific commit point. This is populated by inserting +# all files present in the repo at a specific commit point. +$global:RepoFiles = @{} + +# Maximum number of jobs to run in parallel +$MaxParallelJobs = 16 + +$MaxRetries = 5 +$RetryWaitTimeInSeconds = 30 + +# Wait time between check for system load +$SecondsBetweenLoadChecks = 10 + +if (!$InputPath -or !(Test-Path $InputPath)){ + Write-Host "No files to validate." + ExitWithExitCode 0 +} + +$ValidatePackage = { + param( + [string] $PackagePath # Full path to a Symbols.NuGet package + ) + + . $using:PSScriptRoot\..\tools.ps1 + + # Ensure input file exist + if (!(Test-Path $PackagePath)) { + Write-Host "Input file does not exist: $PackagePath" + return [pscustomobject]@{ + result = 1 + packagePath = $PackagePath + } + } + + # Extensions for which we'll look for SourceLink information + # For now we'll only care about Portable & Embedded PDBs + $RelevantExtensions = @('.dll', '.exe', '.pdb') + + Write-Host -NoNewLine 'Validating ' ([System.IO.Path]::GetFileName($PackagePath)) '...' + + $PackageId = [System.IO.Path]::GetFileNameWithoutExtension($PackagePath) + $ExtractPath = Join-Path -Path $using:ExtractPath -ChildPath $PackageId + $FailedFiles = 0 + + Add-Type -AssemblyName System.IO.Compression.FileSystem + + [System.IO.Directory]::CreateDirectory($ExtractPath) | Out-Null + + try { + $zip = [System.IO.Compression.ZipFile]::OpenRead($PackagePath) + + $zip.Entries | + Where-Object {$RelevantExtensions -contains [System.IO.Path]::GetExtension($_.Name)} | + ForEach-Object { + $FileName = $_.FullName + $Extension = [System.IO.Path]::GetExtension($_.Name) + $FakeName = -Join((New-Guid), $Extension) + $TargetFile = Join-Path -Path $ExtractPath -ChildPath $FakeName + + # We ignore resource DLLs + if ($FileName.EndsWith('.resources.dll')) { + return [pscustomobject]@{ + result = 0 + packagePath = $PackagePath + } + } + + [System.IO.Compression.ZipFileExtensions]::ExtractToFile($_, $TargetFile, $true) + + $ValidateFile = { + param( + [string] $FullPath, # Full path to the module that has to be checked + [string] $RealPath, + [ref] $FailedFiles + ) + + $sourcelinkExe = "$env:USERPROFILE\.dotnet\tools" + $sourcelinkExe = Resolve-Path "$sourcelinkExe\sourcelink.exe" + $SourceLinkInfos = & $sourcelinkExe print-urls $FullPath | Out-String + + if ($LASTEXITCODE -eq 0 -and -not ([string]::IsNullOrEmpty($SourceLinkInfos))) { + $NumFailedLinks = 0 + + # We only care about Http addresses + $Matches = (Select-String '(http[s]?)(:\/\/)([^\s,]+)' -Input $SourceLinkInfos -AllMatches).Matches + + if ($Matches.Count -ne 0) { + $Matches.Value | + ForEach-Object { + $Link = $_ + $CommitUrl = "https://raw.githubusercontent.com/${using:GHRepoName}/${using:GHCommit}/" + + $FilePath = $Link.Replace($CommitUrl, "") + $Status = 200 + $Cache = $using:RepoFiles + + $attempts = 0 + + while ($attempts -lt $using:MaxRetries) { + if ( !($Cache.ContainsKey($FilePath)) ) { + try { + $Uri = $Link -as [System.URI] + + if ($Link -match "submodules") { + # Skip submodule links until sourcelink properly handles submodules + $Status = 200 + } + elseif ($Uri.AbsoluteURI -ne $null -and ($Uri.Host -match 'github' -or $Uri.Host -match 'githubusercontent')) { + # Only GitHub links are valid + $Status = (Invoke-WebRequest -Uri $Link -UseBasicParsing -Method HEAD -TimeoutSec 5).StatusCode + } + else { + # If it's not a github link, we want to break out of the loop and not retry. + $Status = 0 + $attempts = $using:MaxRetries + } + } + catch { + Write-Host $_ + $Status = 0 + } + } + + if ($Status -ne 200) { + $attempts++ + + if ($attempts -lt $using:MaxRetries) + { + $attemptsLeft = $using:MaxRetries - $attempts + Write-Warning "Download failed, $attemptsLeft attempts remaining, will retry in $using:RetryWaitTimeInSeconds seconds" + Start-Sleep -Seconds $using:RetryWaitTimeInSeconds + } + else { + if ($NumFailedLinks -eq 0) { + if ($FailedFiles.Value -eq 0) { + Write-Host + } + + Write-Host "`tFile $RealPath has broken links:" + } + + Write-Host "`t`tFailed to retrieve $Link" + + $NumFailedLinks++ + } + } + else { + break + } + } + } + } + + if ($NumFailedLinks -ne 0) { + $FailedFiles.value++ + $global:LASTEXITCODE = 1 + } + } + } + + &$ValidateFile $TargetFile $FileName ([ref]$FailedFiles) + } + } + catch { + Write-Host $_ + } + finally { + $zip.Dispose() + } + + if ($FailedFiles -eq 0) { + Write-Host 'Passed.' + return [pscustomobject]@{ + result = 0 + packagePath = $PackagePath + } + } + else { + Write-PipelineTelemetryError -Category 'SourceLink' -Message "$PackagePath has broken SourceLink links." + return [pscustomobject]@{ + result = 1 + packagePath = $PackagePath + } + } +} + +function CheckJobResult( + $result, + $packagePath, + [ref]$ValidationFailures, + [switch]$logErrors) { + if ($result -ne '0') { + if ($logErrors) { + Write-PipelineTelemetryError -Category 'SourceLink' -Message "$packagePath has broken SourceLink links." + } + $ValidationFailures.Value++ + } +} + +function ValidateSourceLinkLinks { + if ($GHRepoName -ne '' -and !($GHRepoName -Match '^[^\s\/]+/[^\s\/]+$')) { + if (!($GHRepoName -Match '^[^\s-]+-[^\s]+$')) { + Write-PipelineTelemetryError -Category 'SourceLink' -Message "GHRepoName should be in the format / or -. '$GHRepoName'" + ExitWithExitCode 1 + } + else { + $GHRepoName = $GHRepoName -replace '^([^\s-]+)-([^\s]+)$', '$1/$2'; + } + } + + if ($GHCommit -ne '' -and !($GHCommit -Match '^[0-9a-fA-F]{40}$')) { + Write-PipelineTelemetryError -Category 'SourceLink' -Message "GHCommit should be a 40 chars hexadecimal string. '$GHCommit'" + ExitWithExitCode 1 + } + + if ($GHRepoName -ne '' -and $GHCommit -ne '') { + $RepoTreeURL = -Join('http://api.github.com/repos/', $GHRepoName, '/git/trees/', $GHCommit, '?recursive=1') + $CodeExtensions = @('.cs', '.vb', '.fs', '.fsi', '.fsx', '.fsscript') + + try { + # Retrieve the list of files in the repo at that particular commit point and store them in the RepoFiles hash + $Data = Invoke-WebRequest $RepoTreeURL -UseBasicParsing | ConvertFrom-Json | Select-Object -ExpandProperty tree + + foreach ($file in $Data) { + $Extension = [System.IO.Path]::GetExtension($file.path) + + if ($CodeExtensions.Contains($Extension)) { + $RepoFiles[$file.path] = 1 + } + } + } + catch { + Write-Host "Problems downloading the list of files from the repo. Url used: $RepoTreeURL . Execution will proceed without caching." + } + } + elseif ($GHRepoName -ne '' -or $GHCommit -ne '') { + Write-Host 'For using the http caching mechanism both GHRepoName and GHCommit should be informed.' + } + + if (Test-Path $ExtractPath) { + Remove-Item $ExtractPath -Force -Recurse -ErrorAction SilentlyContinue + } + + $ValidationFailures = 0 + + # Process each NuGet package in parallel + Get-ChildItem "$InputPath\*.symbols.nupkg" | + ForEach-Object { + Write-Host "Starting $($_.FullName)" + Start-Job -ScriptBlock $ValidatePackage -ArgumentList $_.FullName | Out-Null + $NumJobs = @(Get-Job -State 'Running').Count + + while ($NumJobs -ge $MaxParallelJobs) { + Write-Host "There are $NumJobs validation jobs running right now. Waiting $SecondsBetweenLoadChecks seconds to check again." + sleep $SecondsBetweenLoadChecks + $NumJobs = @(Get-Job -State 'Running').Count + } + + foreach ($Job in @(Get-Job -State 'Completed')) { + $jobResult = Wait-Job -Id $Job.Id | Receive-Job + CheckJobResult $jobResult.result $jobResult.packagePath ([ref]$ValidationFailures) -LogErrors + Remove-Job -Id $Job.Id + } + } + + foreach ($Job in @(Get-Job)) { + $jobResult = Wait-Job -Id $Job.Id | Receive-Job + CheckJobResult $jobResult.result $jobResult.packagePath ([ref]$ValidationFailures) + Remove-Job -Id $Job.Id + } + if ($ValidationFailures -gt 0) { + Write-PipelineTelemetryError -Category 'SourceLink' -Message "$ValidationFailures package(s) failed validation." + ExitWithExitCode 1 + } +} + +function InstallSourcelinkCli { + $sourcelinkCliPackageName = 'sourcelink' + + $dotnetRoot = InitializeDotNetCli -install:$true + $dotnet = "$dotnetRoot\dotnet.exe" + $toolList = & "$dotnet" tool list --global + + if (($toolList -like "*$sourcelinkCliPackageName*") -and ($toolList -like "*$sourcelinkCliVersion*")) { + Write-Host "SourceLink CLI version $sourcelinkCliVersion is already installed." + } + else { + Write-Host "Installing SourceLink CLI version $sourcelinkCliVersion..." + Write-Host 'You may need to restart your command window if this is the first dotnet tool you have installed.' + & "$dotnet" tool install $sourcelinkCliPackageName --version $sourcelinkCliVersion --verbosity "minimal" --global + } +} + +try { + InstallSourcelinkCli + + foreach ($Job in @(Get-Job)) { + Remove-Job -Id $Job.Id + } + + ValidateSourceLinkLinks +} +catch { + Write-Host $_.Exception + Write-Host $_.ScriptStackTrace + Write-PipelineTelemetryError -Category 'SourceLink' -Message $_ + ExitWithExitCode 1 +} diff --git a/eng/common/post-build/symbols-validation.ps1 b/eng/common/post-build/symbols-validation.ps1 new file mode 100644 index 0000000000000..cd2181bafa057 --- /dev/null +++ b/eng/common/post-build/symbols-validation.ps1 @@ -0,0 +1,339 @@ +param( + [Parameter(Mandatory = $true)][string] $InputPath, # Full path to directory where NuGet packages to be checked are stored + [Parameter(Mandatory = $true)][string] $ExtractPath, # Full path to directory where the packages will be extracted during validation + [Parameter(Mandatory = $true)][string] $DotnetSymbolVersion, # Version of dotnet symbol to use + [Parameter(Mandatory = $false)][switch] $CheckForWindowsPdbs, # If we should check for the existence of windows pdbs in addition to portable PDBs + [Parameter(Mandatory = $false)][switch] $ContinueOnError, # If we should keep checking symbols after an error + [Parameter(Mandatory = $false)][switch] $Clean, # Clean extracted symbols directory after checking symbols + [Parameter(Mandatory = $false)][string] $SymbolExclusionFile # Exclude the symbols in the file from publishing to symbol server +) + +. $PSScriptRoot\..\tools.ps1 +# Maximum number of jobs to run in parallel +$MaxParallelJobs = 16 + +# Max number of retries +$MaxRetry = 5 + +# Wait time between check for system load +$SecondsBetweenLoadChecks = 10 + +# Set error codes +Set-Variable -Name "ERROR_BADEXTRACT" -Option Constant -Value -1 +Set-Variable -Name "ERROR_FILEDOESNOTEXIST" -Option Constant -Value -2 + +$WindowsPdbVerificationParam = "" +if ($CheckForWindowsPdbs) { + $WindowsPdbVerificationParam = "--windows-pdbs" +} + +$ExclusionSet = New-Object System.Collections.Generic.HashSet[string]; + +if (!$InputPath -or !(Test-Path $InputPath)){ + Write-Host "No symbols to validate." + ExitWithExitCode 0 +} + +#Check if the path exists +if ($SymbolExclusionFile -and (Test-Path $SymbolExclusionFile)){ + [string[]]$Exclusions = Get-Content "$SymbolExclusionFile" + $Exclusions | foreach { if($_ -and $_.Trim()){$ExclusionSet.Add($_)} } +} +else{ + Write-Host "Symbol Exclusion file does not exists. No symbols to exclude." +} + +$CountMissingSymbols = { + param( + [string] $PackagePath, # Path to a NuGet package + [string] $WindowsPdbVerificationParam # If we should check for the existence of windows pdbs in addition to portable PDBs + ) + + Add-Type -AssemblyName System.IO.Compression.FileSystem + + Write-Host "Validating $PackagePath " + + # Ensure input file exist + if (!(Test-Path $PackagePath)) { + Write-PipelineTaskError "Input file does not exist: $PackagePath" + return [pscustomobject]@{ + result = $using:ERROR_FILEDOESNOTEXIST + packagePath = $PackagePath + } + } + + # Extensions for which we'll look for symbols + $RelevantExtensions = @('.dll', '.exe', '.so', '.dylib') + + # How many files are missing symbol information + $MissingSymbols = 0 + + $PackageId = [System.IO.Path]::GetFileNameWithoutExtension($PackagePath) + $PackageGuid = New-Guid + $ExtractPath = Join-Path -Path $using:ExtractPath -ChildPath $PackageGuid + $SymbolsPath = Join-Path -Path $ExtractPath -ChildPath 'Symbols' + + try { + [System.IO.Compression.ZipFile]::ExtractToDirectory($PackagePath, $ExtractPath) + } + catch { + Write-Host "Something went wrong extracting $PackagePath" + Write-Host $_ + return [pscustomobject]@{ + result = $using:ERROR_BADEXTRACT + packagePath = $PackagePath + } + } + + Get-ChildItem -Recurse $ExtractPath | + Where-Object { $RelevantExtensions -contains $_.Extension } | + ForEach-Object { + $FileName = $_.FullName + if ($FileName -Match '\\ref\\') { + Write-Host "`t Ignoring reference assembly file " $FileName + return + } + + $FirstMatchingSymbolDescriptionOrDefault = { + param( + [string] $FullPath, # Full path to the module that has to be checked + [string] $TargetServerParam, # Parameter to pass to `Symbol Tool` indicating the server to lookup for symbols + [string] $WindowsPdbVerificationParam, # Parameter to pass to potential check for windows-pdbs. + [string] $SymbolsPath + ) + + $FileName = [System.IO.Path]::GetFileName($FullPath) + $Extension = [System.IO.Path]::GetExtension($FullPath) + + # Those below are potential symbol files that the `dotnet symbol` might + # return. Which one will be returned depend on the type of file we are + # checking and which type of file was uploaded. + + # The file itself is returned + $SymbolPath = $SymbolsPath + '\' + $FileName + + # PDB file for the module + $PdbPath = $SymbolPath.Replace($Extension, '.pdb') + + # PDB file for R2R module (created by crossgen) + $NGenPdb = $SymbolPath.Replace($Extension, '.ni.pdb') + + # DBG file for a .so library + $SODbg = $SymbolPath.Replace($Extension, '.so.dbg') + + # DWARF file for a .dylib + $DylibDwarf = $SymbolPath.Replace($Extension, '.dylib.dwarf') + + $dotnetSymbolExe = "$env:USERPROFILE\.dotnet\tools" + $dotnetSymbolExe = Resolve-Path "$dotnetSymbolExe\dotnet-symbol.exe" + + $totalRetries = 0 + + while ($totalRetries -lt $using:MaxRetry) { + + # Save the output and get diagnostic output + $output = & $dotnetSymbolExe --symbols --modules $WindowsPdbVerificationParam $TargetServerParam $FullPath -o $SymbolsPath --diagnostics | Out-String + + if ((Test-Path $PdbPath) -and (Test-path $SymbolPath)) { + return 'Module and PDB for Module' + } + elseif ((Test-Path $NGenPdb) -and (Test-Path $PdbPath) -and (Test-Path $SymbolPath)) { + return 'Dll, PDB and NGen PDB' + } + elseif ((Test-Path $SODbg) -and (Test-Path $SymbolPath)) { + return 'So and DBG for SO' + } + elseif ((Test-Path $DylibDwarf) -and (Test-Path $SymbolPath)) { + return 'Dylib and Dwarf for Dylib' + } + elseif (Test-Path $SymbolPath) { + return 'Module' + } + else + { + $totalRetries++ + } + } + + return $null + } + + $FileRelativePath = $FileName.Replace("$ExtractPath\", "") + if (($($using:ExclusionSet) -ne $null) -and ($($using:ExclusionSet).Contains($FileRelativePath) -or ($($using:ExclusionSet).Contains($FileRelativePath.Replace("\", "/"))))){ + Write-Host "Skipping $FileName from symbol validation" + } + + else { + $FileGuid = New-Guid + $ExpandedSymbolsPath = Join-Path -Path $SymbolsPath -ChildPath $FileGuid + + $SymbolsOnMSDL = & $FirstMatchingSymbolDescriptionOrDefault ` + -FullPath $FileName ` + -TargetServerParam '--microsoft-symbol-server' ` + -SymbolsPath "$ExpandedSymbolsPath-msdl" ` + -WindowsPdbVerificationParam $WindowsPdbVerificationParam + $SymbolsOnSymWeb = & $FirstMatchingSymbolDescriptionOrDefault ` + -FullPath $FileName ` + -TargetServerParam '--internal-server' ` + -SymbolsPath "$ExpandedSymbolsPath-symweb" ` + -WindowsPdbVerificationParam $WindowsPdbVerificationParam + + Write-Host -NoNewLine "`t Checking file " $FileName "... " + + if ($SymbolsOnMSDL -ne $null -and $SymbolsOnSymWeb -ne $null) { + Write-Host "Symbols found on MSDL ($SymbolsOnMSDL) and SymWeb ($SymbolsOnSymWeb)" + } + else { + $MissingSymbols++ + + if ($SymbolsOnMSDL -eq $null -and $SymbolsOnSymWeb -eq $null) { + Write-Host 'No symbols found on MSDL or SymWeb!' + } + else { + if ($SymbolsOnMSDL -eq $null) { + Write-Host 'No symbols found on MSDL!' + } + else { + Write-Host 'No symbols found on SymWeb!' + } + } + } + } + } + + if ($using:Clean) { + Remove-Item $ExtractPath -Recurse -Force + } + + Pop-Location + + return [pscustomobject]@{ + result = $MissingSymbols + packagePath = $PackagePath + } +} + +function CheckJobResult( + $result, + $packagePath, + [ref]$DupedSymbols, + [ref]$TotalFailures) { + if ($result -eq $ERROR_BADEXTRACT) { + Write-PipelineTelemetryError -Category 'CheckSymbols' -Message "$packagePath has duplicated symbol files" + $DupedSymbols.Value++ + } + elseif ($result -eq $ERROR_FILEDOESNOTEXIST) { + Write-PipelineTelemetryError -Category 'CheckSymbols' -Message "$packagePath does not exist" + $TotalFailures.Value++ + } + elseif ($result -gt '0') { + Write-PipelineTelemetryError -Category 'CheckSymbols' -Message "Missing symbols for $result modules in the package $packagePath" + $TotalFailures.Value++ + } + else { + Write-Host "All symbols verified for package $packagePath" + } +} + +function CheckSymbolsAvailable { + if (Test-Path $ExtractPath) { + Remove-Item $ExtractPath -Force -Recurse -ErrorAction SilentlyContinue + } + + $TotalPackages = 0 + $TotalFailures = 0 + $DupedSymbols = 0 + + Get-ChildItem "$InputPath\*.nupkg" | + ForEach-Object { + $FileName = $_.Name + $FullName = $_.FullName + + # These packages from Arcade-Services include some native libraries that + # our current symbol uploader can't handle. Below is a workaround until + # we get issue: https://github.com/dotnet/arcade/issues/2457 sorted. + if ($FileName -Match 'Microsoft\.DotNet\.Darc\.') { + Write-Host "Ignoring Arcade-services file: $FileName" + Write-Host + return + } + elseif ($FileName -Match 'Microsoft\.DotNet\.Maestro\.Tasks\.') { + Write-Host "Ignoring Arcade-services file: $FileName" + Write-Host + return + } + + $TotalPackages++ + + Start-Job -ScriptBlock $CountMissingSymbols -ArgumentList @($FullName,$WindowsPdbVerificationParam) | Out-Null + + $NumJobs = @(Get-Job -State 'Running').Count + + while ($NumJobs -ge $MaxParallelJobs) { + Write-Host "There are $NumJobs validation jobs running right now. Waiting $SecondsBetweenLoadChecks seconds to check again." + sleep $SecondsBetweenLoadChecks + $NumJobs = @(Get-Job -State 'Running').Count + } + + foreach ($Job in @(Get-Job -State 'Completed')) { + $jobResult = Wait-Job -Id $Job.Id | Receive-Job + CheckJobResult $jobResult.result $jobResult.packagePath ([ref]$DupedSymbols) ([ref]$TotalFailures) + Remove-Job -Id $Job.Id + } + Write-Host + } + + foreach ($Job in @(Get-Job)) { + $jobResult = Wait-Job -Id $Job.Id | Receive-Job + CheckJobResult $jobResult.result $jobResult.packagePath ([ref]$DupedSymbols) ([ref]$TotalFailures) + } + + if ($TotalFailures -gt 0 -or $DupedSymbols -gt 0) { + if ($TotalFailures -gt 0) { + Write-PipelineTelemetryError -Category 'CheckSymbols' -Message "Symbols missing for $TotalFailures/$TotalPackages packages" + } + + if ($DupedSymbols -gt 0) { + Write-PipelineTelemetryError -Category 'CheckSymbols' -Message "$DupedSymbols/$TotalPackages packages had duplicated symbol files and could not be extracted" + } + + ExitWithExitCode 1 + } + else { + Write-Host "All symbols validated!" + } +} + +function InstallDotnetSymbol { + $dotnetSymbolPackageName = 'dotnet-symbol' + + $dotnetRoot = InitializeDotNetCli -install:$true + $dotnet = "$dotnetRoot\dotnet.exe" + $toolList = & "$dotnet" tool list --global + + if (($toolList -like "*$dotnetSymbolPackageName*") -and ($toolList -like "*$dotnetSymbolVersion*")) { + Write-Host "dotnet-symbol version $dotnetSymbolVersion is already installed." + } + else { + Write-Host "Installing dotnet-symbol version $dotnetSymbolVersion..." + Write-Host 'You may need to restart your command window if this is the first dotnet tool you have installed.' + & "$dotnet" tool install $dotnetSymbolPackageName --version $dotnetSymbolVersion --verbosity "minimal" --global + } +} + +try { + . $PSScriptRoot\post-build-utils.ps1 + + InstallDotnetSymbol + + foreach ($Job in @(Get-Job)) { + Remove-Job -Id $Job.Id + } + + CheckSymbolsAvailable +} +catch { + Write-Host $_.ScriptStackTrace + Write-PipelineTelemetryError -Category 'CheckSymbols' -Message $_ + ExitWithExitCode 1 +} diff --git a/eng/common/post-build/trigger-subscriptions.ps1 b/eng/common/post-build/trigger-subscriptions.ps1 new file mode 100644 index 0000000000000..55dea518ac585 --- /dev/null +++ b/eng/common/post-build/trigger-subscriptions.ps1 @@ -0,0 +1,64 @@ +param( + [Parameter(Mandatory=$true)][string] $SourceRepo, + [Parameter(Mandatory=$true)][int] $ChannelId, + [Parameter(Mandatory=$true)][string] $MaestroApiAccessToken, + [Parameter(Mandatory=$false)][string] $MaestroApiEndPoint = 'https://maestro-prod.westus2.cloudapp.azure.com', + [Parameter(Mandatory=$false)][string] $MaestroApiVersion = '2019-01-16' +) + +try { + . $PSScriptRoot\post-build-utils.ps1 + + # Get all the $SourceRepo subscriptions + $normalizedSourceRepo = $SourceRepo.Replace('dnceng@', '') + $subscriptions = Get-MaestroSubscriptions -SourceRepository $normalizedSourceRepo -ChannelId $ChannelId + + if (!$subscriptions) { + Write-PipelineTelemetryError -Category 'TriggerSubscriptions' -Message "No subscriptions found for source repo '$normalizedSourceRepo' in channel '$ChannelId'" + ExitWithExitCode 0 + } + + $subscriptionsToTrigger = New-Object System.Collections.Generic.List[string] + $failedTriggeredSubscription = $false + + # Get all enabled subscriptions that need dependency flow on 'everyBuild' + foreach ($subscription in $subscriptions) { + if ($subscription.enabled -and $subscription.policy.updateFrequency -like 'everyBuild' -and $subscription.channel.id -eq $ChannelId) { + Write-Host "Should trigger this subscription: ${$subscription.id}" + [void]$subscriptionsToTrigger.Add($subscription.id) + } + } + + foreach ($subscriptionToTrigger in $subscriptionsToTrigger) { + try { + Write-Host "Triggering subscription '$subscriptionToTrigger'." + + Trigger-Subscription -SubscriptionId $subscriptionToTrigger + + Write-Host 'done.' + } + catch + { + Write-Host "There was an error while triggering subscription '$subscriptionToTrigger'" + Write-Host $_ + Write-Host $_.ScriptStackTrace + $failedTriggeredSubscription = $true + } + } + + if ($subscriptionsToTrigger.Count -eq 0) { + Write-Host "No subscription matched source repo '$normalizedSourceRepo' and channel ID '$ChannelId'." + } + elseif ($failedTriggeredSubscription) { + Write-PipelineTelemetryError -Category 'TriggerSubscriptions' -Message 'At least one subscription failed to be triggered...' + ExitWithExitCode 1 + } + else { + Write-Host 'All subscriptions were triggered successfully!' + } +} +catch { + Write-Host $_.ScriptStackTrace + Write-PipelineTelemetryError -Category 'TriggerSubscriptions' -Message $_ + ExitWithExitCode 1 +} diff --git a/eng/common/retain-build.ps1 b/eng/common/retain-build.ps1 new file mode 100644 index 0000000000000..e7ba975adeb6b --- /dev/null +++ b/eng/common/retain-build.ps1 @@ -0,0 +1,45 @@ + +Param( +[Parameter(Mandatory=$true)][int] $buildId, +[Parameter(Mandatory=$true)][string] $azdoOrgUri, +[Parameter(Mandatory=$true)][string] $azdoProject, +[Parameter(Mandatory=$true)][string] $token +) + +$ErrorActionPreference = 'Stop' +Set-StrictMode -Version 2.0 + +function Get-AzDOHeaders( + [string] $token) +{ + $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":${token}")) + $headers = @{"Authorization"="Basic $base64AuthInfo"} + return $headers +} + +function Update-BuildRetention( + [string] $azdoOrgUri, + [string] $azdoProject, + [int] $buildId, + [string] $token) +{ + $headers = Get-AzDOHeaders -token $token + $requestBody = "{ + `"keepForever`": `"true`" + }" + + $requestUri = "${azdoOrgUri}/${azdoProject}/_apis/build/builds/${buildId}?api-version=6.0" + write-Host "Attempting to retain build using the following URI: ${requestUri} ..." + + try { + Invoke-RestMethod -Uri $requestUri -Method Patch -Body $requestBody -Header $headers -contentType "application/json" + Write-Host "Updated retention settings for build ${buildId}." + } + catch { + Write-Error "Failed to update retention settings for build: $_.Exception.Response.StatusDescription" + exit 1 + } +} + +Update-BuildRetention -azdoOrgUri $azdoOrgUri -azdoProject $azdoProject -buildId $buildId -token $token +exit 0 diff --git a/eng/common/sdk-task.ps1 b/eng/common/sdk-task.ps1 new file mode 100644 index 0000000000000..e10a596879746 --- /dev/null +++ b/eng/common/sdk-task.ps1 @@ -0,0 +1,97 @@ +[CmdletBinding(PositionalBinding=$false)] +Param( + [string] $configuration = 'Debug', + [string] $task, + [string] $verbosity = 'minimal', + [string] $msbuildEngine = $null, + [switch] $restore, + [switch] $prepareMachine, + [switch] $help, + [Parameter(ValueFromRemainingArguments=$true)][String[]]$properties +) + +$ci = $true +$binaryLog = $true +$warnAsError = $true + +. $PSScriptRoot\tools.ps1 + +function Print-Usage() { + Write-Host "Common settings:" + Write-Host " -task Name of Arcade task (name of a project in SdkTasks directory of the Arcade SDK package)" + Write-Host " -restore Restore dependencies" + Write-Host " -verbosity Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]" + Write-Host " -help Print help and exit" + Write-Host "" + + Write-Host "Advanced settings:" + Write-Host " -prepareMachine Prepare machine for CI run" + Write-Host " -msbuildEngine Msbuild engine to use to run build ('dotnet', 'vs', or unspecified)." + Write-Host "" + Write-Host "Command line arguments not listed above are passed thru to msbuild." +} + +function Build([string]$target) { + $logSuffix = if ($target -eq 'Execute') { '' } else { ".$target" } + $log = Join-Path $LogDir "$task$logSuffix.binlog" + $outputPath = Join-Path $ToolsetDir "$task\" + + MSBuild $taskProject ` + /bl:$log ` + /t:$target ` + /p:Configuration=$configuration ` + /p:RepoRoot=$RepoRoot ` + /p:BaseIntermediateOutputPath=$outputPath ` + /v:$verbosity ` + @properties +} + +try { + if ($help -or (($null -ne $properties) -and ($properties.Contains('/help') -or $properties.Contains('/?')))) { + Print-Usage + exit 0 + } + + if ($task -eq "") { + Write-PipelineTelemetryError -Category 'Build' -Message "Missing required parameter '-task '" + Print-Usage + ExitWithExitCode 1 + } + + if( $msbuildEngine -eq "vs") { + # Ensure desktop MSBuild is available for sdk tasks. + if( -not ($GlobalJson.tools.PSObject.Properties.Name -contains "vs" )) { + $GlobalJson.tools | Add-Member -Name "vs" -Value (ConvertFrom-Json "{ `"version`": `"16.5`" }") -MemberType NoteProperty + } + if( -not ($GlobalJson.tools.PSObject.Properties.Name -match "xcopy-msbuild" )) { + $GlobalJson.tools | Add-Member -Name "xcopy-msbuild" -Value "17.4.1" -MemberType NoteProperty + } + if ($GlobalJson.tools."xcopy-msbuild".Trim() -ine "none") { + $xcopyMSBuildToolsFolder = InitializeXCopyMSBuild $GlobalJson.tools."xcopy-msbuild" -install $true + } + if ($xcopyMSBuildToolsFolder -eq $null) { + throw 'Unable to get xcopy downloadable version of msbuild' + } + + $global:_MSBuildExe = "$($xcopyMSBuildToolsFolder)\MSBuild\Current\Bin\MSBuild.exe" + } + + $taskProject = GetSdkTaskProject $task + if (!(Test-Path $taskProject)) { + Write-PipelineTelemetryError -Category 'Build' -Message "Unknown task: $task" + ExitWithExitCode 1 + } + + if ($restore) { + Build 'Restore' + } + + Build 'Execute' +} +catch { + Write-Host $_.ScriptStackTrace + Write-PipelineTelemetryError -Category 'Build' -Message $_ + ExitWithExitCode 1 +} + +ExitWithExitCode 0 diff --git a/eng/common/sdl/NuGet.config b/eng/common/sdl/NuGet.config new file mode 100644 index 0000000000000..3849bdb3cf51e --- /dev/null +++ b/eng/common/sdl/NuGet.config @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/eng/common/sdl/configure-sdl-tool.ps1 b/eng/common/sdl/configure-sdl-tool.ps1 new file mode 100644 index 0000000000000..bdbf49e6c71de --- /dev/null +++ b/eng/common/sdl/configure-sdl-tool.ps1 @@ -0,0 +1,116 @@ +Param( + [string] $GuardianCliLocation, + [string] $WorkingDirectory, + [string] $TargetDirectory, + [string] $GdnFolder, + # The list of Guardian tools to configure. For each object in the array: + # - If the item is a [hashtable], it must contain these entries: + # - Name = The tool name as Guardian knows it. + # - Scenario = (Optional) Scenario-specific name for this configuration entry. It must be unique + # among all tool entries with the same Name. + # - Args = (Optional) Array of Guardian tool configuration args, like '@("Target > C:\temp")' + # - If the item is a [string] $v, it is treated as '@{ Name="$v" }' + [object[]] $ToolsList, + [string] $GuardianLoggerLevel='Standard', + # Optional: Additional params to add to any tool using CredScan. + [string[]] $CrScanAdditionalRunConfigParams, + # Optional: Additional params to add to any tool using PoliCheck. + [string[]] $PoliCheckAdditionalRunConfigParams, + # Optional: Additional params to add to any tool using CodeQL/Semmle. + [string[]] $CodeQLAdditionalRunConfigParams +) + +$ErrorActionPreference = 'Stop' +Set-StrictMode -Version 2.0 +$disableConfigureToolsetImport = $true +$global:LASTEXITCODE = 0 + +try { + # `tools.ps1` checks $ci to perform some actions. Since the SDL + # scripts don't necessarily execute in the same agent that run the + # build.ps1/sh script this variable isn't automatically set. + $ci = $true + . $PSScriptRoot\..\tools.ps1 + + # Normalize tools list: all in [hashtable] form with defined values for each key. + $ToolsList = $ToolsList | + ForEach-Object { + if ($_ -is [string]) { + $_ = @{ Name = $_ } + } + + if (-not ($_['Scenario'])) { $_.Scenario = "" } + if (-not ($_['Args'])) { $_.Args = @() } + $_ + } + + Write-Host "List of tools to configure:" + $ToolsList | ForEach-Object { $_ | Out-String | Write-Host } + + # We store config files in the r directory of .gdn + $gdnConfigPath = Join-Path $GdnFolder 'r' + $ValidPath = Test-Path $GuardianCliLocation + + if ($ValidPath -eq $False) + { + Write-PipelineTelemetryError -Force -Category 'Sdl' -Message "Invalid Guardian CLI Location." + ExitWithExitCode 1 + } + + foreach ($tool in $ToolsList) { + # Put together the name and scenario to make a unique key. + $toolConfigName = $tool.Name + if ($tool.Scenario) { + $toolConfigName += "_" + $tool.Scenario + } + + Write-Host "=== Configuring $toolConfigName..." + + $gdnConfigFile = Join-Path $gdnConfigPath "$toolConfigName-configure.gdnconfig" + + # For some tools, add default and automatic args. + if ($tool.Name -eq 'credscan') { + if ($targetDirectory) { + $tool.Args += "`"TargetDirectory < $TargetDirectory`"" + } + $tool.Args += "`"OutputType < pre`"" + $tool.Args += $CrScanAdditionalRunConfigParams + } elseif ($tool.Name -eq 'policheck') { + if ($targetDirectory) { + $tool.Args += "`"Target < $TargetDirectory`"" + } + $tool.Args += $PoliCheckAdditionalRunConfigParams + } elseif ($tool.Name -eq 'semmle' -or $tool.Name -eq 'codeql') { + if ($targetDirectory) { + $tool.Args += "`"SourceCodeDirectory < $TargetDirectory`"" + } + $tool.Args += $CodeQLAdditionalRunConfigParams + } + + # Create variable pointing to the args array directly so we can use splat syntax later. + $toolArgs = $tool.Args + + # Configure the tool. If args array is provided or the current tool has some default arguments + # defined, add "--args" and splat each element on the end. Arg format is "{Arg id} < {Value}", + # one per parameter. Doc page for "guardian configure": + # https://dev.azure.com/securitytools/SecurityIntegration/_wiki/wikis/Guardian/1395/configure + Exec-BlockVerbosely { + & $GuardianCliLocation configure ` + --working-directory $WorkingDirectory ` + --tool $tool.Name ` + --output-path $gdnConfigFile ` + --logger-level $GuardianLoggerLevel ` + --noninteractive ` + --force ` + $(if ($toolArgs) { "--args" }) @toolArgs + Exit-IfNZEC "Sdl" + } + + Write-Host "Created '$toolConfigName' configuration file: $gdnConfigFile" + } +} +catch { + Write-Host $_.ScriptStackTrace + Write-PipelineTelemetryError -Force -Category 'Sdl' -Message $_ + ExitWithExitCode 1 +} diff --git a/eng/common/sdl/execute-all-sdl-tools.ps1 b/eng/common/sdl/execute-all-sdl-tools.ps1 new file mode 100644 index 0000000000000..4797e012c7d2f --- /dev/null +++ b/eng/common/sdl/execute-all-sdl-tools.ps1 @@ -0,0 +1,165 @@ +Param( + [string] $GuardianPackageName, # Required: the name of guardian CLI package (not needed if GuardianCliLocation is specified) + [string] $NugetPackageDirectory, # Required: directory where NuGet packages are installed (not needed if GuardianCliLocation is specified) + [string] $GuardianCliLocation, # Optional: Direct location of Guardian CLI executable if GuardianPackageName & NugetPackageDirectory are not specified + [string] $Repository=$env:BUILD_REPOSITORY_NAME, # Required: the name of the repository (e.g. dotnet/arcade) + [string] $BranchName=$env:BUILD_SOURCEBRANCH, # Optional: name of branch or version of gdn settings; defaults to master + [string] $SourceDirectory=$env:BUILD_SOURCESDIRECTORY, # Required: the directory where source files are located + [string] $ArtifactsDirectory = (Join-Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY ('artifacts')), # Required: the directory where build artifacts are located + [string] $AzureDevOpsAccessToken, # Required: access token for dnceng; should be provided via KeyVault + + # Optional: list of SDL tools to run on source code. See 'configure-sdl-tool.ps1' for tools list + # format. + [object[]] $SourceToolsList, + # Optional: list of SDL tools to run on built artifacts. See 'configure-sdl-tool.ps1' for tools + # list format. + [object[]] $ArtifactToolsList, + # Optional: list of SDL tools to run without automatically specifying a target directory. See + # 'configure-sdl-tool.ps1' for tools list format. + [object[]] $CustomToolsList, + + [bool] $TsaPublish=$False, # Optional: true will publish results to TSA; only set to true after onboarding to TSA; TSA is the automated framework used to upload test results as bugs. + [string] $TsaBranchName=$env:BUILD_SOURCEBRANCH, # Optional: required for TSA publish; defaults to $(Build.SourceBranchName); TSA is the automated framework used to upload test results as bugs. + [string] $TsaRepositoryName=$env:BUILD_REPOSITORY_NAME, # Optional: TSA repository name; will be generated automatically if not submitted; TSA is the automated framework used to upload test results as bugs. + [string] $BuildNumber=$env:BUILD_BUILDNUMBER, # Optional: required for TSA publish; defaults to $(Build.BuildNumber) + [bool] $UpdateBaseline=$False, # Optional: if true, will update the baseline in the repository; should only be run after fixing any issues which need to be fixed + [bool] $TsaOnboard=$False, # Optional: if true, will onboard the repository to TSA; should only be run once; TSA is the automated framework used to upload test results as bugs. + [string] $TsaInstanceUrl, # Optional: only needed if TsaOnboard or TsaPublish is true; the instance-url registered with TSA; TSA is the automated framework used to upload test results as bugs. + [string] $TsaCodebaseName, # Optional: only needed if TsaOnboard or TsaPublish is true; the name of the codebase registered with TSA; TSA is the automated framework used to upload test results as bugs. + [string] $TsaProjectName, # Optional: only needed if TsaOnboard or TsaPublish is true; the name of the project registered with TSA; TSA is the automated framework used to upload test results as bugs. + [string] $TsaNotificationEmail, # Optional: only needed if TsaOnboard is true; the email(s) which will receive notifications of TSA bug filings (e.g. alias@microsoft.com); TSA is the automated framework used to upload test results as bugs. + [string] $TsaCodebaseAdmin, # Optional: only needed if TsaOnboard is true; the aliases which are admins of the TSA codebase (e.g. DOMAIN\alias); TSA is the automated framework used to upload test results as bugs. + [string] $TsaBugAreaPath, # Optional: only needed if TsaOnboard is true; the area path where TSA will file bugs in AzDO; TSA is the automated framework used to upload test results as bugs. + [string] $TsaIterationPath, # Optional: only needed if TsaOnboard is true; the iteration path where TSA will file bugs in AzDO; TSA is the automated framework used to upload test results as bugs. + [string] $GuardianLoggerLevel='Standard', # Optional: the logger level for the Guardian CLI; options are Trace, Verbose, Standard, Warning, and Error + [string[]] $CrScanAdditionalRunConfigParams, # Optional: Additional Params to custom build a CredScan run config in the format @("xyz:abc","sdf:1") + [string[]] $PoliCheckAdditionalRunConfigParams, # Optional: Additional Params to custom build a Policheck run config in the format @("xyz:abc","sdf:1") + [string[]] $CodeQLAdditionalRunConfigParams, # Optional: Additional Params to custom build a Semmle/CodeQL run config in the format @("xyz < abc","sdf < 1") + [bool] $BreakOnFailure=$False # Optional: Fail the build if there were errors during the run +) + +try { + $ErrorActionPreference = 'Stop' + Set-StrictMode -Version 2.0 + $disableConfigureToolsetImport = $true + $global:LASTEXITCODE = 0 + + # `tools.ps1` checks $ci to perform some actions. Since the SDL + # scripts don't necessarily execute in the same agent that run the + # build.ps1/sh script this variable isn't automatically set. + $ci = $true + . $PSScriptRoot\..\tools.ps1 + + #Replace repo names to the format of org/repo + if (!($Repository.contains('/'))) { + $RepoName = $Repository -replace '(.*?)-(.*)', '$1/$2'; + } + else{ + $RepoName = $Repository; + } + + if ($GuardianPackageName) { + $guardianCliLocation = Join-Path $NugetPackageDirectory (Join-Path $GuardianPackageName (Join-Path 'tools' 'guardian.cmd')) + } else { + $guardianCliLocation = $GuardianCliLocation + } + + $workingDirectory = (Split-Path $SourceDirectory -Parent) + $ValidPath = Test-Path $guardianCliLocation + + if ($ValidPath -eq $False) + { + Write-PipelineTelemetryError -Force -Category 'Sdl' -Message 'Invalid Guardian CLI Location.' + ExitWithExitCode 1 + } + + Exec-BlockVerbosely { + & $(Join-Path $PSScriptRoot 'init-sdl.ps1') -GuardianCliLocation $guardianCliLocation -Repository $RepoName -BranchName $BranchName -WorkingDirectory $workingDirectory -AzureDevOpsAccessToken $AzureDevOpsAccessToken -GuardianLoggerLevel $GuardianLoggerLevel + } + $gdnFolder = Join-Path $workingDirectory '.gdn' + + if ($TsaOnboard) { + if ($TsaCodebaseName -and $TsaNotificationEmail -and $TsaCodebaseAdmin -and $TsaBugAreaPath) { + Exec-BlockVerbosely { + & $guardianCliLocation tsa-onboard --codebase-name "$TsaCodebaseName" --notification-alias "$TsaNotificationEmail" --codebase-admin "$TsaCodebaseAdmin" --instance-url "$TsaInstanceUrl" --project-name "$TsaProjectName" --area-path "$TsaBugAreaPath" --iteration-path "$TsaIterationPath" --working-directory $workingDirectory --logger-level $GuardianLoggerLevel + } + if ($LASTEXITCODE -ne 0) { + Write-PipelineTelemetryError -Force -Category 'Sdl' -Message "Guardian tsa-onboard failed with exit code $LASTEXITCODE." + ExitWithExitCode $LASTEXITCODE + } + } else { + Write-PipelineTelemetryError -Force -Category 'Sdl' -Message 'Could not onboard to TSA -- not all required values ($TsaCodebaseName, $TsaNotificationEmail, $TsaCodebaseAdmin, $TsaBugAreaPath) were specified.' + ExitWithExitCode 1 + } + } + + # Configure a list of tools with a default target directory. Populates the ".gdn/r" directory. + function Configure-ToolsList([object[]] $tools, [string] $targetDirectory) { + if ($tools -and $tools.Count -gt 0) { + Exec-BlockVerbosely { + & $(Join-Path $PSScriptRoot 'configure-sdl-tool.ps1') ` + -GuardianCliLocation $guardianCliLocation ` + -WorkingDirectory $workingDirectory ` + -TargetDirectory $targetDirectory ` + -GdnFolder $gdnFolder ` + -ToolsList $tools ` + -AzureDevOpsAccessToken $AzureDevOpsAccessToken ` + -GuardianLoggerLevel $GuardianLoggerLevel ` + -CrScanAdditionalRunConfigParams $CrScanAdditionalRunConfigParams ` + -PoliCheckAdditionalRunConfigParams $PoliCheckAdditionalRunConfigParams ` + -CodeQLAdditionalRunConfigParams $CodeQLAdditionalRunConfigParams + if ($BreakOnFailure) { + Exit-IfNZEC "Sdl" + } + } + } + } + + # Configure Artifact and Source tools with default Target directories. + Configure-ToolsList $ArtifactToolsList $ArtifactsDirectory + Configure-ToolsList $SourceToolsList $SourceDirectory + # Configure custom tools with no default Target directory. + Configure-ToolsList $CustomToolsList $null + + # At this point, all tools are configured in the ".gdn" directory. Run them all in a single call. + # (If we used "run" multiple times, each run would overwrite data from earlier runs.) + Exec-BlockVerbosely { + & $(Join-Path $PSScriptRoot 'run-sdl.ps1') ` + -GuardianCliLocation $guardianCliLocation ` + -WorkingDirectory $SourceDirectory ` + -UpdateBaseline $UpdateBaseline ` + -GdnFolder $gdnFolder + } + + if ($TsaPublish) { + if ($TsaBranchName -and $BuildNumber) { + if (-not $TsaRepositoryName) { + $TsaRepositoryName = "$($Repository)-$($BranchName)" + } + Exec-BlockVerbosely { + & $guardianCliLocation tsa-publish --all-tools --repository-name "$TsaRepositoryName" --branch-name "$TsaBranchName" --build-number "$BuildNumber" --onboard $True --codebase-name "$TsaCodebaseName" --notification-alias "$TsaNotificationEmail" --codebase-admin "$TsaCodebaseAdmin" --instance-url "$TsaInstanceUrl" --project-name "$TsaProjectName" --area-path "$TsaBugAreaPath" --iteration-path "$TsaIterationPath" --working-directory $workingDirectory --logger-level $GuardianLoggerLevel + } + if ($LASTEXITCODE -ne 0) { + Write-PipelineTelemetryError -Force -Category 'Sdl' -Message "Guardian tsa-publish failed with exit code $LASTEXITCODE." + ExitWithExitCode $LASTEXITCODE + } + } else { + Write-PipelineTelemetryError -Force -Category 'Sdl' -Message 'Could not publish to TSA -- not all required values ($TsaBranchName, $BuildNumber) were specified.' + ExitWithExitCode 1 + } + } + + if ($BreakOnFailure) { + Write-Host "Failing the build in case of breaking results..." + Exec-BlockVerbosely { + & $guardianCliLocation break --working-directory $workingDirectory --logger-level $GuardianLoggerLevel + } + } else { + Write-Host "Letting the build pass even if there were breaking results..." + } +} +catch { + Write-Host $_.ScriptStackTrace + Write-PipelineTelemetryError -Force -Category 'Sdl' -Message $_ + exit 1 +} diff --git a/eng/common/sdl/extract-artifact-archives.ps1 b/eng/common/sdl/extract-artifact-archives.ps1 new file mode 100644 index 0000000000000..68da4fbf25717 --- /dev/null +++ b/eng/common/sdl/extract-artifact-archives.ps1 @@ -0,0 +1,63 @@ +# This script looks for each archive file in a directory and extracts it into the target directory. +# For example, the file "$InputPath/bin.tar.gz" extracts to "$ExtractPath/bin.tar.gz.extracted/**". +# Uses the "tar" utility added to Windows 10 / Windows 2019 that supports tar.gz and zip. +param( + # Full path to directory where archives are stored. + [Parameter(Mandatory=$true)][string] $InputPath, + # Full path to directory to extract archives into. May be the same as $InputPath. + [Parameter(Mandatory=$true)][string] $ExtractPath +) + +$ErrorActionPreference = 'Stop' +Set-StrictMode -Version 2.0 + +$disableConfigureToolsetImport = $true + +try { + # `tools.ps1` checks $ci to perform some actions. Since the SDL + # scripts don't necessarily execute in the same agent that run the + # build.ps1/sh script this variable isn't automatically set. + $ci = $true + . $PSScriptRoot\..\tools.ps1 + + Measure-Command { + $jobs = @() + + # Find archive files for non-Windows and Windows builds. + $archiveFiles = @( + Get-ChildItem (Join-Path $InputPath "*.tar.gz") + Get-ChildItem (Join-Path $InputPath "*.zip") + ) + + foreach ($targzFile in $archiveFiles) { + $jobs += Start-Job -ScriptBlock { + $file = $using:targzFile + $fileName = [System.IO.Path]::GetFileName($file) + $extractDir = Join-Path $using:ExtractPath "$fileName.extracted" + + New-Item $extractDir -ItemType Directory -Force | Out-Null + + Write-Host "Extracting '$file' to '$extractDir'..." + + # Pipe errors to stdout to prevent PowerShell detecting them and quitting the job early. + # This type of quit skips the catch, so we wouldn't be able to tell which file triggered the + # error. Save output so it can be stored in the exception string along with context. + $output = tar -xf $file -C $extractDir 2>&1 + # Handle NZEC manually rather than using Exit-IfNZEC: we are in a background job, so we + # don't have access to the outer scope. + if ($LASTEXITCODE -ne 0) { + throw "Error extracting '$file': non-zero exit code ($LASTEXITCODE). Output: '$output'" + } + + Write-Host "Extracted to $extractDir" + } + } + + Receive-Job $jobs -Wait + } +} +catch { + Write-Host $_ + Write-PipelineTelemetryError -Force -Category 'Sdl' -Message $_ + ExitWithExitCode 1 +} diff --git a/eng/common/sdl/extract-artifact-packages.ps1 b/eng/common/sdl/extract-artifact-packages.ps1 new file mode 100644 index 0000000000000..7f28d9c59ec69 --- /dev/null +++ b/eng/common/sdl/extract-artifact-packages.ps1 @@ -0,0 +1,80 @@ +param( + [Parameter(Mandatory=$true)][string] $InputPath, # Full path to directory where artifact packages are stored + [Parameter(Mandatory=$true)][string] $ExtractPath # Full path to directory where the packages will be extracted +) + +$ErrorActionPreference = 'Stop' +Set-StrictMode -Version 2.0 + +$disableConfigureToolsetImport = $true + +function ExtractArtifacts { + if (!(Test-Path $InputPath)) { + Write-Host "Input Path does not exist: $InputPath" + ExitWithExitCode 0 + } + $Jobs = @() + Get-ChildItem "$InputPath\*.nupkg" | + ForEach-Object { + $Jobs += Start-Job -ScriptBlock $ExtractPackage -ArgumentList $_.FullName + } + + foreach ($Job in $Jobs) { + Wait-Job -Id $Job.Id | Receive-Job + } +} + +try { + # `tools.ps1` checks $ci to perform some actions. Since the SDL + # scripts don't necessarily execute in the same agent that run the + # build.ps1/sh script this variable isn't automatically set. + $ci = $true + . $PSScriptRoot\..\tools.ps1 + + $ExtractPackage = { + param( + [string] $PackagePath # Full path to a NuGet package + ) + + if (!(Test-Path $PackagePath)) { + Write-PipelineTelemetryError -Category 'Build' -Message "Input file does not exist: $PackagePath" + ExitWithExitCode 1 + } + + $RelevantExtensions = @('.dll', '.exe', '.pdb') + Write-Host -NoNewLine 'Extracting ' ([System.IO.Path]::GetFileName($PackagePath)) '...' + + $PackageId = [System.IO.Path]::GetFileNameWithoutExtension($PackagePath) + $ExtractPath = Join-Path -Path $using:ExtractPath -ChildPath $PackageId + + Add-Type -AssemblyName System.IO.Compression.FileSystem + + [System.IO.Directory]::CreateDirectory($ExtractPath); + + try { + $zip = [System.IO.Compression.ZipFile]::OpenRead($PackagePath) + + $zip.Entries | + Where-Object {$RelevantExtensions -contains [System.IO.Path]::GetExtension($_.Name)} | + ForEach-Object { + $TargetFile = Join-Path -Path $ExtractPath -ChildPath $_.Name + + [System.IO.Compression.ZipFileExtensions]::ExtractToFile($_, $TargetFile, $true) + } + } + catch { + Write-Host $_ + Write-PipelineTelemetryError -Force -Category 'Sdl' -Message $_ + ExitWithExitCode 1 + } + finally { + $zip.Dispose() + } + } + Measure-Command { ExtractArtifacts } +} +catch { + Write-Host $_ + Write-PipelineTelemetryError -Force -Category 'Sdl' -Message $_ + ExitWithExitCode 1 +} diff --git a/eng/common/sdl/init-sdl.ps1 b/eng/common/sdl/init-sdl.ps1 new file mode 100644 index 0000000000000..3ac1d92b37006 --- /dev/null +++ b/eng/common/sdl/init-sdl.ps1 @@ -0,0 +1,55 @@ +Param( + [string] $GuardianCliLocation, + [string] $Repository, + [string] $BranchName='master', + [string] $WorkingDirectory, + [string] $AzureDevOpsAccessToken, + [string] $GuardianLoggerLevel='Standard' +) + +$ErrorActionPreference = 'Stop' +Set-StrictMode -Version 2.0 +$disableConfigureToolsetImport = $true +$global:LASTEXITCODE = 0 + +# `tools.ps1` checks $ci to perform some actions. Since the SDL +# scripts don't necessarily execute in the same agent that run the +# build.ps1/sh script this variable isn't automatically set. +$ci = $true +. $PSScriptRoot\..\tools.ps1 + +# Don't display the console progress UI - it's a huge perf hit +$ProgressPreference = 'SilentlyContinue' + +# Construct basic auth from AzDO access token; construct URI to the repository's gdn folder stored in that repository; construct location of zip file +$encodedPat = [Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$AzureDevOpsAccessToken")) +$escapedRepository = [Uri]::EscapeDataString("/$Repository/$BranchName/.gdn") +$uri = "https://dev.azure.com/dnceng/internal/_apis/git/repositories/sdl-tool-cfg/Items?path=$escapedRepository&versionDescriptor[versionOptions]=0&`$format=zip&api-version=5.0" +$zipFile = "$WorkingDirectory/gdn.zip" + +Add-Type -AssemblyName System.IO.Compression.FileSystem +$gdnFolder = (Join-Path $WorkingDirectory '.gdn') + +try { + # if the folder does not exist, we'll do a guardian init and push it to the remote repository + Write-Host 'Initializing Guardian...' + Write-Host "$GuardianCliLocation init --working-directory $WorkingDirectory --logger-level $GuardianLoggerLevel" + & $GuardianCliLocation init --working-directory $WorkingDirectory --logger-level $GuardianLoggerLevel + if ($LASTEXITCODE -ne 0) { + Write-PipelineTelemetryError -Force -Category 'Build' -Message "Guardian init failed with exit code $LASTEXITCODE." + ExitWithExitCode $LASTEXITCODE + } + # We create the mainbaseline so it can be edited later + Write-Host "$GuardianCliLocation baseline --working-directory $WorkingDirectory --name mainbaseline" + & $GuardianCliLocation baseline --working-directory $WorkingDirectory --name mainbaseline + if ($LASTEXITCODE -ne 0) { + Write-PipelineTelemetryError -Force -Category 'Build' -Message "Guardian baseline failed with exit code $LASTEXITCODE." + ExitWithExitCode $LASTEXITCODE + } + ExitWithExitCode 0 +} +catch { + Write-Host $_.ScriptStackTrace + Write-PipelineTelemetryError -Force -Category 'Sdl' -Message $_ + ExitWithExitCode 1 +} diff --git a/eng/common/sdl/packages.config b/eng/common/sdl/packages.config new file mode 100644 index 0000000000000..4585cfd6bba1e --- /dev/null +++ b/eng/common/sdl/packages.config @@ -0,0 +1,4 @@ + + + + diff --git a/eng/common/sdl/run-sdl.ps1 b/eng/common/sdl/run-sdl.ps1 new file mode 100644 index 0000000000000..2eac8c78f103d --- /dev/null +++ b/eng/common/sdl/run-sdl.ps1 @@ -0,0 +1,49 @@ +Param( + [string] $GuardianCliLocation, + [string] $WorkingDirectory, + [string] $GdnFolder, + [string] $UpdateBaseline, + [string] $GuardianLoggerLevel='Standard' +) + +$ErrorActionPreference = 'Stop' +Set-StrictMode -Version 2.0 +$disableConfigureToolsetImport = $true +$global:LASTEXITCODE = 0 + +try { + # `tools.ps1` checks $ci to perform some actions. Since the SDL + # scripts don't necessarily execute in the same agent that run the + # build.ps1/sh script this variable isn't automatically set. + $ci = $true + . $PSScriptRoot\..\tools.ps1 + + # We store config files in the r directory of .gdn + $gdnConfigPath = Join-Path $GdnFolder 'r' + $ValidPath = Test-Path $GuardianCliLocation + + if ($ValidPath -eq $False) + { + Write-PipelineTelemetryError -Force -Category 'Sdl' -Message "Invalid Guardian CLI Location." + ExitWithExitCode 1 + } + + $gdnConfigFiles = Get-ChildItem $gdnConfigPath -Recurse -Include '*.gdnconfig' + Write-Host "Discovered Guardian config files:" + $gdnConfigFiles | Out-String | Write-Host + + Exec-BlockVerbosely { + & $GuardianCliLocation run ` + --working-directory $WorkingDirectory ` + --baseline mainbaseline ` + --update-baseline $UpdateBaseline ` + --logger-level $GuardianLoggerLevel ` + --config @gdnConfigFiles + Exit-IfNZEC "Sdl" + } +} +catch { + Write-Host $_.ScriptStackTrace + Write-PipelineTelemetryError -Force -Category 'Sdl' -Message $_ + ExitWithExitCode 1 +} diff --git a/eng/common/sdl/sdl.ps1 b/eng/common/sdl/sdl.ps1 new file mode 100644 index 0000000000000..648c5068d7d60 --- /dev/null +++ b/eng/common/sdl/sdl.ps1 @@ -0,0 +1,38 @@ + +function Install-Gdn { + param( + [Parameter(Mandatory=$true)] + [string]$Path, + + # If omitted, install the latest version of Guardian, otherwise install that specific version. + [string]$Version + ) + + $ErrorActionPreference = 'Stop' + Set-StrictMode -Version 2.0 + $disableConfigureToolsetImport = $true + $global:LASTEXITCODE = 0 + + # `tools.ps1` checks $ci to perform some actions. Since the SDL + # scripts don't necessarily execute in the same agent that run the + # build.ps1/sh script this variable isn't automatically set. + $ci = $true + . $PSScriptRoot\..\tools.ps1 + + $argumentList = @("install", "Microsoft.Guardian.Cli", "-Source https://securitytools.pkgs.visualstudio.com/_packaging/Guardian/nuget/v3/index.json", "-OutputDirectory $Path", "-NonInteractive", "-NoCache") + + if ($Version) { + $argumentList += "-Version $Version" + } + + Start-Process nuget -Verbose -ArgumentList $argumentList -NoNewWindow -Wait + + $gdnCliPath = Get-ChildItem -Filter guardian.cmd -Recurse -Path $Path + + if (!$gdnCliPath) + { + Write-PipelineTelemetryError -Category 'Sdl' -Message 'Failure installing Guardian' + } + + return $gdnCliPath.FullName +} \ No newline at end of file diff --git a/eng/common/templates/job/execute-sdl.yml b/eng/common/templates/job/execute-sdl.yml new file mode 100644 index 0000000000000..7aabaa18017bf --- /dev/null +++ b/eng/common/templates/job/execute-sdl.yml @@ -0,0 +1,134 @@ +parameters: + enable: 'false' # Whether the SDL validation job should execute or not + overrideParameters: '' # Optional: to override values for parameters. + additionalParameters: '' # Optional: parameters that need user specific values eg: '-SourceToolsList @("abc","def") -ArtifactToolsList @("ghi","jkl")' + # Optional: if specified, restore and use this version of Guardian instead of the default. + overrideGuardianVersion: '' + # Optional: if true, publish the '.gdn' folder as a pipeline artifact. This can help with in-depth + # diagnosis of problems with specific tool configurations. + publishGuardianDirectoryToPipeline: false + # The script to run to execute all SDL tools. Use this if you want to use a script to define SDL + # parameters rather than relying on YAML. It may be better to use a local script, because you can + # reproduce results locally without piecing together a command based on the YAML. + executeAllSdlToolsScript: 'eng/common/sdl/execute-all-sdl-tools.ps1' + # There is some sort of bug (has been reported) in Azure DevOps where if this parameter is named + # 'continueOnError', the parameter value is not correctly picked up. + # This can also be remedied by the caller (post-build.yml) if it does not use a nested parameter + sdlContinueOnError: false # optional: determines whether to continue the build if the step errors; + # optional: determines if build artifacts should be downloaded. + downloadArtifacts: true + # optional: determines if this job should search the directory of downloaded artifacts for + # 'tar.gz' and 'zip' archive files and extract them before running SDL validation tasks. + extractArchiveArtifacts: false + dependsOn: '' # Optional: dependencies of the job + artifactNames: '' # Optional: patterns supplied to DownloadBuildArtifacts + # Usage: + # artifactNames: + # - 'BlobArtifacts' + # - 'Artifacts_Windows_NT_Release' + # Optional: download a list of pipeline artifacts. 'downloadArtifacts' controls build artifacts, + # not pipeline artifacts, so doesn't affect the use of this parameter. + pipelineArtifactNames: [] + +jobs: +- job: Run_SDL + dependsOn: ${{ parameters.dependsOn }} + displayName: Run SDL tool + condition: and(succeededOrFailed(), eq( ${{ parameters.enable }}, 'true')) + variables: + - group: DotNet-VSTS-Bot + - name: AzDOProjectName + value: ${{ parameters.AzDOProjectName }} + - name: AzDOPipelineId + value: ${{ parameters.AzDOPipelineId }} + - name: AzDOBuildId + value: ${{ parameters.AzDOBuildId }} + - template: /eng/common/templates/variables/sdl-variables.yml + - name: GuardianVersion + value: ${{ coalesce(parameters.overrideGuardianVersion, '$(DefaultGuardianVersion)') }} + - template: /eng/common/templates/variables/pool-providers.yml + pool: + # We don't use the collection uri here because it might vary (.visualstudio.com vs. dev.azure.com) + ${{ if eq(variables['System.TeamProject'], 'DevDiv') }}: + name: VSEngSS-MicroBuild2022-1ES + demands: Cmd + # If it's not devdiv, it's dnceng + ${{ if ne(variables['System.TeamProject'], 'DevDiv') }}: + name: $(DncEngInternalBuildPool) + demands: ImageOverride -equals windows.vs2019.amd64 + steps: + - checkout: self + clean: true + + # If the template caller didn't provide an AzDO parameter, set them all up as Maestro vars. + - ${{ if not(and(parameters.AzDOProjectName, parameters.AzDOPipelineId, parameters.AzDOBuildId)) }}: + - template: /eng/common/templates/post-build/setup-maestro-vars.yml + + - ${{ if ne(parameters.downloadArtifacts, 'false')}}: + - ${{ if ne(parameters.artifactNames, '') }}: + - ${{ each artifactName in parameters.artifactNames }}: + - task: DownloadBuildArtifacts@0 + displayName: Download Build Artifacts + inputs: + buildType: specific + buildVersionToDownload: specific + project: $(AzDOProjectName) + pipeline: $(AzDOPipelineId) + buildId: $(AzDOBuildId) + artifactName: ${{ artifactName }} + downloadPath: $(Build.ArtifactStagingDirectory)\artifacts + checkDownloadedFiles: true + - ${{ if eq(parameters.artifactNames, '') }}: + - task: DownloadBuildArtifacts@0 + displayName: Download Build Artifacts + inputs: + buildType: specific + buildVersionToDownload: specific + project: $(AzDOProjectName) + pipeline: $(AzDOPipelineId) + buildId: $(AzDOBuildId) + downloadType: specific files + itemPattern: "**" + downloadPath: $(Build.ArtifactStagingDirectory)\artifacts + checkDownloadedFiles: true + + - ${{ each artifactName in parameters.pipelineArtifactNames }}: + - task: DownloadPipelineArtifact@2 + displayName: Download Pipeline Artifacts + inputs: + buildType: specific + buildVersionToDownload: specific + project: $(AzDOProjectName) + pipeline: $(AzDOPipelineId) + buildId: $(AzDOBuildId) + artifactName: ${{ artifactName }} + downloadPath: $(Build.ArtifactStagingDirectory)\artifacts + checkDownloadedFiles: true + + - powershell: eng/common/sdl/extract-artifact-packages.ps1 + -InputPath $(Build.ArtifactStagingDirectory)\artifacts\BlobArtifacts + -ExtractPath $(Build.ArtifactStagingDirectory)\artifacts\BlobArtifacts + displayName: Extract Blob Artifacts + continueOnError: ${{ parameters.sdlContinueOnError }} + + - powershell: eng/common/sdl/extract-artifact-packages.ps1 + -InputPath $(Build.ArtifactStagingDirectory)\artifacts\PackageArtifacts + -ExtractPath $(Build.ArtifactStagingDirectory)\artifacts\PackageArtifacts + displayName: Extract Package Artifacts + continueOnError: ${{ parameters.sdlContinueOnError }} + + - ${{ if ne(parameters.extractArchiveArtifacts, 'false') }}: + - powershell: eng/common/sdl/extract-artifact-archives.ps1 + -InputPath $(Build.ArtifactStagingDirectory)\artifacts + -ExtractPath $(Build.ArtifactStagingDirectory)\artifacts + displayName: Extract Archive Artifacts + continueOnError: ${{ parameters.sdlContinueOnError }} + + - template: /eng/common/templates/steps/execute-sdl.yml + parameters: + overrideGuardianVersion: ${{ parameters.overrideGuardianVersion }} + executeAllSdlToolsScript: ${{ parameters.executeAllSdlToolsScript }} + overrideParameters: ${{ parameters.overrideParameters }} + additionalParameters: ${{ parameters.additionalParameters }} + publishGuardianDirectoryToPipeline: ${{ parameters.publishGuardianDirectoryToPipeline }} + sdlContinueOnError: ${{ parameters.sdlContinueOnError }} diff --git a/eng/common/templates/job/job.yml b/eng/common/templates/job/job.yml new file mode 100644 index 0000000000000..61914a1fbcd3f --- /dev/null +++ b/eng/common/templates/job/job.yml @@ -0,0 +1,246 @@ +# Internal resources (telemetry, microbuild) can only be accessed from non-public projects, +# and some (Microbuild) should only be applied to non-PR cases for internal builds. + +parameters: +# Job schema parameters - https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=vsts&tabs=schema#job + cancelTimeoutInMinutes: '' + condition: '' + container: '' + continueOnError: false + dependsOn: '' + displayName: '' + pool: '' + steps: [] + strategy: '' + timeoutInMinutes: '' + variables: [] + workspace: '' + +# Job base template specific parameters + # See schema documentation - https://github.com/dotnet/arcade/blob/master/Documentation/AzureDevOps/TemplateSchema.md + artifacts: '' + enableMicrobuild: false + enablePublishBuildArtifacts: false + enablePublishBuildAssets: false + enablePublishTestResults: false + enablePublishUsingPipelines: false + enableBuildRetry: false + disableComponentGovernance: false + componentGovernanceIgnoreDirectories: '' + mergeTestResults: false + testRunTitle: '' + testResultsFormat: '' + name: '' + preSteps: [] + runAsPublic: false +# Sbom related params + enableSbom: true + PackageVersion: 7.0.0 + BuildDropPath: '$(Build.SourcesDirectory)/artifacts' + +jobs: +- job: ${{ parameters.name }} + + ${{ if ne(parameters.cancelTimeoutInMinutes, '') }}: + cancelTimeoutInMinutes: ${{ parameters.cancelTimeoutInMinutes }} + + ${{ if ne(parameters.condition, '') }}: + condition: ${{ parameters.condition }} + + ${{ if ne(parameters.container, '') }}: + container: ${{ parameters.container }} + + ${{ if ne(parameters.continueOnError, '') }}: + continueOnError: ${{ parameters.continueOnError }} + + ${{ if ne(parameters.dependsOn, '') }}: + dependsOn: ${{ parameters.dependsOn }} + + ${{ if ne(parameters.displayName, '') }}: + displayName: ${{ parameters.displayName }} + + ${{ if ne(parameters.pool, '') }}: + pool: ${{ parameters.pool }} + + ${{ if ne(parameters.strategy, '') }}: + strategy: ${{ parameters.strategy }} + + ${{ if ne(parameters.timeoutInMinutes, '') }}: + timeoutInMinutes: ${{ parameters.timeoutInMinutes }} + + variables: + - ${{ if ne(parameters.enableTelemetry, 'false') }}: + - name: DOTNET_CLI_TELEMETRY_PROFILE + value: '$(Build.Repository.Uri)' + - ${{ if eq(parameters.enableRichCodeNavigation, 'true') }}: + - name: EnableRichCodeNavigation + value: 'true' + - ${{ each variable in parameters.variables }}: + # handle name-value variable syntax + # example: + # - name: [key] + # value: [value] + - ${{ if ne(variable.name, '') }}: + - name: ${{ variable.name }} + value: ${{ variable.value }} + + # handle variable groups + - ${{ if ne(variable.group, '') }}: + - group: ${{ variable.group }} + + # handle template variable syntax + # example: + # - template: path/to/template.yml + # parameters: + # [key]: [value] + - ${{ if ne(variable.template, '') }}: + - template: ${{ variable.template }} + ${{ if ne(variable.parameters, '') }}: + parameters: ${{ variable.parameters }} + + # handle key-value variable syntax. + # example: + # - [key]: [value] + - ${{ if and(eq(variable.name, ''), eq(variable.group, '')) }}: + - ${{ each pair in variable }}: + - name: ${{ pair.key }} + value: ${{ pair.value }} + + # DotNet-HelixApi-Access provides 'HelixApiAccessToken' for internal builds + - ${{ if and(eq(parameters.enableTelemetry, 'true'), eq(parameters.runAsPublic, 'false'), ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: + - group: DotNet-HelixApi-Access + + ${{ if ne(parameters.workspace, '') }}: + workspace: ${{ parameters.workspace }} + + steps: + - ${{ if ne(parameters.preSteps, '') }}: + - ${{ each preStep in parameters.preSteps }}: + - ${{ preStep }} + + - ${{ if and(eq(parameters.runAsPublic, 'false'), ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: + - ${{ if eq(parameters.enableMicrobuild, 'true') }}: + - task: MicroBuildSigningPlugin@3 + displayName: Install MicroBuild plugin + inputs: + signType: $(_SignType) + zipSources: false + feedSource: https://dnceng.pkgs.visualstudio.com/_packaging/MicroBuildToolset/nuget/v3/index.json + env: + TeamName: $(_TeamName) + continueOnError: ${{ parameters.continueOnError }} + condition: and(succeeded(), in(variables['_SignType'], 'real', 'test'), eq(variables['Agent.Os'], 'Windows_NT')) + + - ${{ if and(eq(parameters.runAsPublic, 'false'), eq(variables['System.TeamProject'], 'internal')) }}: + - task: NuGetAuthenticate@0 + + - ${{ if and(ne(parameters.artifacts.download, 'false'), ne(parameters.artifacts.download, '')) }}: + - task: DownloadPipelineArtifact@2 + inputs: + buildType: current + artifactName: ${{ coalesce(parameters.artifacts.download.name, 'Artifacts_$(Agent.OS)_$(_BuildConfig)') }} + targetPath: ${{ coalesce(parameters.artifacts.download.path, 'artifacts') }} + itemPattern: ${{ coalesce(parameters.artifacts.download.pattern, '**') }} + + - ${{ each step in parameters.steps }}: + - ${{ step }} + + - ${{ if eq(parameters.enableRichCodeNavigation, true) }}: + - task: RichCodeNavIndexer@0 + displayName: RichCodeNav Upload + inputs: + languages: ${{ coalesce(parameters.richCodeNavigationLanguage, 'csharp') }} + environment: ${{ coalesce(parameters.richCodeNavigationEnvironment, 'production') }} + richNavLogOutputDirectory: $(Build.SourcesDirectory)/artifacts/bin + uploadRichNavArtifacts: ${{ coalesce(parameters.richCodeNavigationUploadArtifacts, false) }} + continueOnError: true + + - ${{ if and(eq(parameters.runAsPublic, 'false'), ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest'), ne(parameters.disableComponentGovernance, 'true')) }}: + - task: ComponentGovernanceComponentDetection@0 + continueOnError: true + inputs: + ignoreDirectories: ${{ parameters.componentGovernanceIgnoreDirectories }} + + - ${{ if eq(parameters.enableMicrobuild, 'true') }}: + - ${{ if and(eq(parameters.runAsPublic, 'false'), ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: + - task: MicroBuildCleanup@1 + displayName: Execute Microbuild cleanup tasks + condition: and(always(), in(variables['_SignType'], 'real', 'test'), eq(variables['Agent.Os'], 'Windows_NT')) + continueOnError: ${{ parameters.continueOnError }} + env: + TeamName: $(_TeamName) + + - ${{ if ne(parameters.artifacts.publish, '') }}: + - ${{ if and(ne(parameters.artifacts.publish.artifacts, 'false'), ne(parameters.artifacts.publish.artifacts, '')) }}: + - task: CopyFiles@2 + displayName: Gather binaries for publish to artifacts + inputs: + SourceFolder: 'artifacts/bin' + Contents: '**' + TargetFolder: '$(Build.ArtifactStagingDirectory)/artifacts/bin' + - task: CopyFiles@2 + displayName: Gather packages for publish to artifacts + inputs: + SourceFolder: 'artifacts/packages' + Contents: '**' + TargetFolder: '$(Build.ArtifactStagingDirectory)/artifacts/packages' + - task: PublishBuildArtifacts@1 + displayName: Publish pipeline artifacts + inputs: + PathtoPublish: '$(Build.ArtifactStagingDirectory)/artifacts' + PublishLocation: Container + ArtifactName: ${{ coalesce(parameters.artifacts.publish.artifacts.name , 'Artifacts_$(Agent.Os)_$(_BuildConfig)') }} + continueOnError: true + condition: always() + - ${{ if and(ne(parameters.artifacts.publish.logs, 'false'), ne(parameters.artifacts.publish.logs, '')) }}: + - publish: artifacts/log + artifact: ${{ coalesce(parameters.artifacts.publish.logs.name, 'Logs_Build_$(Agent.Os)_$(_BuildConfig)') }} + displayName: Publish logs + continueOnError: true + condition: always() + + - ${{ if ne(parameters.enablePublishBuildArtifacts, 'false') }}: + - task: PublishBuildArtifacts@1 + displayName: Publish Logs + inputs: + PathtoPublish: '$(Build.SourcesDirectory)/artifacts/log/$(_BuildConfig)' + PublishLocation: Container + ArtifactName: ${{ coalesce(parameters.enablePublishBuildArtifacts.artifactName, '$(Agent.Os)_$(Agent.JobName)' ) }} + continueOnError: true + condition: always() + + - ${{ if or(and(eq(parameters.enablePublishTestResults, 'true'), eq(parameters.testResultsFormat, '')), eq(parameters.testResultsFormat, 'xunit')) }}: + - task: PublishTestResults@2 + displayName: Publish XUnit Test Results + inputs: + testResultsFormat: 'xUnit' + testResultsFiles: '*.xml' + searchFolder: '$(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig)' + testRunTitle: ${{ coalesce(parameters.testRunTitle, parameters.name, '$(System.JobName)') }}-xunit + mergeTestResults: ${{ parameters.mergeTestResults }} + continueOnError: true + condition: always() + - ${{ if or(and(eq(parameters.enablePublishTestResults, 'true'), eq(parameters.testResultsFormat, '')), eq(parameters.testResultsFormat, 'vstest')) }}: + - task: PublishTestResults@2 + displayName: Publish TRX Test Results + inputs: + testResultsFormat: 'VSTest' + testResultsFiles: '*.trx' + searchFolder: '$(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig)' + testRunTitle: ${{ coalesce(parameters.testRunTitle, parameters.name, '$(System.JobName)') }}-trx + mergeTestResults: ${{ parameters.mergeTestResults }} + continueOnError: true + condition: always() + + - ${{ if and(eq(parameters.runAsPublic, 'false'), ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest'), eq(parameters.enableSbom, 'true')) }}: + - template: /eng/common/templates/steps/generate-sbom.yml + parameters: + PackageVersion: ${{ parameters.packageVersion}} + BuildDropPath: ${{ parameters.buildDropPath }} + IgnoreDirectories: ${{ parameters.componentGovernanceIgnoreDirectories }} + + - ${{ if eq(parameters.enableBuildRetry, 'true') }}: + - publish: $(Build.SourcesDirectory)\eng\common\BuildConfiguration + artifact: BuildConfiguration + displayName: Publish build retry configuration + continueOnError: true diff --git a/eng/common/templates/job/onelocbuild.yml b/eng/common/templates/job/onelocbuild.yml new file mode 100644 index 0000000000000..60ab00c4de3ac --- /dev/null +++ b/eng/common/templates/job/onelocbuild.yml @@ -0,0 +1,109 @@ +parameters: + # Optional: dependencies of the job + dependsOn: '' + + # Optional: A defined YAML pool - https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=vsts&tabs=schema#pool + pool: '' + + CeapexPat: $(dn-bot-ceapex-package-r) # PAT for the loc AzDO instance https://dev.azure.com/ceapex + GithubPat: $(BotAccount-dotnet-bot-repo-PAT) + + SourcesDirectory: $(Build.SourcesDirectory) + CreatePr: true + AutoCompletePr: false + ReusePr: true + UseLfLineEndings: true + UseCheckedInLocProjectJson: false + SkipLocProjectJsonGeneration: false + LanguageSet: VS_Main_Languages + LclSource: lclFilesInRepo + LclPackageId: '' + RepoType: gitHub + GitHubOrg: dotnet + MirrorRepo: '' + MirrorBranch: main + condition: '' + JobNameSuffix: '' + +jobs: +- job: OneLocBuild${{ parameters.JobNameSuffix }} + + dependsOn: ${{ parameters.dependsOn }} + + displayName: OneLocBuild${{ parameters.JobNameSuffix }} + + variables: + - group: OneLocBuildVariables # Contains the CeapexPat and GithubPat + - name: _GenerateLocProjectArguments + value: -SourcesDirectory ${{ parameters.SourcesDirectory }} + -LanguageSet "${{ parameters.LanguageSet }}" + -CreateNeutralXlfs + - ${{ if eq(parameters.UseCheckedInLocProjectJson, 'true') }}: + - name: _GenerateLocProjectArguments + value: ${{ variables._GenerateLocProjectArguments }} -UseCheckedInLocProjectJson + - template: /eng/common/templates/variables/pool-providers.yml + + ${{ if ne(parameters.pool, '') }}: + pool: ${{ parameters.pool }} + ${{ if eq(parameters.pool, '') }}: + pool: + # We don't use the collection uri here because it might vary (.visualstudio.com vs. dev.azure.com) + ${{ if eq(variables['System.TeamProject'], 'DevDiv') }}: + name: VSEngSS-MicroBuild2022-1ES + demands: Cmd + # If it's not devdiv, it's dnceng + ${{ if ne(variables['System.TeamProject'], 'DevDiv') }}: + name: $(DncEngInternalBuildPool) + demands: ImageOverride -equals windows.vs2019.amd64 + + steps: + - ${{ if ne(parameters.SkipLocProjectJsonGeneration, 'true') }}: + - task: Powershell@2 + inputs: + filePath: $(Build.SourcesDirectory)/eng/common/generate-locproject.ps1 + arguments: $(_GenerateLocProjectArguments) + displayName: Generate LocProject.json + condition: ${{ parameters.condition }} + + - task: OneLocBuild@2 + displayName: OneLocBuild + env: + SYSTEM_ACCESSTOKEN: $(System.AccessToken) + inputs: + locProj: eng/Localize/LocProject.json + outDir: $(Build.ArtifactStagingDirectory) + lclSource: ${{ parameters.LclSource }} + lclPackageId: ${{ parameters.LclPackageId }} + isCreatePrSelected: ${{ parameters.CreatePr }} + isAutoCompletePrSelected: ${{ parameters.AutoCompletePr }} + ${{ if eq(parameters.CreatePr, true) }}: + isUseLfLineEndingsSelected: ${{ parameters.UseLfLineEndings }} + ${{ if eq(parameters.RepoType, 'gitHub') }}: + isShouldReusePrSelected: ${{ parameters.ReusePr }} + packageSourceAuth: patAuth + patVariable: ${{ parameters.CeapexPat }} + ${{ if eq(parameters.RepoType, 'gitHub') }}: + repoType: ${{ parameters.RepoType }} + gitHubPatVariable: "${{ parameters.GithubPat }}" + ${{ if ne(parameters.MirrorRepo, '') }}: + isMirrorRepoSelected: true + gitHubOrganization: ${{ parameters.GitHubOrg }} + mirrorRepo: ${{ parameters.MirrorRepo }} + mirrorBranch: ${{ parameters.MirrorBranch }} + condition: ${{ parameters.condition }} + + - task: PublishBuildArtifacts@1 + displayName: Publish Localization Files + inputs: + PathtoPublish: '$(Build.ArtifactStagingDirectory)/loc' + PublishLocation: Container + ArtifactName: Loc + condition: ${{ parameters.condition }} + + - task: PublishBuildArtifacts@1 + displayName: Publish LocProject.json + inputs: + PathtoPublish: '$(Build.SourcesDirectory)/eng/Localize/' + PublishLocation: Container + ArtifactName: Loc + condition: ${{ parameters.condition }} \ No newline at end of file diff --git a/eng/common/templates/job/publish-build-assets.yml b/eng/common/templates/job/publish-build-assets.yml new file mode 100644 index 0000000000000..42017109f374d --- /dev/null +++ b/eng/common/templates/job/publish-build-assets.yml @@ -0,0 +1,151 @@ +parameters: + configuration: 'Debug' + + # Optional: condition for the job to run + condition: '' + + # Optional: 'true' if future jobs should run even if this job fails + continueOnError: false + + # Optional: dependencies of the job + dependsOn: '' + + # Optional: Include PublishBuildArtifacts task + enablePublishBuildArtifacts: false + + # Optional: A defined YAML pool - https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=vsts&tabs=schema#pool + pool: {} + + # Optional: should run as a public build even in the internal project + # if 'true', the build won't run any of the internal only steps, even if it is running in non-public projects. + runAsPublic: false + + # Optional: whether the build's artifacts will be published using release pipelines or direct feed publishing + publishUsingPipelines: false + + # Optional: whether the build's artifacts will be published using release pipelines or direct feed publishing + publishAssetsImmediately: false + + artifactsPublishingAdditionalParameters: '' + + signingValidationAdditionalParameters: '' + +jobs: +- job: Asset_Registry_Publish + + dependsOn: ${{ parameters.dependsOn }} + timeoutInMinutes: 150 + + ${{ if eq(parameters.publishAssetsImmediately, 'true') }}: + displayName: Publish Assets + ${{ else }}: + displayName: Publish to Build Asset Registry + + variables: + - template: /eng/common/templates/variables/pool-providers.yml + - ${{ if and(eq(parameters.runAsPublic, 'false'), ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: + - group: Publish-Build-Assets + - group: AzureDevOps-Artifact-Feeds-Pats + - name: runCodesignValidationInjection + value: false + - ${{ if eq(parameters.publishAssetsImmediately, 'true') }}: + - template: /eng/common/templates/post-build/common-variables.yml + + pool: + # We don't use the collection uri here because it might vary (.visualstudio.com vs. dev.azure.com) + ${{ if eq(variables['System.TeamProject'], 'DevDiv') }}: + name: VSEngSS-MicroBuild2022-1ES + demands: Cmd + # If it's not devdiv, it's dnceng + ${{ if ne(variables['System.TeamProject'], 'DevDiv') }}: + name: $(DncEngInternalBuildPool) + demands: ImageOverride -equals windows.vs2019.amd64 + + steps: + - ${{ if and(eq(parameters.runAsPublic, 'false'), ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: + - task: DownloadBuildArtifacts@0 + displayName: Download artifact + inputs: + artifactName: AssetManifests + downloadPath: '$(Build.StagingDirectory)/Download' + checkDownloadedFiles: true + condition: ${{ parameters.condition }} + continueOnError: ${{ parameters.continueOnError }} + + - task: NuGetAuthenticate@0 + + - task: PowerShell@2 + displayName: Publish Build Assets + inputs: + filePath: eng\common\sdk-task.ps1 + arguments: -task PublishBuildAssets -restore -msbuildEngine dotnet + /p:ManifestsPath='$(Build.StagingDirectory)/Download/AssetManifests' + /p:BuildAssetRegistryToken=$(MaestroAccessToken) + /p:MaestroApiEndpoint=https://maestro-prod.westus2.cloudapp.azure.com + /p:PublishUsingPipelines=${{ parameters.publishUsingPipelines }} + /p:OfficialBuildId=$(Build.BuildNumber) + condition: ${{ parameters.condition }} + continueOnError: ${{ parameters.continueOnError }} + + - task: powershell@2 + displayName: Create ReleaseConfigs Artifact + inputs: + targetType: inline + script: | + Add-Content -Path "$(Build.StagingDirectory)/ReleaseConfigs.txt" -Value $(BARBuildId) + Add-Content -Path "$(Build.StagingDirectory)/ReleaseConfigs.txt" -Value "$(DefaultChannels)" + Add-Content -Path "$(Build.StagingDirectory)/ReleaseConfigs.txt" -Value $(IsStableBuild) + + - task: PublishBuildArtifacts@1 + displayName: Publish ReleaseConfigs Artifact + inputs: + PathtoPublish: '$(Build.StagingDirectory)/ReleaseConfigs.txt' + PublishLocation: Container + ArtifactName: ReleaseConfigs + + - task: powershell@2 + displayName: Check if SymbolPublishingExclusionsFile.txt exists + inputs: + targetType: inline + script: | + $symbolExclusionfile = "$(Build.SourcesDirectory)/eng/SymbolPublishingExclusionsFile.txt" + if(Test-Path -Path $symbolExclusionfile) + { + Write-Host "SymbolExclusionFile exists" + Write-Host "##vso[task.setvariable variable=SymbolExclusionFile]true" + } + else{ + Write-Host "Symbols Exclusion file does not exists" + Write-Host "##vso[task.setvariable variable=SymbolExclusionFile]false" + } + + - task: PublishBuildArtifacts@1 + displayName: Publish SymbolPublishingExclusionsFile Artifact + condition: eq(variables['SymbolExclusionFile'], 'true') + inputs: + PathtoPublish: '$(Build.SourcesDirectory)/eng/SymbolPublishingExclusionsFile.txt' + PublishLocation: Container + ArtifactName: ReleaseConfigs + + - ${{ if eq(parameters.publishAssetsImmediately, 'true') }}: + - template: /eng/common/templates/post-build/setup-maestro-vars.yml + parameters: + BARBuildId: ${{ parameters.BARBuildId }} + PromoteToChannelIds: ${{ parameters.PromoteToChannelIds }} + + - task: PowerShell@2 + displayName: Publish Using Darc + inputs: + filePath: $(Build.SourcesDirectory)/eng/common/post-build/publish-using-darc.ps1 + arguments: -BuildId $(BARBuildId) + -PublishingInfraVersion 3 + -AzdoToken '$(publishing-dnceng-devdiv-code-r-build-re)' + -MaestroToken '$(MaestroApiAccessToken)' + -WaitPublishingFinish true + -ArtifactsPublishingAdditionalParameters '${{ parameters.artifactsPublishingAdditionalParameters }}' + -SymbolPublishingAdditionalParameters '${{ parameters.symbolPublishingAdditionalParameters }}' + + - ${{ if eq(parameters.enablePublishBuildArtifacts, 'true') }}: + - template: /eng/common/templates/steps/publish-logs.yml + parameters: + JobLabel: 'Publish_Artifacts_Logs' diff --git a/eng/common/templates/job/source-build.yml b/eng/common/templates/job/source-build.yml new file mode 100644 index 0000000000000..8a3deef2b7274 --- /dev/null +++ b/eng/common/templates/job/source-build.yml @@ -0,0 +1,66 @@ +parameters: + # This template adds arcade-powered source-build to CI. The template produces a server job with a + # default ID 'Source_Build_Complete' to put in a dependency list if necessary. + + # Specifies the prefix for source-build jobs added to pipeline. Use this if disambiguation needed. + jobNamePrefix: 'Source_Build' + + # Defines the platform on which to run the job. By default, a linux-x64 machine, suitable for + # managed-only repositories. This is an object with these properties: + # + # name: '' + # The name of the job. This is included in the job ID. + # targetRID: '' + # The name of the target RID to use, instead of the one auto-detected by Arcade. + # nonPortable: false + # Enables non-portable mode. This means a more specific RID (e.g. fedora.32-x64 rather than + # linux-x64), and compiling against distro-provided packages rather than portable ones. + # skipPublishValidation: false + # Disables publishing validation. By default, a check is performed to ensure no packages are + # published by source-build. + # container: '' + # A container to use. Runs in docker. + # pool: {} + # A pool to use. Runs directly on an agent. + # buildScript: '' + # Specifies the build script to invoke to perform the build in the repo. The default + # './build.sh' should work for typical Arcade repositories, but this is customizable for + # difficult situations. + # jobProperties: {} + # A list of job properties to inject at the top level, for potential extensibility beyond + # container and pool. + platform: {} + +jobs: +- job: ${{ parameters.jobNamePrefix }}_${{ parameters.platform.name }} + displayName: Source-Build (${{ parameters.platform.name }}) + + ${{ each property in parameters.platform.jobProperties }}: + ${{ property.key }}: ${{ property.value }} + + ${{ if ne(parameters.platform.container, '') }}: + container: ${{ parameters.platform.container }} + + ${{ if eq(parameters.platform.pool, '') }}: + # The default VM host AzDO pool. This should be capable of running Docker containers: almost all + # source-build builds run in Docker, including the default managed platform. + # /eng/common/templates/variables/pool-providers.yml can't be used here (some customers declare variables already), so duplicate its logic + pool: + ${{ if eq(variables['System.TeamProject'], 'public') }}: + name: $[replace(replace(eq(contains(coalesce(variables['System.PullRequest.TargetBranch'], variables['Build.SourceBranch'], 'refs/heads/main'), 'release'), 'true'), True, 'NetCore-Svc-Public' ), False, 'NetCore-Public')] + demands: ImageOverride -equals Build.Ubuntu.1804.Amd64.Open + + ${{ if eq(variables['System.TeamProject'], 'internal') }}: + name: $[replace(replace(eq(contains(coalesce(variables['System.PullRequest.TargetBranch'], variables['Build.SourceBranch'], 'refs/heads/main'), 'release'), 'true'), True, 'NetCore1ESPool-Svc-Internal'), False, 'NetCore1ESPool-Internal')] + demands: ImageOverride -equals Build.Ubuntu.1804.Amd64 + + ${{ if ne(parameters.platform.pool, '') }}: + pool: ${{ parameters.platform.pool }} + + workspace: + clean: all + + steps: + - template: /eng/common/templates/steps/source-build.yml + parameters: + platform: ${{ parameters.platform }} diff --git a/eng/common/templates/job/source-index-stage1.yml b/eng/common/templates/job/source-index-stage1.yml new file mode 100644 index 0000000000000..71b66aeb8a5c5 --- /dev/null +++ b/eng/common/templates/job/source-index-stage1.yml @@ -0,0 +1,67 @@ +parameters: + runAsPublic: false + sourceIndexPackageVersion: 1.0.1-20221220.2 + sourceIndexPackageSource: https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json + sourceIndexBuildCommand: powershell -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "eng/common/build.ps1 -restore -build -binarylog -ci" + preSteps: [] + binlogPath: artifacts/log/Debug/Build.binlog + condition: '' + dependsOn: '' + pool: '' + +jobs: +- job: SourceIndexStage1 + dependsOn: ${{ parameters.dependsOn }} + condition: ${{ parameters.condition }} + variables: + - name: SourceIndexPackageVersion + value: ${{ parameters.sourceIndexPackageVersion }} + - name: SourceIndexPackageSource + value: ${{ parameters.sourceIndexPackageSource }} + - name: BinlogPath + value: ${{ parameters.binlogPath }} + - ${{ if and(eq(parameters.runAsPublic, 'false'), ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: + - group: source-dot-net stage1 variables + - template: /eng/common/templates/variables/pool-providers.yml + + ${{ if ne(parameters.pool, '') }}: + pool: ${{ parameters.pool }} + ${{ if eq(parameters.pool, '') }}: + pool: + ${{ if eq(variables['System.TeamProject'], 'public') }}: + name: $(DncEngPublicBuildPool) + demands: ImageOverride -equals windows.vs2019.amd64.open + ${{ if eq(variables['System.TeamProject'], 'internal') }}: + name: $(DncEngInternalBuildPool) + demands: ImageOverride -equals windows.vs2019.amd64 + + steps: + - ${{ each preStep in parameters.preSteps }}: + - ${{ preStep }} + + - task: UseDotNet@2 + displayName: Use .NET Core SDK 6 + inputs: + packageType: sdk + version: 6.0.x + installationPath: $(Agent.TempDirectory)/dotnet + workingDirectory: $(Agent.TempDirectory) + + - script: | + $(Agent.TempDirectory)/dotnet/dotnet tool install BinLogToSln --version $(SourceIndexPackageVersion) --add-source $(SourceIndexPackageSource) --tool-path $(Agent.TempDirectory)/.source-index/tools + $(Agent.TempDirectory)/dotnet/dotnet tool install UploadIndexStage1 --version $(SourceIndexPackageVersion) --add-source $(SourceIndexPackageSource) --tool-path $(Agent.TempDirectory)/.source-index/tools + displayName: Download Tools + # Set working directory to temp directory so 'dotnet' doesn't try to use global.json and use the repo's sdk. + workingDirectory: $(Agent.TempDirectory) + + - script: ${{ parameters.sourceIndexBuildCommand }} + displayName: Build Repository + + - script: $(Agent.TempDirectory)/.source-index/tools/BinLogToSln -i $(BinlogPath) -r $(Build.SourcesDirectory) -n $(Build.Repository.Name) -o .source-index/stage1output + displayName: Process Binlog into indexable sln + + - ${{ if and(eq(parameters.runAsPublic, 'false'), ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: + - script: $(Agent.TempDirectory)/.source-index/tools/UploadIndexStage1 -i .source-index/stage1output -n $(Build.Repository.Name) + displayName: Upload stage1 artifacts to source index + env: + BLOB_CONTAINER_URL: $(source-dot-net-stage1-blob-container-url) diff --git a/eng/common/templates/jobs/codeql-build.yml b/eng/common/templates/jobs/codeql-build.yml new file mode 100644 index 0000000000000..f7dc5ea4aaa63 --- /dev/null +++ b/eng/common/templates/jobs/codeql-build.yml @@ -0,0 +1,31 @@ +parameters: + # See schema documentation in /Documentation/AzureDevOps/TemplateSchema.md + continueOnError: false + # Required: A collection of jobs to run - https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=vsts&tabs=schema#job + jobs: [] + # Optional: if specified, restore and use this version of Guardian instead of the default. + overrideGuardianVersion: '' + +jobs: +- template: /eng/common/templates/jobs/jobs.yml + parameters: + enableMicrobuild: false + enablePublishBuildArtifacts: false + enablePublishTestResults: false + enablePublishBuildAssets: false + enablePublishUsingPipelines: false + enableTelemetry: true + + variables: + - group: Publish-Build-Assets + # The Guardian version specified in 'eng/common/sdl/packages.config'. This value must be kept in + # sync with the packages.config file. + - name: DefaultGuardianVersion + value: 0.109.0 + - name: GuardianPackagesConfigFile + value: $(Build.SourcesDirectory)\eng\common\sdl\packages.config + - name: GuardianVersion + value: ${{ coalesce(parameters.overrideGuardianVersion, '$(DefaultGuardianVersion)') }} + + jobs: ${{ parameters.jobs }} + diff --git a/eng/common/templates/jobs/jobs.yml b/eng/common/templates/jobs/jobs.yml new file mode 100644 index 0000000000000..289bb2396ce83 --- /dev/null +++ b/eng/common/templates/jobs/jobs.yml @@ -0,0 +1,97 @@ +parameters: + # See schema documentation in /Documentation/AzureDevOps/TemplateSchema.md + continueOnError: false + + # Optional: Include PublishBuildArtifacts task + enablePublishBuildArtifacts: false + + # Optional: Enable publishing using release pipelines + enablePublishUsingPipelines: false + + # Optional: Enable running the source-build jobs to build repo from source + enableSourceBuild: false + + # Optional: Parameters for source-build template. + # See /eng/common/templates/jobs/source-build.yml for options + sourceBuildParameters: [] + + graphFileGeneration: + # Optional: Enable generating the graph files at the end of the build + enabled: false + # Optional: Include toolset dependencies in the generated graph files + includeToolset: false + + # Required: A collection of jobs to run - https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=vsts&tabs=schema#job + jobs: [] + + # Optional: Override automatically derived dependsOn value for "publish build assets" job + publishBuildAssetsDependsOn: '' + + # Optional: Publish the assets as soon as the publish to BAR stage is complete, rather doing so in a separate stage. + publishAssetsImmediately: false + + # Optional: If using publishAssetsImmediately and additional parameters are needed, can be used to send along additional parameters (normally sent to post-build.yml) + artifactsPublishingAdditionalParameters: '' + signingValidationAdditionalParameters: '' + + # Optional: should run as a public build even in the internal project + # if 'true', the build won't run any of the internal only steps, even if it is running in non-public projects. + runAsPublic: false + + enableSourceIndex: false + sourceIndexParams: {} + +# Internal resources (telemetry, microbuild) can only be accessed from non-public projects, +# and some (Microbuild) should only be applied to non-PR cases for internal builds. + +jobs: +- ${{ each job in parameters.jobs }}: + - template: ../job/job.yml + parameters: + # pass along parameters + ${{ each parameter in parameters }}: + ${{ if ne(parameter.key, 'jobs') }}: + ${{ parameter.key }}: ${{ parameter.value }} + + # pass along job properties + ${{ each property in job }}: + ${{ if ne(property.key, 'job') }}: + ${{ property.key }}: ${{ property.value }} + + name: ${{ job.job }} + +- ${{ if eq(parameters.enableSourceBuild, true) }}: + - template: /eng/common/templates/jobs/source-build.yml + parameters: + allCompletedJobId: Source_Build_Complete + ${{ each parameter in parameters.sourceBuildParameters }}: + ${{ parameter.key }}: ${{ parameter.value }} + +- ${{ if eq(parameters.enableSourceIndex, 'true') }}: + - template: ../job/source-index-stage1.yml + parameters: + runAsPublic: ${{ parameters.runAsPublic }} + ${{ each parameter in parameters.sourceIndexParams }}: + ${{ parameter.key }}: ${{ parameter.value }} + +- ${{ if and(eq(parameters.runAsPublic, 'false'), ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: + - ${{ if or(eq(parameters.enablePublishBuildAssets, true), eq(parameters.artifacts.publish.manifests, 'true'), ne(parameters.artifacts.publish.manifests, '')) }}: + - template: ../job/publish-build-assets.yml + parameters: + continueOnError: ${{ parameters.continueOnError }} + dependsOn: + - ${{ if ne(parameters.publishBuildAssetsDependsOn, '') }}: + - ${{ each job in parameters.publishBuildAssetsDependsOn }}: + - ${{ job.job }} + - ${{ if eq(parameters.publishBuildAssetsDependsOn, '') }}: + - ${{ each job in parameters.jobs }}: + - ${{ job.job }} + - ${{ if eq(parameters.enableSourceBuild, true) }}: + - Source_Build_Complete + + runAsPublic: ${{ parameters.runAsPublic }} + publishUsingPipelines: ${{ parameters.enablePublishUsingPipelines }} + publishAssetsImmediately: ${{ parameters.publishAssetsImmediately }} + enablePublishBuildArtifacts: ${{ parameters.enablePublishBuildArtifacts }} + artifactsPublishingAdditionalParameters: ${{ parameters.artifactsPublishingAdditionalParameters }} + signingValidationAdditionalParameters: ${{ parameters.signingValidationAdditionalParameters }} diff --git a/eng/common/templates/jobs/source-build.yml b/eng/common/templates/jobs/source-build.yml new file mode 100644 index 0000000000000..a15b07eb51d9d --- /dev/null +++ b/eng/common/templates/jobs/source-build.yml @@ -0,0 +1,46 @@ +parameters: + # This template adds arcade-powered source-build to CI. A job is created for each platform, as + # well as an optional server job that completes when all platform jobs complete. + + # The name of the "join" job for all source-build platforms. If set to empty string, the job is + # not included. Existing repo pipelines can use this job depend on all source-build jobs + # completing without maintaining a separate list of every single job ID: just depend on this one + # server job. By default, not included. Recommended name if used: 'Source_Build_Complete'. + allCompletedJobId: '' + + # See /eng/common/templates/job/source-build.yml + jobNamePrefix: 'Source_Build' + + # This is the default platform provided by Arcade, intended for use by a managed-only repo. + defaultManagedPlatform: + name: 'Managed' + container: 'mcr.microsoft.com/dotnet-buildtools/prereqs:centos-stream8' + + # Defines the platforms on which to run build jobs. One job is created for each platform, and the + # object in this array is sent to the job template as 'platform'. If no platforms are specified, + # one job runs on 'defaultManagedPlatform'. + platforms: [] + +jobs: + +- ${{ if ne(parameters.allCompletedJobId, '') }}: + - job: ${{ parameters.allCompletedJobId }} + displayName: Source-Build Complete + pool: server + dependsOn: + - ${{ each platform in parameters.platforms }}: + - ${{ parameters.jobNamePrefix }}_${{ platform.name }} + - ${{ if eq(length(parameters.platforms), 0) }}: + - ${{ parameters.jobNamePrefix }}_${{ parameters.defaultManagedPlatform.name }} + +- ${{ each platform in parameters.platforms }}: + - template: /eng/common/templates/job/source-build.yml + parameters: + jobNamePrefix: ${{ parameters.jobNamePrefix }} + platform: ${{ platform }} + +- ${{ if eq(length(parameters.platforms), 0) }}: + - template: /eng/common/templates/job/source-build.yml + parameters: + jobNamePrefix: ${{ parameters.jobNamePrefix }} + platform: ${{ parameters.defaultManagedPlatform }} diff --git a/eng/common/templates/post-build/common-variables.yml b/eng/common/templates/post-build/common-variables.yml new file mode 100644 index 0000000000000..c24193acfc981 --- /dev/null +++ b/eng/common/templates/post-build/common-variables.yml @@ -0,0 +1,22 @@ +variables: + - group: Publish-Build-Assets + + # Whether the build is internal or not + - name: IsInternalBuild + value: ${{ and(ne(variables['System.TeamProject'], 'public'), contains(variables['Build.SourceBranch'], 'internal')) }} + + # Default Maestro++ API Endpoint and API Version + - name: MaestroApiEndPoint + value: "https://maestro-prod.westus2.cloudapp.azure.com" + - name: MaestroApiAccessToken + value: $(MaestroAccessToken) + - name: MaestroApiVersion + value: "2020-02-20" + + - name: SourceLinkCLIVersion + value: 3.0.0 + - name: SymbolToolVersion + value: 1.0.1 + + - name: runCodesignValidationInjection + value: false diff --git a/eng/common/templates/post-build/post-build.yml b/eng/common/templates/post-build/post-build.yml new file mode 100644 index 0000000000000..ef720f9d78198 --- /dev/null +++ b/eng/common/templates/post-build/post-build.yml @@ -0,0 +1,281 @@ +parameters: + # Which publishing infra should be used. THIS SHOULD MATCH THE VERSION ON THE BUILD MANIFEST. + # Publishing V1 is no longer supported + # Publishing V2 is no longer supported + # Publishing V3 is the default + - name: publishingInfraVersion + displayName: Which version of publishing should be used to promote the build definition? + type: number + default: 3 + values: + - 3 + + - name: BARBuildId + displayName: BAR Build Id + type: number + default: 0 + + - name: PromoteToChannelIds + displayName: Channel to promote BARBuildId to + type: string + default: '' + + - name: enableSourceLinkValidation + displayName: Enable SourceLink validation + type: boolean + default: false + + - name: enableSigningValidation + displayName: Enable signing validation + type: boolean + default: true + + - name: enableSymbolValidation + displayName: Enable symbol validation + type: boolean + default: false + + - name: enableNugetValidation + displayName: Enable NuGet validation + type: boolean + default: true + + - name: publishInstallersAndChecksums + displayName: Publish installers and checksums + type: boolean + default: true + + - name: SDLValidationParameters + type: object + default: + enable: false + publishGdn: false + continueOnError: false + params: '' + artifactNames: '' + downloadArtifacts: true + + # These parameters let the user customize the call to sdk-task.ps1 for publishing + # symbols & general artifacts as well as for signing validation + - name: symbolPublishingAdditionalParameters + displayName: Symbol publishing additional parameters + type: string + default: '' + + - name: artifactsPublishingAdditionalParameters + displayName: Artifact publishing additional parameters + type: string + default: '' + + - name: signingValidationAdditionalParameters + displayName: Signing validation additional parameters + type: string + default: '' + + # Which stages should finish execution before post-build stages start + - name: validateDependsOn + type: object + default: + - build + + - name: publishDependsOn + type: object + default: + - Validate + + # Optional: Call asset publishing rather than running in a separate stage + - name: publishAssetsImmediately + type: boolean + default: false + +stages: +- ${{ if or(eq( parameters.enableNugetValidation, 'true'), eq(parameters.enableSigningValidation, 'true'), eq(parameters.enableSourceLinkValidation, 'true'), eq(parameters.SDLValidationParameters.enable, 'true')) }}: + - stage: Validate + dependsOn: ${{ parameters.validateDependsOn }} + displayName: Validate Build Assets + variables: + - template: common-variables.yml + - template: /eng/common/templates/variables/pool-providers.yml + jobs: + - job: + displayName: NuGet Validation + condition: and(succeededOrFailed(), eq( ${{ parameters.enableNugetValidation }}, 'true')) + pool: + # We don't use the collection uri here because it might vary (.visualstudio.com vs. dev.azure.com) + ${{ if eq(variables['System.TeamProject'], 'DevDiv') }}: + name: VSEngSS-MicroBuild2022-1ES + demands: Cmd + # If it's not devdiv, it's dnceng + ${{ else }}: + name: $(DncEngInternalBuildPool) + demands: ImageOverride -equals windows.vs2019.amd64 + + steps: + - template: setup-maestro-vars.yml + parameters: + BARBuildId: ${{ parameters.BARBuildId }} + PromoteToChannelIds: ${{ parameters.PromoteToChannelIds }} + + - task: DownloadBuildArtifacts@0 + displayName: Download Package Artifacts + inputs: + buildType: specific + buildVersionToDownload: specific + project: $(AzDOProjectName) + pipeline: $(AzDOPipelineId) + buildId: $(AzDOBuildId) + artifactName: PackageArtifacts + checkDownloadedFiles: true + + - task: PowerShell@2 + displayName: Validate + inputs: + filePath: $(Build.SourcesDirectory)/eng/common/post-build/nuget-validation.ps1 + arguments: -PackagesPath $(Build.ArtifactStagingDirectory)/PackageArtifacts/ + -ToolDestinationPath $(Agent.BuildDirectory)/Extract/ + + - job: + displayName: Signing Validation + condition: and( eq( ${{ parameters.enableSigningValidation }}, 'true'), ne( variables['PostBuildSign'], 'true')) + pool: + # We don't use the collection uri here because it might vary (.visualstudio.com vs. dev.azure.com) + ${{ if eq(variables['System.TeamProject'], 'DevDiv') }}: + name: VSEngSS-MicroBuild2022-1ES + demands: Cmd + # If it's not devdiv, it's dnceng + ${{ else }}: + name: $(DncEngInternalBuildPool) + demands: ImageOverride -equals windows.vs2019.amd64 + steps: + - template: setup-maestro-vars.yml + parameters: + BARBuildId: ${{ parameters.BARBuildId }} + PromoteToChannelIds: ${{ parameters.PromoteToChannelIds }} + + - task: DownloadBuildArtifacts@0 + displayName: Download Package Artifacts + inputs: + buildType: specific + buildVersionToDownload: specific + project: $(AzDOProjectName) + pipeline: $(AzDOPipelineId) + buildId: $(AzDOBuildId) + artifactName: PackageArtifacts + checkDownloadedFiles: true + itemPattern: | + ** + !**/Microsoft.SourceBuild.Intermediate.*.nupkg + + # This is necessary whenever we want to publish/restore to an AzDO private feed + # Since sdk-task.ps1 tries to restore packages we need to do this authentication here + # otherwise it'll complain about accessing a private feed. + - task: NuGetAuthenticate@0 + displayName: 'Authenticate to AzDO Feeds' + + # Signing validation will optionally work with the buildmanifest file which is downloaded from + # Azure DevOps above. + - task: PowerShell@2 + displayName: Validate + inputs: + filePath: eng\common\sdk-task.ps1 + arguments: -task SigningValidation -restore -msbuildEngine vs + /p:PackageBasePath='$(Build.ArtifactStagingDirectory)/PackageArtifacts' + /p:SignCheckExclusionsFile='$(Build.SourcesDirectory)/eng/SignCheckExclusionsFile.txt' + ${{ parameters.signingValidationAdditionalParameters }} + + - template: ../steps/publish-logs.yml + parameters: + StageLabel: 'Validation' + JobLabel: 'Signing' + + - job: + displayName: SourceLink Validation + condition: eq( ${{ parameters.enableSourceLinkValidation }}, 'true') + pool: + # We don't use the collection uri here because it might vary (.visualstudio.com vs. dev.azure.com) + ${{ if eq(variables['System.TeamProject'], 'DevDiv') }}: + name: VSEngSS-MicroBuild2022-1ES + demands: Cmd + # If it's not devdiv, it's dnceng + ${{ else }}: + name: $(DncEngInternalBuildPool) + demands: ImageOverride -equals windows.vs2019.amd64 + steps: + - template: setup-maestro-vars.yml + parameters: + BARBuildId: ${{ parameters.BARBuildId }} + PromoteToChannelIds: ${{ parameters.PromoteToChannelIds }} + + - task: DownloadBuildArtifacts@0 + displayName: Download Blob Artifacts + inputs: + buildType: specific + buildVersionToDownload: specific + project: $(AzDOProjectName) + pipeline: $(AzDOPipelineId) + buildId: $(AzDOBuildId) + artifactName: BlobArtifacts + checkDownloadedFiles: true + + - task: PowerShell@2 + displayName: Validate + inputs: + filePath: $(Build.SourcesDirectory)/eng/common/post-build/sourcelink-validation.ps1 + arguments: -InputPath $(Build.ArtifactStagingDirectory)/BlobArtifacts/ + -ExtractPath $(Agent.BuildDirectory)/Extract/ + -GHRepoName $(Build.Repository.Name) + -GHCommit $(Build.SourceVersion) + -SourcelinkCliVersion $(SourceLinkCLIVersion) + continueOnError: true + + - template: /eng/common/templates/job/execute-sdl.yml + parameters: + enable: ${{ parameters.SDLValidationParameters.enable }} + publishGuardianDirectoryToPipeline: ${{ parameters.SDLValidationParameters.publishGdn }} + additionalParameters: ${{ parameters.SDLValidationParameters.params }} + continueOnError: ${{ parameters.SDLValidationParameters.continueOnError }} + artifactNames: ${{ parameters.SDLValidationParameters.artifactNames }} + downloadArtifacts: ${{ parameters.SDLValidationParameters.downloadArtifacts }} + +- ${{ if ne(parameters.publishAssetsImmediately, 'true') }}: + - stage: publish_using_darc + ${{ if or(eq(parameters.enableNugetValidation, 'true'), eq(parameters.enableSigningValidation, 'true'), eq(parameters.enableSourceLinkValidation, 'true'), eq(parameters.SDLValidationParameters.enable, 'true')) }}: + dependsOn: ${{ parameters.publishDependsOn }} + ${{ else }}: + dependsOn: ${{ parameters.validateDependsOn }} + displayName: Publish using Darc + variables: + - template: common-variables.yml + - template: /eng/common/templates/variables/pool-providers.yml + jobs: + - job: + displayName: Publish Using Darc + timeoutInMinutes: 120 + pool: + # We don't use the collection uri here because it might vary (.visualstudio.com vs. dev.azure.com) + ${{ if eq(variables['System.TeamProject'], 'DevDiv') }}: + name: VSEngSS-MicroBuild2022-1ES + demands: Cmd + # If it's not devdiv, it's dnceng + ${{ else }}: + name: $(DncEngInternalBuildPool) + demands: ImageOverride -equals windows.vs2019.amd64 + steps: + - template: setup-maestro-vars.yml + parameters: + BARBuildId: ${{ parameters.BARBuildId }} + PromoteToChannelIds: ${{ parameters.PromoteToChannelIds }} + + - task: NuGetAuthenticate@0 + + - task: PowerShell@2 + displayName: Publish Using Darc + inputs: + filePath: $(Build.SourcesDirectory)/eng/common/post-build/publish-using-darc.ps1 + arguments: -BuildId $(BARBuildId) + -PublishingInfraVersion ${{ parameters.publishingInfraVersion }} + -AzdoToken '$(publishing-dnceng-devdiv-code-r-build-re)' + -MaestroToken '$(MaestroApiAccessToken)' + -WaitPublishingFinish true + -ArtifactsPublishingAdditionalParameters '${{ parameters.artifactsPublishingAdditionalParameters }}' + -SymbolPublishingAdditionalParameters '${{ parameters.symbolPublishingAdditionalParameters }}' diff --git a/eng/common/templates/post-build/setup-maestro-vars.yml b/eng/common/templates/post-build/setup-maestro-vars.yml new file mode 100644 index 0000000000000..0c87f149a4ad7 --- /dev/null +++ b/eng/common/templates/post-build/setup-maestro-vars.yml @@ -0,0 +1,70 @@ +parameters: + BARBuildId: '' + PromoteToChannelIds: '' + +steps: + - ${{ if eq(coalesce(parameters.PromoteToChannelIds, 0), 0) }}: + - task: DownloadBuildArtifacts@0 + displayName: Download Release Configs + inputs: + buildType: current + artifactName: ReleaseConfigs + checkDownloadedFiles: true + + - task: PowerShell@2 + name: setReleaseVars + displayName: Set Release Configs Vars + inputs: + targetType: inline + pwsh: true + script: | + try { + if (!$Env:PromoteToMaestroChannels -or $Env:PromoteToMaestroChannels.Trim() -eq '') { + $Content = Get-Content $(Build.StagingDirectory)/ReleaseConfigs/ReleaseConfigs.txt + + $BarId = $Content | Select -Index 0 + $Channels = $Content | Select -Index 1 + $IsStableBuild = $Content | Select -Index 2 + + $AzureDevOpsProject = $Env:System_TeamProject + $AzureDevOpsBuildDefinitionId = $Env:System_DefinitionId + $AzureDevOpsBuildId = $Env:Build_BuildId + } + else { + $buildApiEndpoint = "${Env:MaestroApiEndPoint}/api/builds/${Env:BARBuildId}?api-version=${Env:MaestroApiVersion}" + + $apiHeaders = New-Object 'System.Collections.Generic.Dictionary[[String],[String]]' + $apiHeaders.Add('Accept', 'application/json') + $apiHeaders.Add('Authorization',"Bearer ${Env:MAESTRO_API_TOKEN}") + + $buildInfo = try { Invoke-WebRequest -Method Get -Uri $buildApiEndpoint -Headers $apiHeaders | ConvertFrom-Json } catch { Write-Host "Error: $_" } + + $BarId = $Env:BARBuildId + $Channels = $Env:PromoteToMaestroChannels -split "," + $Channels = $Channels -join "][" + $Channels = "[$Channels]" + + $IsStableBuild = $buildInfo.stable + $AzureDevOpsProject = $buildInfo.azureDevOpsProject + $AzureDevOpsBuildDefinitionId = $buildInfo.azureDevOpsBuildDefinitionId + $AzureDevOpsBuildId = $buildInfo.azureDevOpsBuildId + } + + Write-Host "##vso[task.setvariable variable=BARBuildId]$BarId" + Write-Host "##vso[task.setvariable variable=TargetChannels]$Channels" + Write-Host "##vso[task.setvariable variable=IsStableBuild]$IsStableBuild" + + Write-Host "##vso[task.setvariable variable=AzDOProjectName]$AzureDevOpsProject" + Write-Host "##vso[task.setvariable variable=AzDOPipelineId]$AzureDevOpsBuildDefinitionId" + Write-Host "##vso[task.setvariable variable=AzDOBuildId]$AzureDevOpsBuildId" + } + catch { + Write-Host $_ + Write-Host $_.Exception + Write-Host $_.ScriptStackTrace + exit 1 + } + env: + MAESTRO_API_TOKEN: $(MaestroApiAccessToken) + BARBuildId: ${{ parameters.BARBuildId }} + PromoteToMaestroChannels: ${{ parameters.PromoteToChannelIds }} diff --git a/eng/common/templates/post-build/trigger-subscription.yml b/eng/common/templates/post-build/trigger-subscription.yml new file mode 100644 index 0000000000000..da669030daf6e --- /dev/null +++ b/eng/common/templates/post-build/trigger-subscription.yml @@ -0,0 +1,13 @@ +parameters: + ChannelId: 0 + +steps: +- task: PowerShell@2 + displayName: Triggering subscriptions + inputs: + filePath: $(Build.SourcesDirectory)/eng/common/post-build/trigger-subscriptions.ps1 + arguments: -SourceRepo $(Build.Repository.Uri) + -ChannelId ${{ parameters.ChannelId }} + -MaestroApiAccessToken $(MaestroAccessToken) + -MaestroApiEndPoint $(MaestroApiEndPoint) + -MaestroApiVersion $(MaestroApiVersion) diff --git a/eng/common/templates/steps/add-build-to-channel.yml b/eng/common/templates/steps/add-build-to-channel.yml new file mode 100644 index 0000000000000..f67a210d62f3e --- /dev/null +++ b/eng/common/templates/steps/add-build-to-channel.yml @@ -0,0 +1,13 @@ +parameters: + ChannelId: 0 + +steps: +- task: PowerShell@2 + displayName: Add Build to Channel + inputs: + filePath: $(Build.SourcesDirectory)/eng/common/post-build/add-build-to-channel.ps1 + arguments: -BuildId $(BARBuildId) + -ChannelId ${{ parameters.ChannelId }} + -MaestroApiAccessToken $(MaestroApiAccessToken) + -MaestroApiEndPoint $(MaestroApiEndPoint) + -MaestroApiVersion $(MaestroApiVersion) diff --git a/eng/common/templates/steps/build-reason.yml b/eng/common/templates/steps/build-reason.yml new file mode 100644 index 0000000000000..eba58109b52c9 --- /dev/null +++ b/eng/common/templates/steps/build-reason.yml @@ -0,0 +1,12 @@ +# build-reason.yml +# Description: runs steps if build.reason condition is valid. conditions is a string of valid build reasons +# to include steps (',' separated). +parameters: + conditions: '' + steps: [] + +steps: + - ${{ if and( not(startsWith(parameters.conditions, 'not')), contains(parameters.conditions, variables['build.reason'])) }}: + - ${{ parameters.steps }} + - ${{ if and( startsWith(parameters.conditions, 'not'), not(contains(parameters.conditions, variables['build.reason']))) }}: + - ${{ parameters.steps }} diff --git a/eng/common/templates/steps/execute-codeql.yml b/eng/common/templates/steps/execute-codeql.yml new file mode 100644 index 0000000000000..3930b1630214b --- /dev/null +++ b/eng/common/templates/steps/execute-codeql.yml @@ -0,0 +1,32 @@ +parameters: + # Language that should be analyzed. Defaults to csharp + language: csharp + # Build Commands + buildCommands: '' + overrideParameters: '' # Optional: to override values for parameters. + additionalParameters: '' # Optional: parameters that need user specific values eg: '-SourceToolsList @("abc","def") -ArtifactToolsList @("ghi","jkl")' + # Optional: if specified, restore and use this version of Guardian instead of the default. + overrideGuardianVersion: '' + # Optional: if true, publish the '.gdn' folder as a pipeline artifact. This can help with in-depth + # diagnosis of problems with specific tool configurations. + publishGuardianDirectoryToPipeline: false + # The script to run to execute all SDL tools. Use this if you want to use a script to define SDL + # parameters rather than relying on YAML. It may be better to use a local script, because you can + # reproduce results locally without piecing together a command based on the YAML. + executeAllSdlToolsScript: 'eng/common/sdl/execute-all-sdl-tools.ps1' + # There is some sort of bug (has been reported) in Azure DevOps where if this parameter is named + # 'continueOnError', the parameter value is not correctly picked up. + # This can also be remedied by the caller (post-build.yml) if it does not use a nested parameter + # optional: determines whether to continue the build if the step errors; + sdlContinueOnError: false + +steps: +- template: /eng/common/templates/steps/execute-sdl.yml + parameters: + overrideGuardianVersion: ${{ parameters.overrideGuardianVersion }} + executeAllSdlToolsScript: ${{ parameters.executeAllSdlToolsScript }} + overrideParameters: ${{ parameters.overrideParameters }} + additionalParameters: '${{ parameters.additionalParameters }} + -CodeQLAdditionalRunConfigParams @("BuildCommands < ${{ parameters.buildCommands }}", "Language < ${{ parameters.language }}")' + publishGuardianDirectoryToPipeline: ${{ parameters.publishGuardianDirectoryToPipeline }} + sdlContinueOnError: ${{ parameters.sdlContinueOnError }} \ No newline at end of file diff --git a/eng/common/templates/steps/execute-sdl.yml b/eng/common/templates/steps/execute-sdl.yml new file mode 100644 index 0000000000000..9dd5709f66dc7 --- /dev/null +++ b/eng/common/templates/steps/execute-sdl.yml @@ -0,0 +1,88 @@ +parameters: + overrideGuardianVersion: '' + executeAllSdlToolsScript: '' + overrideParameters: '' + additionalParameters: '' + publishGuardianDirectoryToPipeline: false + sdlContinueOnError: false + condition: '' + +steps: +- task: NuGetAuthenticate@1 + inputs: + nuGetServiceConnections: GuardianConnect + +- task: NuGetToolInstaller@1 + displayName: 'Install NuGet.exe' + +- ${{ if ne(parameters.overrideGuardianVersion, '') }}: + - pwsh: | + Set-Location -Path $(Build.SourcesDirectory)\eng\common\sdl + . .\sdl.ps1 + $guardianCliLocation = Install-Gdn -Path $(Build.SourcesDirectory)\.artifacts -Version ${{ parameters.overrideGuardianVersion }} + Write-Host "##vso[task.setvariable variable=GuardianCliLocation]$guardianCliLocation" + displayName: Install Guardian (Overridden) + +- ${{ if eq(parameters.overrideGuardianVersion, '') }}: + - pwsh: | + Set-Location -Path $(Build.SourcesDirectory)\eng\common\sdl + . .\sdl.ps1 + $guardianCliLocation = Install-Gdn -Path $(Build.SourcesDirectory)\.artifacts + Write-Host "##vso[task.setvariable variable=GuardianCliLocation]$guardianCliLocation" + displayName: Install Guardian + +- ${{ if ne(parameters.overrideParameters, '') }}: + - powershell: ${{ parameters.executeAllSdlToolsScript }} ${{ parameters.overrideParameters }} + displayName: Execute SDL + continueOnError: ${{ parameters.sdlContinueOnError }} + condition: ${{ parameters.condition }} + +- ${{ if eq(parameters.overrideParameters, '') }}: + - powershell: ${{ parameters.executeAllSdlToolsScript }} + -GuardianCliLocation $(GuardianCliLocation) + -NugetPackageDirectory $(Build.SourcesDirectory)\.packages + -AzureDevOpsAccessToken $(dn-bot-dotnet-build-rw-code-rw) + ${{ parameters.additionalParameters }} + displayName: Execute SDL + continueOnError: ${{ parameters.sdlContinueOnError }} + condition: ${{ parameters.condition }} + +- ${{ if ne(parameters.publishGuardianDirectoryToPipeline, 'false') }}: + # We want to publish the Guardian results and configuration for easy diagnosis. However, the + # '.gdn' dir is a mix of configuration, results, extracted dependencies, and Guardian default + # tooling files. Some of these files are large and aren't useful during an investigation, so + # exclude them by simply deleting them before publishing. (As of writing, there is no documented + # way to selectively exclude a dir from the pipeline artifact publish task.) + - task: DeleteFiles@1 + displayName: Delete Guardian dependencies to avoid uploading + inputs: + SourceFolder: $(Agent.BuildDirectory)/.gdn + Contents: | + c + i + condition: succeededOrFailed() + + - publish: $(Agent.BuildDirectory)/.gdn + artifact: GuardianConfiguration + displayName: Publish GuardianConfiguration + condition: succeededOrFailed() + + # Publish the SARIF files in a container named CodeAnalysisLogs to enable integration + # with the "SARIF SAST Scans Tab" Azure DevOps extension + - task: CopyFiles@2 + displayName: Copy SARIF files + inputs: + flattenFolders: true + sourceFolder: $(Agent.BuildDirectory)/.gdn/rc/ + contents: '**/*.sarif' + targetFolder: $(Build.SourcesDirectory)/CodeAnalysisLogs + condition: succeededOrFailed() + + # Use PublishBuildArtifacts because the SARIF extension only checks this case + # see microsoft/sarif-azuredevops-extension#4 + - task: PublishBuildArtifacts@1 + displayName: Publish SARIF files to CodeAnalysisLogs container + inputs: + pathToPublish: $(Build.SourcesDirectory)/CodeAnalysisLogs + artifactName: CodeAnalysisLogs + condition: succeededOrFailed() \ No newline at end of file diff --git a/eng/common/templates/steps/generate-sbom.yml b/eng/common/templates/steps/generate-sbom.yml new file mode 100644 index 0000000000000..a06373f38fa5d --- /dev/null +++ b/eng/common/templates/steps/generate-sbom.yml @@ -0,0 +1,48 @@ +# BuildDropPath - The root folder of the drop directory for which the manifest file will be generated. +# PackageName - The name of the package this SBOM represents. +# PackageVersion - The version of the package this SBOM represents. +# ManifestDirPath - The path of the directory where the generated manifest files will be placed +# IgnoreDirectories - Directories to ignore for SBOM generation. This will be passed through to the CG component detector. + +parameters: + PackageVersion: 7.0.0 + BuildDropPath: '$(Build.SourcesDirectory)/artifacts' + PackageName: '.NET' + ManifestDirPath: $(Build.ArtifactStagingDirectory)/sbom + IgnoreDirectories: '' + sbomContinueOnError: true + +steps: +- task: PowerShell@2 + displayName: Prep for SBOM generation in (Non-linux) + condition: or(eq(variables['Agent.Os'], 'Windows_NT'), eq(variables['Agent.Os'], 'Darwin')) + inputs: + filePath: ./eng/common/generate-sbom-prep.ps1 + arguments: ${{parameters.manifestDirPath}} + +# Chmodding is a workaround for https://github.com/dotnet/arcade/issues/8461 +- script: | + chmod +x ./eng/common/generate-sbom-prep.sh + ./eng/common/generate-sbom-prep.sh ${{parameters.manifestDirPath}} + displayName: Prep for SBOM generation in (Linux) + condition: eq(variables['Agent.Os'], 'Linux') + continueOnError: ${{ parameters.sbomContinueOnError }} + +- task: AzureArtifacts.manifest-generator-task.manifest-generator-task.ManifestGeneratorTask@0 + displayName: 'Generate SBOM manifest' + continueOnError: ${{ parameters.sbomContinueOnError }} + inputs: + PackageName: ${{ parameters.packageName }} + BuildDropPath: ${{ parameters.buildDropPath }} + PackageVersion: ${{ parameters.packageVersion }} + ManifestDirPath: ${{ parameters.manifestDirPath }} + ${{ if ne(parameters.IgnoreDirectories, '') }}: + AdditionalComponentDetectorArgs: '--IgnoreDirectories ${{ parameters.IgnoreDirectories }}' + +- task: PublishPipelineArtifact@1 + displayName: Publish SBOM manifest + continueOnError: ${{parameters.sbomContinueOnError}} + inputs: + targetPath: '${{parameters.manifestDirPath}}' + artifactName: $(ARTIFACT_NAME) + diff --git a/eng/common/templates/steps/publish-logs.yml b/eng/common/templates/steps/publish-logs.yml new file mode 100644 index 0000000000000..88f238f36bfd8 --- /dev/null +++ b/eng/common/templates/steps/publish-logs.yml @@ -0,0 +1,23 @@ +parameters: + StageLabel: '' + JobLabel: '' + +steps: +- task: Powershell@2 + displayName: Prepare Binlogs to Upload + inputs: + targetType: inline + script: | + New-Item -ItemType Directory $(Build.SourcesDirectory)/PostBuildLogs/${{parameters.StageLabel}}/${{parameters.JobLabel}}/ + Move-Item -Path $(Build.SourcesDirectory)/artifacts/log/Debug/* $(Build.SourcesDirectory)/PostBuildLogs/${{parameters.StageLabel}}/${{parameters.JobLabel}}/ + continueOnError: true + condition: always() + +- task: PublishBuildArtifacts@1 + displayName: Publish Logs + inputs: + PathtoPublish: '$(Build.SourcesDirectory)/PostBuildLogs' + PublishLocation: Container + ArtifactName: PostBuildLogs + continueOnError: true + condition: always() diff --git a/eng/common/templates/steps/retain-build.yml b/eng/common/templates/steps/retain-build.yml new file mode 100644 index 0000000000000..83d97a26a01ff --- /dev/null +++ b/eng/common/templates/steps/retain-build.yml @@ -0,0 +1,28 @@ +parameters: + # Optional azure devops PAT with build execute permissions for the build's organization, + # only needed if the build that should be retained ran on a different organization than + # the pipeline where this template is executing from + Token: '' + # Optional BuildId to retain, defaults to the current running build + BuildId: '' + # Azure devops Organization URI for the build in the https://dev.azure.com/ format. + # Defaults to the organization the current pipeline is running on + AzdoOrgUri: '$(System.CollectionUri)' + # Azure devops project for the build. Defaults to the project the current pipeline is running on + AzdoProject: '$(System.TeamProject)' + +steps: + - task: powershell@2 + inputs: + targetType: 'filePath' + filePath: eng/common/retain-build.ps1 + pwsh: true + arguments: > + -AzdoOrgUri: ${{parameters.AzdoOrgUri}} + -AzdoProject ${{parameters.AzdoProject}} + -Token ${{coalesce(parameters.Token, '$env:SYSTEM_ACCESSTOKEN') }} + -BuildId ${{coalesce(parameters.BuildId, '$env:BUILD_ID')}} + displayName: Enable permanent build retention + env: + SYSTEM_ACCESSTOKEN: $(System.AccessToken) + BUILD_ID: $(Build.BuildId) \ No newline at end of file diff --git a/eng/common/templates/steps/run-on-unix.yml b/eng/common/templates/steps/run-on-unix.yml new file mode 100644 index 0000000000000..e1733814f65dc --- /dev/null +++ b/eng/common/templates/steps/run-on-unix.yml @@ -0,0 +1,7 @@ +parameters: + agentOs: '' + steps: [] + +steps: +- ${{ if ne(parameters.agentOs, 'Windows_NT') }}: + - ${{ parameters.steps }} diff --git a/eng/common/templates/steps/run-on-windows.yml b/eng/common/templates/steps/run-on-windows.yml new file mode 100644 index 0000000000000..73e7e9c275a1f --- /dev/null +++ b/eng/common/templates/steps/run-on-windows.yml @@ -0,0 +1,7 @@ +parameters: + agentOs: '' + steps: [] + +steps: +- ${{ if eq(parameters.agentOs, 'Windows_NT') }}: + - ${{ parameters.steps }} diff --git a/eng/common/templates/steps/run-script-ifequalelse.yml b/eng/common/templates/steps/run-script-ifequalelse.yml new file mode 100644 index 0000000000000..3d1242f5587c8 --- /dev/null +++ b/eng/common/templates/steps/run-script-ifequalelse.yml @@ -0,0 +1,33 @@ +parameters: + # if parameter1 equals parameter 2, run 'ifScript' command, else run 'elsescript' command + parameter1: '' + parameter2: '' + ifScript: '' + elseScript: '' + + # name of script step + name: Script + + # display name of script step + displayName: If-Equal-Else Script + + # environment + env: {} + + # conditional expression for step execution + condition: '' + +steps: +- ${{ if and(ne(parameters.ifScript, ''), eq(parameters.parameter1, parameters.parameter2)) }}: + - script: ${{ parameters.ifScript }} + name: ${{ parameters.name }} + displayName: ${{ parameters.displayName }} + env: ${{ parameters.env }} + condition: ${{ parameters.condition }} + +- ${{ if and(ne(parameters.elseScript, ''), ne(parameters.parameter1, parameters.parameter2)) }}: + - script: ${{ parameters.elseScript }} + name: ${{ parameters.name }} + displayName: ${{ parameters.displayName }} + env: ${{ parameters.env }} + condition: ${{ parameters.condition }} \ No newline at end of file diff --git a/eng/common/templates/steps/send-to-helix.yml b/eng/common/templates/steps/send-to-helix.yml new file mode 100644 index 0000000000000..3eb7e2d5f840c --- /dev/null +++ b/eng/common/templates/steps/send-to-helix.yml @@ -0,0 +1,91 @@ +# Please remember to update the documentation if you make changes to these parameters! +parameters: + HelixSource: 'pr/default' # required -- sources must start with pr/, official/, prodcon/, or agent/ + HelixType: 'tests/default/' # required -- Helix telemetry which identifies what type of data this is; should include "test" for clarity and must end in '/' + HelixBuild: $(Build.BuildNumber) # required -- the build number Helix will use to identify this -- automatically set to the AzDO build number + HelixTargetQueues: '' # required -- semicolon-delimited list of Helix queues to test on; see https://helix.dot.net/ for a list of queues + HelixAccessToken: '' # required -- access token to make Helix API requests; should be provided by the appropriate variable group + HelixConfiguration: '' # optional -- additional property attached to a job + HelixPreCommands: '' # optional -- commands to run before Helix work item execution + HelixPostCommands: '' # optional -- commands to run after Helix work item execution + WorkItemDirectory: '' # optional -- a payload directory to zip up and send to Helix; requires WorkItemCommand; incompatible with XUnitProjects + WorkItemCommand: '' # optional -- a command to execute on the payload; requires WorkItemDirectory; incompatible with XUnitProjects + WorkItemTimeout: '' # optional -- a timeout in TimeSpan.Parse-ready value (e.g. 00:02:00) for the work item command; requires WorkItemDirectory; incompatible with XUnitProjects + CorrelationPayloadDirectory: '' # optional -- a directory to zip up and send to Helix as a correlation payload + XUnitProjects: '' # optional -- semicolon-delimited list of XUnitProjects to parse and send to Helix; requires XUnitRuntimeTargetFramework, XUnitPublishTargetFramework, XUnitRunnerVersion, and IncludeDotNetCli=true + XUnitWorkItemTimeout: '' # optional -- the workitem timeout in seconds for all workitems created from the xUnit projects specified by XUnitProjects + XUnitPublishTargetFramework: '' # optional -- framework to use to publish your xUnit projects + XUnitRuntimeTargetFramework: '' # optional -- framework to use for the xUnit console runner + XUnitRunnerVersion: '' # optional -- version of the xUnit nuget package you wish to use on Helix; required for XUnitProjects + IncludeDotNetCli: false # optional -- true will download a version of the .NET CLI onto the Helix machine as a correlation payload; requires DotNetCliPackageType and DotNetCliVersion + DotNetCliPackageType: '' # optional -- either 'sdk', 'runtime' or 'aspnetcore-runtime'; determines whether the sdk or runtime will be sent to Helix; see https://raw.githubusercontent.com/dotnet/core/main/release-notes/releases-index.json + DotNetCliVersion: '' # optional -- version of the CLI to send to Helix; based on this: https://raw.githubusercontent.com/dotnet/core/main/release-notes/releases-index.json + WaitForWorkItemCompletion: true # optional -- true will make the task wait until work items have been completed and fail the build if work items fail. False is "fire and forget." + IsExternal: false # [DEPRECATED] -- doesn't do anything, jobs are external if HelixAccessToken is empty and Creator is set + HelixBaseUri: 'https://helix.dot.net/' # optional -- sets the Helix API base URI (allows targeting https://helix.int-dot.net ) + Creator: '' # optional -- if the build is external, use this to specify who is sending the job + DisplayNamePrefix: 'Run Tests' # optional -- rename the beginning of the displayName of the steps in AzDO + condition: succeeded() # optional -- condition for step to execute; defaults to succeeded() + continueOnError: false # optional -- determines whether to continue the build if the step errors; defaults to false + +steps: + - powershell: 'powershell "$env:BUILD_SOURCESDIRECTORY\eng\common\msbuild.ps1 $env:BUILD_SOURCESDIRECTORY\eng\common\helixpublish.proj /restore /p:TreatWarningsAsErrors=false /t:Test /bl:$env:BUILD_SOURCESDIRECTORY\artifacts\log\$env:BuildConfig\SendToHelix.binlog"' + displayName: ${{ parameters.DisplayNamePrefix }} (Windows) + env: + BuildConfig: $(_BuildConfig) + HelixSource: ${{ parameters.HelixSource }} + HelixType: ${{ parameters.HelixType }} + HelixBuild: ${{ parameters.HelixBuild }} + HelixConfiguration: ${{ parameters.HelixConfiguration }} + HelixTargetQueues: ${{ parameters.HelixTargetQueues }} + HelixAccessToken: ${{ parameters.HelixAccessToken }} + HelixPreCommands: ${{ parameters.HelixPreCommands }} + HelixPostCommands: ${{ parameters.HelixPostCommands }} + WorkItemDirectory: ${{ parameters.WorkItemDirectory }} + WorkItemCommand: ${{ parameters.WorkItemCommand }} + WorkItemTimeout: ${{ parameters.WorkItemTimeout }} + CorrelationPayloadDirectory: ${{ parameters.CorrelationPayloadDirectory }} + XUnitProjects: ${{ parameters.XUnitProjects }} + XUnitWorkItemTimeout: ${{ parameters.XUnitWorkItemTimeout }} + XUnitPublishTargetFramework: ${{ parameters.XUnitPublishTargetFramework }} + XUnitRuntimeTargetFramework: ${{ parameters.XUnitRuntimeTargetFramework }} + XUnitRunnerVersion: ${{ parameters.XUnitRunnerVersion }} + IncludeDotNetCli: ${{ parameters.IncludeDotNetCli }} + DotNetCliPackageType: ${{ parameters.DotNetCliPackageType }} + DotNetCliVersion: ${{ parameters.DotNetCliVersion }} + WaitForWorkItemCompletion: ${{ parameters.WaitForWorkItemCompletion }} + HelixBaseUri: ${{ parameters.HelixBaseUri }} + Creator: ${{ parameters.Creator }} + SYSTEM_ACCESSTOKEN: $(System.AccessToken) + condition: and(${{ parameters.condition }}, eq(variables['Agent.Os'], 'Windows_NT')) + continueOnError: ${{ parameters.continueOnError }} + - script: $BUILD_SOURCESDIRECTORY/eng/common/msbuild.sh $BUILD_SOURCESDIRECTORY/eng/common/helixpublish.proj /restore /p:TreatWarningsAsErrors=false /t:Test /bl:$BUILD_SOURCESDIRECTORY/artifacts/log/$BuildConfig/SendToHelix.binlog + displayName: ${{ parameters.DisplayNamePrefix }} (Unix) + env: + BuildConfig: $(_BuildConfig) + HelixSource: ${{ parameters.HelixSource }} + HelixType: ${{ parameters.HelixType }} + HelixBuild: ${{ parameters.HelixBuild }} + HelixConfiguration: ${{ parameters.HelixConfiguration }} + HelixTargetQueues: ${{ parameters.HelixTargetQueues }} + HelixAccessToken: ${{ parameters.HelixAccessToken }} + HelixPreCommands: ${{ parameters.HelixPreCommands }} + HelixPostCommands: ${{ parameters.HelixPostCommands }} + WorkItemDirectory: ${{ parameters.WorkItemDirectory }} + WorkItemCommand: ${{ parameters.WorkItemCommand }} + WorkItemTimeout: ${{ parameters.WorkItemTimeout }} + CorrelationPayloadDirectory: ${{ parameters.CorrelationPayloadDirectory }} + XUnitProjects: ${{ parameters.XUnitProjects }} + XUnitWorkItemTimeout: ${{ parameters.XUnitWorkItemTimeout }} + XUnitPublishTargetFramework: ${{ parameters.XUnitPublishTargetFramework }} + XUnitRuntimeTargetFramework: ${{ parameters.XUnitRuntimeTargetFramework }} + XUnitRunnerVersion: ${{ parameters.XUnitRunnerVersion }} + IncludeDotNetCli: ${{ parameters.IncludeDotNetCli }} + DotNetCliPackageType: ${{ parameters.DotNetCliPackageType }} + DotNetCliVersion: ${{ parameters.DotNetCliVersion }} + WaitForWorkItemCompletion: ${{ parameters.WaitForWorkItemCompletion }} + HelixBaseUri: ${{ parameters.HelixBaseUri }} + Creator: ${{ parameters.Creator }} + SYSTEM_ACCESSTOKEN: $(System.AccessToken) + condition: and(${{ parameters.condition }}, ne(variables['Agent.Os'], 'Windows_NT')) + continueOnError: ${{ parameters.continueOnError }} diff --git a/eng/common/templates/steps/source-build.yml b/eng/common/templates/steps/source-build.yml new file mode 100644 index 0000000000000..a97a185a367a9 --- /dev/null +++ b/eng/common/templates/steps/source-build.yml @@ -0,0 +1,114 @@ +parameters: + # This template adds arcade-powered source-build to CI. + + # This is a 'steps' template, and is intended for advanced scenarios where the existing build + # infra has a careful build methodology that must be followed. For example, a repo + # (dotnet/runtime) might choose to clone the GitHub repo only once and store it as a pipeline + # artifact for all subsequent jobs to use, to reduce dependence on a strong network connection to + # GitHub. Using this steps template leaves room for that infra to be included. + + # Defines the platform on which to run the steps. See 'eng/common/templates/job/source-build.yml' + # for details. The entire object is described in the 'job' template for simplicity, even though + # the usage of the properties on this object is split between the 'job' and 'steps' templates. + platform: {} + +steps: +# Build. Keep it self-contained for simple reusability. (No source-build-specific job variables.) +- script: | + set -x + df -h + + # If building on the internal project, the artifact feeds variable may be available (usually only if needed) + # In that case, call the feed setup script to add internal feeds corresponding to public ones. + # In addition, add an msbuild argument to copy the WIP from the repo to the target build location. + # This is because SetupNuGetSources.sh will alter the current NuGet.config file, and we need to preserve those + # changes. + internalRestoreArgs= + if [ '$(dn-bot-dnceng-artifact-feeds-rw)' != '$''(dn-bot-dnceng-artifact-feeds-rw)' ]; then + # Temporarily work around https://github.com/dotnet/arcade/issues/7709 + chmod +x $(Build.SourcesDirectory)/eng/common/SetupNugetSources.sh + $(Build.SourcesDirectory)/eng/common/SetupNugetSources.sh $(Build.SourcesDirectory)/NuGet.config $(dn-bot-dnceng-artifact-feeds-rw) + internalRestoreArgs='/p:CopyWipIntoInnerSourceBuildRepo=true' + + # The 'Copy WIP' feature of source build uses git stash to apply changes from the original repo. + # This only works if there is a username/email configured, which won't be the case in most CI runs. + git config --get user.email + if [ $? -ne 0 ]; then + git config user.email dn-bot@microsoft.com + git config user.name dn-bot + fi + fi + + # If building on the internal project, the internal storage variable may be available (usually only if needed) + # In that case, add variables to allow the download of internal runtimes if the specified versions are not found + # in the default public locations. + internalRuntimeDownloadArgs= + if [ '$(dotnetbuilds-internal-container-read-token-base64)' != '$''(dotnetbuilds-internal-container-read-token-base64)' ]; then + internalRuntimeDownloadArgs='/p:DotNetRuntimeSourceFeed=https://dotnetbuilds.blob.core.windows.net/internal /p:DotNetRuntimeSourceFeedKey=$(dotnetbuilds-internal-container-read-token-base64) --runtimesourcefeed https://dotnetbuilds.blob.core.windows.net/internal --runtimesourcefeedkey $(dotnetbuilds-internal-container-read-token-base64)' + fi + + buildConfig=Release + # Check if AzDO substitutes in a build config from a variable, and use it if so. + if [ '$(_BuildConfig)' != '$''(_BuildConfig)' ]; then + buildConfig='$(_BuildConfig)' + fi + + officialBuildArgs= + if [ '${{ and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}' = 'True' ]; then + officialBuildArgs='/p:DotNetPublishUsingPipelines=true /p:OfficialBuildId=$(BUILD.BUILDNUMBER)' + fi + + targetRidArgs= + if [ '${{ parameters.platform.targetRID }}' != '' ]; then + targetRidArgs='/p:TargetRid=${{ parameters.platform.targetRID }}' + fi + + runtimeOsArgs= + if [ '${{ parameters.platform.runtimeOS }}' != '' ]; then + runtimeOsArgs='/p:RuntimeOS=${{ parameters.platform.runtimeOS }}' + fi + + publishArgs= + if [ '${{ parameters.platform.skipPublishValidation }}' != 'true' ]; then + publishArgs='--publish' + fi + + assetManifestFileName=SourceBuild_RidSpecific.xml + if [ '${{ parameters.platform.name }}' != '' ]; then + assetManifestFileName=SourceBuild_${{ parameters.platform.name }}.xml + fi + + ${{ coalesce(parameters.platform.buildScript, './build.sh') }} --ci \ + --configuration $buildConfig \ + --restore --build --pack $publishArgs -bl \ + $officialBuildArgs \ + $internalRuntimeDownloadArgs \ + $internalRestoreArgs \ + $targetRidArgs \ + $runtimeOsArgs \ + /p:SourceBuildNonPortable=${{ parameters.platform.nonPortable }} \ + /p:ArcadeBuildFromSource=true \ + /p:AssetManifestFileName=$assetManifestFileName + displayName: Build + +# Upload build logs for diagnosis. +- task: CopyFiles@2 + displayName: Prepare BuildLogs staging directory + inputs: + SourceFolder: '$(Build.SourcesDirectory)' + Contents: | + **/*.log + **/*.binlog + artifacts/source-build/self/prebuilt-report/** + TargetFolder: '$(Build.StagingDirectory)/BuildLogs' + CleanTargetFolder: true + continueOnError: true + condition: succeededOrFailed() + +- task: PublishPipelineArtifact@1 + displayName: Publish BuildLogs + inputs: + targetPath: '$(Build.StagingDirectory)/BuildLogs' + artifactName: BuildLogs_SourceBuild_${{ parameters.platform.name }}_Attempt$(System.JobAttempt) + continueOnError: true + condition: succeededOrFailed() diff --git a/eng/common/templates/steps/telemetry-end.yml b/eng/common/templates/steps/telemetry-end.yml new file mode 100644 index 0000000000000..fadc04ca1b9a3 --- /dev/null +++ b/eng/common/templates/steps/telemetry-end.yml @@ -0,0 +1,102 @@ +parameters: + maxRetries: 5 + retryDelay: 10 # in seconds + +steps: +- bash: | + if [ "$AGENT_JOBSTATUS" = "Succeeded" ] || [ "$AGENT_JOBSTATUS" = "PartiallySucceeded" ]; then + errorCount=0 + else + errorCount=1 + fi + warningCount=0 + + curlStatus=1 + retryCount=0 + # retry loop to harden against spotty telemetry connections + # we don't retry successes and 4xx client errors + until [[ $curlStatus -eq 0 || ( $curlStatus -ge 400 && $curlStatus -le 499 ) || $retryCount -ge $MaxRetries ]] + do + if [ $retryCount -gt 0 ]; then + echo "Failed to send telemetry to Helix; waiting $RetryDelay seconds before retrying..." + sleep $RetryDelay + fi + + # create a temporary file for curl output + res=`mktemp` + + curlResult=` + curl --verbose --output $res --write-out "%{http_code}"\ + -H 'Content-Type: application/json' \ + -H "X-Helix-Job-Token: $Helix_JobToken" \ + -H 'Content-Length: 0' \ + -X POST -G "https://helix.dot.net/api/2018-03-14/telemetry/job/build/$Helix_WorkItemId/finish" \ + --data-urlencode "errorCount=$errorCount" \ + --data-urlencode "warningCount=$warningCount"` + curlStatus=$? + + if [ $curlStatus -eq 0 ]; then + if [ $curlResult -gt 299 ] || [ $curlResult -lt 200 ]; then + curlStatus=$curlResult + fi + fi + + let retryCount++ + done + + if [ $curlStatus -ne 0 ]; then + echo "Failed to Send Build Finish information after $retryCount retries" + vstsLogOutput="vso[task.logissue type=error;sourcepath=templates/steps/telemetry-end.yml;code=1;]Failed to Send Build Finish information: $curlStatus" + echo "##$vstsLogOutput" + exit 1 + fi + displayName: Send Unix Build End Telemetry + env: + # defined via VSTS variables in start-job.sh + Helix_JobToken: $(Helix_JobToken) + Helix_WorkItemId: $(Helix_WorkItemId) + MaxRetries: ${{ parameters.maxRetries }} + RetryDelay: ${{ parameters.retryDelay }} + condition: and(always(), ne(variables['Agent.Os'], 'Windows_NT')) +- powershell: | + if (($env:Agent_JobStatus -eq 'Succeeded') -or ($env:Agent_JobStatus -eq 'PartiallySucceeded')) { + $ErrorCount = 0 + } else { + $ErrorCount = 1 + } + $WarningCount = 0 + + # Basic retry loop to harden against server flakiness + $retryCount = 0 + while ($retryCount -lt $env:MaxRetries) { + try { + Invoke-RestMethod -Uri "https://helix.dot.net/api/2018-03-14/telemetry/job/build/$env:Helix_WorkItemId/finish?errorCount=$ErrorCount&warningCount=$WarningCount" -Method Post -ContentType "application/json" -Body "" ` + -Headers @{ 'X-Helix-Job-Token'=$env:Helix_JobToken } + break + } + catch { + $statusCode = $_.Exception.Response.StatusCode.value__ + if ($statusCode -ge 400 -and $statusCode -le 499) { + Write-Host "##vso[task.logissue]error Failed to send telemetry to Helix (status code $statusCode); not retrying (4xx client error)" + Write-Host "##vso[task.logissue]error ", $_.Exception.GetType().FullName, $_.Exception.Message + exit 1 + } + Write-Host "Failed to send telemetry to Helix (status code $statusCode); waiting $env:RetryDelay seconds before retrying..." + $retryCount++ + sleep $env:RetryDelay + continue + } + } + + if ($retryCount -ge $env:MaxRetries) { + Write-Host "##vso[task.logissue]error Failed to send telemetry to Helix after $retryCount retries." + exit 1 + } + displayName: Send Windows Build End Telemetry + env: + # defined via VSTS variables in start-job.ps1 + Helix_JobToken: $(Helix_JobToken) + Helix_WorkItemId: $(Helix_WorkItemId) + MaxRetries: ${{ parameters.maxRetries }} + RetryDelay: ${{ parameters.retryDelay }} + condition: and(always(),eq(variables['Agent.Os'], 'Windows_NT')) diff --git a/eng/common/templates/steps/telemetry-start.yml b/eng/common/templates/steps/telemetry-start.yml new file mode 100644 index 0000000000000..32c01ef0b553b --- /dev/null +++ b/eng/common/templates/steps/telemetry-start.yml @@ -0,0 +1,241 @@ +parameters: + helixSource: 'undefined_defaulted_in_telemetry.yml' + helixType: 'undefined_defaulted_in_telemetry.yml' + buildConfig: '' + runAsPublic: false + maxRetries: 5 + retryDelay: 10 # in seconds + +steps: +- ${{ if and(eq(parameters.runAsPublic, 'false'), not(eq(variables['System.TeamProject'], 'public'))) }}: + - task: AzureKeyVault@1 + inputs: + azureSubscription: 'HelixProd_KeyVault' + KeyVaultName: HelixProdKV + SecretsFilter: 'HelixApiAccessToken' + condition: always() +- bash: | + # create a temporary file + jobInfo=`mktemp` + + # write job info content to temporary file + cat > $jobInfo < powershell invocations +# as dot sourcing isn't possible. +function InitializeDotNetCli([bool]$install, [bool]$createSdkLocationFile) { + if (Test-Path variable:global:_DotNetInstallDir) { + return $global:_DotNetInstallDir + } + + # Don't resolve runtime, shared framework, or SDK from other locations to ensure build determinism + $env:DOTNET_MULTILEVEL_LOOKUP=0 + + # Disable first run since we do not need all ASP.NET packages restored. + $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 + + # Disable telemetry on CI. + if ($ci) { + $env:DOTNET_CLI_TELEMETRY_OPTOUT=1 + } + + # Source Build uses DotNetCoreSdkDir variable + if ($env:DotNetCoreSdkDir -ne $null) { + $env:DOTNET_INSTALL_DIR = $env:DotNetCoreSdkDir + } + + # Find the first path on %PATH% that contains the dotnet.exe + if ($useInstalledDotNetCli -and (-not $globalJsonHasRuntimes) -and ($env:DOTNET_INSTALL_DIR -eq $null)) { + $dotnetExecutable = GetExecutableFileName 'dotnet' + $dotnetCmd = Get-Command $dotnetExecutable -ErrorAction SilentlyContinue + + if ($dotnetCmd -ne $null) { + $env:DOTNET_INSTALL_DIR = Split-Path $dotnetCmd.Path -Parent + } + } + + $dotnetSdkVersion = $GlobalJson.tools.dotnet + + # Use dotnet installation specified in DOTNET_INSTALL_DIR if it contains the required SDK version, + # otherwise install the dotnet CLI and SDK to repo local .dotnet directory to avoid potential permission issues. + if ((-not $globalJsonHasRuntimes) -and (-not [string]::IsNullOrEmpty($env:DOTNET_INSTALL_DIR)) -and (Test-Path(Join-Path $env:DOTNET_INSTALL_DIR "sdk\$dotnetSdkVersion"))) { + $dotnetRoot = $env:DOTNET_INSTALL_DIR + } else { + $dotnetRoot = Join-Path $RepoRoot '.dotnet' + + if (-not (Test-Path(Join-Path $dotnetRoot "sdk\$dotnetSdkVersion"))) { + if ($install) { + InstallDotNetSdk $dotnetRoot $dotnetSdkVersion + } else { + Write-PipelineTelemetryError -Category 'InitializeToolset' -Message "Unable to find dotnet with SDK version '$dotnetSdkVersion'" + ExitWithExitCode 1 + } + } + + $env:DOTNET_INSTALL_DIR = $dotnetRoot + } + + # Creates a temporary file under the toolset dir. + # The following code block is protecting against concurrent access so that this function can + # be called in parallel. + if ($createSdkLocationFile) { + do { + $sdkCacheFileTemp = Join-Path $ToolsetDir $([System.IO.Path]::GetRandomFileName()) + } + until (!(Test-Path $sdkCacheFileTemp)) + Set-Content -Path $sdkCacheFileTemp -Value $dotnetRoot + + try { + Move-Item -Force $sdkCacheFileTemp (Join-Path $ToolsetDir 'sdk.txt') + } catch { + # Somebody beat us + Remove-Item -Path $sdkCacheFileTemp + } + } + + # Add dotnet to PATH. This prevents any bare invocation of dotnet in custom + # build steps from using anything other than what we've downloaded. + # It also ensures that VS msbuild will use the downloaded sdk targets. + $env:PATH = "$dotnetRoot;$env:PATH" + + # Make Sure that our bootstrapped dotnet cli is available in future steps of the Azure Pipelines build + Write-PipelinePrependPath -Path $dotnetRoot + + Write-PipelineSetVariable -Name 'DOTNET_MULTILEVEL_LOOKUP' -Value '0' + Write-PipelineSetVariable -Name 'DOTNET_SKIP_FIRST_TIME_EXPERIENCE' -Value '1' + + return $global:_DotNetInstallDir = $dotnetRoot +} + +function Retry($downloadBlock, $maxRetries = 5) { + $retries = 1 + + while($true) { + try { + & $downloadBlock + break + } + catch { + Write-PipelineTelemetryError -Category 'InitializeToolset' -Message $_ + } + + if (++$retries -le $maxRetries) { + $delayInSeconds = [math]::Pow(2, $retries) - 1 # Exponential backoff + Write-Host "Retrying. Waiting for $delayInSeconds seconds before next attempt ($retries of $maxRetries)." + Start-Sleep -Seconds $delayInSeconds + } + else { + Write-PipelineTelemetryError -Category 'InitializeToolset' -Message "Unable to download file in $maxRetries attempts." + break + } + + } +} + +function GetDotNetInstallScript([string] $dotnetRoot) { + $installScript = Join-Path $dotnetRoot 'dotnet-install.ps1' + if (!(Test-Path $installScript)) { + Create-Directory $dotnetRoot + $ProgressPreference = 'SilentlyContinue' # Don't display the console progress UI - it's a huge perf hit + $uri = "https://dotnet.microsoft.com/download/dotnet/scripts/$dotnetInstallScriptVersion/dotnet-install.ps1" + + Retry({ + Write-Host "GET $uri" + Invoke-WebRequest $uri -OutFile $installScript + }) + } + + return $installScript +} + +function InstallDotNetSdk([string] $dotnetRoot, [string] $version, [string] $architecture = '', [switch] $noPath) { + InstallDotNet $dotnetRoot $version $architecture '' $false $runtimeSourceFeed $runtimeSourceFeedKey -noPath:$noPath +} + +function InstallDotNet([string] $dotnetRoot, + [string] $version, + [string] $architecture = '', + [string] $runtime = '', + [bool] $skipNonVersionedFiles = $false, + [string] $runtimeSourceFeed = '', + [string] $runtimeSourceFeedKey = '', + [switch] $noPath) { + + $installScript = GetDotNetInstallScript $dotnetRoot + $installParameters = @{ + Version = $version + InstallDir = $dotnetRoot + } + + if ($architecture) { $installParameters.Architecture = $architecture } + if ($runtime) { $installParameters.Runtime = $runtime } + if ($skipNonVersionedFiles) { $installParameters.SkipNonVersionedFiles = $skipNonVersionedFiles } + if ($noPath) { $installParameters.NoPath = $True } + + $variations = @() + $variations += @($installParameters) + + $dotnetBuilds = $installParameters.Clone() + $dotnetbuilds.AzureFeed = "https://dotnetbuilds.azureedge.net/public" + $variations += @($dotnetBuilds) + + if ($runtimeSourceFeed) { + $runtimeSource = $installParameters.Clone() + $runtimeSource.AzureFeed = $runtimeSourceFeed + if ($runtimeSourceFeedKey) { + $decodedBytes = [System.Convert]::FromBase64String($runtimeSourceFeedKey) + $decodedString = [System.Text.Encoding]::UTF8.GetString($decodedBytes) + $runtimeSource.FeedCredential = $decodedString + } + $variations += @($runtimeSource) + } + + $installSuccess = $false + foreach ($variation in $variations) { + if ($variation | Get-Member AzureFeed) { + $location = $variation.AzureFeed + } else { + $location = "public location"; + } + Write-Host "Attempting to install dotnet from $location." + try { + & $installScript @variation + $installSuccess = $true + break + } + catch { + Write-Host "Failed to install dotnet from $location." + } + } + if (-not $installSuccess) { + Write-PipelineTelemetryError -Category 'InitializeToolset' -Message "Failed to install dotnet from any of the specified locations." + ExitWithExitCode 1 + } +} + +# +# Locates Visual Studio MSBuild installation. +# The preference order for MSBuild to use is as follows: +# +# 1. MSBuild from an active VS command prompt +# 2. MSBuild from a compatible VS installation +# 3. MSBuild from the xcopy tool package +# +# Returns full path to msbuild.exe. +# Throws on failure. +# +function InitializeVisualStudioMSBuild([bool]$install, [object]$vsRequirements = $null) { + if (-not (IsWindowsPlatform)) { + throw "Cannot initialize Visual Studio on non-Windows" + } + + if (Test-Path variable:global:_MSBuildExe) { + return $global:_MSBuildExe + } + + # Minimum VS version to require. + $vsMinVersionReqdStr = '16.8' + $vsMinVersionReqd = [Version]::new($vsMinVersionReqdStr) + + # If the version of msbuild is going to be xcopied, + # use this version. Version matches a package here: + # https://dev.azure.com/dnceng/public/_packaging?_a=package&feed=dotnet-eng&package=RoslynTools.MSBuild&protocolType=NuGet&version=17.4.1&view=overview + $defaultXCopyMSBuildVersion = '17.4.1' + + if (!$vsRequirements) { + if (Get-Member -InputObject $GlobalJson.tools -Name 'vs') { + $vsRequirements = $GlobalJson.tools.vs + } + else { + $vsRequirements = New-Object PSObject -Property @{ version = $vsMinVersionReqdStr } + } + } + $vsMinVersionStr = if ($vsRequirements.version) { $vsRequirements.version } else { $vsMinVersionReqdStr } + $vsMinVersion = [Version]::new($vsMinVersionStr) + + # Try msbuild command available in the environment. + if ($env:VSINSTALLDIR -ne $null) { + $msbuildCmd = Get-Command 'msbuild.exe' -ErrorAction SilentlyContinue + if ($msbuildCmd -ne $null) { + # Workaround for https://github.com/dotnet/roslyn/issues/35793 + # Due to this issue $msbuildCmd.Version returns 0.0.0.0 for msbuild.exe 16.2+ + $msbuildVersion = [Version]::new((Get-Item $msbuildCmd.Path).VersionInfo.ProductVersion.Split([char[]]@('-', '+'))[0]) + + if ($msbuildVersion -ge $vsMinVersion) { + return $global:_MSBuildExe = $msbuildCmd.Path + } + + # Report error - the developer environment is initialized with incompatible VS version. + throw "Developer Command Prompt for VS $($env:VisualStudioVersion) is not recent enough. Please upgrade to $vsMinVersionStr or build from a plain CMD window" + } + } + + # Locate Visual Studio installation or download x-copy msbuild. + $vsInfo = LocateVisualStudio $vsRequirements + if ($vsInfo -ne $null) { + $vsInstallDir = $vsInfo.installationPath + $vsMajorVersion = $vsInfo.installationVersion.Split('.')[0] + + InitializeVisualStudioEnvironmentVariables $vsInstallDir $vsMajorVersion + } else { + + if (Get-Member -InputObject $GlobalJson.tools -Name 'xcopy-msbuild') { + $xcopyMSBuildVersion = $GlobalJson.tools.'xcopy-msbuild' + $vsMajorVersion = $xcopyMSBuildVersion.Split('.')[0] + } else { + #if vs version provided in global.json is incompatible (too low) then use the default version for xcopy msbuild download + if($vsMinVersion -lt $vsMinVersionReqd){ + Write-Host "Using xcopy-msbuild version of $defaultXCopyMSBuildVersion since VS version $vsMinVersionStr provided in global.json is not compatible" + $xcopyMSBuildVersion = $defaultXCopyMSBuildVersion + $vsMajorVersion = $xcopyMSBuildVersion.Split('.')[0] + } + else{ + # If the VS version IS compatible, look for an xcopy msbuild package + # with a version matching VS. + # Note: If this version does not exist, then an explicit version of xcopy msbuild + # can be specified in global.json. This will be required for pre-release versions of msbuild. + $vsMajorVersion = $vsMinVersion.Major + $vsMinorVersion = $vsMinVersion.Minor + $xcopyMSBuildVersion = "$vsMajorVersion.$vsMinorVersion.0" + } + } + + $vsInstallDir = $null + if ($xcopyMSBuildVersion.Trim() -ine "none") { + $vsInstallDir = InitializeXCopyMSBuild $xcopyMSBuildVersion $install + if ($vsInstallDir -eq $null) { + throw "Could not xcopy msbuild. Please check that package 'RoslynTools.MSBuild @ $xcopyMSBuildVersion' exists on feed 'dotnet-eng'." + } + } + if ($vsInstallDir -eq $null) { + throw 'Unable to find Visual Studio that has required version and components installed' + } + } + + $msbuildVersionDir = if ([int]$vsMajorVersion -lt 16) { "$vsMajorVersion.0" } else { "Current" } + + $local:BinFolder = Join-Path $vsInstallDir "MSBuild\$msbuildVersionDir\Bin" + $local:Prefer64bit = if (Get-Member -InputObject $vsRequirements -Name 'Prefer64bit') { $vsRequirements.Prefer64bit } else { $false } + if ($local:Prefer64bit -and (Test-Path(Join-Path $local:BinFolder "amd64"))) { + $global:_MSBuildExe = Join-Path $local:BinFolder "amd64\msbuild.exe" + } else { + $global:_MSBuildExe = Join-Path $local:BinFolder "msbuild.exe" + } + + return $global:_MSBuildExe +} + +function InitializeVisualStudioEnvironmentVariables([string] $vsInstallDir, [string] $vsMajorVersion) { + $env:VSINSTALLDIR = $vsInstallDir + Set-Item "env:VS$($vsMajorVersion)0COMNTOOLS" (Join-Path $vsInstallDir "Common7\Tools\") + + $vsSdkInstallDir = Join-Path $vsInstallDir "VSSDK\" + if (Test-Path $vsSdkInstallDir) { + Set-Item "env:VSSDK$($vsMajorVersion)0Install" $vsSdkInstallDir + $env:VSSDKInstall = $vsSdkInstallDir + } +} + +function InstallXCopyMSBuild([string]$packageVersion) { + return InitializeXCopyMSBuild $packageVersion -install $true +} + +function InitializeXCopyMSBuild([string]$packageVersion, [bool]$install) { + $packageName = 'RoslynTools.MSBuild' + $packageDir = Join-Path $ToolsDir "msbuild\$packageVersion" + $packagePath = Join-Path $packageDir "$packageName.$packageVersion.nupkg" + + if (!(Test-Path $packageDir)) { + if (!$install) { + return $null + } + + Create-Directory $packageDir + + Write-Host "Downloading $packageName $packageVersion" + $ProgressPreference = 'SilentlyContinue' # Don't display the console progress UI - it's a huge perf hit + Retry({ + Invoke-WebRequest "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/flat2/$packageName/$packageVersion/$packageName.$packageVersion.nupkg" -OutFile $packagePath + }) + + Unzip $packagePath $packageDir + } + + return Join-Path $packageDir 'tools' +} + +# +# Locates Visual Studio instance that meets the minimal requirements specified by tools.vs object in global.json. +# +# The following properties of tools.vs are recognized: +# "version": "{major}.{minor}" +# Two part minimal VS version, e.g. "15.9", "16.0", etc. +# "components": ["componentId1", "componentId2", ...] +# Array of ids of workload components that must be available in the VS instance. +# See e.g. https://docs.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-enterprise?view=vs-2017 +# +# Returns JSON describing the located VS instance (same format as returned by vswhere), +# or $null if no instance meeting the requirements is found on the machine. +# +function LocateVisualStudio([object]$vsRequirements = $null){ + if (-not (IsWindowsPlatform)) { + throw "Cannot run vswhere on non-Windows platforms." + } + + if (Get-Member -InputObject $GlobalJson.tools -Name 'vswhere') { + $vswhereVersion = $GlobalJson.tools.vswhere + } else { + $vswhereVersion = '2.5.2' + } + + $vsWhereDir = Join-Path $ToolsDir "vswhere\$vswhereVersion" + $vsWhereExe = Join-Path $vsWhereDir 'vswhere.exe' + + if (!(Test-Path $vsWhereExe)) { + Create-Directory $vsWhereDir + Write-Host 'Downloading vswhere' + Retry({ + Invoke-WebRequest "https://netcorenativeassets.blob.core.windows.net/resource-packages/external/windows/vswhere/$vswhereVersion/vswhere.exe" -OutFile $vswhereExe + }) + } + + if (!$vsRequirements) { $vsRequirements = $GlobalJson.tools.vs } + $args = @('-latest', '-format', 'json', '-requires', 'Microsoft.Component.MSBuild', '-products', '*') + + if (!$excludePrereleaseVS) { + $args += '-prerelease' + } + + if (Get-Member -InputObject $vsRequirements -Name 'version') { + $args += '-version' + $args += $vsRequirements.version + } + + if (Get-Member -InputObject $vsRequirements -Name 'components') { + foreach ($component in $vsRequirements.components) { + $args += '-requires' + $args += $component + } + } + + $vsInfo =& $vsWhereExe $args | ConvertFrom-Json + + if ($lastExitCode -ne 0) { + return $null + } + + # use first matching instance + return $vsInfo[0] +} + +function InitializeBuildTool() { + if (Test-Path variable:global:_BuildTool) { + # If the requested msbuild parameters do not match, clear the cached variables. + if($global:_BuildTool.Contains('ExcludePrereleaseVS') -and $global:_BuildTool.ExcludePrereleaseVS -ne $excludePrereleaseVS) { + Remove-Item variable:global:_BuildTool + Remove-Item variable:global:_MSBuildExe + } else { + return $global:_BuildTool + } + } + + if (-not $msbuildEngine) { + $msbuildEngine = GetDefaultMSBuildEngine + } + + # Initialize dotnet cli if listed in 'tools' + $dotnetRoot = $null + if (Get-Member -InputObject $GlobalJson.tools -Name 'dotnet') { + $dotnetRoot = InitializeDotNetCli -install:$restore + } + + if ($msbuildEngine -eq 'dotnet') { + if (!$dotnetRoot) { + Write-PipelineTelemetryError -Category 'InitializeToolset' -Message "/global.json must specify 'tools.dotnet'." + ExitWithExitCode 1 + } + $dotnetPath = Join-Path $dotnetRoot (GetExecutableFileName 'dotnet') + $buildTool = @{ Path = $dotnetPath; Command = 'msbuild'; Tool = 'dotnet'; Framework = 'net8.0' } + } elseif ($msbuildEngine -eq "vs") { + try { + $msbuildPath = InitializeVisualStudioMSBuild -install:$restore + } catch { + Write-PipelineTelemetryError -Category 'InitializeToolset' -Message $_ + ExitWithExitCode 1 + } + + $buildTool = @{ Path = $msbuildPath; Command = ""; Tool = "vs"; Framework = "net472"; ExcludePrereleaseVS = $excludePrereleaseVS } + } else { + Write-PipelineTelemetryError -Category 'InitializeToolset' -Message "Unexpected value of -msbuildEngine: '$msbuildEngine'." + ExitWithExitCode 1 + } + + return $global:_BuildTool = $buildTool +} + +function GetDefaultMSBuildEngine() { + # Presence of tools.vs indicates the repo needs to build using VS msbuild on Windows. + if (Get-Member -InputObject $GlobalJson.tools -Name 'vs') { + return 'vs' + } + + if (Get-Member -InputObject $GlobalJson.tools -Name 'dotnet') { + return 'dotnet' + } + + Write-PipelineTelemetryError -Category 'InitializeToolset' -Message "-msbuildEngine must be specified, or /global.json must specify 'tools.dotnet' or 'tools.vs'." + ExitWithExitCode 1 +} + +function GetNuGetPackageCachePath() { + if ($env:NUGET_PACKAGES -eq $null) { + # Use local cache on CI to ensure deterministic build. + # Avoid using the http cache as workaround for https://github.com/NuGet/Home/issues/3116 + # use global cache in dev builds to avoid cost of downloading packages. + # For directory normalization, see also: https://github.com/NuGet/Home/issues/7968 + if ($useGlobalNuGetCache) { + $env:NUGET_PACKAGES = Join-Path $env:UserProfile '.nuget\packages\' + } else { + $env:NUGET_PACKAGES = Join-Path $RepoRoot '.packages\' + $env:RESTORENOCACHE = $true + } + } + + return $env:NUGET_PACKAGES +} + +# Returns a full path to an Arcade SDK task project file. +function GetSdkTaskProject([string]$taskName) { + return Join-Path (Split-Path (InitializeToolset) -Parent) "SdkTasks\$taskName.proj" +} + +function InitializeNativeTools() { + if (-Not (Test-Path variable:DisableNativeToolsetInstalls) -And (Get-Member -InputObject $GlobalJson -Name "native-tools")) { + $nativeArgs= @{} + if ($ci) { + $nativeArgs = @{ + InstallDirectory = "$ToolsDir" + } + } + if ($env:NativeToolsOnMachine) { + Write-Host "Variable NativeToolsOnMachine detected, enabling native tool path promotion..." + $nativeArgs += @{ PathPromotion = $true } + } + & "$PSScriptRoot/init-tools-native.ps1" @nativeArgs + } +} + +function InitializeToolset() { + if (Test-Path variable:global:_ToolsetBuildProj) { + return $global:_ToolsetBuildProj + } + + $nugetCache = GetNuGetPackageCachePath + + $toolsetVersion = $GlobalJson.'msbuild-sdks'.'Microsoft.DotNet.Arcade.Sdk' + $toolsetLocationFile = Join-Path $ToolsetDir "$toolsetVersion.txt" + + if (Test-Path $toolsetLocationFile) { + $path = Get-Content $toolsetLocationFile -TotalCount 1 + if (Test-Path $path) { + return $global:_ToolsetBuildProj = $path + } + } + + if (-not $restore) { + Write-PipelineTelemetryError -Category 'InitializeToolset' -Message "Toolset version $toolsetVersion has not been restored." + ExitWithExitCode 1 + } + + $buildTool = InitializeBuildTool + + $proj = Join-Path $ToolsetDir 'restore.proj' + $bl = if ($binaryLog) { '/bl:' + (Join-Path $LogDir 'ToolsetRestore.binlog') } else { '' } + + '' | Set-Content $proj + + MSBuild-Core $proj $bl /t:__WriteToolsetLocation /clp:ErrorsOnly`;NoSummary /p:__ToolsetLocationOutputFile=$toolsetLocationFile + + $path = Get-Content $toolsetLocationFile -Encoding UTF8 -TotalCount 1 + if (!(Test-Path $path)) { + throw "Invalid toolset path: $path" + } + + return $global:_ToolsetBuildProj = $path +} + +function ExitWithExitCode([int] $exitCode) { + if ($ci -and $prepareMachine) { + Stop-Processes + } + exit $exitCode +} + +# Check if $LASTEXITCODE is a nonzero exit code (NZEC). If so, print a Azure Pipeline error for +# diagnostics, then exit the script with the $LASTEXITCODE. +function Exit-IfNZEC([string] $category = "General") { + Write-Host "Exit code $LASTEXITCODE" + if ($LASTEXITCODE -ne 0) { + $message = "Last command failed with exit code $LASTEXITCODE." + Write-PipelineTelemetryError -Force -Category $category -Message $message + ExitWithExitCode $LASTEXITCODE + } +} + +function Stop-Processes() { + Write-Host 'Killing running build processes...' + foreach ($processName in $processesToStopOnExit) { + Get-Process -Name $processName -ErrorAction SilentlyContinue | Stop-Process + } +} + +# +# Executes msbuild (or 'dotnet msbuild') with arguments passed to the function. +# The arguments are automatically quoted. +# Terminates the script if the build fails. +# +function MSBuild() { + if ($pipelinesLog) { + $buildTool = InitializeBuildTool + + if ($ci -and $buildTool.Tool -eq 'dotnet') { + $env:NUGET_PLUGIN_HANDSHAKE_TIMEOUT_IN_SECONDS = 20 + $env:NUGET_PLUGIN_REQUEST_TIMEOUT_IN_SECONDS = 20 + Write-PipelineSetVariable -Name 'NUGET_PLUGIN_HANDSHAKE_TIMEOUT_IN_SECONDS' -Value '20' + Write-PipelineSetVariable -Name 'NUGET_PLUGIN_REQUEST_TIMEOUT_IN_SECONDS' -Value '20' + } + + Enable-Nuget-EnhancedRetry + + $toolsetBuildProject = InitializeToolset + $basePath = Split-Path -parent $toolsetBuildProject + $possiblePaths = @( + # new scripts need to work with old packages, so we need to look for the old names/versions + (Join-Path $basePath (Join-Path $buildTool.Framework 'Microsoft.DotNet.ArcadeLogging.dll')), + (Join-Path $basePath (Join-Path $buildTool.Framework 'Microsoft.DotNet.Arcade.Sdk.dll')), + (Join-Path $basePath (Join-Path netcoreapp2.1 'Microsoft.DotNet.ArcadeLogging.dll')), + (Join-Path $basePath (Join-Path netcoreapp2.1 'Microsoft.DotNet.Arcade.Sdk.dll')) + (Join-Path $basePath (Join-Path netcoreapp3.1 'Microsoft.DotNet.ArcadeLogging.dll')), + (Join-Path $basePath (Join-Path netcoreapp3.1 'Microsoft.DotNet.Arcade.Sdk.dll')) + (Join-Path $basePath (Join-Path net7.0 'Microsoft.DotNet.ArcadeLogging.dll')), + (Join-Path $basePath (Join-Path net7.0 'Microsoft.DotNet.Arcade.Sdk.dll')) + ) + $selectedPath = $null + foreach ($path in $possiblePaths) { + if (Test-Path $path -PathType Leaf) { + $selectedPath = $path + break + } + } + if (-not $selectedPath) { + Write-PipelineTelemetryError -Category 'Build' -Message 'Unable to find arcade sdk logger assembly.' + ExitWithExitCode 1 + } + $args += "/logger:$selectedPath" + } + + MSBuild-Core @args +} + +# +# Executes msbuild (or 'dotnet msbuild') with arguments passed to the function. +# The arguments are automatically quoted. +# Terminates the script if the build fails. +# +function MSBuild-Core() { + if ($ci) { + if (!$binaryLog -and !$excludeCIBinarylog) { + Write-PipelineTelemetryError -Category 'Build' -Message 'Binary log must be enabled in CI build, or explicitly opted-out from with the -excludeCIBinarylog switch.' + ExitWithExitCode 1 + } + + if ($nodeReuse) { + Write-PipelineTelemetryError -Category 'Build' -Message 'Node reuse must be disabled in CI build.' + ExitWithExitCode 1 + } + } + + Enable-Nuget-EnhancedRetry + + $buildTool = InitializeBuildTool + + $cmdArgs = "$($buildTool.Command) /m /nologo /clp:Summary /v:$verbosity /nr:$nodeReuse /p:ContinuousIntegrationBuild=$ci" + + if ($warnAsError) { + $cmdArgs += ' /warnaserror /p:TreatWarningsAsErrors=true' + } + else { + $cmdArgs += ' /p:TreatWarningsAsErrors=false' + } + + foreach ($arg in $args) { + if ($null -ne $arg -and $arg.Trim() -ne "") { + if ($arg.EndsWith('\')) { + $arg = $arg + "\" + } + $cmdArgs += " `"$arg`"" + } + } + + $env:ARCADE_BUILD_TOOL_COMMAND = "$($buildTool.Path) $cmdArgs" + + $exitCode = Exec-Process $buildTool.Path $cmdArgs + + if ($exitCode -ne 0) { + # We should not Write-PipelineTaskError here because that message shows up in the build summary + # The build already logged an error, that's the reason it failed. Producing an error here only adds noise. + Write-Host "Build failed with exit code $exitCode. Check errors above." -ForegroundColor Red + + $buildLog = GetMSBuildBinaryLogCommandLineArgument $args + if ($null -ne $buildLog) { + Write-Host "See log: $buildLog" -ForegroundColor DarkGray + } + + # When running on Azure Pipelines, override the returned exit code to avoid double logging. + if ($ci -and $env:SYSTEM_TEAMPROJECT -ne $null) { + Write-PipelineSetResult -Result "Failed" -Message "msbuild execution failed." + # Exiting with an exit code causes the azure pipelines task to log yet another "noise" error + # The above Write-PipelineSetResult will cause the task to be marked as failure without adding yet another error + ExitWithExitCode 0 + } else { + ExitWithExitCode $exitCode + } + } +} + +function GetMSBuildBinaryLogCommandLineArgument($arguments) { + foreach ($argument in $arguments) { + if ($argument -ne $null) { + $arg = $argument.Trim() + if ($arg.StartsWith('/bl:', "OrdinalIgnoreCase")) { + return $arg.Substring('/bl:'.Length) + } + + if ($arg.StartsWith('/binaryLogger:', 'OrdinalIgnoreCase')) { + return $arg.Substring('/binaryLogger:'.Length) + } + } + } + + return $null +} + +function GetExecutableFileName($baseName) { + if (IsWindowsPlatform) { + return "$baseName.exe" + } + else { + return $baseName + } +} + +function IsWindowsPlatform() { + return [environment]::OSVersion.Platform -eq [PlatformID]::Win32NT +} + +function Get-Darc($version) { + $darcPath = "$TempDir\darc\$(New-Guid)" + if ($version -ne $null) { + & $PSScriptRoot\darc-init.ps1 -toolpath $darcPath -darcVersion $version | Out-Host + } else { + & $PSScriptRoot\darc-init.ps1 -toolpath $darcPath | Out-Host + } + return "$darcPath\darc.exe" +} + +. $PSScriptRoot\pipeline-logging-functions.ps1 + +$RepoRoot = Resolve-Path (Join-Path $PSScriptRoot '..\..\') +$EngRoot = Resolve-Path (Join-Path $PSScriptRoot '..') +$ArtifactsDir = Join-Path $RepoRoot 'artifacts' +$ToolsetDir = Join-Path $ArtifactsDir 'toolset' +$ToolsDir = Join-Path $RepoRoot '.tools' +$LogDir = Join-Path (Join-Path $ArtifactsDir 'log') $configuration +$TempDir = Join-Path (Join-Path $ArtifactsDir 'tmp') $configuration +$GlobalJson = Get-Content -Raw -Path (Join-Path $RepoRoot 'global.json') | ConvertFrom-Json +# true if global.json contains a "runtimes" section +$globalJsonHasRuntimes = if ($GlobalJson.tools.PSObject.Properties.Name -Match 'runtimes') { $true } else { $false } + +Create-Directory $ToolsetDir +Create-Directory $TempDir +Create-Directory $LogDir + +Write-PipelineSetVariable -Name 'Artifacts' -Value $ArtifactsDir +Write-PipelineSetVariable -Name 'Artifacts.Toolset' -Value $ToolsetDir +Write-PipelineSetVariable -Name 'Artifacts.Log' -Value $LogDir +Write-PipelineSetVariable -Name 'TEMP' -Value $TempDir +Write-PipelineSetVariable -Name 'TMP' -Value $TempDir + +# Import custom tools configuration, if present in the repo. +# Note: Import in global scope so that the script set top-level variables without qualification. +if (!$disableConfigureToolsetImport) { + $configureToolsetScript = Join-Path $EngRoot 'configure-toolset.ps1' + if (Test-Path $configureToolsetScript) { + . $configureToolsetScript + if ((Test-Path variable:failOnConfigureToolsetError) -And $failOnConfigureToolsetError) { + if ((Test-Path variable:LastExitCode) -And ($LastExitCode -ne 0)) { + Write-PipelineTelemetryError -Category 'Build' -Message 'configure-toolset.ps1 returned a non-zero exit code' + ExitWithExitCode $LastExitCode + } + } + } +} + +# +# If $ci flag is set, turn on (and log that we did) special environment variables for improved Nuget client retry logic. +# +function Enable-Nuget-EnhancedRetry() { + if ($ci) { + Write-Host "Setting NUGET enhanced retry environment variables" + $env:NUGET_ENABLE_EXPERIMENTAL_HTTP_RETRY = 'true' + $env:NUGET_EXPERIMENTAL_MAX_NETWORK_TRY_COUNT = 6 + $env:NUGET_EXPERIMENTAL_NETWORK_RETRY_DELAY_MILLISECONDS = 1000 + Write-PipelineSetVariable -Name 'NUGET_ENABLE_EXPERIMENTAL_HTTP_RETRY' -Value 'true' + Write-PipelineSetVariable -Name 'NUGET_EXPERIMENTAL_MAX_NETWORK_TRY_COUNT' -Value '6' + Write-PipelineSetVariable -Name 'NUGET_EXPERIMENTAL_NETWORK_RETRY_DELAY_MILLISECONDS' -Value '1000' + } +} diff --git a/eng/common/tools.sh b/eng/common/tools.sh new file mode 100755 index 0000000000000..cf9fb1ea2d32b --- /dev/null +++ b/eng/common/tools.sh @@ -0,0 +1,558 @@ +#!/usr/bin/env bash + +# Initialize variables if they aren't already defined. + +# CI mode - set to true on CI server for PR validation build or official build. +ci=${ci:-false} + +# Set to true to use the pipelines logger which will enable Azure logging output. +# https://github.com/Microsoft/azure-pipelines-tasks/blob/master/docs/authoring/commands.md +# This flag is meant as a temporary opt-opt for the feature while validate it across +# our consumers. It will be deleted in the future. +if [[ "$ci" == true ]]; then + pipelines_log=${pipelines_log:-true} +else + pipelines_log=${pipelines_log:-false} +fi + +# Build configuration. Common values include 'Debug' and 'Release', but the repository may use other names. +configuration=${configuration:-'Debug'} + +# Set to true to opt out of outputting binary log while running in CI +exclude_ci_binary_log=${exclude_ci_binary_log:-false} + +if [[ "$ci" == true && "$exclude_ci_binary_log" == false ]]; then + binary_log_default=true +else + binary_log_default=false +fi + +# Set to true to output binary log from msbuild. Note that emitting binary log slows down the build. +binary_log=${binary_log:-$binary_log_default} + +# Turns on machine preparation/clean up code that changes the machine state (e.g. kills build processes). +prepare_machine=${prepare_machine:-false} + +# True to restore toolsets and dependencies. +restore=${restore:-true} + +# Adjusts msbuild verbosity level. +verbosity=${verbosity:-'minimal'} + +# Set to true to reuse msbuild nodes. Recommended to not reuse on CI. +if [[ "$ci" == true ]]; then + node_reuse=${node_reuse:-false} +else + node_reuse=${node_reuse:-true} +fi + +# Configures warning treatment in msbuild. +warn_as_error=${warn_as_error:-true} + +# True to attempt using .NET Core already that meets requirements specified in global.json +# installed on the machine instead of downloading one. +use_installed_dotnet_cli=${use_installed_dotnet_cli:-true} + +# Enable repos to use a particular version of the on-line dotnet-install scripts. +# default URL: https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.sh +dotnetInstallScriptVersion=${dotnetInstallScriptVersion:-'v1'} + +# True to use global NuGet cache instead of restoring packages to repository-local directory. +if [[ "$ci" == true ]]; then + use_global_nuget_cache=${use_global_nuget_cache:-false} +else + use_global_nuget_cache=${use_global_nuget_cache:-true} +fi + +# Used when restoring .NET SDK from alternative feeds +runtime_source_feed=${runtime_source_feed:-''} +runtime_source_feed_key=${runtime_source_feed_key:-''} + +# Resolve any symlinks in the given path. +function ResolvePath { + local path=$1 + + while [[ -h $path ]]; do + local dir="$( cd -P "$( dirname "$path" )" && pwd )" + path="$(readlink "$path")" + + # if $path was a relative symlink, we need to resolve it relative to the path where the + # symlink file was located + [[ $path != /* ]] && path="$dir/$path" + done + + # return value + _ResolvePath="$path" +} + +# ReadVersionFromJson [json key] +function ReadGlobalVersion { + local key=$1 + + if command -v jq &> /dev/null; then + _ReadGlobalVersion="$(jq -r ".[] | select(has(\"$key\")) | .\"$key\"" "$global_json_file")" + elif [[ "$(cat "$global_json_file")" =~ \"$key\"[[:space:]\:]*\"([^\"]+) ]]; then + _ReadGlobalVersion=${BASH_REMATCH[1]} + fi + + if [[ -z "$_ReadGlobalVersion" ]]; then + Write-PipelineTelemetryError -category 'Build' "Error: Cannot find \"$key\" in $global_json_file" + ExitWithExitCode 1 + fi +} + +function InitializeDotNetCli { + if [[ -n "${_InitializeDotNetCli:-}" ]]; then + return + fi + + local install=$1 + + # Don't resolve runtime, shared framework, or SDK from other locations to ensure build determinism + export DOTNET_MULTILEVEL_LOOKUP=0 + + # Disable first run since we want to control all package sources + export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 + + # Disable telemetry on CI + if [[ $ci == true ]]; then + export DOTNET_CLI_TELEMETRY_OPTOUT=1 + fi + + # LTTNG is the logging infrastructure used by Core CLR. Need this variable set + # so it doesn't output warnings to the console. + export LTTNG_HOME="$HOME" + + # Source Build uses DotNetCoreSdkDir variable + if [[ -n "${DotNetCoreSdkDir:-}" ]]; then + export DOTNET_INSTALL_DIR="$DotNetCoreSdkDir" + fi + + # Find the first path on $PATH that contains the dotnet.exe + if [[ "$use_installed_dotnet_cli" == true && $global_json_has_runtimes == false && -z "${DOTNET_INSTALL_DIR:-}" ]]; then + local dotnet_path=`command -v dotnet` + if [[ -n "$dotnet_path" ]]; then + ResolvePath "$dotnet_path" + export DOTNET_INSTALL_DIR=`dirname "$_ResolvePath"` + fi + fi + + ReadGlobalVersion "dotnet" + local dotnet_sdk_version=$_ReadGlobalVersion + local dotnet_root="" + + # Use dotnet installation specified in DOTNET_INSTALL_DIR if it contains the required SDK version, + # otherwise install the dotnet CLI and SDK to repo local .dotnet directory to avoid potential permission issues. + if [[ $global_json_has_runtimes == false && -n "${DOTNET_INSTALL_DIR:-}" && -d "$DOTNET_INSTALL_DIR/sdk/$dotnet_sdk_version" ]]; then + dotnet_root="$DOTNET_INSTALL_DIR" + else + dotnet_root="$repo_root/.dotnet" + + export DOTNET_INSTALL_DIR="$dotnet_root" + + if [[ ! -d "$DOTNET_INSTALL_DIR/sdk/$dotnet_sdk_version" ]]; then + if [[ "$install" == true ]]; then + InstallDotNetSdk "$dotnet_root" "$dotnet_sdk_version" + else + Write-PipelineTelemetryError -category 'InitializeToolset' "Unable to find dotnet with SDK version '$dotnet_sdk_version'" + ExitWithExitCode 1 + fi + fi + fi + + # Add dotnet to PATH. This prevents any bare invocation of dotnet in custom + # build steps from using anything other than what we've downloaded. + Write-PipelinePrependPath -path "$dotnet_root" + + Write-PipelineSetVariable -name "DOTNET_MULTILEVEL_LOOKUP" -value "0" + Write-PipelineSetVariable -name "DOTNET_SKIP_FIRST_TIME_EXPERIENCE" -value "1" + + # return value + _InitializeDotNetCli="$dotnet_root" +} + +function InstallDotNetSdk { + local root=$1 + local version=$2 + local architecture="unset" + if [[ $# -ge 3 ]]; then + architecture=$3 + fi + InstallDotNet "$root" "$version" $architecture 'sdk' 'true' $runtime_source_feed $runtime_source_feed_key +} + +function InstallDotNet { + local root=$1 + local version=$2 + + GetDotNetInstallScript "$root" + local install_script=$_GetDotNetInstallScript + + local installParameters=(--version $version --install-dir "$root") + + if [[ -n "${3:-}" ]] && [ "$3" != 'unset' ]; then + installParameters+=(--architecture $3) + fi + if [[ -n "${4:-}" ]] && [ "$4" != 'sdk' ]; then + installParameters+=(--runtime $4) + fi + if [[ "$#" -ge "5" ]] && [[ "$5" != 'false' ]]; then + installParameters+=(--skip-non-versioned-files) + fi + + local variations=() # list of variable names with parameter arrays in them + + local public_location=("${installParameters[@]}") + variations+=(public_location) + + local dotnetbuilds=("${installParameters[@]}" --azure-feed "https://dotnetbuilds.azureedge.net/public") + variations+=(dotnetbuilds) + + if [[ -n "${6:-}" ]]; then + variations+=(private_feed) + local private_feed=("${installParameters[@]}" --azure-feed $6) + if [[ -n "${7:-}" ]]; then + # The 'base64' binary on alpine uses '-d' and doesn't support '--decode' + # '-d'. To work around this, do a simple detection and switch the parameter + # accordingly. + decodeArg="--decode" + if base64 --help 2>&1 | grep -q "BusyBox"; then + decodeArg="-d" + fi + decodedFeedKey=`echo $7 | base64 $decodeArg` + private_feed+=(--feed-credential $decodedFeedKey) + fi + fi + + local installSuccess=0 + for variationName in "${variations[@]}"; do + local name="$variationName[@]" + local variation=("${!name}") + echo "Attempting to install dotnet from $variationName." + bash "$install_script" "${variation[@]}" && installSuccess=1 + if [[ "$installSuccess" -eq 1 ]]; then + break + fi + + echo "Failed to install dotnet from $variationName." + done + + if [[ "$installSuccess" -eq 0 ]]; then + Write-PipelineTelemetryError -category 'InitializeToolset' "Failed to install dotnet SDK from any of the specified locations." + ExitWithExitCode 1 + fi +} + +function with_retries { + local maxRetries=5 + local retries=1 + echo "Trying to run '$@' for maximum of $maxRetries attempts." + while [[ $((retries++)) -le $maxRetries ]]; do + "$@" + + if [[ $? == 0 ]]; then + echo "Ran '$@' successfully." + return 0 + fi + + timeout=$((3**$retries-1)) + echo "Failed to execute '$@'. Waiting $timeout seconds before next attempt ($retries out of $maxRetries)." 1>&2 + sleep $timeout + done + + echo "Failed to execute '$@' for $maxRetries times." 1>&2 + + return 1 +} + +function GetDotNetInstallScript { + local root=$1 + local install_script="$root/dotnet-install.sh" + local install_script_url="https://dotnet.microsoft.com/download/dotnet/scripts/$dotnetInstallScriptVersion/dotnet-install.sh" + + if [[ ! -a "$install_script" ]]; then + mkdir -p "$root" + + echo "Downloading '$install_script_url'" + + # Use curl if available, otherwise use wget + if command -v curl > /dev/null; then + # first, try directly, if this fails we will retry with verbose logging + curl "$install_script_url" -sSL --retry 10 --create-dirs -o "$install_script" || { + if command -v openssl &> /dev/null; then + echo "Curl failed; dumping some information about dotnet.microsoft.com for later investigation" + echo | openssl s_client -showcerts -servername dotnet.microsoft.com -connect dotnet.microsoft.com:443 + fi + echo "Will now retry the same URL with verbose logging." + with_retries curl "$install_script_url" -sSL --verbose --retry 10 --create-dirs -o "$install_script" || { + local exit_code=$? + Write-PipelineTelemetryError -category 'InitializeToolset' "Failed to acquire dotnet install script (exit code '$exit_code')." + ExitWithExitCode $exit_code + } + } + else + with_retries wget -v -O "$install_script" "$install_script_url" || { + local exit_code=$? + Write-PipelineTelemetryError -category 'InitializeToolset' "Failed to acquire dotnet install script (exit code '$exit_code')." + ExitWithExitCode $exit_code + } + fi + fi + # return value + _GetDotNetInstallScript="$install_script" +} + +function InitializeBuildTool { + if [[ -n "${_InitializeBuildTool:-}" ]]; then + return + fi + + InitializeDotNetCli $restore + + # return values + _InitializeBuildTool="$_InitializeDotNetCli/dotnet" + _InitializeBuildToolCommand="msbuild" + _InitializeBuildToolFramework="net8.0" +} + +# Set RestoreNoCache as a workaround for https://github.com/NuGet/Home/issues/3116 +function GetNuGetPackageCachePath { + if [[ -z ${NUGET_PACKAGES:-} ]]; then + if [[ "$use_global_nuget_cache" == true ]]; then + export NUGET_PACKAGES="$HOME/.nuget/packages" + else + export NUGET_PACKAGES="$repo_root/.packages" + export RESTORENOCACHE=true + fi + fi + + # return value + _GetNuGetPackageCachePath=$NUGET_PACKAGES +} + +function InitializeNativeTools() { + if [[ -n "${DisableNativeToolsetInstalls:-}" ]]; then + return + fi + if grep -Fq "native-tools" $global_json_file + then + local nativeArgs="" + if [[ "$ci" == true ]]; then + nativeArgs="--installDirectory $tools_dir" + fi + "$_script_dir/init-tools-native.sh" $nativeArgs + fi +} + +function InitializeToolset { + if [[ -n "${_InitializeToolset:-}" ]]; then + return + fi + + GetNuGetPackageCachePath + + ReadGlobalVersion "Microsoft.DotNet.Arcade.Sdk" + + local toolset_version=$_ReadGlobalVersion + local toolset_location_file="$toolset_dir/$toolset_version.txt" + + if [[ -a "$toolset_location_file" ]]; then + local path=`cat "$toolset_location_file"` + if [[ -a "$path" ]]; then + # return value + _InitializeToolset="$path" + return + fi + fi + + if [[ "$restore" != true ]]; then + Write-PipelineTelemetryError -category 'InitializeToolset' "Toolset version $toolset_version has not been restored." + ExitWithExitCode 2 + fi + + local proj="$toolset_dir/restore.proj" + + local bl="" + if [[ "$binary_log" == true ]]; then + bl="/bl:$log_dir/ToolsetRestore.binlog" + fi + + echo '' > "$proj" + MSBuild-Core "$proj" $bl /t:__WriteToolsetLocation /clp:ErrorsOnly\;NoSummary /p:__ToolsetLocationOutputFile="$toolset_location_file" + + local toolset_build_proj=`cat "$toolset_location_file"` + + if [[ ! -a "$toolset_build_proj" ]]; then + Write-PipelineTelemetryError -category 'Build' "Invalid toolset path: $toolset_build_proj" + ExitWithExitCode 3 + fi + + # return value + _InitializeToolset="$toolset_build_proj" +} + +function ExitWithExitCode { + if [[ "$ci" == true && "$prepare_machine" == true ]]; then + StopProcesses + fi + exit $1 +} + +function StopProcesses { + echo "Killing running build processes..." + pkill -9 "dotnet" || true + pkill -9 "vbcscompiler" || true + return 0 +} + +function MSBuild { + local args=$@ + if [[ "$pipelines_log" == true ]]; then + InitializeBuildTool + InitializeToolset + + if [[ "$ci" == true ]]; then + export NUGET_PLUGIN_HANDSHAKE_TIMEOUT_IN_SECONDS=20 + export NUGET_PLUGIN_REQUEST_TIMEOUT_IN_SECONDS=20 + Write-PipelineSetVariable -name "NUGET_PLUGIN_HANDSHAKE_TIMEOUT_IN_SECONDS" -value "20" + Write-PipelineSetVariable -name "NUGET_PLUGIN_REQUEST_TIMEOUT_IN_SECONDS" -value "20" + fi + + local toolset_dir="${_InitializeToolset%/*}" + # new scripts need to work with old packages, so we need to look for the old names/versions + local selectedPath= + local possiblePaths=() + possiblePaths+=( "$toolset_dir/$_InitializeBuildToolFramework/Microsoft.DotNet.ArcadeLogging.dll" ) + possiblePaths+=( "$toolset_dir/$_InitializeBuildToolFramework/Microsoft.DotNet.Arcade.Sdk.dll" ) + possiblePaths+=( "$toolset_dir/netcoreapp2.1/Microsoft.DotNet.ArcadeLogging.dll" ) + possiblePaths+=( "$toolset_dir/netcoreapp2.1/Microsoft.DotNet.Arcade.Sdk.dll" ) + possiblePaths+=( "$toolset_dir/netcoreapp3.1/Microsoft.DotNet.ArcadeLogging.dll" ) + possiblePaths+=( "$toolset_dir/netcoreapp3.1/Microsoft.DotNet.Arcade.Sdk.dll" ) + possiblePaths+=( "$toolset_dir/net7.0/Microsoft.DotNet.ArcadeLogging.dll" ) + possiblePaths+=( "$toolset_dir/net7.0/Microsoft.DotNet.Arcade.Sdk.dll" ) + for path in "${possiblePaths[@]}"; do + if [[ -f $path ]]; then + selectedPath=$path + break + fi + done + if [[ -z "$selectedPath" ]]; then + Write-PipelineTelemetryError -category 'Build' "Unable to find arcade sdk logger assembly." + ExitWithExitCode 1 + fi + args+=( "-logger:$selectedPath" ) + fi + + MSBuild-Core ${args[@]} +} + +function MSBuild-Core { + if [[ "$ci" == true ]]; then + if [[ "$binary_log" != true && "$exclude_ci_binary_log" != true ]]; then + Write-PipelineTelemetryError -category 'Build' "Binary log must be enabled in CI build, or explicitly opted-out from with the -noBinaryLog switch." + ExitWithExitCode 1 + fi + + if [[ "$node_reuse" == true ]]; then + Write-PipelineTelemetryError -category 'Build' "Node reuse must be disabled in CI build." + ExitWithExitCode 1 + fi + fi + + InitializeBuildTool + + local warnaserror_switch="" + if [[ $warn_as_error == true ]]; then + warnaserror_switch="/warnaserror" + fi + + function RunBuildTool { + export ARCADE_BUILD_TOOL_COMMAND="$_InitializeBuildTool $@" + + "$_InitializeBuildTool" "$@" || { + local exit_code=$? + # We should not Write-PipelineTaskError here because that message shows up in the build summary + # The build already logged an error, that's the reason it failed. Producing an error here only adds noise. + echo "Build failed with exit code $exit_code. Check errors above." + + # When running on Azure Pipelines, override the returned exit code to avoid double logging. + if [[ "$ci" == "true" && -n ${SYSTEM_TEAMPROJECT:-} ]]; then + Write-PipelineSetResult -result "Failed" -message "msbuild execution failed." + # Exiting with an exit code causes the azure pipelines task to log yet another "noise" error + # The above Write-PipelineSetResult will cause the task to be marked as failure without adding yet another error + ExitWithExitCode 0 + else + ExitWithExitCode $exit_code + fi + } + } + + RunBuildTool "$_InitializeBuildToolCommand" /m /nologo /clp:Summary /v:$verbosity /nr:$node_reuse $warnaserror_switch /p:TreatWarningsAsErrors=$warn_as_error /p:ContinuousIntegrationBuild=$ci "$@" +} + +function GetDarc { + darc_path="$temp_dir/darc" + version="$1" + + if [[ -n "$version" ]]; then + version="--darcversion $version" + fi + + "$eng_root/common/darc-init.sh" --toolpath "$darc_path" $version +} + +ResolvePath "${BASH_SOURCE[0]}" +_script_dir=`dirname "$_ResolvePath"` + +. "$_script_dir/pipeline-logging-functions.sh" + +eng_root=`cd -P "$_script_dir/.." && pwd` +repo_root=`cd -P "$_script_dir/../.." && pwd` +repo_root="${repo_root}/" +artifacts_dir="${repo_root}artifacts" +toolset_dir="$artifacts_dir/toolset" +tools_dir="${repo_root}.tools" +log_dir="$artifacts_dir/log/$configuration" +temp_dir="$artifacts_dir/tmp/$configuration" + +global_json_file="${repo_root}global.json" +# determine if global.json contains a "runtimes" entry +global_json_has_runtimes=false +if command -v jq &> /dev/null; then + if jq -e '.tools | has("runtimes")' "$global_json_file" &> /dev/null; then + global_json_has_runtimes=true + fi +elif [[ "$(cat "$global_json_file")" =~ \"runtimes\"[[:space:]\:]*\{ ]]; then + global_json_has_runtimes=true +fi + +# HOME may not be defined in some scenarios, but it is required by NuGet +if [[ -z $HOME ]]; then + export HOME="${repo_root}artifacts/.home/" + mkdir -p "$HOME" +fi + +mkdir -p "$toolset_dir" +mkdir -p "$temp_dir" +mkdir -p "$log_dir" + +Write-PipelineSetVariable -name "Artifacts" -value "$artifacts_dir" +Write-PipelineSetVariable -name "Artifacts.Toolset" -value "$toolset_dir" +Write-PipelineSetVariable -name "Artifacts.Log" -value "$log_dir" +Write-PipelineSetVariable -name "Temp" -value "$temp_dir" +Write-PipelineSetVariable -name "TMP" -value "$temp_dir" + +# Import custom tools configuration, if present in the repo. +if [ -z "${disable_configure_toolset_import:-}" ]; then + configure_toolset_script="$eng_root/configure-toolset.sh" + if [[ -a "$configure_toolset_script" ]]; then + . "$configure_toolset_script" + fi +fi + +# TODO: https://github.com/dotnet/arcade/issues/1468 +# Temporary workaround to avoid breaking change. +# Remove once repos are updated. +if [[ -n "${useInstalledDotNetCli:-}" ]]; then + use_installed_dotnet_cli="$useInstalledDotNetCli" +fi diff --git a/global.json b/global.json new file mode 100644 index 0000000000000..1851f434f22a3 --- /dev/null +++ b/global.json @@ -0,0 +1,10 @@ +{ + "tools": { + "dotnet": "8.0.100-alpha.1.23061.8" + }, + "msbuild-sdks": { + "Microsoft.DotNet.Arcade.Sdk": "8.0.0-beta.23118.1", + "Microsoft.DotNet.Helix.Sdk": "8.0.0-beta.23118.1", + "Microsoft.Build.Traversal": "2.0.34" + } +} diff --git a/libc/utils/buildbot/Dockerfile b/libc/utils/buildbot/Dockerfile deleted file mode 100644 index 8c497be6db0cc..0000000000000 --- a/libc/utils/buildbot/Dockerfile +++ /dev/null @@ -1,36 +0,0 @@ -FROM debian:10 - -# Installing dependencies. -RUN dpkg --add-architecture i386 -RUN apt-get update && apt-get install -y build-essential clang subversion git \ - vim zip libstdc++6:i386 file binutils-dev binutils-gold cmake python-pip \ - ninja-build python3 -RUN python -m pip install buildbot-worker==2.8.4 - -# Temporary dependencies for AOR tests. -RUN apt-get install -y libmpfr-dev libmpc-dev - -# Change linker to gold. -RUN update-alternatives --install "/usr/bin/ld" "ld" "/usr/bin/ld.gold" 20 - -# Create and switch to buildbot user. -RUN useradd buildbot --create-home -USER buildbot - -WORKDIR /home/buildbot - -# Use clang as the compiler. -ENV CC=/usr/bin/clang -ENV CXX=/usr/bin/clang++ - -ENV WORKER_NAME="libc-x86_64-debian" - -# Set up buildbot host and maintainer info. -RUN mkdir -p "${WORKER_NAME}/info/" -RUN bash -c "(uname -a ; \ - gcc --version | head -n1 ; ld --version \ - | head -n1 ; cmake --version | head -n1 ) > ${WORKER_NAME}/info/host" -RUN echo "Paula Toth " > "${WORKER_NAME}/info/admin" - -ADD --chown=buildbot:buildbot run.sh . -ENTRYPOINT ["./run.sh"] diff --git a/libcxx/utils/ci/Dockerfile b/libcxx/utils/ci/Dockerfile deleted file mode 100644 index b271bfbbd0668..0000000000000 --- a/libcxx/utils/ci/Dockerfile +++ /dev/null @@ -1,102 +0,0 @@ -#===----------------------------------------------------------------------===## -# -# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# -#===----------------------------------------------------------------------===## - -# -# This Dockerfile describes the base image used to run the various libc++ -# build bots. By default, the image runs the Buildkite Agent, however one -# can also just start the image with a shell to debug CI failures. -# -# To start a Buildkite Agent, run it as: -# $ docker run --env-file -it $(docker build -q libcxx/utils/ci) -# -# The environment variables in `` should be the ones necessary -# to run a BuildKite agent. -# -# If you're only looking to run the Docker image locally for debugging a -# build bot, see the `run-buildbot-container` script located in this directory. -# -# A pre-built version of this image is maintained on DockerHub as ldionne/libcxx-builder. -# To update the image, rebuild it and push it to ldionne/libcxx-builder (which -# will obviously only work if you have permission to do so). -# -# $ docker build -t ldionne/libcxx-builder libcxx/utils/ci -# $ docker push ldionne/libcxx-builder -# - -FROM ubuntu:focal - -# Make sure apt-get doesn't try to prompt for stuff like our time zone, etc. -ENV DEBIAN_FRONTEND=noninteractive - -# This dummy command is meant to be edited from time to time, which causes the -# CI builders to rebuild their copy of the Docker image. This is not a great -# solution, however without that, the CI builders will keep the same cached -# Docker image forever. -RUN echo 6 - -RUN apt-get update && apt-get install -y bash curl - -# Install various tools used by the build or the test suite -RUN apt-get update && apt-get install -y ninja-build python3 python3-sphinx python3-distutils git gdb - -# Locales for gdb and localization tests -RUN apt-get update && apt-get install -y language-pack-en language-pack-fr \ - language-pack-ru language-pack-zh-hans -# These two are not enabled by default so generate them -RUN printf "fr_CA ISO-8859-1\ncs_CZ ISO-8859-2" >> /etc/locale.gen -RUN mkdir /usr/local/share/i1en/ -RUN printf "fr_CA ISO-8859-1\ncs_CZ ISO-8859-2" >> /usr/local/share/i1en/SUPPORTED -RUN locale-gen - -# Install Clang , and ToT, which are the ones we support. -ENV LLVM_LATEST_VERSION=13 -RUN apt-get update && apt-get install -y lsb-release wget software-properties-common -RUN wget https://apt.llvm.org/llvm.sh -O /tmp/llvm.sh -RUN bash /tmp/llvm.sh $(($LLVM_LATEST_VERSION - 1)) # previous release -RUN bash /tmp/llvm.sh $LLVM_LATEST_VERSION # latest release -RUN bash /tmp/llvm.sh $(($LLVM_LATEST_VERSION + 1)) # current ToT - -# Make the ToT Clang the "default" compiler on the system -RUN ln -fs /usr/bin/clang++-$(($LLVM_LATEST_VERSION + 1)) /usr/bin/c++ && [ -e $(readlink /usr/bin/c++) ] -RUN ln -fs /usr/bin/clang-$(($LLVM_LATEST_VERSION + 1)) /usr/bin/cc && [ -e $(readlink /usr/bin/cc) ] - -# Install clang-format -RUN apt-get install -y clang-format-$LLVM_LATEST_VERSION -RUN ln -s /usr/bin/clang-format-$LLVM_LATEST_VERSION /usr/bin/clang-format && [ -e $(readlink /usr/bin/clang-format) ] -RUN ln -s /usr/bin/git-clang-format-$LLVM_LATEST_VERSION /usr/bin/git-clang-format && [ -e $(readlink /usr/bin/git-clang-format) ] - -# Install clang-tidy -RUN apt-get install -y clang-tidy-$LLVM_LATEST_VERSION -RUN ln -s /usr/bin/clang-tidy-$LLVM_LATEST_VERSION /usr/bin/clang-tidy && [ -e $(readlink /usr/bin/clang-tidy) ] - -# Install the most recent GCC -ENV GCC_LATEST_VERSION=11 -RUN add-apt-repository ppa:ubuntu-toolchain-r/test -RUN apt-get update && apt install -y gcc-$GCC_LATEST_VERSION g++-$GCC_LATEST_VERSION - -# Install a recent CMake -RUN wget https://github.com/Kitware/CMake/releases/download/v3.21.1/cmake-3.21.1-linux-x86_64.sh -O /tmp/install-cmake.sh -RUN bash /tmp/install-cmake.sh --prefix=/usr --exclude-subdir --skip-license -RUN rm /tmp/install-cmake.sh - -# Change the user to a non-root user, since some of the libc++ tests -# (e.g. filesystem) require running as non-root. Also setup passwordless sudo. -RUN apt-get update && apt-get install -y sudo -RUN echo "ALL ALL = (ALL) NOPASSWD: ALL" >> /etc/sudoers -RUN useradd --create-home libcxx-builder -USER libcxx-builder -WORKDIR /home/libcxx-builder - -# Install the Buildkite agent and dependencies. This must be done as non-root -# for the Buildkite agent to be installed in a path where we can find it. -RUN bash -c "$(curl -sL https://raw.githubusercontent.com/buildkite/agent/main/install.sh)" -ENV PATH="${PATH}:/home/libcxx-builder/.buildkite-agent/bin" -RUN echo "tags=\"queue=libcxx-builders,arch=$(uname -m),os=linux\"" >> "/home/libcxx-builder/.buildkite-agent/buildkite-agent.cfg" - -# By default, start the Buildkite agent (this requires a token). -CMD buildkite-agent start diff --git a/lldb/tools/lldb-vscode/.npmrc b/lldb/tools/lldb-vscode/.npmrc new file mode 100644 index 0000000000000..8701ec2998ee7 --- /dev/null +++ b/lldb/tools/lldb-vscode/.npmrc @@ -0,0 +1 @@ +registry=https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public-npm/npm/registry/ diff --git a/llvm.proj b/llvm.proj new file mode 100644 index 0000000000000..264dd8137ff93 --- /dev/null +++ b/llvm.proj @@ -0,0 +1,163 @@ + + + + + + Unix Makefiles + Ninja + <_VCVarsScriptName Condition="'$(BuildOS)' == 'Windows_NT'">vcvars64.bat + <_VCVarsScriptName Condition="'$(BuildOS)' == 'Windows_NT' and '$(TargetArchitecture)' == 'arm64'">vcvarsamd64_arm64.bat + <_VCVarsScriptName Condition="'$(BuildOS)' == 'Windows_NT' and '$(TargetArchitecture)' == 'arm'">vcvarsamd64_arm.bat + <_SetupEnvironment Condition="'$(BuildOS)' == 'Windows_NT'"> + :: VisualStudio includes vswhere.exe that can be used to locate current VisualStudio installation. + set VSWHERE_TOOLS_BIN=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe + set VS_VCINSTALL_DIR= + + :: Try to locate installed VisualStudio VC environment. + if "%VCINSTALLDIR%" == "" if exist "%VSWHERE_TOOLS_BIN%" ( + for /f "tokens=*" %%a in ('"%VSWHERE_TOOLS_BIN%" -latest -prerelease -property installationPath') do ( + set VS_VCINSTALL_DIR=%%a\VC\ + ) + ) + + if NOT "%VCINSTALLDIR%" == "" set VS_VCINSTALL_DIR=%VCINSTALLDIR% + + :: Run VS build environment script. + call "%VS_VCINSTALL_DIR%\Auxiliary\Build\$(_VCVarsScriptName)" + + + <_CMakeConfigureCommand>$(_SetupEnvironment) cmake $(_LLVMSourceDir) -G "$(CMakeGenerator)" @(_LLVMBuildArgs->'%(Identity)',' ') + <_BuildSubset Condition="'$(BuildLLVMTableGenOnly)' == 'true'">llvm-tblgen clang-tblgen + <_BuildSubset Condition="'$(BuildObjWriterOnly)' == 'true'">objwriter llvm-mca llvm-dwarfdump FileCheck + <_BuildCommand Condition="'$(CMakeGenerator)' == 'Unix Makefiles'">$(_SetupEnvironment) make $(_BuildSubset) -j$([System.Environment]::ProcessorCount) + <_BuildCommand Condition="'$(CMakeGenerator)' == 'Ninja'">$(_SetupEnvironment) ninja $(_BuildSubset) + <_CMakeInstallCommand Condition="'$(BuildObjWriterOnly)' == 'true'"> + $(_SetupEnvironment) + + cmake -DCMAKE_INSTALL_DO_STRIP=1 -DCMAKE_INSTALL_PREFIX=$(_LLVMInstallDir) -DCMAKE_INSTALL_COMPONENT=objwriter -P cmake_install.cmake + cmake -DCMAKE_INSTALL_DO_STRIP=1 -DCMAKE_INSTALL_PREFIX=$(_LLVMInstallDir) -DCMAKE_INSTALL_COMPONENT=llvm-mca -P cmake_install.cmake + cmake -DCMAKE_INSTALL_DO_STRIP=1 -DCMAKE_INSTALL_PREFIX=$(_LLVMInstallDir) -DCMAKE_INSTALL_COMPONENT=llvm-dwarfdump -P cmake_install.cmake + cmake -DCMAKE_INSTALL_DO_STRIP=1 -DCMAKE_INSTALL_PREFIX=$(_LLVMInstallDir) -DCMAKE_INSTALL_COMPONENT=FileCheck -P cmake_install.cmake + + <_CMakeInstallCommand Condition="'$(BuildObjWriterOnly)' != 'true'">$(_SetupEnvironment) cmake -DCMAKE_INSTALL_DO_STRIP=1 -DCMAKE_INSTALL_PREFIX=$(_LLVMInstallDir) -P cmake_install.cmake + + + + /opt/rh/devtoolset-7/root + -L$(DevtoolsetRoot)/usr/lib/gcc/x86_64-redhat-linux/7/ + --gcc-toolchain=$(DevtoolsetRoot)/usr/lib/gcc/x86_64-redhat-linux/7/ -I$(DevtoolsetRoot)/usr/include/c++/7/ -I$(DevtoolsetRoot)/usr/include/c++/7/x86_64-redhat-linux/ -B$(DevtoolsetRoot)/usr/lib/gcc/x86_64-redhat-linux/7/ + + + + <_LLVMBuildArgs Condition="'$(TargetArchitecture)' == 'arm64'" Include="-DLLVM_TARGET_ARCH=AARCH64" /> + <_LLVMBuildArgs Condition="'$(TargetArchitecture)' == 'arm'" Include="-DLLVM_TARGET_ARCH=ARM" /> + <_LLVMBuildArgs Condition="'$(TargetArchitecture)' == 'arm64' and '$(BuildOS)' == 'Windows_NT'" Include="-DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-windows-msvc" /> + <_LLVMBuildArgs Condition="'$(TargetArchitecture)' == 'arm' and '$(BuildOS)' == 'Windows_NT'" Include="-DLLVM_DEFAULT_TARGET_TRIPLE=arm-windows-msvc" /> + <_LLVMBuildArgs Condition="'$(ClangTarget)' != '' and '$(BuildOS)' == 'Linux'" Include="-DLLVM_DEFAULT_TARGET_TRIPLE=$(ClangTarget)" /> + <_LLVMBuildArgs Condition="'$(ClangTarget)' != '' and '$(BuildOS)' == 'Linux'" Include="-DCMAKE_OBJCOPY=/usr/bin/$(ClangTarget)-objcopy" /> + <_LLVMBuildArgs Condition="'$(ClangTarget)' != '' and '$(BuildOS)' == 'Linux'" Include="-DCMAKE_STRIP=/usr/bin/$(ClangTarget)-strip" /> + <_LLVMBuildArgs Condition="'$(TargetArchitecture)' == 'arm64' and '$(BuildOS)' == 'OSX'" Include="-DLLVM_DEFAULT_TARGET_TRIPLE=arm64-apple-darwin" /> + <_LLVMBuildArgs Condition="'$(TargetArchitecture)' == 'arm64' and '$(BuildOS)' == 'OSX'" Include="-DCMAKE_OSX_ARCHITECTURES=arm64"/> + + <_LLVMBuildArgs Condition="('$(TargetArchitecture)' == 'arm' or '$(TargetArchitecture)' == 'arm64') and '$(BuildOS)' == 'Windows_NT'" Include="-DCMAKE_SYSTEM_NAME=Windows" /> + <_LLVMBuildArgs Condition="('$(TargetArchitecture)' == 'arm' or '$(TargetArchitecture)' == 'arm64') and '$(BuildOS)' == 'Linux'" Include="-DCMAKE_SYSTEM_NAME=Linux" /> + <_LLVMBuildArgs Condition="'$(LLVMTableGenPath)' != ''" Include='-DLLVM_TABLEGEN="$(LLVMTableGenPath)"' /> + <_LLVMBuildArgs Condition="'$(ClangTableGenPath)' != ''" Include='-DCLANG_TABLEGEN="$(ClangTableGenPath)"' /> + <_LLVMBuildArgs Include="-DCMAKE_BUILD_TYPE=Release" /> + <_LLVMBuildArgs Include='-DLEGAL_COPYRIGHT="\xa9 Microsoft Corporation. All rights reserved."' /> + <_LLVMBuildArgs Include="-DLLVM_BUILD_LLVM_C_DYLIB=OFF" /> + <_LLVMBuildArgs Include="-DLLVM_ENABLE_DIA_SDK=OFF" /> + <_LLVMBuildArgs Include="-DLLVM_INCLUDE_TESTS=OFF" /> + <_LLVMBuildArgs Include='-DLLVM_TARGETS_TO_BUILD="X86%3BAArch64%3BARM"' /> + <_LLVMBuildArgs Include='-DLLVM_BUILD_TESTS=OFF' /> + <_LLVMBuildArgs Include='-DLLVM_BUILD_EXAMPLES=OFF' /> + <_LLVMBuildArgs Include='-DLLVM_INCLUDE_EXAMPLES=OFF' /> + <_LLVMBuildArgs Include='-DLLVM_TOOLS_TO_BUILD="opt%3Bllc%3Bllvm-config%3Bllvm-dis%3Bllvm-mc%3Bllvm-as%3Bobjwriter%3Bllvm-mca%3Bllvm-dwarfdump%3BFileCheck"' /> + <_LLVMBuildArgs Include='-DLLVM_ENABLE_LIBXML2=OFF' /> + <_LLVMBuildArgs Include='-DLLVM_ENABLE_TERMINFO=OFF' /> + <_LLVMBuildArgs Include='-DLLVM_EXTERNALIZE_DEBUGINFO=ON' /> + <_LLVMBuildArgs Include='-DLLVM_EXTERNALIZE_DEBUGINFO_INSTALL=ON' /> + <_LLVMBuildArgs Include='-DLLVM_ENABLE_PDB=ON' /> + <_LLVMBuildArgs Condition="'$(BuildOS)' == 'Linux'" Include='-DLLVM_EXTERNALIZE_DEBUGINFO_EXTENSION=dbg' /> + <_LLVMBuildArgs Condition="'$(BuildOS)' == 'OSX'" Include='-DLLVM_EXTERNALIZE_DEBUGINFO_EXTENSION=dwarf -DLLVM_EXTERNALIZE_DEBUGINFO_FLATTEN=ON' /> + <_LLVMBuildArgs Condition="'$(BuildOS)' == 'Windows_NT' and '$(Configuration)' == 'Release'" Include='-DLLVM_USE_CRT_DEBUG=MT' /> + <_LLVMBuildArgs Condition="'$(BuildOS)' == 'Windows_NT' and '$(Configuration)' == 'Release'" Include='-DLLVM_USE_CRT_RELEASE=MT' /> + <_LLVMBuildArgs Condition="'$(BuildOS)' == 'Windows_NT' and '$(Configuration)' == 'Debug'" Include='-DLLVM_USE_CRT_DEBUG=MTd' /> + <_LLVMBuildArgs Condition="'$(BuildOS)' == 'Windows_NT' and '$(Configuration)' == 'Debug'" Include='-DLLVM_USE_CRT_RELEASE=MTd' /> + <_LLVMBuildArgs Condition="'$(BuildOS)' == 'Windows_NT'" Include='-DLLVM_ENABLE_ZLIB=OFF' /> + + + + <_LLVMBuildArgs Include='-DLLVM_ENABLE_PROJECTS=clang' /> + <_LLVMBuildArgs Include='-DLLVM_BUILD_TOOLS:BOOL=ON' /> + <_LLVMBuildArgs Include='-DLLVM_INSTALL_UTILS:BOOL=ON' /> + <_LLVMBuildArgs Include="-DLLVM_INCLUDE_UTILS:BOOL=ON" /> + <_LLVMBuildArgs Include='-DCLANG_BUILD_TOOLS=OFF' /> + <_LLVMBuildArgs Include='-DCLANG_INCLUDE_TESTS=OFF' /> + <_LLVMBuildArgs Include='-DCLANG_ENABLE_ARCMT=OFF' /> + <_LLVMBuildArgs Include='-DCLANG_ENABLE_STATIC_ANALYZER=OFF' /> + <_LLVMBuildArgs Condition="'$(BuildOS)' == 'Linux'" Include='-DCMAKE_SHARED_LINKER_FLAGS="$(Devtoolset7LinkFlag) -Wl,--build-id"' /> + <_LLVMBuildArgs Condition="'$(BuildOS)' == 'Linux'" Include='-DCMAKE_MODULE_LINKER_FLAGS="$(Devtoolset7LinkFlag) -Wl,--build-id"' /> + + + + <_CrossCFlags Condition="'$(BuildOS)' == 'Linux' and '$(ClangTarget)' != ''">--target=$(ClangTarget) --sysroot=$(ROOTFS_DIR) + <_CrossCFlags Condition="'$(BuildOS)' == 'OSX' and '$(TargetArchitecture)' == 'arm64'">--target=aarch64-apple-darwin + <_ExeLinkerFlags>$(_CrossCFlags) + <_ExeLinkerFlags Condition="'$(BuildOS)' == 'Linux'">-Wl,--build-id $(_ExeLinkerFlags) + <_SharedLinkerFlags>$(_CrossCFlags) + <_SharedLinkerFlags Condition="'$(BuildOS)' == 'Linux'">-Wl,--build-id $(_SharedLinkerFlags) + + + + <_LLVMBuildArgs Include='-DCMAKE_MODULE_LINKER_FLAGS="$(_CrossCFlags)"' /> + <_LLVMBuildArgs Condition="'$(BuildOS)' == 'Linux'" Include="-DCMAKE_C_COMPILER=$(ClangVersion)" /> + <_LLVMBuildArgs Condition="'$(BuildOS)' == 'Linux'" Include="-DCMAKE_CXX_COMPILER=$(ClangPlusVersion)" /> + + + + <_LLVMBuildArgs Include='-DCMAKE_C_FLAGS="-I../llvm/include -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -DNDEBUG -D__NO_CTYPE_INLINE -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS $(_CrossCFlags)"' /> + <_LLVMBuildArgs Include='-DCMAKE_CXX_FLAGS="-I../llvm/include $(Devtoolset7CompileFlag) -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -DNDEBUG -D__NO_CTYPE_INLINE -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS $(_CrossCFlags) "' /> + <_LLVMBuildArgs Include='-DCMAKE_EXE_LINKER_FLAGS="$(Devtoolset7LinkFlag) $(_ExeLinkerFlags)"' /> + <_LLVMBuildArgs Include='-DCMAKE_SHARED_LINKER_FLAGS="$(Devtoolset7LinkFlag) $(_SharedLinkerFlags)"' /> + <_LLVMBuildArgs Condition="'$(BuildOS)' == 'OSX' and '$(TargetArchitecture)' == 'arm64'" Include='-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0' /> + <_LLVMBuildArgs Condition="'$(BuildOS)' == 'OSX' and '$(TargetArchitecture)' == 'x64'" Include='-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13' /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index 00d01f4ddbbd2..af1f39e32618e 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -23,6 +23,8 @@ if(NOT DEFINED LLVM_VERSION_SUFFIX) set(LLVM_VERSION_SUFFIX) endif() +set(MONO_API_VERSION 1400) + if (NOT PACKAGE_VERSION) set(PACKAGE_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}") @@ -608,6 +610,11 @@ if(LLVM_BUILD_EXAMPLES) add_definitions(-DBUILD_EXAMPLES) endif(LLVM_BUILD_EXAMPLES) +option(LLVM_BUILD_EXECUTION_ENGINE + "Build lib/ExecutionEngine." ON) + +set(LLVM_TOOLS_TO_BUILD "all" CACHE STRING "List of tools to build") + option(LLVM_BUILD_TESTS "Build LLVM unit tests. If OFF, just generate build targets." OFF) option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON) @@ -1259,5 +1266,12 @@ if (LLVM_INCLUDE_BENCHMARKS) endif() if (LLVM_INCLUDE_UTILS AND LLVM_INCLUDE_TOOLS) - add_subdirectory(utils/llvm-locstats) + if (LLVM_TOOLS_TO_BUILD STREQUAL "all" OR "llvm-locstats" IN_LIST LLVM_TOOLS_TO_BUILD) + add_subdirectory(utils/llvm-locstats) + endif() endif() + +# emit version we consume in Arcade +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/version.txt.in + ${CMAKE_CURRENT_BINARY_DIR}/version.txt) diff --git a/llvm/build.sh b/llvm/build.sh new file mode 100644 index 0000000000000..610c4de563a27 --- /dev/null +++ b/llvm/build.sh @@ -0,0 +1 @@ +cmake -DCMAKE_BUILD_TYPE=Release "-DLLVM_TARGETS_TO_BUILD=X86;ARM;AArch64;WebAssembly" -DLLVM_BUILD_TESTS=Off -DLLVM_INCLUDE_TESTS=Off "-DLLVM_TOOLS_TO_BUILD=opt;llc;llvm-config;llvm-dis" -G Ninja -DCMAKE_INSTALL_PREFIX=$PWD/../usr64 .. diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake index 37bc98f9e021e..561781223acc5 100644 --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -361,11 +361,13 @@ endfunction(add_windows_version_resource_file) # Optional version string (defaults to PACKAGE_VERSION) # PRODUCT_NAME # Optional product name string (defaults to "LLVM") +# PRODUCT_LEGAL_COPYRIGHT +# Optional product legal copyright string # ) function(set_windows_version_resource_properties name resource_file) cmake_parse_arguments(ARG "" - "VERSION_MAJOR;VERSION_MINOR;VERSION_PATCHLEVEL;VERSION_STRING;PRODUCT_NAME" + "VERSION_MAJOR;VERSION_MINOR;VERSION_PATCHLEVEL;VERSION_STRING;PRODUCT_NAME;PRODUCT_LEGAL_COPYRIGHT" "" ${ARGN}) @@ -389,6 +391,10 @@ function(set_windows_version_resource_properties name resource_file) set(ARG_PRODUCT_NAME "LLVM") endif() + if (NOT DEFINED ARG_PRODUCT_LEGAL_COPYRIGHT) + set(ARG_PRODUCT_LEGAL_COPYRIGHT ${LEGAL_COPYRIGHT}) + endif() + set_property(SOURCE ${resource_file} PROPERTY COMPILE_FLAGS /nologo) set_property(SOURCE ${resource_file} @@ -400,7 +406,8 @@ function(set_windows_version_resource_properties name resource_file) "RC_FILE_VERSION=\"${ARG_VERSION_STRING}\"" "RC_INTERNAL_NAME=\"${name}\"" "RC_PRODUCT_NAME=\"${ARG_PRODUCT_NAME}\"" - "RC_PRODUCT_VERSION=\"${ARG_VERSION_STRING}\"") + "RC_PRODUCT_VERSION=\"${ARG_VERSION_STRING}\"" + "RC_COPYRIGHT=\"${ARG_PRODUCT_LEGAL_COPYRIGHT}\"") endfunction(set_windows_version_resource_properties) # llvm_add_library(name sources... @@ -859,11 +866,15 @@ endmacro(add_llvm_library name) macro(add_llvm_executable name) cmake_parse_arguments(ARG - "DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH;SUPPORT_PLUGINS" + "DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH;SUPPORT_PLUGINS;DEBUGINFO_INSTALL" "ENTITLEMENTS;BUNDLE_PATH" "DEPENDS" ${ARGN}) + if(ARG_DEBUGINFO_INSTALL) + set(DEBUGINFO_INSTALL "DEBUGINFO_INSTALL") + endif() + llvm_process_sources( ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ) list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS}) @@ -945,7 +956,7 @@ macro(add_llvm_executable name) endif( LLVM_COMMON_DEPENDS ) if(NOT ARG_IGNORE_EXTERNALIZE_DEBUGINFO) - llvm_externalize_debuginfo(${name}) + llvm_externalize_debuginfo(${name} ${DEBUGINFO_INSTALL}) endif() if (LLVM_PTHREAD_LIB) # libpthreads overrides some standard library symbols, so main @@ -1245,7 +1256,12 @@ macro(add_llvm_tool name) if( NOT LLVM_BUILD_TOOLS ) set(EXCLUDE_FROM_ALL ON) endif() - add_llvm_executable(${name} ${ARGN}) + + if ( (${name} IN_LIST LLVM_TOOLCHAIN_TOOLS OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS ) + set(DEBUGINFO_INSTALL "DEBUGINFO_INSTALL") + endif() + + add_llvm_executable(${name} ${DEBUGINFO_INSTALL} ${ARGN}) if ( ${name} IN_LIST LLVM_TOOLCHAIN_TOOLS OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) if( LLVM_BUILD_TOOLS ) @@ -1298,6 +1314,10 @@ macro(add_llvm_utility name) set(EXCLUDE_FROM_ALL ON) endif() + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY AND LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS) + set(DEBUGINFO_INSTALL "DEBUGINFO_INSTALL") + endif() + add_llvm_executable(${name} DISABLE_LLVM_LINK_LLVM_DYLIB ${ARGN}) set_target_properties(${name} PROPERTIES FOLDER "Utils") if ( ${name} IN_LIST LLVM_TOOLCHAIN_UTILITIES OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) @@ -1374,8 +1394,19 @@ function(add_llvm_subdirectory project type name) option(${canonical_full_name}_BUILD "Whether to build ${name} as part of ${project}" On) mark_as_advanced(${project}_${type}_${name}_BUILD) - if(${canonical_full_name}_BUILD) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir} ${add_llvm_external_dir}) + if("${project}${type}" STREQUAL "LLVMTOOL" AND (NOT "${LLVM_TOOLS_TO_BUILD}" STREQUAL "all")) + if("${name}" IN_LIST LLVM_TOOLS_TO_BUILD) + message("Building tool ${name}.") + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir} ${add_llvm_external_dir}) + # Don't process it in add_llvm_implicit_projects(). + set(${project}_${type}_${nameUPPER}_BUILD OFF) + endif() + else() + if(${${project}_${type}_${nameUPPER}_BUILD}) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir} ${add_llvm_external_dir}) + # Don't process it in add_llvm_implicit_projects(). + set(${project}_${type}_${nameUPPER}_BUILD OFF) + endif() endif() else() set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR @@ -1817,6 +1848,9 @@ function(add_lit_target target comment) message(STATUS "${target} does nothing.") endif() + if( NOT LLVM_BUILD_TESTS ) + return() + endif() if (ARG_DEPENDS) add_dependencies(${target} ${ARG_DEPENDS}) endif() @@ -2031,6 +2065,8 @@ function(llvm_externalize_debuginfo name) return() endif() + cmake_parse_arguments(ARG "DEBUGINFO_INSTALL" "" "" ${ARGN}) + if(NOT LLVM_EXTERNALIZE_DEBUGINFO_SKIP_STRIP) if(APPLE) if(NOT CMAKE_STRIP) @@ -2045,6 +2081,8 @@ function(llvm_externalize_debuginfo name) if(APPLE) if(LLVM_EXTERNALIZE_DEBUGINFO_EXTENSION) set(file_ext ${LLVM_EXTERNALIZE_DEBUGINFO_EXTENSION}) + elseif(LLVM_EXTERNALIZE_DEBUGINFO_FLATTEN) + set(file_ext dwarf) else() set(file_ext dSYM) endif() @@ -2052,9 +2090,16 @@ function(llvm_externalize_debuginfo name) set(output_name "$.${file_ext}") if(LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR) - set(output_path "-o=${LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR}/${output_name}") + set(output_path "${LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR}/${output_name}") else() - set(output_path "-o=${output_name}") + set(output_path "${output_name}") + endif() + set(output_flag "-o=${output_path}") + + if(LLVM_EXTERNALIZE_DEBUGINFO_FLATTEN) + set(flatten_debuginfo "--flat") + else() + set(flatten_debuginfo "") endif() if(CMAKE_CXX_FLAGS MATCHES "-flto" @@ -2068,15 +2113,49 @@ function(llvm_externalize_debuginfo name) set(CMAKE_DSYMUTIL xcrun dsymutil) endif() add_custom_command(TARGET ${name} POST_BUILD - COMMAND ${CMAKE_DSYMUTIL} ${output_path} $ + WORKING_DIRECTORY ${LLVM_RUNTIME_OUTPUT_INTDIR} + COMMAND ${CMAKE_DSYMUTIL} ${flatten_debuginfo} ${output_flag} $ ${strip_command} ) + if(LLVM_EXTERNALIZE_DEBUGINFO_INSTALL AND ARG_DEBUGINFO_INSTALL) + get_filename_component(debuginfo_absolute_path ${output_path} REALPATH BASE_DIR $) + install(FILES ${debuginfo_absolute_path} DESTINATION bin OPTIONAL COMPONENT ${name}) + endif() + elseif(WIN32) + if(LLVM_EXTERNALIZE_DEBUGINFO_INSTALL AND ARG_DEBUGINFO_INSTALL) + install(FILES $ DESTINATION bin OPTIONAL COMPONENT ${name}) + endif() else() + if(LLVM_EXTERNALIZE_DEBUGINFO_EXTENSION) + set(file_ext ${LLVM_EXTERNALIZE_DEBUGINFO_EXTENSION}) + else() + set(file_ext debug) + endif() + + set(output_name "$.${file_ext}") + + if(LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR) + set(output_path "${LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR}/${output_name}") + # If an output dir is specified, it must be manually mkdir'd on Linux, + # as that directory needs to exist before we can pipe to a file in it. + add_custom_command(TARGET ${name} POST_BUILD + WORKING_DIRECTORY ${LLVM_RUNTIME_OUTPUT_INTDIR} + COMMAND ${CMAKE_COMMAND} -E make_directory ${LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR} + ) + else() + set(output_path "${output_name}") + endif() + add_custom_command(TARGET ${name} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} --only-keep-debug $ $.debug + WORKING_DIRECTORY ${LLVM_RUNTIME_OUTPUT_INTDIR} + COMMAND ${CMAKE_OBJCOPY} --only-keep-debug $ ${output_path} ${strip_command} -R .gnu_debuglink - COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=$.debug $ + COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=${output_path} $ ) + if(LLVM_EXTERNALIZE_DEBUGINFO_INSTALL AND ARG_DEBUGINFO_INSTALL) + get_filename_component(debuginfo_absolute_path ${output_path} REALPATH BASE_DIR $) + install(FILES ${debuginfo_absolute_path} DESTINATION bin OPTIONAL COMPONENT ${name}) + endif() endif() endfunction() diff --git a/llvm/cmake/modules/CrossCompile.cmake b/llvm/cmake/modules/CrossCompile.cmake index 2a39b6a40a285..2cda21fcf7a5d 100644 --- a/llvm/cmake/modules/CrossCompile.cmake +++ b/llvm/cmake/modules/CrossCompile.cmake @@ -84,6 +84,8 @@ function(llvm_create_cross_target project_name target_name toolchain buildtype) -DLLVM_ENABLE_RUNTIMES="${llvm_enable_runtimes_arg}" ${external_project_source_dirs} -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN="${LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN}" + -DLLVM_TOOLS_TO_BUILD="all" + -DLLVM_INCLUDE_TESTS=OFF ${build_type_flags} ${linker_flag} ${external_clang_dir} ${ARGN} WORKING_DIRECTORY ${${project_name}_${target_name}_BUILD} diff --git a/llvm/cmake/modules/NATIVE.cmake b/llvm/cmake/modules/NATIVE.cmake new file mode 100644 index 0000000000000..4b0abbfa35085 --- /dev/null +++ b/llvm/cmake/modules/NATIVE.cmake @@ -0,0 +1,2 @@ +set(CMAKE_C_COMPILER cc) +set(CMAKE_CXX_COMPILER c++) diff --git a/llvm/cmake/modules/TableGen.cmake b/llvm/cmake/modules/TableGen.cmake index 59fd0d3b07336..ee699f2760668 100644 --- a/llvm/cmake/modules/TableGen.cmake +++ b/llvm/cmake/modules/TableGen.cmake @@ -145,7 +145,11 @@ macro(add_tablegen target project) set(LLVM_ENABLE_OBJLIB ON) endif() - add_llvm_executable(${target} DISABLE_LLVM_LINK_LLVM_DYLIB ${ARGN}) + if ((${project} STREQUAL LLVM OR ${project} STREQUAL MLIR) AND NOT LLVM_INSTALL_TOOLCHAIN_ONLY AND LLVM_BUILD_UTILS) + set(DEBUGINFO_INSTALL "DEBUGINFO_INSTALL") + endif() + + add_llvm_executable(${target} DISABLE_LLVM_LINK_LLVM_DYLIB ${DEBUGINFO_INSTALL} ${ARGN}) set(LLVM_LINK_COMPONENTS ${${target}_OLD_LLVM_LINK_COMPONENTS}) set(${project}_TABLEGEN "${target}" CACHE diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h index 09d80841fa5d3..2bf2fb72c8009 100644 --- a/llvm/include/llvm-c/Core.h +++ b/llvm/include/llvm-c/Core.h @@ -221,6 +221,7 @@ typedef enum { LLVMPreserveAllCallConv = 15, LLVMSwiftCallConv = 16, LLVMCXXFASTTLSCallConv = 17, + LLVMMono1CallConv = 21, LLVMX86StdcallCallConv = 64, LLVMX86FastcallCallConv = 65, LLVMARMAPCSCallConv = 66, diff --git a/llvm/include/llvm/AsmParser/LLToken.h b/llvm/include/llvm/AsmParser/LLToken.h index 78ebb35e0ea4d..420f82a5f38e7 100644 --- a/llvm/include/llvm/AsmParser/LLToken.h +++ b/llvm/include/llvm/AsmParser/LLToken.h @@ -174,6 +174,7 @@ enum Kind { kw_amdgpu_kernel, kw_amdgpu_gfx, kw_tailcc, + kw_monocc, // Attributes: kw_attributes, diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h index c4767a51b0944..6fae62cb161fb 100644 --- a/llvm/include/llvm/CodeGen/MachineFunction.h +++ b/llvm/include/llvm/CodeGen/MachineFunction.h @@ -390,6 +390,9 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { /// \pre Fn, Target, MMI, and FunctionNumber are properly set. void init(); + // Stack slot containing the this pointer for mono compiled functions + int MonoThisSlot; + public: struct VariableDbgInfo { const DILocalVariable *Var; @@ -600,6 +603,9 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { PseudoSourceValueManager &getPSVManager() const { return *PSVManager; } + int getMonoThisSlot() const { return MonoThisSlot; } + void setMonoThisSlot(int Slot) { MonoThisSlot = Slot; } + /// Return the DataLayout attached to the Module associated to this MF. const DataLayout &getDataLayout() const; diff --git a/llvm/include/llvm/Config/llvm-config.h.cmake b/llvm/include/llvm/Config/llvm-config.h.cmake index e8a8c20c7c7ad..32968a1255ee1 100644 --- a/llvm/include/llvm/Config/llvm-config.h.cmake +++ b/llvm/include/llvm/Config/llvm-config.h.cmake @@ -112,4 +112,7 @@ /* Define if building LLVM with LLVM_FORCE_USE_OLD_TOOLCHAIN_LIBS */ #cmakedefine LLVM_FORCE_USE_OLD_TOOLCHAIN $(LLVM_FORCE_USE_OLD_TOOLCHAIN) +/* Mono api version */ +#cmakedefine MONO_API_VERSION ${MONO_API_VERSION} + #endif diff --git a/llvm/include/llvm/IR/CallingConv.h b/llvm/include/llvm/IR/CallingConv.h index fd28542465225..e97806e24c888 100644 --- a/llvm/include/llvm/IR/CallingConv.h +++ b/llvm/include/llvm/IR/CallingConv.h @@ -91,6 +91,9 @@ namespace CallingConv { /// clean up their stack. SwiftTail = 20, + // Mono - Calling convention used by Mono + Mono = 21, + // Target - This is the start of the target-specific calling conventions, // e.g. fastcall and thiscall on X86. FirstTargetCC = 64, diff --git a/llvm/include/llvm/MC/MCObjectStreamer.h b/llvm/include/llvm/MC/MCObjectStreamer.h index 183fd79fb9fc2..dbf2a6ef013bc 100644 --- a/llvm/include/llvm/MC/MCObjectStreamer.h +++ b/llvm/include/llvm/MC/MCObjectStreamer.h @@ -132,6 +132,11 @@ class MCObjectStreamer : public MCStreamer { const MCExpr *Value) override; void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc = SMLoc()) override; + /// \brief EmitValueImpl with additional param, that allows to emit PCRelative + /// MCFixup. + void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc, + bool isPCRelative); + void emitULEB128Value(const MCExpr *Value) override; void emitSLEB128Value(const MCExpr *Value) override; void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override; @@ -162,7 +167,7 @@ class MCObjectStreamer : public MCStreamer { unsigned PointerSize) override; void emitDwarfLineEndEntry(MCSection *Section, MCSymbol *LastLabel) override; void emitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, - const MCSymbol *Label); + const MCSymbol *Label) override; void emitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line, unsigned Column, bool PrologueEnd, bool IsStmt, StringRef FileName, SMLoc Loc) override; diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h index 3d6c512bfe73d..b142803c10990 100644 --- a/llvm/include/llvm/MC/MCStreamer.h +++ b/llvm/include/llvm/MC/MCStreamer.h @@ -147,6 +147,7 @@ class ARMTargetStreamer : public MCTargetStreamer { virtual void emitPad(int64_t Offset); virtual void emitRegSave(const SmallVectorImpl &RegList, bool isVector); + virtual void emitLsda(const MCSymbol *Symbol); virtual void emitUnwindRaw(int64_t StackOffset, const SmallVectorImpl &Opcodes); @@ -683,6 +684,9 @@ class MCStreamer { /// etc. virtual void emitBytes(StringRef Data); + /// \brief Emit the given \p Instruction data into the current section. + virtual void emitInstructionBytes(StringRef Data); + /// Functionally identical to EmitBytes. When emitting textual assembly, this /// method uses .byte directives instead of .ascii or .asciz for readability. virtual void emitBinaryData(StringRef Data); @@ -972,6 +976,9 @@ class MCStreamer { ArrayRef> Ranges, codeview::DefRangeFramePointerRelHeader DRHdr); + virtual void emitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, + const MCSymbol *Label) {} + /// This implements the CodeView '.cv_stringtable' assembler directive. virtual void emitCVStringTableDirective() {} @@ -1021,6 +1028,7 @@ class MCStreamer { virtual void emitCFIRegister(int64_t Register1, int64_t Register2); virtual void emitCFIWindowSave(); virtual void emitCFINegateRAState(); + virtual void emitCFICompactUnwindEncoding(unsigned Encoding); virtual void EmitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc = SMLoc()); virtual void EmitWinCFIEndProc(SMLoc Loc = SMLoc()); diff --git a/llvm/include/llvm/Support/type_traits.h b/llvm/include/llvm/Support/type_traits.h index 7b7d5d991f3f5..be309d04aa774 100644 --- a/llvm/include/llvm/Support/type_traits.h +++ b/llvm/include/llvm/Support/type_traits.h @@ -176,7 +176,7 @@ class is_trivially_copyable { (has_deleted_copy_assign || has_trivial_copy_assign) && (has_deleted_copy_constructor || has_trivial_copy_constructor); -#ifdef HAVE_STD_IS_TRIVIALLY_COPYABLE +#if 0 // see https://reviews.llvm.org/D86126 static_assert(value == std::is_trivially_copyable::value, "inconsistent behavior between llvm:: and std:: implementation of is_trivially_copyable"); #endif diff --git a/llvm/lib/AsmParser/LLLexer.cpp b/llvm/lib/AsmParser/LLLexer.cpp index e3bf41c9721b6..dd7344e32a62f 100644 --- a/llvm/lib/AsmParser/LLLexer.cpp +++ b/llvm/lib/AsmParser/LLLexer.cpp @@ -627,6 +627,7 @@ lltok::Kind LLLexer::LexIdentifier() { KEYWORD(amdgpu_kernel); KEYWORD(amdgpu_gfx); KEYWORD(tailcc); + KEYWORD(monocc); KEYWORD(cc); KEYWORD(c); diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index 432ec151cf8ae..0c521aebb6191 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -1821,6 +1821,7 @@ void LLParser::parseOptionalDLLStorageClass(unsigned &Res) { /// ::= 'amdgpu_cs' /// ::= 'amdgpu_kernel' /// ::= 'tailcc' +/// ::= 'monocc' /// ::= 'cc' UINT /// bool LLParser::parseOptionalCallingConv(unsigned &CC) { @@ -1873,6 +1874,7 @@ bool LLParser::parseOptionalCallingConv(unsigned &CC) { case lltok::kw_amdgpu_cs: CC = CallingConv::AMDGPU_CS; break; case lltok::kw_amdgpu_kernel: CC = CallingConv::AMDGPU_KERNEL; break; case lltok::kw_tailcc: CC = CallingConv::Tail; break; + case lltok::kw_monocc: CC = CallingConv::Mono; break; case lltok::kw_cc: { Lex.Lex(); return parseUInt32(CC); diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 3e8e190eecc3f..204d549f452af 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -18,6 +18,7 @@ #include "WasmException.h" #include "WinCFGuard.h" #include "WinException.h" +#include "MonoException.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/DenseMap.h" @@ -157,6 +158,12 @@ const char PPGroupDescription[] = "Pseudo Probe Emission"; STATISTIC(EmittedInsts, "Number of machine instrs printed"); +cl::opt EnableMonoEH("enable-mono-eh-frame", cl::NotHidden, + cl::desc("Enable generation of Mono specific EH tables")); + +static cl::opt DisableGNUEH("disable-gnu-eh-frame", cl::NotHidden, + cl::desc("Disable generation of GNU .eh_frame")); + char AsmPrinter::ID = 0; using gcp_map_type = DenseMap>; @@ -396,10 +403,12 @@ bool AsmPrinter::doInitialization(Module &M) { LLVM_FALLTHROUGH; case ExceptionHandling::SjLj: case ExceptionHandling::DwarfCFI: - ES = new DwarfCFIException(this); + if (!DisableGNUEH) + ES = new DwarfCFIException(this); break; case ExceptionHandling::ARM: - ES = new ARMException(this); + if (!DisableGNUEH) + ES = new ARMException(this); break; case ExceptionHandling::WinEH: switch (MAI->getWinEHEncodingType()) { @@ -408,7 +417,10 @@ bool AsmPrinter::doInitialization(Module &M) { break; case WinEH::EncodingType::X86: case WinEH::EncodingType::Itanium: - ES = new WinException(this); + if (!EnableMonoEH) + ES = new WinException(this); + else + ES = new WinException(this, true); break; } break; @@ -436,6 +448,11 @@ bool AsmPrinter::doInitialization(Module &M) { HI.Handler->beginModule(&M); } + if (EnableMonoEH) { + MonoException *mono_eh = new MonoException (this, DisableGNUEH); + Handlers.push_back(HandlerInfo(std::unique_ptr (mono_eh), EHTimerName, EHTimerDescription, DWARFGroupName, DWARFGroupDescription)); + } + return false; } @@ -1302,7 +1319,8 @@ void AsmPrinter::emitFunctionBody() { switch (MI.getOpcode()) { case TargetOpcode::CFI_INSTRUCTION: - emitCFIInstruction(MI); + if (!EnableMonoEH) + emitCFIInstruction(MI); break; case TargetOpcode::LOCAL_ESCAPE: emitFrameAlloc(MI); @@ -1477,7 +1495,7 @@ void AsmPrinter::emitFunctionBody() { emitFunctionBodyEnd(); if (needFuncLabelsForEHOrDebugInfo(*MF) || - MAI->hasDotTypeDotSizeDirective()) { + MAI->hasDotTypeDotSizeDirective() || EnableMonoEH) { // Create a symbol for the end of function. CurrentFnEnd = createTempSymbol("func_end"); OutStreamer->emitLabel(CurrentFnEnd); @@ -2035,7 +2053,7 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) { F.hasFnAttribute("function-instrument") || F.hasFnAttribute("xray-instruction-threshold") || needFuncLabelsForEHOrDebugInfo(MF) || NeedsLocalForSize || - MF.getTarget().Options.EmitStackSizeSection || MF.hasBBLabels()) { + MF.getTarget().Options.EmitStackSizeSection || MF.hasBBLabels() || EnableMonoEH) { CurrentFnBegin = createTempSymbol("func_begin"); if (NeedsLocalForSize) CurrentFnSymForSize = CurrentFnBegin; diff --git a/llvm/lib/CodeGen/AsmPrinter/CMakeLists.txt b/llvm/lib/CodeGen/AsmPrinter/CMakeLists.txt index eb924282a75e5..ec975555ef1b8 100644 --- a/llvm/lib/CodeGen/AsmPrinter/CMakeLists.txt +++ b/llvm/lib/CodeGen/AsmPrinter/CMakeLists.txt @@ -26,6 +26,7 @@ add_llvm_component_library(LLVMAsmPrinter WinException.cpp CodeViewDebug.cpp WasmException.cpp + MonoException.cpp DEPENDS intrinsics_gen diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 609b568f28beb..6da0269736070 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1959,6 +1959,8 @@ void DwarfDebug::collectEntityInfo(DwarfCompileUnit &TheCU, // Process beginning of an instruction. void DwarfDebug::beginInstruction(const MachineInstr *MI) { + if (!MMI->hasDebugInfo()) + return; const MachineFunction &MF = *MI->getMF(); const auto *SP = MF.getFunction().getSubprogram(); bool NoDebug = diff --git a/llvm/lib/CodeGen/AsmPrinter/MonoException.cpp b/llvm/lib/CodeGen/AsmPrinter/MonoException.cpp new file mode 100644 index 0000000000000..e67964fac4cdf --- /dev/null +++ b/llvm/lib/CodeGen/AsmPrinter/MonoException.cpp @@ -0,0 +1,671 @@ +//===---*- mode: c++; indent-tabs-mode: nil; c-basic-offset: 2 -*---------===// +//===-- CodeGen/AsmPrinter/MonoException.cpp - Dwarf Exception Impl ------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file contains code to emit Mono specific exception handling tables. +// It is based on code in DwarfException.cpp and MCDwarf.cpp. +// +//===----------------------------------------------------------------------===// + +#include "MonoException.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/Constants.h" +#include "llvm/CodeGen/AsmPrinter.h" +#include "llvm/CodeGen/MachineModuleInfo.h" +#include "llvm/CodeGen/MachineFrameInfo.h" +#include "llvm/CodeGen/MachineFunction.h" +#include "llvm/CodeGen/TargetRegisterInfo.h" +#include "llvm/CodeGen/TargetSubtargetInfo.h" +#include "llvm/CodeGen/TargetFrameLowering.h" +#include "llvm/MC/MCAsmInfo.h" +#include "llvm/MC/MCContext.h" +#include "llvm/MC/MCExpr.h" +#include "llvm/MC/MCSection.h" +#include "llvm/MC/MCStreamer.h" +#include "llvm/MC/MCSymbol.h" +#include "llvm/MC/MCSymbolELF.h" +#include "llvm/IR/DataLayout.h" +#include "llvm/Target/TargetMachine.h" +#include "llvm/Target/TargetOptions.h" +#include "llvm/Target/TargetLoweringObjectFile.h" +#include "llvm/BinaryFormat/Dwarf.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/FormattedStream.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/Twine.h" +using namespace llvm; + +// +// The EH tables emitted by this class enable the following functionality: +// - obtaining the GNU EH information for a given method +// - obtaining the DWARF CFI unwind info for a given method +// - obtaining the address of the table itself from user +// code, ie. it is in the text segment pointed to by +// a symbol. +// + +cl::opt MonoEHFrameSymbol("mono-eh-frame-symbol", cl::NotHidden, + cl::desc("Symbol name for the mono eh frame")); + +// Emit a CFI instruction in DWARF format +static void +emitCFIInstruction(MCStreamer &Streamer, + const MCCFIInstruction &Instr, + int &CFAOffset, int DataAlignmentFactor) +{ + // Same as MCDwarf::EmitCFIInstruction () + // FIXME: Unify + int dataAlignmentFactor = DataAlignmentFactor; + bool VerboseAsm = Streamer.isVerboseAsm(); + + switch (Instr.getOperation()) { + case MCCFIInstruction::OpWindowSave: { + Streamer.emitIntValue(dwarf::DW_CFA_GNU_window_save, 1); + return; + } + case MCCFIInstruction::OpUndefined: { + unsigned Reg = Instr.getRegister(); + if (VerboseAsm) { + Streamer.AddComment("DW_CFA_undefined"); + Streamer.AddComment(Twine("Reg ") + Twine(Reg)); + } + Streamer.emitIntValue(dwarf::DW_CFA_undefined, 1); + Streamer.emitULEB128IntValue(Reg); + return; + } + case MCCFIInstruction::OpAdjustCfaOffset: + case MCCFIInstruction::OpDefCfaOffset: { + const bool IsRelative = + Instr.getOperation() == MCCFIInstruction::OpAdjustCfaOffset; + + if (VerboseAsm) + Streamer.AddComment("DW_CFA_def_cfa_offset"); + Streamer.emitIntValue(dwarf::DW_CFA_def_cfa_offset, 1); + + if (IsRelative) { + CFAOffset += Instr.getOffset(); + } else { + // The backends pass in a negative value, + // then createDefCfaOffset () negates it + CFAOffset = Instr.getOffset(); + assert(CFAOffset >= 0); + } + + if (VerboseAsm) + Streamer.AddComment(Twine("Offset " + Twine(CFAOffset))); + Streamer.emitULEB128IntValue(CFAOffset); + + return; + } + case MCCFIInstruction::OpDefCfa: { + if (VerboseAsm) + Streamer.AddComment("DW_CFA_def_cfa"); + Streamer.emitIntValue(dwarf::DW_CFA_def_cfa, 1); + + if (VerboseAsm) + Streamer.AddComment(Twine("Reg ") + Twine(Instr.getRegister())); + Streamer.emitULEB128IntValue(Instr.getRegister()); + + // The backends pass in a negative value, + // then createDefCfaOffset () negates it + CFAOffset = Instr.getOffset(); + if (CFAOffset < 0) { + outs () << CFAOffset << "\n"; + LLVM_BUILTIN_TRAP; + } + assert(CFAOffset >= 0); + + if (VerboseAsm) + Streamer.AddComment(Twine("Offset " + Twine(CFAOffset))); + Streamer.emitULEB128IntValue(CFAOffset); + + return; + } + + case MCCFIInstruction::OpDefCfaRegister: { + if (VerboseAsm) + Streamer.AddComment("DW_CFA_def_cfa_register"); + Streamer.emitIntValue(dwarf::DW_CFA_def_cfa_register, 1); + + if (VerboseAsm) + Streamer.AddComment(Twine("Reg ") + Twine(Instr.getRegister())); + Streamer.emitULEB128IntValue(Instr.getRegister()); + + return; + } + + case MCCFIInstruction::OpOffset: + case MCCFIInstruction::OpRelOffset: { + const bool IsRelative = + Instr.getOperation() == MCCFIInstruction::OpRelOffset; + + unsigned Reg = Instr.getRegister(); + int Offset = Instr.getOffset(); + if (IsRelative) + Offset -= CFAOffset; + Offset = Offset / dataAlignmentFactor; + + if (Offset < 0) { + if (VerboseAsm) Streamer.AddComment("DW_CFA_offset_extended_sf"); + Streamer.emitIntValue(dwarf::DW_CFA_offset_extended_sf, 1); + if (VerboseAsm) Streamer.AddComment(Twine("Reg ") + Twine(Reg)); + Streamer.emitULEB128IntValue(Reg); + if (VerboseAsm) Streamer.AddComment(Twine("Offset ") + Twine(Offset)); + Streamer.emitSLEB128IntValue(Offset); + } else if (Reg < 64) { + if (VerboseAsm) Streamer.AddComment(Twine("DW_CFA_offset + Reg(") + + Twine(Reg) + ")"); + Streamer.emitIntValue(dwarf::DW_CFA_offset + Reg, 1); + if (VerboseAsm) Streamer.AddComment(Twine("Offset ") + Twine(Offset)); + Streamer.emitULEB128IntValue(Offset); + } else { + if (VerboseAsm) Streamer.AddComment("DW_CFA_offset_extended"); + Streamer.emitIntValue(dwarf::DW_CFA_offset_extended, 1); + if (VerboseAsm) Streamer.AddComment(Twine("Reg ") + Twine(Reg)); + Streamer.emitULEB128IntValue(Reg); + if (VerboseAsm) Streamer.AddComment(Twine("Offset ") + Twine(Offset)); + Streamer.emitULEB128IntValue(Offset); + } + return; + } + case MCCFIInstruction::OpRememberState: + if (VerboseAsm) Streamer.AddComment("DW_CFA_remember_state"); + Streamer.emitIntValue(dwarf::DW_CFA_remember_state, 1); + return; + case MCCFIInstruction::OpRestoreState: + if (VerboseAsm) Streamer.AddComment("DW_CFA_restore_state"); + Streamer.emitIntValue(dwarf::DW_CFA_restore_state, 1); + return; + case MCCFIInstruction::OpSameValue: { + unsigned Reg = Instr.getRegister(); + if (VerboseAsm) Streamer.AddComment("DW_CFA_same_value"); + Streamer.emitIntValue(dwarf::DW_CFA_same_value, 1); + if (VerboseAsm) Streamer.AddComment(Twine("Reg ") + Twine(Reg)); + Streamer.emitULEB128IntValue(Reg); + return; + } + case MCCFIInstruction::OpRestore: { + unsigned Reg = Instr.getRegister(); + if (VerboseAsm) { + Streamer.AddComment("DW_CFA_restore"); + Streamer.AddComment(Twine("Reg ") + Twine(Reg)); + } + Streamer.emitIntValue(dwarf::DW_CFA_restore | Reg, 1); + return; + } + case MCCFIInstruction::OpEscape: + if (VerboseAsm) Streamer.AddComment("Escape bytes"); + Streamer.emitBytes(Instr.getValues()); + return; + case MCCFIInstruction::OpRegister: + case MCCFIInstruction::OpGnuArgsSize: + llvm_unreachable("Unhandled case in switch"); + return; + default: + break; + } + llvm_unreachable("Unhandled case in switch"); +} + +// Emit a list of CFI instructions +static void +emitCFIInstructions(MCStreamer &streamer, + const std::vector &Instrs, + MCSymbol *BaseLabel, + const std::vector &labeled_cfi, + int &CFAOffset, + int DataAlignmentFactor) +{ + for (const auto &lblcfi : labeled_cfi) { + const auto ix = lblcfi.CfiIndex; + const auto Label = lblcfi.Label; + const auto &Instr = Instrs.at(ix); + // Throw out move if the Label is invalid. + if (Label && !Label->isDefined()) continue; // Not emitted, in dead code. + + // Advance row if new location. + if (BaseLabel && Label) { + MCSymbol *ThisSym = Label; + if (ThisSym != BaseLabel) { + streamer.AddComment("cfa_advance"); + streamer.emitDwarfAdvanceFrameAddr(BaseLabel, ThisSym); + BaseLabel = ThisSym; + } + } + + emitCFIInstruction(streamer, Instr, CFAOffset, DataAlignmentFactor); + } +} + +MonoException::MonoException(AsmPrinter *A, bool disableGNUEH) + : EHStreamer(A) +{ + RI = nullptr; + DisableGNUEH = disableGNUEH; +} + +MonoException::~MonoException() +{ +} + +void +MonoException::beginFunction(const MachineFunction *MF) +{ + EmitFnStart(); + CfiInstructions.clear(); +} + +void +MonoException::PrepareMonoLSDA(EHInfo *info) +{ + const MachineFunction *MF = Asm->MF; + const std::vector &TypeInfos = MF->getTypeInfos(); + const std::vector &PadInfos = MF->getLandingPads(); + + // Sort the landing pads in order of their type ids. This is used to fold + // duplicate actions. + SmallVector LandingPads; + LandingPads.reserve(PadInfos.size()); + + for (unsigned i = 0, N = PadInfos.size(); i != N; ++i) + LandingPads.push_back(&PadInfos[i]); + + std::sort(LandingPads.begin(), LandingPads.end(), + [](const LandingPadInfo *L, + const LandingPadInfo *R) { return L->TypeIds < R->TypeIds; }); + + // Invokes and nounwind calls have entries in PadMap (due to being bracketed + // by try-range labels when lowered). Ordinary calls do not, so appropriate + // try-ranges for them need be deduced when using DWARF exception handling. + RangeMapType PadMap; + for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) { + const LandingPadInfo *LandingPad = LandingPads[i]; + for (unsigned j = 0, E = LandingPad->BeginLabels.size(); j != E; ++j) { + MCSymbol *BeginLabel = LandingPad->BeginLabels[j]; + assert(!PadMap.count(BeginLabel) && "Duplicate landing pad labels!"); + PadRange P = { i, j }; + PadMap[BeginLabel] = P; + } + } + + // Compute the call-site table. + SmallVector CallSites; + + MCSymbol *LastLabel = 0; + for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); + I != E; ++I) { + for (MachineBasicBlock::const_iterator MI = I->begin(), E = I->end(); + MI != E; ++MI) { + if (!MI->isLabel()) { + continue; + } + + MCSymbol *BeginLabel = MI->getOperand(0).getMCSymbol(); + assert(BeginLabel && "Invalid label!"); + + RangeMapType::iterator L = PadMap.find(BeginLabel); + + if (L == PadMap.end()) + continue; + + PadRange P = L->second; + const LandingPadInfo *LandingPad = LandingPads[P.PadIndex]; + + assert(BeginLabel == LandingPad->BeginLabels[P.RangeIndex] && + "Inconsistent landing pad map!"); + + // Mono emits one landing pad for each CLR exception clause, + // and the type info contains the clause index + assert (LandingPad->TypeIds.size() == 1); + assert (LandingPad->LandingPadLabel); + + LastLabel = LandingPad->EndLabels[P.RangeIndex]; + MonoCallSiteEntry Site = {BeginLabel, LastLabel, + LandingPad->LandingPadLabel, LandingPad->TypeIds [0]}; + + assert(Site.BeginLabel && Site.EndLabel && Site.PadLabel && + "Invalid landing pad!"); + + // FIXME: This doesn't work because it includes ranges outside clauses +#if 0 + // Try to merge with the previous call-site. + if (CallSites.size()) { + MonoCallSiteEntry &Prev = CallSites.back(); + if (Site.PadLabel == Prev.PadLabel && Site.TypeID == Prev.TypeID) { + // Extend the range of the previous entry. + Prev.EndLabel = Site.EndLabel; + continue; + } + } +#endif + + // Otherwise, create a new call-site. + CallSites.push_back(Site); + } + } + + info->CallSites.insert(info->CallSites.begin(), CallSites.begin(), CallSites.end()); + info->TypeInfos = TypeInfos; + info->PadInfos = PadInfos; + + int ThisSlot = Asm->MF->getMonoThisSlot(); + + if (ThisSlot != -1) { + llvm::Register FrameReg; + info->ThisOffset = Asm->MF->getTarget ().getSubtargetImpl (Asm->MF->getFunction())->getFrameLowering ()->getFrameIndexReference (*Asm->MF, ThisSlot, FrameReg).getFixed (); + info->FrameReg = Asm->MF->getTarget ().getSubtargetImpl (Asm->MF->getFunction())->getRegisterInfo ()->getDwarfRegNum (FrameReg, true); + } else { + info->FrameReg = -1; + } +} + +void +MonoException::EmitFnStart(void) +{ + if (DisableGNUEH && Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM) + static_cast(Asm->OutStreamer->getTargetStreamer())->emitFnStart(); +} + +void +MonoException::EmitFnEnd(void) +{ + if (DisableGNUEH && Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM) + static_cast(Asm->OutStreamer->getTargetStreamer())->emitFnEnd(); +} + +void +MonoException::endFunction(const MachineFunction *MF) +{ + // + // Compute a mapping from method names to their AOT method index + // + if (FuncIndexes.size () == 0) { + const Module *m = MMI->getModule (); + NamedMDNode *indexes = m->getNamedMetadata ("mono.function_indexes"); + if (indexes) { + for (unsigned int i = 0; i < indexes->getNumOperands (); ++i) { + MDNode *n = indexes->getOperand (i); + MDString *s = cast(n->getOperand (0)); + auto *idx = mdconst::dyn_extract(n->getOperand (1)); + FuncIndexes.insert (std::make_pair(s->getString (), (int)idx->getLimitedValue () + 1)); + } + } + } + + // Remember the register info + RI = MF->getSubtarget().getRegisterInfo(); + + MachineFunction *NonConstMF = const_cast(MF); + NonConstMF->tidyLandingPads(); + + int monoMethodIdx = FuncIndexes.lookup (Asm->MF->getFunction ().getName ()) - 1; + + if (monoMethodIdx == -1) { + EmitFnEnd (); + return; + } + + //outs () << "D: " << Asm->MF->getFunction()->getName() << " " << monoMethodIdx << "\n"; + + // Save information for use by endModule () + EHInfo info; + + info.FunctionNumber = Asm->getFunctionNumber(); + info.BeginSym = Asm->getFunctionBegin (); + info.EndSym = Asm->getFunctionEnd (); + info.MonoMethodIdx = monoMethodIdx; + info.HasLandingPads = !MF->getLandingPads().empty(); + info.Instructions = MF->getFrameInstructions(); + info.CfiInstructions = std::move(CfiInstructions); + + if (DisableGNUEH) + /* ARMAsmPrinter generates references to this */ + Asm->OutStreamer->emitLabel(Asm->getMBBExceptionSym(MF->front())); + + PrepareMonoLSDA(&info); + + Frames.push_back(info); + + EmitFnEnd (); +} + +/// EmitMonoLSDA - Mono's version of EmitExceptionTable +/// +/// The code below is a modified/simplified version of DwarfException::EmitExceptionTable() +/// We emit the information inline instead of into a separate section. +/// +void +MonoException::EmitMonoLSDA(const EHInfo *info) +{ + // Load saved information from EHFrameInfo + const std::vector &TypeInfos = info->TypeInfos; + const std::vector &PadInfos = info->PadInfos; + const std::vector CallSites = info->CallSites; + int FrameReg = info->FrameReg; + int ThisOffset = info->ThisOffset; + + // Sort the landing pads in order of their type ids. This is used to fold + // duplicate actions. + SmallVector LandingPads; + LandingPads.reserve(PadInfos.size()); + + for (unsigned i = 0, N = PadInfos.size(); i != N; ++i) + LandingPads.push_back(&PadInfos[i]); + + std::sort(LandingPads.begin(), LandingPads.end(), + [](const LandingPadInfo *L, + const LandingPadInfo *R) { return L->TypeIds < R->TypeIds; }); + + // The type_info itself is emitted + int TTypeEncoding = dwarf::DW_EH_PE_udata4; + + // Emit the LSDA. + // Keep this in sync with JITDwarfEmitter::EmitExceptionTable () + Asm->emitULEB128(0x4d4fef4f, "MONO Magic"); + Asm->emitULEB128(1, "Version"); + + // Emit the LSDA header. + if (FrameReg != -1) { + Asm->emitEncodingByte(dwarf::DW_EH_PE_udata4, "This encoding"); + + // Emit 'this' location + Asm->OutStreamer->AddComment("bregx"); + Asm->emitInt8((int)dwarf::DW_OP_bregx); + Asm->emitULEB128(FrameReg, "Base reg"); + Asm->emitSLEB128(ThisOffset, "Offset"); + } else { + Asm->emitEncodingByte(dwarf::DW_EH_PE_omit, "@This encoding"); + } + + Asm->emitULEB128 (CallSites.size (), "Number of call sites"); + Asm->emitAlignment(llvm::Align(4)); + for (std::vector::const_iterator + I = CallSites.begin(), E = CallSites.end(); I != E; ++I) { + const MonoCallSiteEntry &S = *I; + + MCSymbol *EHFuncBeginSym = info->BeginSym; + + MCSymbol *BeginLabel = S.BeginLabel; + if (BeginLabel == 0) + BeginLabel = EHFuncBeginSym; + MCSymbol *EndLabel = S.EndLabel; + if (EndLabel == 0) + EndLabel = info->EndSym; + + Asm->OutStreamer->AddComment("Region start"); + Asm->emitLabelDifference(BeginLabel, EHFuncBeginSym, 4); + + Asm->OutStreamer->AddComment("Region length"); + Asm->emitLabelDifference(EndLabel, BeginLabel, 4); + + Asm->OutStreamer->AddComment("Landing pad"); + if (!S.PadLabel) + Asm->OutStreamer->emitIntValue(0, 4); + else + Asm->emitLabelDifference(S.PadLabel, EHFuncBeginSym, 4); + + unsigned int TypeID = S.TypeID; + assert (TypeID > 0 && TypeID <= TypeInfos.size ()); + const GlobalVariable *GV = dyn_cast(TypeInfos[TypeID - 1]); + assert (GV); + + // + // Mono typeinfos are simple constant integers. Emit the constant itself. + // + assert(GV); + const ConstantInt *ci = dyn_cast(GV->getInitializer()); + + Asm->OutStreamer->AddComment("TypeInfo"); + Asm->OutStreamer->emitIntValue(ci->getZExtValue(),Asm->GetSizeOfEncodedValue(TTypeEncoding)); + } +} + +void +MonoException::endModule() +{ + const TargetLoweringObjectFile &tlof = Asm->getObjFileLowering(); + auto &streamer = *Asm->OutStreamer; + + // Size and sign of stack growth. + int stackGrowth = -Asm->getDataLayout().getPointerSize(); + int dataAlignmentFactor = stackGrowth; + + // Emit the EH table + + // Can't use rodata as the symbols we reference are in the text segment + streamer.SwitchSection(tlof.getTextSection()); + + MCSymbol *tableSymbol = + Asm->OutContext.getOrCreateSymbol(Twine(MonoEHFrameSymbol)); + MCSymbol *tableEndSym = Asm->createTempSymbol ("mono_eh_frame_end"); + + // Symbol + Asm->emitAlignment(llvm::Align(16)); + streamer.emitLabel(tableSymbol); + streamer.emitSymbolAttribute(tableSymbol, MCSA_ELF_TypeObject); + if (Asm->MAI->hasDotTypeDotSizeDirective()) { + const MCExpr *SizeExp = MCBinaryExpr::createSub( + MCSymbolRefExpr::create(tableEndSym, Asm->OutContext), + MCSymbolRefExpr::create(tableSymbol, Asm->OutContext), Asm->OutContext); + streamer.emitELFSize(cast(tableSymbol), SizeExp); + } + + // Header + streamer.AddComment("version"); + streamer.emitIntValue(3, 1); + streamer.AddComment ("func addr encoding"); + // Unused + streamer.emitIntValue (0, 1); + + // Search table + Asm->emitAlignment(llvm::Align(4)); + streamer.AddComment("fde_count"); + streamer.emitIntValue (Frames.size(), 4); + + MCSymbol *lastBegin = nullptr; + MCSymbol *lastEnd = nullptr; + for (std::vector::iterator + I = Frames.begin(), E = Frames.end(); I != E; ++I) { + EHInfo &info = *I; + + info.FDESym = Asm->createTempSymbol ("mono_fde"); + + streamer.AddComment("mono method idx"); + streamer.emitIntValue (info.MonoMethodIdx, 4); + + Asm->emitLabelDifference(info.FDESym, tableSymbol, 4); + lastBegin = info.BeginSym; + lastEnd = info.EndSym; + } + + // Emit a last entry to simplify binary searches and to enable the computation of + // the size of the last function/FDE entry + if (Frames.size() == 0) { + streamer.emitIntValue (-1, 4); + Asm->emitLabelDifference(tableSymbol, tableSymbol, 4); + } else { + // Emit the size of the last function, since it cannot be computed using the next table entry + Asm->emitLabelDifference(lastEnd, lastBegin, 4); + Asm->emitLabelDifference(tableEndSym, tableSymbol, 4); + } + + // CIE + // This comes right after the search table + Asm->emitULEB128(1, "CIE Code Alignment Factor"); + Asm->emitSLEB128(stackGrowth, "CIE Data Alignment Factor"); + streamer.AddComment("CIE Return Address Column"); + // RI can be null if there are no methods + if (RI) + Asm->emitInt8(RI->getDwarfRegNum(RI->getRARegister(), true)); + Asm->emitEncodingByte(dwarf::DW_EH_PE_omit, "Personality"); + + int cfaOffset = 0; + + // Initial CIE program + std::vector cieInstructions; + const unsigned int cieSize = streamer.getContext().getAsmInfo()->getInitialFrameState().size(); + for (unsigned int i = 0; i < cieSize; ++i) { + cieInstructions.push_back({ nullptr, i }); + } + emitCFIInstructions(streamer, streamer.getContext().getAsmInfo()->getInitialFrameState(), nullptr, cieInstructions, cfaOffset, stackGrowth); + streamer.AddComment("End of CIE program"); + streamer.emitIntValue(dwarf::DW_CFA_nop, 1); + + int cieCfaOffset = cfaOffset; + + // FDEs + streamer.AddBlankLine(); + for (std::vector::iterator + I = Frames.begin(), E = Frames.end(); I != E; ++I) { + const EHInfo &info = *I; + + streamer.emitLabel(info.FDESym); + + // Emit augmentation + if (info.HasLandingPads || info.FrameReg != -1) { + // Need an extra has_augmentation field as the augmentation size is always encoded + // in 4 bytes + Asm->emitULEB128(1, "Has augmentation"); + + MCSymbol *fdeBeginSym = Asm->OutContext.createTempSymbol("mono_fde_aug_begin", info.FunctionNumber); + MCSymbol *fdeEndSym = Asm->OutContext.createTempSymbol("mono_fde_aug_end", info.FunctionNumber); + + streamer.AddComment("Augmentation size"); + Asm->emitLabelDifference(fdeEndSym, fdeBeginSym, 4); + + streamer.emitLabel(fdeBeginSym); + EmitMonoLSDA (&info); + streamer.emitLabel(fdeEndSym); + } else { + Asm->emitULEB128(0, "Has augmentation"); + } + + // Emit unwind info + cfaOffset = cieCfaOffset; + emitCFIInstructions(streamer, info.Instructions, info.BeginSym, info.CfiInstructions, cfaOffset, dataAlignmentFactor); + + streamer.AddBlankLine(); + } + + streamer.emitLabel(tableEndSym); + Asm->emitAlignment(llvm::Align(8)); +} + +void +MonoException::beginInstruction(const MachineInstr *MI) +{ + if (MI->getOpcode() == TargetOpcode::CFI_INSTRUCTION) { + const auto cfiIndex = MI->getOperand(0).getCFIIndex(); + const auto label = Asm->OutContext.createTempSymbol(); + Asm->OutStreamer->emitLabel(label); + CfiInstructions.push_back({ label, cfiIndex }); + } +} diff --git a/llvm/lib/CodeGen/AsmPrinter/MonoException.h b/llvm/lib/CodeGen/AsmPrinter/MonoException.h new file mode 100644 index 0000000000000..307d2316e15f0 --- /dev/null +++ b/llvm/lib/CodeGen/AsmPrinter/MonoException.h @@ -0,0 +1,87 @@ +//===---*- mode: c++; indent-tabs-mode: nil -*----------------------------===// +//===-- MonoException.h - Dwarf Exception Framework -----------*- C++ -*--===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// + +#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_MONOEXCEPTION_H +#define LLVM_LIB_CODEGEN_ASMPRINTER_MONOEXCEPTION_H + +#include "EHStreamer.h" +#include "llvm/CodeGen/AsmPrinter.h" + +namespace llvm { + +class TargetRegisterInfo; + +struct MonoLabeledCfiInstruction { + MCSymbol *Label; + unsigned int CfiIndex; +}; + +class MonoException : public EHStreamer { +public: + MonoException(AsmPrinter *A, bool disableGNUEH); + virtual ~MonoException(); + + void endModule() override; + + void beginFunction(const MachineFunction *MF) override; + + void endFunction(const MachineFunction *) override; + + void beginInstruction(const MachineInstr *MI) override; +private: + + struct MonoCallSiteEntry { + // The 'try-range' is BeginLabel .. EndLabel. + MCSymbol *BeginLabel; // zero indicates the start of the function. + MCSymbol *EndLabel; // zero indicates the end of the function. + + // The landing pad starts at PadLabel. + MCSymbol *PadLabel; // zero indicates that there is no landing pad. + int TypeID; + }; + + // Per-function EH info + struct EHInfo { + int FunctionNumber, MonoMethodIdx; + MCSymbol *BeginSym, *EndSym, *FDESym; + std::vector Instructions; + std::vector CallSites; + std::vector TypeInfos; + std::vector PadInfos; + std::vector CfiInstructions; + int FrameReg; + int ThisOffset; + bool HasLandingPads; + + EHInfo() { + FunctionNumber = 0; + MonoMethodIdx = 0; + BeginSym = nullptr; + EndSym = nullptr; + FrameReg = -1; + ThisOffset = 0; + HasLandingPads = 0; + } + }; + + void PrepareMonoLSDA(EHInfo *info); + void EmitMonoLSDA(const EHInfo *info); + void EmitFnStart(); + void EmitFnEnd(); + + std::vector CfiInstructions; + std::vector Frames; + StringMap FuncIndexes; + const TargetRegisterInfo *RI; + bool DisableGNUEH; +}; +} // End of namespace llvm + +#endif + diff --git a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp index ef57031c7294e..4f8ffb84b57c5 100644 --- a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp @@ -46,6 +46,13 @@ WinException::WinException(AsmPrinter *A) : EHStreamer(A) { isThumb = Asm->TM.getTargetTriple().isThumb(); } +WinException::WinException(AsmPrinter *A, bool disableEmitPersonality) +: EHStreamer(A), disableEmitPersonality(disableEmitPersonality) { + // MSVC's EH tables are always composed of 32-bit words. All known 64-bit + // platforms use an imagerel32 relocation to refer to symbols. + useImageRel32 = (A->getDataLayout().getPointerSizeInBits() == 64); +} + WinException::~WinException() {} /// endModule - Emit all exception information that should come after the @@ -91,9 +98,11 @@ void WinException::beginFunction(const MachineFunction *MF) { !isNoOpWithoutInvoke(Per) && F.needsUnwindTableEntry(); - shouldEmitPersonality = - forceEmitPersonality || ((hasLandingPads || hasEHFunclets) && - PerEncoding != dwarf::DW_EH_PE_omit && PerFn); + if (!disableEmitPersonality) { + shouldEmitPersonality = + forceEmitPersonality || ((hasLandingPads || hasEHFunclets) && + PerEncoding != dwarf::DW_EH_PE_omit && PerFn); + } unsigned LSDAEncoding = TLOF.getLSDAEncoding(); shouldEmitLSDA = shouldEmitPersonality && diff --git a/llvm/lib/CodeGen/AsmPrinter/WinException.h b/llvm/lib/CodeGen/AsmPrinter/WinException.h index 638589adf0ddc..1deba2016bb5f 100644 --- a/llvm/lib/CodeGen/AsmPrinter/WinException.h +++ b/llvm/lib/CodeGen/AsmPrinter/WinException.h @@ -33,6 +33,9 @@ class LLVM_LIBRARY_VISIBILITY WinException : public EHStreamer { /// Per-function flag to indicate if frame moves info should be emitted. bool shouldEmitMoves = false; + /// Per-function flag to indicate if personality info should be disabled. + bool disableEmitPersonality = false; + /// True if this is a 64-bit target and we should use image relative offsets. bool useImageRel32 = false; @@ -97,6 +100,7 @@ class LLVM_LIBRARY_VISIBILITY WinException : public EHStreamer { // Main entry points. // WinException(AsmPrinter *A); + WinException(AsmPrinter *A, bool disableEmitPersonality); ~WinException() override; /// Emit all exception information that should come after the content. diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index c888adeafca5d..1f28608f045f8 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -3602,6 +3602,17 @@ class AddressingModeCombiner { // Request is // p -> ? // The function tries to find or build phi [b1, BB1], [b2, BB2] in BB3. + #if defined(__MINGW32__) + // This function triggers an optimization error in i686-w64-mingw32-gcc/i686-w64-mingw32-g++ + // at least observed in 5.3.1 and 5.4.0. Since these mingw releases are the ones currently + // fetched by package managers building LLVM cross compilers targeting Windows, this make sure + // this method only gets compiled with an optimization level not triggering this bug. When the + // optimization error occurs it results in an incorrect stack pointer restore after the call to + // MatchPhiSet and since this method uses FPO next instruction loading NewPhiNodes relative stack pointer + // will get incorrect value triggering an access violation. + #pragma GCC push_options + #pragma GCC optimize ("O1") + #endif Value *findCommon(FoldAddrToValueMapping &Map) { // Tracks the simplification of newly created phi nodes. The reason we use // this mapping is because we will add new created Phi nodes in AddrToBase. @@ -3639,6 +3650,9 @@ class AddressingModeCombiner { } return Result; } + #if defined(__MINGW32__) + #pragma GCC pop_options + #endif /// Try to match PHI node to Candidate. /// Matcher tracks the matched Phi nodes. diff --git a/llvm/lib/CodeGen/FaultMaps.cpp b/llvm/lib/CodeGen/FaultMaps.cpp index 1d35b194f2182..fc48277d0f085 100644 --- a/llvm/lib/CodeGen/FaultMaps.cpp +++ b/llvm/lib/CodeGen/FaultMaps.cpp @@ -15,9 +15,16 @@ #include "llvm/MC/MCStreamer.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/Format.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/CommandLine.h" using namespace llvm; +static cl::opt DisableFaultMaps("disable-fault-maps", + cl::desc("Disables emission of fault map metadata."), + cl::init(false), cl::Hidden); + #define DEBUG_TYPE "faultmaps" static const int FaultMapVersion = 1; @@ -43,6 +50,8 @@ void FaultMaps::recordFaultingOp(FaultKind FaultTy, } void FaultMaps::serializeToFaultMapSection() { + if (DisableFaultMaps) + return; if (FunctionInfos.empty()) return; diff --git a/llvm/lib/CodeGen/ImplicitNullChecks.cpp b/llvm/lib/CodeGen/ImplicitNullChecks.cpp index fc97938ccd3e9..6010609675861 100644 --- a/llvm/lib/CodeGen/ImplicitNullChecks.cpp +++ b/llvm/lib/CodeGen/ImplicitNullChecks.cpp @@ -353,6 +353,8 @@ ImplicitNullChecks::areMemoryOpsAliased(const MachineInstr &MI, return AR_MayAlias; continue; } + if (MMO2->getValue() == nullptr) + return AR_MayAlias; if (!AA->isNoAlias( MemoryLocation::getAfter(MMO1->getValue(), MMO1->getAAInfo()), MemoryLocation::getAfter(MMO2->getValue(), MMO2->getAAInfo()))) diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp index fd5ea5cad072c..e38e5f138a104 100644 --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -211,6 +211,8 @@ void MachineFunction::init() { PSVManager = std::make_unique(*(getSubtarget(). getInstrInfo())); + + MonoThisSlot = -1; } MachineFunction::~MachineFunction() { diff --git a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp index 85c6eca5775e6..2fe0b2228d834 100644 --- a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp @@ -184,6 +184,17 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf, for (int *CatchObjPtr : Iter->second) *CatchObjPtr = FrameIndex; } + + // + // The mono exception handling code needs to location of the 'this' pointer + // to handle stack traces containing generic shared methods. + // To implement this, it saves the this pointer to an alloca which is marked with + // the 'mono.this' custom metadata. We save the stack slot used by this alloca + // in MachineFunction, so the dwarf exception info emission code can use it to + // compute the reg+offset for it, and save it into the LSDA. + // + if (AI->getMetadata("mono.this")) + MF->setMonoThisSlot(StaticAllocaMap[AI]); } else { // FIXME: Overaligned static allocas should be grouped into // a single dynamic allocation instead of using a separate diff --git a/llvm/lib/ExecutionEngine/CMakeLists.txt b/llvm/lib/ExecutionEngine/CMakeLists.txt index a5607872c7068..d25ad18554826 100644 --- a/llvm/lib/ExecutionEngine/CMakeLists.txt +++ b/llvm/lib/ExecutionEngine/CMakeLists.txt @@ -1,4 +1,6 @@ - +if(NOT LLVM_BUILD_EXECUTION_ENGINE) + set(EXCLUDE_FROM_ALL ON) +endif() add_llvm_component_library(LLVMExecutionEngine ExecutionEngine.cpp @@ -27,11 +29,13 @@ if(BUILD_SHARED_LIBS) target_link_libraries(LLVMExecutionEngine PUBLIC LLVMRuntimeDyld) endif() +if(LLVM_BUILD_EXECUTION_ENGINE) add_subdirectory(Interpreter) add_subdirectory(JITLink) add_subdirectory(MCJIT) add_subdirectory(Orc) add_subdirectory(RuntimeDyld) +endif() if( LLVM_USE_OPROFILE ) add_subdirectory(OProfileJIT) diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index 179754e275b03..5bed73a648354 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -336,6 +336,7 @@ static void PrintCallingConv(unsigned cc, raw_ostream &Out) { case CallingConv::AMDGPU_CS: Out << "amdgpu_cs"; break; case CallingConv::AMDGPU_KERNEL: Out << "amdgpu_kernel"; break; case CallingConv::AMDGPU_Gfx: Out << "amdgpu_gfx"; break; + case CallingConv::Mono: Out << "monocc"; break; } } diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp index 61ec941f50b82..6d7190ac2b175 100644 --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -178,6 +178,8 @@ class MCAsmStreamer final : public MCStreamer { const MCExpr *Value) override; void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override; bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override; + void emitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, + const MCSymbol *Label) override; void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override; void BeginCOFFSymbolDef(const MCSymbol *Symbol) override; @@ -700,6 +702,36 @@ void MCAsmStreamer::emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) { EmitEOL(); } +static const MCExpr *buildSymbolDiff(MCContext &Context, + const MCSymbol *A, + const MCSymbol *B) { + MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None; + const MCExpr *ARef = MCSymbolRefExpr::create(A, Variant, Context); + const MCExpr *BRef = MCSymbolRefExpr::create(B, Variant, Context); + const MCExpr *AddrDelta = + MCBinaryExpr::create(MCBinaryExpr::Sub, ARef, BRef, Context); + return AddrDelta; +} + +static const MCExpr *forceExpAbs(MCStreamer &Streamer, const MCExpr* Expr) { + MCContext &Context = Streamer.getContext(); + assert(!isa(Expr)); + if (Context.getAsmInfo()->hasAggressiveSymbolFolding()) + return Expr; + + MCSymbol *ABS = Context.createTempSymbol(); + Streamer.emitAssignment(ABS, Expr); + return MCSymbolRefExpr::create(ABS, Context); + } + +void MCAsmStreamer::emitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, + const MCSymbol *Label) { + emitIntValue(dwarf::DW_CFA_advance_loc4, 1); + const MCExpr *AddrDelta = buildSymbolDiff(getContext(), Label, LastLabel); + AddrDelta = forceExpAbs(*this, AddrDelta); + emitValue(AddrDelta, 4); +} + bool MCAsmStreamer::emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) { switch (Attribute) { diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp index ebbbd6ad4e164..30e581279f1d7 100644 --- a/llvm/lib/MC/MCObjectStreamer.cpp +++ b/llvm/lib/MC/MCObjectStreamer.cpp @@ -243,7 +243,7 @@ void MCObjectStreamer::emitCFISections(bool EH, bool Debug) { } void MCObjectStreamer::emitValueImpl(const MCExpr *Value, unsigned Size, - SMLoc Loc) { + SMLoc Loc, bool isPCRelative) { MCStreamer::emitValueImpl(Value, Size, Loc); MCDataFragment *DF = getOrCreateDataFragment(); flushPendingLabels(DF, DF->getContents().size()); @@ -263,10 +263,15 @@ void MCObjectStreamer::emitValueImpl(const MCExpr *Value, unsigned Size, } DF->getFixups().push_back( MCFixup::create(DF->getContents().size(), Value, - MCFixup::getKindForSize(Size, false), Loc)); + MCFixup::getKindForSize(Size, isPCRelative), Loc)); DF->getContents().resize(DF->getContents().size() + Size, 0); } +void MCObjectStreamer::emitValueImpl(const MCExpr *Value, unsigned Size, + SMLoc Loc) { + emitValueImpl(Value, Size, Loc, false); +} + MCSymbol *MCObjectStreamer::emitCFILabel() { MCSymbol *Label = getContext().createTempSymbol("cfi"); emitLabel(Label); diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp index a14f0de65a9d1..0d53511b926a7 100644 --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -123,9 +123,12 @@ void MCStreamer::addExplicitComment(const Twine &T) {} void MCStreamer::emitExplicitComments() {} void MCStreamer::generateCompactUnwindEncodings(MCAsmBackend *MAB) { - for (auto &FI : DwarfFrameInfos) - FI.CompactUnwindEncoding = - (MAB ? MAB->generateCompactUnwindEncoding(FI.Instructions) : 0); + for (auto &FI : DwarfFrameInfos) { + if (FI.CompactUnwindEncoding == 0) { + FI.CompactUnwindEncoding = + (MAB ? MAB->generateCompactUnwindEncoding(FI.Instructions) : 0); + } + } } /// EmitIntValue - Special case of EmitValue that avoids the client having to @@ -676,6 +679,14 @@ void MCStreamer::emitCFINegateRAState() { CurFrame->Instructions.push_back(Instruction); } +void MCStreamer::emitCFICompactUnwindEncoding(unsigned Encoding) +{ + MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); + if (!CurFrame) + return; + CurFrame->CompactUnwindEncoding = Encoding; +} + void MCStreamer::emitCFIReturnColumn(int64_t Register) { MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); if (!CurFrame) @@ -1190,6 +1201,7 @@ void MCStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, void MCStreamer::changeSection(MCSection *, const MCExpr *) {} void MCStreamer::emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {} void MCStreamer::emitBytes(StringRef Data) {} +void MCStreamer::emitInstructionBytes(StringRef Data) { emitBytes(Data); } void MCStreamer::emitBinaryData(StringRef Data) { emitBytes(Data); } void MCStreamer::emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) { visitUsedExpr(*Value); diff --git a/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp index f6003b783245e..faf012acce24b 100644 --- a/llvm/lib/Support/Host.cpp +++ b/llvm/lib/Support/Host.cpp @@ -1704,6 +1704,8 @@ bool sys::getHostCPUFeatures(StringMap &Features) { StringRef LLVMFeatureStr = StringSwitch(CPUFeatures[I]) #if defined(__aarch64__) .Case("asimd", "neon") + .Case("asimddp", "dotprod") + .Case("asimdrdm", "rdm") .Case("fp", "fp-armv8") .Case("crc32", "crc") #else diff --git a/llvm/lib/Support/SmallVector.cpp b/llvm/lib/Support/SmallVector.cpp index 8cafbc7fad0de..7549fe7307edd 100644 --- a/llvm/lib/Support/SmallVector.cpp +++ b/llvm/lib/Support/SmallVector.cpp @@ -27,6 +27,7 @@ namespace { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Waix-compat" #endif + struct Struct16B { alignas(16) void *X; }; @@ -37,6 +38,8 @@ struct Struct32B { #pragma GCC diagnostic pop #endif } + +#if 0 static_assert(sizeof(SmallVector) == sizeof(unsigned) * 2 + sizeof(void *), "wasted space in SmallVector size 0"); @@ -51,6 +54,7 @@ static_assert(sizeof(SmallVector) >= alignof(Struct32B), static_assert(sizeof(SmallVector) == sizeof(unsigned) * 2 + sizeof(void *) * 2, "wasted space in SmallVector size 1"); +#endif static_assert(sizeof(SmallVector) == sizeof(void *) * 2 + sizeof(void *), diff --git a/llvm/lib/Target/AArch64/AArch64CallingConvention.h b/llvm/lib/Target/AArch64/AArch64CallingConvention.h index 59939e0684ed2..e8250e1fb2dd8 100644 --- a/llvm/lib/Target/AArch64/AArch64CallingConvention.h +++ b/llvm/lib/Target/AArch64/AArch64CallingConvention.h @@ -46,6 +46,12 @@ bool RetCC_AArch64_AAPCS(unsigned ValNo, MVT ValVT, MVT LocVT, bool RetCC_AArch64_WebKit_JS(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State); +bool CC_AArch64_Mono_DarwinPCS(unsigned ValNo, MVT ValVT, MVT LocVT, + CCValAssign::LocInfo LocInfo, + ISD::ArgFlagsTy ArgFlags, CCState &State); +bool CC_AArch64_Mono_AAPCS(unsigned ValNo, MVT ValVT, MVT LocVT, + CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, + CCState &State); } // namespace llvm #endif diff --git a/llvm/lib/Target/AArch64/AArch64CallingConvention.td b/llvm/lib/Target/AArch64/AArch64CallingConvention.td index f26151536a586..87749f220bbf4 100644 --- a/llvm/lib/Target/AArch64/AArch64CallingConvention.td +++ b/llvm/lib/Target/AArch64/AArch64CallingConvention.td @@ -498,3 +498,28 @@ def CSR_AArch64_SVE_AAPCS_SCS : CalleeSavedRegs<(add CSR_AArch64_SVE_AAPCS, X18)>; def CSR_AArch64_AAPCS_SCS : CalleeSavedRegs<(add CSR_AArch64_AAPCS, X18)>; + +//===----------------------------------------------------------------------===// +// AARCH64 Mono calling conventions +//===----------------------------------------------------------------------===// + +let Entry = 1 in +def CC_AArch64_Mono_DarwinPCS : CallingConv<[ + + // Mono marks the parameter it wants to pass in this non-abi register with + // the 'inreg' attribute. + CCIfInReg>, + + CCDelegateTo +]>; + +let Entry = 1 in +def CC_AArch64_Mono_AAPCS : CallingConv<[ + + // Mono marks the parameter it wants to pass in this non-abi register with + // the 'inreg' attribute. + CCIfInReg>, + + CCDelegateTo +]>; + diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp index ac5e51e47ddf1..1cdaf8b10f561 100644 --- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -5354,6 +5354,13 @@ CCAssignFn *AArch64TargetLowering::CCAssignFnForCall(CallingConv::ID CC, case CallingConv::AArch64_VectorCall: case CallingConv::AArch64_SVE_VectorCall: return CC_AArch64_AAPCS; + case CallingConv::Mono: + if (Subtarget->isTargetDarwin()) + return CC_AArch64_Mono_DarwinPCS; + else if (Subtarget->isTargetWindows()) + report_fatal_error("Unsupported calling convention."); + else + return CC_AArch64_Mono_AAPCS; } } diff --git a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp index d1b901e58d273..35f97ad5b9e64 100644 --- a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp @@ -320,6 +320,9 @@ AArch64RegisterInfo::getReservedRegs(const MachineFunction &MF) const { markSuperRegs(Reserved, AArch64::WSP); markSuperRegs(Reserved, AArch64::WZR); + if (MF.getFunction().getCallingConv() == CallingConv::Mono) + markSuperRegs(Reserved, AArch64::W15); + if (TFI->hasFP(MF) || TT.isOSDarwin()) markSuperRegs(Reserved, AArch64::W29); diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp index dbb8e85713cba..e55dbb11ebcb3 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp @@ -134,6 +134,7 @@ static unsigned getFixupKindNumBytes(unsigned Kind) { case AArch64::fixup_aarch64_pcrel_call26: case FK_Data_4: case FK_SecRel_4: + case FK_PCRel_4: return 4; case FK_Data_8: @@ -326,13 +327,19 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, const MCValue &Target, case FK_Data_8: case FK_SecRel_2: case FK_SecRel_4: + case FK_PCRel_4: return Value; } } Optional AArch64AsmBackend::getFixupKind(StringRef Name) const { - if (!TheTriple.isOSBinFormatELF()) - return None; + if (!TheTriple.isOSBinFormatELF()) { + return StringSwitch>(Name) + .Case("R_AARCH64_CALL26", (MCFixupKind)AArch64::fixup_aarch64_pcrel_call26) + .Case("R_AARCH64_ADR_PREL_PG_HI21", (MCFixupKind)AArch64::fixup_aarch64_pcrel_adrp_imm21) + .Case("R_AARCH64_ADD_ABS_LO12_NC", (MCFixupKind)AArch64::fixup_aarch64_add_imm12) + .Default(MCAsmBackend::getFixupKind(Name)); + } unsigned Type = llvm::StringSwitch(Name) #define ELF_RELOC(X, Y) .Case(#X, Y) diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp index 2f9c17245b5f6..5bb41aa2c551b 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp @@ -130,6 +130,7 @@ unsigned AArch64ELFObjectWriter::getRelocType(MCContext &Ctx, return ELF::R_AARCH64_NONE; case FK_Data_2: return R_CLS(PREL16); + case FK_PCRel_4: case FK_Data_4: { return Target.getAccessVariant() == MCSymbolRefExpr::VK_PLT ? R_CLS(PLT32) diff --git a/llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp b/llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp index c543d02ff75aa..2ea90c43597f0 100644 --- a/llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp +++ b/llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp @@ -208,6 +208,11 @@ getReservedRegs(const MachineFunction &MF) const { // Some targets reserve R9. if (STI.isR9Reserved()) markSuperRegs(Reserved, ARM::R9); + if (MF.getFunction().getCallingConv() == CallingConv::Mono) + // FIXME: This is required for some reason, otherwise llvm treats R8 as a callee-saved registers + // even if we exclude it in getCalleeSavedRegs (). Luckily, R8 can still be used for argument + // passing even if it is 'reserved'. + markSuperRegs(Reserved, ARM::R8); // Reserve D16-D31 if the subtarget doesn't support them. if (!STI.hasD32()) { static_assert(ARM::D31 == ARM::D16 + 15, "Register list not consecutive!"); diff --git a/llvm/lib/Target/ARM/ARMCallingConv.h b/llvm/lib/Target/ARM/ARMCallingConv.h index 7c692f03b4405..970cf1bbb6118 100644 --- a/llvm/lib/Target/ARM/ARMCallingConv.h +++ b/llvm/lib/Target/ARM/ARMCallingConv.h @@ -47,7 +47,15 @@ bool RetCC_ARM_APCS(unsigned ValNo, MVT ValVT, MVT LocVT, bool RetFastCC_ARM_APCS(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State); - +bool CC_ARM_Mono_AAPCS(unsigned ValNo, MVT ValVT, MVT LocVT, + CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, + CCState &State); +bool CC_ARM_Mono_AAPCS_VFP(unsigned ValNo, MVT ValVT, MVT LocVT, + CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, + CCState &State); +bool CC_ARM_Mono_APCS(unsigned ValNo, MVT ValVT, MVT LocVT, + CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, + CCState &State); } // namespace llvm #endif diff --git a/llvm/lib/Target/ARM/ARMCallingConv.td b/llvm/lib/Target/ARM/ARMCallingConv.td index a6dbe563a4ab7..c28cebbf227fb 100644 --- a/llvm/lib/Target/ARM/ARMCallingConv.td +++ b/llvm/lib/Target/ARM/ARMCallingConv.td @@ -352,4 +352,34 @@ def CSR_GenericInt : CalleeSavedRegs<(add LR, (sequence "R%u", 12, 0))>; // registers. def CSR_FIQ : CalleeSavedRegs<(add LR, R11, (sequence "R%u", 7, 0))>; +//===----------------------------------------------------------------------===// +// ARM Mono calling conventions +//===----------------------------------------------------------------------===// + +let Entry = 1 in +def CC_ARM_Mono_APCS : CallingConv<[ + // Mono marks the parameter it wants to pass in this non-abi register with + // the 'inreg' attribute. + CCIfInReg>, + + CCDelegateTo +]>; + +let Entry = 1 in +def CC_ARM_Mono_AAPCS : CallingConv<[ + // Mono marks the parameter it wants to pass in this non-abi register with + // the 'inreg' attribute. + CCIfInReg>, + + CCDelegateTo +]>; + +let Entry = 1 in +def CC_ARM_Mono_AAPCS_VFP : CallingConv<[ + // Mono marks the parameter it wants to pass in this non-abi register with + // the 'inreg' attribute. + CCIfInReg>, + + CCDelegateTo +]>; diff --git a/llvm/lib/Target/ARM/ARMFrameLowering.cpp b/llvm/lib/Target/ARM/ARMFrameLowering.cpp index 1f2f6f7497e02..998b4c3e0088d 100644 --- a/llvm/lib/Target/ARM/ARMFrameLowering.cpp +++ b/llvm/lib/Target/ARM/ARMFrameLowering.cpp @@ -482,6 +482,7 @@ void ARMFrameLowering::emitPrologue(MachineFunction &MF, unsigned NumBytes = MFI.getStackSize(); const std::vector &CSI = MFI.getCalleeSavedInfo(); int FPCXTSaveSize = 0; + bool AvoidNonfpCFA = false; // Debug location must be unknown since the first debug location is used // to determine the end of the prologue. @@ -727,6 +728,7 @@ void ARMFrameLowering::emitPrologue(MachineFunction &MF, dl, TII, FramePtr, ARM::SP, PushSize + FramePtrOffsetInPush, MachineInstr::FrameSetup); +#if 0 if (FramePtrOffsetInPush + PushSize != 0) { unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::cfiDefCfa( nullptr, MRI->getDwarfRegNum(FramePtr, true), @@ -742,6 +744,15 @@ void ARMFrameLowering::emitPrologue(MachineFunction &MF, .addCFIIndex(CFIIndex) .setMIFlags(MachineInstr::FrameSetup); } +#else + /* on iOS `r7 + 8` is always the previous stack pointer */ + unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::cfiDefCfa(nullptr, MRI->getDwarfRegNum(FramePtr, true), 8)); + BuildMI(MBB, AfterPush, dl, TII.get(TargetOpcode::CFI_INSTRUCTION)) + .addCFIIndex(CFIIndex) + .setMIFlags(MachineInstr::FrameSetup); + + AvoidNonfpCFA = true; +#endif } // Now that the prologue's actual instructions are finalised, we can insert @@ -831,7 +842,8 @@ void ARMFrameLowering::emitPrologue(MachineFunction &MF, // throughout the process. If we have a frame pointer, it takes over the job // half-way through, so only the first few .cfi_def_cfa_offset instructions // actually get emitted. - DefCFAOffsetCandidates.emitDefCFAOffsets(MBB, dl, TII, HasFP); + if (!AvoidNonfpCFA) + DefCFAOffsetCandidates.emitDefCFAOffsets(MBB, dl, TII, HasFP); if (STI.isTargetELF() && hasFP(MF)) MFI.setOffsetAdjustment(MFI.getOffsetAdjustment() - diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp index 1b41427a1cab1..b317bbd5647e5 100644 --- a/llvm/lib/Target/ARM/ARMISelLowering.cpp +++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp @@ -2077,6 +2077,8 @@ ARMTargetLowering::getEffectiveCallingConv(CallingConv::ID CC, return CallingConv::ARM_AAPCS_VFP; else return CallingConv::ARM_AAPCS; + case CallingConv::Mono: + return CallingConv::Mono; } } @@ -2112,6 +2114,19 @@ CCAssignFn *ARMTargetLowering::CCAssignFnForNode(CallingConv::ID CC, return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); case CallingConv::CFGuard_Check: return (Return ? RetCC_ARM_AAPCS : CC_ARM_Win32_CFGuard_Check); + case CallingConv::Mono: + if (Return) { + return CCAssignFnForNode(CallingConv::C, true, isVarArg); + } else { + if (!Subtarget->isAAPCS_ABI()) + return CC_ARM_Mono_APCS; + else if (Subtarget->hasVFP2Base() && !Subtarget->isThumb1Only() && + getTargetMachine().Options.FloatABIType == FloatABI::Hard && + !isVarArg) + return CC_ARM_Mono_AAPCS_VFP; + else + return CC_ARM_Mono_AAPCS; + } } } diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp index 23430dfc017a0..6104736107564 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp @@ -454,6 +454,8 @@ unsigned ARMAsmBackend::adjustFixupValue(const MCAssembler &Asm, case FK_Data_2: case FK_Data_4: return Value; + case FK_PCRel_4: + return Value; case FK_SecRel_2: return Value; case FK_SecRel_4: @@ -976,6 +978,9 @@ static unsigned getFixupKindNumBytes(unsigned Kind) { case ARM::fixup_le: return 4; + case FK_PCRel_4: + return 4; + case FK_SecRel_2: return 2; case FK_SecRel_4: diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp index df8f54d14a869..d45ddf5fa50a1 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp @@ -111,6 +111,8 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target, case MCSymbolRefExpr::VK_ARM_PREL31: return ELF::R_ARM_PREL31; } + case FK_PCRel_4: + return ELF::R_ARM_REL32; case ARM::fixup_arm_blx: case ARM::fixup_arm_uncondbl: switch (Modifier) { diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp index 16bc0ca179a7c..265e9cc408956 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp @@ -83,6 +83,7 @@ class ARMTargetAsmStreamer : public ARMTargetStreamer { void emitPad(int64_t Offset) override; void emitRegSave(const SmallVectorImpl &RegList, bool isVector) override; + void emitLsda(const MCSymbol* Symbol) override; void emitUnwindRaw(int64_t Offset, const SmallVectorImpl &Opcodes) override; @@ -269,6 +270,8 @@ void ARMTargetAsmStreamer::emitUnwindRaw(int64_t Offset, OS << '\n'; } +void ARMTargetAsmStreamer::emitLsda(const MCSymbol* Symbol) {} + class ARMTargetELFStreamer : public ARMTargetStreamer { private: StringRef CurrentVendor; @@ -294,6 +297,7 @@ class ARMTargetELFStreamer : public ARMTargetStreamer { void emitPad(int64_t Offset) override; void emitRegSave(const SmallVectorImpl &RegList, bool isVector) override; + void emitLsda(const MCSymbol *Symbol) override; void emitUnwindRaw(int64_t Offset, const SmallVectorImpl &Opcodes) override; @@ -361,6 +365,7 @@ class ARMELFStreamer : public MCELFStreamer { void emitMovSP(unsigned Reg, int64_t Offset = 0); void emitPad(int64_t Offset); void emitRegSave(const SmallVectorImpl &RegList, bool isVector); + void emitLsda(const MCSymbol* Symbol); void emitUnwindRaw(int64_t Offset, const SmallVectorImpl &Opcodes); void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc) override { @@ -440,6 +445,18 @@ class ARMELFStreamer : public MCELFStreamer { MCELFStreamer::emitBytes(Data); } + /// This function is the one used to emit instruction data into the ELF + /// streamer. We override it to add the appropriate mapping symbol if + /// necessary. + void emitInstructionBytes(StringRef Data) override { + if (IsThumb) + EmitThumbMappingSymbol(); + else + EmitARMMappingSymbol(); + + MCELFStreamer::emitBytes(Data); + } + void FlushPendingMappingSymbol() { if (!LastEMSInfo->hasInfo()) return; @@ -625,6 +642,7 @@ class ARMELFStreamer : public MCELFStreamer { bool CantUnwind; SmallVector Opcodes; UnwindOpcodeAssembler UnwindOpAsm; + const MCSymbol *Lsda; }; } // end anonymous namespace @@ -667,6 +685,10 @@ void ARMTargetELFStreamer::emitRegSave(const SmallVectorImpl &RegList, getStreamer().emitRegSave(RegList, isVector); } +void ARMTargetELFStreamer::emitLsda(const MCSymbol *Symbol) { + getStreamer().emitLsda(Symbol); +} + void ARMTargetELFStreamer::emitUnwindRaw(int64_t Offset, const SmallVectorImpl &Opcodes) { getStreamer().emitUnwindRaw(Offset, Opcodes); @@ -1089,6 +1111,7 @@ void ARMELFStreamer::EHReset() { PendingOffset = 0; UsedFP = false; CantUnwind = false; + Lsda = nullptr; Opcodes.clear(); UnwindOpAsm.Reset(); @@ -1191,6 +1214,8 @@ void ARMELFStreamer::FlushUnwindOpcodes(bool NoHandlerData) { } // Finalize the unwind opcode sequence + if (Lsda != nullptr && Opcodes.size() <= 4u) + PersonalityIndex = ARM::EHABI::AEABI_UNWIND_CPP_PR1; UnwindOpAsm.Finalize(PersonalityIndex, Opcodes); // For compact model 0, we have to emit the unwind opcodes in the .ARM.exidx @@ -1235,7 +1260,13 @@ void ARMELFStreamer::FlushUnwindOpcodes(bool NoHandlerData) { // // In case that the .handlerdata directive is not specified by the // programmer, we should emit zero to terminate the handler data. - if (NoHandlerData && !Personality) + if (Lsda != nullptr) { + const MCSymbolRefExpr *LsdaRef = + MCSymbolRefExpr::create(Lsda, + MCSymbolRefExpr::VK_None, + getContext()); + emitValue(LsdaRef, 4); + } else if (NoHandlerData && !Personality) emitInt32(0); } @@ -1349,6 +1380,10 @@ void ARMELFStreamer::emitRegSave(const SmallVectorImpl &RegList, } } +void ARMELFStreamer::emitLsda(const MCSymbol *Symbol) { + Lsda = Symbol; +} + void ARMELFStreamer::emitUnwindRaw(int64_t Offset, const SmallVectorImpl &Opcodes) { FlushPendingOffset(); diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp index 02a2d01176fca..e3825c9a8fd00 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp @@ -99,6 +99,7 @@ void ARMTargetStreamer::emitMovSP(unsigned Reg, int64_t Offset) {} void ARMTargetStreamer::emitPad(int64_t Offset) {} void ARMTargetStreamer::emitRegSave(const SmallVectorImpl &RegList, bool isVector) {} +void ARMTargetStreamer::emitLsda(const MCSymbol *Symbol) {} void ARMTargetStreamer::emitUnwindRaw(int64_t StackOffset, const SmallVectorImpl &Opcodes) { } diff --git a/llvm/lib/Target/X86/X86CallingConv.td b/llvm/lib/Target/X86/X86CallingConv.td index 4dd8a6cdd8982..ca14f4db11f1d 100644 --- a/llvm/lib/Target/X86/X86CallingConv.td +++ b/llvm/lib/Target/X86/X86CallingConv.td @@ -761,6 +761,15 @@ def CC_X86_64_AnyReg : CallingConv<[ CCCustom<"CC_X86_AnyReg_Error"> ]>; +def CC_X86_64_Mono : CallingConv<[ + CCIfInReg>, + + // Mingw64 and native Win64 use Win64 CC + CCIfSubtarget<"isTargetWin64()", CCDelegateTo>, + // Otherwise, drop to normal X86-64 CC + CCDelegateTo +]>; + //===----------------------------------------------------------------------===// // X86 C Calling Convention //===----------------------------------------------------------------------===// @@ -1064,6 +1073,12 @@ def CC_Intel_OCL_BI : CallingConv<[ CCDelegateTo ]>; +def CC_X86_32_Mono : CallingConv<[ + CCIfInReg>, + + CCDelegateTo +]>; + //===----------------------------------------------------------------------===// // X86 Root Argument Calling Conventions //===----------------------------------------------------------------------===// @@ -1083,6 +1098,7 @@ def CC_X86_32 : CallingConv<[ CCIfCC<"CallingConv::GHC", CCDelegateTo>, CCIfCC<"CallingConv::HiPE", CCDelegateTo>, CCIfCC<"CallingConv::X86_RegCall", CCDelegateTo>, + CCIfCC<"CallingConv::Mono", CCDelegateTo>, // Otherwise, drop to normal X86-32 CC CCDelegateTo @@ -1103,6 +1119,7 @@ def CC_X86_64 : CallingConv<[ CCIfSubtarget<"isTargetWin64()", CCDelegateTo>>, CCIfCC<"CallingConv::X86_RegCall", CCDelegateTo>, CCIfCC<"CallingConv::X86_INTR", CCCustom<"CC_X86_Intr">>, + CCIfCC<"CallingConv::Mono", CCDelegateTo>, // Mingw64 and native Win64 use Win64 CC CCIfSubtarget<"isTargetWin64()", CCDelegateTo>, @@ -1154,11 +1171,11 @@ def CSR_64_CXX_TLS_Darwin_PE : CalleeSavedRegs<(add RBP)>; // CSRs that are handled explicitly via copies. def CSR_64_CXX_TLS_Darwin_ViaCopy : CalleeSavedRegs<(sub CSR_64_TLS_Darwin, RBP)>; -// All GPRs - except r11 +// All GPRs - except r11/rsp def CSR_64_RT_MostRegs : CalleeSavedRegs<(add CSR_64, RAX, RCX, RDX, RSI, RDI, R8, R9, R10)>; -// All registers - except r11 +// All registers - except r11/rsp def CSR_64_RT_AllRegs : CalleeSavedRegs<(add CSR_64_RT_MostRegs, (sequence "XMM%u", 0, 15))>; def CSR_64_RT_AllRegs_AVX : CalleeSavedRegs<(add CSR_64_RT_MostRegs, diff --git a/llvm/lib/Target/X86/X86FastISel.cpp b/llvm/lib/Target/X86/X86FastISel.cpp index 1ac998b7ff7ed..76a146b6de87d 100644 --- a/llvm/lib/Target/X86/X86FastISel.cpp +++ b/llvm/lib/Target/X86/X86FastISel.cpp @@ -1184,6 +1184,9 @@ bool X86FastISel::X86SelectRet(const Instruction *I) { return false; CallingConv::ID CC = F.getCallingConv(); + if (CC == CallingConv::Mono && Subtarget->isTargetWin64()) + CC = CallingConv::Win64; + if (CC != CallingConv::C && CC != CallingConv::Fast && CC != CallingConv::Tail && @@ -3194,6 +3197,9 @@ bool X86FastISel::fastLowerCall(CallLoweringInfo &CLI) { if (Subtarget->useIndirectThunkCalls()) return false; + if (CC == CallingConv::Mono && Subtarget->isTargetWin64()) + CC = CallingConv::Win64; + // Handle only C, fastcc, and webkit_js calling conventions for now. switch (CC) { default: return false; diff --git a/llvm/lib/Target/X86/X86FrameLowering.cpp b/llvm/lib/Target/X86/X86FrameLowering.cpp index 0971a0e33f98b..45ed21012de05 100644 --- a/llvm/lib/Target/X86/X86FrameLowering.cpp +++ b/llvm/lib/Target/X86/X86FrameLowering.cpp @@ -1410,7 +1410,10 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF, bool NeedsWinFPO = !IsFunclet && STI.isTargetWin32() && MMI.getModule()->getCodeViewFlag(); bool NeedsWinCFI = NeedsWin64CFI || NeedsWinFPO; - bool NeedsDwarfCFI = needsDwarfCFI(MF); + bool NeedsDwarfCFI = + Fn.getCallingConv() == CallingConv::Mono + ? MF.needsFrameMoves() + : needsDwarfCFI(MF); Register FramePtr = TRI->getFrameRegister(MF); const Register MachineFramePtr = STI.isTarget64BitILP32() @@ -1516,6 +1519,7 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF, uint64_t NumBytes = 0; int stackGrowth = -SlotSize; + int StackOffset = 2 * stackGrowth; // Find the funclet establisher parameter Register Establisher = X86::NoRegister; @@ -1561,12 +1565,14 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF, // Define the current CFA rule to use the provided offset. assert(StackSize); BuildCFI(MBB, MBBI, DL, - MCCFIInstruction::cfiDefCfaOffset(nullptr, -2 * stackGrowth)); + MCCFIInstruction::cfiDefCfaOffset(nullptr, -StackOffset)); // Change the rule for the FramePtr to be an "offset" rule. unsigned DwarfFramePtr = TRI->getDwarfRegNum(MachineFramePtr, true); BuildCFI(MBB, MBBI, DL, MCCFIInstruction::createOffset( - nullptr, DwarfFramePtr, 2 * stackGrowth)); + nullptr, DwarfFramePtr, StackOffset)); + + StackOffset += stackGrowth; } if (NeedsWinCFI) { @@ -1669,7 +1675,6 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF, // Skip the callee-saved push instructions. bool PushedRegs = false; - int StackOffset = 2 * stackGrowth; while (MBBI != MBB.end() && MBBI->getFlag(MachineInstr::FrameSetup) && @@ -1679,12 +1684,19 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF, Register Reg = MBBI->getOperand(0).getReg(); ++MBBI; - if (!HasFP && NeedsDwarfCFI) { + if (!HasFP && NeedsDwarfCFI || (IsWin64Prologue && NeedsDwarfCFI)) { // Mark callee-saved push instruction. // Define the current CFA rule to use the provided offset. assert(StackSize); BuildCFI(MBB, MBBI, DL, MCCFIInstruction::cfiDefCfaOffset(nullptr, -StackOffset)); + + if (IsWin64Prologue && NeedsDwarfCFI) { + unsigned DwarfReg= TRI->getDwarfRegNum(Reg, true); + BuildCFI(MBB, MBBI, DL, + MCCFIInstruction::createOffset(nullptr, DwarfReg, StackOffset)); + } + StackOffset += stackGrowth; } @@ -1791,6 +1803,13 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF, .setMIFlag(MachineInstr::FrameSetup); } + // When emitting Dwarf CFI on Win64 account for adjustment at correct + // location in stream. + if (IsWin64Prologue && NeedsDwarfCFI && NumBytes) { + BuildCFI(MBB, MBBI, DL, + MCCFIInstruction::createAdjustCfaOffset(nullptr, NumBytes)); + } + int SEHFrameOffset = 0; unsigned SPOrEstablisher; if (IsFunclet) { @@ -1845,6 +1864,21 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF, if (isAsynchronousEHPersonality(Personality)) MF.getWinEHFuncInfo()->SEHSetFrameOffset = SEHFrameOffset; } + + if (NeedsDwarfCFI && !IsFunclet) { + // Define the current CFA to use the EBP/RBP register. + unsigned DwarfFramePtr = TRI->getDwarfRegNum(FramePtr, true); + BuildCFI(MBB, MBBI, DL, + MCCFIInstruction::createDefCfaRegister(nullptr, DwarfFramePtr)); + + if (SEHFrameOffset) { + // Framepointer has been adjusted with an offset, make sure + // it is reflected in CFA offset. + BuildCFI(MBB, MBBI, DL, + MCCFIInstruction::createAdjustCfaOffset(nullptr, -SEHFrameOffset)); + } + } + } else if (IsFunclet && STI.is32Bit()) { // Reset EBP / ESI to something good for funclets. MBBI = restoreWin32EHStackPointers(MBB, MBBI, DL); @@ -1958,7 +1992,7 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF, } } - if (((!HasFP && NumBytes) || PushedRegs) && NeedsDwarfCFI) { + if (((!HasFP && NumBytes) || PushedRegs) && NeedsDwarfCFI && !IsWin64Prologue) { // Mark end of stack pointer adjustment. if (!HasFP && NumBytes) { // Define the current CFA rule to use the provided offset. diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 77c2e7d169907..1fbbd759cd68c 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -3423,7 +3423,9 @@ static bool canGuaranteeTCO(CallingConv::ID CC) { } /// Return true if we might ever do TCO for calls with this calling convention. -static bool mayTailCallThisCC(CallingConv::ID CC) { +static bool mayTailCallThisCC(CallingConv::ID CC, bool isTargetWin64) { + if (CC == CallingConv::Mono && isTargetWin64) + CC = CallingConv::Win64; switch (CC) { // C calling conventions: case CallingConv::C: @@ -3454,7 +3456,7 @@ bool X86TargetLowering::mayBeEmittedAsTailCall(const CallInst *CI) const { return false; CallingConv::ID CalleeCC = CI->getCallingConv(); - if (!mayTailCallThisCC(CalleeCC)) + if (!mayTailCallThisCC(CalleeCC, Subtarget.isTargetWin64())) return false; return true; @@ -4861,7 +4863,7 @@ bool X86TargetLowering::IsEligibleForTailCallOptimization( bool isVarArg, Type *RetTy, const SmallVectorImpl &Outs, const SmallVectorImpl &OutVals, const SmallVectorImpl &Ins, SelectionDAG &DAG) const { - if (!mayTailCallThisCC(CalleeCC)) + if (!mayTailCallThisCC(CalleeCC, Subtarget.isTargetWin64())) return false; // If -tailcallopt is specified, make fastcc functions tail-callable. diff --git a/llvm/lib/Target/X86/X86RegisterInfo.cpp b/llvm/lib/Target/X86/X86RegisterInfo.cpp index 130cb61cdde24..42fd1444163b3 100644 --- a/llvm/lib/Target/X86/X86RegisterInfo.cpp +++ b/llvm/lib/Target/X86/X86RegisterInfo.cpp @@ -295,6 +295,9 @@ X86RegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const { if (MF->getFunction().hasFnAttribute("no_callee_saved_registers")) return CSR_NoRegs_SaveList; + if (CC == CallingConv::Mono && IsWin64) + CC = CallingConv::Win64; + switch (CC) { case CallingConv::GHC: case CallingConv::HiPE: @@ -418,6 +421,9 @@ X86RegisterInfo::getCallPreservedMask(const MachineFunction &MF, bool HasAVX = Subtarget.hasAVX(); bool HasAVX512 = Subtarget.hasAVX512(); + if ( CC == CallingConv::Mono && IsWin64) + CC = CallingConv::Win64; + switch (CC) { case CallingConv::GHC: case CallingConv::HiPE: diff --git a/llvm/lib/Target/X86/X86Subtarget.h b/llvm/lib/Target/X86/X86Subtarget.h index 5d773f0c57dfb..b19cbbd77b3f7 100644 --- a/llvm/lib/Target/X86/X86Subtarget.h +++ b/llvm/lib/Target/X86/X86Subtarget.h @@ -916,6 +916,7 @@ class X86Subtarget final : public X86GenSubtargetInfo { case CallingConv::X86_ThisCall: case CallingConv::X86_VectorCall: case CallingConv::Intel_OCL_BI: + case CallingConv::Mono: return isTargetWin64(); // This convention allows using the Win64 convention on other targets. case CallingConv::Win64: diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp index c51acdf52f14d..addd24ee65882 100644 --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -4384,15 +4384,23 @@ struct VarArgAMD64Helper : public VarArgHelper { // nonzero shadow. } + bool isTargetWin64() const { + Triple TargetTriple(F.getParent()->getTargetTriple()); + return TargetTriple.isArch64Bit() && TargetTriple.isOSWindows(); + } + void visitVAStartInst(VAStartInst &I) override { - if (F.getCallingConv() == CallingConv::Win64) + if (F.getCallingConv() == CallingConv::Win64 || + (F.getCallingConv() == CallingConv::Mono && isTargetWin64())) return; VAStartInstrumentationList.push_back(&I); unpoisonVAListTagForInst(I); } void visitVACopyInst(VACopyInst &I) override { - if (F.getCallingConv() == CallingConv::Win64) return; + if (F.getCallingConv() == CallingConv::Win64 || + (F.getCallingConv() == CallingConv::Mono && isTargetWin64())) + return; unpoisonVAListTagForInst(I); } diff --git a/llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp b/llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp index a110f7d5c2417..a3138118791b9 100644 --- a/llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp +++ b/llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp @@ -450,8 +450,10 @@ static bool shouldRewriteFunction(Function &F) { const auto &FunctionGCName = F.getGC(); const StringRef StatepointExampleName("statepoint-example"); const StringRef CoreCLRName("coreclr"); + const StringRef MonoName("mono"); return (StatepointExampleName == FunctionGCName) || - (CoreCLRName == FunctionGCName); + (CoreCLRName == FunctionGCName) || + (MonoName == FunctionGCName); } else return false; } diff --git a/llvm/tools/llvm-config/llvm-config.cpp b/llvm/tools/llvm-config/llvm-config.cpp index 8ed88f33ead46..4f8dc69d14a89 100644 --- a/llvm/tools/llvm-config/llvm-config.cpp +++ b/llvm/tools/llvm-config/llvm-config.cpp @@ -507,7 +507,9 @@ int main(int argc, char **argv) { if (Arg.startswith("-")) { HasAnyOption = true; if (Arg == "--version") { - OS << PACKAGE_VERSION << '\n'; + OS << PACKAGE_VERSION << "-mono" << '\n'; + } else if (Arg == "--mono-api-version") { + OS << MONO_API_VERSION << '\n'; } else if (Arg == "--prefix") { OS << ActivePrefix << '\n'; } else if (Arg == "--bindir") { diff --git a/llvm/tools/objwriter/CMakeLists.txt b/llvm/tools/objwriter/CMakeLists.txt new file mode 100644 index 0000000000000..caa4a88807970 --- /dev/null +++ b/llvm/tools/objwriter/CMakeLists.txt @@ -0,0 +1,24 @@ +set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/objwriter.exports) + +set(LLVM_LINK_COMPONENTS + AllTargetsDescs + AllTargetsInfos + MC + Support + ) + +message(STATUS "ObjWriter configuring with (${CMAKE_BUILD_TYPE}) build type and (${LLVM_DEFAULT_TARGET_TRIPLE}) default target triple") + +add_llvm_library(objwriter SHARED + objwriter.cpp + debugInfo/codeView/codeViewTypeBuilder.cpp + debugInfo/codeView/codeViewTypeBuilder.h + debugInfo/dwarf/dwarfTypeBuilder.cpp + debugInfo/dwarf/dwarfTypeBuilder.h + debugInfo/dwarf/dwarfGen.cpp + debugInfo/dwarf/dwarfGen.h + debugInfo/dwarf/dwarfAbbrev.cpp + debugInfo/dwarf/dwarfAbbrev.h + debugInfo/typeBuilder.h + objwriter.h # Visual Studio generator doesn't include necessary header files into the project automatically +) diff --git a/llvm/tools/objwriter/README.md b/llvm/tools/objwriter/README.md new file mode 100644 index 0000000000000..5a508e9db10f8 --- /dev/null +++ b/llvm/tools/objwriter/README.md @@ -0,0 +1,5 @@ +# Native Object Writer library + +This library exposes C APIs to emit ELF/Mach-O/PE object files. + +The implementation is based on LLVM's assembler APIs - these are APIs intended to be consumed by assembly language compilers and are therefore close to the underlying object file formats. When in doubt, look at how the assemblers (e.g. llvm-ml in the tools directory of LLVM) use these APIs. diff --git a/llvm/tools/objwriter/cfi.h b/llvm/tools/objwriter/cfi.h new file mode 100644 index 0000000000000..56d49c56c21f4 --- /dev/null +++ b/llvm/tools/objwriter/cfi.h @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#ifndef CFI_H_ +#define CFI_H_ + +#define DWARF_REG_ILLEGAL -1 +enum CFI_OPCODE +{ + CFI_ADJUST_CFA_OFFSET, // Offset is adjusted relative to the current one. + CFI_DEF_CFA_REGISTER, // New register is used to compute CFA + CFI_REL_OFFSET, // Register is saved at offset from the current CFA + CFI_DEF_CFA, // Take address from register and add offset to it +}; + +struct CFI_CODE +{ + unsigned char CodeOffset;// Offset from the start of code the frame covers. + unsigned char CfiOpCode; + short DwarfReg; // Dwarf register number. 0~32 for x64. + int Offset; + CFI_CODE(unsigned char codeOffset, unsigned char cfiOpcode, + short dwarfReg, int offset) + : CodeOffset(codeOffset) + , CfiOpCode(cfiOpcode) + , DwarfReg(dwarfReg) + , Offset(offset) + {} +}; +typedef CFI_CODE* PCFI_CODE; + +#endif // CFI_H + diff --git a/llvm/tools/objwriter/cordebuginfo.h b/llvm/tools/objwriter/cordebuginfo.h new file mode 100644 index 0000000000000..5ccecbcb36bf4 --- /dev/null +++ b/llvm/tools/objwriter/cordebuginfo.h @@ -0,0 +1,336 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// +// Keep in sync with https://github.com/dotnet/runtime/blob/main/src/coreclr/inc/cordebuginfo.h +// + +/**********************************************************************************/ +// DebugInfo types shared by JIT-EE interface and EE-Debugger interface + +class ICorDebugInfo +{ +public: + /*----------------------------- Boundary-info ---------------------------*/ + + enum MappingTypes + { + NO_MAPPING = -1, + PROLOG = -2, + EPILOG = -3, + MAX_MAPPING_VALUE = -3 // Sentinal value. This should be set to the largest magnitude value in the enum + // so that the compression routines know the enum's range. + }; + + enum BoundaryTypes + { + NO_BOUNDARIES = 0x00, // No implicit boundaries + STACK_EMPTY_BOUNDARIES = 0x01, // Boundary whenever the IL evaluation stack is empty + NOP_BOUNDARIES = 0x02, // Before every CEE_NOP instruction + CALL_SITE_BOUNDARIES = 0x04, // Before every CEE_CALL, CEE_CALLVIRT, etc instruction + + // Set of boundaries that debugger should always reasonably ask the JIT for. + DEFAULT_BOUNDARIES = STACK_EMPTY_BOUNDARIES | NOP_BOUNDARIES | CALL_SITE_BOUNDARIES + }; + + // Note that SourceTypes can be OR'd together - it's possible that + // a sequence point will also be a stack_empty point, and/or a call site. + // The debugger will check to see if a boundary offset's source field & + // SEQUENCE_POINT is true to determine if the boundary is a sequence point. + + enum SourceTypes + { + SOURCE_TYPE_INVALID = 0x00, // To indicate that nothing else applies + SEQUENCE_POINT = 0x01, // The debugger asked for it. + STACK_EMPTY = 0x02, // The stack is empty here + CALL_SITE = 0x04, // This is a call site. + NATIVE_END_OFFSET_UNKNOWN = 0x08, // Indicates a epilog endpoint + CALL_INSTRUCTION = 0x10 // The actual instruction of a call. + + }; + + struct OffsetMapping + { + uint32_t nativeOffset; + uint32_t ilOffset; // IL offset or one of the special values in MappingTypes + SourceTypes source; // The debugger needs this so that + // we don't put Edit and Continue breakpoints where + // the stack isn't empty. We can put regular breakpoints + // there, though, so we need a way to discriminate + // between offsets. + }; + + /*------------------------------ Var-info -------------------------------*/ + + // Note: The debugger needs to target register numbers on platforms other than which the debugger itself + // is running. To this end it maintains its own values for REGNUM_SP and REGNUM_AMBIENT_SP across multiple + // platforms. So any change here that may effect these values should be reflected in the definitions + // contained in debug/inc/DbgIPCEvents.h. + enum RegNum + { +#ifdef TARGET_X86 + REGNUM_EAX, + REGNUM_ECX, + REGNUM_EDX, + REGNUM_EBX, + REGNUM_ESP, + REGNUM_EBP, + REGNUM_ESI, + REGNUM_EDI, +#elif TARGET_ARM + REGNUM_R0, + REGNUM_R1, + REGNUM_R2, + REGNUM_R3, + REGNUM_R4, + REGNUM_R5, + REGNUM_R6, + REGNUM_R7, + REGNUM_R8, + REGNUM_R9, + REGNUM_R10, + REGNUM_R11, + REGNUM_R12, + REGNUM_SP, + REGNUM_LR, + REGNUM_PC, +#elif TARGET_ARM64 + REGNUM_X0, + REGNUM_X1, + REGNUM_X2, + REGNUM_X3, + REGNUM_X4, + REGNUM_X5, + REGNUM_X6, + REGNUM_X7, + REGNUM_X8, + REGNUM_X9, + REGNUM_X10, + REGNUM_X11, + REGNUM_X12, + REGNUM_X13, + REGNUM_X14, + REGNUM_X15, + REGNUM_X16, + REGNUM_X17, + REGNUM_X18, + REGNUM_X19, + REGNUM_X20, + REGNUM_X21, + REGNUM_X22, + REGNUM_X23, + REGNUM_X24, + REGNUM_X25, + REGNUM_X26, + REGNUM_X27, + REGNUM_X28, + REGNUM_FP, + REGNUM_LR, + REGNUM_SP, + REGNUM_PC, +#elif TARGET_AMD64 + REGNUM_RAX, + REGNUM_RCX, + REGNUM_RDX, + REGNUM_RBX, + REGNUM_RSP, + REGNUM_RBP, + REGNUM_RSI, + REGNUM_RDI, + REGNUM_R8, + REGNUM_R9, + REGNUM_R10, + REGNUM_R11, + REGNUM_R12, + REGNUM_R13, + REGNUM_R14, + REGNUM_R15, +#else + PORTABILITY_WARNING("Register numbers not defined on this platform") +#endif + REGNUM_COUNT, + REGNUM_AMBIENT_SP, // ambient SP support. Ambient SP is the original SP in the non-BP based frame. + // Ambient SP should not change even if there are push/pop operations in the method. + +#ifdef TARGET_X86 + REGNUM_FP = REGNUM_EBP, + REGNUM_SP = REGNUM_ESP, +#elif TARGET_AMD64 + REGNUM_SP = REGNUM_RSP, +#elif TARGET_ARM +#ifdef REDHAWK + REGNUM_FP = REGNUM_R7, +#else + REGNUM_FP = REGNUM_R11, +#endif //REDHAWK +#elif TARGET_ARM64 + //Nothing to do here. FP is already alloted. +#else + // RegNum values should be properly defined for this platform + REGNUM_FP = 0, + REGNUM_SP = 1, +#endif + + }; + + // VarLoc describes the location of a native variable. Note that currently, VLT_REG_BYREF and VLT_STK_BYREF + // are only used for value types on X64. + + enum VarLocType + { + VLT_REG, // variable is in a register + VLT_REG_BYREF, // address of the variable is in a register + VLT_REG_FP, // variable is in an fp register + VLT_STK, // variable is on the stack (memory addressed relative to the frame-pointer) + VLT_STK_BYREF, // address of the variable is on the stack (memory addressed relative to the frame-pointer) + VLT_REG_REG, // variable lives in two registers + VLT_REG_STK, // variable lives partly in a register and partly on the stack + VLT_STK_REG, // reverse of VLT_REG_STK + VLT_STK2, // variable lives in two slots on the stack + VLT_FPSTK, // variable lives on the floating-point stack + VLT_FIXED_VA, // variable is a fixed argument in a varargs function (relative to VARARGS_HANDLE) + + VLT_COUNT, + VLT_INVALID, + }; + + // VLT_REG/VLT_REG_FP -- Any pointer-sized enregistered value (TYP_INT, TYP_REF, etc) + // eg. EAX + // VLT_REG_BYREF -- the specified register contains the address of the variable + // eg. [EAX] + + struct vlReg + { + RegNum vlrReg; + }; + + // VLT_STK -- Any 32 bit value which is on the stack + // eg. [ESP+0x20], or [EBP-0x28] + // VLT_STK_BYREF -- the specified stack location contains the address of the variable + // eg. mov EAX, [ESP+0x20]; [EAX] + + struct vlStk + { + RegNum vlsBaseReg; + signed vlsOffset; + }; + + // VLT_REG_REG -- TYP_LONG with both uint32_ts enregistred + // eg. RBM_EAXEDX + + struct vlRegReg + { + RegNum vlrrReg1; + RegNum vlrrReg2; + }; + + // VLT_REG_STK -- Partly enregistered TYP_LONG + // eg { LowerDWord=EAX UpperDWord=[ESP+0x8] } + + struct vlRegStk + { + RegNum vlrsReg; + struct + { + RegNum vlrssBaseReg; + signed vlrssOffset; + } vlrsStk; + }; + + // VLT_STK_REG -- Partly enregistered TYP_LONG + // eg { LowerDWord=[ESP+0x8] UpperDWord=EAX } + + struct vlStkReg + { + struct + { + RegNum vlsrsBaseReg; + signed vlsrsOffset; + } vlsrStk; + RegNum vlsrReg; + }; + + // VLT_STK2 -- Any 64 bit value which is on the stack, + // in 2 successive DWords. + // eg 2 DWords at [ESP+0x10] + + struct vlStk2 + { + RegNum vls2BaseReg; + signed vls2Offset; + }; + + // VLT_FPSTK -- enregisterd TYP_DOUBLE (on the FP stack) + // eg. ST(3). Actually it is ST("FPstkHeigth - vpFpStk") + + struct vlFPstk + { + unsigned vlfReg; + }; + + // VLT_FIXED_VA -- fixed argument of a varargs function. + // The argument location depends on the size of the variable + // arguments (...). Inspecting the VARARGS_HANDLE indicates the + // location of the first arg. This argument can then be accessed + // relative to the position of the first arg + + struct vlFixedVarArg + { + unsigned vlfvOffset; + }; + + // VLT_MEMORY + + struct vlMemory + { + void *rpValue; // pointer to the in-process + // location of the value. + }; + + struct VarLoc + { + VarLocType vlType; + + union + { + ICorDebugInfo::vlReg vlReg; + ICorDebugInfo::vlStk vlStk; + ICorDebugInfo::vlRegReg vlRegReg; + ICorDebugInfo::vlRegStk vlRegStk; + ICorDebugInfo::vlStkReg vlStkReg; + ICorDebugInfo::vlStk2 vlStk2; + ICorDebugInfo::vlFPstk vlFPstk; + ICorDebugInfo::vlFixedVarArg vlFixedVarArg; + ICorDebugInfo::vlMemory vlMemory; + }; + }; + + // This is used to report implicit/hidden arguments + + enum + { + VARARGS_HND_ILNUM = -1, // Value for the CORINFO_VARARGS_HANDLE varNumber + RETBUF_ILNUM = -2, // Pointer to the return-buffer + TYPECTXT_ILNUM = -3, // ParamTypeArg for CORINFO_GENERICS_CTXT_FROM_PARAMTYPEARG + + UNKNOWN_ILNUM = -4, // Unknown variable + + MAX_ILNUM = -4 // Sentinal value. This should be set to the largest magnitude value in th enum + // so that the compression routines know the enum's range. + }; + + struct ILVarInfo + { + uint32_t startOffset; + uint32_t endOffset; + uint32_t varNumber; + }; + + struct NativeVarInfo + { + uint32_t startOffset; + uint32_t endOffset; + uint32_t varNumber; + VarLoc loc; + }; +}; diff --git a/llvm/tools/objwriter/cvconst.h b/llvm/tools/objwriter/cvconst.h new file mode 100644 index 0000000000000..3fbbfdd011a2c --- /dev/null +++ b/llvm/tools/objwriter/cvconst.h @@ -0,0 +1,3729 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// cvconst.h - codeview constant definitions +//----------------------------------------------------------------- +// +// Copyright Microsoft Corporation. All Rights Reserved. +// +//--------------------------------------------------------------- +#ifndef _CVCONST_H_ +#define _CVCONST_H_ + + + +// Enumeration for function call type + + +typedef enum CV_call_e { + CV_CALL_NEAR_C = 0x00, // near right to left push, caller pops stack + CV_CALL_FAR_C = 0x01, // far right to left push, caller pops stack + CV_CALL_NEAR_PASCAL = 0x02, // near left to right push, callee pops stack + CV_CALL_FAR_PASCAL = 0x03, // far left to right push, callee pops stack + CV_CALL_NEAR_FAST = 0x04, // near left to right push with regs, callee pops stack + CV_CALL_FAR_FAST = 0x05, // far left to right push with regs, callee pops stack + CV_CALL_SKIPPED = 0x06, // skipped (unused) call index + CV_CALL_NEAR_STD = 0x07, // near standard call + CV_CALL_FAR_STD = 0x08, // far standard call + CV_CALL_NEAR_SYS = 0x09, // near sys call + CV_CALL_FAR_SYS = 0x0a, // far sys call + CV_CALL_THISCALL = 0x0b, // this call (this passed in register) + CV_CALL_MIPSCALL = 0x0c, // Mips call + CV_CALL_GENERIC = 0x0d, // Generic call sequence + CV_CALL_ALPHACALL = 0x0e, // Alpha call + CV_CALL_PPCCALL = 0x0f, // PPC call + CV_CALL_SHCALL = 0x10, // Hitachi SuperH call + CV_CALL_ARMCALL = 0x11, // ARM call + CV_CALL_AM33CALL = 0x12, // AM33 call + CV_CALL_TRICALL = 0x13, // TriCore Call + CV_CALL_SH5CALL = 0x14, // Hitachi SuperH-5 call + CV_CALL_M32RCALL = 0x15, // M32R Call + CV_CALL_CLRCALL = 0x16, // clr call + CV_CALL_INLINE = 0x17, // Marker for routines always inlined and thus lacking a convention + CV_CALL_NEAR_VECTOR = 0x18, // near left to right push with regs, callee pops stack + CV_CALL_RESERVED = 0x19 // first unused call enumeration + + // Do NOT add any more machine specific conventions. This is to be used for + // calling conventions in the source only (e.g. __cdecl, __stdcall). +} CV_call_e; + + +// Values for the access protection of class attributes + + +typedef enum CV_access_e { + CV_private = 1, + CV_protected = 2, + CV_public = 3 +} CV_access_e; + +typedef enum THUNK_ORDINAL { + THUNK_ORDINAL_NOTYPE, // standard thunk + THUNK_ORDINAL_ADJUSTOR, // "this" adjustor thunk + THUNK_ORDINAL_VCALL, // virtual call thunk + THUNK_ORDINAL_PCODE, // pcode thunk + THUNK_ORDINAL_LOAD, // thunk which loads the address to jump to + // via unknown means... + + // trampoline thunk ordinals - only for use in Trampoline thunk symbols + THUNK_ORDINAL_TRAMP_INCREMENTAL, + THUNK_ORDINAL_TRAMP_BRANCHISLAND, + +} THUNK_ORDINAL; + + +enum CV_SourceChksum_t { + CHKSUM_TYPE_NONE = 0, // indicates no checksum is available + CHKSUM_TYPE_MD5, + CHKSUM_TYPE_SHA1, + CHKSUM_TYPE_SHA_256, +}; + +// +// DIA enums +// + +enum SymTagEnum +{ + SymTagNull, + SymTagExe, + SymTagCompiland, + SymTagCompilandDetails, + SymTagCompilandEnv, + SymTagFunction, + SymTagBlock, + SymTagData, + SymTagAnnotation, + SymTagLabel, + SymTagPublicSymbol, + SymTagUDT, + SymTagEnum, + SymTagFunctionType, + SymTagPointerType, + SymTagArrayType, + SymTagBaseType, + SymTagTypedef, + SymTagBaseClass, + SymTagFriend, + SymTagFunctionArgType, + SymTagFuncDebugStart, + SymTagFuncDebugEnd, + SymTagUsingNamespace, + SymTagVTableShape, + SymTagVTable, + SymTagCustom, + SymTagThunk, + SymTagCustomType, + SymTagManagedType, + SymTagDimension, + SymTagCallSite, + SymTagInlineSite, + SymTagBaseInterface, + SymTagVectorType, + SymTagMatrixType, + SymTagHLSLType, + SymTagCaller, + SymTagCallee, + SymTagExport, + SymTagHeapAllocationSite, + SymTagCoffGroup, + SymTagMax +}; + +enum LocationType +{ + LocIsNull, + LocIsStatic, + LocIsTLS, + LocIsRegRel, + LocIsThisRel, + LocIsEnregistered, + LocIsBitField, + LocIsSlot, + LocIsIlRel, + LocInMetaData, + LocIsConstant, + LocTypeMax +}; + +enum DataKind +{ + DataIsUnknown, + DataIsLocal, + DataIsStaticLocal, + DataIsParam, + DataIsObjectPtr, + DataIsFileStatic, + DataIsGlobal, + DataIsMember, + DataIsStaticMember, + DataIsConstant +}; + +enum UdtKind +{ + UdtStruct, + UdtClass, + UdtUnion, + UdtInterface +}; + +enum BasicType +{ + btNoType = 0, + btVoid = 1, + btChar = 2, + btWChar = 3, + btInt = 6, + btUInt = 7, + btFloat = 8, + btBCD = 9, + btBool = 10, + btLong = 13, + btULong = 14, + btCurrency = 25, + btDate = 26, + btVariant = 27, + btComplex = 28, + btBit = 29, + btBSTR = 30, + btHresult = 31, + btChar16 = 32, // char16_t + btChar32 = 33, // char32_t +}; + + +// enumeration for type modifier values + +typedef enum CV_modifier_e { + // 0x0000 - 0x01ff - Reserved. + + CV_MOD_INVALID = 0x0000, + + // Standard modifiers. + + CV_MOD_CONST = 0x0001, + CV_MOD_VOLATILE = 0x0002, + CV_MOD_UNALIGNED = 0x0003, + + // 0x0200 - 0x03ff - HLSL modifiers. + + CV_MOD_HLSL_UNIFORM = 0x0200, + CV_MOD_HLSL_LINE = 0x0201, + CV_MOD_HLSL_TRIANGLE = 0x0202, + CV_MOD_HLSL_LINEADJ = 0x0203, + CV_MOD_HLSL_TRIANGLEADJ = 0x0204, + CV_MOD_HLSL_LINEAR = 0x0205, + CV_MOD_HLSL_CENTROID = 0x0206, + CV_MOD_HLSL_CONSTINTERP = 0x0207, + CV_MOD_HLSL_NOPERSPECTIVE = 0x0208, + CV_MOD_HLSL_SAMPLE = 0x0209, + CV_MOD_HLSL_CENTER = 0x020a, + CV_MOD_HLSL_SNORM = 0x020b, + CV_MOD_HLSL_UNORM = 0x020c, + CV_MOD_HLSL_PRECISE = 0x020d, + CV_MOD_HLSL_UAV_GLOBALLY_COHERENT = 0x020e, + + // 0x0400 - 0xffff - Unused. + +} CV_modifier_e; + + +// built-in type kinds + + +typedef enum CV_builtin_e { + + // 0x0000 - 0x01ff - Reserved. + CV_BI_INVALID = 0x0000, + + // 0x0200 - 0x03ff - HLSL types. + + CV_BI_HLSL_INTERFACE_POINTER = 0x0200, + CV_BI_HLSL_TEXTURE1D = 0x0201, + CV_BI_HLSL_TEXTURE1D_ARRAY = 0x0202, + CV_BI_HLSL_TEXTURE2D = 0x0203, + CV_BI_HLSL_TEXTURE2D_ARRAY = 0x0204, + CV_BI_HLSL_TEXTURE3D = 0x0205, + CV_BI_HLSL_TEXTURECUBE = 0x0206, + CV_BI_HLSL_TEXTURECUBE_ARRAY = 0x0207, + CV_BI_HLSL_TEXTURE2DMS = 0x0208, + CV_BI_HLSL_TEXTURE2DMS_ARRAY = 0x0209, + CV_BI_HLSL_SAMPLER = 0x020a, + CV_BI_HLSL_SAMPLERCOMPARISON = 0x020b, + CV_BI_HLSL_BUFFER = 0x020c, + CV_BI_HLSL_POINTSTREAM = 0x020d, + CV_BI_HLSL_LINESTREAM = 0x020e, + CV_BI_HLSL_TRIANGLESTREAM = 0x020f, + CV_BI_HLSL_INPUTPATCH = 0x0210, + CV_BI_HLSL_OUTPUTPATCH = 0x0211, + CV_BI_HLSL_RWTEXTURE1D = 0x0212, + CV_BI_HLSL_RWTEXTURE1D_ARRAY = 0x0213, + CV_BI_HLSL_RWTEXTURE2D = 0x0214, + CV_BI_HLSL_RWTEXTURE2D_ARRAY = 0x0215, + CV_BI_HLSL_RWTEXTURE3D = 0x0216, + CV_BI_HLSL_RWBUFFER = 0x0217, + CV_BI_HLSL_BYTEADDRESS_BUFFER = 0x0218, + CV_BI_HLSL_RWBYTEADDRESS_BUFFER = 0x0219, + CV_BI_HLSL_STRUCTURED_BUFFER = 0x021a, + CV_BI_HLSL_RWSTRUCTURED_BUFFER = 0x021b, + CV_BI_HLSL_APPEND_STRUCTURED_BUFFER = 0x021c, + CV_BI_HLSL_CONSUME_STRUCTURED_BUFFER= 0x021d, + CV_BI_HLSL_MIN8FLOAT = 0x021e, + CV_BI_HLSL_MIN10FLOAT = 0x021f, + CV_BI_HLSL_MIN16FLOAT = 0x0220, + CV_BI_HLSL_MIN12INT = 0x0221, + CV_BI_HLSL_MIN16INT = 0x0222, + CV_BI_HLSL_MIN16UINT = 0x0223, + + // 0x0400 - 0xffff - Unused. + +} CV_builtin_e; + + +// enum describing the compile flag source language + + +typedef enum CV_CFL_LANG { + CV_CFL_C = 0x00, + CV_CFL_CXX = 0x01, + CV_CFL_FORTRAN = 0x02, + CV_CFL_MASM = 0x03, + CV_CFL_PASCAL = 0x04, + CV_CFL_BASIC = 0x05, + CV_CFL_COBOL = 0x06, + CV_CFL_LINK = 0x07, + CV_CFL_CVTRES = 0x08, + CV_CFL_CVTPGD = 0x09, + CV_CFL_CSHARP = 0x0A, // C# + CV_CFL_VB = 0x0B, // Visual Basic + CV_CFL_ILASM = 0x0C, // IL (as in CLR) ASM + CV_CFL_JAVA = 0x0D, + CV_CFL_JSCRIPT = 0x0E, + CV_CFL_MSIL = 0x0F, // Unknown MSIL (LTCG of .NETMODULE) + CV_CFL_HLSL = 0x10, // High Level Shader Language +} CV_CFL_LANG; + + +// enum describing target processor + + +typedef enum CV_CPU_TYPE_e { + CV_CFL_8080 = 0x00, + CV_CFL_8086 = 0x01, + CV_CFL_80286 = 0x02, + CV_CFL_80386 = 0x03, + CV_CFL_80486 = 0x04, + CV_CFL_PENTIUM = 0x05, + CV_CFL_PENTIUMII = 0x06, + CV_CFL_PENTIUMPRO = CV_CFL_PENTIUMII, + CV_CFL_PENTIUMIII = 0x07, + CV_CFL_MIPS = 0x10, + CV_CFL_MIPSR4000 = CV_CFL_MIPS, // don't break current code + CV_CFL_MIPS16 = 0x11, + CV_CFL_MIPS32 = 0x12, + CV_CFL_MIPS64 = 0x13, + CV_CFL_MIPSI = 0x14, + CV_CFL_MIPSII = 0x15, + CV_CFL_MIPSIII = 0x16, + CV_CFL_MIPSIV = 0x17, + CV_CFL_MIPSV = 0x18, + CV_CFL_M68000 = 0x20, + CV_CFL_M68010 = 0x21, + CV_CFL_M68020 = 0x22, + CV_CFL_M68030 = 0x23, + CV_CFL_M68040 = 0x24, + CV_CFL_ALPHA = 0x30, + CV_CFL_ALPHA_21064 = 0x30, + CV_CFL_ALPHA_21164 = 0x31, + CV_CFL_ALPHA_21164A = 0x32, + CV_CFL_ALPHA_21264 = 0x33, + CV_CFL_ALPHA_21364 = 0x34, + CV_CFL_PPC601 = 0x40, + CV_CFL_PPC603 = 0x41, + CV_CFL_PPC604 = 0x42, + CV_CFL_PPC620 = 0x43, + CV_CFL_PPCFP = 0x44, + CV_CFL_PPCBE = 0x45, + CV_CFL_SH3 = 0x50, + CV_CFL_SH3E = 0x51, + CV_CFL_SH3DSP = 0x52, + CV_CFL_SH4 = 0x53, + CV_CFL_SHMEDIA = 0x54, + CV_CFL_ARM3 = 0x60, + CV_CFL_ARM4 = 0x61, + CV_CFL_ARM4T = 0x62, + CV_CFL_ARM5 = 0x63, + CV_CFL_ARM5T = 0x64, + CV_CFL_ARM6 = 0x65, + CV_CFL_ARM_XMAC = 0x66, + CV_CFL_ARM_WMMX = 0x67, + CV_CFL_ARM7 = 0x68, + CV_CFL_OMNI = 0x70, + CV_CFL_IA64 = 0x80, + CV_CFL_IA64_1 = 0x80, + CV_CFL_IA64_2 = 0x81, + CV_CFL_CEE = 0x90, + CV_CFL_AM33 = 0xA0, + CV_CFL_M32R = 0xB0, + CV_CFL_TRICORE = 0xC0, + CV_CFL_X64 = 0xD0, + CV_CFL_AMD64 = CV_CFL_X64, + CV_CFL_EBC = 0xE0, + CV_CFL_THUMB = 0xF0, + CV_CFL_ARMNT = 0xF4, + CV_CFL_ARM64 = 0xF6, + CV_CFL_D3D11_SHADER = 0x100, +} CV_CPU_TYPE_e; + +typedef enum CV_HREG_e { + // Register subset shared by all processor types, + // must not overlap with any of the ranges below, hence the high values + + CV_ALLREG_ERR = 30000, + CV_ALLREG_TEB = 30001, + CV_ALLREG_TIMER = 30002, + CV_ALLREG_EFAD1 = 30003, + CV_ALLREG_EFAD2 = 30004, + CV_ALLREG_EFAD3 = 30005, + CV_ALLREG_VFRAME= 30006, + CV_ALLREG_HANDLE= 30007, + CV_ALLREG_PARAMS= 30008, + CV_ALLREG_LOCALS= 30009, + CV_ALLREG_TID = 30010, + CV_ALLREG_ENV = 30011, + CV_ALLREG_CMDLN = 30012, + + + // Register set for the Intel 80x86 and ix86 processor series + // (plus PCODE registers) + + CV_REG_NONE = 0, + CV_REG_AL = 1, + CV_REG_CL = 2, + CV_REG_DL = 3, + CV_REG_BL = 4, + CV_REG_AH = 5, + CV_REG_CH = 6, + CV_REG_DH = 7, + CV_REG_BH = 8, + CV_REG_AX = 9, + CV_REG_CX = 10, + CV_REG_DX = 11, + CV_REG_BX = 12, + CV_REG_SP = 13, + CV_REG_BP = 14, + CV_REG_SI = 15, + CV_REG_DI = 16, + CV_REG_EAX = 17, + CV_REG_ECX = 18, + CV_REG_EDX = 19, + CV_REG_EBX = 20, + CV_REG_ESP = 21, + CV_REG_EBP = 22, + CV_REG_ESI = 23, + CV_REG_EDI = 24, + CV_REG_ES = 25, + CV_REG_CS = 26, + CV_REG_SS = 27, + CV_REG_DS = 28, + CV_REG_FS = 29, + CV_REG_GS = 30, + CV_REG_IP = 31, + CV_REG_FLAGS = 32, + CV_REG_EIP = 33, + CV_REG_EFLAGS = 34, + CV_REG_TEMP = 40, // PCODE Temp + CV_REG_TEMPH = 41, // PCODE TempH + CV_REG_QUOTE = 42, // PCODE Quote + CV_REG_PCDR3 = 43, // PCODE reserved + CV_REG_PCDR4 = 44, // PCODE reserved + CV_REG_PCDR5 = 45, // PCODE reserved + CV_REG_PCDR6 = 46, // PCODE reserved + CV_REG_PCDR7 = 47, // PCODE reserved + CV_REG_CR0 = 80, // CR0 -- control registers + CV_REG_CR1 = 81, + CV_REG_CR2 = 82, + CV_REG_CR3 = 83, + CV_REG_CR4 = 84, // Pentium + CV_REG_DR0 = 90, // Debug register + CV_REG_DR1 = 91, + CV_REG_DR2 = 92, + CV_REG_DR3 = 93, + CV_REG_DR4 = 94, + CV_REG_DR5 = 95, + CV_REG_DR6 = 96, + CV_REG_DR7 = 97, + CV_REG_GDTR = 110, + CV_REG_GDTL = 111, + CV_REG_IDTR = 112, + CV_REG_IDTL = 113, + CV_REG_LDTR = 114, + CV_REG_TR = 115, + + CV_REG_PSEUDO1 = 116, + CV_REG_PSEUDO2 = 117, + CV_REG_PSEUDO3 = 118, + CV_REG_PSEUDO4 = 119, + CV_REG_PSEUDO5 = 120, + CV_REG_PSEUDO6 = 121, + CV_REG_PSEUDO7 = 122, + CV_REG_PSEUDO8 = 123, + CV_REG_PSEUDO9 = 124, + + CV_REG_ST0 = 128, + CV_REG_ST1 = 129, + CV_REG_ST2 = 130, + CV_REG_ST3 = 131, + CV_REG_ST4 = 132, + CV_REG_ST5 = 133, + CV_REG_ST6 = 134, + CV_REG_ST7 = 135, + CV_REG_CTRL = 136, + CV_REG_STAT = 137, + CV_REG_TAG = 138, + CV_REG_FPIP = 139, + CV_REG_FPCS = 140, + CV_REG_FPDO = 141, + CV_REG_FPDS = 142, + CV_REG_ISEM = 143, + CV_REG_FPEIP = 144, + CV_REG_FPEDO = 145, + + CV_REG_MM0 = 146, + CV_REG_MM1 = 147, + CV_REG_MM2 = 148, + CV_REG_MM3 = 149, + CV_REG_MM4 = 150, + CV_REG_MM5 = 151, + CV_REG_MM6 = 152, + CV_REG_MM7 = 153, + + CV_REG_XMM0 = 154, // KATMAI registers + CV_REG_XMM1 = 155, + CV_REG_XMM2 = 156, + CV_REG_XMM3 = 157, + CV_REG_XMM4 = 158, + CV_REG_XMM5 = 159, + CV_REG_XMM6 = 160, + CV_REG_XMM7 = 161, + + CV_REG_XMM00 = 162, // KATMAI sub-registers + CV_REG_XMM01 = 163, + CV_REG_XMM02 = 164, + CV_REG_XMM03 = 165, + CV_REG_XMM10 = 166, + CV_REG_XMM11 = 167, + CV_REG_XMM12 = 168, + CV_REG_XMM13 = 169, + CV_REG_XMM20 = 170, + CV_REG_XMM21 = 171, + CV_REG_XMM22 = 172, + CV_REG_XMM23 = 173, + CV_REG_XMM30 = 174, + CV_REG_XMM31 = 175, + CV_REG_XMM32 = 176, + CV_REG_XMM33 = 177, + CV_REG_XMM40 = 178, + CV_REG_XMM41 = 179, + CV_REG_XMM42 = 180, + CV_REG_XMM43 = 181, + CV_REG_XMM50 = 182, + CV_REG_XMM51 = 183, + CV_REG_XMM52 = 184, + CV_REG_XMM53 = 185, + CV_REG_XMM60 = 186, + CV_REG_XMM61 = 187, + CV_REG_XMM62 = 188, + CV_REG_XMM63 = 189, + CV_REG_XMM70 = 190, + CV_REG_XMM71 = 191, + CV_REG_XMM72 = 192, + CV_REG_XMM73 = 193, + + CV_REG_XMM0L = 194, + CV_REG_XMM1L = 195, + CV_REG_XMM2L = 196, + CV_REG_XMM3L = 197, + CV_REG_XMM4L = 198, + CV_REG_XMM5L = 199, + CV_REG_XMM6L = 200, + CV_REG_XMM7L = 201, + + CV_REG_XMM0H = 202, + CV_REG_XMM1H = 203, + CV_REG_XMM2H = 204, + CV_REG_XMM3H = 205, + CV_REG_XMM4H = 206, + CV_REG_XMM5H = 207, + CV_REG_XMM6H = 208, + CV_REG_XMM7H = 209, + + CV_REG_MXCSR = 211, // XMM status register + + CV_REG_EDXEAX = 212, // EDX:EAX pair + + CV_REG_EMM0L = 220, // XMM sub-registers (WNI integer) + CV_REG_EMM1L = 221, + CV_REG_EMM2L = 222, + CV_REG_EMM3L = 223, + CV_REG_EMM4L = 224, + CV_REG_EMM5L = 225, + CV_REG_EMM6L = 226, + CV_REG_EMM7L = 227, + + CV_REG_EMM0H = 228, + CV_REG_EMM1H = 229, + CV_REG_EMM2H = 230, + CV_REG_EMM3H = 231, + CV_REG_EMM4H = 232, + CV_REG_EMM5H = 233, + CV_REG_EMM6H = 234, + CV_REG_EMM7H = 235, + + // do not change the order of these regs, first one must be even too + CV_REG_MM00 = 236, + CV_REG_MM01 = 237, + CV_REG_MM10 = 238, + CV_REG_MM11 = 239, + CV_REG_MM20 = 240, + CV_REG_MM21 = 241, + CV_REG_MM30 = 242, + CV_REG_MM31 = 243, + CV_REG_MM40 = 244, + CV_REG_MM41 = 245, + CV_REG_MM50 = 246, + CV_REG_MM51 = 247, + CV_REG_MM60 = 248, + CV_REG_MM61 = 249, + CV_REG_MM70 = 250, + CV_REG_MM71 = 251, + + CV_REG_YMM0 = 252, // AVX registers + CV_REG_YMM1 = 253, + CV_REG_YMM2 = 254, + CV_REG_YMM3 = 255, + CV_REG_YMM4 = 256, + CV_REG_YMM5 = 257, + CV_REG_YMM6 = 258, + CV_REG_YMM7 = 259, + + CV_REG_YMM0H = 260, + CV_REG_YMM1H = 261, + CV_REG_YMM2H = 262, + CV_REG_YMM3H = 263, + CV_REG_YMM4H = 264, + CV_REG_YMM5H = 265, + CV_REG_YMM6H = 266, + CV_REG_YMM7H = 267, + + CV_REG_YMM0I0 = 268, // AVX integer registers + CV_REG_YMM0I1 = 269, + CV_REG_YMM0I2 = 270, + CV_REG_YMM0I3 = 271, + CV_REG_YMM1I0 = 272, + CV_REG_YMM1I1 = 273, + CV_REG_YMM1I2 = 274, + CV_REG_YMM1I3 = 275, + CV_REG_YMM2I0 = 276, + CV_REG_YMM2I1 = 277, + CV_REG_YMM2I2 = 278, + CV_REG_YMM2I3 = 279, + CV_REG_YMM3I0 = 280, + CV_REG_YMM3I1 = 281, + CV_REG_YMM3I2 = 282, + CV_REG_YMM3I3 = 283, + CV_REG_YMM4I0 = 284, + CV_REG_YMM4I1 = 285, + CV_REG_YMM4I2 = 286, + CV_REG_YMM4I3 = 287, + CV_REG_YMM5I0 = 288, + CV_REG_YMM5I1 = 289, + CV_REG_YMM5I2 = 290, + CV_REG_YMM5I3 = 291, + CV_REG_YMM6I0 = 292, + CV_REG_YMM6I1 = 293, + CV_REG_YMM6I2 = 294, + CV_REG_YMM6I3 = 295, + CV_REG_YMM7I0 = 296, + CV_REG_YMM7I1 = 297, + CV_REG_YMM7I2 = 298, + CV_REG_YMM7I3 = 299, + + CV_REG_YMM0F0 = 300, // AVX floating-point single precise registers + CV_REG_YMM0F1 = 301, + CV_REG_YMM0F2 = 302, + CV_REG_YMM0F3 = 303, + CV_REG_YMM0F4 = 304, + CV_REG_YMM0F5 = 305, + CV_REG_YMM0F6 = 306, + CV_REG_YMM0F7 = 307, + CV_REG_YMM1F0 = 308, + CV_REG_YMM1F1 = 309, + CV_REG_YMM1F2 = 310, + CV_REG_YMM1F3 = 311, + CV_REG_YMM1F4 = 312, + CV_REG_YMM1F5 = 313, + CV_REG_YMM1F6 = 314, + CV_REG_YMM1F7 = 315, + CV_REG_YMM2F0 = 316, + CV_REG_YMM2F1 = 317, + CV_REG_YMM2F2 = 318, + CV_REG_YMM2F3 = 319, + CV_REG_YMM2F4 = 320, + CV_REG_YMM2F5 = 321, + CV_REG_YMM2F6 = 322, + CV_REG_YMM2F7 = 323, + CV_REG_YMM3F0 = 324, + CV_REG_YMM3F1 = 325, + CV_REG_YMM3F2 = 326, + CV_REG_YMM3F3 = 327, + CV_REG_YMM3F4 = 328, + CV_REG_YMM3F5 = 329, + CV_REG_YMM3F6 = 330, + CV_REG_YMM3F7 = 331, + CV_REG_YMM4F0 = 332, + CV_REG_YMM4F1 = 333, + CV_REG_YMM4F2 = 334, + CV_REG_YMM4F3 = 335, + CV_REG_YMM4F4 = 336, + CV_REG_YMM4F5 = 337, + CV_REG_YMM4F6 = 338, + CV_REG_YMM4F7 = 339, + CV_REG_YMM5F0 = 340, + CV_REG_YMM5F1 = 341, + CV_REG_YMM5F2 = 342, + CV_REG_YMM5F3 = 343, + CV_REG_YMM5F4 = 344, + CV_REG_YMM5F5 = 345, + CV_REG_YMM5F6 = 346, + CV_REG_YMM5F7 = 347, + CV_REG_YMM6F0 = 348, + CV_REG_YMM6F1 = 349, + CV_REG_YMM6F2 = 350, + CV_REG_YMM6F3 = 351, + CV_REG_YMM6F4 = 352, + CV_REG_YMM6F5 = 353, + CV_REG_YMM6F6 = 354, + CV_REG_YMM6F7 = 355, + CV_REG_YMM7F0 = 356, + CV_REG_YMM7F1 = 357, + CV_REG_YMM7F2 = 358, + CV_REG_YMM7F3 = 359, + CV_REG_YMM7F4 = 360, + CV_REG_YMM7F5 = 361, + CV_REG_YMM7F6 = 362, + CV_REG_YMM7F7 = 363, + + CV_REG_YMM0D0 = 364, // AVX floating-point double precise registers + CV_REG_YMM0D1 = 365, + CV_REG_YMM0D2 = 366, + CV_REG_YMM0D3 = 367, + CV_REG_YMM1D0 = 368, + CV_REG_YMM1D1 = 369, + CV_REG_YMM1D2 = 370, + CV_REG_YMM1D3 = 371, + CV_REG_YMM2D0 = 372, + CV_REG_YMM2D1 = 373, + CV_REG_YMM2D2 = 374, + CV_REG_YMM2D3 = 375, + CV_REG_YMM3D0 = 376, + CV_REG_YMM3D1 = 377, + CV_REG_YMM3D2 = 378, + CV_REG_YMM3D3 = 379, + CV_REG_YMM4D0 = 380, + CV_REG_YMM4D1 = 381, + CV_REG_YMM4D2 = 382, + CV_REG_YMM4D3 = 383, + CV_REG_YMM5D0 = 384, + CV_REG_YMM5D1 = 385, + CV_REG_YMM5D2 = 386, + CV_REG_YMM5D3 = 387, + CV_REG_YMM6D0 = 388, + CV_REG_YMM6D1 = 389, + CV_REG_YMM6D2 = 390, + CV_REG_YMM6D3 = 391, + CV_REG_YMM7D0 = 392, + CV_REG_YMM7D1 = 393, + CV_REG_YMM7D2 = 394, + CV_REG_YMM7D3 = 395, + + CV_REG_BND0 = 396, + CV_REG_BND1 = 397, + CV_REG_BND2 = 398, + CV_REG_BND3 = 399, + + // registers for the 68K processors + + CV_R68_D0 = 0, + CV_R68_D1 = 1, + CV_R68_D2 = 2, + CV_R68_D3 = 3, + CV_R68_D4 = 4, + CV_R68_D5 = 5, + CV_R68_D6 = 6, + CV_R68_D7 = 7, + CV_R68_A0 = 8, + CV_R68_A1 = 9, + CV_R68_A2 = 10, + CV_R68_A3 = 11, + CV_R68_A4 = 12, + CV_R68_A5 = 13, + CV_R68_A6 = 14, + CV_R68_A7 = 15, + CV_R68_CCR = 16, + CV_R68_SR = 17, + CV_R68_USP = 18, + CV_R68_MSP = 19, + CV_R68_SFC = 20, + CV_R68_DFC = 21, + CV_R68_CACR = 22, + CV_R68_VBR = 23, + CV_R68_CAAR = 24, + CV_R68_ISP = 25, + CV_R68_PC = 26, + //reserved 27 + CV_R68_FPCR = 28, + CV_R68_FPSR = 29, + CV_R68_FPIAR = 30, + //reserved 31 + CV_R68_FP0 = 32, + CV_R68_FP1 = 33, + CV_R68_FP2 = 34, + CV_R68_FP3 = 35, + CV_R68_FP4 = 36, + CV_R68_FP5 = 37, + CV_R68_FP6 = 38, + CV_R68_FP7 = 39, + //reserved 40 + CV_R68_MMUSR030 = 41, + CV_R68_MMUSR = 42, + CV_R68_URP = 43, + CV_R68_DTT0 = 44, + CV_R68_DTT1 = 45, + CV_R68_ITT0 = 46, + CV_R68_ITT1 = 47, + //reserved 50 + CV_R68_PSR = 51, + CV_R68_PCSR = 52, + CV_R68_VAL = 53, + CV_R68_CRP = 54, + CV_R68_SRP = 55, + CV_R68_DRP = 56, + CV_R68_TC = 57, + CV_R68_AC = 58, + CV_R68_SCC = 59, + CV_R68_CAL = 60, + CV_R68_TT0 = 61, + CV_R68_TT1 = 62, + //reserved 63 + CV_R68_BAD0 = 64, + CV_R68_BAD1 = 65, + CV_R68_BAD2 = 66, + CV_R68_BAD3 = 67, + CV_R68_BAD4 = 68, + CV_R68_BAD5 = 69, + CV_R68_BAD6 = 70, + CV_R68_BAD7 = 71, + CV_R68_BAC0 = 72, + CV_R68_BAC1 = 73, + CV_R68_BAC2 = 74, + CV_R68_BAC3 = 75, + CV_R68_BAC4 = 76, + CV_R68_BAC5 = 77, + CV_R68_BAC6 = 78, + CV_R68_BAC7 = 79, + + // Register set for the MIPS 4000 + + CV_M4_NOREG = CV_REG_NONE, + + CV_M4_IntZERO = 10, /* CPU REGISTER */ + CV_M4_IntAT = 11, + CV_M4_IntV0 = 12, + CV_M4_IntV1 = 13, + CV_M4_IntA0 = 14, + CV_M4_IntA1 = 15, + CV_M4_IntA2 = 16, + CV_M4_IntA3 = 17, + CV_M4_IntT0 = 18, + CV_M4_IntT1 = 19, + CV_M4_IntT2 = 20, + CV_M4_IntT3 = 21, + CV_M4_IntT4 = 22, + CV_M4_IntT5 = 23, + CV_M4_IntT6 = 24, + CV_M4_IntT7 = 25, + CV_M4_IntS0 = 26, + CV_M4_IntS1 = 27, + CV_M4_IntS2 = 28, + CV_M4_IntS3 = 29, + CV_M4_IntS4 = 30, + CV_M4_IntS5 = 31, + CV_M4_IntS6 = 32, + CV_M4_IntS7 = 33, + CV_M4_IntT8 = 34, + CV_M4_IntT9 = 35, + CV_M4_IntKT0 = 36, + CV_M4_IntKT1 = 37, + CV_M4_IntGP = 38, + CV_M4_IntSP = 39, + CV_M4_IntS8 = 40, + CV_M4_IntRA = 41, + CV_M4_IntLO = 42, + CV_M4_IntHI = 43, + + CV_M4_Fir = 50, + CV_M4_Psr = 51, + + CV_M4_FltF0 = 60, /* Floating point registers */ + CV_M4_FltF1 = 61, + CV_M4_FltF2 = 62, + CV_M4_FltF3 = 63, + CV_M4_FltF4 = 64, + CV_M4_FltF5 = 65, + CV_M4_FltF6 = 66, + CV_M4_FltF7 = 67, + CV_M4_FltF8 = 68, + CV_M4_FltF9 = 69, + CV_M4_FltF10 = 70, + CV_M4_FltF11 = 71, + CV_M4_FltF12 = 72, + CV_M4_FltF13 = 73, + CV_M4_FltF14 = 74, + CV_M4_FltF15 = 75, + CV_M4_FltF16 = 76, + CV_M4_FltF17 = 77, + CV_M4_FltF18 = 78, + CV_M4_FltF19 = 79, + CV_M4_FltF20 = 80, + CV_M4_FltF21 = 81, + CV_M4_FltF22 = 82, + CV_M4_FltF23 = 83, + CV_M4_FltF24 = 84, + CV_M4_FltF25 = 85, + CV_M4_FltF26 = 86, + CV_M4_FltF27 = 87, + CV_M4_FltF28 = 88, + CV_M4_FltF29 = 89, + CV_M4_FltF30 = 90, + CV_M4_FltF31 = 91, + CV_M4_FltFsr = 92, + + + // Register set for the ALPHA AXP + + CV_ALPHA_NOREG = CV_REG_NONE, + + CV_ALPHA_FltF0 = 10, // Floating point registers + CV_ALPHA_FltF1 = 11, + CV_ALPHA_FltF2 = 12, + CV_ALPHA_FltF3 = 13, + CV_ALPHA_FltF4 = 14, + CV_ALPHA_FltF5 = 15, + CV_ALPHA_FltF6 = 16, + CV_ALPHA_FltF7 = 17, + CV_ALPHA_FltF8 = 18, + CV_ALPHA_FltF9 = 19, + CV_ALPHA_FltF10 = 20, + CV_ALPHA_FltF11 = 21, + CV_ALPHA_FltF12 = 22, + CV_ALPHA_FltF13 = 23, + CV_ALPHA_FltF14 = 24, + CV_ALPHA_FltF15 = 25, + CV_ALPHA_FltF16 = 26, + CV_ALPHA_FltF17 = 27, + CV_ALPHA_FltF18 = 28, + CV_ALPHA_FltF19 = 29, + CV_ALPHA_FltF20 = 30, + CV_ALPHA_FltF21 = 31, + CV_ALPHA_FltF22 = 32, + CV_ALPHA_FltF23 = 33, + CV_ALPHA_FltF24 = 34, + CV_ALPHA_FltF25 = 35, + CV_ALPHA_FltF26 = 36, + CV_ALPHA_FltF27 = 37, + CV_ALPHA_FltF28 = 38, + CV_ALPHA_FltF29 = 39, + CV_ALPHA_FltF30 = 40, + CV_ALPHA_FltF31 = 41, + + CV_ALPHA_IntV0 = 42, // Integer registers + CV_ALPHA_IntT0 = 43, + CV_ALPHA_IntT1 = 44, + CV_ALPHA_IntT2 = 45, + CV_ALPHA_IntT3 = 46, + CV_ALPHA_IntT4 = 47, + CV_ALPHA_IntT5 = 48, + CV_ALPHA_IntT6 = 49, + CV_ALPHA_IntT7 = 50, + CV_ALPHA_IntS0 = 51, + CV_ALPHA_IntS1 = 52, + CV_ALPHA_IntS2 = 53, + CV_ALPHA_IntS3 = 54, + CV_ALPHA_IntS4 = 55, + CV_ALPHA_IntS5 = 56, + CV_ALPHA_IntFP = 57, + CV_ALPHA_IntA0 = 58, + CV_ALPHA_IntA1 = 59, + CV_ALPHA_IntA2 = 60, + CV_ALPHA_IntA3 = 61, + CV_ALPHA_IntA4 = 62, + CV_ALPHA_IntA5 = 63, + CV_ALPHA_IntT8 = 64, + CV_ALPHA_IntT9 = 65, + CV_ALPHA_IntT10 = 66, + CV_ALPHA_IntT11 = 67, + CV_ALPHA_IntRA = 68, + CV_ALPHA_IntT12 = 69, + CV_ALPHA_IntAT = 70, + CV_ALPHA_IntGP = 71, + CV_ALPHA_IntSP = 72, + CV_ALPHA_IntZERO = 73, + + + CV_ALPHA_Fpcr = 74, // Control registers + CV_ALPHA_Fir = 75, + CV_ALPHA_Psr = 76, + CV_ALPHA_FltFsr = 77, + CV_ALPHA_SoftFpcr = 78, + + // Register Set for Motorola/IBM PowerPC + + /* + ** PowerPC General Registers ( User Level ) + */ + CV_PPC_GPR0 = 1, + CV_PPC_GPR1 = 2, + CV_PPC_GPR2 = 3, + CV_PPC_GPR3 = 4, + CV_PPC_GPR4 = 5, + CV_PPC_GPR5 = 6, + CV_PPC_GPR6 = 7, + CV_PPC_GPR7 = 8, + CV_PPC_GPR8 = 9, + CV_PPC_GPR9 = 10, + CV_PPC_GPR10 = 11, + CV_PPC_GPR11 = 12, + CV_PPC_GPR12 = 13, + CV_PPC_GPR13 = 14, + CV_PPC_GPR14 = 15, + CV_PPC_GPR15 = 16, + CV_PPC_GPR16 = 17, + CV_PPC_GPR17 = 18, + CV_PPC_GPR18 = 19, + CV_PPC_GPR19 = 20, + CV_PPC_GPR20 = 21, + CV_PPC_GPR21 = 22, + CV_PPC_GPR22 = 23, + CV_PPC_GPR23 = 24, + CV_PPC_GPR24 = 25, + CV_PPC_GPR25 = 26, + CV_PPC_GPR26 = 27, + CV_PPC_GPR27 = 28, + CV_PPC_GPR28 = 29, + CV_PPC_GPR29 = 30, + CV_PPC_GPR30 = 31, + CV_PPC_GPR31 = 32, + + /* + ** PowerPC Condition Register ( User Level ) + */ + CV_PPC_CR = 33, + CV_PPC_CR0 = 34, + CV_PPC_CR1 = 35, + CV_PPC_CR2 = 36, + CV_PPC_CR3 = 37, + CV_PPC_CR4 = 38, + CV_PPC_CR5 = 39, + CV_PPC_CR6 = 40, + CV_PPC_CR7 = 41, + + /* + ** PowerPC Floating Point Registers ( User Level ) + */ + CV_PPC_FPR0 = 42, + CV_PPC_FPR1 = 43, + CV_PPC_FPR2 = 44, + CV_PPC_FPR3 = 45, + CV_PPC_FPR4 = 46, + CV_PPC_FPR5 = 47, + CV_PPC_FPR6 = 48, + CV_PPC_FPR7 = 49, + CV_PPC_FPR8 = 50, + CV_PPC_FPR9 = 51, + CV_PPC_FPR10 = 52, + CV_PPC_FPR11 = 53, + CV_PPC_FPR12 = 54, + CV_PPC_FPR13 = 55, + CV_PPC_FPR14 = 56, + CV_PPC_FPR15 = 57, + CV_PPC_FPR16 = 58, + CV_PPC_FPR17 = 59, + CV_PPC_FPR18 = 60, + CV_PPC_FPR19 = 61, + CV_PPC_FPR20 = 62, + CV_PPC_FPR21 = 63, + CV_PPC_FPR22 = 64, + CV_PPC_FPR23 = 65, + CV_PPC_FPR24 = 66, + CV_PPC_FPR25 = 67, + CV_PPC_FPR26 = 68, + CV_PPC_FPR27 = 69, + CV_PPC_FPR28 = 70, + CV_PPC_FPR29 = 71, + CV_PPC_FPR30 = 72, + CV_PPC_FPR31 = 73, + + /* + ** PowerPC Floating Point Status and Control Register ( User Level ) + */ + CV_PPC_FPSCR = 74, + + /* + ** PowerPC Machine State Register ( Supervisor Level ) + */ + CV_PPC_MSR = 75, + + /* + ** PowerPC Segment Registers ( Supervisor Level ) + */ + CV_PPC_SR0 = 76, + CV_PPC_SR1 = 77, + CV_PPC_SR2 = 78, + CV_PPC_SR3 = 79, + CV_PPC_SR4 = 80, + CV_PPC_SR5 = 81, + CV_PPC_SR6 = 82, + CV_PPC_SR7 = 83, + CV_PPC_SR8 = 84, + CV_PPC_SR9 = 85, + CV_PPC_SR10 = 86, + CV_PPC_SR11 = 87, + CV_PPC_SR12 = 88, + CV_PPC_SR13 = 89, + CV_PPC_SR14 = 90, + CV_PPC_SR15 = 91, + + /* + ** For all of the special purpose registers add 100 to the SPR# that the + ** Motorola/IBM documentation gives with the exception of any imaginary + ** registers. + */ + + /* + ** PowerPC Special Purpose Registers ( User Level ) + */ + CV_PPC_PC = 99, // PC (imaginary register) + + CV_PPC_MQ = 100, // MPC601 + CV_PPC_XER = 101, + CV_PPC_RTCU = 104, // MPC601 + CV_PPC_RTCL = 105, // MPC601 + CV_PPC_LR = 108, + CV_PPC_CTR = 109, + + CV_PPC_COMPARE = 110, // part of XER (internal to the debugger only) + CV_PPC_COUNT = 111, // part of XER (internal to the debugger only) + + /* + ** PowerPC Special Purpose Registers ( Supervisor Level ) + */ + CV_PPC_DSISR = 118, + CV_PPC_DAR = 119, + CV_PPC_DEC = 122, + CV_PPC_SDR1 = 125, + CV_PPC_SRR0 = 126, + CV_PPC_SRR1 = 127, + CV_PPC_SPRG0 = 372, + CV_PPC_SPRG1 = 373, + CV_PPC_SPRG2 = 374, + CV_PPC_SPRG3 = 375, + CV_PPC_ASR = 280, // 64-bit implementations only + CV_PPC_EAR = 382, + CV_PPC_PVR = 287, + CV_PPC_BAT0U = 628, + CV_PPC_BAT0L = 629, + CV_PPC_BAT1U = 630, + CV_PPC_BAT1L = 631, + CV_PPC_BAT2U = 632, + CV_PPC_BAT2L = 633, + CV_PPC_BAT3U = 634, + CV_PPC_BAT3L = 635, + CV_PPC_DBAT0U = 636, + CV_PPC_DBAT0L = 637, + CV_PPC_DBAT1U = 638, + CV_PPC_DBAT1L = 639, + CV_PPC_DBAT2U = 640, + CV_PPC_DBAT2L = 641, + CV_PPC_DBAT3U = 642, + CV_PPC_DBAT3L = 643, + + /* + ** PowerPC Special Purpose Registers Implementation Dependent ( Supervisor Level ) + */ + + /* + ** Doesn't appear that IBM/Motorola has finished defining these. + */ + + CV_PPC_PMR0 = 1044, // MPC620, + CV_PPC_PMR1 = 1045, // MPC620, + CV_PPC_PMR2 = 1046, // MPC620, + CV_PPC_PMR3 = 1047, // MPC620, + CV_PPC_PMR4 = 1048, // MPC620, + CV_PPC_PMR5 = 1049, // MPC620, + CV_PPC_PMR6 = 1050, // MPC620, + CV_PPC_PMR7 = 1051, // MPC620, + CV_PPC_PMR8 = 1052, // MPC620, + CV_PPC_PMR9 = 1053, // MPC620, + CV_PPC_PMR10 = 1054, // MPC620, + CV_PPC_PMR11 = 1055, // MPC620, + CV_PPC_PMR12 = 1056, // MPC620, + CV_PPC_PMR13 = 1057, // MPC620, + CV_PPC_PMR14 = 1058, // MPC620, + CV_PPC_PMR15 = 1059, // MPC620, + + CV_PPC_DMISS = 1076, // MPC603 + CV_PPC_DCMP = 1077, // MPC603 + CV_PPC_HASH1 = 1078, // MPC603 + CV_PPC_HASH2 = 1079, // MPC603 + CV_PPC_IMISS = 1080, // MPC603 + CV_PPC_ICMP = 1081, // MPC603 + CV_PPC_RPA = 1082, // MPC603 + + CV_PPC_HID0 = 1108, // MPC601, MPC603, MPC620 + CV_PPC_HID1 = 1109, // MPC601 + CV_PPC_HID2 = 1110, // MPC601, MPC603, MPC620 ( IABR ) + CV_PPC_HID3 = 1111, // Not Defined + CV_PPC_HID4 = 1112, // Not Defined + CV_PPC_HID5 = 1113, // MPC601, MPC604, MPC620 ( DABR ) + CV_PPC_HID6 = 1114, // Not Defined + CV_PPC_HID7 = 1115, // Not Defined + CV_PPC_HID8 = 1116, // MPC620 ( BUSCSR ) + CV_PPC_HID9 = 1117, // MPC620 ( L2CSR ) + CV_PPC_HID10 = 1118, // Not Defined + CV_PPC_HID11 = 1119, // Not Defined + CV_PPC_HID12 = 1120, // Not Defined + CV_PPC_HID13 = 1121, // MPC604 ( HCR ) + CV_PPC_HID14 = 1122, // Not Defined + CV_PPC_HID15 = 1123, // MPC601, MPC604, MPC620 ( PIR ) + + // + // JAVA VM registers + // + + CV_JAVA_PC = 1, + + // + // Register set for the Hitachi SH3 + // + + CV_SH3_NOREG = CV_REG_NONE, + + CV_SH3_IntR0 = 10, // CPU REGISTER + CV_SH3_IntR1 = 11, + CV_SH3_IntR2 = 12, + CV_SH3_IntR3 = 13, + CV_SH3_IntR4 = 14, + CV_SH3_IntR5 = 15, + CV_SH3_IntR6 = 16, + CV_SH3_IntR7 = 17, + CV_SH3_IntR8 = 18, + CV_SH3_IntR9 = 19, + CV_SH3_IntR10 = 20, + CV_SH3_IntR11 = 21, + CV_SH3_IntR12 = 22, + CV_SH3_IntR13 = 23, + CV_SH3_IntFp = 24, + CV_SH3_IntSp = 25, + CV_SH3_Gbr = 38, + CV_SH3_Pr = 39, + CV_SH3_Mach = 40, + CV_SH3_Macl = 41, + + CV_SH3_Pc = 50, + CV_SH3_Sr = 51, + + CV_SH3_BarA = 60, + CV_SH3_BasrA = 61, + CV_SH3_BamrA = 62, + CV_SH3_BbrA = 63, + CV_SH3_BarB = 64, + CV_SH3_BasrB = 65, + CV_SH3_BamrB = 66, + CV_SH3_BbrB = 67, + CV_SH3_BdrB = 68, + CV_SH3_BdmrB = 69, + CV_SH3_Brcr = 70, + + // + // Additional registers for Hitachi SH processors + // + + CV_SH_Fpscr = 75, // floating point status/control register + CV_SH_Fpul = 76, // floating point communication register + + CV_SH_FpR0 = 80, // Floating point registers + CV_SH_FpR1 = 81, + CV_SH_FpR2 = 82, + CV_SH_FpR3 = 83, + CV_SH_FpR4 = 84, + CV_SH_FpR5 = 85, + CV_SH_FpR6 = 86, + CV_SH_FpR7 = 87, + CV_SH_FpR8 = 88, + CV_SH_FpR9 = 89, + CV_SH_FpR10 = 90, + CV_SH_FpR11 = 91, + CV_SH_FpR12 = 92, + CV_SH_FpR13 = 93, + CV_SH_FpR14 = 94, + CV_SH_FpR15 = 95, + + CV_SH_XFpR0 = 96, + CV_SH_XFpR1 = 97, + CV_SH_XFpR2 = 98, + CV_SH_XFpR3 = 99, + CV_SH_XFpR4 = 100, + CV_SH_XFpR5 = 101, + CV_SH_XFpR6 = 102, + CV_SH_XFpR7 = 103, + CV_SH_XFpR8 = 104, + CV_SH_XFpR9 = 105, + CV_SH_XFpR10 = 106, + CV_SH_XFpR11 = 107, + CV_SH_XFpR12 = 108, + CV_SH_XFpR13 = 109, + CV_SH_XFpR14 = 110, + CV_SH_XFpR15 = 111, + + // + // Register set for the ARM processor. + // + + CV_ARM_NOREG = CV_REG_NONE, + + CV_ARM_R0 = 10, + CV_ARM_R1 = 11, + CV_ARM_R2 = 12, + CV_ARM_R3 = 13, + CV_ARM_R4 = 14, + CV_ARM_R5 = 15, + CV_ARM_R6 = 16, + CV_ARM_R7 = 17, + CV_ARM_R8 = 18, + CV_ARM_R9 = 19, + CV_ARM_R10 = 20, + CV_ARM_R11 = 21, // Frame pointer, if allocated + CV_ARM_R12 = 22, + CV_ARM_SP = 23, // Stack pointer + CV_ARM_LR = 24, // Link Register + CV_ARM_PC = 25, // Program counter + CV_ARM_CPSR = 26, // Current program status register + + CV_ARM_ACC0 = 27, // DSP co-processor 0 40 bit accumulator + + // + // Registers for ARM VFP10 support + // + + CV_ARM_FPSCR = 40, + CV_ARM_FPEXC = 41, + + CV_ARM_FS0 = 50, + CV_ARM_FS1 = 51, + CV_ARM_FS2 = 52, + CV_ARM_FS3 = 53, + CV_ARM_FS4 = 54, + CV_ARM_FS5 = 55, + CV_ARM_FS6 = 56, + CV_ARM_FS7 = 57, + CV_ARM_FS8 = 58, + CV_ARM_FS9 = 59, + CV_ARM_FS10 = 60, + CV_ARM_FS11 = 61, + CV_ARM_FS12 = 62, + CV_ARM_FS13 = 63, + CV_ARM_FS14 = 64, + CV_ARM_FS15 = 65, + CV_ARM_FS16 = 66, + CV_ARM_FS17 = 67, + CV_ARM_FS18 = 68, + CV_ARM_FS19 = 69, + CV_ARM_FS20 = 70, + CV_ARM_FS21 = 71, + CV_ARM_FS22 = 72, + CV_ARM_FS23 = 73, + CV_ARM_FS24 = 74, + CV_ARM_FS25 = 75, + CV_ARM_FS26 = 76, + CV_ARM_FS27 = 77, + CV_ARM_FS28 = 78, + CV_ARM_FS29 = 79, + CV_ARM_FS30 = 80, + CV_ARM_FS31 = 81, + + // + // ARM VFP Floating Point Extra control registers + // + + CV_ARM_FPEXTRA0 = 90, + CV_ARM_FPEXTRA1 = 91, + CV_ARM_FPEXTRA2 = 92, + CV_ARM_FPEXTRA3 = 93, + CV_ARM_FPEXTRA4 = 94, + CV_ARM_FPEXTRA5 = 95, + CV_ARM_FPEXTRA6 = 96, + CV_ARM_FPEXTRA7 = 97, + + // XSCALE Concan co-processor registers + CV_ARM_WR0 = 128, + CV_ARM_WR1 = 129, + CV_ARM_WR2 = 130, + CV_ARM_WR3 = 131, + CV_ARM_WR4 = 132, + CV_ARM_WR5 = 133, + CV_ARM_WR6 = 134, + CV_ARM_WR7 = 135, + CV_ARM_WR8 = 136, + CV_ARM_WR9 = 137, + CV_ARM_WR10 = 138, + CV_ARM_WR11 = 139, + CV_ARM_WR12 = 140, + CV_ARM_WR13 = 141, + CV_ARM_WR14 = 142, + CV_ARM_WR15 = 143, + + // XSCALE Concan co-processor control registers + CV_ARM_WCID = 144, + CV_ARM_WCON = 145, + CV_ARM_WCSSF = 146, + CV_ARM_WCASF = 147, + CV_ARM_WC4 = 148, + CV_ARM_WC5 = 149, + CV_ARM_WC6 = 150, + CV_ARM_WC7 = 151, + CV_ARM_WCGR0 = 152, + CV_ARM_WCGR1 = 153, + CV_ARM_WCGR2 = 154, + CV_ARM_WCGR3 = 155, + CV_ARM_WC12 = 156, + CV_ARM_WC13 = 157, + CV_ARM_WC14 = 158, + CV_ARM_WC15 = 159, + + // + // ARM VFPv3/Neon extended floating Point + // + + CV_ARM_FS32 = 200, + CV_ARM_FS33 = 201, + CV_ARM_FS34 = 202, + CV_ARM_FS35 = 203, + CV_ARM_FS36 = 204, + CV_ARM_FS37 = 205, + CV_ARM_FS38 = 206, + CV_ARM_FS39 = 207, + CV_ARM_FS40 = 208, + CV_ARM_FS41 = 209, + CV_ARM_FS42 = 210, + CV_ARM_FS43 = 211, + CV_ARM_FS44 = 212, + CV_ARM_FS45 = 213, + CV_ARM_FS46 = 214, + CV_ARM_FS47 = 215, + CV_ARM_FS48 = 216, + CV_ARM_FS49 = 217, + CV_ARM_FS50 = 218, + CV_ARM_FS51 = 219, + CV_ARM_FS52 = 220, + CV_ARM_FS53 = 221, + CV_ARM_FS54 = 222, + CV_ARM_FS55 = 223, + CV_ARM_FS56 = 224, + CV_ARM_FS57 = 225, + CV_ARM_FS58 = 226, + CV_ARM_FS59 = 227, + CV_ARM_FS60 = 228, + CV_ARM_FS61 = 229, + CV_ARM_FS62 = 230, + CV_ARM_FS63 = 231, + + // ARM double-precision floating point + + CV_ARM_ND0 = 300, + CV_ARM_ND1 = 301, + CV_ARM_ND2 = 302, + CV_ARM_ND3 = 303, + CV_ARM_ND4 = 304, + CV_ARM_ND5 = 305, + CV_ARM_ND6 = 306, + CV_ARM_ND7 = 307, + CV_ARM_ND8 = 308, + CV_ARM_ND9 = 309, + CV_ARM_ND10 = 310, + CV_ARM_ND11 = 311, + CV_ARM_ND12 = 312, + CV_ARM_ND13 = 313, + CV_ARM_ND14 = 314, + CV_ARM_ND15 = 315, + CV_ARM_ND16 = 316, + CV_ARM_ND17 = 317, + CV_ARM_ND18 = 318, + CV_ARM_ND19 = 319, + CV_ARM_ND20 = 320, + CV_ARM_ND21 = 321, + CV_ARM_ND22 = 322, + CV_ARM_ND23 = 323, + CV_ARM_ND24 = 324, + CV_ARM_ND25 = 325, + CV_ARM_ND26 = 326, + CV_ARM_ND27 = 327, + CV_ARM_ND28 = 328, + CV_ARM_ND29 = 329, + CV_ARM_ND30 = 330, + CV_ARM_ND31 = 331, + + // ARM extended precision floating point + + CV_ARM_NQ0 = 400, + CV_ARM_NQ1 = 401, + CV_ARM_NQ2 = 402, + CV_ARM_NQ3 = 403, + CV_ARM_NQ4 = 404, + CV_ARM_NQ5 = 405, + CV_ARM_NQ6 = 406, + CV_ARM_NQ7 = 407, + CV_ARM_NQ8 = 408, + CV_ARM_NQ9 = 409, + CV_ARM_NQ10 = 410, + CV_ARM_NQ11 = 411, + CV_ARM_NQ12 = 412, + CV_ARM_NQ13 = 413, + CV_ARM_NQ14 = 414, + CV_ARM_NQ15 = 415, + + // + // Register set for ARM64 + // + + CV_ARM64_NOREG = CV_REG_NONE, + + // General purpose 32-bit integer registers + + CV_ARM64_W0 = 10, + CV_ARM64_W1 = 11, + CV_ARM64_W2 = 12, + CV_ARM64_W3 = 13, + CV_ARM64_W4 = 14, + CV_ARM64_W5 = 15, + CV_ARM64_W6 = 16, + CV_ARM64_W7 = 17, + CV_ARM64_W8 = 18, + CV_ARM64_W9 = 19, + CV_ARM64_W10 = 20, + CV_ARM64_W11 = 21, + CV_ARM64_W12 = 22, + CV_ARM64_W13 = 23, + CV_ARM64_W14 = 24, + CV_ARM64_W15 = 25, + CV_ARM64_W16 = 26, + CV_ARM64_W17 = 27, + CV_ARM64_W18 = 28, + CV_ARM64_W19 = 29, + CV_ARM64_W20 = 30, + CV_ARM64_W21 = 31, + CV_ARM64_W22 = 32, + CV_ARM64_W23 = 33, + CV_ARM64_W24 = 34, + CV_ARM64_W25 = 35, + CV_ARM64_W26 = 36, + CV_ARM64_W27 = 37, + CV_ARM64_W28 = 38, + CV_ARM64_W29 = 39, + CV_ARM64_W30 = 40, + CV_ARM64_WZR = 41, + + // General purpose 64-bit integer registers + + CV_ARM64_X0 = 50, + CV_ARM64_X1 = 51, + CV_ARM64_X2 = 52, + CV_ARM64_X3 = 53, + CV_ARM64_X4 = 54, + CV_ARM64_X5 = 55, + CV_ARM64_X6 = 56, + CV_ARM64_X7 = 57, + CV_ARM64_X8 = 58, + CV_ARM64_X9 = 59, + CV_ARM64_X10 = 60, + CV_ARM64_X11 = 61, + CV_ARM64_X12 = 62, + CV_ARM64_X13 = 63, + CV_ARM64_X14 = 64, + CV_ARM64_X15 = 65, + CV_ARM64_IP0 = 66, + CV_ARM64_IP1 = 67, + CV_ARM64_X18 = 68, + CV_ARM64_X19 = 69, + CV_ARM64_X20 = 70, + CV_ARM64_X21 = 71, + CV_ARM64_X22 = 72, + CV_ARM64_X23 = 73, + CV_ARM64_X24 = 74, + CV_ARM64_X25 = 75, + CV_ARM64_X26 = 76, + CV_ARM64_X27 = 77, + CV_ARM64_X28 = 78, + CV_ARM64_FP = 79, + CV_ARM64_LR = 80, + CV_ARM64_SP = 81, + CV_ARM64_ZR = 82, + CV_ARM64_PC = 83, + + // status registers + + CV_ARM64_NZCV = 90, + CV_ARM64_CPSR = 91, + + // 32-bit floating point registers + + CV_ARM64_S0 = 100, + CV_ARM64_S1 = 101, + CV_ARM64_S2 = 102, + CV_ARM64_S3 = 103, + CV_ARM64_S4 = 104, + CV_ARM64_S5 = 105, + CV_ARM64_S6 = 106, + CV_ARM64_S7 = 107, + CV_ARM64_S8 = 108, + CV_ARM64_S9 = 109, + CV_ARM64_S10 = 110, + CV_ARM64_S11 = 111, + CV_ARM64_S12 = 112, + CV_ARM64_S13 = 113, + CV_ARM64_S14 = 114, + CV_ARM64_S15 = 115, + CV_ARM64_S16 = 116, + CV_ARM64_S17 = 117, + CV_ARM64_S18 = 118, + CV_ARM64_S19 = 119, + CV_ARM64_S20 = 120, + CV_ARM64_S21 = 121, + CV_ARM64_S22 = 122, + CV_ARM64_S23 = 123, + CV_ARM64_S24 = 124, + CV_ARM64_S25 = 125, + CV_ARM64_S26 = 126, + CV_ARM64_S27 = 127, + CV_ARM64_S28 = 128, + CV_ARM64_S29 = 129, + CV_ARM64_S30 = 130, + CV_ARM64_S31 = 131, + + // 64-bit floating point registers + + CV_ARM64_D0 = 140, + CV_ARM64_D1 = 141, + CV_ARM64_D2 = 142, + CV_ARM64_D3 = 143, + CV_ARM64_D4 = 144, + CV_ARM64_D5 = 145, + CV_ARM64_D6 = 146, + CV_ARM64_D7 = 147, + CV_ARM64_D8 = 148, + CV_ARM64_D9 = 149, + CV_ARM64_D10 = 150, + CV_ARM64_D11 = 151, + CV_ARM64_D12 = 152, + CV_ARM64_D13 = 153, + CV_ARM64_D14 = 154, + CV_ARM64_D15 = 155, + CV_ARM64_D16 = 156, + CV_ARM64_D17 = 157, + CV_ARM64_D18 = 158, + CV_ARM64_D19 = 159, + CV_ARM64_D20 = 160, + CV_ARM64_D21 = 161, + CV_ARM64_D22 = 162, + CV_ARM64_D23 = 163, + CV_ARM64_D24 = 164, + CV_ARM64_D25 = 165, + CV_ARM64_D26 = 166, + CV_ARM64_D27 = 167, + CV_ARM64_D28 = 168, + CV_ARM64_D29 = 169, + CV_ARM64_D30 = 170, + CV_ARM64_D31 = 171, + + // 128-bit SIMD registers + + CV_ARM64_Q0 = 180, + CV_ARM64_Q1 = 181, + CV_ARM64_Q2 = 182, + CV_ARM64_Q3 = 183, + CV_ARM64_Q4 = 184, + CV_ARM64_Q5 = 185, + CV_ARM64_Q6 = 186, + CV_ARM64_Q7 = 187, + CV_ARM64_Q8 = 188, + CV_ARM64_Q9 = 189, + CV_ARM64_Q10 = 190, + CV_ARM64_Q11 = 191, + CV_ARM64_Q12 = 192, + CV_ARM64_Q13 = 193, + CV_ARM64_Q14 = 194, + CV_ARM64_Q15 = 195, + CV_ARM64_Q16 = 196, + CV_ARM64_Q17 = 197, + CV_ARM64_Q18 = 198, + CV_ARM64_Q19 = 199, + CV_ARM64_Q20 = 200, + CV_ARM64_Q21 = 201, + CV_ARM64_Q22 = 202, + CV_ARM64_Q23 = 203, + CV_ARM64_Q24 = 204, + CV_ARM64_Q25 = 205, + CV_ARM64_Q26 = 206, + CV_ARM64_Q27 = 207, + CV_ARM64_Q28 = 208, + CV_ARM64_Q29 = 209, + CV_ARM64_Q30 = 210, + CV_ARM64_Q31 = 211, + + // Floating point status register + + CV_ARM64_FPSR = 220, + + // + // Register set for Intel IA64 + // + + CV_IA64_NOREG = CV_REG_NONE, + + // Branch Registers + + CV_IA64_Br0 = 512, + CV_IA64_Br1 = 513, + CV_IA64_Br2 = 514, + CV_IA64_Br3 = 515, + CV_IA64_Br4 = 516, + CV_IA64_Br5 = 517, + CV_IA64_Br6 = 518, + CV_IA64_Br7 = 519, + + // Predicate Registers + + CV_IA64_P0 = 704, + CV_IA64_P1 = 705, + CV_IA64_P2 = 706, + CV_IA64_P3 = 707, + CV_IA64_P4 = 708, + CV_IA64_P5 = 709, + CV_IA64_P6 = 710, + CV_IA64_P7 = 711, + CV_IA64_P8 = 712, + CV_IA64_P9 = 713, + CV_IA64_P10 = 714, + CV_IA64_P11 = 715, + CV_IA64_P12 = 716, + CV_IA64_P13 = 717, + CV_IA64_P14 = 718, + CV_IA64_P15 = 719, + CV_IA64_P16 = 720, + CV_IA64_P17 = 721, + CV_IA64_P18 = 722, + CV_IA64_P19 = 723, + CV_IA64_P20 = 724, + CV_IA64_P21 = 725, + CV_IA64_P22 = 726, + CV_IA64_P23 = 727, + CV_IA64_P24 = 728, + CV_IA64_P25 = 729, + CV_IA64_P26 = 730, + CV_IA64_P27 = 731, + CV_IA64_P28 = 732, + CV_IA64_P29 = 733, + CV_IA64_P30 = 734, + CV_IA64_P31 = 735, + CV_IA64_P32 = 736, + CV_IA64_P33 = 737, + CV_IA64_P34 = 738, + CV_IA64_P35 = 739, + CV_IA64_P36 = 740, + CV_IA64_P37 = 741, + CV_IA64_P38 = 742, + CV_IA64_P39 = 743, + CV_IA64_P40 = 744, + CV_IA64_P41 = 745, + CV_IA64_P42 = 746, + CV_IA64_P43 = 747, + CV_IA64_P44 = 748, + CV_IA64_P45 = 749, + CV_IA64_P46 = 750, + CV_IA64_P47 = 751, + CV_IA64_P48 = 752, + CV_IA64_P49 = 753, + CV_IA64_P50 = 754, + CV_IA64_P51 = 755, + CV_IA64_P52 = 756, + CV_IA64_P53 = 757, + CV_IA64_P54 = 758, + CV_IA64_P55 = 759, + CV_IA64_P56 = 760, + CV_IA64_P57 = 761, + CV_IA64_P58 = 762, + CV_IA64_P59 = 763, + CV_IA64_P60 = 764, + CV_IA64_P61 = 765, + CV_IA64_P62 = 766, + CV_IA64_P63 = 767, + + CV_IA64_Preds = 768, + + // Banked General Registers + + CV_IA64_IntH0 = 832, + CV_IA64_IntH1 = 833, + CV_IA64_IntH2 = 834, + CV_IA64_IntH3 = 835, + CV_IA64_IntH4 = 836, + CV_IA64_IntH5 = 837, + CV_IA64_IntH6 = 838, + CV_IA64_IntH7 = 839, + CV_IA64_IntH8 = 840, + CV_IA64_IntH9 = 841, + CV_IA64_IntH10 = 842, + CV_IA64_IntH11 = 843, + CV_IA64_IntH12 = 844, + CV_IA64_IntH13 = 845, + CV_IA64_IntH14 = 846, + CV_IA64_IntH15 = 847, + + // Special Registers + + CV_IA64_Ip = 1016, + CV_IA64_Umask = 1017, + CV_IA64_Cfm = 1018, + CV_IA64_Psr = 1019, + + // Banked General Registers + + CV_IA64_Nats = 1020, + CV_IA64_Nats2 = 1021, + CV_IA64_Nats3 = 1022, + + // General-Purpose Registers + + // Integer registers + CV_IA64_IntR0 = 1024, + CV_IA64_IntR1 = 1025, + CV_IA64_IntR2 = 1026, + CV_IA64_IntR3 = 1027, + CV_IA64_IntR4 = 1028, + CV_IA64_IntR5 = 1029, + CV_IA64_IntR6 = 1030, + CV_IA64_IntR7 = 1031, + CV_IA64_IntR8 = 1032, + CV_IA64_IntR9 = 1033, + CV_IA64_IntR10 = 1034, + CV_IA64_IntR11 = 1035, + CV_IA64_IntR12 = 1036, + CV_IA64_IntR13 = 1037, + CV_IA64_IntR14 = 1038, + CV_IA64_IntR15 = 1039, + CV_IA64_IntR16 = 1040, + CV_IA64_IntR17 = 1041, + CV_IA64_IntR18 = 1042, + CV_IA64_IntR19 = 1043, + CV_IA64_IntR20 = 1044, + CV_IA64_IntR21 = 1045, + CV_IA64_IntR22 = 1046, + CV_IA64_IntR23 = 1047, + CV_IA64_IntR24 = 1048, + CV_IA64_IntR25 = 1049, + CV_IA64_IntR26 = 1050, + CV_IA64_IntR27 = 1051, + CV_IA64_IntR28 = 1052, + CV_IA64_IntR29 = 1053, + CV_IA64_IntR30 = 1054, + CV_IA64_IntR31 = 1055, + + // Register Stack + CV_IA64_IntR32 = 1056, + CV_IA64_IntR33 = 1057, + CV_IA64_IntR34 = 1058, + CV_IA64_IntR35 = 1059, + CV_IA64_IntR36 = 1060, + CV_IA64_IntR37 = 1061, + CV_IA64_IntR38 = 1062, + CV_IA64_IntR39 = 1063, + CV_IA64_IntR40 = 1064, + CV_IA64_IntR41 = 1065, + CV_IA64_IntR42 = 1066, + CV_IA64_IntR43 = 1067, + CV_IA64_IntR44 = 1068, + CV_IA64_IntR45 = 1069, + CV_IA64_IntR46 = 1070, + CV_IA64_IntR47 = 1071, + CV_IA64_IntR48 = 1072, + CV_IA64_IntR49 = 1073, + CV_IA64_IntR50 = 1074, + CV_IA64_IntR51 = 1075, + CV_IA64_IntR52 = 1076, + CV_IA64_IntR53 = 1077, + CV_IA64_IntR54 = 1078, + CV_IA64_IntR55 = 1079, + CV_IA64_IntR56 = 1080, + CV_IA64_IntR57 = 1081, + CV_IA64_IntR58 = 1082, + CV_IA64_IntR59 = 1083, + CV_IA64_IntR60 = 1084, + CV_IA64_IntR61 = 1085, + CV_IA64_IntR62 = 1086, + CV_IA64_IntR63 = 1087, + CV_IA64_IntR64 = 1088, + CV_IA64_IntR65 = 1089, + CV_IA64_IntR66 = 1090, + CV_IA64_IntR67 = 1091, + CV_IA64_IntR68 = 1092, + CV_IA64_IntR69 = 1093, + CV_IA64_IntR70 = 1094, + CV_IA64_IntR71 = 1095, + CV_IA64_IntR72 = 1096, + CV_IA64_IntR73 = 1097, + CV_IA64_IntR74 = 1098, + CV_IA64_IntR75 = 1099, + CV_IA64_IntR76 = 1100, + CV_IA64_IntR77 = 1101, + CV_IA64_IntR78 = 1102, + CV_IA64_IntR79 = 1103, + CV_IA64_IntR80 = 1104, + CV_IA64_IntR81 = 1105, + CV_IA64_IntR82 = 1106, + CV_IA64_IntR83 = 1107, + CV_IA64_IntR84 = 1108, + CV_IA64_IntR85 = 1109, + CV_IA64_IntR86 = 1110, + CV_IA64_IntR87 = 1111, + CV_IA64_IntR88 = 1112, + CV_IA64_IntR89 = 1113, + CV_IA64_IntR90 = 1114, + CV_IA64_IntR91 = 1115, + CV_IA64_IntR92 = 1116, + CV_IA64_IntR93 = 1117, + CV_IA64_IntR94 = 1118, + CV_IA64_IntR95 = 1119, + CV_IA64_IntR96 = 1120, + CV_IA64_IntR97 = 1121, + CV_IA64_IntR98 = 1122, + CV_IA64_IntR99 = 1123, + CV_IA64_IntR100 = 1124, + CV_IA64_IntR101 = 1125, + CV_IA64_IntR102 = 1126, + CV_IA64_IntR103 = 1127, + CV_IA64_IntR104 = 1128, + CV_IA64_IntR105 = 1129, + CV_IA64_IntR106 = 1130, + CV_IA64_IntR107 = 1131, + CV_IA64_IntR108 = 1132, + CV_IA64_IntR109 = 1133, + CV_IA64_IntR110 = 1134, + CV_IA64_IntR111 = 1135, + CV_IA64_IntR112 = 1136, + CV_IA64_IntR113 = 1137, + CV_IA64_IntR114 = 1138, + CV_IA64_IntR115 = 1139, + CV_IA64_IntR116 = 1140, + CV_IA64_IntR117 = 1141, + CV_IA64_IntR118 = 1142, + CV_IA64_IntR119 = 1143, + CV_IA64_IntR120 = 1144, + CV_IA64_IntR121 = 1145, + CV_IA64_IntR122 = 1146, + CV_IA64_IntR123 = 1147, + CV_IA64_IntR124 = 1148, + CV_IA64_IntR125 = 1149, + CV_IA64_IntR126 = 1150, + CV_IA64_IntR127 = 1151, + + // Floating-Point Registers + + // Low Floating Point Registers + CV_IA64_FltF0 = 2048, + CV_IA64_FltF1 = 2049, + CV_IA64_FltF2 = 2050, + CV_IA64_FltF3 = 2051, + CV_IA64_FltF4 = 2052, + CV_IA64_FltF5 = 2053, + CV_IA64_FltF6 = 2054, + CV_IA64_FltF7 = 2055, + CV_IA64_FltF8 = 2056, + CV_IA64_FltF9 = 2057, + CV_IA64_FltF10 = 2058, + CV_IA64_FltF11 = 2059, + CV_IA64_FltF12 = 2060, + CV_IA64_FltF13 = 2061, + CV_IA64_FltF14 = 2062, + CV_IA64_FltF15 = 2063, + CV_IA64_FltF16 = 2064, + CV_IA64_FltF17 = 2065, + CV_IA64_FltF18 = 2066, + CV_IA64_FltF19 = 2067, + CV_IA64_FltF20 = 2068, + CV_IA64_FltF21 = 2069, + CV_IA64_FltF22 = 2070, + CV_IA64_FltF23 = 2071, + CV_IA64_FltF24 = 2072, + CV_IA64_FltF25 = 2073, + CV_IA64_FltF26 = 2074, + CV_IA64_FltF27 = 2075, + CV_IA64_FltF28 = 2076, + CV_IA64_FltF29 = 2077, + CV_IA64_FltF30 = 2078, + CV_IA64_FltF31 = 2079, + + // High Floating Point Registers + CV_IA64_FltF32 = 2080, + CV_IA64_FltF33 = 2081, + CV_IA64_FltF34 = 2082, + CV_IA64_FltF35 = 2083, + CV_IA64_FltF36 = 2084, + CV_IA64_FltF37 = 2085, + CV_IA64_FltF38 = 2086, + CV_IA64_FltF39 = 2087, + CV_IA64_FltF40 = 2088, + CV_IA64_FltF41 = 2089, + CV_IA64_FltF42 = 2090, + CV_IA64_FltF43 = 2091, + CV_IA64_FltF44 = 2092, + CV_IA64_FltF45 = 2093, + CV_IA64_FltF46 = 2094, + CV_IA64_FltF47 = 2095, + CV_IA64_FltF48 = 2096, + CV_IA64_FltF49 = 2097, + CV_IA64_FltF50 = 2098, + CV_IA64_FltF51 = 2099, + CV_IA64_FltF52 = 2100, + CV_IA64_FltF53 = 2101, + CV_IA64_FltF54 = 2102, + CV_IA64_FltF55 = 2103, + CV_IA64_FltF56 = 2104, + CV_IA64_FltF57 = 2105, + CV_IA64_FltF58 = 2106, + CV_IA64_FltF59 = 2107, + CV_IA64_FltF60 = 2108, + CV_IA64_FltF61 = 2109, + CV_IA64_FltF62 = 2110, + CV_IA64_FltF63 = 2111, + CV_IA64_FltF64 = 2112, + CV_IA64_FltF65 = 2113, + CV_IA64_FltF66 = 2114, + CV_IA64_FltF67 = 2115, + CV_IA64_FltF68 = 2116, + CV_IA64_FltF69 = 2117, + CV_IA64_FltF70 = 2118, + CV_IA64_FltF71 = 2119, + CV_IA64_FltF72 = 2120, + CV_IA64_FltF73 = 2121, + CV_IA64_FltF74 = 2122, + CV_IA64_FltF75 = 2123, + CV_IA64_FltF76 = 2124, + CV_IA64_FltF77 = 2125, + CV_IA64_FltF78 = 2126, + CV_IA64_FltF79 = 2127, + CV_IA64_FltF80 = 2128, + CV_IA64_FltF81 = 2129, + CV_IA64_FltF82 = 2130, + CV_IA64_FltF83 = 2131, + CV_IA64_FltF84 = 2132, + CV_IA64_FltF85 = 2133, + CV_IA64_FltF86 = 2134, + CV_IA64_FltF87 = 2135, + CV_IA64_FltF88 = 2136, + CV_IA64_FltF89 = 2137, + CV_IA64_FltF90 = 2138, + CV_IA64_FltF91 = 2139, + CV_IA64_FltF92 = 2140, + CV_IA64_FltF93 = 2141, + CV_IA64_FltF94 = 2142, + CV_IA64_FltF95 = 2143, + CV_IA64_FltF96 = 2144, + CV_IA64_FltF97 = 2145, + CV_IA64_FltF98 = 2146, + CV_IA64_FltF99 = 2147, + CV_IA64_FltF100 = 2148, + CV_IA64_FltF101 = 2149, + CV_IA64_FltF102 = 2150, + CV_IA64_FltF103 = 2151, + CV_IA64_FltF104 = 2152, + CV_IA64_FltF105 = 2153, + CV_IA64_FltF106 = 2154, + CV_IA64_FltF107 = 2155, + CV_IA64_FltF108 = 2156, + CV_IA64_FltF109 = 2157, + CV_IA64_FltF110 = 2158, + CV_IA64_FltF111 = 2159, + CV_IA64_FltF112 = 2160, + CV_IA64_FltF113 = 2161, + CV_IA64_FltF114 = 2162, + CV_IA64_FltF115 = 2163, + CV_IA64_FltF116 = 2164, + CV_IA64_FltF117 = 2165, + CV_IA64_FltF118 = 2166, + CV_IA64_FltF119 = 2167, + CV_IA64_FltF120 = 2168, + CV_IA64_FltF121 = 2169, + CV_IA64_FltF122 = 2170, + CV_IA64_FltF123 = 2171, + CV_IA64_FltF124 = 2172, + CV_IA64_FltF125 = 2173, + CV_IA64_FltF126 = 2174, + CV_IA64_FltF127 = 2175, + + // Application Registers + + CV_IA64_ApKR0 = 3072, + CV_IA64_ApKR1 = 3073, + CV_IA64_ApKR2 = 3074, + CV_IA64_ApKR3 = 3075, + CV_IA64_ApKR4 = 3076, + CV_IA64_ApKR5 = 3077, + CV_IA64_ApKR6 = 3078, + CV_IA64_ApKR7 = 3079, + CV_IA64_AR8 = 3080, + CV_IA64_AR9 = 3081, + CV_IA64_AR10 = 3082, + CV_IA64_AR11 = 3083, + CV_IA64_AR12 = 3084, + CV_IA64_AR13 = 3085, + CV_IA64_AR14 = 3086, + CV_IA64_AR15 = 3087, + CV_IA64_RsRSC = 3088, + CV_IA64_RsBSP = 3089, + CV_IA64_RsBSPSTORE = 3090, + CV_IA64_RsRNAT = 3091, + CV_IA64_AR20 = 3092, + CV_IA64_StFCR = 3093, + CV_IA64_AR22 = 3094, + CV_IA64_AR23 = 3095, + CV_IA64_EFLAG = 3096, + CV_IA64_CSD = 3097, + CV_IA64_SSD = 3098, + CV_IA64_CFLG = 3099, + CV_IA64_StFSR = 3100, + CV_IA64_StFIR = 3101, + CV_IA64_StFDR = 3102, + CV_IA64_AR31 = 3103, + CV_IA64_ApCCV = 3104, + CV_IA64_AR33 = 3105, + CV_IA64_AR34 = 3106, + CV_IA64_AR35 = 3107, + CV_IA64_ApUNAT = 3108, + CV_IA64_AR37 = 3109, + CV_IA64_AR38 = 3110, + CV_IA64_AR39 = 3111, + CV_IA64_StFPSR = 3112, + CV_IA64_AR41 = 3113, + CV_IA64_AR42 = 3114, + CV_IA64_AR43 = 3115, + CV_IA64_ApITC = 3116, + CV_IA64_AR45 = 3117, + CV_IA64_AR46 = 3118, + CV_IA64_AR47 = 3119, + CV_IA64_AR48 = 3120, + CV_IA64_AR49 = 3121, + CV_IA64_AR50 = 3122, + CV_IA64_AR51 = 3123, + CV_IA64_AR52 = 3124, + CV_IA64_AR53 = 3125, + CV_IA64_AR54 = 3126, + CV_IA64_AR55 = 3127, + CV_IA64_AR56 = 3128, + CV_IA64_AR57 = 3129, + CV_IA64_AR58 = 3130, + CV_IA64_AR59 = 3131, + CV_IA64_AR60 = 3132, + CV_IA64_AR61 = 3133, + CV_IA64_AR62 = 3134, + CV_IA64_AR63 = 3135, + CV_IA64_RsPFS = 3136, + CV_IA64_ApLC = 3137, + CV_IA64_ApEC = 3138, + CV_IA64_AR67 = 3139, + CV_IA64_AR68 = 3140, + CV_IA64_AR69 = 3141, + CV_IA64_AR70 = 3142, + CV_IA64_AR71 = 3143, + CV_IA64_AR72 = 3144, + CV_IA64_AR73 = 3145, + CV_IA64_AR74 = 3146, + CV_IA64_AR75 = 3147, + CV_IA64_AR76 = 3148, + CV_IA64_AR77 = 3149, + CV_IA64_AR78 = 3150, + CV_IA64_AR79 = 3151, + CV_IA64_AR80 = 3152, + CV_IA64_AR81 = 3153, + CV_IA64_AR82 = 3154, + CV_IA64_AR83 = 3155, + CV_IA64_AR84 = 3156, + CV_IA64_AR85 = 3157, + CV_IA64_AR86 = 3158, + CV_IA64_AR87 = 3159, + CV_IA64_AR88 = 3160, + CV_IA64_AR89 = 3161, + CV_IA64_AR90 = 3162, + CV_IA64_AR91 = 3163, + CV_IA64_AR92 = 3164, + CV_IA64_AR93 = 3165, + CV_IA64_AR94 = 3166, + CV_IA64_AR95 = 3167, + CV_IA64_AR96 = 3168, + CV_IA64_AR97 = 3169, + CV_IA64_AR98 = 3170, + CV_IA64_AR99 = 3171, + CV_IA64_AR100 = 3172, + CV_IA64_AR101 = 3173, + CV_IA64_AR102 = 3174, + CV_IA64_AR103 = 3175, + CV_IA64_AR104 = 3176, + CV_IA64_AR105 = 3177, + CV_IA64_AR106 = 3178, + CV_IA64_AR107 = 3179, + CV_IA64_AR108 = 3180, + CV_IA64_AR109 = 3181, + CV_IA64_AR110 = 3182, + CV_IA64_AR111 = 3183, + CV_IA64_AR112 = 3184, + CV_IA64_AR113 = 3185, + CV_IA64_AR114 = 3186, + CV_IA64_AR115 = 3187, + CV_IA64_AR116 = 3188, + CV_IA64_AR117 = 3189, + CV_IA64_AR118 = 3190, + CV_IA64_AR119 = 3191, + CV_IA64_AR120 = 3192, + CV_IA64_AR121 = 3193, + CV_IA64_AR122 = 3194, + CV_IA64_AR123 = 3195, + CV_IA64_AR124 = 3196, + CV_IA64_AR125 = 3197, + CV_IA64_AR126 = 3198, + CV_IA64_AR127 = 3199, + + // CPUID Registers + + CV_IA64_CPUID0 = 3328, + CV_IA64_CPUID1 = 3329, + CV_IA64_CPUID2 = 3330, + CV_IA64_CPUID3 = 3331, + CV_IA64_CPUID4 = 3332, + + // Control Registers + + CV_IA64_ApDCR = 4096, + CV_IA64_ApITM = 4097, + CV_IA64_ApIVA = 4098, + CV_IA64_CR3 = 4099, + CV_IA64_CR4 = 4100, + CV_IA64_CR5 = 4101, + CV_IA64_CR6 = 4102, + CV_IA64_CR7 = 4103, + CV_IA64_ApPTA = 4104, + CV_IA64_ApGPTA = 4105, + CV_IA64_CR10 = 4106, + CV_IA64_CR11 = 4107, + CV_IA64_CR12 = 4108, + CV_IA64_CR13 = 4109, + CV_IA64_CR14 = 4110, + CV_IA64_CR15 = 4111, + CV_IA64_StIPSR = 4112, + CV_IA64_StISR = 4113, + CV_IA64_CR18 = 4114, + CV_IA64_StIIP = 4115, + CV_IA64_StIFA = 4116, + CV_IA64_StITIR = 4117, + CV_IA64_StIIPA = 4118, + CV_IA64_StIFS = 4119, + CV_IA64_StIIM = 4120, + CV_IA64_StIHA = 4121, + CV_IA64_CR26 = 4122, + CV_IA64_CR27 = 4123, + CV_IA64_CR28 = 4124, + CV_IA64_CR29 = 4125, + CV_IA64_CR30 = 4126, + CV_IA64_CR31 = 4127, + CV_IA64_CR32 = 4128, + CV_IA64_CR33 = 4129, + CV_IA64_CR34 = 4130, + CV_IA64_CR35 = 4131, + CV_IA64_CR36 = 4132, + CV_IA64_CR37 = 4133, + CV_IA64_CR38 = 4134, + CV_IA64_CR39 = 4135, + CV_IA64_CR40 = 4136, + CV_IA64_CR41 = 4137, + CV_IA64_CR42 = 4138, + CV_IA64_CR43 = 4139, + CV_IA64_CR44 = 4140, + CV_IA64_CR45 = 4141, + CV_IA64_CR46 = 4142, + CV_IA64_CR47 = 4143, + CV_IA64_CR48 = 4144, + CV_IA64_CR49 = 4145, + CV_IA64_CR50 = 4146, + CV_IA64_CR51 = 4147, + CV_IA64_CR52 = 4148, + CV_IA64_CR53 = 4149, + CV_IA64_CR54 = 4150, + CV_IA64_CR55 = 4151, + CV_IA64_CR56 = 4152, + CV_IA64_CR57 = 4153, + CV_IA64_CR58 = 4154, + CV_IA64_CR59 = 4155, + CV_IA64_CR60 = 4156, + CV_IA64_CR61 = 4157, + CV_IA64_CR62 = 4158, + CV_IA64_CR63 = 4159, + CV_IA64_SaLID = 4160, + CV_IA64_SaIVR = 4161, + CV_IA64_SaTPR = 4162, + CV_IA64_SaEOI = 4163, + CV_IA64_SaIRR0 = 4164, + CV_IA64_SaIRR1 = 4165, + CV_IA64_SaIRR2 = 4166, + CV_IA64_SaIRR3 = 4167, + CV_IA64_SaITV = 4168, + CV_IA64_SaPMV = 4169, + CV_IA64_SaCMCV = 4170, + CV_IA64_CR75 = 4171, + CV_IA64_CR76 = 4172, + CV_IA64_CR77 = 4173, + CV_IA64_CR78 = 4174, + CV_IA64_CR79 = 4175, + CV_IA64_SaLRR0 = 4176, + CV_IA64_SaLRR1 = 4177, + CV_IA64_CR82 = 4178, + CV_IA64_CR83 = 4179, + CV_IA64_CR84 = 4180, + CV_IA64_CR85 = 4181, + CV_IA64_CR86 = 4182, + CV_IA64_CR87 = 4183, + CV_IA64_CR88 = 4184, + CV_IA64_CR89 = 4185, + CV_IA64_CR90 = 4186, + CV_IA64_CR91 = 4187, + CV_IA64_CR92 = 4188, + CV_IA64_CR93 = 4189, + CV_IA64_CR94 = 4190, + CV_IA64_CR95 = 4191, + CV_IA64_CR96 = 4192, + CV_IA64_CR97 = 4193, + CV_IA64_CR98 = 4194, + CV_IA64_CR99 = 4195, + CV_IA64_CR100 = 4196, + CV_IA64_CR101 = 4197, + CV_IA64_CR102 = 4198, + CV_IA64_CR103 = 4199, + CV_IA64_CR104 = 4200, + CV_IA64_CR105 = 4201, + CV_IA64_CR106 = 4202, + CV_IA64_CR107 = 4203, + CV_IA64_CR108 = 4204, + CV_IA64_CR109 = 4205, + CV_IA64_CR110 = 4206, + CV_IA64_CR111 = 4207, + CV_IA64_CR112 = 4208, + CV_IA64_CR113 = 4209, + CV_IA64_CR114 = 4210, + CV_IA64_CR115 = 4211, + CV_IA64_CR116 = 4212, + CV_IA64_CR117 = 4213, + CV_IA64_CR118 = 4214, + CV_IA64_CR119 = 4215, + CV_IA64_CR120 = 4216, + CV_IA64_CR121 = 4217, + CV_IA64_CR122 = 4218, + CV_IA64_CR123 = 4219, + CV_IA64_CR124 = 4220, + CV_IA64_CR125 = 4221, + CV_IA64_CR126 = 4222, + CV_IA64_CR127 = 4223, + + // Protection Key Registers + + CV_IA64_Pkr0 = 5120, + CV_IA64_Pkr1 = 5121, + CV_IA64_Pkr2 = 5122, + CV_IA64_Pkr3 = 5123, + CV_IA64_Pkr4 = 5124, + CV_IA64_Pkr5 = 5125, + CV_IA64_Pkr6 = 5126, + CV_IA64_Pkr7 = 5127, + CV_IA64_Pkr8 = 5128, + CV_IA64_Pkr9 = 5129, + CV_IA64_Pkr10 = 5130, + CV_IA64_Pkr11 = 5131, + CV_IA64_Pkr12 = 5132, + CV_IA64_Pkr13 = 5133, + CV_IA64_Pkr14 = 5134, + CV_IA64_Pkr15 = 5135, + + // Region Registers + + CV_IA64_Rr0 = 6144, + CV_IA64_Rr1 = 6145, + CV_IA64_Rr2 = 6146, + CV_IA64_Rr3 = 6147, + CV_IA64_Rr4 = 6148, + CV_IA64_Rr5 = 6149, + CV_IA64_Rr6 = 6150, + CV_IA64_Rr7 = 6151, + + // Performance Monitor Data Registers + + CV_IA64_PFD0 = 7168, + CV_IA64_PFD1 = 7169, + CV_IA64_PFD2 = 7170, + CV_IA64_PFD3 = 7171, + CV_IA64_PFD4 = 7172, + CV_IA64_PFD5 = 7173, + CV_IA64_PFD6 = 7174, + CV_IA64_PFD7 = 7175, + CV_IA64_PFD8 = 7176, + CV_IA64_PFD9 = 7177, + CV_IA64_PFD10 = 7178, + CV_IA64_PFD11 = 7179, + CV_IA64_PFD12 = 7180, + CV_IA64_PFD13 = 7181, + CV_IA64_PFD14 = 7182, + CV_IA64_PFD15 = 7183, + CV_IA64_PFD16 = 7184, + CV_IA64_PFD17 = 7185, + + // Performance Monitor Config Registers + + CV_IA64_PFC0 = 7424, + CV_IA64_PFC1 = 7425, + CV_IA64_PFC2 = 7426, + CV_IA64_PFC3 = 7427, + CV_IA64_PFC4 = 7428, + CV_IA64_PFC5 = 7429, + CV_IA64_PFC6 = 7430, + CV_IA64_PFC7 = 7431, + CV_IA64_PFC8 = 7432, + CV_IA64_PFC9 = 7433, + CV_IA64_PFC10 = 7434, + CV_IA64_PFC11 = 7435, + CV_IA64_PFC12 = 7436, + CV_IA64_PFC13 = 7437, + CV_IA64_PFC14 = 7438, + CV_IA64_PFC15 = 7439, + + // Instruction Translation Registers + + CV_IA64_TrI0 = 8192, + CV_IA64_TrI1 = 8193, + CV_IA64_TrI2 = 8194, + CV_IA64_TrI3 = 8195, + CV_IA64_TrI4 = 8196, + CV_IA64_TrI5 = 8197, + CV_IA64_TrI6 = 8198, + CV_IA64_TrI7 = 8199, + + // Data Translation Registers + + CV_IA64_TrD0 = 8320, + CV_IA64_TrD1 = 8321, + CV_IA64_TrD2 = 8322, + CV_IA64_TrD3 = 8323, + CV_IA64_TrD4 = 8324, + CV_IA64_TrD5 = 8325, + CV_IA64_TrD6 = 8326, + CV_IA64_TrD7 = 8327, + + // Instruction Breakpoint Registers + + CV_IA64_DbI0 = 8448, + CV_IA64_DbI1 = 8449, + CV_IA64_DbI2 = 8450, + CV_IA64_DbI3 = 8451, + CV_IA64_DbI4 = 8452, + CV_IA64_DbI5 = 8453, + CV_IA64_DbI6 = 8454, + CV_IA64_DbI7 = 8455, + + // Data Breakpoint Registers + + CV_IA64_DbD0 = 8576, + CV_IA64_DbD1 = 8577, + CV_IA64_DbD2 = 8578, + CV_IA64_DbD3 = 8579, + CV_IA64_DbD4 = 8580, + CV_IA64_DbD5 = 8581, + CV_IA64_DbD6 = 8582, + CV_IA64_DbD7 = 8583, + + // + // Register set for the TriCore processor. + // + + CV_TRI_NOREG = CV_REG_NONE, + + // General Purpose Data Registers + + CV_TRI_D0 = 10, + CV_TRI_D1 = 11, + CV_TRI_D2 = 12, + CV_TRI_D3 = 13, + CV_TRI_D4 = 14, + CV_TRI_D5 = 15, + CV_TRI_D6 = 16, + CV_TRI_D7 = 17, + CV_TRI_D8 = 18, + CV_TRI_D9 = 19, + CV_TRI_D10 = 20, + CV_TRI_D11 = 21, + CV_TRI_D12 = 22, + CV_TRI_D13 = 23, + CV_TRI_D14 = 24, + CV_TRI_D15 = 25, + + // General Purpose Address Registers + + CV_TRI_A0 = 26, + CV_TRI_A1 = 27, + CV_TRI_A2 = 28, + CV_TRI_A3 = 29, + CV_TRI_A4 = 30, + CV_TRI_A5 = 31, + CV_TRI_A6 = 32, + CV_TRI_A7 = 33, + CV_TRI_A8 = 34, + CV_TRI_A9 = 35, + CV_TRI_A10 = 36, + CV_TRI_A11 = 37, + CV_TRI_A12 = 38, + CV_TRI_A13 = 39, + CV_TRI_A14 = 40, + CV_TRI_A15 = 41, + + // Extended (64-bit) data registers + + CV_TRI_E0 = 42, + CV_TRI_E2 = 43, + CV_TRI_E4 = 44, + CV_TRI_E6 = 45, + CV_TRI_E8 = 46, + CV_TRI_E10 = 47, + CV_TRI_E12 = 48, + CV_TRI_E14 = 49, + + // Extended (64-bit) address registers + + CV_TRI_EA0 = 50, + CV_TRI_EA2 = 51, + CV_TRI_EA4 = 52, + CV_TRI_EA6 = 53, + CV_TRI_EA8 = 54, + CV_TRI_EA10 = 55, + CV_TRI_EA12 = 56, + CV_TRI_EA14 = 57, + + CV_TRI_PSW = 58, + CV_TRI_PCXI = 59, + CV_TRI_PC = 60, + CV_TRI_FCX = 61, + CV_TRI_LCX = 62, + CV_TRI_ISP = 63, + CV_TRI_ICR = 64, + CV_TRI_BIV = 65, + CV_TRI_BTV = 66, + CV_TRI_SYSCON = 67, + CV_TRI_DPRx_0 = 68, + CV_TRI_DPRx_1 = 69, + CV_TRI_DPRx_2 = 70, + CV_TRI_DPRx_3 = 71, + CV_TRI_CPRx_0 = 68, + CV_TRI_CPRx_1 = 69, + CV_TRI_CPRx_2 = 70, + CV_TRI_CPRx_3 = 71, + CV_TRI_DPMx_0 = 68, + CV_TRI_DPMx_1 = 69, + CV_TRI_DPMx_2 = 70, + CV_TRI_DPMx_3 = 71, + CV_TRI_CPMx_0 = 68, + CV_TRI_CPMx_1 = 69, + CV_TRI_CPMx_2 = 70, + CV_TRI_CPMx_3 = 71, + CV_TRI_DBGSSR = 72, + CV_TRI_EXEVT = 73, + CV_TRI_SWEVT = 74, + CV_TRI_CREVT = 75, + CV_TRI_TRnEVT = 76, + CV_TRI_MMUCON = 77, + CV_TRI_ASI = 78, + CV_TRI_TVA = 79, + CV_TRI_TPA = 80, + CV_TRI_TPX = 81, + CV_TRI_TFA = 82, + + // + // Register set for the AM33 and related processors. + // + + CV_AM33_NOREG = CV_REG_NONE, + + // "Extended" (general purpose integer) registers + CV_AM33_E0 = 10, + CV_AM33_E1 = 11, + CV_AM33_E2 = 12, + CV_AM33_E3 = 13, + CV_AM33_E4 = 14, + CV_AM33_E5 = 15, + CV_AM33_E6 = 16, + CV_AM33_E7 = 17, + + // Address registers + CV_AM33_A0 = 20, + CV_AM33_A1 = 21, + CV_AM33_A2 = 22, + CV_AM33_A3 = 23, + + // Integer data registers + CV_AM33_D0 = 30, + CV_AM33_D1 = 31, + CV_AM33_D2 = 32, + CV_AM33_D3 = 33, + + // (Single-precision) floating-point registers + CV_AM33_FS0 = 40, + CV_AM33_FS1 = 41, + CV_AM33_FS2 = 42, + CV_AM33_FS3 = 43, + CV_AM33_FS4 = 44, + CV_AM33_FS5 = 45, + CV_AM33_FS6 = 46, + CV_AM33_FS7 = 47, + CV_AM33_FS8 = 48, + CV_AM33_FS9 = 49, + CV_AM33_FS10 = 50, + CV_AM33_FS11 = 51, + CV_AM33_FS12 = 52, + CV_AM33_FS13 = 53, + CV_AM33_FS14 = 54, + CV_AM33_FS15 = 55, + CV_AM33_FS16 = 56, + CV_AM33_FS17 = 57, + CV_AM33_FS18 = 58, + CV_AM33_FS19 = 59, + CV_AM33_FS20 = 60, + CV_AM33_FS21 = 61, + CV_AM33_FS22 = 62, + CV_AM33_FS23 = 63, + CV_AM33_FS24 = 64, + CV_AM33_FS25 = 65, + CV_AM33_FS26 = 66, + CV_AM33_FS27 = 67, + CV_AM33_FS28 = 68, + CV_AM33_FS29 = 69, + CV_AM33_FS30 = 70, + CV_AM33_FS31 = 71, + + // Special purpose registers + + // Stack pointer + CV_AM33_SP = 80, + + // Program counter + CV_AM33_PC = 81, + + // Multiply-divide/accumulate registers + CV_AM33_MDR = 82, + CV_AM33_MDRQ = 83, + CV_AM33_MCRH = 84, + CV_AM33_MCRL = 85, + CV_AM33_MCVF = 86, + + // CPU status words + CV_AM33_EPSW = 87, + CV_AM33_FPCR = 88, + + // Loop buffer registers + CV_AM33_LIR = 89, + CV_AM33_LAR = 90, + + // + // Register set for the Mitsubishi M32R + // + + CV_M32R_NOREG = CV_REG_NONE, + + CV_M32R_R0 = 10, + CV_M32R_R1 = 11, + CV_M32R_R2 = 12, + CV_M32R_R3 = 13, + CV_M32R_R4 = 14, + CV_M32R_R5 = 15, + CV_M32R_R6 = 16, + CV_M32R_R7 = 17, + CV_M32R_R8 = 18, + CV_M32R_R9 = 19, + CV_M32R_R10 = 20, + CV_M32R_R11 = 21, + CV_M32R_R12 = 22, // Gloabal Pointer, if used + CV_M32R_R13 = 23, // Frame Pointer, if allocated + CV_M32R_R14 = 24, // Link Register + CV_M32R_R15 = 25, // Stack Pointer + CV_M32R_PSW = 26, // Preocessor Status Register + CV_M32R_CBR = 27, // Condition Bit Register + CV_M32R_SPI = 28, // Interrupt Stack Pointer + CV_M32R_SPU = 29, // User Stack Pointer + CV_M32R_SPO = 30, // OS Stack Pointer + CV_M32R_BPC = 31, // Backup Program Counter + CV_M32R_ACHI = 32, // Accumulator High + CV_M32R_ACLO = 33, // Accumulator Low + CV_M32R_PC = 34, // Program Counter + + // + // Register set for the SuperH SHMedia processor including compact + // mode + // + + // Integer - 64 bit general registers + CV_SHMEDIA_NOREG = CV_REG_NONE, + CV_SHMEDIA_R0 = 10, + CV_SHMEDIA_R1 = 11, + CV_SHMEDIA_R2 = 12, + CV_SHMEDIA_R3 = 13, + CV_SHMEDIA_R4 = 14, + CV_SHMEDIA_R5 = 15, + CV_SHMEDIA_R6 = 16, + CV_SHMEDIA_R7 = 17, + CV_SHMEDIA_R8 = 18, + CV_SHMEDIA_R9 = 19, + CV_SHMEDIA_R10 = 20, + CV_SHMEDIA_R11 = 21, + CV_SHMEDIA_R12 = 22, + CV_SHMEDIA_R13 = 23, + CV_SHMEDIA_R14 = 24, + CV_SHMEDIA_R15 = 25, + CV_SHMEDIA_R16 = 26, + CV_SHMEDIA_R17 = 27, + CV_SHMEDIA_R18 = 28, + CV_SHMEDIA_R19 = 29, + CV_SHMEDIA_R20 = 30, + CV_SHMEDIA_R21 = 31, + CV_SHMEDIA_R22 = 32, + CV_SHMEDIA_R23 = 33, + CV_SHMEDIA_R24 = 34, + CV_SHMEDIA_R25 = 35, + CV_SHMEDIA_R26 = 36, + CV_SHMEDIA_R27 = 37, + CV_SHMEDIA_R28 = 38, + CV_SHMEDIA_R29 = 39, + CV_SHMEDIA_R30 = 40, + CV_SHMEDIA_R31 = 41, + CV_SHMEDIA_R32 = 42, + CV_SHMEDIA_R33 = 43, + CV_SHMEDIA_R34 = 44, + CV_SHMEDIA_R35 = 45, + CV_SHMEDIA_R36 = 46, + CV_SHMEDIA_R37 = 47, + CV_SHMEDIA_R38 = 48, + CV_SHMEDIA_R39 = 49, + CV_SHMEDIA_R40 = 50, + CV_SHMEDIA_R41 = 51, + CV_SHMEDIA_R42 = 52, + CV_SHMEDIA_R43 = 53, + CV_SHMEDIA_R44 = 54, + CV_SHMEDIA_R45 = 55, + CV_SHMEDIA_R46 = 56, + CV_SHMEDIA_R47 = 57, + CV_SHMEDIA_R48 = 58, + CV_SHMEDIA_R49 = 59, + CV_SHMEDIA_R50 = 60, + CV_SHMEDIA_R51 = 61, + CV_SHMEDIA_R52 = 62, + CV_SHMEDIA_R53 = 63, + CV_SHMEDIA_R54 = 64, + CV_SHMEDIA_R55 = 65, + CV_SHMEDIA_R56 = 66, + CV_SHMEDIA_R57 = 67, + CV_SHMEDIA_R58 = 68, + CV_SHMEDIA_R59 = 69, + CV_SHMEDIA_R60 = 70, + CV_SHMEDIA_R61 = 71, + CV_SHMEDIA_R62 = 72, + CV_SHMEDIA_R63 = 73, + + // Target Registers - 32 bit + CV_SHMEDIA_TR0 = 74, + CV_SHMEDIA_TR1 = 75, + CV_SHMEDIA_TR2 = 76, + CV_SHMEDIA_TR3 = 77, + CV_SHMEDIA_TR4 = 78, + CV_SHMEDIA_TR5 = 79, + CV_SHMEDIA_TR6 = 80, + CV_SHMEDIA_TR7 = 81, + CV_SHMEDIA_TR8 = 82, // future-proof + CV_SHMEDIA_TR9 = 83, // future-proof + CV_SHMEDIA_TR10 = 84, // future-proof + CV_SHMEDIA_TR11 = 85, // future-proof + CV_SHMEDIA_TR12 = 86, // future-proof + CV_SHMEDIA_TR13 = 87, // future-proof + CV_SHMEDIA_TR14 = 88, // future-proof + CV_SHMEDIA_TR15 = 89, // future-proof + + // Single - 32 bit fp registers + CV_SHMEDIA_FR0 = 128, + CV_SHMEDIA_FR1 = 129, + CV_SHMEDIA_FR2 = 130, + CV_SHMEDIA_FR3 = 131, + CV_SHMEDIA_FR4 = 132, + CV_SHMEDIA_FR5 = 133, + CV_SHMEDIA_FR6 = 134, + CV_SHMEDIA_FR7 = 135, + CV_SHMEDIA_FR8 = 136, + CV_SHMEDIA_FR9 = 137, + CV_SHMEDIA_FR10 = 138, + CV_SHMEDIA_FR11 = 139, + CV_SHMEDIA_FR12 = 140, + CV_SHMEDIA_FR13 = 141, + CV_SHMEDIA_FR14 = 142, + CV_SHMEDIA_FR15 = 143, + CV_SHMEDIA_FR16 = 144, + CV_SHMEDIA_FR17 = 145, + CV_SHMEDIA_FR18 = 146, + CV_SHMEDIA_FR19 = 147, + CV_SHMEDIA_FR20 = 148, + CV_SHMEDIA_FR21 = 149, + CV_SHMEDIA_FR22 = 150, + CV_SHMEDIA_FR23 = 151, + CV_SHMEDIA_FR24 = 152, + CV_SHMEDIA_FR25 = 153, + CV_SHMEDIA_FR26 = 154, + CV_SHMEDIA_FR27 = 155, + CV_SHMEDIA_FR28 = 156, + CV_SHMEDIA_FR29 = 157, + CV_SHMEDIA_FR30 = 158, + CV_SHMEDIA_FR31 = 159, + CV_SHMEDIA_FR32 = 160, + CV_SHMEDIA_FR33 = 161, + CV_SHMEDIA_FR34 = 162, + CV_SHMEDIA_FR35 = 163, + CV_SHMEDIA_FR36 = 164, + CV_SHMEDIA_FR37 = 165, + CV_SHMEDIA_FR38 = 166, + CV_SHMEDIA_FR39 = 167, + CV_SHMEDIA_FR40 = 168, + CV_SHMEDIA_FR41 = 169, + CV_SHMEDIA_FR42 = 170, + CV_SHMEDIA_FR43 = 171, + CV_SHMEDIA_FR44 = 172, + CV_SHMEDIA_FR45 = 173, + CV_SHMEDIA_FR46 = 174, + CV_SHMEDIA_FR47 = 175, + CV_SHMEDIA_FR48 = 176, + CV_SHMEDIA_FR49 = 177, + CV_SHMEDIA_FR50 = 178, + CV_SHMEDIA_FR51 = 179, + CV_SHMEDIA_FR52 = 180, + CV_SHMEDIA_FR53 = 181, + CV_SHMEDIA_FR54 = 182, + CV_SHMEDIA_FR55 = 183, + CV_SHMEDIA_FR56 = 184, + CV_SHMEDIA_FR57 = 185, + CV_SHMEDIA_FR58 = 186, + CV_SHMEDIA_FR59 = 187, + CV_SHMEDIA_FR60 = 188, + CV_SHMEDIA_FR61 = 189, + CV_SHMEDIA_FR62 = 190, + CV_SHMEDIA_FR63 = 191, + + // Double - 64 bit synonyms for 32bit fp register pairs + // subtract 128 to find first base single register + CV_SHMEDIA_DR0 = 256, + CV_SHMEDIA_DR2 = 258, + CV_SHMEDIA_DR4 = 260, + CV_SHMEDIA_DR6 = 262, + CV_SHMEDIA_DR8 = 264, + CV_SHMEDIA_DR10 = 266, + CV_SHMEDIA_DR12 = 268, + CV_SHMEDIA_DR14 = 270, + CV_SHMEDIA_DR16 = 272, + CV_SHMEDIA_DR18 = 274, + CV_SHMEDIA_DR20 = 276, + CV_SHMEDIA_DR22 = 278, + CV_SHMEDIA_DR24 = 280, + CV_SHMEDIA_DR26 = 282, + CV_SHMEDIA_DR28 = 284, + CV_SHMEDIA_DR30 = 286, + CV_SHMEDIA_DR32 = 288, + CV_SHMEDIA_DR34 = 290, + CV_SHMEDIA_DR36 = 292, + CV_SHMEDIA_DR38 = 294, + CV_SHMEDIA_DR40 = 296, + CV_SHMEDIA_DR42 = 298, + CV_SHMEDIA_DR44 = 300, + CV_SHMEDIA_DR46 = 302, + CV_SHMEDIA_DR48 = 304, + CV_SHMEDIA_DR50 = 306, + CV_SHMEDIA_DR52 = 308, + CV_SHMEDIA_DR54 = 310, + CV_SHMEDIA_DR56 = 312, + CV_SHMEDIA_DR58 = 314, + CV_SHMEDIA_DR60 = 316, + CV_SHMEDIA_DR62 = 318, + + // Vector - 128 bit synonyms for 32bit fp register quads + // subtract 384 to find first base single register + CV_SHMEDIA_FV0 = 512, + CV_SHMEDIA_FV4 = 516, + CV_SHMEDIA_FV8 = 520, + CV_SHMEDIA_FV12 = 524, + CV_SHMEDIA_FV16 = 528, + CV_SHMEDIA_FV20 = 532, + CV_SHMEDIA_FV24 = 536, + CV_SHMEDIA_FV28 = 540, + CV_SHMEDIA_FV32 = 544, + CV_SHMEDIA_FV36 = 548, + CV_SHMEDIA_FV40 = 552, + CV_SHMEDIA_FV44 = 556, + CV_SHMEDIA_FV48 = 560, + CV_SHMEDIA_FV52 = 564, + CV_SHMEDIA_FV56 = 568, + CV_SHMEDIA_FV60 = 572, + + // Matrix - 512 bit synonyms for 16 adjacent 32bit fp registers + // subtract 896 to find first base single register + CV_SHMEDIA_MTRX0 = 1024, + CV_SHMEDIA_MTRX16 = 1040, + CV_SHMEDIA_MTRX32 = 1056, + CV_SHMEDIA_MTRX48 = 1072, + + // Control - Implementation defined 64bit control registers + CV_SHMEDIA_CR0 = 2000, + CV_SHMEDIA_CR1 = 2001, + CV_SHMEDIA_CR2 = 2002, + CV_SHMEDIA_CR3 = 2003, + CV_SHMEDIA_CR4 = 2004, + CV_SHMEDIA_CR5 = 2005, + CV_SHMEDIA_CR6 = 2006, + CV_SHMEDIA_CR7 = 2007, + CV_SHMEDIA_CR8 = 2008, + CV_SHMEDIA_CR9 = 2009, + CV_SHMEDIA_CR10 = 2010, + CV_SHMEDIA_CR11 = 2011, + CV_SHMEDIA_CR12 = 2012, + CV_SHMEDIA_CR13 = 2013, + CV_SHMEDIA_CR14 = 2014, + CV_SHMEDIA_CR15 = 2015, + CV_SHMEDIA_CR16 = 2016, + CV_SHMEDIA_CR17 = 2017, + CV_SHMEDIA_CR18 = 2018, + CV_SHMEDIA_CR19 = 2019, + CV_SHMEDIA_CR20 = 2020, + CV_SHMEDIA_CR21 = 2021, + CV_SHMEDIA_CR22 = 2022, + CV_SHMEDIA_CR23 = 2023, + CV_SHMEDIA_CR24 = 2024, + CV_SHMEDIA_CR25 = 2025, + CV_SHMEDIA_CR26 = 2026, + CV_SHMEDIA_CR27 = 2027, + CV_SHMEDIA_CR28 = 2028, + CV_SHMEDIA_CR29 = 2029, + CV_SHMEDIA_CR30 = 2030, + CV_SHMEDIA_CR31 = 2031, + CV_SHMEDIA_CR32 = 2032, + CV_SHMEDIA_CR33 = 2033, + CV_SHMEDIA_CR34 = 2034, + CV_SHMEDIA_CR35 = 2035, + CV_SHMEDIA_CR36 = 2036, + CV_SHMEDIA_CR37 = 2037, + CV_SHMEDIA_CR38 = 2038, + CV_SHMEDIA_CR39 = 2039, + CV_SHMEDIA_CR40 = 2040, + CV_SHMEDIA_CR41 = 2041, + CV_SHMEDIA_CR42 = 2042, + CV_SHMEDIA_CR43 = 2043, + CV_SHMEDIA_CR44 = 2044, + CV_SHMEDIA_CR45 = 2045, + CV_SHMEDIA_CR46 = 2046, + CV_SHMEDIA_CR47 = 2047, + CV_SHMEDIA_CR48 = 2048, + CV_SHMEDIA_CR49 = 2049, + CV_SHMEDIA_CR50 = 2050, + CV_SHMEDIA_CR51 = 2051, + CV_SHMEDIA_CR52 = 2052, + CV_SHMEDIA_CR53 = 2053, + CV_SHMEDIA_CR54 = 2054, + CV_SHMEDIA_CR55 = 2055, + CV_SHMEDIA_CR56 = 2056, + CV_SHMEDIA_CR57 = 2057, + CV_SHMEDIA_CR58 = 2058, + CV_SHMEDIA_CR59 = 2059, + CV_SHMEDIA_CR60 = 2060, + CV_SHMEDIA_CR61 = 2061, + CV_SHMEDIA_CR62 = 2062, + CV_SHMEDIA_CR63 = 2063, + + CV_SHMEDIA_FPSCR = 2064, + + // Compact mode synonyms + CV_SHMEDIA_GBR = CV_SHMEDIA_R16, + CV_SHMEDIA_MACL = 90, // synonym for lower 32bits of media R17 + CV_SHMEDIA_MACH = 91, // synonym for upper 32bits of media R17 + CV_SHMEDIA_PR = CV_SHMEDIA_R18, + CV_SHMEDIA_T = 92, // synonym for lowest bit of media R19 + CV_SHMEDIA_FPUL = CV_SHMEDIA_FR32, + CV_SHMEDIA_PC = 93, + CV_SHMEDIA_SR = CV_SHMEDIA_CR0, + + // + // AMD64 registers + // + + CV_AMD64_AL = 1, + CV_AMD64_CL = 2, + CV_AMD64_DL = 3, + CV_AMD64_BL = 4, + CV_AMD64_AH = 5, + CV_AMD64_CH = 6, + CV_AMD64_DH = 7, + CV_AMD64_BH = 8, + CV_AMD64_AX = 9, + CV_AMD64_CX = 10, + CV_AMD64_DX = 11, + CV_AMD64_BX = 12, + CV_AMD64_SP = 13, + CV_AMD64_BP = 14, + CV_AMD64_SI = 15, + CV_AMD64_DI = 16, + CV_AMD64_EAX = 17, + CV_AMD64_ECX = 18, + CV_AMD64_EDX = 19, + CV_AMD64_EBX = 20, + CV_AMD64_ESP = 21, + CV_AMD64_EBP = 22, + CV_AMD64_ESI = 23, + CV_AMD64_EDI = 24, + CV_AMD64_ES = 25, + CV_AMD64_CS = 26, + CV_AMD64_SS = 27, + CV_AMD64_DS = 28, + CV_AMD64_FS = 29, + CV_AMD64_GS = 30, + CV_AMD64_FLAGS = 32, + CV_AMD64_RIP = 33, + CV_AMD64_EFLAGS = 34, + + // Control registers + CV_AMD64_CR0 = 80, + CV_AMD64_CR1 = 81, + CV_AMD64_CR2 = 82, + CV_AMD64_CR3 = 83, + CV_AMD64_CR4 = 84, + CV_AMD64_CR8 = 88, + + // Debug registers + CV_AMD64_DR0 = 90, + CV_AMD64_DR1 = 91, + CV_AMD64_DR2 = 92, + CV_AMD64_DR3 = 93, + CV_AMD64_DR4 = 94, + CV_AMD64_DR5 = 95, + CV_AMD64_DR6 = 96, + CV_AMD64_DR7 = 97, + CV_AMD64_DR8 = 98, + CV_AMD64_DR9 = 99, + CV_AMD64_DR10 = 100, + CV_AMD64_DR11 = 101, + CV_AMD64_DR12 = 102, + CV_AMD64_DR13 = 103, + CV_AMD64_DR14 = 104, + CV_AMD64_DR15 = 105, + + CV_AMD64_GDTR = 110, + CV_AMD64_GDTL = 111, + CV_AMD64_IDTR = 112, + CV_AMD64_IDTL = 113, + CV_AMD64_LDTR = 114, + CV_AMD64_TR = 115, + + CV_AMD64_ST0 = 128, + CV_AMD64_ST1 = 129, + CV_AMD64_ST2 = 130, + CV_AMD64_ST3 = 131, + CV_AMD64_ST4 = 132, + CV_AMD64_ST5 = 133, + CV_AMD64_ST6 = 134, + CV_AMD64_ST7 = 135, + CV_AMD64_CTRL = 136, + CV_AMD64_STAT = 137, + CV_AMD64_TAG = 138, + CV_AMD64_FPIP = 139, + CV_AMD64_FPCS = 140, + CV_AMD64_FPDO = 141, + CV_AMD64_FPDS = 142, + CV_AMD64_ISEM = 143, + CV_AMD64_FPEIP = 144, + CV_AMD64_FPEDO = 145, + + CV_AMD64_MM0 = 146, + CV_AMD64_MM1 = 147, + CV_AMD64_MM2 = 148, + CV_AMD64_MM3 = 149, + CV_AMD64_MM4 = 150, + CV_AMD64_MM5 = 151, + CV_AMD64_MM6 = 152, + CV_AMD64_MM7 = 153, + + CV_AMD64_XMM0 = 154, // KATMAI registers + CV_AMD64_XMM1 = 155, + CV_AMD64_XMM2 = 156, + CV_AMD64_XMM3 = 157, + CV_AMD64_XMM4 = 158, + CV_AMD64_XMM5 = 159, + CV_AMD64_XMM6 = 160, + CV_AMD64_XMM7 = 161, + + CV_AMD64_XMM0_0 = 162, // KATMAI sub-registers + CV_AMD64_XMM0_1 = 163, + CV_AMD64_XMM0_2 = 164, + CV_AMD64_XMM0_3 = 165, + CV_AMD64_XMM1_0 = 166, + CV_AMD64_XMM1_1 = 167, + CV_AMD64_XMM1_2 = 168, + CV_AMD64_XMM1_3 = 169, + CV_AMD64_XMM2_0 = 170, + CV_AMD64_XMM2_1 = 171, + CV_AMD64_XMM2_2 = 172, + CV_AMD64_XMM2_3 = 173, + CV_AMD64_XMM3_0 = 174, + CV_AMD64_XMM3_1 = 175, + CV_AMD64_XMM3_2 = 176, + CV_AMD64_XMM3_3 = 177, + CV_AMD64_XMM4_0 = 178, + CV_AMD64_XMM4_1 = 179, + CV_AMD64_XMM4_2 = 180, + CV_AMD64_XMM4_3 = 181, + CV_AMD64_XMM5_0 = 182, + CV_AMD64_XMM5_1 = 183, + CV_AMD64_XMM5_2 = 184, + CV_AMD64_XMM5_3 = 185, + CV_AMD64_XMM6_0 = 186, + CV_AMD64_XMM6_1 = 187, + CV_AMD64_XMM6_2 = 188, + CV_AMD64_XMM6_3 = 189, + CV_AMD64_XMM7_0 = 190, + CV_AMD64_XMM7_1 = 191, + CV_AMD64_XMM7_2 = 192, + CV_AMD64_XMM7_3 = 193, + + CV_AMD64_XMM0L = 194, + CV_AMD64_XMM1L = 195, + CV_AMD64_XMM2L = 196, + CV_AMD64_XMM3L = 197, + CV_AMD64_XMM4L = 198, + CV_AMD64_XMM5L = 199, + CV_AMD64_XMM6L = 200, + CV_AMD64_XMM7L = 201, + + CV_AMD64_XMM0H = 202, + CV_AMD64_XMM1H = 203, + CV_AMD64_XMM2H = 204, + CV_AMD64_XMM3H = 205, + CV_AMD64_XMM4H = 206, + CV_AMD64_XMM5H = 207, + CV_AMD64_XMM6H = 208, + CV_AMD64_XMM7H = 209, + + CV_AMD64_MXCSR = 211, // XMM status register + + CV_AMD64_EMM0L = 220, // XMM sub-registers (WNI integer) + CV_AMD64_EMM1L = 221, + CV_AMD64_EMM2L = 222, + CV_AMD64_EMM3L = 223, + CV_AMD64_EMM4L = 224, + CV_AMD64_EMM5L = 225, + CV_AMD64_EMM6L = 226, + CV_AMD64_EMM7L = 227, + + CV_AMD64_EMM0H = 228, + CV_AMD64_EMM1H = 229, + CV_AMD64_EMM2H = 230, + CV_AMD64_EMM3H = 231, + CV_AMD64_EMM4H = 232, + CV_AMD64_EMM5H = 233, + CV_AMD64_EMM6H = 234, + CV_AMD64_EMM7H = 235, + + // do not change the order of these regs, first one must be even too + CV_AMD64_MM00 = 236, + CV_AMD64_MM01 = 237, + CV_AMD64_MM10 = 238, + CV_AMD64_MM11 = 239, + CV_AMD64_MM20 = 240, + CV_AMD64_MM21 = 241, + CV_AMD64_MM30 = 242, + CV_AMD64_MM31 = 243, + CV_AMD64_MM40 = 244, + CV_AMD64_MM41 = 245, + CV_AMD64_MM50 = 246, + CV_AMD64_MM51 = 247, + CV_AMD64_MM60 = 248, + CV_AMD64_MM61 = 249, + CV_AMD64_MM70 = 250, + CV_AMD64_MM71 = 251, + + // Extended KATMAI registers + CV_AMD64_XMM8 = 252, // KATMAI registers + CV_AMD64_XMM9 = 253, + CV_AMD64_XMM10 = 254, + CV_AMD64_XMM11 = 255, + CV_AMD64_XMM12 = 256, + CV_AMD64_XMM13 = 257, + CV_AMD64_XMM14 = 258, + CV_AMD64_XMM15 = 259, + + CV_AMD64_XMM8_0 = 260, // KATMAI sub-registers + CV_AMD64_XMM8_1 = 261, + CV_AMD64_XMM8_2 = 262, + CV_AMD64_XMM8_3 = 263, + CV_AMD64_XMM9_0 = 264, + CV_AMD64_XMM9_1 = 265, + CV_AMD64_XMM9_2 = 266, + CV_AMD64_XMM9_3 = 267, + CV_AMD64_XMM10_0 = 268, + CV_AMD64_XMM10_1 = 269, + CV_AMD64_XMM10_2 = 270, + CV_AMD64_XMM10_3 = 271, + CV_AMD64_XMM11_0 = 272, + CV_AMD64_XMM11_1 = 273, + CV_AMD64_XMM11_2 = 274, + CV_AMD64_XMM11_3 = 275, + CV_AMD64_XMM12_0 = 276, + CV_AMD64_XMM12_1 = 277, + CV_AMD64_XMM12_2 = 278, + CV_AMD64_XMM12_3 = 279, + CV_AMD64_XMM13_0 = 280, + CV_AMD64_XMM13_1 = 281, + CV_AMD64_XMM13_2 = 282, + CV_AMD64_XMM13_3 = 283, + CV_AMD64_XMM14_0 = 284, + CV_AMD64_XMM14_1 = 285, + CV_AMD64_XMM14_2 = 286, + CV_AMD64_XMM14_3 = 287, + CV_AMD64_XMM15_0 = 288, + CV_AMD64_XMM15_1 = 289, + CV_AMD64_XMM15_2 = 290, + CV_AMD64_XMM15_3 = 291, + + CV_AMD64_XMM8L = 292, + CV_AMD64_XMM9L = 293, + CV_AMD64_XMM10L = 294, + CV_AMD64_XMM11L = 295, + CV_AMD64_XMM12L = 296, + CV_AMD64_XMM13L = 297, + CV_AMD64_XMM14L = 298, + CV_AMD64_XMM15L = 299, + + CV_AMD64_XMM8H = 300, + CV_AMD64_XMM9H = 301, + CV_AMD64_XMM10H = 302, + CV_AMD64_XMM11H = 303, + CV_AMD64_XMM12H = 304, + CV_AMD64_XMM13H = 305, + CV_AMD64_XMM14H = 306, + CV_AMD64_XMM15H = 307, + + CV_AMD64_EMM8L = 308, // XMM sub-registers (WNI integer) + CV_AMD64_EMM9L = 309, + CV_AMD64_EMM10L = 310, + CV_AMD64_EMM11L = 311, + CV_AMD64_EMM12L = 312, + CV_AMD64_EMM13L = 313, + CV_AMD64_EMM14L = 314, + CV_AMD64_EMM15L = 315, + + CV_AMD64_EMM8H = 316, + CV_AMD64_EMM9H = 317, + CV_AMD64_EMM10H = 318, + CV_AMD64_EMM11H = 319, + CV_AMD64_EMM12H = 320, + CV_AMD64_EMM13H = 321, + CV_AMD64_EMM14H = 322, + CV_AMD64_EMM15H = 323, + + // Low byte forms of some standard registers + CV_AMD64_SIL = 324, + CV_AMD64_DIL = 325, + CV_AMD64_BPL = 326, + CV_AMD64_SPL = 327, + + // 64-bit regular registers + CV_AMD64_RAX = 328, + CV_AMD64_RBX = 329, + CV_AMD64_RCX = 330, + CV_AMD64_RDX = 331, + CV_AMD64_RSI = 332, + CV_AMD64_RDI = 333, + CV_AMD64_RBP = 334, + CV_AMD64_RSP = 335, + + // 64-bit integer registers with 8-, 16-, and 32-bit forms (B, W, and D) + CV_AMD64_R8 = 336, + CV_AMD64_R9 = 337, + CV_AMD64_R10 = 338, + CV_AMD64_R11 = 339, + CV_AMD64_R12 = 340, + CV_AMD64_R13 = 341, + CV_AMD64_R14 = 342, + CV_AMD64_R15 = 343, + + CV_AMD64_R8B = 344, + CV_AMD64_R9B = 345, + CV_AMD64_R10B = 346, + CV_AMD64_R11B = 347, + CV_AMD64_R12B = 348, + CV_AMD64_R13B = 349, + CV_AMD64_R14B = 350, + CV_AMD64_R15B = 351, + + CV_AMD64_R8W = 352, + CV_AMD64_R9W = 353, + CV_AMD64_R10W = 354, + CV_AMD64_R11W = 355, + CV_AMD64_R12W = 356, + CV_AMD64_R13W = 357, + CV_AMD64_R14W = 358, + CV_AMD64_R15W = 359, + + CV_AMD64_R8D = 360, + CV_AMD64_R9D = 361, + CV_AMD64_R10D = 362, + CV_AMD64_R11D = 363, + CV_AMD64_R12D = 364, + CV_AMD64_R13D = 365, + CV_AMD64_R14D = 366, + CV_AMD64_R15D = 367, + + // AVX registers 256 bits + CV_AMD64_YMM0 = 368, + CV_AMD64_YMM1 = 369, + CV_AMD64_YMM2 = 370, + CV_AMD64_YMM3 = 371, + CV_AMD64_YMM4 = 372, + CV_AMD64_YMM5 = 373, + CV_AMD64_YMM6 = 374, + CV_AMD64_YMM7 = 375, + CV_AMD64_YMM8 = 376, + CV_AMD64_YMM9 = 377, + CV_AMD64_YMM10 = 378, + CV_AMD64_YMM11 = 379, + CV_AMD64_YMM12 = 380, + CV_AMD64_YMM13 = 381, + CV_AMD64_YMM14 = 382, + CV_AMD64_YMM15 = 383, + + // AVX registers upper 128 bits + CV_AMD64_YMM0H = 384, + CV_AMD64_YMM1H = 385, + CV_AMD64_YMM2H = 386, + CV_AMD64_YMM3H = 387, + CV_AMD64_YMM4H = 388, + CV_AMD64_YMM5H = 389, + CV_AMD64_YMM6H = 390, + CV_AMD64_YMM7H = 391, + CV_AMD64_YMM8H = 392, + CV_AMD64_YMM9H = 393, + CV_AMD64_YMM10H = 394, + CV_AMD64_YMM11H = 395, + CV_AMD64_YMM12H = 396, + CV_AMD64_YMM13H = 397, + CV_AMD64_YMM14H = 398, + CV_AMD64_YMM15H = 399, + + //Lower/upper 8 bytes of XMM registers. Unlike CV_AMD64_XMM, these + //values reprsesent the bit patterns of the registers as 64-bit integers, not + //the representation of these registers as a double. + CV_AMD64_XMM0IL = 400, + CV_AMD64_XMM1IL = 401, + CV_AMD64_XMM2IL = 402, + CV_AMD64_XMM3IL = 403, + CV_AMD64_XMM4IL = 404, + CV_AMD64_XMM5IL = 405, + CV_AMD64_XMM6IL = 406, + CV_AMD64_XMM7IL = 407, + CV_AMD64_XMM8IL = 408, + CV_AMD64_XMM9IL = 409, + CV_AMD64_XMM10IL = 410, + CV_AMD64_XMM11IL = 411, + CV_AMD64_XMM12IL = 412, + CV_AMD64_XMM13IL = 413, + CV_AMD64_XMM14IL = 414, + CV_AMD64_XMM15IL = 415, + + CV_AMD64_XMM0IH = 416, + CV_AMD64_XMM1IH = 417, + CV_AMD64_XMM2IH = 418, + CV_AMD64_XMM3IH = 419, + CV_AMD64_XMM4IH = 420, + CV_AMD64_XMM5IH = 421, + CV_AMD64_XMM6IH = 422, + CV_AMD64_XMM7IH = 423, + CV_AMD64_XMM8IH = 424, + CV_AMD64_XMM9IH = 425, + CV_AMD64_XMM10IH = 426, + CV_AMD64_XMM11IH = 427, + CV_AMD64_XMM12IH = 428, + CV_AMD64_XMM13IH = 429, + CV_AMD64_XMM14IH = 430, + CV_AMD64_XMM15IH = 431, + + CV_AMD64_YMM0I0 = 432, // AVX integer registers + CV_AMD64_YMM0I1 = 433, + CV_AMD64_YMM0I2 = 434, + CV_AMD64_YMM0I3 = 435, + CV_AMD64_YMM1I0 = 436, + CV_AMD64_YMM1I1 = 437, + CV_AMD64_YMM1I2 = 438, + CV_AMD64_YMM1I3 = 439, + CV_AMD64_YMM2I0 = 440, + CV_AMD64_YMM2I1 = 441, + CV_AMD64_YMM2I2 = 442, + CV_AMD64_YMM2I3 = 443, + CV_AMD64_YMM3I0 = 444, + CV_AMD64_YMM3I1 = 445, + CV_AMD64_YMM3I2 = 446, + CV_AMD64_YMM3I3 = 447, + CV_AMD64_YMM4I0 = 448, + CV_AMD64_YMM4I1 = 449, + CV_AMD64_YMM4I2 = 450, + CV_AMD64_YMM4I3 = 451, + CV_AMD64_YMM5I0 = 452, + CV_AMD64_YMM5I1 = 453, + CV_AMD64_YMM5I2 = 454, + CV_AMD64_YMM5I3 = 455, + CV_AMD64_YMM6I0 = 456, + CV_AMD64_YMM6I1 = 457, + CV_AMD64_YMM6I2 = 458, + CV_AMD64_YMM6I3 = 459, + CV_AMD64_YMM7I0 = 460, + CV_AMD64_YMM7I1 = 461, + CV_AMD64_YMM7I2 = 462, + CV_AMD64_YMM7I3 = 463, + CV_AMD64_YMM8I0 = 464, + CV_AMD64_YMM8I1 = 465, + CV_AMD64_YMM8I2 = 466, + CV_AMD64_YMM8I3 = 467, + CV_AMD64_YMM9I0 = 468, + CV_AMD64_YMM9I1 = 469, + CV_AMD64_YMM9I2 = 470, + CV_AMD64_YMM9I3 = 471, + CV_AMD64_YMM10I0 = 472, + CV_AMD64_YMM10I1 = 473, + CV_AMD64_YMM10I2 = 474, + CV_AMD64_YMM10I3 = 475, + CV_AMD64_YMM11I0 = 476, + CV_AMD64_YMM11I1 = 477, + CV_AMD64_YMM11I2 = 478, + CV_AMD64_YMM11I3 = 479, + CV_AMD64_YMM12I0 = 480, + CV_AMD64_YMM12I1 = 481, + CV_AMD64_YMM12I2 = 482, + CV_AMD64_YMM12I3 = 483, + CV_AMD64_YMM13I0 = 484, + CV_AMD64_YMM13I1 = 485, + CV_AMD64_YMM13I2 = 486, + CV_AMD64_YMM13I3 = 487, + CV_AMD64_YMM14I0 = 488, + CV_AMD64_YMM14I1 = 489, + CV_AMD64_YMM14I2 = 490, + CV_AMD64_YMM14I3 = 491, + CV_AMD64_YMM15I0 = 492, + CV_AMD64_YMM15I1 = 493, + CV_AMD64_YMM15I2 = 494, + CV_AMD64_YMM15I3 = 495, + + CV_AMD64_YMM0F0 = 496, // AVX floating-point single precise registers + CV_AMD64_YMM0F1 = 497, + CV_AMD64_YMM0F2 = 498, + CV_AMD64_YMM0F3 = 499, + CV_AMD64_YMM0F4 = 500, + CV_AMD64_YMM0F5 = 501, + CV_AMD64_YMM0F6 = 502, + CV_AMD64_YMM0F7 = 503, + CV_AMD64_YMM1F0 = 504, + CV_AMD64_YMM1F1 = 505, + CV_AMD64_YMM1F2 = 506, + CV_AMD64_YMM1F3 = 507, + CV_AMD64_YMM1F4 = 508, + CV_AMD64_YMM1F5 = 509, + CV_AMD64_YMM1F6 = 510, + CV_AMD64_YMM1F7 = 511, + CV_AMD64_YMM2F0 = 512, + CV_AMD64_YMM2F1 = 513, + CV_AMD64_YMM2F2 = 514, + CV_AMD64_YMM2F3 = 515, + CV_AMD64_YMM2F4 = 516, + CV_AMD64_YMM2F5 = 517, + CV_AMD64_YMM2F6 = 518, + CV_AMD64_YMM2F7 = 519, + CV_AMD64_YMM3F0 = 520, + CV_AMD64_YMM3F1 = 521, + CV_AMD64_YMM3F2 = 522, + CV_AMD64_YMM3F3 = 523, + CV_AMD64_YMM3F4 = 524, + CV_AMD64_YMM3F5 = 525, + CV_AMD64_YMM3F6 = 526, + CV_AMD64_YMM3F7 = 527, + CV_AMD64_YMM4F0 = 528, + CV_AMD64_YMM4F1 = 529, + CV_AMD64_YMM4F2 = 530, + CV_AMD64_YMM4F3 = 531, + CV_AMD64_YMM4F4 = 532, + CV_AMD64_YMM4F5 = 533, + CV_AMD64_YMM4F6 = 534, + CV_AMD64_YMM4F7 = 535, + CV_AMD64_YMM5F0 = 536, + CV_AMD64_YMM5F1 = 537, + CV_AMD64_YMM5F2 = 538, + CV_AMD64_YMM5F3 = 539, + CV_AMD64_YMM5F4 = 540, + CV_AMD64_YMM5F5 = 541, + CV_AMD64_YMM5F6 = 542, + CV_AMD64_YMM5F7 = 543, + CV_AMD64_YMM6F0 = 544, + CV_AMD64_YMM6F1 = 545, + CV_AMD64_YMM6F2 = 546, + CV_AMD64_YMM6F3 = 547, + CV_AMD64_YMM6F4 = 548, + CV_AMD64_YMM6F5 = 549, + CV_AMD64_YMM6F6 = 550, + CV_AMD64_YMM6F7 = 551, + CV_AMD64_YMM7F0 = 552, + CV_AMD64_YMM7F1 = 553, + CV_AMD64_YMM7F2 = 554, + CV_AMD64_YMM7F3 = 555, + CV_AMD64_YMM7F4 = 556, + CV_AMD64_YMM7F5 = 557, + CV_AMD64_YMM7F6 = 558, + CV_AMD64_YMM7F7 = 559, + CV_AMD64_YMM8F0 = 560, + CV_AMD64_YMM8F1 = 561, + CV_AMD64_YMM8F2 = 562, + CV_AMD64_YMM8F3 = 563, + CV_AMD64_YMM8F4 = 564, + CV_AMD64_YMM8F5 = 565, + CV_AMD64_YMM8F6 = 566, + CV_AMD64_YMM8F7 = 567, + CV_AMD64_YMM9F0 = 568, + CV_AMD64_YMM9F1 = 569, + CV_AMD64_YMM9F2 = 570, + CV_AMD64_YMM9F3 = 571, + CV_AMD64_YMM9F4 = 572, + CV_AMD64_YMM9F5 = 573, + CV_AMD64_YMM9F6 = 574, + CV_AMD64_YMM9F7 = 575, + CV_AMD64_YMM10F0 = 576, + CV_AMD64_YMM10F1 = 577, + CV_AMD64_YMM10F2 = 578, + CV_AMD64_YMM10F3 = 579, + CV_AMD64_YMM10F4 = 580, + CV_AMD64_YMM10F5 = 581, + CV_AMD64_YMM10F6 = 582, + CV_AMD64_YMM10F7 = 583, + CV_AMD64_YMM11F0 = 584, + CV_AMD64_YMM11F1 = 585, + CV_AMD64_YMM11F2 = 586, + CV_AMD64_YMM11F3 = 587, + CV_AMD64_YMM11F4 = 588, + CV_AMD64_YMM11F5 = 589, + CV_AMD64_YMM11F6 = 590, + CV_AMD64_YMM11F7 = 591, + CV_AMD64_YMM12F0 = 592, + CV_AMD64_YMM12F1 = 593, + CV_AMD64_YMM12F2 = 594, + CV_AMD64_YMM12F3 = 595, + CV_AMD64_YMM12F4 = 596, + CV_AMD64_YMM12F5 = 597, + CV_AMD64_YMM12F6 = 598, + CV_AMD64_YMM12F7 = 599, + CV_AMD64_YMM13F0 = 600, + CV_AMD64_YMM13F1 = 601, + CV_AMD64_YMM13F2 = 602, + CV_AMD64_YMM13F3 = 603, + CV_AMD64_YMM13F4 = 604, + CV_AMD64_YMM13F5 = 605, + CV_AMD64_YMM13F6 = 606, + CV_AMD64_YMM13F7 = 607, + CV_AMD64_YMM14F0 = 608, + CV_AMD64_YMM14F1 = 609, + CV_AMD64_YMM14F2 = 610, + CV_AMD64_YMM14F3 = 611, + CV_AMD64_YMM14F4 = 612, + CV_AMD64_YMM14F5 = 613, + CV_AMD64_YMM14F6 = 614, + CV_AMD64_YMM14F7 = 615, + CV_AMD64_YMM15F0 = 616, + CV_AMD64_YMM15F1 = 617, + CV_AMD64_YMM15F2 = 618, + CV_AMD64_YMM15F3 = 619, + CV_AMD64_YMM15F4 = 620, + CV_AMD64_YMM15F5 = 621, + CV_AMD64_YMM15F6 = 622, + CV_AMD64_YMM15F7 = 623, + + CV_AMD64_YMM0D0 = 624, // AVX floating-point double precise registers + CV_AMD64_YMM0D1 = 625, + CV_AMD64_YMM0D2 = 626, + CV_AMD64_YMM0D3 = 627, + CV_AMD64_YMM1D0 = 628, + CV_AMD64_YMM1D1 = 629, + CV_AMD64_YMM1D2 = 630, + CV_AMD64_YMM1D3 = 631, + CV_AMD64_YMM2D0 = 632, + CV_AMD64_YMM2D1 = 633, + CV_AMD64_YMM2D2 = 634, + CV_AMD64_YMM2D3 = 635, + CV_AMD64_YMM3D0 = 636, + CV_AMD64_YMM3D1 = 637, + CV_AMD64_YMM3D2 = 638, + CV_AMD64_YMM3D3 = 639, + CV_AMD64_YMM4D0 = 640, + CV_AMD64_YMM4D1 = 641, + CV_AMD64_YMM4D2 = 642, + CV_AMD64_YMM4D3 = 643, + CV_AMD64_YMM5D0 = 644, + CV_AMD64_YMM5D1 = 645, + CV_AMD64_YMM5D2 = 646, + CV_AMD64_YMM5D3 = 647, + CV_AMD64_YMM6D0 = 648, + CV_AMD64_YMM6D1 = 649, + CV_AMD64_YMM6D2 = 650, + CV_AMD64_YMM6D3 = 651, + CV_AMD64_YMM7D0 = 652, + CV_AMD64_YMM7D1 = 653, + CV_AMD64_YMM7D2 = 654, + CV_AMD64_YMM7D3 = 655, + CV_AMD64_YMM8D0 = 656, + CV_AMD64_YMM8D1 = 657, + CV_AMD64_YMM8D2 = 658, + CV_AMD64_YMM8D3 = 659, + CV_AMD64_YMM9D0 = 660, + CV_AMD64_YMM9D1 = 661, + CV_AMD64_YMM9D2 = 662, + CV_AMD64_YMM9D3 = 663, + CV_AMD64_YMM10D0 = 664, + CV_AMD64_YMM10D1 = 665, + CV_AMD64_YMM10D2 = 666, + CV_AMD64_YMM10D3 = 667, + CV_AMD64_YMM11D0 = 668, + CV_AMD64_YMM11D1 = 669, + CV_AMD64_YMM11D2 = 670, + CV_AMD64_YMM11D3 = 671, + CV_AMD64_YMM12D0 = 672, + CV_AMD64_YMM12D1 = 673, + CV_AMD64_YMM12D2 = 674, + CV_AMD64_YMM12D3 = 675, + CV_AMD64_YMM13D0 = 676, + CV_AMD64_YMM13D1 = 677, + CV_AMD64_YMM13D2 = 678, + CV_AMD64_YMM13D3 = 679, + CV_AMD64_YMM14D0 = 680, + CV_AMD64_YMM14D1 = 681, + CV_AMD64_YMM14D2 = 682, + CV_AMD64_YMM14D3 = 683, + CV_AMD64_YMM15D0 = 684, + CV_AMD64_YMM15D1 = 685, + CV_AMD64_YMM15D2 = 686, + CV_AMD64_YMM15D3 = 687 + + + // Note: Next set of platform registers need to go into a new enum... + // this one is above 44K now. + +} CV_HREG_e; + +typedef enum CV_HLSLREG_e { + CV_HLSLREG_TEMP = 0, + CV_HLSLREG_INPUT = 1, + CV_HLSLREG_OUTPUT = 2, + CV_HLSLREG_INDEXABLE_TEMP = 3, + CV_HLSLREG_IMMEDIATE32 = 4, + CV_HLSLREG_IMMEDIATE64 = 5, + CV_HLSLREG_SAMPLER = 6, + CV_HLSLREG_RESOURCE = 7, + CV_HLSLREG_CONSTANT_BUFFER = 8, + CV_HLSLREG_IMMEDIATE_CONSTANT_BUFFER = 9, + CV_HLSLREG_LABEL = 10, + CV_HLSLREG_INPUT_PRIMITIVEID = 11, + CV_HLSLREG_OUTPUT_DEPTH = 12, + CV_HLSLREG_NULL = 13, + CV_HLSLREG_RASTERIZER = 14, + CV_HLSLREG_OUTPUT_COVERAGE_MASK = 15, + CV_HLSLREG_STREAM = 16, + CV_HLSLREG_FUNCTION_BODY = 17, + CV_HLSLREG_FUNCTION_TABLE = 18, + CV_HLSLREG_INTERFACE = 19, + CV_HLSLREG_FUNCTION_INPUT = 20, + CV_HLSLREG_FUNCTION_OUTPUT = 21, + CV_HLSLREG_OUTPUT_CONTROL_POINT_ID = 22, + CV_HLSLREG_INPUT_FORK_INSTANCE_ID = 23, + CV_HLSLREG_INPUT_JOIN_INSTANCE_ID = 24, + CV_HLSLREG_INPUT_CONTROL_POINT = 25, + CV_HLSLREG_OUTPUT_CONTROL_POINT = 26, + CV_HLSLREG_INPUT_PATCH_CONSTANT = 27, + CV_HLSLREG_INPUT_DOMAIN_POINT = 28, + CV_HLSLREG_THIS_POINTER = 29, + CV_HLSLREG_UNORDERED_ACCESS_VIEW = 30, + CV_HLSLREG_THREAD_GROUP_SHARED_MEMORY = 31, + CV_HLSLREG_INPUT_THREAD_ID = 32, + CV_HLSLREG_INPUT_THREAD_GROUP_ID = 33, + CV_HLSLREG_INPUT_THREAD_ID_IN_GROUP = 34, + CV_HLSLREG_INPUT_COVERAGE_MASK = 35, + CV_HLSLREG_INPUT_THREAD_ID_IN_GROUP_FLATTENED = 36, + CV_HLSLREG_INPUT_GS_INSTANCE_ID = 37, + CV_HLSLREG_OUTPUT_DEPTH_GREATER_EQUAL = 38, + CV_HLSLREG_OUTPUT_DEPTH_LESS_EQUAL = 39, + CV_HLSLREG_CYCLE_COUNTER = 40, +} CV_HLSLREG_e; + +enum StackFrameTypeEnum +{ + FrameTypeFPO, // Frame pointer omitted, FPO info available + FrameTypeTrap, // Kernel Trap frame + FrameTypeTSS, // Kernel Trap frame + FrameTypeStandard, // Standard EBP stackframe + FrameTypeFrameData, // Frame pointer omitted, FrameData info available + + FrameTypeUnknown = -1, // Frame which does not have any debug info +}; + +enum MemoryTypeEnum +{ + MemTypeCode, // Read only code memory + MemTypeData, // Read only data/stack memory + MemTypeStack, // Read only stack memory + MemTypeCodeOnHeap, // Read only memory for code generated on heap by runtime + + MemTypeAny = -1, +}; + +typedef enum CV_HLSLMemorySpace_e +{ + // HLSL specific memory spaces + + CV_HLSL_MEMSPACE_DATA = 0x00, + CV_HLSL_MEMSPACE_SAMPLER = 0x01, + CV_HLSL_MEMSPACE_RESOURCE = 0x02, + CV_HLSL_MEMSPACE_RWRESOURCE = 0x03, + + CV_HLSL_MEMSPACE_MAX = 0x0F, +} CV_HLSLMemorySpace_e; + +#endif diff --git a/llvm/tools/objwriter/debugInfo/codeView/codeViewTypeBuilder.cpp b/llvm/tools/objwriter/debugInfo/codeView/codeViewTypeBuilder.cpp new file mode 100644 index 0000000000000..de90c5319008d --- /dev/null +++ b/llvm/tools/objwriter/debugInfo/codeView/codeViewTypeBuilder.cpp @@ -0,0 +1,344 @@ +//===---- codeViewTypeBuilder.cpp -------------------------------*- C++ -*-===// +// +// type builder implementation using codeview::TypeTableBuilder +// +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// +//===----------------------------------------------------------------------===// + +#include "codeViewTypeBuilder.h" +#include "llvm/BinaryFormat/COFF.h" +#include +#include + +UserDefinedCodeViewTypesBuilder::UserDefinedCodeViewTypesBuilder() + : Allocator(), TypeTable(Allocator) +{ + // We pretend that the MethodTable pointer in System.Object is VTable shape. + // We use the same "Vtable" for all types because the vtable shape debug + // record is not expressive enough to capture our vtable shape (where the + // vtable slots don't start at the beginning of the vtable). + VFTableShapeRecord vfTableShape(TypeRecordKind::VFTableShape); + ClassVTableTypeIndex = TypeTable.writeLeafType(vfTableShape); + + PointerRecord ptrToVfTableShape(ClassVTableTypeIndex, + TargetPointerSize == 8 ? PointerKind::Near64 : PointerKind::Near32, + PointerMode::LValueReference, + PointerOptions::None, + 0); + + VFuncTabTypeIndex = TypeTable.writeLeafType(ptrToVfTableShape); +} + +void UserDefinedCodeViewTypesBuilder::EmitCodeViewMagicVersion() { + Streamer->emitValueToAlignment(4); + Streamer->AddComment("Debug section magic"); + Streamer->emitIntValue(COFF::DEBUG_SECTION_MAGIC, 4); +} + +ClassOptions UserDefinedCodeViewTypesBuilder::GetCommonClassOptions() { + return ClassOptions(); +} + +void UserDefinedCodeViewTypesBuilder::EmitTypeInformation( + MCSection *TypeSection, + MCSection *StrSection) { + + if (TypeTable.empty()) + return; + + Streamer->SwitchSection(TypeSection); + EmitCodeViewMagicVersion(); + + TypeTable.ForEachRecord([&](TypeIndex FieldTypeIndex, + CVRecord Record) { + StringRef S(reinterpret_cast(Record.data().data()), Record.data().size()); + Streamer->emitBinaryData(S); + }); +} + +unsigned UserDefinedCodeViewTypesBuilder::GetEnumFieldListType( + uint64 Count, const EnumRecordTypeDescriptor *TypeRecords) { + ContinuationRecordBuilder CRB; + CRB.begin(ContinuationRecordKind::FieldList); +#ifndef NDEBUG + uint64 MaxInt = (unsigned int)-1; + assert(Count <= MaxInt && "There are too many fields inside enum"); +#endif + for (int i = 0; i < (int)Count; ++i) { + EnumRecordTypeDescriptor record = TypeRecords[i]; + EnumeratorRecord ER(MemberAccess::Public, APSInt::getUnsigned(record.Value), + record.Name); + CRB.writeMemberType(ER); + } + return TypeTable.insertRecord(CRB).getIndex(); +} + +unsigned UserDefinedCodeViewTypesBuilder::GetEnumTypeIndex( + const EnumTypeDescriptor &TypeDescriptor, + const EnumRecordTypeDescriptor *TypeRecords) { + + ClassOptions CO = GetCommonClassOptions(); + unsigned FieldListIndex = + GetEnumFieldListType(TypeDescriptor.ElementCount, TypeRecords); + TypeIndex FieldListIndexType = TypeIndex(FieldListIndex); + TypeIndex ElementTypeIndex = TypeIndex(TypeDescriptor.ElementType); + + EnumRecord EnumRecord(TypeDescriptor.ElementCount, CO, FieldListIndexType, + TypeDescriptor.Name, StringRef(), + ElementTypeIndex); + + TypeIndex Type = TypeTable.writeLeafType(EnumRecord); + UserDefinedTypes.push_back(std::make_pair(TypeDescriptor.Name, Type.getIndex())); + return Type.getIndex(); +} + +unsigned UserDefinedCodeViewTypesBuilder::GetClassTypeIndex( + const ClassTypeDescriptor &ClassDescriptor) { + TypeRecordKind Kind = + ClassDescriptor.IsStruct ? TypeRecordKind::Struct : TypeRecordKind::Class; + ClassOptions CO = ClassOptions::ForwardReference | GetCommonClassOptions(); + + ClassRecord CR(Kind, 0, CO, TypeIndex(), TypeIndex(), TypeIndex(), 0, + ClassDescriptor.Name, StringRef()); + TypeIndex FwdDeclTI = TypeTable.writeLeafType(CR); + return FwdDeclTI.getIndex(); +} + +unsigned UserDefinedCodeViewTypesBuilder::GetCompleteClassTypeIndex( + const ClassTypeDescriptor &ClassDescriptor, + const ClassFieldsTypeDescriptior &ClassFieldsDescriptor, + const DataFieldDescriptor *FieldsDescriptors, + const StaticDataFieldDescriptor *StaticsDescriptors) { + + ContinuationRecordBuilder CRB; + CRB.begin(ContinuationRecordKind::FieldList); + + uint16_t memberCount = 0; + if (ClassDescriptor.BaseClassId != 0) { + memberCount++; + AddBaseClass(CRB, ClassDescriptor.BaseClassId); + } + else if (!ClassDescriptor.IsStruct) { + memberCount++; + AddClassVTShape(CRB); + } + + for (int i = 0; i < ClassFieldsDescriptor.FieldsCount; ++i) { + DataFieldDescriptor desc = FieldsDescriptors[i]; + MemberAccess Access = MemberAccess::Public; + TypeIndex MemberBaseType(desc.FieldTypeIndex); + if (desc.Offset == 0xFFFFFFFF) + { + StaticDataMemberRecord SDMR(Access, MemberBaseType, desc.Name); + CRB.writeMemberType(SDMR); + } + else + { + int MemberOffsetInBytes = desc.Offset; + DataMemberRecord DMR(Access, MemberBaseType, MemberOffsetInBytes, + desc.Name); + CRB.writeMemberType(DMR); + } + memberCount++; + } + TypeIndex FieldListIndex = TypeTable.insertRecord(CRB); + TypeRecordKind Kind = + ClassDescriptor.IsStruct ? TypeRecordKind::Struct : TypeRecordKind::Class; + ClassOptions CO = GetCommonClassOptions(); + ClassRecord CR(Kind, memberCount, CO, FieldListIndex, + TypeIndex(), TypeIndex(), ClassFieldsDescriptor.Size, + ClassDescriptor.Name, StringRef()); + TypeIndex ClassIndex = TypeTable.writeLeafType(CR); + + UserDefinedTypes.push_back(std::make_pair(ClassDescriptor.Name, ClassIndex.getIndex())); + + return ClassIndex.getIndex(); +} + +unsigned UserDefinedCodeViewTypesBuilder::GetArrayTypeIndex( + const ClassTypeDescriptor &ClassDescriptor, + const ArrayTypeDescriptor &ArrayDescriptor) { + ContinuationRecordBuilder CRB; + CRB.begin(ContinuationRecordKind::FieldList); + + unsigned Offset = 0; + unsigned FieldsCount = 0; + + assert(ClassDescriptor.BaseClassId != 0); + + AddBaseClass(CRB, ClassDescriptor.BaseClassId); + FieldsCount++; + Offset += TargetPointerSize; + + MemberAccess Access = MemberAccess::Public; + TypeIndex IndexType = TypeIndex(SimpleTypeKind::Int32); + DataMemberRecord CountDMR(Access, IndexType, Offset, "count"); + CRB.writeMemberType(CountDMR); + FieldsCount++; + Offset += TargetPointerSize; + + if (ArrayDescriptor.IsMultiDimensional == 1) { + for (unsigned i = 0; i < ArrayDescriptor.Rank; ++i) { + DataMemberRecord LengthDMR(Access, TypeIndex(SimpleTypeKind::Int32), + Offset, ArrayDimentions.GetLengthName(i)); + CRB.writeMemberType(LengthDMR); + FieldsCount++; + Offset += 4; + } + + for (unsigned i = 0; i < ArrayDescriptor.Rank; ++i) { + DataMemberRecord BoundsDMR(Access, TypeIndex(SimpleTypeKind::Int32), + Offset, ArrayDimentions.GetBoundsName(i)); + CRB.writeMemberType(BoundsDMR); + FieldsCount++; + Offset += 4; + } + } + + TypeIndex ElementTypeIndex = TypeIndex(ArrayDescriptor.ElementType); + ArrayRecord AR(ElementTypeIndex, IndexType, ArrayDescriptor.Size, ""); + TypeIndex ArrayIndex = TypeTable.writeLeafType(AR); + DataMemberRecord ArrayDMR(Access, ArrayIndex, Offset, "values"); + CRB.writeMemberType(ArrayDMR); + FieldsCount++; + + TypeIndex FieldListIndex = TypeTable.insertRecord(CRB); + + assert(ClassDescriptor.IsStruct == false); + TypeRecordKind Kind = TypeRecordKind::Class; + ClassOptions CO = GetCommonClassOptions(); + ClassRecord CR(Kind, FieldsCount, CO, FieldListIndex, TypeIndex(), + TypeIndex(), ArrayDescriptor.Size, ClassDescriptor.Name, + StringRef()); + TypeIndex ClassIndex = TypeTable.writeLeafType(CR); + + UserDefinedTypes.push_back(std::make_pair(ClassDescriptor.Name, ClassIndex.getIndex())); + + return ClassIndex.getIndex(); +} + +unsigned UserDefinedCodeViewTypesBuilder::GetPointerTypeIndex(const PointerTypeDescriptor& PointerDescriptor) +{ + uint32_t elementType = PointerDescriptor.ElementType; + PointerKind pointerKind = PointerDescriptor.Is64Bit ? PointerKind::Near64 : PointerKind::Near32; + PointerMode pointerMode = PointerDescriptor.IsReference ? PointerMode::LValueReference : PointerMode::Pointer; + PointerOptions pointerOptions = PointerDescriptor.IsConst ? PointerOptions::Const : PointerOptions::None; + + PointerRecord PointerToClass(TypeIndex(elementType), pointerKind, pointerMode, pointerOptions, 0); + TypeIndex PointerIndex = TypeTable.writeLeafType(PointerToClass); + return PointerIndex.getIndex(); +} + +unsigned UserDefinedCodeViewTypesBuilder::GetMemberFunctionTypeIndex(const MemberFunctionTypeDescriptor& MemberDescriptor, + uint32_t const *const ArgumentTypes) +{ + std::vector argumentTypes; + argumentTypes.reserve(MemberDescriptor.NumberOfArguments); + for (uint16_t iArgument = 0; iArgument < MemberDescriptor.NumberOfArguments; iArgument++) + { + argumentTypes.emplace_back(ArgumentTypes[iArgument]); + } + + ArgListRecord ArgList(TypeRecordKind::ArgList, argumentTypes); + TypeIndex ArgumentList = TypeTable.writeLeafType(ArgList); + + MemberFunctionRecord MemberFunction(TypeIndex(MemberDescriptor.ReturnType), + TypeIndex(MemberDescriptor.ContainingClass), + TypeIndex(MemberDescriptor.TypeIndexOfThisPointer), + CallingConvention(MemberDescriptor.CallingConvention), + FunctionOptions::None, MemberDescriptor.NumberOfArguments, + ArgumentList, + MemberDescriptor.ThisAdjust); + + TypeIndex MemberFunctionIndex = TypeTable.writeLeafType(MemberFunction); + return MemberFunctionIndex.getIndex(); +} + +unsigned UserDefinedCodeViewTypesBuilder::GetMemberFunctionId(const MemberFunctionIdTypeDescriptor& MemberIdDescriptor) +{ + MemberFuncIdRecord MemberFuncId(TypeIndex(MemberIdDescriptor.MemberFunction), TypeIndex(MemberIdDescriptor.ParentClass), MemberIdDescriptor.Name); + TypeIndex MemberFuncIdIndex = TypeTable.writeLeafType(MemberFuncId); + return MemberFuncIdIndex.getIndex(); +} + +unsigned UserDefinedCodeViewTypesBuilder::GetPrimitiveTypeIndex(PrimitiveTypeFlags Type) { + switch (Type) { + case PrimitiveTypeFlags::Void: + return TypeIndex::Void().getIndex(); + case PrimitiveTypeFlags::Boolean: + return TypeIndex(SimpleTypeKind::Boolean8).getIndex(); + case PrimitiveTypeFlags::Char: + return TypeIndex::WideCharacter().getIndex(); + case PrimitiveTypeFlags::SByte: + return TypeIndex(SimpleTypeKind::SByte).getIndex(); + case PrimitiveTypeFlags::Byte: + return TypeIndex(SimpleTypeKind::Byte).getIndex(); + case PrimitiveTypeFlags::Int16: + return TypeIndex(SimpleTypeKind::Int16).getIndex(); + case PrimitiveTypeFlags::UInt16: + return TypeIndex(SimpleTypeKind::UInt16).getIndex(); + case PrimitiveTypeFlags::Int32: + return TypeIndex::Int32().getIndex(); + case PrimitiveTypeFlags::UInt32: + return TypeIndex::UInt32().getIndex(); + case PrimitiveTypeFlags::Int64: + return TypeIndex::Int64().getIndex(); + case PrimitiveTypeFlags::UInt64: + return TypeIndex::UInt64().getIndex(); + case PrimitiveTypeFlags::Single: + return TypeIndex::Float32().getIndex(); + case PrimitiveTypeFlags::Double: + return TypeIndex::Float64().getIndex(); + case PrimitiveTypeFlags::IntPtr: + case PrimitiveTypeFlags::UIntPtr: + return TargetPointerSize == 4 ? TypeIndex::VoidPointer32().getIndex() : + TypeIndex::VoidPointer64().getIndex(); + default: + assert(false && "Unexpected type"); + return 0; + } +} + +void UserDefinedCodeViewTypesBuilder::AddBaseClass(ContinuationRecordBuilder &CRB, + unsigned BaseClassId) { + MemberAttributes def; + TypeIndex BaseTypeIndex(BaseClassId); + BaseClassRecord BCR(def, BaseTypeIndex, 0); + CRB.writeMemberType(BCR); +} + +void UserDefinedCodeViewTypesBuilder::AddClassVTShape(ContinuationRecordBuilder &CRB) { + VFPtrRecord VfPtr(VFuncTabTypeIndex); + CRB.writeMemberType(VfPtr); +} + +const char *ArrayDimensionsDescriptor::GetLengthName(unsigned index) { + if (Lengths.size() <= index) { + Resize(index + 1); + } + return Lengths[index].c_str(); +} + +const char *ArrayDimensionsDescriptor::GetBoundsName(unsigned index) { + if (Bounds.size() <= index) { + Resize(index); + } + return Bounds[index].c_str(); +} + +void ArrayDimensionsDescriptor::Resize(unsigned NewSize) { + unsigned OldSize = Lengths.size(); + assert(OldSize == Bounds.size()); + Lengths.resize(NewSize); + Bounds.resize(NewSize); + for (unsigned i = OldSize; i < NewSize; ++i) { + std::stringstream ss; + ss << "length" << i; + ss >> Lengths[i]; + ss.clear(); + ss << "bounds" << i; + ss >> Bounds[i]; + } +} diff --git a/llvm/tools/objwriter/debugInfo/codeView/codeViewTypeBuilder.h b/llvm/tools/objwriter/debugInfo/codeView/codeViewTypeBuilder.h new file mode 100644 index 0000000000000..14980fa996374 --- /dev/null +++ b/llvm/tools/objwriter/debugInfo/codeView/codeViewTypeBuilder.h @@ -0,0 +1,74 @@ +//===---- codeViewTypeBuilder.h ---------------------------------*- C++ -*-===// +// +// type builder is used to convert .Net types into CodeView descriptors. +// +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "debugInfo/typeBuilder.h" +#include "llvm/DebugInfo/CodeView/ContinuationRecordBuilder.h" +#include "llvm/DebugInfo/CodeView/GlobalTypeTableBuilder.h" + +#include + +using namespace llvm::codeview; + +class ArrayDimensionsDescriptor { +public: + const char *GetLengthName(unsigned index); + const char *GetBoundsName(unsigned index); + +private: + void Resize(unsigned NewSize); + + std::vector Lengths; + std::vector Bounds; +}; + +class UserDefinedCodeViewTypesBuilder : public UserDefinedTypesBuilder { +public: + UserDefinedCodeViewTypesBuilder(); + void EmitTypeInformation(MCSection *TypeSection, MCSection *StrSection = nullptr) override; + + unsigned GetEnumTypeIndex(const EnumTypeDescriptor &TypeDescriptor, + const EnumRecordTypeDescriptor *TypeRecords) override; + unsigned GetClassTypeIndex(const ClassTypeDescriptor &ClassDescriptor) override; + unsigned GetCompleteClassTypeIndex( + const ClassTypeDescriptor &ClassDescriptor, + const ClassFieldsTypeDescriptior &ClassFieldsDescriptor, + const DataFieldDescriptor *FieldsDescriptors, + const StaticDataFieldDescriptor *StaticsDescriptors) override; + + unsigned GetArrayTypeIndex(const ClassTypeDescriptor &ClassDescriptor, + const ArrayTypeDescriptor &ArrayDescriptor) override; + + unsigned GetPointerTypeIndex(const PointerTypeDescriptor& PointerDescriptor) override; + + unsigned GetMemberFunctionTypeIndex(const MemberFunctionTypeDescriptor& MemberDescriptor, + uint32_t const *const ArgumentTypes) override; + + unsigned GetMemberFunctionId(const MemberFunctionIdTypeDescriptor& MemberIdDescriptor) override; + + unsigned GetPrimitiveTypeIndex(PrimitiveTypeFlags Type) override; + +private: + void EmitCodeViewMagicVersion(); + ClassOptions GetCommonClassOptions(); + + unsigned GetEnumFieldListType(uint64 Count, + const EnumRecordTypeDescriptor *TypeRecords); + + void AddBaseClass(ContinuationRecordBuilder &CRB, unsigned BaseClassId); + void AddClassVTShape(ContinuationRecordBuilder &CRB); + + BumpPtrAllocator Allocator; + GlobalTypeTableBuilder TypeTable; + + ArrayDimensionsDescriptor ArrayDimentions; + TypeIndex ClassVTableTypeIndex; + TypeIndex VFuncTabTypeIndex; +}; diff --git a/llvm/tools/objwriter/debugInfo/dwarf/dwarfAbbrev.cpp b/llvm/tools/objwriter/debugInfo/dwarf/dwarfAbbrev.cpp new file mode 100644 index 0000000000000..db71acd6d6247 --- /dev/null +++ b/llvm/tools/objwriter/debugInfo/dwarf/dwarfAbbrev.cpp @@ -0,0 +1,330 @@ +//===---- dwarfAbbrev.cpp ---------------------------------------*- C++ -*-===// +// +// dwarf abbreviations implementation +// +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// +//===----------------------------------------------------------------------===// + +#include "dwarfAbbrev.h" +#include "llvm/MC/MCContext.h" +#include "llvm/MC/MCObjectFileInfo.h" + +namespace DwarfAbbrev { + +void Dump(MCObjectStreamer *Streamer, uint16_t DwarfVersion, unsigned TargetPointerSize) { + uint16_t DW_FORM_size; + switch (TargetPointerSize) { + case 1: + DW_FORM_size = dwarf::DW_FORM_data1; + break; + case 2: + DW_FORM_size = dwarf::DW_FORM_data2; + break; + case 4: + DW_FORM_size = dwarf::DW_FORM_data4; + break; + case 8: + DW_FORM_size = dwarf::DW_FORM_data8; + break; + default: + assert(false && "Unexpected TargerPointerSize"); + return; + } + + const uint16_t AbbrevTable[] = { + CompileUnit, + dwarf::DW_TAG_compile_unit, dwarf::DW_CHILDREN_yes, + dwarf::DW_AT_producer, dwarf::DW_FORM_string, + dwarf::DW_AT_language, dwarf::DW_FORM_data2, + dwarf::DW_AT_name, dwarf::DW_FORM_string, + dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string, + dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, + dwarf::DW_AT_high_pc, DW_FORM_size, + dwarf::DW_AT_stmt_list, (DwarfVersion >= 4 ? dwarf::DW_FORM_sec_offset : dwarf::DW_FORM_data4), + 0, 0, + + BaseType, + dwarf::DW_TAG_base_type, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, + dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, + 0, 0, + + EnumerationType, + dwarf::DW_TAG_enumeration_type, dwarf::DW_CHILDREN_yes, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_type, dwarf::DW_FORM_ref4, + dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, + 0, 0, + + Enumerator1, + dwarf::DW_TAG_enumerator, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_const_value, dwarf::DW_FORM_data1, + 0, 0, + + Enumerator2, + dwarf::DW_TAG_enumerator, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_const_value, dwarf::DW_FORM_data2, + 0, 0, + + Enumerator4, + dwarf::DW_TAG_enumerator, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_const_value, dwarf::DW_FORM_data4, + 0, 0, + + Enumerator8, + dwarf::DW_TAG_enumerator, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_const_value, dwarf::DW_FORM_data8, + 0, 0, + + TypeDef, + dwarf::DW_TAG_typedef, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_type, dwarf::DW_FORM_ref4, + 0, 0, + + Subprogram, + dwarf::DW_TAG_subprogram, dwarf::DW_CHILDREN_yes, + dwarf::DW_AT_specification, dwarf::DW_FORM_ref4, + dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, + dwarf::DW_AT_high_pc, DW_FORM_size, + dwarf::DW_AT_frame_base, dwarf::DW_FORM_exprloc, + dwarf::DW_AT_object_pointer, dwarf::DW_FORM_ref4, + 0, 0, + + SubprogramNoChildren, + dwarf::DW_TAG_subprogram, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_specification, dwarf::DW_FORM_ref4, + dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, + dwarf::DW_AT_high_pc, DW_FORM_size, + dwarf::DW_AT_frame_base, dwarf::DW_FORM_exprloc, + dwarf::DW_AT_object_pointer, dwarf::DW_FORM_ref4, + 0, 0, + + SubprogramStatic, + dwarf::DW_TAG_subprogram, dwarf::DW_CHILDREN_yes, + dwarf::DW_AT_specification, dwarf::DW_FORM_ref4, + dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, + dwarf::DW_AT_high_pc, DW_FORM_size, + dwarf::DW_AT_frame_base, dwarf::DW_FORM_exprloc, + 0, 0, + + SubprogramStaticNoChildren, + dwarf::DW_TAG_subprogram, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_specification, dwarf::DW_FORM_ref4, + dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, + dwarf::DW_AT_high_pc, DW_FORM_size, + dwarf::DW_AT_frame_base, dwarf::DW_FORM_exprloc, + 0, 0, + + SubprogramSpec, + dwarf::DW_TAG_subprogram, dwarf::DW_CHILDREN_yes, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_linkage_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, + dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, + dwarf::DW_AT_type, dwarf::DW_FORM_ref4, + dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, + dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, + dwarf::DW_AT_object_pointer, dwarf::DW_FORM_ref4, + 0, 0, + + SubprogramStaticSpec, + dwarf::DW_TAG_subprogram, dwarf::DW_CHILDREN_yes, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_linkage_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, + dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, + dwarf::DW_AT_type, dwarf::DW_FORM_ref4, + dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, + dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, + 0, 0, + + SubprogramStaticNoChildrenSpec, + dwarf::DW_TAG_subprogram, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_linkage_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, + dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, + dwarf::DW_AT_type, dwarf::DW_FORM_ref4, + dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, + dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, + 0, 0, + + Variable, + dwarf::DW_TAG_variable, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, + dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, + dwarf::DW_AT_type, dwarf::DW_FORM_ref4, + dwarf::DW_AT_location, dwarf::DW_FORM_exprloc, + 0, 0, + + VariableLoc, + dwarf::DW_TAG_variable, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, + dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, + dwarf::DW_AT_type, dwarf::DW_FORM_ref4, + dwarf::DW_AT_location, dwarf::DW_FORM_sec_offset, + 0, 0, + + VariableStatic, + dwarf::DW_TAG_variable, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_specification, dwarf::DW_FORM_ref4, + dwarf::DW_AT_location, dwarf::DW_FORM_exprloc, + 0, 0, + + FormalParameter, + dwarf::DW_TAG_formal_parameter, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, + dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, + dwarf::DW_AT_type, dwarf::DW_FORM_ref4, + dwarf::DW_AT_location, dwarf::DW_FORM_exprloc, + 0, 0, + + FormalParameterThis, + dwarf::DW_TAG_formal_parameter, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, + dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, + dwarf::DW_AT_type, dwarf::DW_FORM_ref4, + dwarf::DW_AT_location, dwarf::DW_FORM_exprloc, + dwarf::DW_AT_artificial, dwarf::DW_FORM_flag_present, + 0, 0, + + FormalParameterLoc, + dwarf::DW_TAG_formal_parameter, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, + dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, + dwarf::DW_AT_type, dwarf::DW_FORM_ref4, + dwarf::DW_AT_location, dwarf::DW_FORM_sec_offset, + 0, 0, + + FormalParameterThisLoc, + dwarf::DW_TAG_formal_parameter, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, + dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, + dwarf::DW_AT_type, dwarf::DW_FORM_ref4, + dwarf::DW_AT_location, dwarf::DW_FORM_sec_offset, + dwarf::DW_AT_artificial, dwarf::DW_FORM_flag_present, + 0, 0, + + FormalParameterSpec, + dwarf::DW_TAG_formal_parameter, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_type, dwarf::DW_FORM_ref4, + 0, 0, + + FormalParameterThisSpec, + dwarf::DW_TAG_formal_parameter, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_type, dwarf::DW_FORM_ref4, + dwarf::DW_AT_artificial, dwarf::DW_FORM_flag_present, + 0, 0, + + ClassType, + dwarf::DW_TAG_class_type, dwarf::DW_CHILDREN_yes, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_byte_size, dwarf::DW_FORM_data4, + 0, 0, + + ClassTypeNoChildren, + dwarf::DW_TAG_class_type, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_byte_size, dwarf::DW_FORM_data4, + 0, 0, + + ClassTypeDecl, + dwarf::DW_TAG_class_type, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, + 0, 0, + + ClassMember, + dwarf::DW_TAG_member, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_type, dwarf::DW_FORM_ref4, + dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data4, + 0, 0, + + ClassMemberStatic, + dwarf::DW_TAG_member, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + dwarf::DW_AT_type, dwarf::DW_FORM_ref4, + dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, + dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, + 0, 0, + + PointerType, + dwarf::DW_TAG_pointer_type, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_type, dwarf::DW_FORM_ref4, + dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, + 0, 0, + + ReferenceType, + dwarf::DW_TAG_reference_type, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_type, dwarf::DW_FORM_ref4, + dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, + 0, 0, + + ArrayType, + dwarf::DW_TAG_array_type, dwarf::DW_CHILDREN_yes, + dwarf::DW_AT_type, dwarf::DW_FORM_ref4, + 0, 0, + + SubrangeType, + dwarf::DW_TAG_subrange_type, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_upper_bound, dwarf::DW_FORM_udata, + 0, 0, + + ClassInheritance, + dwarf::DW_TAG_inheritance, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_type, dwarf::DW_FORM_ref4, + dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, + 0, 0, + + LexicalBlock, + dwarf::DW_TAG_lexical_block, dwarf::DW_CHILDREN_yes, + dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, + dwarf::DW_AT_high_pc, DW_FORM_size, + 0, 0, + + TryBlock, + dwarf::DW_TAG_try_block, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, + dwarf::DW_AT_high_pc, DW_FORM_size, + 0, 0, + + CatchBlock, + dwarf::DW_TAG_catch_block, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, + dwarf::DW_AT_high_pc, DW_FORM_size, + 0, 0, + + VoidType, + dwarf::DW_TAG_unspecified_type, dwarf::DW_CHILDREN_no, + dwarf::DW_AT_name, dwarf::DW_FORM_strp, + 0, 0, + + VoidPointerType, + dwarf::DW_TAG_pointer_type, dwarf::DW_CHILDREN_no, + 0, 0, + }; + + MCContext &context = Streamer->getContext(); + Streamer->SwitchSection(context.getObjectFileInfo()->getDwarfAbbrevSection()); + + for (uint16_t e : AbbrevTable) { + Streamer->emitULEB128IntValue(e); + } +} + +} diff --git a/llvm/tools/objwriter/debugInfo/dwarf/dwarfAbbrev.h b/llvm/tools/objwriter/debugInfo/dwarf/dwarfAbbrev.h new file mode 100644 index 0000000000000..448123c99a92d --- /dev/null +++ b/llvm/tools/objwriter/debugInfo/dwarf/dwarfAbbrev.h @@ -0,0 +1,64 @@ +//===---- dwarfAbbrev.h -----------------------------------------*- C++ -*-===// +// +// dwarf abbreviations +// +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "llvm/BinaryFormat/Dwarf.h" +#include "llvm/MC/MCObjectStreamer.h" + +using namespace llvm; + +namespace DwarfAbbrev { + +enum DwarfAbbrev : uint16_t +{ + CompileUnit = 0x1, + BaseType, + EnumerationType, + Enumerator1, + Enumerator2, + Enumerator4, + Enumerator8, + TypeDef, + Subprogram, + SubprogramNoChildren, + SubprogramStatic, + SubprogramStaticNoChildren, + SubprogramSpec, + SubprogramStaticSpec, + SubprogramStaticNoChildrenSpec, + Variable, + VariableLoc, + VariableStatic, + FormalParameter, + FormalParameterThis, + FormalParameterLoc, + FormalParameterThisLoc, + FormalParameterSpec, + FormalParameterThisSpec, + ClassType, + ClassTypeNoChildren, + ClassTypeDecl, + ClassMember, + ClassMemberStatic, + PointerType, + ReferenceType, + ArrayType, + SubrangeType, + ClassInheritance, + LexicalBlock, + TryBlock, + CatchBlock, + VoidType, + VoidPointerType, +}; + +void Dump(MCObjectStreamer *Streamer, uint16_t DwarfVersion, unsigned TargetPointerSize); + +} diff --git a/llvm/tools/objwriter/debugInfo/dwarf/dwarfGen.cpp b/llvm/tools/objwriter/debugInfo/dwarf/dwarfGen.cpp new file mode 100644 index 0000000000000..649ed1e446c6a --- /dev/null +++ b/llvm/tools/objwriter/debugInfo/dwarf/dwarfGen.cpp @@ -0,0 +1,1143 @@ +//===---- dwarfGen.cpp ------------------------------------------*- C++ -*-===// +// +// dwarf generator implementation +// +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// +//===----------------------------------------------------------------------===// + +#include "dwarfGen.h" +#include "dwarfAbbrev.h" + +#include "llvm/MC/MCContext.h" +#include "llvm/MC/MCAsmInfo.h" +#include "llvm/MC/MCObjectFileInfo.h" +#include "llvm/Support/LEB128.h" + +#ifdef FEATURE_LANGID_CS +#define DW_LANG_MICROSOFT_CSHARP 0x9e57 +#endif + +// Keep sync with ICorDebugInfo::RegNum (cordebuginfo.h) + +enum class RegNumX86 +{ + REGNUM_EAX, + REGNUM_ECX, + REGNUM_EDX, + REGNUM_EBX, + REGNUM_ESP, + REGNUM_EBP, + REGNUM_ESI, + REGNUM_EDI, + REGNUM_COUNT, + REGNUM_FP = REGNUM_EBP, + REGNUM_SP = REGNUM_ESP +}; + +enum class RegNumArm +{ + REGNUM_R0, + REGNUM_R1, + REGNUM_R2, + REGNUM_R3, + REGNUM_R4, + REGNUM_R5, + REGNUM_R6, + REGNUM_R7, + REGNUM_R8, + REGNUM_R9, + REGNUM_R10, + REGNUM_R11, + REGNUM_R12, + REGNUM_SP, + REGNUM_LR, + REGNUM_PC, + REGNUM_COUNT, + REGNUM_FP = REGNUM_R7 +}; + +enum class RegNumArm64 +{ + REGNUM_X0, + REGNUM_X1, + REGNUM_X2, + REGNUM_X3, + REGNUM_X4, + REGNUM_X5, + REGNUM_X6, + REGNUM_X7, + REGNUM_X8, + REGNUM_X9, + REGNUM_X10, + REGNUM_X11, + REGNUM_X12, + REGNUM_X13, + REGNUM_X14, + REGNUM_X15, + REGNUM_X16, + REGNUM_X17, + REGNUM_X18, + REGNUM_X19, + REGNUM_X20, + REGNUM_X21, + REGNUM_X22, + REGNUM_X23, + REGNUM_X24, + REGNUM_X25, + REGNUM_X26, + REGNUM_X27, + REGNUM_X28, + REGNUM_FP, + REGNUM_LR, + REGNUM_SP, + REGNUM_PC, + REGNUM_COUNT +}; + +enum class RegNumAmd64 +{ + REGNUM_RAX, + REGNUM_RCX, + REGNUM_RDX, + REGNUM_RBX, + REGNUM_RSP, + REGNUM_RBP, + REGNUM_RSI, + REGNUM_RDI, + REGNUM_R8, + REGNUM_R9, + REGNUM_R10, + REGNUM_R11, + REGNUM_R12, + REGNUM_R13, + REGNUM_R14, + REGNUM_R15, + REGNUM_COUNT, + REGNUM_SP = REGNUM_RSP, + REGNUM_FP = REGNUM_RBP +}; + +// Helper routines from lib/MC/MCDwarf.cpp +static const MCExpr *forceExpAbs(MCStreamer &OS, const MCExpr* Expr) { + MCContext &Context = OS.getContext(); + assert(!isa(Expr)); + if (Context.getAsmInfo()->hasAggressiveSymbolFolding()) + return Expr; + + MCSymbol *ABS = Context.createTempSymbol(); + OS.emitAssignment(ABS, Expr); + return MCSymbolRefExpr::create(ABS, Context); +} + +static void emitAbsValue(MCStreamer &OS, const MCExpr *Value, unsigned Size) { + const MCExpr *ABS = forceExpAbs(OS, Value); + OS.emitValue(ABS, Size); +} + +static const MCExpr *MakeStartMinusEndExpr(const MCStreamer &MCOS, + const MCSymbol &Start, + const MCSymbol &End, + int IntVal) { + MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None; + const MCExpr *Res = + MCSymbolRefExpr::create(&End, Variant, MCOS.getContext()); + const MCExpr *RHS = + MCSymbolRefExpr::create(&Start, Variant, MCOS.getContext()); + const MCExpr *Res1 = + MCBinaryExpr::create(MCBinaryExpr::Sub, Res, RHS, MCOS.getContext()); + const MCExpr *Res2 = + MCConstantExpr::create(IntVal, MCOS.getContext()); + const MCExpr *Res3 = + MCBinaryExpr::create(MCBinaryExpr::Sub, Res1, Res2, MCOS.getContext()); + return Res3; +} + +static int GetDwarfRegNum(Triple::ArchType ArchType, int RegNum) { + switch (ArchType) { + case Triple::x86: + switch (static_cast(RegNum)) { + case RegNumX86::REGNUM_EAX: return 0; + case RegNumX86::REGNUM_ECX: return 1; + case RegNumX86::REGNUM_EDX: return 2; + case RegNumX86::REGNUM_EBX: return 3; + case RegNumX86::REGNUM_ESP: return 4; + case RegNumX86::REGNUM_EBP: return 5; + case RegNumX86::REGNUM_ESI: return 6; + case RegNumX86::REGNUM_EDI: return 7; + // fp registers + default: + return RegNum - static_cast(RegNumX86::REGNUM_COUNT) + 32; + } + case Triple::arm: // fall through + case Triple::armeb: // fall through + case Triple::thumb: // fall through + case Triple::thumbeb: + switch (static_cast(RegNum)) { + case RegNumArm::REGNUM_R0: return 0; + case RegNumArm::REGNUM_R1: return 1; + case RegNumArm::REGNUM_R2: return 2; + case RegNumArm::REGNUM_R3: return 3; + case RegNumArm::REGNUM_R4: return 4; + case RegNumArm::REGNUM_R5: return 5; + case RegNumArm::REGNUM_R6: return 6; + case RegNumArm::REGNUM_R7: return 7; + case RegNumArm::REGNUM_R8: return 8; + case RegNumArm::REGNUM_R9: return 9; + case RegNumArm::REGNUM_R10: return 10; + case RegNumArm::REGNUM_R11: return 11; + case RegNumArm::REGNUM_R12: return 12; + case RegNumArm::REGNUM_SP: return 13; + case RegNumArm::REGNUM_LR: return 14; + case RegNumArm::REGNUM_PC: return 15; + // fp registers + default: + return (RegNum - static_cast(RegNumArm::REGNUM_COUNT)) / 2 + 256; + } + case Triple::aarch64: // fall through + case Triple::aarch64_be: + switch (static_cast(RegNum)) { + case RegNumArm64::REGNUM_X0: return 0; + case RegNumArm64::REGNUM_X1: return 1; + case RegNumArm64::REGNUM_X2: return 2; + case RegNumArm64::REGNUM_X3: return 3; + case RegNumArm64::REGNUM_X4: return 4; + case RegNumArm64::REGNUM_X5: return 5; + case RegNumArm64::REGNUM_X6: return 6; + case RegNumArm64::REGNUM_X7: return 7; + case RegNumArm64::REGNUM_X8: return 8; + case RegNumArm64::REGNUM_X9: return 9; + case RegNumArm64::REGNUM_X10: return 10; + case RegNumArm64::REGNUM_X11: return 11; + case RegNumArm64::REGNUM_X12: return 12; + case RegNumArm64::REGNUM_X13: return 13; + case RegNumArm64::REGNUM_X14: return 14; + case RegNumArm64::REGNUM_X15: return 15; + case RegNumArm64::REGNUM_X16: return 16; + case RegNumArm64::REGNUM_X17: return 17; + case RegNumArm64::REGNUM_X18: return 18; + case RegNumArm64::REGNUM_X19: return 19; + case RegNumArm64::REGNUM_X20: return 20; + case RegNumArm64::REGNUM_X21: return 21; + case RegNumArm64::REGNUM_X22: return 22; + case RegNumArm64::REGNUM_X23: return 23; + case RegNumArm64::REGNUM_X24: return 24; + case RegNumArm64::REGNUM_X25: return 25; + case RegNumArm64::REGNUM_X26: return 26; + case RegNumArm64::REGNUM_X27: return 27; + case RegNumArm64::REGNUM_X28: return 28; + case RegNumArm64::REGNUM_FP: return 29; + case RegNumArm64::REGNUM_LR: return 30; + case RegNumArm64::REGNUM_SP: return 31; + case RegNumArm64::REGNUM_PC: return 32; + // fp registers + default: + return RegNum - static_cast(RegNumArm64::REGNUM_COUNT) + 64; + } + case Triple::x86_64: + switch (static_cast(RegNum)) { + case RegNumAmd64::REGNUM_RAX: return 0; + case RegNumAmd64::REGNUM_RDX: return 1; + case RegNumAmd64::REGNUM_RCX: return 2; + case RegNumAmd64::REGNUM_RBX: return 3; + case RegNumAmd64::REGNUM_RSI: return 4; + case RegNumAmd64::REGNUM_RDI: return 5; + case RegNumAmd64::REGNUM_RBP: return 6; + case RegNumAmd64::REGNUM_RSP: return 7; + case RegNumAmd64::REGNUM_R8: return 8; + case RegNumAmd64::REGNUM_R9: return 9; + case RegNumAmd64::REGNUM_R10: return 10; + case RegNumAmd64::REGNUM_R11: return 11; + case RegNumAmd64::REGNUM_R12: return 12; + case RegNumAmd64::REGNUM_R13: return 13; + case RegNumAmd64::REGNUM_R14: return 14; + case RegNumAmd64::REGNUM_R15: return 15; + // fp registers + default: + return RegNum - static_cast(RegNumAmd64::REGNUM_COUNT) + 17; + } + default: + assert(false && "Unexpected architecture"); + return 0; + } +} + +static int GetDwarfFpRegNum(Triple::ArchType ArchType) +{ + switch (ArchType) { + case Triple::x86: + return GetDwarfRegNum(ArchType, static_cast(RegNumX86::REGNUM_FP)); + case Triple::arm: // fall through + case Triple::armeb: // fall through + case Triple::thumb: // fall through + case Triple::thumbeb: + return GetDwarfRegNum(ArchType, static_cast(RegNumArm::REGNUM_FP)); + case Triple::aarch64: // fall through + case Triple::aarch64_be: + return GetDwarfRegNum(ArchType, static_cast(RegNumArm64::REGNUM_FP)); + case Triple::x86_64: + return GetDwarfRegNum(ArchType, static_cast(RegNumAmd64::REGNUM_FP)); + default: + assert(false && "Unexpected architecture"); + return 0; + } +} + +static int GetRegOpSize(int DwarfRegNum) { + if (DwarfRegNum <= 31) { + return 1; + } + else if (DwarfRegNum < 128) { + return 2; + } + else if (DwarfRegNum < 16384) { + return 3; + } + else { + assert(false && "Too big register number"); + return 0; + } +} + +static void EmitBreg(MCObjectStreamer* Streamer, int DwarfRegNum, StringRef bytes) { + if (DwarfRegNum <= 31) { + Streamer->emitIntValue(DwarfRegNum + dwarf::DW_OP_breg0, 1); + } + else { + Streamer->emitIntValue(dwarf::DW_OP_bregx, 1); + Streamer->emitULEB128IntValue(DwarfRegNum); + } + Streamer->emitBytes(bytes); +} + +static void EmitBreg(MCObjectStreamer* Streamer, int DwarfRegNum, int value) { + if (DwarfRegNum <= 31) { + Streamer->emitIntValue(DwarfRegNum + dwarf::DW_OP_breg0, 1); + } + else { + Streamer->emitIntValue(dwarf::DW_OP_bregx, 1); + Streamer->emitULEB128IntValue(DwarfRegNum); + } + Streamer->emitSLEB128IntValue(value); +} + +static void EmitReg(MCObjectStreamer* Streamer, int DwarfRegNum) { + if (DwarfRegNum <= 31) { + Streamer->emitIntValue(DwarfRegNum + dwarf::DW_OP_reg0, 1); + } + else { + Streamer->emitIntValue(dwarf::DW_OP_regx, 1); + Streamer->emitULEB128IntValue(DwarfRegNum); + } +} + +static void EmitVarLocation(MCObjectStreamer *Streamer, + const ICorDebugInfo::NativeVarInfo &VarInfo, + bool IsLocList = false) { + MCContext &context = Streamer->getContext(); + unsigned TargetPointerSize = context.getAsmInfo()->getCodePointerSize(); + Triple::ArchType ArchType = context.getTargetTriple().getArch(); + + int DwarfRegNum; + int DwarfRegNum2; + int DwarfBaseRegNum; + unsigned Len; + + bool IsByRef = false; + bool IsStk2 = false; + bool IsRegStk = false; + + switch (VarInfo.loc.vlType) { + case ICorDebugInfo::VLT_REG_BYREF: // fall through + IsByRef = true; + case ICorDebugInfo::VLT_REG_FP: // fall through + case ICorDebugInfo::VLT_REG: { + DwarfRegNum = GetDwarfRegNum(ArchType, VarInfo.loc.vlReg.vlrReg); + if (IsByRef) { + Len = 1 + GetRegOpSize(DwarfRegNum); + if (IsLocList) { + Streamer->emitIntValue(Len, 2); + } else { + Streamer->emitULEB128IntValue(Len); + } + EmitBreg(Streamer, DwarfRegNum, 0); + } else { + Len = GetRegOpSize(DwarfRegNum); + if (IsLocList) { + Streamer->emitIntValue(Len, 2); + } else { + Streamer->emitULEB128IntValue(Len); + } + EmitReg(Streamer, DwarfRegNum); + } + + break; + } + case ICorDebugInfo::VLT_STK_BYREF: // fall through + IsByRef = true; + case ICorDebugInfo::VLT_STK2: + IsStk2 = true; + case ICorDebugInfo::VLT_FPSTK: + case ICorDebugInfo::VLT_STK: { + DwarfBaseRegNum = GetDwarfRegNum(ArchType, IsStk2 ? VarInfo.loc.vlStk2.vls2BaseReg : + VarInfo.loc.vlStk.vlsBaseReg); + + SmallString<128> Tmp; + raw_svector_ostream OSE(Tmp); + encodeSLEB128(IsStk2 ? VarInfo.loc.vlStk2.vls2Offset : + VarInfo.loc.vlStk.vlsOffset, OSE); + StringRef OffsetRepr = OSE.str(); + + if (IsByRef) { + Len = OffsetRepr.size() + 1 + GetRegOpSize(DwarfBaseRegNum); + if (IsLocList) { + Streamer->emitIntValue(Len, 2); + } else { + Streamer->emitULEB128IntValue(Len); + } + EmitBreg(Streamer, DwarfBaseRegNum, OffsetRepr); + Streamer->emitIntValue(dwarf::DW_OP_deref, 1); + } else { + Len = OffsetRepr.size() + GetRegOpSize(DwarfBaseRegNum); + if (IsLocList) { + Streamer->emitIntValue(Len, 2); + } else { + Streamer->emitULEB128IntValue(Len); + } + EmitBreg(Streamer, DwarfBaseRegNum, OffsetRepr); + } + + break; + } + case ICorDebugInfo::VLT_REG_REG: { + DwarfRegNum = GetDwarfRegNum(ArchType, VarInfo.loc.vlRegReg.vlrrReg1); + DwarfRegNum2 = GetDwarfRegNum(ArchType, VarInfo.loc.vlRegReg.vlrrReg2); + + Len = (GetRegOpSize(DwarfRegNum2) /* DW_OP_reg */ + 1 /* DW_OP_piece */ + 1 /* Reg size */) + + (GetRegOpSize(DwarfRegNum) /* DW_OP_reg */ + 1 /* DW_OP_piece */ + 1 /* Reg size */); + if (IsLocList) { + Streamer->emitIntValue(Len, 2); + } else { + Streamer->emitULEB128IntValue(Len); + } + + EmitReg(Streamer, DwarfRegNum2); + Streamer->emitIntValue(dwarf::DW_OP_piece, 1); + Streamer->emitULEB128IntValue(TargetPointerSize); + + EmitReg(Streamer, DwarfRegNum); + Streamer->emitIntValue(dwarf::DW_OP_piece, 1); + Streamer->emitULEB128IntValue(TargetPointerSize); + + break; + } + case ICorDebugInfo::VLT_REG_STK: // fall through + IsRegStk = true; + case ICorDebugInfo::VLT_STK_REG: { + DwarfRegNum = GetDwarfRegNum(ArchType, IsRegStk ? VarInfo.loc.vlRegStk.vlrsReg : + VarInfo.loc.vlStkReg.vlsrReg); + DwarfBaseRegNum = GetDwarfRegNum(ArchType, IsRegStk ? VarInfo.loc.vlRegStk.vlrsStk.vlrssBaseReg : + VarInfo.loc.vlStkReg.vlsrStk.vlsrsBaseReg); + + SmallString<128> Tmp; + raw_svector_ostream OSE(Tmp); + encodeSLEB128(IsRegStk ? VarInfo.loc.vlRegStk.vlrsStk.vlrssOffset : + VarInfo.loc.vlStkReg.vlsrStk.vlsrsOffset, OSE); + StringRef OffsetRepr = OSE.str(); + + Len = (GetRegOpSize(DwarfRegNum) /* DW_OP_reg */ + 1 /* DW_OP_piece */ + 1 /* Reg size */) + + (GetRegOpSize(DwarfBaseRegNum) /*DW_OP_breg */ + OffsetRepr.size() + 1 /* DW_OP_piece */ + 1 /* Reg size */); + + if (IsLocList) { + Streamer->emitIntValue(Len, 2); + } else { + Streamer->emitULEB128IntValue(Len + 1); + } + + if (IsRegStk) { + EmitReg(Streamer, DwarfRegNum); + Streamer->emitIntValue(dwarf::DW_OP_piece, 1); + Streamer->emitULEB128IntValue(TargetPointerSize); + + EmitBreg(Streamer, DwarfBaseRegNum, OffsetRepr); + Streamer->emitIntValue(dwarf::DW_OP_piece, 1); + Streamer->emitULEB128IntValue(TargetPointerSize); + } else { + EmitBreg(Streamer, DwarfBaseRegNum, OffsetRepr); + Streamer->emitIntValue(dwarf::DW_OP_piece, 1); + Streamer->emitULEB128IntValue(TargetPointerSize); + + EmitReg(Streamer, DwarfRegNum); + Streamer->emitIntValue(dwarf::DW_OP_piece, 1); + Streamer->emitULEB128IntValue(TargetPointerSize); + } + + break; + } + case ICorDebugInfo::VLT_FIXED_VA: + assert(false && "Unsupported varloc type!"); + default: + assert(false && "Unknown varloc type!"); + if (IsLocList) { + Streamer->emitIntValue(0, 2); + } else { + Streamer->emitULEB128IntValue(0); + } + } +} + +// Lexical scope + +class LexicalScope +{ +public: + LexicalScope(uint64_t Start, uint64_t End, bool IsFuncScope = false) : + Start(Start), + End(End), + IsFuncScope(IsFuncScope) {} + + LexicalScope(VarInfo *Info) : + Start(Info->GetStartOffset()), + End(Info->GetEndOffset()), + IsFuncScope(false) { Vars.push_back(Info); } + + bool IsContains(const VarInfo *Info) const { + return Start <= Info->GetStartOffset() && End >= Info->GetEndOffset(); + } + + void AddVar(VarInfo *Info); + + void Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection, const MCExpr *SymExpr); + +private: + uint64_t Start; + uint64_t End; + bool IsFuncScope; + std::vector Vars; + std::vector InnerScopes; +}; + +void LexicalScope::AddVar(VarInfo *Info) { + if (Info->IsParam() && IsFuncScope) { + Vars.push_back(Info); + return; + } + + if (!IsContains(Info)) + return; + + uint64_t VarStart = Info->GetStartOffset(); + uint64_t VarEnd = Info->GetEndOffset(); + + // Var belongs to inner scope + if (VarStart != Start || VarEnd != End) { + // Try to add variable to one the inner scopes + for (auto &Scope : InnerScopes) { + if (Scope.IsContains(Info)) { + Scope.AddVar(Info); + return; + } + } + // We need to create new inner scope for this var + InnerScopes.emplace_back(Info); + } else { + Vars.push_back(Info); + } +} + +void LexicalScope::Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection, const MCExpr *SymExpr) { + Streamer->SwitchSection(TypeSection); + + if (!IsFuncScope) + { + // Dump lexical block DIE + MCContext &context = Streamer->getContext(); + unsigned TargetPointerSize = context.getAsmInfo()->getCodePointerSize(); + + // Abbrev Number + Streamer->emitULEB128IntValue(DwarfAbbrev::LexicalBlock); + + // DW_AT_low_pc + const MCExpr *StartExpr = MCConstantExpr::create(Start, context); + const MCExpr *LowPcExpr = MCBinaryExpr::create(MCBinaryExpr::Add, SymExpr, + StartExpr, context); + Streamer->emitValue(LowPcExpr, TargetPointerSize); + + // DW_AT_high_pc + Streamer->emitIntValue(End - Start, TargetPointerSize); + } + + for (auto *Var : Vars) { + Var->Dump(TypeBuilder, Streamer, TypeSection, StrSection); + } + + for (auto &Scope : InnerScopes) { + Scope.Dump(TypeBuilder, Streamer, TypeSection, StrSection, SymExpr); + } + + if (!IsFuncScope) { + // Terminate block + Streamer->emitIntValue(0, 1); + } +} + +// StaticVarInfo + +class StaticVarInfo : public DwarfInfo +{ +public: + StaticVarInfo(const DwarfStaticDataField *StaticField) : StaticField(StaticField) {} + + void Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) override; + +protected: + void DumpStrings(MCObjectStreamer *Streamer) override {}; + void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override; + +private: + const DwarfStaticDataField *StaticField; + + void EmitLocation(MCObjectStreamer *Streamer); +}; + +void StaticVarInfo::Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) { + MCContext &context = Streamer->getContext(); + MCSymbol *Sym = context.getOrCreateSymbol(Twine(StaticField->GetStaticDataName())); + if (Sym->isUndefined()) + return; + + DwarfInfo::Dump(TypeBuilder, Streamer, TypeSection, StrSection); +} + +void StaticVarInfo::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) { + // Abbrev Number + Streamer->emitULEB128IntValue(DwarfAbbrev::VariableStatic); + + // DW_AT_specification + EmitInfoOffset(Streamer, StaticField, 4); + + // DW_AT_location + EmitLocation(Streamer); +} + +void StaticVarInfo::EmitLocation(MCObjectStreamer *Streamer) { + MCContext &context = Streamer->getContext(); + unsigned TargetPointerSize = context.getAsmInfo()->getCodePointerSize(); + + MCSymbol *Sym = context.getOrCreateSymbol(Twine(StaticField->GetStaticDataName())); + + SmallString<128> Tmp; + raw_svector_ostream OSE(Tmp); + encodeULEB128(StaticField->GetStaticOffset(), OSE); + StringRef OffsetRepr = OSE.str(); + + unsigned Len = 1 /* DW_OP_addr */ + TargetPointerSize; + + // Need double deref + if (StaticField->IsStaticDataInObject()) { + Len += (1 /* DW_OP_deref */) * 2; + } + + if (StaticField->GetStaticOffset() != 0) { + Len += 1 /* DW_OP_plus_uconst */ + OffsetRepr.size(); + } + + Streamer->emitULEB128IntValue(Len); + Streamer->emitIntValue(dwarf::DW_OP_addr, 1); + Streamer->emitSymbolValue(Sym, TargetPointerSize); + + if (StaticField->IsStaticDataInObject()) { + Streamer->emitIntValue(dwarf::DW_OP_deref, 1); + Streamer->emitIntValue(dwarf::DW_OP_deref, 1); + } + + if (StaticField->GetStaticOffset() != 0) { + Streamer->emitIntValue(dwarf::DW_OP_plus_uconst, 1); + Streamer->emitBytes(OffsetRepr); + } +} + +// VarInfo + +VarInfo::VarInfo(const DebugVarInfo &Info, bool IsThis) : + DebugInfo(Info), + LocSymbol(nullptr), + IsThis(IsThis) { + if (!Info.IsParam) { + assert(!Info.Ranges.empty()); + StartOffset = Info.Ranges.front().startOffset; + EndOffset = Info.Ranges.back().endOffset; + } else { + // Params belong to func scope + StartOffset = 0xFFFFFFFF; + EndOffset = 0xFFFFFFFF; + } +} + +void VarInfo::DumpLocsIfNeeded(MCObjectStreamer *Streamer, + MCSection *LocSection, + const MCExpr *SymExpr) { + if (!IsDebugLocNeeded()) + return; + + Streamer->SwitchSection(LocSection); + + MCContext &context = Streamer->getContext(); + unsigned TargetPointerSize = context.getAsmInfo()->getCodePointerSize(); + + LocSymbol = context.createTempSymbol(); + Streamer->emitLabel(LocSymbol); + + for (const auto &NativeInfo : DebugInfo.Ranges) { + const MCExpr *StartOffsetExpr = MCConstantExpr::create(NativeInfo.startOffset, context); + const MCExpr *EndOffsetExpr = MCConstantExpr::create(NativeInfo.endOffset, context); + + // Begin address + const MCExpr *BeginAddrExpr = MCBinaryExpr::create(MCBinaryExpr::Add, SymExpr, + StartOffsetExpr, context); + Streamer->emitValue(BeginAddrExpr, TargetPointerSize); + + // End address + const MCExpr *EndAddrExpr = MCBinaryExpr::create(MCBinaryExpr::Add, SymExpr, + EndOffsetExpr, context); + Streamer->emitValue(EndAddrExpr, TargetPointerSize); + + // Expression + EmitVarLocation(Streamer, NativeInfo, true); + } + + // Terminate list entry + Streamer->emitIntValue(0, TargetPointerSize); + Streamer->emitIntValue(0, TargetPointerSize); +} + +void VarInfo::DumpStrings(MCObjectStreamer *Streamer) { + if (IsThis) { + Streamer->emitBytes(StringRef("this")); + } else { + Streamer->emitBytes(StringRef(DebugInfo.Name)); + } + Streamer->emitIntValue(0, 1); +} + +void VarInfo::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) { + bool IsDebugLocUsed = IsDebugLocNeeded(); + + // Abbrev Number + if (DebugInfo.IsParam) { + if (IsThis) { + Streamer->emitULEB128IntValue(IsDebugLocUsed ? DwarfAbbrev::FormalParameterThisLoc : + DwarfAbbrev::FormalParameterThis); + } else { + Streamer->emitULEB128IntValue(IsDebugLocUsed ? DwarfAbbrev::FormalParameterLoc : + DwarfAbbrev::FormalParameter); + } + } else { + Streamer->emitULEB128IntValue(IsDebugLocUsed ? DwarfAbbrev::VariableLoc : + DwarfAbbrev::Variable); + } + + // DW_AT_name + EmitSectionOffset(Streamer, StrSymbol, 4); + + // DW_AT_decl_file + Streamer->emitIntValue(1, 1); + + // DW_AT_decl_line + Streamer->emitIntValue(1, 1); + + // DW_AT_type + DwarfInfo *Info = TypeBuilder->GetTypeInfoByIndex(DebugInfo.TypeIndex); + assert(Info != nullptr); + + EmitInfoOffset(Streamer, Info, 4); + + // DW_AT_location + if (IsDebugLocUsed) { + EmitSectionOffset(Streamer, LocSymbol, 4); + } else { + assert(DebugInfo.Ranges.size() == 1); + EmitVarLocation(Streamer, DebugInfo.Ranges[0]); + } +} + +// SubprogramInfo + +SubprogramInfo::SubprogramInfo(const char *Name, + int Size, + DwarfMemberFunctionIdTypeInfo *MethodTypeInfo, + const std::vector &DebugVarInfos, + const std::vector &DebugEHClauseInfos) : + Name(Name), + Size(Size), + MethodTypeInfo(MethodTypeInfo), + DebugEHClauseInfos(DebugEHClauseInfos) { + bool IsStatic = MethodTypeInfo->IsStatic(); + for (unsigned i = 0; i < DebugVarInfos.size(); i++) { + VarInfos.emplace_back(DebugVarInfos[i], i == 0 && !IsStatic); + } +} + +void SubprogramInfo::Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection, MCSection *LocSection) { + DumpDebugLoc(Streamer, LocSection); + + DwarfInfo::Dump(TypeBuilder, Streamer, TypeSection, StrSection); + + // Dump vars + DumpVars(TypeBuilder, Streamer, TypeSection, StrSection); + + // Dump try-catch blocks + Streamer->SwitchSection(TypeSection); + DumpEHClauses(Streamer, TypeSection); + + DwarfInfo::EndChildrenList(Streamer); +} + +void SubprogramInfo::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) { + MCContext &context = Streamer->getContext(); + bool IsStatic = MethodTypeInfo->IsStatic(); + unsigned TargetPointerSize = context.getAsmInfo()->getCodePointerSize(); + Triple::ArchType ArchType = context.getTargetTriple().getArch(); + + // Subprogram DIE + + // Abbrev Number + auto abbrev = IsStatic + ? HasChildren() ? DwarfAbbrev::SubprogramStatic + : DwarfAbbrev::SubprogramStaticNoChildren + : HasChildren() ? DwarfAbbrev::Subprogram + : DwarfAbbrev::SubprogramNoChildren; + + Streamer->emitULEB128IntValue(abbrev); + + // DW_AT_specification + EmitInfoOffset(Streamer, MethodTypeInfo, 4); + + // DW_AT_low_pc + MCSymbol *Sym = context.lookupSymbol(Twine(Name)); + const MCExpr *SymExpr = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, context); + Streamer->emitValue(SymExpr, TargetPointerSize); + + // DW_AT_high_pc + Streamer->emitIntValue(Size, TargetPointerSize); + + // DW_AT_frame_base + Streamer->emitULEB128IntValue(1); + Streamer->emitIntValue(GetDwarfFpRegNum(ArchType) + dwarf::DW_OP_reg0, 1); + + if (!IsStatic) { + // DW_AT_object_pointer + uint32_t Offset = Streamer->getOrCreateDataFragment()->getContents().size(); + + Streamer->emitIntValue(Offset + 4, 4); + } +} + +void SubprogramInfo::DumpDebugLoc(MCObjectStreamer *Streamer, MCSection *LocSection) { + MCContext &context = Streamer->getContext(); + MCSymbol *Sym = context.getOrCreateSymbol(Twine(Name)); + const MCExpr *SymExpr = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, context); + + for (auto &VarInfo : VarInfos) { + VarInfo.DumpLocsIfNeeded(Streamer, LocSection, SymExpr); + } +} + +void SubprogramInfo::DumpVars(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) { + MCContext &context = Streamer->getContext(); + MCSymbol *Sym = context.getOrCreateSymbol(Twine(Name)); + const MCExpr *SymExpr = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, context); + + LexicalScope FuncScope(0, Size, true); + + for (unsigned i = 0; i < VarInfos.size(); i++) { + FuncScope.AddVar(&VarInfos[i]); + } + + FuncScope.Dump(TypeBuilder, Streamer, TypeSection, StrSection, SymExpr); +} + +static void DumpEHClause(MCObjectStreamer *Streamer, MCSection *TypeSection, int Abbrev, + const MCExpr *SymExpr, unsigned Offset, unsigned Length) { + MCContext &context = Streamer->getContext(); + unsigned TargetPointerSize = context.getAsmInfo()->getCodePointerSize(); + + // Abbrev Number + Streamer->emitULEB128IntValue(Abbrev); + + // DW_AT_low_pc + const MCExpr *OffsetExpr = MCConstantExpr::create(Offset, context); + const MCExpr *AddrExpr = MCBinaryExpr::create(MCBinaryExpr::Add, SymExpr, + OffsetExpr, context); + + Streamer->emitValue(AddrExpr, TargetPointerSize); + + // DW_AT_high_pc + Streamer->emitIntValue(Length, TargetPointerSize); +} + +void SubprogramInfo::DumpEHClauses(MCObjectStreamer *Streamer, MCSection *TypeSection) { + MCContext &context = Streamer->getContext(); + + MCSymbol *Sym = context.getOrCreateSymbol(Twine(Name)); + const MCExpr *SymExpr = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, context); + + for (const auto &EHClause: DebugEHClauseInfos) { + // Try block DIE + DumpEHClause(Streamer, TypeSection, DwarfAbbrev::TryBlock, + SymExpr, EHClause.TryOffset, EHClause.TryLength); + + // Catch block DIE + DumpEHClause(Streamer, TypeSection, DwarfAbbrev::CatchBlock, + SymExpr, EHClause.HandlerOffset, EHClause.HandlerLength); + } +} + +bool SubprogramInfo::HasChildren() { + return !MethodTypeInfo->IsStatic() || !DebugEHClauseInfos.empty() || !VarInfos.empty(); +} + +// DwarfGen + +void DwarfGen::SetTypeBuilder(UserDefinedDwarfTypesBuilder *TypeBuilder) { + assert(this->TypeBuilder == nullptr); + assert(TypeBuilder != nullptr); + this->TypeBuilder = TypeBuilder; + this->Streamer = TypeBuilder->GetStreamer(); +} + +void DwarfGen::EmitCompileUnit() { + MCContext &context = Streamer->getContext(); + unsigned TargetPointerSize = context.getAsmInfo()->getCodePointerSize(); + + MCSymbol *LineSectionSymbol = nullptr; + MCSymbol *AbbrevSectionSymbol = nullptr; + if (context.getAsmInfo()->doesDwarfUseRelocationsAcrossSections()) { + LineSectionSymbol = Streamer->getDwarfLineTableSymbol(0); + + Streamer->SwitchSection(context.getObjectFileInfo()->getDwarfAbbrevSection()); + AbbrevSectionSymbol = context.createTempSymbol(); + Streamer->emitLabel(AbbrevSectionSymbol); + } + + MCSection *debugSection = context.getObjectFileInfo()->getDwarfInfoSection(); + Streamer->SwitchSection(debugSection); + + InfoStart = debugSection->getBeginSymbol(); + InfoEnd = context.createTempSymbol(); + + // Length + const MCExpr *Length = MakeStartMinusEndExpr(*Streamer, *InfoStart, *InfoEnd, 4); + emitAbsValue(*Streamer, Length, 4); + + // Version + Streamer->emitIntValue(context.getDwarfVersion(), 2); + + // Unit type, Addr Size and Abbrev offset - DWARF >= 5 + // Abbrev offset, Addr Size - DWARF <= 4 + unsigned addrSize = context.getAsmInfo()->getCodePointerSize(); + if (context.getDwarfVersion() >= 5) { + Streamer->emitIntValue(dwarf::DW_UT_compile, 1); + Streamer->emitIntValue(addrSize, 1); + } + + // Abbrev Offset + if (AbbrevSectionSymbol == nullptr) { + Streamer->emitIntValue(0, 4); + } else { + Streamer->emitSymbolValue(AbbrevSectionSymbol, 4, + context.getAsmInfo()->needsDwarfSectionOffsetDirective()); + } + + if (context.getDwarfVersion() <= 4) + Streamer->emitIntValue(addrSize, 1); + + // CompileUnit DIE + + // Abbrev Number + Streamer->emitULEB128IntValue(DwarfAbbrev::CompileUnit); + + // DW_AT_producer: CoreRT + Streamer->emitBytes(StringRef("CoreRT")); + Streamer->emitIntValue(0, 1); + + // DW_AT_language +#ifdef FEATURE_LANGID_CS + Streamer->EmitIntValue(DW_LANG_MICROSOFT_CSHARP, 2); +#else + Streamer->emitIntValue(dwarf::DW_LANG_C_plus_plus, 2); +#endif + + // We need to generate DW_AT_name and DW_AT_compdir to get Apple's ld64 to correctly + // generate debug map in final executable. If we don't generate it then the linker + // will skip over the object file. + // Ref: https://github.com/apple-oss-distributions/ld64/blob/dbf8f7feb5579761f1623b004bd468bdea7c6225/src/ld/OutputFile.cpp#L7166 + + // DW_AT_name + Streamer->emitBytes(StringRef("IL.c")); + Streamer->emitIntValue(0, 1); + + // DW_AT_compdir + Streamer->emitBytes(StringRef("/tmp")); + Streamer->emitIntValue(0, 1); + + // There need to be global DW_AT_low_pc/DW_AT_high_pc symbols to indicate the base and + // size of the range covered by the symbols. Currently we use a shortcut where we emit + // a range starting at the beginning of file and ending at the start of the debug section + // which is located at the end of the object file. + + // DW_AT_low_pc + Streamer->emitIntValue(0, TargetPointerSize); + + // DW_AT_high_pc + const MCExpr *SymExpr = MCSymbolRefExpr::create(debugSection->getBeginSymbol(), MCSymbolRefExpr::VK_None, context); + Streamer->emitValue(SymExpr, TargetPointerSize); + + // DW_AT_stmt_list + if (LineSectionSymbol == nullptr) { + Streamer->emitIntValue(0, 4); + } else { + Streamer->emitSymbolValue(LineSectionSymbol, 4, + context.getAsmInfo()->needsDwarfSectionOffsetDirective()); + } +} + +void DwarfGen::EmitSubprogramInfo(const char *FunctionName, + int FunctionSize, + unsigned MethodTypeIndex, + const std::vector &VarInfos, + const std::vector &DebugEHClauseInfos) { + // return if CU isn't emitted + if (InfoStart == nullptr) + return; + + if (MethodTypeIndex == 0) + return; + + DwarfMemberFunctionIdTypeInfo *MethodTypeInfo = static_cast( + TypeBuilder->GetTypeInfoByIndex(MethodTypeIndex)); + assert(MethodTypeInfo != nullptr); + + MethodTypeInfo->SetLinkageName(FunctionName); + + Subprograms.emplace_back(FunctionName, FunctionSize, MethodTypeInfo, VarInfos, DebugEHClauseInfos); +} + +void DwarfGen::EmitAbbrev() { + // return if CU isn't emitted + if (InfoStart == nullptr) + return; + + MCContext &context = Streamer->getContext(); + + DwarfAbbrev::Dump(Streamer, context.getDwarfVersion(), + context.getAsmInfo()->getCodePointerSize()); +} + +void DwarfGen::EmitAranges() { + // return if CU isn't emitted + if (InfoStart == nullptr) + return; + + MCContext &context = Streamer->getContext(); + Streamer->SwitchSection(context.getObjectFileInfo()->getDwarfARangesSection()); + + auto &Sections = context.getGenDwarfSectionSyms(); + + int Length = 4 + 2 + 4 + 1 + 1; + int AddrSize = context.getAsmInfo()->getCodePointerSize(); + int Pad = 2 * AddrSize - (Length & (2 * AddrSize - 1)); + if (Pad == 2 * AddrSize) + Pad = 0; + Length += Pad; + + Length += 2 * AddrSize * Sections.size(); + Length += 2 * AddrSize; + + // Emit the header for this section. + // The 4 byte length not including the 4 byte value for the length. + Streamer->emitIntValue(Length - 4, 4); + + // The 2 byte version, which is 2. + Streamer->emitIntValue(2, 2); + + // The 4 byte offset to the compile unit in the .debug_info from the start + // of the .debug_info. + Streamer->emitSymbolValue(InfoStart, 4, + context.getAsmInfo()->needsDwarfSectionOffsetDirective()); + + Streamer->emitIntValue(AddrSize, 1); + + Streamer->emitIntValue(0, 1); + + for(int i = 0; i < Pad; i++) + Streamer->emitIntValue(0, 1); + + for (MCSection *Sec : Sections) { + const MCSymbol *StartSymbol = Sec->getBeginSymbol(); + MCSymbol *EndSymbol = Sec->getEndSymbol(context); + assert(StartSymbol && "StartSymbol must not be NULL"); + assert(EndSymbol && "EndSymbol must not be NULL"); + + const MCExpr *Addr = MCSymbolRefExpr::create( + StartSymbol, MCSymbolRefExpr::VK_None, context); + const MCExpr *Size = MakeStartMinusEndExpr(*Streamer, + *StartSymbol, *EndSymbol, 0); + Streamer->emitValue(Addr, AddrSize); + emitAbsValue(*Streamer, Size, AddrSize); + } + + // Terminating zeros. + Streamer->emitIntValue(0, AddrSize); + Streamer->emitIntValue(0, AddrSize); +} + +void DwarfGen::Finish() { + // return if CU isn't emitted + if (InfoStart == nullptr) + return; + + MCContext &context = Streamer->getContext(); + + // Dump type info + + MCSection *InfoSection = context.getObjectFileInfo()->getDwarfInfoSection(); + MCSection *StrSection = context.getObjectFileInfo()->getDwarfStrSection(); + MCSection *LocSection = context.getObjectFileInfo()->getDwarfLocSection(); + + TypeBuilder->EmitTypeInformation(InfoSection, StrSection); + + // Dump subprograms + + for (auto &Subprogram : Subprograms) { + Subprogram.Dump(TypeBuilder, Streamer, InfoSection, StrSection, LocSection); + } + + // Dump static vars + + for (const auto *ClassTypeInfo : TypeBuilder->GetClassesWithStaticFields()) { + for (const auto &StaticField : ClassTypeInfo->GetStaticFields()) { + StaticVarInfo Info(&StaticField); + Info.Dump(TypeBuilder, Streamer, InfoSection, StrSection); + } + } + + // Add the NULL terminating the Compile Unit DIE's. + Streamer->SwitchSection(context.getObjectFileInfo()->getDwarfInfoSection()); + + Streamer->emitIntValue(0, 1); + + Streamer->emitLabel(InfoEnd); + + Streamer->SwitchSection(context.getObjectFileInfo()->getDwarfAbbrevSection()); + + // Terminate the abbreviations for this compilation unit + Streamer->emitIntValue(0, 1); +} diff --git a/llvm/tools/objwriter/debugInfo/dwarf/dwarfGen.h b/llvm/tools/objwriter/debugInfo/dwarf/dwarfGen.h new file mode 100644 index 0000000000000..b3a9b4c0c7ba6 --- /dev/null +++ b/llvm/tools/objwriter/debugInfo/dwarf/dwarfGen.h @@ -0,0 +1,106 @@ +//===---- dwarfGen.h --------------------------------------------*- C++ -*-===// +// +// dwarf generator is used to generate dwarf debuginfo. +// +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "llvm/MC/MCObjectStreamer.h" + +#include "dwarfTypeBuilder.h" +#include "jitDebugInfo.h" + +#include + +class VarInfo : public DwarfInfo +{ +public: + VarInfo(const DebugVarInfo &Info, bool IsThis); + + bool IsDebugLocNeeded() const { return DebugInfo.Ranges.size() > 1; } + + void DumpLocsIfNeeded(MCObjectStreamer *Streamer, MCSection *LocSection, const MCExpr *SymExpr); + + uint64_t GetStartOffset() const { return StartOffset; } + + uint64_t GetEndOffset() const { return EndOffset; } + + bool IsParam() const { return DebugInfo.IsParam; } + +protected: + void DumpStrings(MCObjectStreamer *Streamer) override; + void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override; + +private: + DebugVarInfo DebugInfo; + MCSymbol *LocSymbol; + bool IsThis; + uint64_t StartOffset; + uint64_t EndOffset; +}; + +class SubprogramInfo : public DwarfInfo +{ +public: + using DwarfInfo::Dump; + + SubprogramInfo(const char *Name, + int Size, + DwarfMemberFunctionIdTypeInfo *MethodTypeInfo, + const std::vector &DebugVarInfos, + const std::vector &DebugEHClauseInfos); + + void Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection, MCSection *LocSection); + +protected: + void DumpStrings(MCObjectStreamer *Streamer) override {} + void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override; + bool HasChildren() override; + +private: + void DumpDebugLoc(MCObjectStreamer *Streamer, MCSection *LocSection); + void DumpVars(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection); + void DumpEHClauses(MCObjectStreamer *Streamer, MCSection *TypeSection); + + std::string Name; + int Size; + DwarfMemberFunctionIdTypeInfo *MethodTypeInfo; + std::vector DebugEHClauseInfos; + std::vector VarInfos; +}; + +class DwarfGen +{ +public: + DwarfGen() : Streamer(nullptr), + TypeBuilder(nullptr), + InfoStart(nullptr), + InfoEnd(nullptr) {} + + void SetTypeBuilder(UserDefinedDwarfTypesBuilder *TypeBuilder); + void EmitCompileUnit(); + void EmitSubprogramInfo(const char *FunctionName, + int FunctionSize, + unsigned MethodTypeIndex, + const std::vector &VarsInfo, + const std::vector &DebugEHClauseInfos); + + void EmitAbbrev(); + void EmitAranges(); + void Finish(); + +private: + MCObjectStreamer *Streamer; + UserDefinedDwarfTypesBuilder *TypeBuilder; + + MCSymbol *InfoStart; + MCSymbol *InfoEnd; + + std::vector Subprograms; +}; diff --git a/llvm/tools/objwriter/debugInfo/dwarf/dwarfTypeBuilder.cpp b/llvm/tools/objwriter/debugInfo/dwarf/dwarfTypeBuilder.cpp new file mode 100644 index 0000000000000..ff4ab03e6c9bb --- /dev/null +++ b/llvm/tools/objwriter/debugInfo/dwarf/dwarfTypeBuilder.cpp @@ -0,0 +1,844 @@ +//===---- dwarfTypeBuilder.cpp ----------------------------------*- C++ -*-===// +// +// dwarf type builder implementation +// +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// +//===----------------------------------------------------------------------===// + +#include "dwarfTypeBuilder.h" +#include "dwarfAbbrev.h" +#include "llvm/MC/MCContext.h" +#include "llvm/MC/MCAsmInfo.h" +#include "llvm/MC/MCObjectFileInfo.h" + +#include +#include + +// DwarfInfo + +void DwarfInfo::Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) { + if (IsDumped) + return; + + IsDumped = true; + + MCContext &context = Streamer->getContext(); + + InfoSymbol = context.createTempSymbol(); + InfoExpr = CreateOffsetExpr(context, TypeSection->getBeginSymbol(), InfoSymbol); + + DumpTypes(TypeBuilder, Streamer, TypeSection, StrSection); + + Streamer->SwitchSection(StrSection); + StrSymbol = context.createTempSymbol(); + Streamer->emitLabel(StrSymbol); + DumpStrings(Streamer); + + Streamer->SwitchSection(TypeSection); + Streamer->emitLabel(InfoSymbol); + DumpTypeInfo(Streamer, TypeBuilder); +} + +void DwarfInfo::DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) { + if (IsDumpedTypes) + return; + + IsDumpedTypes = true; +} + +void DwarfInfo::EndChildrenList(MCObjectStreamer* Streamer) { + if (HasChildren()) { + // Emit null entry + Streamer->emitIntValue(0, 1); + } +} + +void DwarfInfo::EmitSectionOffset(MCObjectStreamer *Streamer, + MCSymbol *Symbol, + unsigned Size, + uint32_t Offset) { + MCContext &context = Streamer->getContext(); + + if (context.getAsmInfo()->doesDwarfUseRelocationsAcrossSections()) { + if (Offset == 0) { + Streamer->emitSymbolValue(Symbol, Size); + } else { + const MCSymbolRefExpr *SymbolExpr = MCSymbolRefExpr::create(Symbol, + MCSymbolRefExpr::VK_None, context); + const MCExpr *OffsetExpr = MCConstantExpr::create(Offset, context); + const MCExpr *Expr = MCBinaryExpr::createAdd(SymbolExpr, OffsetExpr, context); + Streamer->emitValue(Expr, Size); + } + } else { + Streamer->emitIntValue(Symbol->getOffset() + Offset, Size); + } +} + +const MCExpr *DwarfInfo::CreateOffsetExpr(MCContext &Context, + MCSymbol *BeginSymbol, + MCSymbol *Symbol) { + MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None; + const MCExpr *StartExpr = + MCSymbolRefExpr::create(BeginSymbol, Variant, Context); + const MCExpr *EndExpr = + MCSymbolRefExpr::create(Symbol, Variant, Context); + return MCBinaryExpr::createSub(EndExpr, StartExpr, Context); +} + +void DwarfInfo::EmitOffset(MCObjectStreamer *Streamer, + const MCExpr *OffsetExpr, + unsigned Size) { + MCContext &context = Streamer->getContext(); + + if (!context.getAsmInfo()->hasAggressiveSymbolFolding()) { + MCSymbol *Temp = context.createTempSymbol(); + Streamer->emitAssignment(Temp, OffsetExpr); + OffsetExpr = MCSymbolRefExpr::create(Temp, context); + } + + Streamer->emitValue(OffsetExpr, Size); +} + +void DwarfInfo::EmitInfoOffset(MCObjectStreamer *Streamer, const DwarfInfo *Info, unsigned Size) { + uint64_t Offset = Info->InfoSymbol->getOffset(); + if (Offset != 0) { + Streamer->emitIntValue(Offset, Size); + } else { + EmitOffset(Streamer, Info->InfoExpr, Size); + } +} + +// DwarfPrimitiveTypeInfo + +struct PrimitiveTypeDesc { + const char *Name; + int Encoding; + unsigned ByteSize; +}; + +static PrimitiveTypeDesc GetPrimitiveTypeDesc(PrimitiveTypeFlags Type, unsigned TargetPointerSize) { + switch (Type) { + case PrimitiveTypeFlags::Boolean: return {"bool", dwarf::DW_ATE_boolean, 1}; + case PrimitiveTypeFlags::Char: return {"char16_t", dwarf::DW_ATE_UTF, 2}; + case PrimitiveTypeFlags::SByte: return {"sbyte", dwarf::DW_ATE_signed, 1}; + case PrimitiveTypeFlags::Byte: return {"byte", dwarf::DW_ATE_unsigned, 1}; + case PrimitiveTypeFlags::Int16: return {"short", dwarf::DW_ATE_signed, 2}; + case PrimitiveTypeFlags::UInt16: return {"ushort", dwarf::DW_ATE_unsigned, 2}; + case PrimitiveTypeFlags::Int32: return {"int", dwarf::DW_ATE_signed, 4}; + case PrimitiveTypeFlags::UInt32: return {"uint", dwarf::DW_ATE_unsigned, 4}; + case PrimitiveTypeFlags::Int64: return {"long", dwarf::DW_ATE_signed, 8}; + case PrimitiveTypeFlags::UInt64: return {"ulong", dwarf::DW_ATE_unsigned, 8}; + case PrimitiveTypeFlags::IntPtr: return {"System.IntPtr", dwarf::DW_ATE_signed, TargetPointerSize}; + case PrimitiveTypeFlags::UIntPtr: return {"System.UIntPtr", dwarf::DW_ATE_unsigned, TargetPointerSize}; + case PrimitiveTypeFlags::Single: return {"float", dwarf::DW_ATE_float, 4}; + case PrimitiveTypeFlags::Double: return {"double", dwarf::DW_ATE_float, 8}; + default: + assert(false && "Unexpected type"); + return {nullptr, 0, 0}; + } +} + +void DwarfPrimitiveTypeInfo::DumpStrings(MCObjectStreamer *Streamer) { + MCContext &context = Streamer->getContext(); + unsigned TargetPointerSize = context.getAsmInfo()->getCodePointerSize(); + + PrimitiveTypeDesc TD = GetPrimitiveTypeDesc(Type, TargetPointerSize); + if (TD.Name == nullptr) + return; + + Streamer->emitBytes(StringRef(TD.Name)); + Streamer->emitIntValue(0, 1); +} + +void DwarfPrimitiveTypeInfo::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) { + MCContext &context = Streamer->getContext(); + unsigned TargetPointerSize = context.getAsmInfo()->getCodePointerSize(); + + PrimitiveTypeDesc TD = GetPrimitiveTypeDesc(Type, TargetPointerSize); + if (TD.Name == nullptr) + return; + + // Abbrev Number + Streamer->emitULEB128IntValue(DwarfAbbrev::BaseType); + + // DW_AT_name + EmitSectionOffset(Streamer, StrSymbol, 4); + + // DW_AT_encoding + Streamer->emitIntValue(TD.Encoding, 1); + + // DW_AT_byte_size + Streamer->emitIntValue(TD.ByteSize, 1); +} + +// DwarfVoidTypeInfo + +void DwarfVoidTypeInfo::DumpStrings(MCObjectStreamer* Streamer) { + Streamer->emitBytes(StringRef("void")); + Streamer->emitIntValue(0, 1); +} + +void DwarfVoidTypeInfo::DumpTypeInfo(MCObjectStreamer* Streamer, UserDefinedDwarfTypesBuilder* TypeBuilder) { + // Abbrev Number + Streamer->emitULEB128IntValue(DwarfAbbrev::VoidType); + + // DW_AT_name + EmitSectionOffset(Streamer, StrSymbol, 4); +} + +// DwarfEnumerator + +void DwarfEnumerator::DumpStrings(MCObjectStreamer *Streamer) { + Streamer->emitBytes(Name); + Streamer->emitIntValue(0, 1); +} + +void DwarfEnumerator::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) { + uint8_t Size = EnumTypeInfo->GetByteSize(); + + // Abbrev Number + switch (Size) { + case 1: + Streamer->emitULEB128IntValue(DwarfAbbrev::Enumerator1); + break; + case 2: + Streamer->emitULEB128IntValue(DwarfAbbrev::Enumerator2); + break; + case 4: + Streamer->emitULEB128IntValue(DwarfAbbrev::Enumerator4); + break; + case 8: + Streamer->emitULEB128IntValue(DwarfAbbrev::Enumerator8); + break; + default: + assert(false && "Unexpected byte size value"); + } + + // DW_AT_name + EmitSectionOffset(Streamer, StrSymbol, 4); + + // DW_AT_const_value + Streamer->emitIntValue(Value, Size); +} + +// DwarfEnumTypeInfo + +DwarfEnumTypeInfo::DwarfEnumTypeInfo(const EnumTypeDescriptor &TypeDescriptor, + const EnumRecordTypeDescriptor *TypeRecords) : + Name(TypeDescriptor.Name), + ElementType(TypeDescriptor.ElementType) { + for (uint64 i = 0; i < TypeDescriptor.ElementCount; i++) { + Records.emplace_back(TypeRecords[i], this); + } +} + +void DwarfEnumTypeInfo::DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) { + if (IsDumpedTypes) + return; + + DwarfInfo::DumpTypes(TypeBuilder, Streamer, TypeSection, StrSection); + + DwarfInfo *Info = TypeBuilder->GetTypeInfoByIndex(ElementType); + assert(Info != nullptr); + + Info->Dump(TypeBuilder, Streamer, TypeSection, StrSection); +} + +void DwarfEnumTypeInfo::Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) { + if (IsDumped) + return; + + MCContext &context = Streamer->getContext(); + unsigned TargetPointerSize = context.getAsmInfo()->getCodePointerSize(); + + DwarfPrimitiveTypeInfo *ElementTypeInfo = static_cast( + TypeBuilder->GetTypeInfoByIndex(ElementType)); + assert(ElementTypeInfo != nullptr); + + PrimitiveTypeDesc TD = GetPrimitiveTypeDesc(ElementTypeInfo->GetType(), TargetPointerSize); + ByteSize = TD.ByteSize; + + DwarfInfo::Dump(TypeBuilder, Streamer, TypeSection, StrSection); + + for (auto &Enumerator : Records) { + Enumerator.Dump(TypeBuilder, Streamer, TypeSection, StrSection); + } + + // Terminate DIE + Streamer->SwitchSection(TypeSection); + EndChildrenList(Streamer); +} + +void DwarfEnumTypeInfo::DumpStrings(MCObjectStreamer *Streamer) { + Streamer->emitBytes(Name); + Streamer->emitIntValue(0, 1); +} + +void DwarfEnumTypeInfo::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) { + // Abbrev Number + Streamer->emitULEB128IntValue(DwarfAbbrev::EnumerationType); + + // DW_AT_name + EmitSectionOffset(Streamer, StrSymbol, 4); + + // DW_AT_type + DwarfInfo *Info = TypeBuilder->GetTypeInfoByIndex(ElementType); + assert(Info != nullptr); + + EmitInfoOffset(Streamer, Info, 4); + + // DW_AT_byte_size + Streamer->emitIntValue(ByteSize, 1); +} + +// DwarfDataField + +void DwarfDataField::DumpStrings(MCObjectStreamer *Streamer) { + Streamer->emitBytes(StringRef(Name)); + Streamer->emitIntValue(0, 1); +} + +void DwarfDataField::DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) { + if (IsDumpedTypes) + return; + + DwarfInfo::DumpTypes(TypeBuilder, Streamer, TypeSection, StrSection); + + DwarfInfo *MemberTypeInfo = TypeBuilder->GetTypeInfoByIndex(TypeIndex); + assert(MemberTypeInfo != nullptr); + + MemberTypeInfo->Dump(TypeBuilder, Streamer, TypeSection, StrSection); +} + +void DwarfDataField::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) { + // Abbrev Number + Streamer->emitULEB128IntValue(DwarfAbbrev::ClassMember); + + // DW_AT_name + EmitSectionOffset(Streamer, StrSymbol, 4); + + // DW_AT_type + DwarfInfo *MemberTypeInfo = TypeBuilder->GetTypeInfoByIndex(TypeIndex); + assert(MemberTypeInfo != nullptr); + EmitInfoOffset(Streamer, MemberTypeInfo, 4); + + // DW_AT_data_member_location + Streamer->emitIntValue(Offset, 4); +} + +// DwarfStaticDataField + +void DwarfStaticDataField::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) { + // Abbrev Number + Streamer->emitULEB128IntValue(DwarfAbbrev::ClassMemberStatic); + + // DW_AT_name + EmitSectionOffset(Streamer, StrSymbol, 4); + + // DW_AT_type + DwarfInfo *MemberTypeInfo = TypeBuilder->GetTypeInfoByIndex(TypeIndex); + assert(MemberTypeInfo != nullptr); + EmitInfoOffset(Streamer, MemberTypeInfo, 4); +} + +// DwarfClassTypeInfo + +DwarfClassTypeInfo::DwarfClassTypeInfo(const ClassTypeDescriptor &ClassDescriptor, + const ClassFieldsTypeDescriptior &ClassFieldsDescriptor, + const DataFieldDescriptor *FieldsDescriptors, + const StaticDataFieldDescriptor *StaticsDescriptors) : + Name(ClassDescriptor.Name), + IsStruct(ClassDescriptor.IsStruct), + BaseClassId(ClassDescriptor.BaseClassId), + Size(ClassDescriptor.InstanceSize), + IsForwardDecl(false) { + int32_t staticIdx = 0; + for (int32_t i = 0; i < ClassFieldsDescriptor.FieldsCount; i++) { + if (FieldsDescriptors[i].Offset == 0xFFFFFFFF) { + StaticFields.emplace_back(FieldsDescriptors[i], StaticsDescriptors[staticIdx++]); + } else { + Fields.emplace_back(FieldsDescriptors[i]); + } + } +} + +void DwarfClassTypeInfo::DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) { + if (IsDumpedTypes) + return; + + DwarfInfo::DumpTypes(TypeBuilder, Streamer, TypeSection, StrSection); + + if (BaseClassId != 0) { + DwarfInfo *BaseClassInfo = TypeBuilder->GetTypeInfoByIndex(BaseClassId); + assert(BaseClassInfo != nullptr); + + BaseClassInfo->Dump(TypeBuilder, Streamer, TypeSection, StrSection); + } + + for (auto &Field : Fields) { + Field.DumpTypes(TypeBuilder, Streamer, TypeSection, StrSection); + } + + for (auto &StaticField : StaticFields) { + StaticField.DumpTypes(TypeBuilder, Streamer, TypeSection, StrSection); + } + + for (auto *Function : MemberFunctions) { + Function->DumpTypes(TypeBuilder, Streamer, TypeSection, StrSection); + } +} + +void DwarfClassTypeInfo::Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) { + if (IsDumped) + return; + + DwarfInfo::Dump(TypeBuilder, Streamer, TypeSection, StrSection); + + if (IsForwardDecl) + return; + + for (auto &Field : Fields) { + Field.Dump(TypeBuilder, Streamer, TypeSection, StrSection); + } + + for (auto &StaticField : StaticFields) { + StaticField.Dump(TypeBuilder, Streamer, TypeSection, StrSection); + } + + for (auto *Function : MemberFunctions) { + Function->Dump(TypeBuilder, Streamer, TypeSection, StrSection); + } + + // Terminate DIE + Streamer->SwitchSection(TypeSection); + DwarfInfo::EndChildrenList(Streamer); +} + +void DwarfClassTypeInfo::DumpStrings(MCObjectStreamer *Streamer) { + Streamer->emitBytes(StringRef(Name)); + Streamer->emitIntValue(0, 1); +} + +void DwarfClassTypeInfo::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) { + // Abbrev Number + auto abbrev = IsForwardDecl ? DwarfAbbrev::ClassTypeDecl + : HasChildren() ? DwarfAbbrev::ClassType + : DwarfAbbrev::ClassTypeNoChildren; + + Streamer->emitULEB128IntValue(abbrev); + + // DW_AT_name + EmitSectionOffset(Streamer, StrSymbol, 4); + + if (!IsForwardDecl) { + // DW_AT_byte_size + Streamer->emitIntValue(Size, 4); + } + + if (BaseClassId != 0) { + DwarfInfo *BaseClassInfo = TypeBuilder->GetTypeInfoByIndex(BaseClassId); + assert(BaseClassInfo != nullptr); + + // DW_TAG_inheritance DIE + + // Abbrev Number + Streamer->emitULEB128IntValue(DwarfAbbrev::ClassInheritance); + + // DW_AT_type + EmitInfoOffset(Streamer, BaseClassInfo, 4); + + // DW_AT_data_member_location = 0 + Streamer->emitIntValue(0, 1); + } +} + +bool DwarfClassTypeInfo::HasChildren() { + return BaseClassId != 0 || !Fields.empty() || !StaticFields.empty() || !MemberFunctions.empty(); +} + +// DwarfSimpleArrayTypeInfo + +void DwarfSimpleArrayTypeInfo::DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) { + if (IsDumpedTypes) + return; + + DwarfInfo::DumpTypes(TypeBuilder, Streamer, TypeSection, StrSection); + + DwarfInfo *ElementInfo = TypeBuilder->GetTypeInfoByIndex(ElementType); + assert(ElementInfo != nullptr); + + ElementInfo->Dump(TypeBuilder, Streamer, TypeSection, StrSection); +} + +void DwarfSimpleArrayTypeInfo::DumpStrings(MCObjectStreamer *Streamer) { + // nothing to dump +} + +void DwarfSimpleArrayTypeInfo::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) { + // Abbrev Number + Streamer->emitULEB128IntValue(DwarfAbbrev::ArrayType); + + DwarfInfo *Info = TypeBuilder->GetTypeInfoByIndex(ElementType); + assert(Info != nullptr); + + // DW_AT_type + EmitInfoOffset(Streamer, Info, 4); + + // DW_TAG_subrange_type DIE + + // Abbrev Number + Streamer->emitULEB128IntValue(DwarfAbbrev::SubrangeType); + + // DW_AT_upper_bound + Streamer->emitULEB128IntValue(Size - 1); + + // Terminate DIE + EndChildrenList(Streamer); +} + +// DwarfPointerTypeInfo + +void DwarfPointerTypeInfo::DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) { + if (IsDumpedTypes) + return; + + DwarfInfo::DumpTypes(TypeBuilder, Streamer, TypeSection, StrSection); + + DwarfInfo *Info = TypeBuilder->GetTypeInfoByIndex(TypeDesc.ElementType); + assert(Info != nullptr); + + Info->Dump(TypeBuilder, Streamer, TypeSection, StrSection); +} + +void DwarfPointerTypeInfo::DumpStrings(MCObjectStreamer *Streamer) { + // nothing to dump +} + +void DwarfPointerTypeInfo::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) { + // Abbrev Number + Streamer->emitULEB128IntValue(TypeDesc.IsReference ? DwarfAbbrev::ReferenceType : DwarfAbbrev::PointerType); + + DwarfInfo *Info = TypeBuilder->GetTypeInfoByIndex(TypeDesc.ElementType); + assert(Info != nullptr); + + // DW_AT_type + EmitInfoOffset(Streamer, Info, 4); + + // DW_AT_byte_size + Streamer->emitIntValue(TypeDesc.Is64Bit ? 8 : 4, 1); +} + +// DwarfVoidPtrTypeInfo + +void DwarfVoidPtrTypeInfo::DumpStrings(MCObjectStreamer* Streamer) { + // nothing to dump +} + +void DwarfVoidPtrTypeInfo::DumpTypeInfo(MCObjectStreamer* Streamer, UserDefinedDwarfTypesBuilder* TypeBuilder) { + // Abbrev Number + Streamer->emitULEB128IntValue(DwarfAbbrev::VoidPointerType); +} + +// DwarfMemberFunctionTypeInfo + +DwarfMemberFunctionTypeInfo::DwarfMemberFunctionTypeInfo( + const MemberFunctionTypeDescriptor& MemberDescriptor, + uint32_t const *const ArgumentTypes, + bool IsStaticMethod) : + TypeDesc(MemberDescriptor), + IsStaticMethod(IsStaticMethod) { + for (uint16_t i = 0; i < MemberDescriptor.NumberOfArguments; i++) { + this->ArgumentTypes.push_back(ArgumentTypes[i]); + } +} + +void DwarfMemberFunctionTypeInfo::DumpStrings(MCObjectStreamer *Streamer) { + // nothing to dump +} + +void DwarfMemberFunctionTypeInfo::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) { + // nothing to dump +} + +// DwarfMemberFunctionIdTypeInfo + +void DwarfMemberFunctionIdTypeInfo::DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) { + if (IsDumpedTypes) + return; + + DwarfInfo::DumpTypes(TypeBuilder, Streamer, TypeSection, StrSection); + + // Dump return type + DwarfInfo *ReturnTypeInfo = TypeBuilder->GetTypeInfoByIndex(MemberFunctionTypeInfo->GetReturnTypeIndex()); + assert(ReturnTypeInfo != nullptr); + + ReturnTypeInfo->Dump(TypeBuilder, Streamer, TypeSection, StrSection); + + // Dump this pointer type + if (!MemberFunctionTypeInfo->IsStatic()) { + DwarfInfo *ThisPtrTypeInfo = TypeBuilder->GetTypeInfoByIndex(MemberFunctionTypeInfo->GetThisPtrTypeIndex()); + assert(ThisPtrTypeInfo != nullptr); + + ThisPtrTypeInfo->Dump(TypeBuilder, Streamer, TypeSection, StrSection); + } + + // Dump argument types + for (uint32_t ArgTypeIndex : MemberFunctionTypeInfo->GetArgTypes()) { + DwarfInfo *ArgTypeInfo = TypeBuilder->GetTypeInfoByIndex(ArgTypeIndex); + assert(ArgTypeInfo != nullptr); + ArgTypeInfo->Dump(TypeBuilder, Streamer, TypeSection, StrSection); + } +} + +void DwarfMemberFunctionIdTypeInfo::DumpStrings(MCObjectStreamer *Streamer) { + Streamer->emitBytes(StringRef(Name)); + Streamer->emitIntValue(0, 1); + + MCContext &context = Streamer->getContext(); + LinkageNameSymbol = context.createTempSymbol(); + Streamer->emitLabel(LinkageNameSymbol); + Streamer->emitBytes(StringRef(LinkageName)); + Streamer->emitIntValue(0, 1); +} + +void DwarfMemberFunctionIdTypeInfo::DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) { + // Abbrev Number + bool IsStatic = MemberFunctionTypeInfo->IsStatic(); + bool HasParameters = MemberFunctionTypeInfo->GetArgTypes().size(); + + Streamer->emitULEB128IntValue( + IsStatic ? (HasParameters ? DwarfAbbrev::SubprogramStaticSpec + : DwarfAbbrev::SubprogramStaticNoChildrenSpec) + : DwarfAbbrev::SubprogramSpec); + + // DW_AT_name + EmitSectionOffset(Streamer, StrSymbol, 4); + + // DW_AT_linkage_name + EmitSectionOffset(Streamer, LinkageNameSymbol, 4); + + // DW_AT_decl_file + Streamer->emitIntValue(1, 1); + + // DW_AT_decl_line + Streamer->emitIntValue(1, 1); + + // DW_AT_type + DwarfInfo *ReturnTypeInfo = TypeBuilder->GetTypeInfoByIndex(MemberFunctionTypeInfo->GetReturnTypeIndex()); + assert(ReturnTypeInfo != nullptr); + + EmitInfoOffset(Streamer, ReturnTypeInfo, 4); + + if (!IsStatic) { + // DW_AT_object_pointer + uint32_t Offset = Streamer->getOrCreateDataFragment()->getContents().size(); + + Streamer->emitIntValue(Offset + 4, 4); + + // This formal parameter DIE + DwarfInfo *ThisTypeInfo = TypeBuilder->GetTypeInfoByIndex(MemberFunctionTypeInfo->GetThisPtrTypeIndex()); + assert(ThisTypeInfo != nullptr); + + // Abbrev Number + Streamer->emitULEB128IntValue(DwarfAbbrev::FormalParameterThisSpec); + + // DW_AT_type + EmitInfoOffset(Streamer, ThisTypeInfo, 4); + } + + for (uint32_t ArgTypeIndex : MemberFunctionTypeInfo->GetArgTypes()) { + DwarfInfo *ArgTypeInfo = TypeBuilder->GetTypeInfoByIndex(ArgTypeIndex); + assert(ArgTypeInfo != nullptr); + + // Formal parameter DIE + + // Abbrev Number + Streamer->emitULEB128IntValue(DwarfAbbrev::FormalParameterSpec); + + // DW_AT_type + EmitInfoOffset(Streamer, ArgTypeInfo, 4); + } + + // Terminate DIE (skip for SubprogramStaticNoChildrenSpec which has no children) + if (!IsStatic || HasParameters) { + Streamer->emitIntValue(0, 1); + } +} + +// DwarfTypesBuilder + +void UserDefinedDwarfTypesBuilder::EmitTypeInformation( + MCSection *TypeSection, + MCSection *StrSection) { + for (auto &Info : DwarfTypes) { + Info->Dump(this, Streamer, TypeSection, StrSection); + } +} + +unsigned UserDefinedDwarfTypesBuilder::GetEnumTypeIndex( + const EnumTypeDescriptor &TypeDescriptor, + const EnumRecordTypeDescriptor *TypeRecords) { + unsigned TypeIndex = ArrayIndexToTypeIndex(DwarfTypes.size()); + UserDefinedTypes.push_back(std::make_pair(TypeDescriptor.Name, TypeIndex)); + DwarfTypes.push_back(std::make_unique(TypeDescriptor, TypeRecords)); + return TypeIndex; +} + +unsigned UserDefinedDwarfTypesBuilder::GetClassTypeIndex( + const ClassTypeDescriptor &ClassDescriptor) { + unsigned TypeIndex = ArrayIndexToTypeIndex(DwarfTypes.size()); + DwarfTypes.push_back(std::make_unique(ClassDescriptor)); + return TypeIndex; +} + +unsigned UserDefinedDwarfTypesBuilder::GetCompleteClassTypeIndex( + const ClassTypeDescriptor &ClassDescriptor, + const ClassFieldsTypeDescriptior &ClassFieldsDescriptor, + const DataFieldDescriptor *FieldsDescriptors, + const StaticDataFieldDescriptor *StaticsDescriptors) { + unsigned TypeIndex = ArrayIndexToTypeIndex(DwarfTypes.size()); + UserDefinedTypes.push_back(std::make_pair(ClassDescriptor.Name, TypeIndex)); + + DwarfClassTypeInfo *ClassTypeInfo = new DwarfClassTypeInfo(ClassDescriptor, ClassFieldsDescriptor, + FieldsDescriptors, StaticsDescriptors); + + DwarfTypes.push_back(std::unique_ptr(ClassTypeInfo)); + + if (ClassTypeInfo->GetStaticFields().size() > 0) { + ClassesWithStaticFields.push_back(ClassTypeInfo); + } + + return TypeIndex; +} + +unsigned UserDefinedDwarfTypesBuilder::GetArrayTypeIndex( + const ClassTypeDescriptor &ClassDescriptor, + const ArrayTypeDescriptor &ArrayDescriptor) { + // Create corresponding class info + ClassTypeDescriptor ArrayClassDescriptor = ClassDescriptor; + + std::vector FieldDescs; + unsigned FieldOffset = TargetPointerSize; + + FieldDescs.push_back({GetPrimitiveTypeIndex(PrimitiveTypeFlags::Int32), FieldOffset, "m_NumComponents"}); + FieldOffset += TargetPointerSize; + + if (ArrayDescriptor.IsMultiDimensional == 1) { + unsigned BoundsTypeIndex = GetSimpleArrayTypeIndex(GetPrimitiveTypeIndex(PrimitiveTypeFlags::Int32), ArrayDescriptor.Rank); + FieldDescs.push_back({BoundsTypeIndex, FieldOffset, "m_Bounds"}); + FieldOffset += 2 * 4 * ArrayDescriptor.Rank; + } + + unsigned DataTypeIndex = GetSimpleArrayTypeIndex(ArrayDescriptor.ElementType, 0); + FieldDescs.push_back({DataTypeIndex, FieldOffset, "m_Data"}); + + ClassFieldsTypeDescriptior FieldsTypeDesc = + {TargetPointerSize, ArrayDescriptor.IsMultiDimensional ? 3 : 2}; + + ArrayClassDescriptor.InstanceSize = FieldOffset; + + unsigned TypeIndex = ArrayIndexToTypeIndex(DwarfTypes.size()); + UserDefinedTypes.push_back(std::make_pair(ArrayClassDescriptor.Name, TypeIndex)); + DwarfTypes.push_back(std::make_unique(ArrayClassDescriptor, FieldsTypeDesc, FieldDescs.data(), nullptr)); + + return TypeIndex; +} + +unsigned UserDefinedDwarfTypesBuilder::GetPointerTypeIndex(const PointerTypeDescriptor& PointerDescriptor) +{ + unsigned VoidTypeIndex = GetPrimitiveTypeIndex(PrimitiveTypeFlags::Void); + + unsigned TypeIndex = ArrayIndexToTypeIndex(DwarfTypes.size()); + + // Creating a pointer to what DWARF considers Void type (DW_TAG_unspecified_type - + // per http://eagercon.com/dwarf/issues/minutes-001017.htm) leads to unhappines + // since debuggers don't really know how to handle that. The Clang symbol parser + // in LLDB only handles DW_TAG_unspecified_type if it's named + // "nullptr_t" or "decltype(nullptr)". + // + // We resort to this kludge to generate the exact same debug info for void* that + // clang would generate (pointer type with no element type specified). + if (PointerDescriptor.ElementType == VoidTypeIndex) + DwarfTypes.push_back(std::make_unique()); + else + DwarfTypes.push_back(std::make_unique(PointerDescriptor)); + + return TypeIndex; +} + +unsigned UserDefinedDwarfTypesBuilder::GetMemberFunctionTypeIndex(const MemberFunctionTypeDescriptor& MemberDescriptor, + uint32_t const *const ArgumentTypes) +{ + bool IsStatic = MemberDescriptor.TypeIndexOfThisPointer == GetPrimitiveTypeIndex(PrimitiveTypeFlags::Void); + unsigned TypeIndex = ArrayIndexToTypeIndex(DwarfTypes.size()); + DwarfTypes.push_back(std::make_unique(MemberDescriptor, ArgumentTypes, IsStatic)); + return TypeIndex; +} + +unsigned UserDefinedDwarfTypesBuilder::GetMemberFunctionId(const MemberFunctionIdTypeDescriptor& MemberIdDescriptor) +{ + unsigned TypeIndex = ArrayIndexToTypeIndex(DwarfTypes.size()); + + DwarfMemberFunctionTypeInfo *MemberFunctionTypeInfo = static_cast( + GetTypeInfoByIndex(MemberIdDescriptor.MemberFunction)); + assert(MemberFunctionTypeInfo != nullptr); + + DwarfMemberFunctionIdTypeInfo *MemberFunctionIdTypeInfo = + new DwarfMemberFunctionIdTypeInfo(MemberIdDescriptor, MemberFunctionTypeInfo); + + DwarfTypes.push_back(std::unique_ptr(MemberFunctionIdTypeInfo)); + + DwarfClassTypeInfo *ParentClassInfo = static_cast( + GetTypeInfoByIndex(MemberIdDescriptor.ParentClass)); + assert(ParentClassInfo != nullptr); + + ParentClassInfo->AddMemberFunction(MemberFunctionIdTypeInfo); + + return TypeIndex; +} + +unsigned UserDefinedDwarfTypesBuilder::GetPrimitiveTypeIndex(PrimitiveTypeFlags Type) { + auto Iter = PrimitiveDwarfTypes.find(Type); + if (Iter != PrimitiveDwarfTypes.end()) + return Iter->second; + + unsigned TypeIndex = ArrayIndexToTypeIndex(DwarfTypes.size()); + + if (Type == PrimitiveTypeFlags::Void) + DwarfTypes.push_back(std::make_unique()); + else + DwarfTypes.push_back(std::make_unique(Type)); + + PrimitiveDwarfTypes.insert(std::make_pair(Type, TypeIndex)); + + return TypeIndex; +} + +unsigned UserDefinedDwarfTypesBuilder::GetSimpleArrayTypeIndex(unsigned ElemIndex, unsigned Size) { + auto Iter = SimpleArrayDwarfTypes.find(ElemIndex); + if (Iter != SimpleArrayDwarfTypes.end()) { + auto CountMap = Iter->second; + auto CountIter = CountMap.find(Size); + if (CountIter != CountMap.end()) + return CountIter->second; + } + + unsigned TypeIndex = ArrayIndexToTypeIndex(DwarfTypes.size()); + DwarfTypes.push_back(std::make_unique(ElemIndex, Size)); + + SimpleArrayDwarfTypes[ElemIndex][Size] = TypeIndex; + + return TypeIndex; +} diff --git a/llvm/tools/objwriter/debugInfo/dwarf/dwarfTypeBuilder.h b/llvm/tools/objwriter/debugInfo/dwarf/dwarfTypeBuilder.h new file mode 100644 index 0000000000000..eb04620b00a94 --- /dev/null +++ b/llvm/tools/objwriter/debugInfo/dwarf/dwarfTypeBuilder.h @@ -0,0 +1,390 @@ +//===---- dwarfTypeBuilder.h ------------------------------------*- C++ -*-===// +// +// type builder is used to convert .Net types into Dwarf debuginfo. +// +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "debugInfo/typeBuilder.h" + +#include +#include + +class UserDefinedDwarfTypesBuilder; + +class DwarfInfo +{ +public: + DwarfInfo() : + StrSymbol(nullptr), + InfoSymbol(nullptr), + IsDumped(false), + IsDumpedTypes(false) {} + + virtual ~DwarfInfo() {} + + virtual void Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection); + + virtual void DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection); + + MCSymbol *GetInfoSymbol() { return InfoSymbol; } + + const MCExpr *GetInfoExpr() { return InfoExpr; } + +protected: + virtual void DumpStrings(MCObjectStreamer *Streamer) = 0; + virtual void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) = 0; + virtual bool HasChildren() { return false; } + virtual void EndChildrenList(MCObjectStreamer *Streamer); + + static void EmitSectionOffset(MCObjectStreamer *Streamer, + MCSymbol *Symbol, + unsigned Size, + uint32_t Offset = 0); + + static const MCExpr *CreateOffsetExpr(MCContext &Context, + MCSymbol *BeginSymbol, + MCSymbol *Symbol); + + static void EmitOffset(MCObjectStreamer *Streamer, + const MCExpr *OffsetExpr, + unsigned Size); + + static void EmitInfoOffset(MCObjectStreamer *Streamer, const DwarfInfo *Info, unsigned Size); + + MCSymbol *StrSymbol; + MCSymbol *InfoSymbol; + const MCExpr *InfoExpr; + + bool IsDumped; + bool IsDumpedTypes; +}; + +class DwarfPrimitiveTypeInfo : public DwarfInfo +{ +public: + DwarfPrimitiveTypeInfo(PrimitiveTypeFlags PrimitiveType) : Type(PrimitiveType) {} + + PrimitiveTypeFlags GetType() { return Type; } + +protected: + void DumpStrings(MCObjectStreamer *Streamer) override; + void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override; + +private: + PrimitiveTypeFlags Type; +}; + +class DwarfVoidTypeInfo : public DwarfPrimitiveTypeInfo +{ +public: + DwarfVoidTypeInfo() : DwarfPrimitiveTypeInfo(PrimitiveTypeFlags::Void) {} + +protected: + void DumpStrings(MCObjectStreamer* Streamer) override; + void DumpTypeInfo(MCObjectStreamer* Streamer, UserDefinedDwarfTypesBuilder* TypeBuilder) override; +}; + +class DwarfEnumTypeInfo; + +class DwarfEnumerator : public DwarfInfo +{ +public: + DwarfEnumerator(const EnumRecordTypeDescriptor &Descriptor, DwarfEnumTypeInfo *TypeInfo) : + Name(Descriptor.Name), Value(Descriptor.Value), EnumTypeInfo(TypeInfo) {} + +protected: + void DumpStrings(MCObjectStreamer *Streamer) override; + void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override; + +private: + std::string Name; + uint64 Value; + DwarfEnumTypeInfo *EnumTypeInfo; +}; + +class DwarfEnumTypeInfo : public DwarfInfo +{ +public: + DwarfEnumTypeInfo(const EnumTypeDescriptor &TypeDescriptor, + const EnumRecordTypeDescriptor *TypeRecords); + + void Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) override; + + void DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) override; + + uint8_t GetByteSize() const { return ByteSize; } + +protected: + void DumpStrings(MCObjectStreamer *Streamer) override; + void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override; + bool HasChildren() override { return !Records.empty(); } + +private: + std::string Name; + uint32_t ElementType; + std::vector Records; + uint8_t ByteSize; +}; + +class DwarfDataField : public DwarfInfo +{ +public: + DwarfDataField(const DataFieldDescriptor &Descriptor) : + Name(Descriptor.Name), + TypeIndex(Descriptor.FieldTypeIndex), + Offset(Descriptor.Offset) {} + + void DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) override; + + uint32_t GetTypeIndex() const { return TypeIndex; } + + const std::string &GetName() const { return Name; } + +protected: + void DumpStrings(MCObjectStreamer *Streamer) override; + void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override; + + std::string Name; + uint32_t TypeIndex; + uint64 Offset; +}; + +class DwarfStaticDataField : public DwarfDataField +{ +public: + DwarfStaticDataField(const DataFieldDescriptor &Descriptor, + const StaticDataFieldDescriptor &StaticDescriptor) : + DwarfDataField(Descriptor), + StaticDataName(StaticDescriptor.StaticDataName), + StaticOffset(StaticDescriptor.StaticOffset), + StaticDataInObject(StaticDescriptor.IsStaticDataInObject) {} + + const std::string &GetStaticDataName() const { return StaticDataName; } + uint64 GetStaticOffset() const { return StaticOffset; } + bool IsStaticDataInObject() const { return StaticDataInObject; } + +protected: + void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override; + +private: + std::string StaticDataName; + uint64 StaticOffset; + bool StaticDataInObject; +}; + +class DwarfMemberFunctionIdTypeInfo; + +class DwarfClassTypeInfo : public DwarfInfo +{ +public: + DwarfClassTypeInfo(const ClassTypeDescriptor &ClassDescriptor) : + Name(ClassDescriptor.Name), + IsStruct(ClassDescriptor.IsStruct), + BaseClassId(ClassDescriptor.BaseClassId), + Size(ClassDescriptor.InstanceSize), + IsForwardDecl(true) {} + + DwarfClassTypeInfo(const ClassTypeDescriptor &ClassDescriptor, + const ClassFieldsTypeDescriptior &ClassFieldsDescriptor, + const DataFieldDescriptor *FieldsDescriptors, + const StaticDataFieldDescriptor *StaticsDescriptors); + + void Dump(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) override; + + void DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) override; + + void AddMemberFunction(DwarfMemberFunctionIdTypeInfo* TypeInfo) { + MemberFunctions.push_back(TypeInfo); + } + + const std::vector &GetStaticFields() const { return StaticFields; } + + const std::string &GetName() const { return Name; } + +protected: + void DumpStrings(MCObjectStreamer *Streamer) override; + void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override; + bool HasChildren() override; + + std::string Name; + bool IsStruct; + uint32_t BaseClassId; + uint64 Size; + bool IsForwardDecl; + std::vector Fields; + std::vector StaticFields; + std::vector MemberFunctions; +}; + +class DwarfSimpleArrayTypeInfo : public DwarfInfo +{ +public: + DwarfSimpleArrayTypeInfo(uint32_t ArrayElementType, uint64_t Size) : + ElementType(ArrayElementType), + Size(Size) {} + + void DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) override; + +protected: + void DumpStrings(MCObjectStreamer *Streamer) override; + void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override; + // ArrayTypeInfo always contains a SubrangeType entry + bool HasChildren() override { return true; } + +private: + uint32_t ElementType; + uint64_t Size; +}; + +class DwarfPointerTypeInfo : public DwarfInfo +{ +public: + DwarfPointerTypeInfo(const PointerTypeDescriptor& PointerDescriptor) : + TypeDesc(PointerDescriptor) {} + + void DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) override; + +protected: + void DumpStrings(MCObjectStreamer *Streamer) override; + void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override; + +private: + PointerTypeDescriptor TypeDesc; +}; + +class DwarfVoidPtrTypeInfo : public DwarfInfo +{ +public: + DwarfVoidPtrTypeInfo() {} + +protected: + void DumpStrings(MCObjectStreamer* Streamer) override; + void DumpTypeInfo(MCObjectStreamer* Streamer, UserDefinedDwarfTypesBuilder* TypeBuilder) override; +}; + +class DwarfMemberFunctionTypeInfo : public DwarfInfo +{ +public: + DwarfMemberFunctionTypeInfo(const MemberFunctionTypeDescriptor& MemberDescriptor, + uint32_t const *const ArgumentTypes, + bool IsStaticMethod); + + const std::vector &GetArgTypes() const { return ArgumentTypes; } + + bool IsStatic() const { return IsStaticMethod; } + + uint32_t GetReturnTypeIndex() const { return TypeDesc.ReturnType; } + + uint32_t GetThisPtrTypeIndex() const { return TypeDesc.TypeIndexOfThisPointer; } + +protected: + void DumpStrings(MCObjectStreamer *Streamer) override; + void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override; + +private: + MemberFunctionTypeDescriptor TypeDesc; + std::vector ArgumentTypes; + bool IsStaticMethod; +}; + +class DwarfMemberFunctionIdTypeInfo : public DwarfInfo +{ +public: + DwarfMemberFunctionIdTypeInfo(const MemberFunctionIdTypeDescriptor& MemberIdDescriptor, + DwarfMemberFunctionTypeInfo *TypeInfo) : + LinkageName(MemberIdDescriptor.Name), + Name(MemberIdDescriptor.Name), + ParentClass(MemberIdDescriptor.ParentClass), + MemberFunctionTypeInfo(TypeInfo), + LinkageNameSymbol(nullptr) {} + + const std::vector &GetArgTypes() const { return MemberFunctionTypeInfo->GetArgTypes(); } + + void SetLinkageName(const char *Name) { LinkageName = Name; } + + void DumpTypes(UserDefinedDwarfTypesBuilder *TypeBuilder, MCObjectStreamer *Streamer, + MCSection *TypeSection, MCSection *StrSection) override; + + bool IsStatic() const { return MemberFunctionTypeInfo->IsStatic(); } + +protected: + void DumpStrings(MCObjectStreamer *Streamer) override; + void DumpTypeInfo(MCObjectStreamer *Streamer, UserDefinedDwarfTypesBuilder *TypeBuilder) override; + +private: + std::string LinkageName; + std::string Name; + uint32_t ParentClass; + DwarfMemberFunctionTypeInfo *MemberFunctionTypeInfo; + MCSymbol *LinkageNameSymbol; +}; + +template +class EnumHash +{ + typedef typename std::underlying_type::type enumType; +public: + size_t operator()(const T& elem) const { + return std::hash()(static_cast(elem)); + } +}; + +class UserDefinedDwarfTypesBuilder : public UserDefinedTypesBuilder +{ +public: + UserDefinedDwarfTypesBuilder() {} + void EmitTypeInformation(MCSection *TypeSection, MCSection *StrSection = nullptr) override; + + unsigned GetEnumTypeIndex(const EnumTypeDescriptor &TypeDescriptor, + const EnumRecordTypeDescriptor *TypeRecords) override; + unsigned GetClassTypeIndex(const ClassTypeDescriptor &ClassDescriptor) override; + unsigned GetCompleteClassTypeIndex( + const ClassTypeDescriptor &ClassDescriptor, + const ClassFieldsTypeDescriptior &ClassFieldsDescriptor, + const DataFieldDescriptor *FieldsDescriptors, + const StaticDataFieldDescriptor *StaticsDescriptors) override; + + unsigned GetArrayTypeIndex(const ClassTypeDescriptor &ClassDescriptor, + const ArrayTypeDescriptor &ArrayDescriptor) override; + + unsigned GetPointerTypeIndex(const PointerTypeDescriptor& PointerDescriptor) override; + + unsigned GetMemberFunctionTypeIndex(const MemberFunctionTypeDescriptor& MemberDescriptor, + uint32_t const *const ArgumentTypes) override; + + unsigned GetMemberFunctionId(const MemberFunctionIdTypeDescriptor& MemberIdDescriptor) override; + + unsigned GetPrimitiveTypeIndex(PrimitiveTypeFlags Type) override; + + DwarfInfo *GetTypeInfoByIndex(unsigned Index) const { return DwarfTypes[TypeIndexToArrayIndex(Index)].get(); } + + unsigned GetSimpleArrayTypeIndex(unsigned ElemIndex, unsigned Size); + + const std::vector &GetClassesWithStaticFields() const { return ClassesWithStaticFields; } + +private: + static const unsigned StartTypeIndex = 1; // Make TypeIndex 0 - Invalid + static unsigned TypeIndexToArrayIndex(unsigned TypeIndex) { return TypeIndex - StartTypeIndex; } + static unsigned ArrayIndexToTypeIndex(unsigned ArrayIndex) { return ArrayIndex + StartTypeIndex; } + + std::vector> DwarfTypes; + std::unordered_map> PrimitiveDwarfTypes; + // map[ElemTypeIndex][Size] -> ArrTypeIndex + std::unordered_map> SimpleArrayDwarfTypes; + + std::vector ClassesWithStaticFields; +}; diff --git a/llvm/tools/objwriter/debugInfo/typeBuilder.h b/llvm/tools/objwriter/debugInfo/typeBuilder.h new file mode 100644 index 0000000000000..67a5004d248b9 --- /dev/null +++ b/llvm/tools/objwriter/debugInfo/typeBuilder.h @@ -0,0 +1,157 @@ +//===---- typeBuilder.h -----------------------------------------*- C++ -*-===// +// +// type builder is used to convert .Net types into debuginfo. +// +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "llvm/MC/MCObjectStreamer.h" + +#include +#include + +using namespace llvm; + +// Keep in sync with Internal.TypeSystem.TypeFlags (Common/src/TypeSystem/Common/TypeFlags.cs) +enum class PrimitiveTypeFlags { + Unknown = 0x00, + Void = 0x01, + Boolean = 0x02, + Char = 0x03, + SByte = 0x04, + Byte = 0x05, + Int16 = 0x06, + UInt16 = 0x07, + Int32 = 0x08, + UInt32 = 0x09, + Int64 = 0x0A, + UInt64 = 0x0B, + IntPtr = 0x0C, + UIntPtr = 0x0D, + Single = 0x0E, + Double = 0x0F +}; + +typedef unsigned long long uint64; + +#pragma pack(push, 8) + +extern "C" struct EnumRecordTypeDescriptor { + uint64 Value; + const char *Name; +}; + +extern "C" struct EnumTypeDescriptor { + uint32_t ElementType; + uint64 ElementCount; + const char *Name; +}; + +extern "C" struct ClassTypeDescriptor { + int32_t IsStruct; + const char *Name; + uint32_t BaseClassId; + uint64 InstanceSize; +}; + +extern "C" struct DataFieldDescriptor { + uint32_t FieldTypeIndex; + uint64 Offset; + const char *Name; +}; + +extern "C" struct StaticDataFieldDescriptor { + const char *StaticDataName; + uint64 StaticOffset; + int IsStaticDataInObject; +}; + +extern "C" struct ClassFieldsTypeDescriptior { + uint64 Size; + int32_t FieldsCount; +}; + +extern "C" struct ArrayTypeDescriptor { + uint32_t Rank; + uint32_t ElementType; + uint32_t Size; // ElementSize + int32_t IsMultiDimensional; +}; + +extern "C" struct PointerTypeDescriptor { + uint32_t ElementType; + int32_t IsReference; + int32_t IsConst; + int32_t Is64Bit; +}; + +extern "C" struct MemberFunctionTypeDescriptor { + uint32_t ReturnType; + uint32_t ContainingClass; + uint32_t TypeIndexOfThisPointer; + int32_t ThisAdjust; + uint32_t CallingConvention; + uint16_t NumberOfArguments; +}; + +extern "C" struct MemberFunctionIdTypeDescriptor { + uint32_t MemberFunction; + uint32_t ParentClass; + const char *Name; +}; + +#pragma pack(pop) +class UserDefinedTypesBuilder { +public: + UserDefinedTypesBuilder() : Streamer(nullptr), TargetPointerSize(0) {} + virtual ~UserDefinedTypesBuilder() {} + void SetStreamer(MCObjectStreamer *Streamer) { + assert(this->Streamer == nullptr); + assert(Streamer != nullptr); + this->Streamer = Streamer; + } + MCObjectStreamer *GetStreamer() const { + return Streamer; + } + void SetTargetPointerSize(unsigned TargetPointerSize) { + assert(this->TargetPointerSize == 0); + assert(TargetPointerSize != 0); + this->TargetPointerSize = TargetPointerSize; + } + virtual void EmitTypeInformation(MCSection *TypeSection, MCSection *StrSection = nullptr) = 0; + + virtual unsigned GetEnumTypeIndex(const EnumTypeDescriptor &TypeDescriptor, + const EnumRecordTypeDescriptor *TypeRecords) = 0; + virtual unsigned GetClassTypeIndex(const ClassTypeDescriptor &ClassDescriptor) = 0; + virtual unsigned GetCompleteClassTypeIndex( + const ClassTypeDescriptor &ClassDescriptor, + const ClassFieldsTypeDescriptior &ClassFieldsDescriptor, + const DataFieldDescriptor *FieldsDescriptors, + const StaticDataFieldDescriptor *StaticsDescriptors) = 0; + + virtual unsigned GetArrayTypeIndex(const ClassTypeDescriptor &ClassDescriptor, + const ArrayTypeDescriptor &ArrayDescriptor) = 0; + + virtual unsigned GetPointerTypeIndex(const PointerTypeDescriptor& PointerDescriptor) = 0; + + virtual unsigned GetMemberFunctionTypeIndex(const MemberFunctionTypeDescriptor& MemberDescriptor, + uint32_t const *const ArgumentTypes) = 0; + + virtual unsigned GetMemberFunctionId(const MemberFunctionIdTypeDescriptor& MemberIdDescriptor) = 0; + + virtual unsigned GetPrimitiveTypeIndex(PrimitiveTypeFlags Type) = 0; + + virtual const std::vector> &GetUDTs() { + return UserDefinedTypes; + } + +protected: + MCObjectStreamer *Streamer; + unsigned TargetPointerSize; + + std::vector> UserDefinedTypes; +}; diff --git a/llvm/tools/objwriter/jitDebugInfo.h b/llvm/tools/objwriter/jitDebugInfo.h new file mode 100644 index 0000000000000..88a96f7673287 --- /dev/null +++ b/llvm/tools/objwriter/jitDebugInfo.h @@ -0,0 +1,66 @@ +#ifndef JIT_DEBUG_INFO_H +#define JIT_DEBUG_INFO_H + +typedef unsigned int DWORD; + +#define PORTABILITY_WARNING(msg) +#include "cordebuginfo.h" + +// RegNum enumeration is architecture-specific and we need it for all +// architectures we support. + +namespace X86 { +#define TARGET_X86 1 +#include "cordebuginfo.h" +#undef TARGET_X86 +} + +namespace Amd64 { +#define TARGET_AMD64 1 +#include "cordebuginfo.h" +#undef TARGET_AMD64 +} + +namespace Arm { +#define TARGET_ARM 1 +#include "cordebuginfo.h" +#undef TARGET_ARM +} + +namespace Arm64 { +#define TARGET_ARM64 1 +#include "cordebuginfo.h" +#undef TARGET_ARM64 +} + +struct DebugLocInfo { + int NativeOffset; + int FileId; + int LineNumber; + int ColNumber; +}; + +struct DebugVarInfo { + std::string Name; + int TypeIndex; + bool IsParam; + std::vector Ranges; + + DebugVarInfo() {} + DebugVarInfo(char *ArgName, int ArgTypeIndex, bool ArgIsParam) + : Name(ArgName), TypeIndex(ArgTypeIndex), IsParam(ArgIsParam) {} +}; + +struct DebugEHClauseInfo { + unsigned TryOffset; + unsigned TryLength; + unsigned HandlerOffset; + unsigned HandlerLength; + + DebugEHClauseInfo(unsigned TryOffset, unsigned TryLength, + unsigned HandlerOffset, unsigned HandlerLength) : + TryOffset(TryOffset), TryLength(TryLength), + HandlerOffset(HandlerOffset), HandlerLength(HandlerLength) {} +}; + +#endif // JIT_DEBUG_INFO_H diff --git a/llvm/tools/objwriter/objwriter.cpp b/llvm/tools/objwriter/objwriter.cpp new file mode 100644 index 0000000000000..bc22a28055c70 --- /dev/null +++ b/llvm/tools/objwriter/objwriter.cpp @@ -0,0 +1,1211 @@ +//===---- objwriter.cpp -----------------------------------------*- C++ -*-===// +// +// object writer +// +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// \brief Implementation of object writer API for JIT/AOT +/// +//===----------------------------------------------------------------------===// + +#include "objwriter.h" +#include "debugInfo/dwarf/dwarfTypeBuilder.h" +#include "debugInfo/codeView/codeViewTypeBuilder.h" +#include "cvconst.h" +#include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/DebugInfo/CodeView/Line.h" +#include "llvm/DebugInfo/CodeView/SymbolRecord.h" +#include "llvm/MC/MCAsmBackend.h" +#include "llvm/MC/MCAsmInfo.h" +#include "llvm/MC/MCContext.h" +#include "llvm/MC/MCCodeEmitter.h" +#include "llvm/MC/MCDwarf.h" +#include "llvm/MC/MCInstPrinter.h" +#include "llvm/MC/MCInstrInfo.h" +#include "llvm/MC/MCParser/AsmLexer.h" +#include "llvm/MC/MCParser/MCTargetAsmParser.h" +#include "llvm/MC/MCRegisterInfo.h" +#include "llvm/MC/MCSectionCOFF.h" +#include "llvm/MC/MCSectionELF.h" +#include "llvm/MC/MCSectionMachO.h" +#include "llvm/MC/MCObjectStreamer.h" +#include "llvm/MC/MCObjectWriter.h" +#include "llvm/MC/MCSubtargetInfo.h" +#include "llvm/MC/MCTargetOptionsCommandFlags.h" +#include "llvm/MC/MCELFStreamer.h" +#include "llvm/MC/TargetRegistry.h" +#include "llvm/BinaryFormat/COFF.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Compression.h" +#include "llvm/BinaryFormat/ELF.h" +#include "llvm/Support/FileUtilities.h" +#include "llvm/Support/FormattedStream.h" +#include "llvm/Support/Host.h" +#include "llvm/Support/ManagedStatic.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/PrettyStackTrace.h" +#include "llvm/Support/SourceMgr.h" +#include "llvm/Support/TargetSelect.h" +#include "llvm/Support/ToolOutputFile.h" +#include "llvm/Support/Win64EH.h" +#include "llvm/Target/TargetMachine.h" +#include "../../lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.h" + +using namespace llvm; +using namespace llvm::codeview; + +bool error(const Twine &Error) { + errs() << Twine("error: ") + Error + "\n"; + return false; +} + +void ObjectWriter::InitTripleName(const char* tripleName) { + TripleName = tripleName != nullptr ? tripleName : sys::getDefaultTargetTriple(); +} + +bool ObjectWriter::Init(llvm::StringRef ObjectFilePath, const char* tripleName) { + llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. + + // Initialize targets + InitializeAllTargetInfos(); + InitializeAllTargetMCs(); + + InitTripleName(tripleName); + Triple TheTriple(TripleName); + + // Get the target specific parser. + std::string TargetError; + const Target *TheTarget = + TargetRegistry::lookupTarget(TripleName, TargetError); + if (!TheTarget) { + return error("Unable to create target for " + ObjectFilePath + ": " + + TargetError); + } + + std::error_code EC; + OS.reset(new raw_fd_ostream(ObjectFilePath, EC, sys::fs::OF_None)); + if (EC) + return error("Unable to create file for " + ObjectFilePath + ": " + + EC.message()); + + RegisterInfo.reset(TheTarget->createMCRegInfo(TripleName)); + if (!RegisterInfo) + return error("Unable to create target register info!"); + + AsmInfo.reset(TheTarget->createMCAsmInfo(*RegisterInfo, TripleName, TargetMOptions)); + if (!AsmInfo) + return error("Unable to create target asm info!"); + + InstrInfo.reset(TheTarget->createMCInstrInfo()); + if (!InstrInfo) + return error("no instr info info for target " + TripleName); + + std::string FeaturesStr; + std::string MCPU; + SubtargetInfo.reset( + TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr)); + if (!SubtargetInfo) + return error("no subtarget info for target " + TripleName); + + OutContext.reset( + new MCContext(TheTriple, AsmInfo.get(), RegisterInfo.get(), SubtargetInfo.get())); + ObjFileInfo.reset(TheTarget->createMCObjectFileInfo(*OutContext, false)); + OutContext->setObjectFileInfo(ObjFileInfo.get()); + + CodeEmitter = + TheTarget->createMCCodeEmitter(*InstrInfo, *RegisterInfo, *OutContext); + if (!CodeEmitter) + return error("no code emitter for target " + TripleName); + + AsmBackend = TheTarget->createMCAsmBackend(*SubtargetInfo, *RegisterInfo, TargetMOptions); + if (!AsmBackend) + return error("no asm backend for target " + TripleName); + + Streamer = (MCObjectStreamer *)TheTarget->createMCObjectStreamer( + TheTriple, *OutContext, std::unique_ptr(AsmBackend), AsmBackend->createObjectWriter(*OS), + std::unique_ptr(CodeEmitter), *SubtargetInfo, + /*RelaxAll*/ true, + /*IncrementalLinkerCompatible*/ false, + /*DWARFMustBeAtTheEnd*/ false); + if (!Streamer) + return error("no object streamer for target " + TripleName); + Streamer->initSections(/* NoExecStack */ true, *SubtargetInfo); + Assembler = &Streamer->getAssembler(); + + FrameOpened = false; + FuncId = 1; + + if (OutContext->getObjectFileType() == MCContext::IsCOFF) { + TypeBuilder.reset(new UserDefinedCodeViewTypesBuilder()); + } else { + TypeBuilder.reset(new UserDefinedDwarfTypesBuilder()); + } + + TypeBuilder->SetStreamer(Streamer); + unsigned TargetPointerSize = Streamer->getContext().getAsmInfo()->getCodePointerSize(); + TypeBuilder->SetTargetPointerSize(TargetPointerSize); + + DwarfGenerator.reset(new DwarfGen()); + DwarfGenerator->SetTypeBuilder(static_cast(TypeBuilder.get())); + + CFIsPerOffset.truncate(0); + + return true; +} + +void ObjectWriter::Finish() { + + if (OutContext->getObjectFileType() == MCContext::IsCOFF + && AddressTakenFunctions.size() > 0) { + + // Emit all address-taken functions into the GFIDs section + // to support control flow guard. + Streamer->SwitchSection(ObjFileInfo->getGFIDsSection()); + for (const MCSymbol* S : AddressTakenFunctions) { + Streamer->EmitCOFFSymbolIndex(S); + } + + // Emit the feat.00 symbol that controls various linker behaviors + MCSymbol* S = OutContext->getOrCreateSymbol(StringRef("@feat.00")); + Streamer->BeginCOFFSymbolDef(S); + Streamer->EmitCOFFSymbolStorageClass(COFF::IMAGE_SYM_CLASS_STATIC); + Streamer->EmitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_NULL); + Streamer->EndCOFFSymbolDef(); + int64_t Feat00Flags = 0; + + Feat00Flags |= 0x800; // cfGuardCF flags this object as control flow guard aware + + Streamer->emitSymbolAttribute(S, MCSA_Global); + Streamer->emitAssignment( + S, MCConstantExpr::create(Feat00Flags, *OutContext)); + } + + Streamer->Finish(); +} + +void ObjectWriter::SetDwarfVersion(uint16_t v) { + Streamer->getContext().setDwarfVersion(v); +} + +void ObjectWriter::SwitchSection(const char *SectionName, + CustomSectionAttributes attributes, + const char *ComdatName) { + MCSection *Section = GetSection(SectionName, attributes, ComdatName); + Streamer->SwitchSection(Section); + if (Sections.count(Section) == 0) { + Sections.insert(Section); + if (OutContext->getObjectFileType() == MCContext::IsMachO) { + assert(!Section->getBeginSymbol()); + // Output a DWARF linker-local symbol. + // This symbol is used as a base for other symbols in a section. + MCSymbol *SectionStartSym = OutContext->createLinkerPrivateTempSymbol(); + Streamer->emitLabel(SectionStartSym); + Section->setBeginSymbol(SectionStartSym); + } + } +} + +MCSection *ObjectWriter::GetSection(const char *SectionName, + CustomSectionAttributes attributes, + const char *ComdatName) { + MCSection *Section = nullptr; + + if (strcmp(SectionName, "text") == 0) { + Section = ObjFileInfo->getTextSection(); + } else if (strcmp(SectionName, "data") == 0) { + Section = ObjFileInfo->getDataSection(); + } else if (strcmp(SectionName, "rdata") == 0) { + Section = ObjFileInfo->getReadOnlySection(); + } else if (strcmp(SectionName, "xdata") == 0) { + Section = ObjFileInfo->getXDataSection(); + } else if (strcmp(SectionName, "bss") == 0) { + if (OutContext->getObjectFileType() == MCContext::IsMachO) { + Section = ObjFileInfo->getDataBSSSection(); + } else { + Section = ObjFileInfo->getBSSSection(); + } + } else { + Section = GetSpecificSection(SectionName, attributes, ComdatName); + } + assert(Section); + return Section; +} + +MCSection *ObjectWriter::GetSpecificSection(const char *SectionName, + CustomSectionAttributes attributes, + const char *ComdatName) { + Triple TheTriple(TripleName); + MCSection *Section = nullptr; + SectionKind Kind; + if (attributes & CustomSectionAttributes_Executable) + Kind = SectionKind::getText(); + else if (attributes & CustomSectionAttributes_Uninitialized) + Kind = SectionKind::getBSS(); + else if (attributes & CustomSectionAttributes_Writeable) + Kind = SectionKind::getData(); + else + Kind = SectionKind::getReadOnly(); + + switch (TheTriple.getObjectFormat()) { + case Triple::MachO: { + unsigned typeAndAttributes = 0; + if (attributes & CustomSectionAttributes_MachO_Init_Func_Pointers) { + typeAndAttributes |= MachO::SectionType::S_MOD_INIT_FUNC_POINTERS; + } + if (attributes & CustomSectionAttributes_Executable) { + // Needs to be set on sections with actual code. The linker uses + // it to determine code sections and emit information about function + // boundaries. + typeAndAttributes |= MachO::S_ATTR_PURE_INSTRUCTIONS; + } + if (attributes & CustomSectionAttributes_Uninitialized) { + typeAndAttributes |= MachO::S_ZEROFILL; + } + Section = OutContext->getMachOSection( + (attributes & CustomSectionAttributes_Executable) ? "__TEXT" : "__DATA", + SectionName, typeAndAttributes, Kind); + break; + } + case Triple::COFF: { + unsigned Characteristics = COFF::IMAGE_SCN_MEM_READ; + + if (attributes & CustomSectionAttributes_Executable) { + Characteristics |= COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE; + } else if (attributes & CustomSectionAttributes_Writeable) { + Characteristics |= COFF::IMAGE_SCN_MEM_WRITE; + if (attributes & CustomSectionAttributes_Uninitialized) + Characteristics |= COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA; + else + Characteristics |= COFF::IMAGE_SCN_CNT_INITIALIZED_DATA; + } else { + Characteristics |= COFF::IMAGE_SCN_CNT_INITIALIZED_DATA; + } + + if (ComdatName != nullptr) { + Section = OutContext->getCOFFSection( + SectionName, Characteristics | COFF::IMAGE_SCN_LNK_COMDAT, Kind, + ComdatName, COFF::COMDATType::IMAGE_COMDAT_SELECT_ANY); + } else { + Section = OutContext->getCOFFSection(SectionName, Characteristics, Kind); + } + break; + } + case Triple::ELF: { + unsigned Flags = ELF::SHF_ALLOC; + if (ComdatName != nullptr) { + MCSymbolELF *GroupSym = + cast(OutContext->getOrCreateSymbol(ComdatName)); + OutContext->createELFGroupSection(GroupSym, true); + Flags |= ELF::SHF_GROUP; + } + if (attributes & CustomSectionAttributes_Executable) { + Flags |= ELF::SHF_EXECINSTR; + } else if (attributes & CustomSectionAttributes_Writeable) { + Flags |= ELF::SHF_WRITE; + } + unsigned SectionType = (attributes & CustomSectionAttributes_Uninitialized) + ? ELF::SHT_NOBITS + : ELF::SHT_PROGBITS; + Section = + OutContext->getELFSection(SectionName, SectionType, Flags, 0, + ComdatName != nullptr ? ComdatName : "", + ComdatName != nullptr); + break; + } + default: + error("Unknown output format for target " + TripleName); + break; + } + return Section; +} + +void ObjectWriter::SetCodeSectionAttribute(const char *SectionName, + CustomSectionAttributes attributes, + const char *ComdatName) { + MCSection *Section = GetSection(SectionName, attributes, ComdatName); + + assert(!Section->hasInstructions()); + Section->setHasInstructions(true); + if (OutContext->getObjectFileType() != MCContext::IsCOFF) { + OutContext->addGenDwarfSection(Section); + } +} + +void ObjectWriter::EmitAlignment(int ByteAlignment) { + int64_t fillValue = 0; + + if (Streamer->getCurrentSectionOnly()->getKind().isText()) { + if (OutContext->getTargetTriple().getArch() == llvm::Triple::ArchType::x86 || + OutContext->getTargetTriple().getArch() == llvm::Triple::ArchType::x86_64) { + fillValue = 0x90; // x86 nop + } + } + + Streamer->emitValueToAlignment(ByteAlignment, fillValue); +} + +void ObjectWriter::EmitBlob(int BlobSize, const char *Blob) { + if (Streamer->getCurrentSectionOnly()->getKind().isText()) { + Streamer->emitInstructionBytes(StringRef(Blob, BlobSize)); + } else { + Streamer->emitBytes(StringRef(Blob, BlobSize)); + } +} + +void ObjectWriter::EmitIntValue(uint64_t Value, unsigned Size) { + Streamer->emitIntValue(Value, Size); +} + +void ObjectWriter::EmitSymbolDef(const char *SymbolName, bool global) { + MCSymbol *Sym = OutContext->getOrCreateSymbol(Twine(SymbolName)); + + Streamer->emitSymbolAttribute(Sym, MCSA_Global); + + Triple TheTriple = OutContext->getTargetTriple(); + + if (TheTriple.getObjectFormat() == Triple::ELF) { + // An ARM function symbol should be marked with an appropriate ELF attribute + // to make later computation of a relocation address value correct + if (Streamer->getCurrentSectionOnly()->getKind().isText()) { + switch (TheTriple.getArch()) { + case Triple::arm: + case Triple::armeb: + case Triple::thumb: + case Triple::thumbeb: + case Triple::aarch64: + case Triple::aarch64_be: + Streamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeFunction); + break; + default: + break; + } + } + + // Mark the symbol hidden if requested + if (!global) { + Streamer->emitSymbolAttribute(Sym, MCSA_Hidden); + } + } + + Streamer->emitLabel(Sym); +} + +const MCSymbolRefExpr * +ObjectWriter::GetSymbolRefExpr(const char *SymbolName, + MCSymbolRefExpr::VariantKind Kind) { + // Create symbol reference + MCSymbol *T = OutContext->getOrCreateSymbol(SymbolName); + Assembler->registerSymbol(*T); + return MCSymbolRefExpr::create(T, Kind, *OutContext); +} + +unsigned ObjectWriter::GetDFSize() { + return Streamer->getOrCreateDataFragment()->getContents().size(); +} + +void ObjectWriter::EmitRelocDirective(const int Offset, StringRef Name, const MCExpr *Expr) { + const MCExpr *OffsetExpr = MCConstantExpr::create(Offset, *OutContext); + Optional> result = Streamer->emitRelocDirective(*OffsetExpr, Name, Expr, SMLoc(), *SubtargetInfo); + assert(!result.hasValue()); +} + +const MCExpr *ObjectWriter::GenTargetExpr(const MCSymbol* Symbol, MCSymbolRefExpr::VariantKind Kind, + int Delta, bool IsPCRel, int Size) { + const MCExpr *TargetExpr = MCSymbolRefExpr::create(Symbol, Kind, *OutContext); + if (IsPCRel && Size != 0) { + // If the fixup is pc-relative, we need to bias the value to be relative to + // the start of the field, not the end of the field + TargetExpr = MCBinaryExpr::createSub( + TargetExpr, MCConstantExpr::create(Size, *OutContext), *OutContext); + } + if (Delta != 0) { + TargetExpr = MCBinaryExpr::createAdd( + TargetExpr, MCConstantExpr::create(Delta, *OutContext), *OutContext); + } + return TargetExpr; +} + +int ObjectWriter::EmitSymbolRef(const char *SymbolName, + RelocType RelocationType, int Delta, SymbolRefFlags Flags) { + bool IsPCRel = false; + int Size = 0; + MCSymbolRefExpr::VariantKind Kind = MCSymbolRefExpr::VK_None; + + MCSymbol* Symbol = OutContext->getOrCreateSymbol(SymbolName); + Assembler->registerSymbol(*Symbol); + + if ((int)Flags & (int)SymbolRefFlags::SymbolRefFlags_AddressTakenFunction) { + AddressTakenFunctions.insert(Symbol); + } + + // Convert RelocationType to MCSymbolRefExpr + switch (RelocationType) { + case RelocType::IMAGE_REL_BASED_ABSOLUTE: + assert(OutContext->getObjectFileType() == MCContext::IsCOFF); + Kind = MCSymbolRefExpr::VK_COFF_IMGREL32; + Size = 4; + break; + case RelocType::IMAGE_REL_BASED_HIGHLOW: + Size = 4; + break; + case RelocType::IMAGE_REL_BASED_DIR64: + Size = 8; + break; + case RelocType::IMAGE_REL_BASED_REL32: + if (OutContext->getObjectFileType() == MCContext::IsMachO && + OutContext->getTargetTriple().getArch() == Triple::aarch64) { + MCSymbol *TempSymbol = OutContext->createTempSymbol(); + Streamer->emitLabel(TempSymbol); + const MCExpr *TargetExpr = MCSymbolRefExpr::create(Symbol, Kind, *OutContext); + const MCSymbolRefExpr *SectionExpr = MCSymbolRefExpr::create(TempSymbol, Kind, *OutContext); + TargetExpr = MCBinaryExpr::createSub( + TargetExpr, SectionExpr, *OutContext); + // If the fixup is pc-relative, we need to bias the value to be relative to + // the start of the field, not the end of the field + TargetExpr = MCBinaryExpr::createSub( + TargetExpr, MCConstantExpr::create(4, *OutContext), *OutContext); + if (Delta != 0) { + TargetExpr = MCBinaryExpr::createAdd( + TargetExpr, MCConstantExpr::create(Delta, *OutContext), *OutContext); + } + Streamer->emitValueImpl(TargetExpr, 4, SMLoc(), false); + return 4; + } + Size = 4; + IsPCRel = true; + if (OutContext->getObjectFileType() == MCContext::IsELF) { + // PLT is valid only for code symbols, + // but there shouldn't be references to global data symbols + Kind = MCSymbolRefExpr::VK_PLT; + } + break; + case RelocType::IMAGE_REL_BASED_RELPTR32: + if (OutContext->getObjectFileType() == MCContext::IsMachO && + OutContext->getTargetTriple().getArch() == Triple::aarch64) { + MCSymbol *TempSymbol = OutContext->createTempSymbol(); + Streamer->emitLabel(TempSymbol); + const MCExpr *TargetExpr = MCSymbolRefExpr::create(Symbol, Kind, *OutContext); + const MCSymbolRefExpr *SectionExpr = MCSymbolRefExpr::create(TempSymbol, Kind, *OutContext); + TargetExpr = MCBinaryExpr::createSub( + TargetExpr, SectionExpr, *OutContext); + if (Delta != 0) { + TargetExpr = MCBinaryExpr::createAdd( + TargetExpr, MCConstantExpr::create(Delta, *OutContext), *OutContext); + } + Streamer->emitValueImpl(TargetExpr, 4, SMLoc(), false); + return 4; + } + Size = 4; + IsPCRel = true; + Delta += 4; + break; + case RelocType::IMAGE_REL_BASED_THUMB_MOV32: { + const unsigned Offset = GetDFSize(); + const MCExpr *TargetExpr = GenTargetExpr(Symbol, Kind, Delta); + EmitRelocDirective(Offset, "R_ARM_THM_MOVW_ABS_NC", TargetExpr); + EmitRelocDirective(Offset + 4, "R_ARM_THM_MOVT_ABS", TargetExpr); + return 8; + } + case RelocType::IMAGE_REL_BASED_THUMB_BRANCH24: { + const MCExpr *TargetExpr = GenTargetExpr(Symbol, Kind, Delta); + EmitRelocDirective(GetDFSize(), "R_ARM_THM_CALL", TargetExpr); + return 4; + } + case RelocType::IMAGE_REL_BASED_ARM64_BRANCH26: { + const MCExpr *TargetExpr = GenTargetExpr(Symbol, Kind, Delta); + EmitRelocDirective(GetDFSize(), "R_AARCH64_CALL26", TargetExpr); + return 4; + } + case RelocType::IMAGE_REL_BASED_ARM64_PAGEBASE_REL21: { + if (OutContext->getObjectFileType() == MCContext::IsMachO) { + Kind = MCSymbolRefExpr::VK_PAGE; + } + const MCExpr *TargetExpr = GenTargetExpr(Symbol, Kind, Delta); + TargetExpr = + AArch64MCExpr::create(TargetExpr, AArch64MCExpr::VK_CALL, *OutContext); + EmitRelocDirective(GetDFSize(), "R_AARCH64_ADR_PREL_PG_HI21", TargetExpr); + return 4; + } + case RelocType::IMAGE_REL_BASED_ARM64_PAGEOFFSET_12A: { + if (OutContext->getObjectFileType() == MCContext::IsMachO) { + Kind = MCSymbolRefExpr::VK_PAGEOFF; + } + const MCExpr *TargetExpr = GenTargetExpr(Symbol, Kind, Delta); + TargetExpr = + AArch64MCExpr::create(TargetExpr, AArch64MCExpr::VK_LO12, *OutContext); + EmitRelocDirective(GetDFSize(), "R_AARCH64_ADD_ABS_LO12_NC", TargetExpr); + return 4; + } + } + + const MCExpr *TargetExpr = GenTargetExpr(Symbol, Kind, Delta, IsPCRel, Size); + Streamer->emitValueImpl(TargetExpr, Size, SMLoc(), IsPCRel); + return Size; +} + +void ObjectWriter::EmitWinFrameInfo(const char *FunctionName, int StartOffset, + int EndOffset, const char *BlobSymbolName) { + assert(OutContext->getObjectFileType() == MCContext::IsCOFF); + + // .pdata emission + MCSection *Section = ObjFileInfo->getPDataSection(); + + // If the function was emitted to a Comdat section, create an associative + // section to place the frame info in. This is due to the Windows linker + // requirement that a function and its unwind info come from the same + // object file. + MCSymbol *Fn = OutContext->getOrCreateSymbol(Twine(FunctionName)); + const MCSectionCOFF *FunctionSection = cast(&Fn->getSection()); + if (FunctionSection->getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) { + Section = OutContext->getAssociativeCOFFSection( + cast(Section), FunctionSection->getCOMDATSymbol()); + } + + Streamer->SwitchSection(Section); + Streamer->emitValueToAlignment(4); + + const MCExpr *BaseRefRel = + GetSymbolRefExpr(FunctionName, MCSymbolRefExpr::VK_COFF_IMGREL32); + + Triple::ArchType Arch = OutContext->getTargetTriple().getArch(); + + if (Arch == Triple::thumb || Arch == Triple::thumbeb) { + StartOffset |= 1; + } + + // start Offset + const MCExpr *StartOfs = MCConstantExpr::create(StartOffset, *OutContext); + Streamer->emitValue( + MCBinaryExpr::createAdd(BaseRefRel, StartOfs, *OutContext), 4); + + if (Arch == Triple::x86 || Arch == Triple::x86_64) { + // end Offset + const MCExpr *EndOfs = MCConstantExpr::create(EndOffset, *OutContext); + Streamer->emitValue( + MCBinaryExpr::createAdd(BaseRefRel, EndOfs, *OutContext), 4); + } + + // frame symbol reference + Streamer->emitValue( + GetSymbolRefExpr(BlobSymbolName, MCSymbolRefExpr::VK_COFF_IMGREL32), 4); +} + +void ObjectWriter::EmitCFIStart(int Offset) { + assert(!FrameOpened && "frame should be closed before CFIStart"); + Streamer->emitCFIStartProc(false); + FrameOpened = true; + FrameHasCompactEncoding = false; +} + +void ObjectWriter::EmitCFIEnd(int Offset) { + assert(FrameOpened && "frame should be opened before CFIEnd"); + + // If compact unwinding was not set through EmitCFICompactUnwindEncoding + // force compact unwinding to use DWARF references which allow unwinding + // prologs and epilogs correctly. + if (!FrameHasCompactEncoding) { + Streamer->emitCFICompactUnwindEncoding(ObjFileInfo->getCompactUnwindDwarfEHFrameOnly()); + } + + Streamer->emitCFIEndProc(); + FrameOpened = false; +} + +void ObjectWriter::EmitCFILsda(const char *LsdaBlobSymbolName) { + assert(FrameOpened && "frame should be opened before CFILsda"); + + // Create symbol reference + MCSymbol *T = OutContext->getOrCreateSymbol(LsdaBlobSymbolName); + Assembler->registerSymbol(*T); + if (OutContext->getObjectFileType() == MCContext::IsMachO) { + Streamer->emitCFILsda(T, llvm::dwarf::Constants::DW_EH_PE_pcrel); + } else { + Streamer->emitCFILsda(T, llvm::dwarf::Constants::DW_EH_PE_pcrel | + llvm::dwarf::Constants::DW_EH_PE_sdata4); + } +} + +void ObjectWriter::EmitCFICode(int Offset, const char *Blob) { + assert(FrameOpened && "frame should be opened before CFICode"); + + const CFI_CODE *CfiCode = (const CFI_CODE *)Blob; + switch (CfiCode->CfiOpCode) { + case CFI_ADJUST_CFA_OFFSET: + assert(CfiCode->DwarfReg == DWARF_REG_ILLEGAL && + "Unexpected Register Value for OpAdjustCfaOffset"); + Streamer->emitCFIAdjustCfaOffset(CfiCode->Offset); + break; + case CFI_REL_OFFSET: + Streamer->emitCFIRelOffset(CfiCode->DwarfReg, CfiCode->Offset); + break; + case CFI_DEF_CFA_REGISTER: + assert(CfiCode->Offset == 0 && + "Unexpected Offset Value for OpDefCfaRegister"); + Streamer->emitCFIDefCfaRegister(CfiCode->DwarfReg); + break; + case CFI_DEF_CFA: + assert(CfiCode->Offset != 0 && + "Unexpected Offset Value for OpDefCfa"); + Streamer->emitCFIDefCfa(CfiCode->DwarfReg, CfiCode->Offset); + break; + default: + assert(false && "Unrecognized CFI"); + break; + } +} + +void ObjectWriter::EmitCFICompactUnwindEncoding(unsigned int Encoding) +{ + // Emits architecture specific compact unwinding encoding for MachO + // files on Apple platforms. Currently that's the only platform where + // compact unwinding tables are used. + // + // If EmitCFICompactUnwindEncoding is never called then EmitCFIEnd + // will cause compact unwinding to reference DWARF CFI info. It + // essentially turns the compact unwinding tables into an index for + // the DWARF CFI data, much like .eh_frame_hdr works in ELF files. + // + // If Encoding is set to zero it instructs LLVM to infer the compact + // unwinding encoding from the DWARF CFI data. + // + // Any non-zero value in Encoding is emitted directly into the + // __compact_unwind section and then processed by the linker. + // + // See generateCompactUnwindEncoding in AArch64AsmBackend.cpp and + // X86AsmBackend.cpp for specific encodings for a given architecture. + FrameHasCompactEncoding = true; + Streamer->emitCFICompactUnwindEncoding(Encoding); +} + +void ObjectWriter::EmitLabelDiff(const MCSymbol *From, const MCSymbol *To, + unsigned int Size) { + MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None; + const MCExpr *FromRef = MCSymbolRefExpr::create(From, Variant, *OutContext), + *ToRef = MCSymbolRefExpr::create(To, Variant, *OutContext); + const MCExpr *AddrDelta = + MCBinaryExpr::create(MCBinaryExpr::Sub, ToRef, FromRef, *OutContext); + Streamer->emitValue(AddrDelta, Size); +} + +void ObjectWriter::EmitSymRecord(int Size, SymbolRecordKind SymbolKind) { + RecordPrefix Rec; + Rec.RecordLen = ulittle16_t(Size + sizeof(ulittle16_t)); + Rec.RecordKind = ulittle16_t((uint16_t)SymbolKind); + Streamer->emitBytes(StringRef((char *)&Rec, sizeof(Rec))); +} + +void ObjectWriter::EmitCOFFSecRel32Value(MCExpr const *Value) { + MCDataFragment *DF = Streamer->getOrCreateDataFragment(); + MCFixup Fixup = MCFixup::create(DF->getContents().size(), Value, FK_SecRel_4); + DF->getFixups().push_back(Fixup); + DF->getContents().resize(DF->getContents().size() + 4, 0); +} + +void ObjectWriter::EmitVarDefRange(const MCSymbol *Fn, + const LocalVariableAddrRange &Range) { + const MCSymbolRefExpr *BaseSym = MCSymbolRefExpr::create(Fn, *OutContext); + const MCExpr *Offset = MCConstantExpr::create(Range.OffsetStart, *OutContext); + const MCExpr *Expr = MCBinaryExpr::createAdd(BaseSym, Offset, *OutContext); + EmitCOFFSecRel32Value(Expr); + Streamer->EmitCOFFSectionIndex(Fn); + Streamer->emitIntValue(Range.Range, 2); +} + +// Maps an ICorDebugInfo register number to the corresponding CodeView +// register number +CVRegNum ObjectWriter::GetCVRegNum(unsigned RegNum) { + static const CVRegNum CVRegMapAmd64[] = { + CV_AMD64_RAX, CV_AMD64_RCX, CV_AMD64_RDX, CV_AMD64_RBX, + CV_AMD64_RSP, CV_AMD64_RBP, CV_AMD64_RSI, CV_AMD64_RDI, + CV_AMD64_R8, CV_AMD64_R9, CV_AMD64_R10, CV_AMD64_R11, + CV_AMD64_R12, CV_AMD64_R13, CV_AMD64_R14, CV_AMD64_R15, + }; + + switch (OutContext->getTargetTriple().getArch()) { + case Triple::x86: + if (X86::ICorDebugInfo::REGNUM_EAX <= RegNum && + RegNum <= X86::ICorDebugInfo::REGNUM_EDI) { + return RegNum - X86::ICorDebugInfo::REGNUM_EAX + CV_REG_EAX; + } + break; + case Triple::x86_64: + if (RegNum < sizeof(CVRegMapAmd64) / sizeof(CVRegMapAmd64[0])) { + return CVRegMapAmd64[RegNum]; + } + break; + case Triple::arm: + case Triple::armeb: + case Triple::thumb: + case Triple::thumbeb: + if (Arm::ICorDebugInfo::REGNUM_R0 <= RegNum && + RegNum <= Arm::ICorDebugInfo::REGNUM_PC) { + return RegNum - Arm::ICorDebugInfo::REGNUM_R0 + CV_ARM_R0; + } + break; + case Triple::aarch64: + case Triple::aarch64_be: + if (Arm64::ICorDebugInfo::REGNUM_X0 <= RegNum && + RegNum < Arm64::ICorDebugInfo::REGNUM_PC) { + return RegNum - Arm64::ICorDebugInfo::REGNUM_X0 + CV_ARM64_X0; + } + // Special registers are ordered FP, LR, SP, PC in ICorDebugInfo's + // enumeration and FP, LR, SP, *ZR*, PC in CodeView's enumeration. + // For that reason handle the PC register separately. + if (RegNum == Arm64::ICorDebugInfo::REGNUM_PC) { + return CV_ARM64_PC; + } + break; + default: + assert(false && "Unexpected architecture"); + break; + } + return CV_REG_NONE; +} + +void ObjectWriter::EmitCVDebugVarInfo(const MCSymbol *Fn, + const DebugVarInfo LocInfos[], + int NumVarInfos) { + for (int I = 0; I < NumVarInfos; I++) { + // Emit an S_LOCAL record + DebugVarInfo Var = LocInfos[I]; + TypeIndex Type = TypeIndex(Var.TypeIndex); + LocalSymFlags Flags = LocalSymFlags::None; + unsigned SizeofSym = sizeof(Type) + sizeof(Flags); + unsigned NameLength = Var.Name.length() + 1; + EmitSymRecord(SizeofSym + NameLength, SymbolRecordKind::LocalSym); + if (Var.IsParam) { + Flags |= LocalSymFlags::IsParameter; + } + Streamer->emitBytes(StringRef((char *)&Type, sizeof(Type))); + Streamer->emitIntValue(static_cast(Flags), sizeof(Flags)); + Streamer->emitBytes(StringRef(Var.Name.c_str(), NameLength)); + + for (const auto &Range : Var.Ranges) { + // Emit a range record + switch (Range.loc.vlType) { + case ICorDebugInfo::VLT_REG: + case ICorDebugInfo::VLT_REG_FP: { + + // Currently only support integer registers. + // TODO: support xmm registers + CVRegNum CVReg = GetCVRegNum(Range.loc.vlReg.vlrReg); + if (CVReg == CV_REG_NONE) { + break; + } + SymbolRecordKind SymbolKind = SymbolRecordKind::DefRangeRegisterSym; + unsigned SizeofDefRangeRegisterSym = sizeof(DefRangeRegisterSym::Hdr) + + sizeof(DefRangeRegisterSym::Range); + EmitSymRecord(SizeofDefRangeRegisterSym, SymbolKind); + + DefRangeRegisterSym DefRangeRegisterSymbol(SymbolKind); + DefRangeRegisterSymbol.Range.OffsetStart = Range.startOffset; + DefRangeRegisterSymbol.Range.Range = + Range.endOffset - Range.startOffset; + DefRangeRegisterSymbol.Range.ISectStart = 0; + DefRangeRegisterSymbol.Hdr.Register = CVReg; + DefRangeRegisterSymbol.Hdr.MayHaveNoName = 0; + + unsigned Length = sizeof(DefRangeRegisterSymbol.Hdr); + Streamer->emitBytes( + StringRef((char *)&DefRangeRegisterSymbol.Hdr, Length)); + EmitVarDefRange(Fn, DefRangeRegisterSymbol.Range); + break; + } + + case ICorDebugInfo::VLT_STK: { + + // TODO: support REGNUM_AMBIENT_SP + CVRegNum CVReg = GetCVRegNum(Range.loc.vlStk.vlsBaseReg); + if (CVReg == CV_REG_NONE) { + break; + } + + SymbolRecordKind SymbolKind = SymbolRecordKind::DefRangeRegisterRelSym; + unsigned SizeofDefRangeRegisterRelSym = + sizeof(DefRangeRegisterRelSym::Hdr) + + sizeof(DefRangeRegisterRelSym::Range); + EmitSymRecord(SizeofDefRangeRegisterRelSym, SymbolKind); + + DefRangeRegisterRelSym DefRangeRegisterRelSymbol(SymbolKind); + DefRangeRegisterRelSymbol.Range.OffsetStart = Range.startOffset; + DefRangeRegisterRelSymbol.Range.Range = + Range.endOffset - Range.startOffset; + DefRangeRegisterRelSymbol.Range.ISectStart = 0; + DefRangeRegisterRelSymbol.Hdr.Register = CVReg; + DefRangeRegisterRelSymbol.Hdr.Flags = 0; + DefRangeRegisterRelSymbol.Hdr.BasePointerOffset = + Range.loc.vlStk.vlsOffset; + + unsigned Length = sizeof(DefRangeRegisterRelSymbol.Hdr); + Streamer->emitBytes( + StringRef((char *)&DefRangeRegisterRelSymbol.Hdr, Length)); + EmitVarDefRange(Fn, DefRangeRegisterRelSymbol.Range); + break; + } + + case ICorDebugInfo::VLT_REG_BYREF: + case ICorDebugInfo::VLT_STK_BYREF: + case ICorDebugInfo::VLT_REG_REG: + case ICorDebugInfo::VLT_REG_STK: + case ICorDebugInfo::VLT_STK_REG: + case ICorDebugInfo::VLT_STK2: + case ICorDebugInfo::VLT_FPSTK: + case ICorDebugInfo::VLT_FIXED_VA: + // TODO: for optimized debugging + break; + + default: + assert(false && "Unknown varloc type!"); + break; + } + } + } +} + +void ObjectWriter::EmitCVDebugFunctionInfo(const char *FunctionName, + int FunctionSize) { + assert(OutContext->getObjectFileType() == MCContext::IsCOFF); + + // Mark the end of function. + MCSymbol *FnEnd = OutContext->createTempSymbol(); + Streamer->emitLabel(FnEnd); + + MCSection *Section = ObjFileInfo->getCOFFDebugSymbolsSection(); + Streamer->SwitchSection(Section); + // Emit debug section magic before the first entry. + if (FuncId == 1) { + Streamer->emitIntValue(COFF::DEBUG_SECTION_MAGIC, 4); + } + MCSymbol *Fn = OutContext->getOrCreateSymbol(Twine(FunctionName)); + + // Emit a symbol subsection, required by VS2012+ to find function boundaries. + MCSymbol *SymbolsBegin = OutContext->createTempSymbol(), + *SymbolsEnd = OutContext->createTempSymbol(); + Streamer->emitIntValue(unsigned(DebugSubsectionKind::Symbols), 4); + EmitLabelDiff(SymbolsBegin, SymbolsEnd); + Streamer->emitLabel(SymbolsBegin); + { + ProcSym ProcSymbol(SymbolRecordKind::GlobalProcIdSym); + ProcSymbol.CodeSize = FunctionSize; + ProcSymbol.DbgEnd = FunctionSize; + + unsigned FunctionNameLength = strlen(FunctionName) + 1; + unsigned HeaderSize = + sizeof(ProcSymbol.Parent) + sizeof(ProcSymbol.End) + + sizeof(ProcSymbol.Next) + sizeof(ProcSymbol.CodeSize) + + sizeof(ProcSymbol.DbgStart) + sizeof(ProcSymbol.DbgEnd) + + sizeof(ProcSymbol.FunctionType); + unsigned SymbolSize = HeaderSize + 4 + 2 + 1 + FunctionNameLength; + EmitSymRecord(SymbolSize, SymbolRecordKind::GlobalProcIdSym); + + Streamer->emitBytes(StringRef((char *)&ProcSymbol.Parent, HeaderSize)); + // Emit relocation + Streamer->EmitCOFFSecRel32(Fn, 0); + Streamer->EmitCOFFSectionIndex(Fn); + + // Emit flags + Streamer->emitIntValue(0, 1); + + // Emit the function display name as a null-terminated string. + + Streamer->emitBytes(StringRef(FunctionName, FunctionNameLength)); + + // Emit local var info + int NumVarInfos = DebugVarInfos.size(); + if (NumVarInfos > 0) { + EmitCVDebugVarInfo(Fn, &DebugVarInfos[0], NumVarInfos); + DebugVarInfos.clear(); + } + + // We're done with this function. + EmitSymRecord(0, SymbolRecordKind::ProcEnd); + } + + Streamer->emitLabel(SymbolsEnd); + + // Every subsection must be aligned to a 4-byte boundary. + Streamer->emitValueToAlignment(4); + + // We have an assembler directive that takes care of the whole line table. + // We also increase function id for the next function. + Streamer->emitCVLinetableDirective(FuncId++, Fn, FnEnd); +} + +void ObjectWriter::EmitDwarfFunctionInfo(const char *FunctionName, + int FunctionSize, + unsigned MethodTypeIndex) { + if (FuncId == 1) { + DwarfGenerator->EmitCompileUnit(); + } + + DwarfGenerator->EmitSubprogramInfo(FunctionName, FunctionSize, + MethodTypeIndex, DebugVarInfos, DebugEHClauseInfos); + + DebugVarInfos.clear(); + DebugEHClauseInfos.clear(); + + FuncId++; +} + +void ObjectWriter::EmitDebugFileInfo(int FileId, const char *FileName) { + assert(FileId > 0 && "FileId should be greater than 0."); + if (OutContext->getObjectFileType() == MCContext::IsCOFF) { + // TODO: we could pipe through the checksum and hash algorithm from the managed PDB + ArrayRef ChecksumAsBytes; + Streamer->EmitCVFileDirective(FileId, FileName, ChecksumAsBytes, 0); + } else { + Streamer->emitDwarfFileDirective(FileId, "", FileName); + } +} + +void ObjectWriter::EmitDebugFunctionInfo(const char *FunctionName, + int FunctionSize, + unsigned MethodTypeIndex) { + if (OutContext->getObjectFileType() == MCContext::IsCOFF) { + Streamer->EmitCVFuncIdDirective(FuncId); + EmitCVDebugFunctionInfo(FunctionName, FunctionSize); + } else { + if (OutContext->getObjectFileType() == MCContext::IsELF) { + MCSymbol *Sym = OutContext->getOrCreateSymbol(Twine(FunctionName)); + Streamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeFunction); + Streamer->emitELFSize(Sym, + MCConstantExpr::create(FunctionSize, *OutContext)); + } + EmitDwarfFunctionInfo(FunctionName, FunctionSize, MethodTypeIndex); + } +} + +void ObjectWriter::EmitDebugVar(char *Name, int TypeIndex, bool IsParm, + int RangeCount, + const ICorDebugInfo::NativeVarInfo *Ranges) { + assert(RangeCount != 0); + DebugVarInfo NewVar(Name, TypeIndex, IsParm); + + for (int I = 0; I < RangeCount; I++) { + assert(Ranges[0].varNumber == Ranges[I].varNumber); + NewVar.Ranges.push_back(Ranges[I]); + } + + DebugVarInfos.push_back(NewVar); +} + +void ObjectWriter::EmitDebugEHClause(unsigned TryOffset, unsigned TryLength, + unsigned HandlerOffset, unsigned HandlerLength) { + if (OutContext->getObjectFileType() == MCContext::IsELF) { + DebugEHClauseInfos.emplace_back(TryOffset, TryLength, HandlerOffset, HandlerLength); + } +} + +void ObjectWriter::EmitDebugLoc(int NativeOffset, int FileId, int LineNumber, + int ColNumber) { + assert(FileId > 0 && "FileId should be greater than 0."); + if (OutContext->getObjectFileType() == MCContext::IsCOFF) { + Streamer->EmitCVFuncIdDirective(FuncId); + Streamer->emitCVLocDirective(FuncId, FileId, LineNumber, ColNumber, false, + true, "", SMLoc()); + } else { + Streamer->emitDwarfLocDirective(FileId, LineNumber, ColNumber, 1, 0, 0, ""); + } +} + +void ObjectWriter::EmitCVUserDefinedTypesSymbols() { + const auto &UDTs = TypeBuilder->GetUDTs(); + if (UDTs.empty()) { + return; + } + MCSection *Section = ObjFileInfo->getCOFFDebugSymbolsSection(); + Streamer->SwitchSection(Section); + + MCSymbol *SymbolsBegin = OutContext->createTempSymbol(), + *SymbolsEnd = OutContext->createTempSymbol(); + Streamer->emitIntValue(unsigned(DebugSubsectionKind::Symbols), 4); + EmitLabelDiff(SymbolsBegin, SymbolsEnd); + Streamer->emitLabel(SymbolsBegin); + + for (const std::pair &UDT : UDTs) { + unsigned NameLength = UDT.first.length() + 1; + unsigned RecordLength = 2 + 4 + NameLength; + Streamer->emitIntValue(RecordLength, 2); + Streamer->emitIntValue(unsigned(SymbolKind::S_UDT), 2); + Streamer->emitIntValue(UDT.second, 4); + Streamer->emitBytes(StringRef(UDT.first.c_str(), NameLength)); + } + Streamer->emitLabel(SymbolsEnd); + Streamer->emitValueToAlignment(4); +} + +void ObjectWriter::EmitDebugModuleInfo() { + if (OutContext->getObjectFileType() == MCContext::IsCOFF) { + TypeBuilder->EmitTypeInformation(ObjFileInfo->getCOFFDebugTypesSection()); + EmitCVUserDefinedTypesSymbols(); + } + + // Ensure ending all sections. + for (auto Section : Sections) { + Streamer->endSection(Section); + } + + if (OutContext->getObjectFileType() == MCContext::IsCOFF) { + MCSection *Section = ObjFileInfo->getCOFFDebugSymbolsSection(); + Streamer->SwitchSection(Section); + Streamer->emitCVFileChecksumsDirective(); + Streamer->emitCVStringTableDirective(); + } else { + DwarfGenerator->EmitAbbrev(); + DwarfGenerator->EmitAranges(); + DwarfGenerator->Finish(); + } +} + +unsigned +ObjectWriter::GetEnumTypeIndex(const EnumTypeDescriptor &TypeDescriptor, + const EnumRecordTypeDescriptor *TypeRecords) { + return TypeBuilder->GetEnumTypeIndex(TypeDescriptor, TypeRecords); +} + +unsigned +ObjectWriter::GetClassTypeIndex(const ClassTypeDescriptor &ClassDescriptor) { + unsigned res = TypeBuilder->GetClassTypeIndex(ClassDescriptor); + return res; +} + +unsigned ObjectWriter::GetCompleteClassTypeIndex( + const ClassTypeDescriptor &ClassDescriptor, + const ClassFieldsTypeDescriptior &ClassFieldsDescriptor, + const DataFieldDescriptor *FieldsDescriptors, + const StaticDataFieldDescriptor *StaticsDescriptors) { + unsigned res = TypeBuilder->GetCompleteClassTypeIndex(ClassDescriptor, + ClassFieldsDescriptor, FieldsDescriptors, StaticsDescriptors); + return res; +} + +unsigned +ObjectWriter::GetArrayTypeIndex(const ClassTypeDescriptor &ClassDescriptor, + const ArrayTypeDescriptor &ArrayDescriptor) { + return TypeBuilder->GetArrayTypeIndex(ClassDescriptor, ArrayDescriptor); +} + +unsigned +ObjectWriter::GetPointerTypeIndex(const PointerTypeDescriptor& PointerDescriptor) { + return TypeBuilder->GetPointerTypeIndex(PointerDescriptor); +} + +unsigned +ObjectWriter::GetMemberFunctionTypeIndex(const MemberFunctionTypeDescriptor& MemberDescriptor, + uint32_t const *const ArgumentTypes) { + return TypeBuilder->GetMemberFunctionTypeIndex(MemberDescriptor, ArgumentTypes); +} + +unsigned +ObjectWriter::GetMemberFunctionId(const MemberFunctionIdTypeDescriptor& MemberIdDescriptor) { + return TypeBuilder->GetMemberFunctionId(MemberIdDescriptor); +} + +unsigned +ObjectWriter::GetPrimitiveTypeIndex(int Type) { + return TypeBuilder->GetPrimitiveTypeIndex(static_cast(Type)); +} + +void +ObjectWriter::EmitARMFnStart() { + MCTargetStreamer &TS = *(Streamer->getTargetStreamer()); + ARMTargetStreamer &ATS = static_cast(TS); + + ATS.emitFnStart(); +} + +void ObjectWriter::EmitARMFnEnd() { + + if (!CFIsPerOffset.empty()) + { + EmitARMExIdxPerOffset(); + } + + MCTargetStreamer &TS = *(Streamer->getTargetStreamer()); + ARMTargetStreamer &ATS = static_cast(TS); + + ATS.emitFnEnd(); +} + +void ObjectWriter::EmitARMExIdxLsda(const char *LsdaBlobSymbolName) +{ + MCTargetStreamer &TS = *(Streamer->getTargetStreamer()); + ARMTargetStreamer &ATS = static_cast(TS); + + MCSymbol *T = OutContext->getOrCreateSymbol(LsdaBlobSymbolName); + Assembler->registerSymbol(*T); + + ATS.emitLsda(T); +} + +void ObjectWriter::EmitARMExIdxPerOffset() +{ + MCTargetStreamer &TS = *(Streamer->getTargetStreamer()); + ARMTargetStreamer &ATS = static_cast(TS); + const MCRegisterInfo *MRI = OutContext->getRegisterInfo(); + + SmallVector RegSet; + bool IsVector = false; + + // LLVM reverses opcodes that are fed to ARMTargetStreamer, so we do the same, + // but per code offset. Opcodes with different code offsets are already given in + // the correct order. + for (int i = CFIsPerOffset.size() - 1; i >= 0; --i) + { + unsigned char opCode = CFIsPerOffset[i].CfiOpCode; + short Reg = CFIsPerOffset[i].DwarfReg; + + if (RegSet.empty() && opCode == CFI_REL_OFFSET) + { + IsVector = Reg >= 16; + } + else if (!RegSet.empty() && opCode != CFI_REL_OFFSET) + { + ATS.emitRegSave(RegSet, IsVector); + RegSet.clear(); + } + + switch (opCode) + { + case CFI_REL_OFFSET: + assert(IsVector == (Reg >= 16) && "Unexpected Register Type"); + RegSet.push_back(MRI->getLLVMRegNum(Reg, true).getValue()); + break; + case CFI_ADJUST_CFA_OFFSET: + assert(Reg == DWARF_REG_ILLEGAL && + "Unexpected Register Value for OpAdjustCfaOffset"); + ATS.emitPad(CFIsPerOffset[i].Offset); + break; + case CFI_DEF_CFA_REGISTER: + ATS.emitMovSP(MRI->getLLVMRegNum(Reg, true).getValue()); + break; + default: + assert(false && "Unrecognized CFI"); + break; + } + } + + // if we have some registers left over, emit them + if (!RegSet.empty()) + { + ATS.emitRegSave(RegSet, IsVector); + } + + CFIsPerOffset.clear(); +} + +void ObjectWriter::EmitARMExIdxCode(int Offset, const char *Blob) +{ + const CFI_CODE *CfiCode = (const CFI_CODE *)Blob; + + if (!CFIsPerOffset.empty() && CFIsPerOffset[0].CodeOffset != CfiCode->CodeOffset) + { + EmitARMExIdxPerOffset(); + } + + CFIsPerOffset.push_back(*CfiCode); +} diff --git a/llvm/tools/objwriter/objwriter.exports b/llvm/tools/objwriter/objwriter.exports new file mode 100644 index 0000000000000..d8a22c2b45afa --- /dev/null +++ b/llvm/tools/objwriter/objwriter.exports @@ -0,0 +1,34 @@ +InitObjWriter +FinishObjWriter +SetDwarfVersion +SwitchSection +SetCodeSectionAttribute +EmitAlignment +EmitBlob +EmitIntValue +EmitSymbolDef +EmitSymbolRef +EmitWinFrameInfo +EmitCFIStart +EmitCFIEnd +EmitCFILsda +EmitCFICode +EmitCFICompactUnwindEncoding +EmitDebugFileInfo +EmitDebugFunctionInfo +EmitDebugVar +EmitDebugEHClause +EmitDebugLoc +EmitDebugModuleInfo +GetEnumTypeIndex +GetClassTypeIndex +GetCompleteClassTypeIndex +GetArrayTypeIndex +GetPointerTypeIndex +GetMemberFunctionTypeIndex +GetMemberFunctionIdTypeIndex +GetPrimitiveTypeIndex +EmitARMFnStart +EmitARMFnEnd +EmitARMExIdxLsda +EmitARMExIdxCode diff --git a/llvm/tools/objwriter/objwriter.h b/llvm/tools/objwriter/objwriter.h new file mode 100644 index 0000000000000..860312f92a13e --- /dev/null +++ b/llvm/tools/objwriter/objwriter.h @@ -0,0 +1,410 @@ +//===---- objwriter.h ------------------------------------------*- C++ -*-===// +// +// object writer +// +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// +//===----------------------------------------------------------------------===// + +#include "llvm/CodeGen/AsmPrinter.h" +#include "llvm/MC/MCInstrInfo.h" +#include "llvm/MC/MCObjectFileInfo.h" +#include "llvm/Target/TargetOptions.h" +#include "llvm/DebugInfo/CodeView/SymbolRecord.h" + +#include "cfi.h" +#include "jitDebugInfo.h" +#include "debugInfo/dwarf/dwarfGen.h" + +#include +#include + +using namespace llvm; +using namespace llvm::codeview; + +#ifdef _WIN32 +#define DLL_EXPORT extern "C" __declspec(dllexport) +#else +#define DLL_EXPORT extern "C" __attribute((visibility("default"))) +#endif + +// *** +// Define default call conventions +// *** +#if defined(HOST_X86) && !defined(HOST_UNIX) +#define STDMETHODCALLTYPE __stdcall +#else +#define STDMETHODCALLTYPE +#endif // defined(HOST_X86) && !defined(HOST_UNIX) + +typedef uint16_t CVRegNum; + +enum CustomSectionAttributes : int32_t { + CustomSectionAttributes_ReadOnly = 0x0000, + CustomSectionAttributes_Writeable = 0x0001, + CustomSectionAttributes_Executable = 0x0002, + CustomSectionAttributes_Uninitialized = 0x0004, + CustomSectionAttributes_MachO_Init_Func_Pointers = 0x0100, +}; + +enum class RelocType { + IMAGE_REL_BASED_ABSOLUTE = 0x00, + IMAGE_REL_BASED_HIGHLOW = 0x03, + IMAGE_REL_BASED_THUMB_MOV32 = 0x07, + IMAGE_REL_BASED_DIR64 = 0x0A, + IMAGE_REL_BASED_REL32 = 0x10, + IMAGE_REL_BASED_THUMB_BRANCH24 = 0x13, + IMAGE_REL_BASED_ARM64_BRANCH26 = 0x15, + IMAGE_REL_BASED_RELPTR32 = 0x7C, + IMAGE_REL_BASED_ARM64_PAGEBASE_REL21 = 0x81, + IMAGE_REL_BASED_ARM64_PAGEOFFSET_12A = 0x82, +}; + +enum class SymbolRefFlags +{ + SymbolRefFlags_AddressTakenFunction = 0x0001, +}; + +class ObjectWriter { +public: + bool Init(StringRef FunctionName, const char* tripleName = nullptr); + void Finish(); + + void SetDwarfVersion(uint16_t v); + void SwitchSection(const char *SectionName, + CustomSectionAttributes attributes, + const char *ComdatName); + void SetCodeSectionAttribute(const char *SectionName, + CustomSectionAttributes attributes, + const char *ComdatName); + + void EmitAlignment(int ByteAlignment); + void EmitBlob(int BlobSize, const char *Blob); + void EmitIntValue(uint64_t Value, unsigned Size); + void EmitSymbolDef(const char *SymbolName, bool global); + void EmitWinFrameInfo(const char *FunctionName, int StartOffset, + int EndOffset, const char *BlobSymbolName); + int EmitSymbolRef(const char *SymbolName, RelocType RelocType, int Delta, SymbolRefFlags Flags); + + void EmitDebugFileInfo(int FileId, const char *FileName); + void EmitDebugFunctionInfo(const char *FunctionName, int FunctionSize, unsigned MethodTypeIndex); + void EmitDebugVar(char *Name, int TypeIndex, bool IsParm, int RangeCount, + const ICorDebugInfo::NativeVarInfo *Ranges); + void EmitDebugLoc(int NativeOffset, int FileId, int LineNumber, + int ColNumber); + void EmitDebugEHClause(unsigned TryOffset, unsigned TryLength, + unsigned HandlerOffset, unsigned HandlerLength); + void EmitDebugModuleInfo(); + + void EmitCFIStart(int Offset); + void EmitCFIEnd(int Offset); + void EmitCFILsda(const char *LsdaBlobSymbolName); + void EmitCFICode(int Offset, const char *Blob); + void EmitCFICompactUnwindEncoding(unsigned int Encoding); + + unsigned GetEnumTypeIndex(const EnumTypeDescriptor &TypeDescriptor, + const EnumRecordTypeDescriptor *TypeRecords); + unsigned GetClassTypeIndex(const ClassTypeDescriptor &ClassDescriptor); + unsigned GetCompleteClassTypeIndex( + const ClassTypeDescriptor &ClassDescriptor, + const ClassFieldsTypeDescriptior &ClassFieldsDescriptor, + const DataFieldDescriptor *FieldsDescriptors, + const StaticDataFieldDescriptor *StaticsDescriptors); + + unsigned GetArrayTypeIndex(const ClassTypeDescriptor &ClassDescriptor, + const ArrayTypeDescriptor &ArrayDescriptor); + + unsigned GetPointerTypeIndex(const PointerTypeDescriptor& PointerDescriptor); + + unsigned GetMemberFunctionTypeIndex(const MemberFunctionTypeDescriptor& MemberDescriptor, + uint32_t const *const ArgumentTypes); + + unsigned GetMemberFunctionId(const MemberFunctionIdTypeDescriptor& MemberIdDescriptor); + + unsigned GetPrimitiveTypeIndex(int Type); + + void EmitARMFnStart(); + void EmitARMFnEnd(); + void EmitARMExIdxCode(int Offset, const char *Blob); + void EmitARMExIdxLsda(const char *Blob); + +private: + void EmitLabelDiff(const MCSymbol *From, const MCSymbol *To, + unsigned int Size = 4); + void EmitSymRecord(int Size, SymbolRecordKind SymbolKind); + void EmitCOFFSecRel32Value(MCExpr const *Value); + + void EmitVarDefRange(const MCSymbol *Fn, const LocalVariableAddrRange &Range); + + CVRegNum GetCVRegNum(unsigned RegNum); + void EmitCVDebugVarInfo(const MCSymbol *Fn, const DebugVarInfo LocInfos[], + int NumVarInfos); + void EmitCVDebugFunctionInfo(const char *FunctionName, int FunctionSize); + + void EmitDwarfFunctionInfo(const char *FunctionName, int FunctionSize, unsigned MethodTypeIndex); + + const MCSymbolRefExpr *GetSymbolRefExpr( + const char *SymbolName, + MCSymbolRefExpr::VariantKind Kind = MCSymbolRefExpr::VK_None); + + MCSection *GetSection(const char *SectionName, + CustomSectionAttributes attributes, + const char *ComdatName); + + MCSection *GetSpecificSection(const char *SectionName, + CustomSectionAttributes attributes, + const char *ComdatName); + + void EmitCVUserDefinedTypesSymbols(); + + void InitTripleName(const char* tripleName = nullptr); + unsigned GetDFSize(); + void EmitRelocDirective(const int Offset, StringRef Name, const MCExpr *Expr); + const MCExpr *GenTargetExpr(const MCSymbol* Symbol, + MCSymbolRefExpr::VariantKind Kind, int Delta, + bool IsPCRel = false, int Size = 0); + void EmitARMExIdxPerOffset(); + + +private: + std::unique_ptr RegisterInfo; + std::unique_ptr AsmInfo; + std::unique_ptr ObjFileInfo; + std::unique_ptr OutContext; + MCAsmBackend *AsmBackend; // Owned by MCStreamer + std::unique_ptr InstrInfo; + std::unique_ptr SubtargetInfo; + MCCodeEmitter *CodeEmitter; // Owned by MCStreamer + MCAssembler *Assembler; // Owned by MCStreamer + std::unique_ptr DwarfGenerator; + + std::unique_ptr OS; + MCTargetOptions TargetMOptions; + bool FrameOpened; + bool FrameHasCompactEncoding; + std::vector DebugVarInfos; + std::vector DebugEHClauseInfos; + DenseSet AddressTakenFunctions; + + std::set Sections; + int FuncId; + + std::unique_ptr TypeBuilder; + + std::string TripleName; + + MCObjectStreamer *Streamer; // Owned by AsmPrinter + + SmallVector CFIsPerOffset; +}; + +// When object writer is created/initialized successfully, it is returned. +// Or null object is returned. Client should check this. +DLL_EXPORT STDMETHODCALLTYPE ObjectWriter *InitObjWriter(const char *ObjectFilePath, const char* TripleName = nullptr) { + ObjectWriter *OW = new ObjectWriter(); + if (OW->Init(ObjectFilePath, TripleName)) { + return OW; + } + delete OW; + return nullptr; +} + +DLL_EXPORT STDMETHODCALLTYPE void FinishObjWriter(ObjectWriter *OW) { + assert(OW && "ObjWriter is null"); + OW->Finish(); + delete OW; +} + +DLL_EXPORT STDMETHODCALLTYPE void SetDwarfVersion(ObjectWriter *OW, uint16_t v) { + assert(OW && "ObjWriter is null"); + OW->SetDwarfVersion(v); +} + +DLL_EXPORT STDMETHODCALLTYPE void SwitchSection(ObjectWriter *OW, const char *SectionName, + CustomSectionAttributes attributes, + const char *ComdatName) { + assert(OW && "ObjWriter is null"); + OW->SwitchSection(SectionName, attributes, ComdatName); +} + +DLL_EXPORT STDMETHODCALLTYPE void SetCodeSectionAttribute(ObjectWriter *OW, + const char *SectionName, + CustomSectionAttributes attributes, + const char *ComdatName) { + assert(OW && "ObjWriter is null"); + OW->SetCodeSectionAttribute(SectionName, attributes, ComdatName); +} + +DLL_EXPORT STDMETHODCALLTYPE void EmitAlignment(ObjectWriter *OW, int ByteAlignment) { + assert(OW && "ObjWriter is null"); + OW->EmitAlignment(ByteAlignment); +} + +DLL_EXPORT STDMETHODCALLTYPE void EmitBlob(ObjectWriter *OW, int BlobSize, const char *Blob) { + assert(OW && "ObjWriter null"); + OW->EmitBlob(BlobSize, Blob); +} + +DLL_EXPORT STDMETHODCALLTYPE void EmitIntValue(ObjectWriter *OW, uint64_t Value, unsigned Size) { + assert(OW && "ObjWriter is null"); + OW->EmitIntValue(Value, Size); +} + +DLL_EXPORT STDMETHODCALLTYPE void EmitSymbolDef(ObjectWriter *OW, const char *SymbolName, bool global) { + assert(OW && "ObjWriter is null"); + OW->EmitSymbolDef(SymbolName, global); +} + +DLL_EXPORT STDMETHODCALLTYPE int EmitSymbolRef(ObjectWriter *OW, const char *SymbolName, + RelocType RelocType, int Delta, SymbolRefFlags Flags) { + assert(OW && "ObjWriter is null"); + return OW->EmitSymbolRef(SymbolName, RelocType, Delta, Flags); +} + +DLL_EXPORT STDMETHODCALLTYPE void EmitWinFrameInfo(ObjectWriter *OW, const char *FunctionName, + int StartOffset, int EndOffset, + const char *BlobSymbolName) { + assert(OW && "ObjWriter is null"); + OW->EmitWinFrameInfo(FunctionName, StartOffset, EndOffset, BlobSymbolName); +} + +DLL_EXPORT STDMETHODCALLTYPE void EmitCFIStart(ObjectWriter *OW, int Offset) { + assert(OW && "ObjWriter is null"); + OW->EmitCFIStart(Offset); +} + +DLL_EXPORT STDMETHODCALLTYPE void EmitCFIEnd(ObjectWriter *OW, int Offset) { + assert(OW && "ObjWriter is null"); + OW->EmitCFIEnd(Offset); +} + +DLL_EXPORT STDMETHODCALLTYPE void EmitCFILsda(ObjectWriter *OW, const char *LsdaBlobSymbolName) { + assert(OW && "ObjWriter is null"); + OW->EmitCFILsda(LsdaBlobSymbolName); +} + +DLL_EXPORT STDMETHODCALLTYPE void EmitCFICode(ObjectWriter *OW, int Offset, const char *Blob) { + assert(OW && "ObjWriter is null"); + OW->EmitCFICode(Offset, Blob); +} + +DLL_EXPORT STDMETHODCALLTYPE void EmitCFICompactUnwindEncoding(ObjectWriter *OW, unsigned int Encoding) { + assert(OW && "ObjWriter is null"); + OW->EmitCFICompactUnwindEncoding(Encoding); +} + +DLL_EXPORT STDMETHODCALLTYPE void EmitDebugFileInfo(ObjectWriter *OW, int FileId, + const char *FileName) { + assert(OW && "ObjWriter is null"); + OW->EmitDebugFileInfo(FileId, FileName); +} + +DLL_EXPORT STDMETHODCALLTYPE void EmitDebugFunctionInfo(ObjectWriter *OW, + const char *FunctionName, + int FunctionSize, + unsigned MethodTypeIndex) { + assert(OW && "ObjWriter is null"); + OW->EmitDebugFunctionInfo(FunctionName, FunctionSize, MethodTypeIndex); +} + +DLL_EXPORT STDMETHODCALLTYPE void EmitDebugVar(ObjectWriter *OW, char *Name, int TypeIndex, + bool IsParam, int RangeCount, + ICorDebugInfo::NativeVarInfo *Ranges) { + assert(OW && "ObjWriter is null"); + OW->EmitDebugVar(Name, TypeIndex, IsParam, RangeCount, Ranges); +} + +DLL_EXPORT STDMETHODCALLTYPE void EmitDebugEHClause(ObjectWriter *OW, unsigned TryOffset, + unsigned TryLength, unsigned HandlerOffset, + unsigned HandlerLength) { + assert(OW && "ObjWriter is null"); + OW->EmitDebugEHClause(TryOffset, TryLength, HandlerOffset, HandlerLength); +} + +DLL_EXPORT STDMETHODCALLTYPE void EmitDebugLoc(ObjectWriter *OW, int NativeOffset, int FileId, + int LineNumber, int ColNumber) { + assert(OW && "ObjWriter is null"); + OW->EmitDebugLoc(NativeOffset, FileId, LineNumber, ColNumber); +} + +// This should be invoked at the end of module emission to finalize +// debug module info. +DLL_EXPORT STDMETHODCALLTYPE void EmitDebugModuleInfo(ObjectWriter *OW) { + assert(OW && "ObjWriter is null"); + OW->EmitDebugModuleInfo(); +} + +DLL_EXPORT STDMETHODCALLTYPE unsigned GetEnumTypeIndex(ObjectWriter *OW, + EnumTypeDescriptor TypeDescriptor, + EnumRecordTypeDescriptor *TypeRecords) { + assert(OW && "ObjWriter is null"); + return OW->GetEnumTypeIndex(TypeDescriptor, TypeRecords); +} + +DLL_EXPORT STDMETHODCALLTYPE unsigned GetClassTypeIndex(ObjectWriter *OW, + ClassTypeDescriptor ClassDescriptor) { + assert(OW && "ObjWriter is null"); + return OW->GetClassTypeIndex(ClassDescriptor); +} + +DLL_EXPORT STDMETHODCALLTYPE unsigned +GetCompleteClassTypeIndex(ObjectWriter *OW, ClassTypeDescriptor ClassDescriptor, + ClassFieldsTypeDescriptior ClassFieldsDescriptor, + DataFieldDescriptor *FieldsDescriptors, + StaticDataFieldDescriptor *StaticsDescriptors) { + assert(OW && "ObjWriter is null"); + return OW->GetCompleteClassTypeIndex(ClassDescriptor, ClassFieldsDescriptor, + FieldsDescriptors, StaticsDescriptors); +} + +DLL_EXPORT STDMETHODCALLTYPE unsigned GetArrayTypeIndex(ObjectWriter *OW, + ClassTypeDescriptor ClassDescriptor, + ArrayTypeDescriptor ArrayDescriptor) { + assert(OW && "ObjWriter is null"); + return OW->GetArrayTypeIndex(ClassDescriptor, ArrayDescriptor); +} + +DLL_EXPORT STDMETHODCALLTYPE unsigned GetPointerTypeIndex(ObjectWriter *OW, + PointerTypeDescriptor PointerDescriptor) { + assert(OW && "ObjWriter is null"); + return OW->GetPointerTypeIndex(PointerDescriptor); +} + +DLL_EXPORT STDMETHODCALLTYPE unsigned GetMemberFunctionTypeIndex(ObjectWriter *OW, + MemberFunctionTypeDescriptor MemberDescriptor, + uint32_t *ArgumentTypes) { + assert(OW && "ObjWriter is null"); + return OW->GetMemberFunctionTypeIndex(MemberDescriptor, ArgumentTypes); +} + +DLL_EXPORT STDMETHODCALLTYPE unsigned GetMemberFunctionIdTypeIndex(ObjectWriter *OW, + MemberFunctionIdTypeDescriptor MemberIdDescriptor) { + assert(OW && "ObjWriter is null"); + return OW->GetMemberFunctionId(MemberIdDescriptor); +} + +DLL_EXPORT STDMETHODCALLTYPE unsigned GetPrimitiveTypeIndex(ObjectWriter *OW, int Type) { + assert(OW && "ObjWriter is null"); + return OW->GetPrimitiveTypeIndex(Type); +} + +DLL_EXPORT STDMETHODCALLTYPE void EmitARMFnStart(ObjectWriter *OW) { + assert(OW && "ObjWriter is null"); + return OW->EmitARMFnStart(); +} + +DLL_EXPORT STDMETHODCALLTYPE void EmitARMFnEnd(ObjectWriter *OW) { + assert(OW && "ObjWriter is null"); + return OW->EmitARMFnEnd(); +} + +DLL_EXPORT STDMETHODCALLTYPE void EmitARMExIdxLsda(ObjectWriter *OW, const char *Blob) { + assert(OW && "ObjWriter is null"); + return OW->EmitARMExIdxLsda(Blob); +} + +DLL_EXPORT STDMETHODCALLTYPE void EmitARMExIdxCode(ObjectWriter *OW, int Offset, const char *Blob) { + assert(OW && "ObjWriter is null"); + return OW->EmitARMExIdxCode(Offset, Blob); +} diff --git a/llvm/utils/docker/debian8/Dockerfile b/llvm/utils/docker/debian8/Dockerfile deleted file mode 100644 index 9d0e2b8d795e5..0000000000000 --- a/llvm/utils/docker/debian8/Dockerfile +++ /dev/null @@ -1,60 +0,0 @@ -#===- llvm/utils/docker/debian8/build/Dockerfile -------------------------===// -# -# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# -#===----------------------------------------------------------------------===// -# Stage 1. Check out LLVM source code and run the build. -FROM launcher.gcr.io/google/debian8:latest as builder -LABEL maintainer "LLVM Developers" -# Install build dependencies of llvm. -# First, Update the apt's source list and include the sources of the packages. -RUN grep deb /etc/apt/sources.list | \ - sed 's/^deb/deb-src /g' >> /etc/apt/sources.list -# Install compiler, python and subversion. -RUN apt-get update && \ - apt-get install -y --no-install-recommends ca-certificates gnupg \ - build-essential python wget subversion unzip && \ - rm -rf /var/lib/apt/lists/* -# Install a newer ninja release. It seems the older version in the debian repos -# randomly crashes when compiling llvm. -RUN wget "https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip" && \ - echo "d2fea9ff33b3ef353161ed906f260d565ca55b8ca0568fa07b1d2cab90a84a07 ninja-linux.zip" \ - | sha256sum -c && \ - unzip ninja-linux.zip -d /usr/local/bin && \ - rm ninja-linux.zip -# Import public key required for verifying signature of cmake download. -RUN gpg --keyserver hkp://pgp.mit.edu --recv 0x2D2CEF1034921684 -# Download, verify and install cmake version that can compile clang into /usr/local. -# (Version in debian8 repos is is too old) -RUN mkdir /tmp/cmake-install && cd /tmp/cmake-install && \ - wget "https://cmake.org/files/v3.7/cmake-3.7.2-SHA-256.txt.asc" && \ - wget "https://cmake.org/files/v3.7/cmake-3.7.2-SHA-256.txt" && \ - gpg --verify cmake-3.7.2-SHA-256.txt.asc cmake-3.7.2-SHA-256.txt && \ - wget "https://cmake.org/files/v3.7/cmake-3.7.2-Linux-x86_64.tar.gz" && \ - ( grep "cmake-3.7.2-Linux-x86_64.tar.gz" cmake-3.7.2-SHA-256.txt | \ - sha256sum -c - ) && \ - tar xzf cmake-3.7.2-Linux-x86_64.tar.gz -C /usr/local --strip-components=1 && \ - cd / && rm -rf /tmp/cmake-install - -ADD checksums /tmp/checksums -ADD scripts /tmp/scripts - -# Checkout the source code. -ARG checkout_args -RUN /tmp/scripts/checkout.sh ${checkout_args} -# Run the build. Results of the build will be available at /tmp/clang-install/. -ARG buildscript_args -RUN /tmp/scripts/build_install_llvm.sh --to /tmp/clang-install ${buildscript_args} - - -# Stage 2. Produce a minimal release image with build results. -FROM launcher.gcr.io/google/debian8:latest -LABEL maintainer "LLVM Developers" -# Install packages for minimal useful image. -RUN apt-get update && \ - apt-get install -y --no-install-recommends libstdc++-4.9-dev binutils && \ - rm -rf /var/lib/apt/lists/* -# Copy build results of stage 1 to /usr/local. -COPY --from=builder /tmp/clang-install/ /usr/local/ diff --git a/llvm/utils/docker/example/Dockerfile b/llvm/utils/docker/example/Dockerfile deleted file mode 100644 index ebfb0e49c82c8..0000000000000 --- a/llvm/utils/docker/example/Dockerfile +++ /dev/null @@ -1,39 +0,0 @@ -#===- llvm/utils/docker/example/build/Dockerfile -------------------------===// -# -# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# -#===----------------------------------------------------------------------===// -# This is an example Dockerfile to build an image that compiles clang. -# Replace FIXMEs to prepare your own image. - -# Stage 1. Check out LLVM source code and run the build. -# FIXME: Replace 'ubuntu' with your base image -FROM ubuntu as builder -# FIXME: Change maintainer name -LABEL maintainer "Maintainer " -# FIXME: Install llvm/clang build dependencies here. Including compiler to -# build stage1, cmake, subversion, ninja, etc. - -ADD checksums /tmp/checksums -ADD scripts /tmp/scripts - -# Checkout the source code. -ARG checkout_args -RUN /tmp/scripts/checkout.sh ${checkout_args} -# Run the build. Results of the build will be available at /tmp/clang-install/. -ARG buildscript_args -RUN /tmp/scripts/build_install_llvm.sh --to /tmp/clang-install ${buildscript_args} - - -# Stage 2. Produce a minimal release image with build results. -# FIXME: Replace 'ubuntu' with your base image. -FROM ubuntu -# FIXME: Change maintainer name. -LABEL maintainer "Maintainer " -# FIXME: Install all packages you want to have in your release container. -# A minimal useful installation should include at least libstdc++ and binutils. - -# Copy build results of stage 1 to /usr/local. -COPY --from=builder /tmp/clang-install/ /usr/local/ diff --git a/llvm/utils/docker/nvidia-cuda/Dockerfile b/llvm/utils/docker/nvidia-cuda/Dockerfile deleted file mode 100644 index 5878259c27f4e..0000000000000 --- a/llvm/utils/docker/nvidia-cuda/Dockerfile +++ /dev/null @@ -1,33 +0,0 @@ -#===- llvm/utils/docker/nvidia-cuda/build/Dockerfile ---------------------===// -# -# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# -#===----------------------------------------------------------------------===// -# Stage 1. Check out LLVM source code and run the build. -FROM nvidia/cuda:8.0-devel as builder -LABEL maintainer "LLVM Developers" -# Install llvm build dependencies. -RUN apt-get update && \ - apt-get install -y --no-install-recommends ca-certificates cmake python \ - subversion ninja-build && \ - rm -rf /var/lib/apt/lists/* - -ADD checksums /tmp/checksums -ADD scripts /tmp/scripts - -# Checkout the source code. -ARG checkout_args -RUN /tmp/scripts/checkout.sh ${checkout_args} -# Run the build. Results of the build will be available at /tmp/clang-install/. -ARG buildscript_args -RUN /tmp/scripts/build_install_llvm.sh --to /tmp/clang-install ${buildscript_args} - - -# Stage 2. Produce a minimal release image with build results. -FROM nvidia/cuda:8.0-devel -LABEL maintainer "LLVM Developers" -# Copy clang installation into this container. -COPY --from=builder /tmp/clang-install/ /usr/local/ -# C++ standard library and binutils are already included in the base package. diff --git a/llvm/utils/vscode/llvm/.npmrc b/llvm/utils/vscode/llvm/.npmrc new file mode 100644 index 0000000000000..8701ec2998ee7 --- /dev/null +++ b/llvm/utils/vscode/llvm/.npmrc @@ -0,0 +1 @@ +registry=https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public-npm/npm/registry/ diff --git a/llvm/version.txt.in b/llvm/version.txt.in new file mode 100644 index 0000000000000..a24f9877ac158 --- /dev/null +++ b/llvm/version.txt.in @@ -0,0 +1 @@ +@PACKAGE_VERSION@ diff --git a/mlir/utils/vscode/.npmrc b/mlir/utils/vscode/.npmrc new file mode 100644 index 0000000000000..8701ec2998ee7 --- /dev/null +++ b/mlir/utils/vscode/.npmrc @@ -0,0 +1 @@ +registry=https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public-npm/npm/registry/ diff --git a/nuget/Directory.Build.props b/nuget/Directory.Build.props new file mode 100644 index 0000000000000..9b159f511261d --- /dev/null +++ b/nuget/Directory.Build.props @@ -0,0 +1,205 @@ + + + + + + + + + + + AnyCPU + + + <_parseDistroRid>$(__DistroRid) + <_parseDistroRid Condition="'$(_parseDistroRid)' == '' and '$(__BuildOS)' == 'OSX'">osx-$(Platform) + <_distroRidIndex>$(_parseDistroRid.IndexOfAny("-")) + <_archRidIndex>$([MSBuild]::Add($(_distroRidIndex), 1)) + $(_parseDistroRid.SubString(0, $(_distroRidIndex))) + linux + win10 + + $(_parseDistroRid.SubString($(_archRidIndex))) + $(Platform) + $(BuildArch) + + $(OSRid) + + Windows_NT;OSX;Android;Linux;FreeBSD + ;$(SupportedPackageOSGroups); + + + <_runtimeOSVersionIndex>$(RuntimeOS.IndexOfAny(".-0123456789")) + <_runtimeOSFamily Condition="'$(_runtimeOSVersionIndex)' != '-1'">$(RuntimeOS.SubString(0, $(_runtimeOSVersionIndex))) + <_runtimeOSFamily Condition="'$(_runtimeOSVersionIndex)' == '-1'">$(RuntimeOS) + <_isSupportedOSGroup>true + + + + + <_derivedPackageTargetOSGroup Condition="'$(_derivedPackageTargetOSGroup)' == '' and '$(_runtimeOSFamily)' == 'osx'">OSX + <_derivedPackageTargetOSGroup Condition="'$(_derivedPackageTargetOSGroup)' == '' and '$(_runtimeOSFamily)' == 'android'">Android + <_derivedPackageTargetOSGroup Condition="'$(_derivedPackageTargetOSGroup)' == '' and '$(_runtimeOSFamily)' == 'win'">Windows_NT + <_derivedPackageTargetOSGroup Condition="'$(_derivedPackageTargetOSGroup)' == '' and '$(__BuildOS)' != ''">$(__BuildOS) + <_derivedPackageTargetOSGroup Condition="'$(_derivedPackageTargetOSGroup)' == ''">Linux + + <_isSupportedOSGroup Condition="!$(SupportedPackageOSGroups.Contains(';$(_derivedPackageTargetOSGroup);'))">false + + + + + <_packageTargetOSGroup>$(_derivedPackageTargetOSGroup) + <_packageTargetOSGroup Condition="'$(_derivedPackageTargetOSGroup)' == 'Android'">Linux + + + true + $(PackageOutputPath) + + + + true + + + + + + + + $(OutputRID) + + + + + + win-$(ArchGroup) + + + + + osx-$(ArchGroup) + + osx-$(ArchGroup) + + + + + freebsd.11-$(ArchGroup) + + freebsd-$(ArchGroup) + + + + + android.21-$(ArchGroup) + + android-$(ArchGroup) + + + + + $(OSRid)-$(ArchGroup) + + linux-$(ArchGroup) + + + + + $(RuntimeOS)-$(ArchGroup) + + linux-$(ArchGroup) + + + + + + + + + + .dylib + .dwarf + + + + + .so + + .debug + + + + + .so + .dbg + + + + + + + + + + arm + + + arm64 + + + arm64 + + + armel + + + armel + + + + + + + + + + + x86 + + + + arm + + + arm64 + + + + + + + amd64 + $(ArchGroup) + + + + + <_project Include="@(BuildRID)"> + amd64 + %(Identity) + PackageTargetRuntime=%(Identity);Platform=%(Platform) + + + <_buildRidProjects Include="@(_project->'$(MSBuildProjectName).pkgproj')" /> + + + + + + + + + diff --git a/nuget/Directory.Build.targets b/nuget/Directory.Build.targets new file mode 100644 index 0000000000000..f5aaa3315faa1 --- /dev/null +++ b/nuget/Directory.Build.targets @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + runtimes/$(PackageTargetRuntime)/native + + + + runtimes/$(PackageTargetRuntime)/lib/netstandard1.0 + + + tools + + + + + + + + + + + + + + + + + + + + + + + true + + + + + true + + + + + runtimes/$(PackageTargetRuntime)/native + true + + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.JIT.Tools/Directory.Build.props b/nuget/Microsoft.NETCore.Runtime.JIT.Tools/Directory.Build.props new file mode 100644 index 0000000000000..f4a1490ea1da5 --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.JIT.Tools/Directory.Build.props @@ -0,0 +1,4 @@ + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.JIT.Tools/Microsoft.NETCore.Runtime.JIT.Tools.builds b/nuget/Microsoft.NETCore.Runtime.JIT.Tools/Microsoft.NETCore.Runtime.JIT.Tools.builds new file mode 100644 index 0000000000000..eaae7d884d1c9 --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.JIT.Tools/Microsoft.NETCore.Runtime.JIT.Tools.builds @@ -0,0 +1,4 @@ + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.JIT.Tools/Microsoft.NETCore.Runtime.JIT.Tools.pkgproj b/nuget/Microsoft.NETCore.Runtime.JIT.Tools/Microsoft.NETCore.Runtime.JIT.Tools.pkgproj new file mode 100644 index 0000000000000..a574caec29e4f --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.JIT.Tools/Microsoft.NETCore.Runtime.JIT.Tools.pkgproj @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.JIT.Tools/runtime.Linux.Microsoft.NETCore.Runtime.JIT.Tools.props b/nuget/Microsoft.NETCore.Runtime.JIT.Tools/runtime.Linux.Microsoft.NETCore.Runtime.JIT.Tools.props new file mode 100644 index 0000000000000..2bd12bbd01e47 --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.JIT.Tools/runtime.Linux.Microsoft.NETCore.Runtime.JIT.Tools.props @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.JIT.Tools/runtime.OSX.Microsoft.NETCore.Runtime.JIT.Tools.props b/nuget/Microsoft.NETCore.Runtime.JIT.Tools/runtime.OSX.Microsoft.NETCore.Runtime.JIT.Tools.props new file mode 100644 index 0000000000000..c4fb271a83161 --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.JIT.Tools/runtime.OSX.Microsoft.NETCore.Runtime.JIT.Tools.props @@ -0,0 +1,7 @@ + + + + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.JIT.Tools/runtime.Windows_NT.Microsoft.NETCore.Runtime.JIT.Tools.props b/nuget/Microsoft.NETCore.Runtime.JIT.Tools/runtime.Windows_NT.Microsoft.NETCore.Runtime.JIT.Tools.props new file mode 100644 index 0000000000000..0efb2beedbf52 --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.JIT.Tools/runtime.Windows_NT.Microsoft.NETCore.Runtime.JIT.Tools.props @@ -0,0 +1,7 @@ + + + + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/Directory.Build.props b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/Directory.Build.props new file mode 100644 index 0000000000000..f4a1490ea1da5 --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/Directory.Build.props @@ -0,0 +1,4 @@ + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.Debug.builds b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.Debug.builds new file mode 100644 index 0000000000000..eaae7d884d1c9 --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.Debug.builds @@ -0,0 +1,4 @@ + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.Debug.pkgproj b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.Debug.pkgproj new file mode 100644 index 0000000000000..10df842e48c1e --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.Debug.pkgproj @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.builds b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.builds new file mode 100644 index 0000000000000..eaae7d884d1c9 --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.builds @@ -0,0 +1,4 @@ + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.pkgproj b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.pkgproj new file mode 100644 index 0000000000000..a574caec29e4f --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.pkgproj @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/runtime.Linux.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.props b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/runtime.Linux.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.props new file mode 100644 index 0000000000000..a38988124ca11 --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/runtime.Linux.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.props @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/runtime.OSX.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.props b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/runtime.OSX.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.props new file mode 100644 index 0000000000000..21bab096c5e99 --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/runtime.OSX.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.props @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/runtime.Windows_NT.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.props b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/runtime.Windows_NT.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.props new file mode 100644 index 0000000000000..5e54411ce9638 --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Sdk/runtime.Windows_NT.Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.props @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/Directory.Build.props b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/Directory.Build.props new file mode 100644 index 0000000000000..f4a1490ea1da5 --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/Directory.Build.props @@ -0,0 +1,4 @@ + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/Microsoft.NETCore.Runtime.Mono.LLVM.Tools.Debug.builds b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/Microsoft.NETCore.Runtime.Mono.LLVM.Tools.Debug.builds new file mode 100644 index 0000000000000..eaae7d884d1c9 --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/Microsoft.NETCore.Runtime.Mono.LLVM.Tools.Debug.builds @@ -0,0 +1,4 @@ + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/Microsoft.NETCore.Runtime.Mono.LLVM.Tools.Debug.pkgproj b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/Microsoft.NETCore.Runtime.Mono.LLVM.Tools.Debug.pkgproj new file mode 100644 index 0000000000000..10df842e48c1e --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/Microsoft.NETCore.Runtime.Mono.LLVM.Tools.Debug.pkgproj @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/Microsoft.NETCore.Runtime.Mono.LLVM.Tools.builds b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/Microsoft.NETCore.Runtime.Mono.LLVM.Tools.builds new file mode 100644 index 0000000000000..eaae7d884d1c9 --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/Microsoft.NETCore.Runtime.Mono.LLVM.Tools.builds @@ -0,0 +1,4 @@ + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/Microsoft.NETCore.Runtime.Mono.LLVM.Tools.pkgproj b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/Microsoft.NETCore.Runtime.Mono.LLVM.Tools.pkgproj new file mode 100644 index 0000000000000..a574caec29e4f --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/Microsoft.NETCore.Runtime.Mono.LLVM.Tools.pkgproj @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/runtime.Linux.Microsoft.NETCore.Runtime.Mono.LLVM.Tools.props b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/runtime.Linux.Microsoft.NETCore.Runtime.Mono.LLVM.Tools.props new file mode 100644 index 0000000000000..380e3ad2abc7d --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/runtime.Linux.Microsoft.NETCore.Runtime.Mono.LLVM.Tools.props @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/runtime.OSX.Microsoft.NETCore.Runtime.Mono.LLVM.Tools.props b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/runtime.OSX.Microsoft.NETCore.Runtime.Mono.LLVM.Tools.props new file mode 100644 index 0000000000000..c2c6b0392785e --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/runtime.OSX.Microsoft.NETCore.Runtime.Mono.LLVM.Tools.props @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/runtime.Windows_NT.Microsoft.NETCore.Runtime.Mono.LLVM.Tools.props b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/runtime.Windows_NT.Microsoft.NETCore.Runtime.Mono.LLVM.Tools.props new file mode 100644 index 0000000000000..cf9091a3ed976 --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.Mono.LLVM.Tools/runtime.Windows_NT.Microsoft.NETCore.Runtime.Mono.LLVM.Tools.props @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.ObjWriter/Directory.Build.props b/nuget/Microsoft.NETCore.Runtime.ObjWriter/Directory.Build.props new file mode 100644 index 0000000000000..f4a1490ea1da5 --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.ObjWriter/Directory.Build.props @@ -0,0 +1,4 @@ + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.ObjWriter/Microsoft.NETCore.Runtime.ObjWriter.builds b/nuget/Microsoft.NETCore.Runtime.ObjWriter/Microsoft.NETCore.Runtime.ObjWriter.builds new file mode 100644 index 0000000000000..eaae7d884d1c9 --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.ObjWriter/Microsoft.NETCore.Runtime.ObjWriter.builds @@ -0,0 +1,4 @@ + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.ObjWriter/Microsoft.NETCore.Runtime.ObjWriter.pkgproj b/nuget/Microsoft.NETCore.Runtime.ObjWriter/Microsoft.NETCore.Runtime.ObjWriter.pkgproj new file mode 100644 index 0000000000000..a574caec29e4f --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.ObjWriter/Microsoft.NETCore.Runtime.ObjWriter.pkgproj @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.ObjWriter/runtime.Linux.Microsoft.NETCore.Runtime.ObjWriter.props b/nuget/Microsoft.NETCore.Runtime.ObjWriter/runtime.Linux.Microsoft.NETCore.Runtime.ObjWriter.props new file mode 100644 index 0000000000000..eb7f16da6d7ee --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.ObjWriter/runtime.Linux.Microsoft.NETCore.Runtime.ObjWriter.props @@ -0,0 +1,6 @@ + + + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.ObjWriter/runtime.OSX.Microsoft.NETCore.Runtime.ObjWriter.props b/nuget/Microsoft.NETCore.Runtime.ObjWriter/runtime.OSX.Microsoft.NETCore.Runtime.ObjWriter.props new file mode 100644 index 0000000000000..5ae09a3211786 --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.ObjWriter/runtime.OSX.Microsoft.NETCore.Runtime.ObjWriter.props @@ -0,0 +1,6 @@ + + + + + + diff --git a/nuget/Microsoft.NETCore.Runtime.ObjWriter/runtime.Windows_NT.Microsoft.NETCore.Runtime.ObjWriter.props b/nuget/Microsoft.NETCore.Runtime.ObjWriter/runtime.Windows_NT.Microsoft.NETCore.Runtime.ObjWriter.props new file mode 100644 index 0000000000000..f2e842f9163fb --- /dev/null +++ b/nuget/Microsoft.NETCore.Runtime.ObjWriter/runtime.Windows_NT.Microsoft.NETCore.Runtime.ObjWriter.props @@ -0,0 +1,6 @@ + + + + + + diff --git a/nuget/builds.targets b/nuget/builds.targets new file mode 100644 index 0000000000000..d58f010d3939b --- /dev/null +++ b/nuget/builds.targets @@ -0,0 +1,31 @@ + + + + true + + + true + + + false + + + + + + + + <_projectsToBuild Include="@(Project)" Condition="'%(Project.PackageTargetRuntime)' == '$(PackageRID)'" /> + + + + <_projectsToBuild Include="@(Project)" Condition="'%(Project.PackageTargetRuntime)' == ''" /> + + + + + + + \ No newline at end of file diff --git a/nuget/descriptions.json b/nuget/descriptions.json new file mode 100644 index 0000000000000..5d981f5466dd5 --- /dev/null +++ b/nuget/descriptions.json @@ -0,0 +1,42 @@ +[ + { + "Name": "RuntimePackage", + "Description": "Internal implementation package not meant for direct consumption. Please do not reference directly.", + "CommonTypes": [ ] + }, + { + "Name": "NuGet3MinVersion", + "Description": "When using NuGet 3.x this package requires at least version {0}.", + "CommonTypes": [ ] + }, + { + "Name": "Microsoft.NETCore.Runtime.Mono.LLVM.Sdk", + "Description": "The .NET Core fork of the LLVM project, used to compile the Mono .NET Core runtime in LLVM JIT mode. Internal implementation package not meant for direct consumption. Please do not reference directly.", + "CommonTypes": [ ] + }, + { + "Name": "Microsoft.NETCore.Runtime.Mono.LLVM.Sdk.Debug", + "Description": "The .NET Core fork of the LLVM project, used to compile the Mono .NET Core runtime in LLVM JIT mode (Debug runtime). Internal implementation package not meant for direct consumption. Please do not reference directly.", + "CommonTypes": [ ] + }, + { + "Name": "Microsoft.NETCore.Runtime.Mono.LLVM.Tools", + "Description": "The llvm-as, llc and opt tools, used by the Mono .NET Core runtime in LLVM AOT mode.", + "CommonTypes": [ ] + }, + { + "Name": "Microsoft.NETCore.Runtime.Mono.LLVM.Tools.Debug", + "Description": "The llvm-as, llc and opt tools, used by the Mono .NET Core runtime in LLVM AOT mode (Debug runtime).", + "CommonTypes": [ ] + }, + { + "Name": "Microsoft.NETCore.Runtime.ObjWriter", + "Description": "ELF/PE/Mach-O object file writer based on LLVM used in .NET AOT compiler. Internal implementation package not meant for direct consumption. Please do not reference directly.", + "CommonTypes": [ ] + }, + { + "Name": "Microsoft.NETCore.Runtime.JIT.Tools", + "Description": "Tools such as FileCheck and llvm-mca used for testing the .NET JIT compiler. Internal implementation package not meant for direct consumption. Please do not reference directly.", + "CommonTypes": [ ] + } +] diff --git a/nuget/packageIndex.json b/nuget/packageIndex.json new file mode 100644 index 0000000000000..7a73a41bfdf76 --- /dev/null +++ b/nuget/packageIndex.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/nuget/packages.builds b/nuget/packages.builds new file mode 100644 index 0000000000000..74792043d64f4 --- /dev/null +++ b/nuget/packages.builds @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/nuget/packaging.props b/nuget/packaging.props new file mode 100644 index 0000000000000..3424836526167 --- /dev/null +++ b/nuget/packaging.props @@ -0,0 +1,39 @@ + + + + + $(MSBuildThisFileDirectory)/descriptions.json + $(RepoRoot)/llvm/LICENSE.TXT + $(RepoRoot)/THIRD-PARTY-NOTICES.TXT + + https://go.microsoft.com/fwlink/?LinkID=799421 + + https://dot.net + https://github.com/dotnet/llvm-project/blob/dotnet/main/llvm/LICENSE.TXT + + $(MSBuildThisFileDirectory)/packageIndex.json + + + true + + + + + + + true + + + true + + + + + + true + + + diff --git a/polly/lib/External/isl/imath/tests/linux/Dockerfile b/polly/lib/External/isl/imath/tests/linux/Dockerfile deleted file mode 100644 index 50e1a91e8f530..0000000000000 --- a/polly/lib/External/isl/imath/tests/linux/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -# Build IMath and run tests with GCC on Linux. -# -# Usage (from the imath root): -# -# docker run --rm -it "$(docker build -f tests/linux/Dockerfile -q .)" -# -FROM alpine:latest AS base - -RUN apk add --no-cache bash build-base gcc gmp-dev make python2 - -FROM base AS test -COPY . /imath -WORKDIR /imath -CMD make distclean examples check diff --git a/utils/bazel/.bazelignore b/utils/bazel/.bazelignore deleted file mode 100644 index 1463bcc9c490e..0000000000000 --- a/utils/bazel/.bazelignore +++ /dev/null @@ -1,2 +0,0 @@ -llvm-project-overlay -examples diff --git a/utils/bazel/.bazelrc b/utils/bazel/.bazelrc deleted file mode 100644 index a89cd17955c16..0000000000000 --- a/utils/bazel/.bazelrc +++ /dev/null @@ -1,196 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -############################################################################### -# Common flags that apply to all configurations. -# Use sparingly for things common to all compilers and platforms. -############################################################################### -# Prevent invalid caching if input files are modified during a build. -build --experimental_guard_against_concurrent_changes - -############################################################################### -# Options to select different strategies for linking potential dependent -# libraries. The default leaves it disabled. -############################################################################### - -build:zlib_external --repo_env=BAZEL_LLVM_ZLIB_STRATEGY=external -build:zlib_system --repo_env=BAZEL_LLVM_ZLIB_STRATEGY=system - -build:terminfo_external --repo_env=BAZEL_LLVM_TERMINFO_STRATEGY=external -build:terminfo_system --repo_env=BAZEL_LLVM_TERMINFO_STRATEGY=system - -############################################################################### -# Options for "generic_clang" builds: these options should generally apply to -# builds using a Clang-based compiler, and default to the `clang` executable on -# the `PATH`. While these are provided for convenience and may serve as a -# reference, it would be preferable for users to configure an explicit C++ -# toolchain instead of relying on `.bazelrc` files. -############################################################################### - -# Set the default compiler to the `clang` binary on the `PATH`. -build:generic_clang --repo_env=CC=clang - -# C++14 standard version is required. -build:generic_clang --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 - -# Use `-Wall` and `-Werror` for Clang. -build:generic_clang --copt=-Wall --copt=-Werror --host_copt=-Wall --host_copt=-Werror - -# The Clang available on MacOS has a warning that isn't clean on MLIR code. The -# warning doesn't show up with more recent Clangs, so just disable for now. -build:generic_clang --cxxopt=-Wno-range-loop-analysis --host_cxxopt=-Wno-range-loop-analysis - -# Build errors are not a helpful way to enforce deprecation in-repo and it is -# not the point of the Bazel build to catch usage of deprecated APIs. -build:generic_clang --copt=-Wno-deprecated --host_copt=-Wno-deprecated - -############################################################################### -# Options for "generic_gcc" builds: these options should generally apply to -# builds using a GCC-based compiler, and default to the `gcc` executable on -# the `PATH`. While these are provided for convenience and may serve as a -# reference, it would be preferable for users to configure an explicit C++ -# toolchain instead of relying on `.bazelrc` files. -############################################################################### - -# Set the default compiler to the `gcc` binary on the `PATH`. -build:generic_gcc --repo_env=CC=gcc - -# C++14 standard version is required. -build:generic_gcc --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 - -# Build errors are not a helpful way to enforce deprecation in-repo and it is -# not the point of the Bazel build to catch usage of deprecated APIs. -build:generic_gcc --copt=-Wno-deprecated --host_copt=-Wno-deprecated - -# Disable GCC warnings that are noisy and/or false positives on LLVM code. -# These need to be global as some code triggering these is in header files. -build:generic_gcc --copt=-Wno-unused-parameter --host_copt=-Wno-unused-parameter -build:generic_gcc --copt=-Wno-comment --host_copt=-Wno-comment -build:generic_gcc --cxxopt=-Wno-class-memaccess --host_cxxopt=-Wno-class-memaccess -build:generic_gcc --copt=-Wno-maybe-uninitialized --host_copt=-Wno-maybe-uninitialized -build:generic_gcc --copt=-Wno-misleading-indentation --host_copt=-Wno-misleading-indentation - -# Use `-Werror` for GCC to make sure warnings don't slip past. -build:generic_gcc --copt=-Werror --host_copt=-Werror - -############################################################################### -# Generic Windows flags common to both MSVC and Clang. -############################################################################### - -# C++14 standard version is required. -build:windows --cxxopt=/std:c++14 --host_cxxopt=/std:c++14 - -# Other generic dialect flags. -build:windows --copt=/Zc:strictStrings --host_copt=/Zc:strictStrings -build:windows --copt=/Oi --host_copt=/Oi -build:windows --cxxopt=/Zc:rvalueCast --host_cxxopt=/Zc:rvalueCast - -# Use the more flexible bigobj format for C++ files that have lots of symbols. -build:windows --cxxopt=/bigobj --host_cxxopt=/bigobj - -############################################################################### -# Windows specific flags for building with MSVC. -############################################################################### - -build:msvc --config=windows - -build:msvc --copt=/WX --host_copt=/WX # Treat warnings as errors... -# ...but disable the ones that are violated -build:msvc --copt=/wd4141 --host_copt=/wd4141 # inline used more than once -build:msvc --copt=/wd4244 --host_copt=/wd4244 # conversion type -> type -build:msvc --copt=/wd4267 --host_copt=/wd4267 # conversion size_t -> type -build:msvc --copt=/wd4273 --host_copt=/wd4273 # multiple definitions with different dllimport -build:msvc --copt=/wd4319 --host_copt=/wd4319 # zero-extending after complement -build:msvc --copt=/wd4624 --host_copt=/wd4624 # destructor was implicitly defined as deleted -build:msvc --copt=/wd4804 --host_copt=/wd4804 # comparisons between bool and int -build:msvc --copt=/wd4805 --host_copt=/wd4805 # comparisons between bool and int - -build:msvc --linkopt=/WX --host_linkopt=/WX # Treat warnings as errors... -# ...but disable the ones that are violated. -build:msvc --linkopt=/IGNORE:4001 --host_linkopt=/IGNORE:4001 # no object files - -############################################################################### -# Options for Windows `clang-cl` builds. -############################################################################### - -# We just start with the baseline Windows config as `clang-cl` doesn't accept -# some of the generic Clang flags. -build:clang-cl --config=windows - -# Switch from MSVC to the `clang-cl` compiler. -build:clang-cl --compiler=clang-cl - -# Use Clang's internal warning flags instead of the ones that sometimes map -# through to MSVC's flags. -build:clang-cl --copt=/clang:-Wall --host_copt=/clang:-Wall -build:clang-cl --copt=/clang:-Werror --host_copt=/clang:-Werror - -# This doesn't appear to be enforced by any upstream bot. -build:clang-cl --copt=/clang:-Wno-unused --host_copt=/clang:-Wno-unused - -# There appears to be an unused constant in GoogleTest on Windows. -build:clang-cl --copt=/clang:-Wno-unused-const-variable --host_copt=/clang:-Wno-unused-const-variable - -# Disable some warnings hit even with `clang-cl` in Clang's own code. -build:clang-cl --copt=/clang:-Wno-inconsistent-dllimport --host_copt=/clang:-Wno-inconsistent-dllimport -build:clang-cl --cxxopt=/clang:-Wno-c++11-narrowing --host_cxxopt=/clang:-Wno-c++11-narrowing - -############################################################################### - -############################################################################### -# Configuration for building remotely using Remote Build Execution (RBE) -# Based on https://github.com/bazelbuild/bazel-toolchains/blob/master/bazelrc/bazel-1.0.0.bazelrc -############################################################################### - -build:rbe --remote_instance_name=projects/llvm-bazel/instances/default_instance - -# Depending on how many machines are in the remote execution instance, setting -# this higher can make builds faster by allowing more jobs to run in parallel. -# Setting it too high can result in jobs that timeout, however, while waiting -# for a remote machine to execute them. -build:rbe --jobs=150 - -# Set several flags related to specifying the platform, toolchain and java -# properties. -# These flags should only be used as is for the rbe-ubuntu16-04 container -# and need to be adapted to work with other toolchain containers. -build:rbe --host_javabase=@rbe_default//java:jdk -build:rbe --javabase=@rbe_default//java:jdk -build:rbe --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8 -build:rbe --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8 -build:rbe --crosstool_top=@rbe_default//cc:toolchain -build:rbe --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 -# Platform flags: -# The toolchain container used for execution is defined in the target indicated -# by "extra_execution_platforms", "host_platform" and "platforms". -# More about platforms: https://docs.bazel.build/versions/main/platforms.html -build:rbe --extra_toolchains=@rbe_default//config:cc-toolchain -build:rbe --extra_execution_platforms=@rbe_default//config:platform -build:rbe --host_platform=@rbe_default//config:platform -build:rbe --platforms=@rbe_default//config:platform - -build:rbe --define=EXECUTOR=remote - -# Enable remote execution so actions are performed on the remote systems. -build:rbe --remote_executor=grpcs://remotebuildexecution.googleapis.com - -# Enforce stricter environment rules, which eliminates some non-hermetic -# behavior and therefore improves both the remote cache hit rate and the -# correctness and repeatability of the build. -build:rbe --incompatible_strict_action_env=true - -# Set a higher timeout value, just in case. -build:rbe --remote_timeout=3600 - -# Local disk cache is incompatible with remote execution (for obvious reasons). -build:rbe --disk_cache="" - -# Enable authentication. This will pick up application default credentials by -# default. You can use --google_credentials=some_file.json to use a service -# account credential instead. -build:rbe --google_default_credentials=true - -# The user.bazelrc file is not checked in but available for local mods. -# Always keep this at the end of the file so that user flags override. -try-import %workspace%/user.bazelrc diff --git a/utils/bazel/.bazelversion b/utils/bazel/.bazelversion deleted file mode 100644 index fcdb2e109f68c..0000000000000 --- a/utils/bazel/.bazelversion +++ /dev/null @@ -1 +0,0 @@ -4.0.0 diff --git a/utils/bazel/.gitignore b/utils/bazel/.gitignore deleted file mode 100644 index 6bb9fd1ef0a2a..0000000000000 --- a/utils/bazel/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# Bazel artifacts -**/bazel-* - -# Per-user bazelrc files -user.bazelrc diff --git a/utils/bazel/BUILD.bazel b/utils/bazel/BUILD.bazel deleted file mode 100644 index dd837093c62ac..0000000000000 --- a/utils/bazel/BUILD.bazel +++ /dev/null @@ -1,5 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -# Required to reference .bzl files in this package diff --git a/utils/bazel/README.md b/utils/bazel/README.md deleted file mode 100644 index fe8ead32f7d90..0000000000000 --- a/utils/bazel/README.md +++ /dev/null @@ -1,79 +0,0 @@ -# Introduction - -*Warning* The Bazel build is experimental and best-effort, supported in line -with the policy for -[LLVM's peripheral support tier](https://llvm.org/docs/SupportPolicy.html). -LLVM's official build system is CMake. If in doubt use that. If you make changes -to LLVM, you're expected to update the CMake build but you don't need to update -Bazel build files. Reviewers should not ask authors to update Bazel build files -unless the author has opted in to support Bazel. Keeping the Bazel build files -up-to-date is on the people who use the Bazel build. - -[Bazel](https://bazel.build/) is a multi-language build system focused on -reproducible builds to enable dependency analysis and caching for fast -incremental builds. - -The main motivation behind the existence of an LLVM Bazel build is that a number -of projects that depend on LLVM use Bazel, and Bazel works best when it knows -about the whole source tree (as opposed to installing artifacts coming from -another build system). Community members are also welcome to use Bazel for their -own development as long as they continue to maintain the official CMake build -system. See also, the -[proposal](https://github.com/llvm/llvm-www/blob/main/proposals/LP0002-BazelBuildConfiguration.md) -for adding this configuration. - -# Quick Start - -1. `git clone https://github.com/llvm/llvm-project.git; cd llvm-project` if - you don't have a checkout yet. -2. Install Bazel at the version indicated by [.bazelversion](./.bazelversion), - following the official instructions, if you don't have it installed yet: - https://docs.bazel.build/versions/main/install.html. -3. `cd utils/bazel` -4. `bazel build --config=generic_clang @llvm-project//...` (if building on Unix - with Clang). `--config=generic_gcc` and `--config=msvc` are also available. - - -# Configuration - -The repository `.bazelrc` will import user-specific settings from a -`user.bazelrc` file (in addition to the standard locations). Adding your typical -config setting is recommended. - -```.bazelrc -build --config=generic_clang -``` - -You can enable -[disk caching](https://docs.bazel.build/versions/main/remote-caching.html#disk-cache), -which will cache build results - -```.bazelrc -build --disk_cache=~/.cache/bazel-disk-cache -``` - -You can instruct Bazel to use a ramdisk for its sandboxing operations via -[--sandbox_base](https://docs.bazel.build/versions/main/command-line-reference.html#flag--sandbox_base), -which can help avoid IO bottlenecks for the symlink stragegy used for -sandboxing. This is especially important with many inputs and many cores (see -https://github.com/bazelbuild/bazel/issues/11868): - -```.bazelrc -build --sandbox_base=/dev/shm -``` - -Bear in mind that this requires that your ramdisk is of sufficient size to hold -any temporary files. Anecdotally, 1GB should be sufficient. - -# Coverage - -The LLVM, MLIR, and Clang subprojects have configurations for Linux (Clang and -GCC), Mac (Clang and GCC), and Windows (MSVC). Configuration options that are -platform-specific are selected for in defines. Many are also hardcoded to the -values currently used by all supported configurations. If there is a -configuration you'd like to use that isn't supported, please send a patch. - -# Usage - -To use in dependent projects using Bazel, you can import LLVM and then use the -provided configuration rule. See example usage in the `examples/` directory. diff --git a/utils/bazel/WORKSPACE b/utils/bazel/WORKSPACE deleted file mode 100644 index 572c9fee878ff..0000000000000 --- a/utils/bazel/WORKSPACE +++ /dev/null @@ -1,86 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") - -SKYLIB_VERSION = "1.0.3" - -http_archive( - name = "bazel_skylib", - sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version=SKYLIB_VERSION), - "https://github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version=SKYLIB_VERSION), - ], -) - -new_local_repository( - name = "llvm-raw", - path = "../../", - build_file_content = "# empty", -) - -load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure") - -llvm_configure(name = "llvm-project") - -load("@llvm-raw//utils/bazel:terminfo.bzl", "llvm_terminfo_from_env") - -maybe( - llvm_terminfo_from_env, - name = "llvm_terminfo", -) - -maybe( - http_archive, - name = "zlib", - build_file = "@llvm-raw//utils/bazel/third_party_build:zlib.BUILD", - sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1", - strip_prefix = "zlib-1.2.11", - urls = [ - "https://storage.googleapis.com/mirror.tensorflow.org/zlib.net/zlib-1.2.11.tar.gz", - "https://zlib.net/zlib-1.2.11.tar.gz", - ], -) - -load("@llvm-raw//utils/bazel:zlib.bzl", "llvm_zlib_from_env") - -maybe( - llvm_zlib_from_env, - name = "llvm_zlib", - external_zlib = "@zlib", -) - -maybe( - http_archive, - name = "vulkan_headers", - build_file = "@llvm-raw//utils/bazel/third_party_build:vulkan_headers.BUILD", - sha256 = "19f491784ef0bc73caff877d11c96a48b946b5a1c805079d9006e3fbaa5c1895", - strip_prefix = "Vulkan-Headers-9bd3f561bcee3f01d22912de10bb07ce4e23d378", - urls = [ - "https://github.com/KhronosGroup/Vulkan-Headers/archive/9bd3f561bcee3f01d22912de10bb07ce4e23d378.tar.gz", - ], -) - -load("@llvm-raw//utils/bazel:vulkan_sdk.bzl", "vulkan_sdk_setup") - -maybe( - vulkan_sdk_setup, - name = "vulkan_sdk", -) - -http_archive( - name = "bazel_toolchains", - sha256 = "1adf5db506a7e3c465a26988514cfc3971af6d5b3c2218925cd6e71ee443fc3f", - strip_prefix = "bazel-toolchains-4.0.0", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/releases/download/4.0.0/bazel-toolchains-4.0.0.tar.gz", - "https://github.com/bazelbuild/bazel-toolchains/releases/download/4.0.0/bazel-toolchains-4.0.0.tar.gz", - ], -) - -load("@bazel_toolchains//rules:rbe_repo.bzl", "rbe_autoconfig") - -rbe_autoconfig(name = "rbe_default") diff --git a/utils/bazel/configure.bzl b/utils/bazel/configure.bzl deleted file mode 100644 index 4c5ab8bd09724..0000000000000 --- a/utils/bazel/configure.bzl +++ /dev/null @@ -1,112 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -"""Helper macros to configure the LLVM overlay project.""" - -load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -load(":zlib.bzl", "llvm_zlib_disable", "llvm_zlib_system") -load(":terminfo.bzl", "llvm_terminfo_disable", "llvm_terminfo_system") - -# Directory of overlay files relative to WORKSPACE -DEFAULT_OVERLAY_PATH = "llvm-project-overlay" - -DEFAULT_TARGETS = [ - "AArch64", - "AMDGPU", - "ARM", - "AVR", - "BPF", - "Hexagon", - "Lanai", - "Mips", - "MSP430", - "NVPTX", - "PowerPC", - "RISCV", - "Sparc", - "SystemZ", - "WebAssembly", - "X86", - "XCore", -] - -def _overlay_directories(repository_ctx): - src_path = repository_ctx.path(Label("//:WORKSPACE")).dirname - bazel_path = src_path.get_child("utils").get_child("bazel") - overlay_path = bazel_path.get_child("llvm-project-overlay") - script_path = bazel_path.get_child("overlay_directories.py") - - python_bin = repository_ctx.which("python3") - if not python_bin: - # Windows typically just defines "python" as python3. The script itself - # contains a check to ensure python3. - python_bin = repository_ctx.which("python") - - if not python_bin: - fail("Failed to find python3 binary") - - cmd = [ - python_bin, - script_path, - "--src", - src_path, - "--overlay", - overlay_path, - "--target", - ".", - ] - exec_result = repository_ctx.execute(cmd, timeout = 20) - - if exec_result.return_code != 0: - fail(("Failed to execute overlay script: '{cmd}'\n" + - "Exited with code {return_code}\n" + - "stdout:\n{stdout}\n" + - "stderr:\n{stderr}\n").format( - cmd = " ".join([str(arg) for arg in cmd]), - return_code = exec_result.return_code, - stdout = exec_result.stdout, - stderr = exec_result.stderr, - )) - -def _llvm_configure_impl(repository_ctx): - _overlay_directories(repository_ctx) - - # Create a starlark file with the requested LLVM targets. - targets = repository_ctx.attr.targets - repository_ctx.file( - "llvm/targets.bzl", - content = "llvm_targets = " + str(targets), - executable = False, - ) - -llvm_configure = repository_rule( - implementation = _llvm_configure_impl, - local = True, - configure = True, - attrs = { - "targets": attr.string_list(default = DEFAULT_TARGETS), - }, -) - -def llvm_disable_optional_support_deps(): - maybe( - llvm_zlib_disable, - name = "llvm_zlib", - ) - - maybe( - llvm_terminfo_disable, - name = "llvm_terminfo", - ) - -def llvm_use_system_support_deps(): - maybe( - llvm_zlib_system, - name = "llvm_zlib", - ) - - maybe( - llvm_terminfo_system, - name = "llvm_terminfo", - ) diff --git a/utils/bazel/deps_impl/BUILD.bazel b/utils/bazel/deps_impl/BUILD.bazel deleted file mode 100644 index 291c60fe3af2d..0000000000000 --- a/utils/bazel/deps_impl/BUILD.bazel +++ /dev/null @@ -1,5 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -# Required to reference files in this package diff --git a/utils/bazel/deps_impl/terminfo_disable.BUILD b/utils/bazel/deps_impl/terminfo_disable.BUILD deleted file mode 100644 index a39da265cab65..0000000000000 --- a/utils/bazel/deps_impl/terminfo_disable.BUILD +++ /dev/null @@ -1,10 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -# Empty stub library. This doesn't include any terminfo library and doesn't set -# the LLVM `#define`s to enable usage of terminfo. -cc_library( - name = "terminfo", - visibility = ["//visibility:public"], -) diff --git a/utils/bazel/deps_impl/terminfo_system.BUILD b/utils/bazel/deps_impl/terminfo_system.BUILD deleted file mode 100644 index 51643bb63e61f..0000000000000 --- a/utils/bazel/deps_impl/terminfo_system.BUILD +++ /dev/null @@ -1,15 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -# Wrapper library for some system terminfo. Using this only works if the -# toolchain already has the relevant library search paths configured. It also -# sets the relevant LLVM `#define`s to enoble using terminfo. -cc_library( - name = "terminfo", - defines = ["LLVM_ENABLE_TERMINFO=1"], - # Note that we will replace these link options with ones needed to - # effectively link against a terminfo providing library on the system. - linkopts = {TERMINFO_LINKOPTS}, - visibility = ["//visibility:public"], -) diff --git a/utils/bazel/deps_impl/terminfo_test.c b/utils/bazel/deps_impl/terminfo_test.c deleted file mode 100644 index 3b401728e7973..0000000000000 --- a/utils/bazel/deps_impl/terminfo_test.c +++ /dev/null @@ -1,17 +0,0 @@ -/* -This file is licensed under the Apache License v2.0 with LLVM Exceptions. -See https://llvm.org/LICENSE.txt for license information. -SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -*/ - -extern int setupterm(char *term, int filedes, int *errret); -extern struct term *set_curterm(struct term *termp); -extern int del_curterm(struct term *termp); -extern int tigetnum(char *capname); - -int main() { - setupterm(0, 0, 0); - set_curterm(0); - del_curterm(0); - tigetnum(0); -} diff --git a/utils/bazel/deps_impl/zlib_disable.BUILD b/utils/bazel/deps_impl/zlib_disable.BUILD deleted file mode 100644 index e2e4997d2ab5a..0000000000000 --- a/utils/bazel/deps_impl/zlib_disable.BUILD +++ /dev/null @@ -1,10 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -# Empty stub library. This doesn't include zlib and doesn't set the LLVM -# `#define`s to enable it. -cc_library( - name = "zlib", - visibility = ["//visibility:public"], -) diff --git a/utils/bazel/deps_impl/zlib_external.BUILD b/utils/bazel/deps_impl/zlib_external.BUILD deleted file mode 100644 index 7e505ffd105a4..0000000000000 --- a/utils/bazel/deps_impl/zlib_external.BUILD +++ /dev/null @@ -1,11 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -# Wrapper around an external zlib library to add the relevant LLVM `#define`s. -cc_library( - name = "zlib", - defines = ["LLVM_ENABLE_ZLIB=1"], - visibility = ["//visibility:public"], - deps = ["@external_zlib_repo//:zlib_rule"], -) diff --git a/utils/bazel/deps_impl/zlib_system.BUILD b/utils/bazel/deps_impl/zlib_system.BUILD deleted file mode 100644 index 8f591f0a97e44..0000000000000 --- a/utils/bazel/deps_impl/zlib_system.BUILD +++ /dev/null @@ -1,13 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -# Wrapper library for the system's zlib. Using this only works if the toolchain -# already has the relevant header search and library search paths configured. -# It also sets the relevant LLVM `#define`s to enable zlib. -cc_library( - name = "zlib", - defines = ["LLVM_ENABLE_ZLIB=1"], - linkopts = ["-lz"], - visibility = ["//visibility:public"], -) diff --git a/utils/bazel/examples/http_archive/WORKSPACE b/utils/bazel/examples/http_archive/WORKSPACE deleted file mode 100644 index ea604f5f69d6d..0000000000000 --- a/utils/bazel/examples/http_archive/WORKSPACE +++ /dev/null @@ -1,45 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -"""An example WORKSPACE for configuring LLVM using http_archive.""" - -workspace(name = "http_archive_example") - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -SKYLIB_VERSION = "1.0.3" - -http_archive( - name = "bazel_skylib", - sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version=SKYLIB_VERSION), - "https://github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version=SKYLIB_VERSION), - ], -) - -# Replace with the LLVM commit you want to use. -LLVM_COMMIT = "81d5412439efd0860c0a8dd51b831204f118d485" - -# The easiest way to calculate this for a new commit is to set it to empty and -# then run a bazel build and it will report the digest necessary to cache the -# archive and make the build reproducible. -LLVM_SHA256 = "50b3ef31b228ea0c96ae074005bfac087c56e6a4b1c147592dd33f41cad0706b" - -http_archive( - name = "llvm-raw", - build_file_content = "# empty", - sha256 = LLVM_SHA256, - strip_prefix = "llvm-project-" + LLVM_COMMIT, - urls = ["https://github.com/llvm/llvm-project/archive/{commit}.tar.gz".format(commit = LLVM_COMMIT)], -) - -load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure", "llvm_disable_optional_support_deps") - -llvm_configure(name = "llvm-project") - -# Disables optional dependencies for Support like zlib and terminfo. You may -# instead want to configure them using the macros in the corresponding bzl -# files. -llvm_disable_optional_support_deps() diff --git a/utils/bazel/examples/submodule/WORKSPACE b/utils/bazel/examples/submodule/WORKSPACE deleted file mode 100644 index e702caa78b2f7..0000000000000 --- a/utils/bazel/examples/submodule/WORKSPACE +++ /dev/null @@ -1,34 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -"""An example WORKSPACE for configuring LLVM using a git submodule.""" - -workspace(name = "submodule_example") - -SKYLIB_VERSION = "1.0.3" - -http_archive( - name = "bazel_skylib", - sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version=SKYLIB_VERSION), - "https://github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version=SKYLIB_VERSION), - ], -) - -new_local_repository( - name = "llvm-raw", - build_file_content = "# empty", - # Or wherever your submodule is located. - path = "third_party/llvm-project", -) - -load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure", "llvm_disable_optional_support_deps") - -llvm_configure(name = "llvm-project") - -# Disables optional dependencies for Support like zlib and terminfo. You may -# instead want to configure them using the macros in the corresponding bzl -# files. -llvm_disable_optional_support_deps() diff --git a/utils/bazel/llvm-project-overlay/.bazelignore b/utils/bazel/llvm-project-overlay/.bazelignore deleted file mode 100644 index fad56edd2b715..0000000000000 --- a/utils/bazel/llvm-project-overlay/.bazelignore +++ /dev/null @@ -1,6 +0,0 @@ -# Ignore the utils/bazel directory when this is overlayed onto the repo root. -utils/bazel -# Ignore third-party projects. These should be configured separately and some -# include Bazel configs. -libcxx/utils/google-benchmark -third-party diff --git a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel deleted file mode 100644 index a2b1e0f33073d..0000000000000 --- a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel +++ /dev/null @@ -1,2142 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -load("//llvm:tblgen.bzl", "gentbl") -load("//llvm:binary_alias.bzl", "binary_alias") -load("//llvm:cc_plugin_library.bzl", "cc_plugin_library") - -package( - default_visibility = ["//visibility:public"], - licenses = ["notice"], -) - -exports_files([ - "tools/clang-format/clang-format.el", - "tools/clang-format/clang-format-test.el", - "tools/clang-format/clang-format.py", - "tools/clang-rename/clang-rename.el", - "tools/extra/clang-include-fixer/tool/clang-include-fixer.el", - "tools/extra/clang-include-fixer/tool/clang-include-fixer-test.el", -]) - -cc_binary( - name = "clang-tblgen", - srcs = glob([ - "utils/TableGen/*.cpp", - "utils/TableGen/*.h", - ]), - copts = [ - "$(STACK_FRAME_UNLIMITED)", - ], - stamp = 0, - deps = [ - "//llvm:Support", - "//llvm:TableGen", - "//llvm:config", - ], -) - -gentbl( - name = "diagnostic_defs_gen", - tbl_outs = [( - "-gen-clang-diags-defs -clang-component=%s" % c, - "include/clang/Basic/Diagnostic%sKinds.inc" % c, - ) for c in [ - "AST", - "Analysis", - "Comment", - "Common", - "CrossTU", - "Driver", - "Frontend", - "Lex", - "Parse", - "Refactoring", - "Sema", - "Serialization", - ]] + [ - ( - "-gen-clang-diag-groups", - "include/clang/Basic/DiagnosticGroups.inc", - ), - ( - "-gen-clang-diags-index-name", - "include/clang/Basic/DiagnosticIndexName.inc", - ), - ], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/Diagnostic.td", - td_srcs = glob(["include/clang/Basic/*.td"]), -) - -gentbl( - name = "basic_arm_neon_inc_gen", - tbl_outs = [( - "-gen-arm-neon-sema", - "include/clang/Basic/arm_neon.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/arm_neon.td", - td_srcs = [ - "include/clang/Basic/arm_neon.td", - "include/clang/Basic/arm_neon_incl.td", - ], -) - -gentbl( - name = "basic_arm_fp16_inc_gen", - tbl_outs = [( - "-gen-arm-neon-sema", - "include/clang/Basic/arm_fp16.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/arm_fp16.td", - td_srcs = [ - "include/clang/Basic/arm_fp16.td", - "include/clang/Basic/arm_neon_incl.td", - ], -) - -gentbl( - name = "basic_arm_mve_aliases_gen", - tbl_outs = [( - "-gen-arm-mve-builtin-aliases", - "include/clang/Basic/arm_mve_builtin_aliases.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/arm_mve.td", - td_srcs = [ - "include/clang/Basic/arm_mve.td", - "include/clang/Basic/arm_mve_defs.td", - ], -) - -gentbl( - name = "basic_arm_sve_builtins_gen", - tbl_outs = [( - "-gen-arm-sve-builtins", - "include/clang/Basic/arm_sve_builtins.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/arm_sve.td", - td_srcs = [ - "include/clang/Basic/arm_sve.td", - ], -) - -gentbl( - name = "basic_arm_sve_builtin_cg_gen", - tbl_outs = [( - "-gen-arm-sve-builtin-codegen", - "include/clang/Basic/arm_sve_builtin_cg.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/arm_sve.td", - td_srcs = [ - "include/clang/Basic/arm_sve.td", - ], -) - -gentbl( - name = "basic_arm_sve_typeflags_gen", - tbl_outs = [( - "-gen-arm-sve-typeflags", - "include/clang/Basic/arm_sve_typeflags.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/arm_sve.td", - td_srcs = [ - "include/clang/Basic/arm_sve.td", - ], -) - -gentbl( - name = "basic_arm_sve_sema_rangechecks_gen", - tbl_outs = [( - "-gen-arm-sve-sema-rangechecks", - "include/clang/Basic/arm_sve_sema_rangechecks.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/arm_sve.td", - td_srcs = [ - "include/clang/Basic/arm_sve.td", - ], -) - -gentbl( - name = "basic_arm_mve_cg_gen", - tbl_outs = [( - "-gen-arm-mve-builtin-codegen", - "include/clang/Basic/arm_mve_builtin_cg.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/arm_mve.td", - td_srcs = [ - "include/clang/Basic/arm_mve.td", - "include/clang/Basic/arm_mve_defs.td", - ], -) - -gentbl( - name = "basic_arm_mve_inc_gen", - tbl_outs = [( - "-gen-arm-mve-builtin-def", - "include/clang/Basic/arm_mve_builtins.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/arm_mve.td", - td_srcs = [ - "include/clang/Basic/arm_mve.td", - "include/clang/Basic/arm_mve_defs.td", - ], -) - -gentbl( - name = "basic_arm_mve_sema_gen", - tbl_outs = [( - "-gen-arm-mve-builtin-sema", - "include/clang/Basic/arm_mve_builtin_sema.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/arm_mve.td", - td_srcs = [ - "include/clang/Basic/arm_mve.td", - "include/clang/Basic/arm_mve_defs.td", - ], -) - -gentbl( - name = "basic_riscv_vector_builtins_gen", - tbl_outs = [( - "-gen-riscv-vector-builtins", - "include/clang/Basic/riscv_vector_builtins.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/riscv_vector.td", - td_srcs = [ - "include/clang/Basic/riscv_vector.td", - ], -) - -gentbl( - name = "basic_riscv_vector_builtin_cg_gen", - tbl_outs = [( - "-gen-riscv-vector-builtin-codegen", - "include/clang/Basic/riscv_vector_builtin_cg.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/riscv_vector.td", - td_srcs = [ - "include/clang/Basic/riscv_vector.td", - ], -) - -gentbl( - name = "basic_arm_cde_gen", - tbl_outs = [( - "-gen-arm-cde-builtin-def", - "include/clang/Basic/arm_cde_builtins.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/arm_cde.td", - td_srcs = [ - "include/clang/Basic/arm_cde.td", - "include/clang/Basic/arm_mve_defs.td", - ], -) - -gentbl( - name = "basic_arm_cde_aliases_gen", - tbl_outs = [( - "-gen-arm-cde-builtin-aliases", - "include/clang/Basic/arm_cde_builtin_aliases.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/arm_cde.td", - td_srcs = [ - "include/clang/Basic/arm_cde.td", - "include/clang/Basic/arm_mve_defs.td", - ], -) - -gentbl( - name = "basic_arm_cde_cg_gen", - tbl_outs = [( - "-gen-arm-cde-builtin-codegen", - "include/clang/Basic/arm_cde_builtin_cg.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/arm_cde.td", - td_srcs = [ - "include/clang/Basic/arm_cde.td", - "include/clang/Basic/arm_mve_defs.td", - ], -) - -gentbl( - name = "basic_arm_cde_sema_gen", - tbl_outs = [( - "-gen-arm-cde-builtin-sema", - "include/clang/Basic/arm_cde_builtin_sema.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/arm_cde.td", - td_srcs = [ - "include/clang/Basic/arm_cde.td", - "include/clang/Basic/arm_mve_defs.td", - ], -) - -gentbl( - name = "basic_attr_gen", - tbl_outs = [ - ( - "-gen-clang-attr-has-attribute-impl", - "include/clang/Basic/AttrHasAttributeImpl.inc", - ), - ( - "-gen-clang-attr-list", - "include/clang/Basic/AttrList.inc", - ), - ( - "-gen-clang-attr-subject-match-rule-list", - "include/clang/Basic/AttrSubMatchRulesList.inc", - ), - ], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/Attr.td", - td_srcs = [ - "include/clang/Basic/ASTNode.td", - "include/clang/Basic/Attr.td", - "include/clang/Basic/AttrDocs.td", - "include/clang/Basic/DeclNodes.td", - "include/clang/Basic/StmtNodes.td", - ], -) - -gentbl( - name = "libsema_openclbuiltins_inc_gen", - strip_include_prefix = "lib/Sema", - tbl_outs = [( - "-gen-clang-opencl-builtins", - "lib/Sema/OpenCLBuiltins.inc", - )], - tblgen = ":clang-tblgen", - td_file = "lib/Sema/OpenCLBuiltins.td", - td_srcs = [ - "lib/Sema/OpenCLBuiltins.td", - ], -) - -# Table definition files can be used for documentation: -filegroup( - name = "all_table_defs", - srcs = glob(["include/**/*.td"]), -) - -exports_files( - glob(["include/**/*.td"]), -) - -genrule( - name = "basic_version_gen", - outs = ["include/clang/Basic/Version.inc"], - cmd = ( - "echo '#define CLANG_VERSION 14.0.0' >> $@\n" + - "echo '#define CLANG_VERSION_MAJOR 14' >> $@\n" + - "echo '#define CLANG_VERSION_MINOR 0' >> $@\n" + - "echo '#define CLANG_VERSION_PATCHLEVEL 0' >> $@\n" + - "echo '#define CLANG_VERSION_STRING \"14.0.0\"' >> $@\n" - ), -) - -cc_library( - name = "config", - hdrs = [ - "include/clang/Basic/Version.inc", - "include/clang/Config/config.h", - ], - includes = ["include"], - deps = [ - # We rely on the LLVM config library to provide configuration defines. - "//llvm:config", - ], -) - -# TODO: This should get replaced with something that actually generates the -# correct version number. -genrule( - name = "vcs_version_gen", - # This should be under lib/Basic, but because of how the include paths - # are passed through bazel, it's easier to drop generated files next to - # the other includes. - outs = ["include/VCSVersion.inc"], - cmd = "echo '#define CLANG_REVISION \"git\"' > $@", -) - -# A hacky library to expose some internal headers of the `basic` library to its -# own implementation source files using a stripped include prefix rather than -# file-relative-inclusion. This is inherently non-modular as these headers will -# be repeated in the sources below for file-relative-inclusion. -cc_library( - name = "basic_internal_headers", - hdrs = glob([ - "lib/Basic/*.h", - ]), - features = ["-header_modules"], - strip_include_prefix = "lib/Basic", -) - -cc_library( - name = "basic", - srcs = [ - "include/clang/Basic/Version.inc", - "include/VCSVersion.inc", - ] + glob([ - "lib/Basic/*.cpp", - "lib/Basic/*.c", - "lib/Basic/*.h", - "lib/Basic/Targets/*.cpp", - "lib/Basic/Targets/*.h", - ]), - hdrs = glob([ - "include/clang/Basic/*.h", - ]), - copts = [ - "-DHAVE_VCS_VERSION_INC", - "$(STACK_FRAME_UNLIMITED)", - ], - includes = ["include"], - textual_hdrs = [ - "include/clang/Basic/arm_fp16.inc", - "include/clang/Basic/arm_mve_builtins.inc", - "include/clang/Basic/arm_mve_builtin_aliases.inc", - "include/clang/Basic/arm_mve_builtin_cg.inc", - "include/clang/Basic/arm_mve_builtin_sema.inc", - "include/clang/Basic/arm_neon.inc", - "include/clang/Basic/AttrHasAttributeImpl.inc", - "include/clang/Basic/AttrList.inc", - "include/clang/Basic/AttrSubMatchRulesList.inc", - "include/clang/Basic/DiagnosticASTKinds.inc", - "include/clang/Basic/DiagnosticGroups.inc", - "include/clang/Basic/DiagnosticRefactoringKinds.inc", - "include/clang/Basic/DiagnosticAnalysisKinds.inc", - "include/clang/Basic/DiagnosticSemaKinds.inc", - "include/clang/Basic/DiagnosticCommentKinds.inc", - "include/clang/Basic/DiagnosticParseKinds.inc", - "include/clang/Basic/DiagnosticLexKinds.inc", - "include/clang/Basic/DiagnosticSerializationKinds.inc", - "include/clang/Basic/DiagnosticFrontendKinds.inc", - "include/clang/Basic/DiagnosticDriverKinds.inc", - "include/clang/Basic/DiagnosticCrossTUKinds.inc", - "include/clang/Basic/DiagnosticCommonKinds.inc", - "include/clang/Basic/DiagnosticIndexName.inc", - ] + glob([ - "include/clang/Basic/*.def", - ]), - deps = [ - ":basic_arm_cde_gen", - ":basic_arm_fp16_inc_gen", - ":basic_arm_mve_aliases_gen", - ":basic_arm_mve_cg_gen", - ":basic_arm_mve_inc_gen", - ":basic_arm_mve_sema_gen", - ":basic_arm_neon_inc_gen", - ":basic_arm_sve_builtins_gen", - ":basic_arm_sve_typeflags_gen", - ":basic_attr_gen", - ":basic_internal_headers", - ":basic_riscv_vector_builtin_cg_gen", - ":basic_riscv_vector_builtins_gen", - ":config", - ":diagnostic_defs_gen", - ":sema_attr_gen", - "//llvm:Core", - "//llvm:FrontendOpenMP", - "//llvm:Instrumentation", - "//llvm:MC", - "//llvm:Support", - "//llvm:Target", - "//llvm:config", - ], -) - -cc_library( - name = "lex", - srcs = glob([ - "lib/Lex/*.cpp", - "lib/Lex/*.h", - ]), - hdrs = glob([ - "include/clang/Lex/*.h", - ]), - includes = ["include"], - deps = [ - ":basic", - ":config", - "//llvm:Support", - ], -) - -gentbl( - name = "ast_attr_gen", - tbl_outs = [ - ( - "-gen-clang-attr-ast-visitor", - "include/clang/AST/AttrVisitor.inc", - ), - ( - "-gen-clang-attr-classes", - "include/clang/AST/Attrs.inc", - ), - ( - "-gen-clang-attr-doc-table", - "lib/AST/AttrDocTable.inc", - ), - ( - "-gen-clang-attr-text-node-dump", - "include/clang/AST/AttrTextNodeDump.inc", - ), - ( - "-gen-clang-attr-node-traverse", - "include/clang/AST/AttrNodeTraverse.inc", - ), - ( - "-gen-clang-attr-impl", - "include/clang/AST/AttrImpl.inc", - ), - ], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/Attr.td", - td_srcs = [ - "include/clang/Basic/Attr.td", - "include/clang/Basic/AttrDocs.td", - "include/clang/Basic/ASTNode.td", - "include/clang/Basic/DeclNodes.td", - "include/clang/Basic/StmtNodes.td", - ], -) - -gentbl( - name = "ast_decl_nodes_gen", - tbl_outs = [( - "-gen-clang-decl-nodes", - "include/clang/AST/DeclNodes.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/DeclNodes.td", - td_srcs = [ - "include/clang/Basic/ASTNode.td", - "include/clang/Basic/DeclNodes.td", - ], -) - -gentbl( - name = "ast_stmt_nodes_gen", - tbl_outs = [( - "-gen-clang-stmt-nodes", - "include/clang/AST/StmtNodes.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/StmtNodes.td", - td_srcs = [ - "include/clang/Basic/ASTNode.td", - "include/clang/Basic/StmtNodes.td", - ], -) - -gentbl( - name = "ast_comment_nodes_gen", - tbl_outs = [( - "-gen-clang-comment-nodes", - "include/clang/AST/CommentNodes.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/CommentNodes.td", - td_srcs = [ - "include/clang/Basic/ASTNode.td", - "include/clang/Basic/CommentNodes.td", - ], -) - -gentbl( - name = "ast_comment_command_info_gen", - tbl_outs = [ - ( - "-gen-clang-comment-command-info", - "include/clang/AST/CommentCommandInfo.inc", - ), - ( - "-gen-clang-comment-command-list", - "include/clang/AST/CommentCommandList.inc", - ), - ], - tblgen = ":clang-tblgen", - td_file = "include/clang/AST/CommentCommands.td", - td_srcs = ["include/clang/AST/CommentCommands.td"], -) - -gentbl( - name = "ast_comment_html_tags_gen", - tbl_outs = [( - "-gen-clang-comment-html-tags", - "include/clang/AST/CommentHTMLTags.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/AST/CommentHTMLTags.td", - td_srcs = ["include/clang/AST/CommentHTMLTags.td"], -) - -gentbl( - name = "ast_comment_html_tags_properties_gen", - tbl_outs = [( - "-gen-clang-comment-html-tags-properties", - "include/clang/AST/CommentHTMLTagsProperties.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/AST/CommentHTMLTags.td", - td_srcs = ["include/clang/AST/CommentHTMLTags.td"], -) - -gentbl( - name = "ast_comment_html_named_character_references_gen", - tbl_outs = [( - "-gen-clang-comment-html-named-character-references", - "include/clang/AST/CommentHTMLNamedCharacterReferences.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/AST/CommentHTMLNamedCharacterReferences.td", - td_srcs = ["include/clang/AST/CommentHTMLNamedCharacterReferences.td"], -) - -gentbl( - name = "ast_stmt_data_collectors_gen", - tbl_outs = [( - "-gen-clang-data-collectors", - "include/clang/AST/StmtDataCollectors.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/AST/StmtDataCollectors.td", - td_srcs = ["include/clang/AST/StmtDataCollectors.td"], -) - -gentbl( - name = "ast_interp_opcodes_gen", - tbl_outs = [( - "-gen-clang-opcodes", - "lib/AST/Interp/Opcodes.inc", - )], - tblgen = ":clang-tblgen", - td_file = "lib/AST/Interp/Opcodes.td", - td_srcs = ["lib/AST/Interp/Opcodes.td"], -) - -gentbl( - name = "ast_properties_base_gen", - tbl_outs = [ - ( - "-gen-clang-basic-reader", - "include/clang/AST/AbstractBasicReader.inc", - ), - ( - "-gen-clang-basic-writer", - "include/clang/AST/AbstractBasicWriter.inc", - ), - ], - tblgen = ":clang-tblgen", - td_file = "include/clang/AST/PropertiesBase.td", - td_srcs = ["include/clang/AST/PropertiesBase.td"], -) - -gentbl( - name = "ast_type_properties_gen", - tbl_outs = [ - ( - "-gen-clang-type-reader", - "include/clang/AST/AbstractTypeReader.inc", - ), - ( - "-gen-clang-type-writer", - "include/clang/AST/AbstractTypeWriter.inc", - ), - ], - tblgen = ":clang-tblgen", - td_file = "include/clang/AST/TypeProperties.td", - td_srcs = [ - "include/clang/AST/PropertiesBase.td", - "include/clang/AST/TypeProperties.td", - "include/clang/Basic/ASTNode.td", - "include/clang/Basic/TypeNodes.td", - ], -) - -gentbl( - name = "type_nodes_gen", - tbl_outs = [( - "-gen-clang-type-nodes", - "include/clang/AST/TypeNodes.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/TypeNodes.td", - td_srcs = [ - "include/clang/Basic/ASTNode.td", - "include/clang/Basic/TypeNodes.td", - ], -) - -cc_library( - name = "ast", - srcs = glob([ - "lib/AST/*.cpp", - "lib/AST/*.h", - "lib/AST/Interp/*.cpp", - "lib/AST/Interp/*.h", - ]) + [ - "lib/AST/AttrDocTable.inc", - "lib/AST/Interp/Opcodes.inc", - ], - hdrs = glob([ - "include/clang/AST/*.h", - ]), - copts = [ - # FIXME: This is necessary to allow "file relative" include paths from - # non-generated `srcs` to find generated `srcs` above. Bazel should - # either make this work automatically by creating a unified tree of - # `srcs` or at least provide a `local_includes` that has the path - # translation logic of `includes` but is only used locally (similar to - # `local_defines` vs. `defines`). Until one of those lands, this is the - # least bad approach. Using `includes` is *specifically* problematic for - # this library because it contains files that collide easily with system - # headers such as `CXXABI.h`. - "-I$(GENDIR)/external/llvm-project/clang/lib/AST", - "-I$(GENDIR)/external/llvm-project/clang/lib/AST/Interp", - ], - textual_hdrs = [ - "include/clang/AST/AttrImpl.inc", - "include/clang/AST/AttrNodeTraverse.inc", - "include/clang/AST/Attrs.inc", - "include/clang/AST/AttrTextNodeDump.inc", - "include/clang/AST/AttrVisitor.inc", - "include/clang/AST/CommentCommandInfo.inc", - "include/clang/AST/CommentCommandList.inc", - "include/clang/AST/CommentHTMLNamedCharacterReferences.inc", - "include/clang/AST/CommentHTMLTags.inc", - "include/clang/AST/CommentHTMLTagsProperties.inc", - "include/clang/AST/CommentNodes.inc", - "include/clang/AST/DeclNodes.inc", - "include/clang/AST/StmtDataCollectors.inc", - "include/clang/AST/StmtNodes.inc", - ] + glob([ - "include/clang/AST/*.def", - ]), - deps = [ - ":ast_attr_gen", - ":ast_comment_command_info_gen", - ":ast_comment_html_named_character_references_gen", - ":ast_comment_html_tags_gen", - ":ast_comment_html_tags_properties_gen", - ":ast_comment_nodes_gen", - ":ast_decl_nodes_gen", - ":ast_interp_opcodes_gen", - ":ast_properties_base_gen", - ":ast_stmt_data_collectors_gen", - ":ast_stmt_nodes_gen", - ":ast_type_properties_gen", - ":basic", - ":lex", - ":type_nodes_gen", - "//llvm:BinaryFormat", - "//llvm:Core", - "//llvm:FrontendOpenMP", - "//llvm:Support", - ], -) - -cc_library( - name = "index", - srcs = glob([ - "lib/Index/*.cpp", - "lib/Index/*.h", - ]), - hdrs = glob([ - "include/clang/Index/*.h", - "include/clang-c/*.h", - ]), - includes = ["include"], - deps = [ - ":ast", - ":basic", - ":format", - ":frontend", - ":lex", - ":rewrite", - ":serialization", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "analysis", - srcs = glob([ - "lib/Analysis/*.cpp", - "lib/Analysis/*.h", - ]), - hdrs = glob([ - "include/clang/Analysis/**/*.h", - ]), - includes = ["include"], - textual_hdrs = glob([ - "include/clang/Analysis/**/*.def", - ]), - deps = [ - ":ast", - ":ast_matchers", - ":basic", - ":lex", - "//llvm:Support", - ], -) - -gentbl( - name = "sema_attr_gen", - tbl_outs = [ - ( - "-gen-clang-attr-parsed-attr-impl", - "include/clang/Sema/AttrParsedAttrImpl.inc", - ), - ( - "-gen-clang-attr-parsed-attr-kinds", - "include/clang/Sema/AttrParsedAttrKinds.inc", - ), - ( - "-gen-clang-attr-parsed-attr-list", - "include/clang/Sema/AttrParsedAttrList.inc", - ), - ( - "-gen-clang-attr-spelling-index", - "include/clang/Sema/AttrSpellingListIndex.inc", - ), - ( - "-gen-clang-attr-template-instantiate", - "include/clang/Sema/AttrTemplateInstantiate.inc", - ), - ], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/Attr.td", - td_srcs = [ - "include/clang/Basic/ASTNode.td", - "include/clang/Basic/Attr.td", - "include/clang/Basic/AttrDocs.td", - "include/clang/Basic/DeclNodes.td", - "include/clang/Basic/StmtNodes.td", - ], -) - -cc_library( - name = "sema", - srcs = glob([ - "lib/Sema/*.cpp", - "lib/Sema/*.h", - ]), - hdrs = glob([ - "include/clang/Sema/*.h", - "include/clang-c/*.h", - ]), - copts = ["$(STACK_FRAME_UNLIMITED)"], - includes = ["include"], - textual_hdrs = [ - "include/clang/Sema/AttrParsedAttrImpl.inc", - "include/clang/Sema/AttrParsedAttrKinds.inc", - "include/clang/Sema/AttrParsedAttrList.inc", - "include/clang/Sema/AttrSpellingListIndex.inc", - "include/clang/Sema/AttrTemplateInstantiate.inc", - "lib/Sema/OpenCLBuiltins.inc", - ], - deps = [ - ":analysis", - ":ast", - ":basic", - ":basic_arm_cde_aliases_gen", - ":basic_arm_cde_sema_gen", - ":basic_arm_sve_builtins_gen", - ":basic_arm_sve_sema_rangechecks_gen", - ":edit", - ":lex", - ":libsema_openclbuiltins_inc_gen", - ":sema_attr_gen", - ":type_nodes_gen", - "//llvm:AllTargetsAsmParsers", - "//llvm:AllTargetsCodeGens", - "//llvm:Core", - "//llvm:FrontendOpenMP", - "//llvm:MC", - "//llvm:MCParser", - "//llvm:Support", - ], -) - -gentbl( - name = "parse_attr_gen", - tbl_outs = [ - ( - "-gen-clang-attr-parser-string-switches", - "include/clang/Parse/AttrParserStringSwitches.inc", - ), - ( - "-gen-clang-attr-subject-match-rules-parser-string-switches", - "include/clang/Parse/AttrSubMatchRulesParserStringSwitches.inc", - ), - ], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/Attr.td", - td_srcs = [ - "include/clang/Basic/ASTNode.td", - "include/clang/Basic/Attr.td", - "include/clang/Basic/AttrDocs.td", - "include/clang/Basic/DeclNodes.td", - "include/clang/Basic/StmtNodes.td", - ], -) - -cc_library( - name = "parse", - srcs = [ - ] + glob([ - "lib/Parse/*.cpp", - "lib/Parse/*.h", - ]), - hdrs = [ - "include/clang/Parse/AttrParserStringSwitches.inc", - "include/clang/Parse/AttrSubMatchRulesParserStringSwitches.inc", - ] + glob(["include/clang/Parse/*.h"]), - includes = ["include"], - deps = [ - ":ast", - ":basic", - ":lex", - ":parse_attr_gen", - ":sema", - "//llvm:FrontendOpenMP", - "//llvm:MC", - "//llvm:MCParser", - "//llvm:Support", - ], -) - -cc_library( - name = "ast_matchers", - srcs = glob([ - "lib/ASTMatchers/*.cpp", - "lib/ASTMatchers/*.h", - ]), - hdrs = glob(["include/clang/ASTMatchers/*.h"]), - includes = ["include"], - deps = [ - ":ast", - ":basic", - ":lex", - "//llvm:Support", - ], -) - -cc_library( - name = "ast_matchers_dynamic", - srcs = glob([ - "lib/ASTMatchers/Dynamic/*.cpp", - "lib/ASTMatchers/Dynamic/*.h", - ]), - hdrs = glob(["include/clang/ASTMatchers/Dynamic/*.h"]), - copts = ["$(STACK_FRAME_UNLIMITED)"], - includes = ["include"], - deps = [ - ":ast", - ":ast_matchers", - ":basic", - "//llvm:FrontendOpenMP", - "//llvm:Support", - ], -) - -cc_library( - name = "rewrite", - srcs = glob([ - "lib/Rewrite/*.cpp", - "lib/Rewrite/*.h", - ]), - hdrs = glob(["include/clang/Rewrite/Core/*.h"]), - includes = ["include"], - deps = [ - ":ast", - ":basic", - ":edit", - ":lex", - "//llvm:Support", - ], -) - -cc_library( - name = "testing", - srcs = glob([ - "lib/Testing/*.cpp", - ]), - hdrs = glob(["include/clang/Testing/*.h"]), - includes = ["include"], - deps = [ - ":basic", - "//llvm:Support", - ], -) - -cc_library( - name = "tooling_core", - srcs = glob([ - "lib/Tooling/Core/*.cpp", - "lib/Tooling/Core/*.h", - ]), - hdrs = glob(["include/clang/Tooling/Core/*.h"]), - includes = ["include"], - deps = [ - ":ast", - ":basic", - ":lex", - ":rewrite", - "//llvm:Support", - ], -) - -cc_library( - name = "tooling", - srcs = glob( - [ - "lib/Tooling/*.cpp", - ], - # Temporarily disable until we support the generated file. - exclude = ["lib/Tooling/NodeIntrospection.cpp"], - ), - hdrs = glob([ - "include/clang/Tooling/*.h", - ]), - includes = ["include"], - deps = [ - ":ast", - ":ast_matchers", - ":basic", - ":driver", - ":format", - ":frontend", - ":lex", - ":rewrite", - ":tooling_core", - "//llvm:Option", - "//llvm:Support", - ], -) - -cc_library( - name = "tooling_inclusions", - srcs = glob([ - "lib/Tooling/Inclusions/**/*.cpp", - ]), - hdrs = glob([ - "include/clang/Tooling/Inclusions/**/*.h", - ]), - deps = [ - ":basic", - ":lex", - ":rewrite", - ":tooling_core", - "//llvm:Support", - ], -) - -cc_library( - name = "tooling_refactoring", - srcs = glob([ - "lib/Tooling/Refactoring/**/*.cpp", - "lib/Tooling/Refactoring/**/*.h", - ]), - hdrs = glob([ - "include/clang/Tooling/Refactoring/**/*.h", - "include/clang/Tooling/Refactoring/**/*.def", - ]), - deps = [ - ":ast", - ":ast_matchers", - ":basic", - ":format", - ":frontend", - ":index", - ":lex", - ":rewrite", - ":tooling", - ":tooling_core", - "//llvm:Support", - ], -) - -gentbl( - name = "tooling_syntax_gen", - tbl_outs = [ - ("-gen-clang-syntax-node-list", "include/clang/Tooling/Syntax/Nodes.inc"), - ("-gen-clang-syntax-node-classes", "include/clang/Tooling/Syntax/NodeClasses.inc"), - ], - tblgen = ":clang-tblgen", - td_file = "include/clang/Tooling/Syntax/Nodes.td", - td_srcs = [ - "include/clang/Tooling/Syntax/Nodes.td", - "include/clang/Tooling/Syntax/Syntax.td", - ], -) - -cc_library( - name = "tooling_syntax", - srcs = glob(["lib/Tooling/Syntax/**/*.cpp"]), - hdrs = glob(["include/clang/Tooling/Syntax/**/*.h"]), - deps = [ - ":ast", - ":basic", - ":lex", - ":tooling_core", - ":tooling_syntax_gen", - "//llvm:Support", - ], -) - -cc_library( - name = "tooling_dependency_scanning", - srcs = glob(["lib/Tooling/DependencyScanning/**/*.cpp"]), - hdrs = glob(["include/clang/Tooling/DependencyScanning/**/*.h"]), - deps = [ - ":basic", - ":codegen", - ":frontend", - ":lex", - ":serialization", - ":tooling", - "//llvm:Support", - ], -) - -cc_library( - name = "transformer", - srcs = glob(["lib/Tooling/Transformer/**/*.cpp"]), - hdrs = glob(["include/clang/Tooling/Transformer/**/*.h"]), - deps = [ - ":ast", - ":ast_matchers", - ":basic", - ":lex", - ":rewrite", - ":tooling_refactoring", - "//llvm:Support", - ], -) - -cc_library( - name = "ast-diff", - srcs = glob(["lib/Tooling/ASTDiff/*.cpp"]), - hdrs = glob(["include/clang/Tooling/ASTDiff/*.h"]), - deps = [ - ":ast", - ":basic", - ":lex", - "//llvm:Support", - ], -) - -cc_library( - name = "crosstu", - srcs = glob(["lib/CrossTU/*.cpp"]), - hdrs = glob(["include/clang/CrossTU/*.h"]), - deps = [ - ":ast", - ":basic", - ":frontend", - ":index", - "//llvm:Option", - "//llvm:Support", - ], -) - -cc_library( - name = "format", - srcs = glob( - [ - "lib/Format/*.cpp", - "lib/Format/*.h", - ], - ), - hdrs = [ - "lib/Format/FormatTokenLexer.h", - "lib/Format/Macros.h", - ] + glob([ - "include/clang/Format/*.h", - ]), - includes = ["include"], - deps = [ - ":basic", - ":lex", - ":tooling_core", - ":tooling_inclusions", - "//llvm:Support", - ], -) - -cc_library( - name = "edit", - srcs = glob(["lib/Edit/*.cpp"]), - hdrs = glob(["include/clang/Edit/*.h"]), - includes = ["include"], - deps = [ - ":ast", - ":basic", - ":lex", - "//llvm:Support", - ], -) - -cc_library( - name = "static_analyzer_core_options", - hdrs = [ - "include/clang/StaticAnalyzer/Core/AnalyzerOptions.h", - ], - textual_hdrs = [ - "include/clang/StaticAnalyzer/Core/Analyses.def", - "include/clang/StaticAnalyzer/Core/AnalyzerOptions.def", - ], - deps = [ - ":basic", - ":static_analyzer_checkers_gen", - "//llvm:Support", - ], -) - -cc_library( - name = "static_analyzer_core", - srcs = glob([ - "lib/StaticAnalyzer/Core/**/*.cpp", - "lib/StaticAnalyzer/Core/**/*.h", - ]), - hdrs = glob([ - "include/clang/StaticAnalyzer/Core/**/*.h", - ]), - includes = ["include"], - textual_hdrs = glob([ - "include/clang/StaticAnalyzer/Core/**/*.def", - ]), - deps = [ - ":analysis", - ":ast", - ":ast_matchers", - ":basic", - ":crosstu", - ":driver", - ":frontend", - ":lex", - ":rewrite", - ":static_analyzer_checkers_gen", - ":tooling", - ":tooling_core", - "//llvm:Support", - ], -) - -gentbl( - name = "static_analyzer_checkers_gen", - tbl_outs = [( - "-gen-clang-sa-checkers", - "include/clang/StaticAnalyzer/Checkers/Checkers.inc", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/StaticAnalyzer/Checkers/Checkers.td", - td_srcs = [ - "include/clang/StaticAnalyzer/Checkers/CheckerBase.td", - "include/clang/StaticAnalyzer/Checkers/Checkers.td", - ], -) - -cc_library( - name = "static_analyzer_checkers", - srcs = glob([ - "lib/StaticAnalyzer/Checkers/**/*.cpp", - "lib/StaticAnalyzer/Checkers/**/*.h", - ]), - hdrs = [ - "include/clang/StaticAnalyzer/Checkers/Checkers.inc", - ] + glob([ - "include/clang/StaticAnalyzer/Checkers/**/*.h", - ]), - copts = ["$(STACK_FRAME_UNLIMITED)"], - includes = ["include"], - deps = [ - ":analysis", - ":ast", - ":ast_matchers", - ":basic", - ":driver", - ":lex", - ":static_analyzer_checkers_gen", - ":static_analyzer_core", - "//llvm:Support", - ], -) - -gentbl( - name = "driver_options_inc_gen", - tbl_outs = [( - "-gen-opt-parser-defs", - "include/clang/Driver/Options.inc", - )], - tblgen = "//llvm:llvm-tblgen", - td_file = "include/clang/Driver/Options.td", - td_srcs = [ - "//llvm:include/llvm/Option/OptParser.td", - ], -) - -cc_library( - name = "driver", - srcs = glob( - [ - "lib/Driver/*.cpp", - "lib/Driver/*.h", - "lib/Driver/Arch/*.cpp", - "lib/Driver/Arch/*.h", - "lib/Driver/ToolChains/*.cpp", - "lib/Driver/ToolChains/*.h", - "lib/Driver/ToolChains/Arch/*.cpp", - "lib/Driver/ToolChains/Arch/*.h", - ], - exclude = [ - "lib/Driver/ToolChains/MSVCSetupApi.h", - ], - ), - hdrs = glob([ - "include/clang/Driver/*.h", - ]), - copts = ["$(STACK_FRAME_UNLIMITED)"], - includes = [ - "include", - # TODO: This is likely a layering issue, but files in Arch are currently - # directly #including "Tools.h". - "lib/Driver", - ], - linkopts = select({ - "@bazel_tools//src/conditions:windows": ["version.lib"], - "//conditions:default": [], - }), - textual_hdrs = glob([ - "include/clang/Driver/*.def", - ]), - deps = [ - ":ast", - ":basic", - ":config", - ":driver_options_inc_gen", - ":parse", - ":static_analyzer_checkers_gen", - "//llvm:BinaryFormat", - "//llvm:MC", - "//llvm:Option", - "//llvm:ProfileData", - "//llvm:Support", - "//llvm:Target", - "//llvm:config", - ], -) - -gentbl( - name = "headers_arm_neon_gen", - tbl_outs = [( - "-gen-arm-neon", - "lib/Headers/arm_neon.h", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/arm_neon.td", - td_srcs = [ - "include/clang/Basic/arm_neon.td", - "include/clang/Basic/arm_neon_incl.td", - ], -) - -gentbl( - name = "headers_arm_fp16_gen", - tbl_outs = [( - "-gen-arm-fp16", - "lib/Headers/arm_fp16.h", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/arm_fp16.td", - td_srcs = [ - "include/clang/Basic/arm_fp16.td", - "include/clang/Basic/arm_neon_incl.td", - ], -) - -gentbl( - name = "headers_arm_mve_gen", - tbl_outs = [( - "-gen-arm-mve-header", - "lib/Headers/arm_mve.h", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/arm_mve.td", - td_srcs = [ - "include/clang/Basic/arm_mve.td", - "include/clang/Basic/arm_mve_defs.td", - ], -) - -gentbl( - name = "headers_arm_cde_gen", - tbl_outs = [( - "-gen-arm-cde-header", - "lib/Headers/arm_cde.h", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/arm_cde.td", - td_srcs = [ - "include/clang/Basic/arm_cde.td", - "include/clang/Basic/arm_mve_defs.td", - ], -) - -gentbl( - name = "headers_arm_sve_gen", - tbl_outs = [( - "-gen-arm-sve-header", - "lib/Headers/arm_sve.h", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/arm_sve.td", - td_srcs = [ - "include/clang/Basic/arm_sve.td", - ], -) - -gentbl( - name = "headers_arm_bf16_gen", - tbl_outs = [( - "-gen-arm-bf16", - "lib/Headers/arm_bf16.h", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/arm_bf16.td", - td_srcs = [ - "include/clang/Basic/arm_bf16.td", - "include/clang/Basic/arm_neon_incl.td", - ], -) - -gentbl( - name = "headers_riscv_vector", - tbl_outs = [( - "-gen-riscv-vector-header", - "lib/Headers/riscv_vector.h", - )], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/riscv_vector.td", - td_srcs = [ - "include/clang/Basic/riscv_vector.td", - ], -) - -# We generate the set of builtin headers under a special subdirectory in the -# 'bin' section of the bazel output so that they can be used as data -# dependencies. It requires listing explicitly all the generated inputs here. -builtin_headers = glob(["lib/Headers/**/*.h"]) + [ - "lib/Headers/arm_cde.h", - "lib/Headers/arm_fp16.h", - "lib/Headers/arm_mve.h", - "lib/Headers/arm_neon.h", - "lib/Headers/arm_sve.h", - "lib/Headers/arm_bf16.h", - "lib/Headers/riscv_vector.h", -] - -genrule( - name = "builtin_headers_gen", - srcs = builtin_headers, - outs = [hdr.replace("lib/Headers/", "staging/include/") for hdr in builtin_headers], - cmd = """ - for src in $(SRCS); do - relsrc=$${src/*external\\/llvm-project\\/clang\\/lib\\/Headers\\/} - target=$(@D)/staging/include/$$relsrc - mkdir -p $$(dirname $$target) - cp $$src $$target - done""", - output_to_bindir = 1, -) - -cc_library( - name = "frontend", - srcs = glob([ - "lib/Frontend/*.cpp", - "lib/Frontend/*.h", - ]), - hdrs = glob([ - "include/clang/Frontend/*.h", - ]), - copts = ["$(STACK_FRAME_UNLIMITED)"], - data = [":builtin_headers_gen"], - includes = ["include"], - textual_hdrs = glob([ - "include/clang/Frontend/*.def", - ]), - deps = [ - ":ast", - ":basic", - ":config", - ":driver", - ":driver_options_inc_gen", - ":edit", - ":lex", - ":parse", - ":sema", - ":serialization", - ":static_analyzer_core_options", - "//llvm:BinaryFormat", - "//llvm:BitReader", - "//llvm:BitstreamReader", - "//llvm:BitstreamWriter", - "//llvm:Core", - "//llvm:Linker", - "//llvm:MC", - "//llvm:Option", - "//llvm:ProfileData", - "//llvm:Support", - "//llvm:Target", - "//llvm:config", - ], -) - -cc_library( - name = "frontend_rewrite", - srcs = glob([ - "lib/Frontend/Rewrite/*.cpp", - "lib/Frontend/Rewrite/*.h", - ]), - hdrs = glob(["include/clang/Rewrite/Frontend/*.h"]), - includes = ["include"], - deps = [ - ":ast", - ":basic", - ":config", - ":edit", - ":frontend", - ":lex", - ":parse", - ":rewrite", - ":serialization", - "//llvm:Support", - ], -) - -cc_library( - name = "interpreter", - srcs = glob([ - "lib/Interpreter/*.cpp", - "lib/Interpreter/*.h", - ]), - hdrs = glob(["include/clang/Interpreter/*.h"]), - includes = ["include"], - deps = [ - ":analysis", - ":ast", - ":basic", - ":codegen", - ":driver", - ":edit", - ":frontend", - ":frontend_tool", - ":lex", - ":parse", - ":sema", - ":serialization", - "//llvm:AllTargetsAsmParsers", - "//llvm:AllTargetsCodeGens", - "//llvm:Core", - "//llvm:ExecutionEngine", - "//llvm:Option", - "//llvm:OrcJIT", - "//llvm:Support", - "//llvm:Target", - ], -) - -cc_library( - name = "codegen", - srcs = glob([ - "lib/CodeGen/*.cpp", - "lib/CodeGen/*.h", - ]), - hdrs = glob(["include/clang/CodeGen/*.h"]), - copts = ["$(STACK_FRAME_UNLIMITED)"], - includes = ["include"], - deps = [ - ":analysis", - ":ast", - ":basic", - ":basic_arm_cde_cg_gen", - ":basic_arm_sve_builtin_cg_gen", - ":basic_riscv_vector_builtin_cg_gen", - ":driver", - ":frontend", - ":lex", - ":sema", - ":type_nodes_gen", - "//llvm:AllTargetsAsmParsers", - "//llvm:Analysis", - "//llvm:BitReader", - "//llvm:BitWriter", - "//llvm:BitstreamReader", - "//llvm:CodeGen", - "//llvm:Core", - "//llvm:Coroutines", - "//llvm:Coverage", - "//llvm:DebugInfoDWARF", - "//llvm:Demangle", - "//llvm:FrontendOpenMP", - "//llvm:IPO", - "//llvm:IRReader", - "//llvm:InstCombine", - "//llvm:Instrumentation", - "//llvm:LTO", - "//llvm:Linker", - "//llvm:MC", - "//llvm:ObjCARC", - "//llvm:Object", - "//llvm:Passes", - "//llvm:ProfileData", - "//llvm:Scalar", - "//llvm:Support", - "//llvm:Target", - "//llvm:TransformUtils", - ], -) - -cc_library( - name = "static_analyzer_frontend", - srcs = glob([ - "lib/StaticAnalyzer/Frontend/**/*.cpp", - "lib/StaticAnalyzer/Frontend/**/*.h", - ]), - hdrs = glob(["include/clang/StaticAnalyzer/Frontend/**/*.h"]), - includes = ["include"], - deps = [ - ":analysis", - ":ast", - ":basic", - ":crosstu", - ":driver", - ":frontend", - ":lex", - ":rewrite", - ":serialization", - ":static_analyzer_checkers", - ":static_analyzer_core", - ":tooling", - ":tooling_core", - "//llvm:Support", - ], -) - -gentbl( - name = "serialization_attr_gen", - tbl_outs = [ - ( - "-gen-clang-attr-pch-read", - "include/clang/Serialization/AttrPCHRead.inc", - ), - ( - "-gen-clang-attr-pch-write", - "include/clang/Serialization/AttrPCHWrite.inc", - ), - ], - tblgen = ":clang-tblgen", - td_file = "include/clang/Basic/Attr.td", - td_srcs = [ - "include/clang/Basic/ASTNode.td", - "include/clang/Basic/Attr.td", - "include/clang/Basic/AttrDocs.td", - "include/clang/Basic/DeclNodes.td", - "include/clang/Basic/StmtNodes.td", - ], -) - -cc_library( - name = "serialization", - srcs = [ - "include/clang/Serialization/AttrPCHRead.inc", - "include/clang/Serialization/AttrPCHWrite.inc", - ] + glob([ - "lib/Serialization/*.cpp", - "lib/Serialization/*.h", - ]), - hdrs = glob([ - "include/clang/Serialization/*.h", - ]), - includes = ["include"], - textual_hdrs = glob([ - "include/clang/Serialization/*.def", - ]), - deps = [ - ":ast", - ":basic", - ":lex", - ":sema", - ":serialization_attr_gen", - ":type_nodes_gen", - "//llvm:BitReader", - "//llvm:BitWriter", - "//llvm:BitstreamReader", - "//llvm:BitstreamWriter", - "//llvm:FrontendOpenMP", - "//llvm:Support", - ], -) - -cc_library( - name = "frontend_tool", - srcs = glob([ - "lib/FrontendTool/*.cpp", - "lib/FrontendTool/*.h", - ]), - hdrs = glob(["include/clang/FrontendTool/*.h"]), - includes = ["include"], - deps = [ - ":arc_migrate", - ":codegen", - ":config", - ":driver", - ":frontend", - ":frontend_rewrite", - ":static_analyzer_frontend", - "//llvm:Option", - "//llvm:Support", - ], -) - -cc_library( - name = "arc_migrate", - srcs = glob([ - "lib/ARCMigrate/*.cpp", - "lib/ARCMigrate/*.h", - ]), - hdrs = glob(["include/clang/ARCMigrate/*.h"]), - includes = ["include"], - deps = [ - ":analysis", - ":ast", - ":basic", - ":edit", - ":frontend", - ":frontend_rewrite", - ":lex", - ":parse", - ":rewrite", - ":sema", - ":serialization", - ":static_analyzer_checkers", - ":static_analyzer_core", - "//llvm:Support", - ], -) - -cc_library( - name = "libclang_static", - srcs = glob([ - "tools/libclang/*.cpp", - "tools/libclang/*.h", - ]), - hdrs = glob(["include/clang-c/*.h"]), - defines = ["CINDEX_NO_EXPORTS"], - deps = [ - ":arc_migrate", - ":ast", - ":basic", - ":codegen", - ":config", - ":driver", - ":frontend", - ":index", - ":lex", - ":rewrite", - ":sema", - ":tooling", - "//llvm:BitstreamReader", - "//llvm:FrontendOpenMP", - "//llvm:Support", - "//llvm:config", - ], -) - -cc_plugin_library( - name = "libclang", - srcs = glob([ - "tools/libclang/*.cpp", - "tools/libclang/*.h", - ]), - hdrs = glob(["include/clang-c/*.h"]), - copts = select({ - "@bazel_tools//src/conditions:windows": ["-D_CINDEX_LIB_"], - "//conditions:default": [], - }), - strip_include_prefix = "include", - deps = [ - ":arc_migrate", - ":ast", - ":basic", - ":codegen", - ":config", - ":driver", - ":frontend", - ":index", - ":lex", - ":rewrite", - ":sema", - ":tooling", - "//llvm:BitstreamReader", - "//llvm:FrontendOpenMP", - "//llvm:Support", - "//llvm:config", - ], -) - -filegroup( - name = "python-sources", - srcs = [ - "bindings/python/clang/cindex.py", - "bindings/python/clang/enumerations.py", - ], -) - -filegroup( - name = "python-cindex-examples", - srcs = [ - "bindings/python/examples/cindex/cindex-dump.py", - "bindings/python/examples/cindex/cindex-includes.py", - ], -) - -cc_binary( - name = "c-index-test", - testonly = 1, - srcs = [ - "tools/c-index-test/c-index-test.c", - "tools/c-index-test/core_main.cpp", - ], - copts = [ - "-Wno-uninitialized", - ], - stamp = 0, - deps = [ - ":ast", - ":basic", - ":codegen", - ":config", - ":frontend", - ":index", - ":lex", - ":libclang", - ":serialization", - "//llvm:Core", - "//llvm:MC", - "//llvm:Support", - ], -) - -cc_binary( - name = "arcmt-test", - testonly = 1, - srcs = ["tools/arcmt-test/arcmt-test.cpp"], - stamp = 0, - deps = [ - ":arc_migrate", - ":ast", - ":basic", - ":frontend", - ":frontend_rewrite", - ":lex", - "//llvm:Support", - ], -) - -cc_binary( - name = "c-arcmt-test", - testonly = 1, - srcs = ["tools/c-arcmt-test/c-arcmt-test.c"], - copts = select({ - "@bazel_tools//src/conditions:windows": [], - "//conditions:default": ["-std=gnu99"], - }), - stamp = 0, - deps = [ - ":codegen", - ":libclang", - "//llvm:MC", - "//llvm:Support", - ], -) - -cc_binary( - name = "clang-import-test", - testonly = 1, - srcs = glob([ - "tools/clang-import-test/*.cpp", - "tools/clang-import-test/*.h", - ]), - stamp = 0, - deps = [ - ":ast", - ":basic", - ":codegen", - ":driver", - ":frontend", - ":lex", - ":parse", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "clang-driver", - srcs = glob([ - "tools/driver/*.cpp", - "tools/driver/*.h", - ]), - copts = [ - # Disable stack frame size checks in the driver because - # clang::ensureStackAddressSpace allocates a large array on the stack. - "$(STACK_FRAME_UNLIMITED)", - ], - deps = [ - ":analysis", - ":ast", - ":basic", - ":codegen", - ":config", - ":driver", - ":frontend", - ":frontend_rewrite", - ":frontend_tool", - ":lex", - ":parse", - ":sema", - ":serialization", - ":static_analyzer_frontend", - "//llvm:AllTargetsAsmParsers", - "//llvm:AllTargetsCodeGens", - "//llvm:BitReader", - "//llvm:BitWriter", - "//llvm:CodeGen", - "//llvm:Core", - "//llvm:IPO", - "//llvm:MC", - "//llvm:MCParser", - "//llvm:Option", - "//llvm:Support", - "//llvm:Target", - "//llvm:config", - ], -) - -cc_binary( - name = "clang", - srcs = [], - stamp = 0, - deps = [ - ":clang-driver", - ], -) - -cc_binary( - name = "diagtool", - srcs = glob([ - "tools/diagtool/*.cpp", - "tools/diagtool/*.h", - ]), - stamp = 0, - deps = [ - ":basic", - ":frontend", - ":lex", - ":sema", - "//llvm:Support", - ], -) - -filegroup( - name = "exploded_graph_rewriter", - testonly = 1, - data = ["utils/analyzer/exploded-graph-rewriter.py"], -) - -filegroup( - name = "module-deps-to-rsp", - testonly = 1, - data = ["utils/module-deps-to-rsp.py"], -) - -filegroup( - name = "hmaptool", - testonly = 1, - data = ["utils/hmaptool/hmaptool"], -) - -binary_alias( - name = "clang++", - binary = ":clang", -) - -cc_binary( - name = "clang-check", - srcs = ["tools/clang-check/ClangCheck.cpp"], - stamp = 0, - deps = [ - ":ast", - ":codegen", - ":driver", - ":frontend", - ":frontend_rewrite", - ":serialization", - ":static_analyzer_frontend", - ":tooling", - ":tooling_syntax", - "//llvm:Option", - "//llvm:Support", - ], -) - -cc_binary( - name = "clang-format", - srcs = [ - "tools/clang-format/ClangFormat.cpp", - ], - stamp = 0, - deps = [ - ":basic", - ":format", - ":frontend", - ":rewrite", - "//llvm:Support", - ], -) - -cc_binary( - name = "clang-diff", - srcs = glob(["tools/clang-diff/*.cpp"]), - stamp = 0, - deps = [ - ":ast-diff", - ":tooling", - "//llvm:Support", - ], -) - -cc_binary( - name = "clang-offload-bundler", - srcs = glob(["tools/clang-offload-bundler/*.cpp"]), - stamp = 0, - deps = [ - ":basic", - ":tooling", - "//llvm:BitWriter", - "//llvm:Core", - "//llvm:Object", - "//llvm:Support", - ], -) - -cc_binary( - name = "clang-offload-wrapper", - srcs = glob(["tools/clang-offload-wrapper/*.cpp"]), - stamp = 0, - deps = [ - ":basic", - "//llvm:BitWriter", - "//llvm:Support", - "//llvm:TransformUtils", - "//llvm:ir_headers", - ], -) - -cc_binary( - name = "clang-refactor", - srcs = glob([ - "tools/clang-refactor/*.cpp", - "tools/clang-refactor/*.h", - ]), - stamp = 0, - deps = [ - ":ast", - ":basic", - ":format", - ":frontend", - ":lex", - ":rewrite", - ":tooling", - ":tooling_refactoring", - "//llvm:Support", - ], -) - -cc_binary( - name = "clang-rename", - srcs = glob(["tools/clang-rename/*.cpp"]), - stamp = 0, - deps = [ - ":basic", - ":frontend", - ":rewrite", - ":tooling", - ":tooling_refactoring", - "//llvm:Support", - ], -) - -cc_binary( - name = "clang-repl", - srcs = glob(["tools/clang-repl/*.cpp"]), - stamp = 0, - deps = [ - ":basic", - ":frontend", - ":interpreter", - ":tooling", - "//llvm:Core", - "//llvm:LineEditor", - "//llvm:Option", - "//llvm:OrcJIT", - "//llvm:Support", - ], -) - -cc_binary( - name = "clang-extdef-mapping", - srcs = glob(["tools/clang-extdef-mapping/*.cpp"]), - stamp = 0, - deps = [ - ":ast", - ":basic", - ":crosstu", - ":frontend", - ":tooling", - "//llvm:Support", - ], -) - -cc_binary( - name = "clang-scan-deps", - srcs = glob(["tools/clang-scan-deps/*.cpp"]), - stamp = 0, - deps = [ - ":frontend", - ":tooling", - ":tooling_dependency_scanning", - "//llvm:Support", - ], -) diff --git a/utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h b/utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h deleted file mode 100644 index ccf47729f3adb..0000000000000 --- a/utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h +++ /dev/null @@ -1,119 +0,0 @@ -/*===------- clang/Config/config.h - llvm configuration -----------*- C -*-===*/ -/* */ -/* Part of the LLVM Project, under the Apache License v2.0 with LLVM */ -/* Exceptions. */ -/* See https://llvm.org/LICENSE.txt for license information. */ -/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -/* */ -/*===----------------------------------------------------------------------===*/ - -/* This is a manual port of config.h.cmake for the symbols that do not change - based on platform. Those that do change should not be defined here and - instead use Bazel cc_library defines. Some attempt has been made to extract - such symbols that do vary based on platform (for the platforms we care about) - into Bazel defines, but it is by no means complete, so if you see something - that looks wrong, it probably is. */ - -#ifdef CLANG_CONFIG_H -#error config.h can only be included once -#else -#define CLANG_CONFIG_H - -/* Bug report URL. */ -#define BUG_REPORT_URL "https://github.com/llvm/llvm-project/issues/" - -/* Default to -fPIE and -pie on Linux. */ -#define CLANG_DEFAULT_PIE_ON_LINUX 0 - -/* Default linker to use. */ -#define CLANG_DEFAULT_LINKER "" - -/* Default C/ObjC standard to use. */ -/* #undef CLANG_DEFAULT_STD_C */ - -/* Default C++/ObjC++ standard to use. */ -/* #undef CLANG_DEFAULT_STD_CXX */ - -/* Default C++ stdlib to use. */ -#define CLANG_DEFAULT_CXX_STDLIB "" - -/* Default runtime library to use. */ -#define CLANG_DEFAULT_RTLIB "" - -/* Default unwind library to use. */ -#define CLANG_DEFAULT_UNWINDLIB "" - -/* Default objcopy to use */ -#define CLANG_DEFAULT_OBJCOPY "objcopy" - -/* Default OpenMP runtime used by -fopenmp. */ -#define CLANG_DEFAULT_OPENMP_RUNTIME "libomp" - -/* Default architecture for OpenMP offloading to Nvidia GPUs. */ -#define CLANG_OPENMP_NVPTX_DEFAULT_ARCH "sm_35" - -/* Default architecture for SystemZ. */ -#define CLANG_SYSTEMZ_DEFAULT_ARCH "z10" - -/* Multilib suffix for libdir. */ -#define CLANG_LIBDIR_SUFFIX "" - -/* Relative directory for resource files */ -#define CLANG_RESOURCE_DIR "" - -/* Directories clang will search for headers */ -#define C_INCLUDE_DIRS "" - -/* Directories clang will search for configuration files */ -/* #undef CLANG_CONFIG_FILE_SYSTEM_DIR */ -/* #undef CLANG_CONFIG_FILE_USER_DIR */ - -/* Default to all compiler invocations for --sysroot=. */ -#define DEFAULT_SYSROOT "" - -/* Directory where gcc is installed. */ -#define GCC_INSTALL_PREFIX "" - -/* Define if we have libxml2 */ -/* #undef CLANG_HAVE_LIBXML */ - -/* Define if we have sys/resource.h (rlimits) */ -/* CLANG_HAVE_RLIMITS defined conditionally below */ - -/* The LLVM product name and version */ -#define BACKEND_PACKAGE_STRING "LLVM 12.0.0git" - -/* Linker version detected at compile time. */ -/* #undef HOST_LINK_VERSION */ - -/* pass --build-id to ld */ -/* #undef ENABLE_LINKER_BUILD_ID */ - -/* enable x86 relax relocations by default */ -#define ENABLE_X86_RELAX_RELOCATIONS 1 - -/* enable IEEE binary128 as default long double format on PowerPC Linux. */ -#define PPC_LINUX_DEFAULT_IEEELONGDOUBLE 0 - -/* Enable the experimental new pass manager by default */ -#define ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER 0 - -/* Enable each functionality of modules */ -#define CLANG_ENABLE_ARCMT 1 -#define CLANG_ENABLE_OBJC_REWRITER 1 -#define CLANG_ENABLE_STATIC_ANALYZER 1 - -/* Spawn a new process clang.exe for the CC1 tool invocation, when necessary */ -#define CLANG_SPAWN_CC1 0 - -/* Directly provide definitions here behind platform preprocessor definitions. - * The preprocessor conditions are sufficient to handle all of the configuration - * on platforms targeted by Bazel, and defining these here more faithfully - * matches how the users of this header expect things to work with CMake. - */ - -#ifndef _WIN32 -#define CLANG_HAVE_RLIMITS 1 -#endif - -#endif diff --git a/utils/bazel/llvm-project-overlay/clang/unittests/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang/unittests/BUILD.bazel deleted file mode 100644 index da4991f934ee4..0000000000000 --- a/utils/bazel/llvm-project-overlay/clang/unittests/BUILD.bazel +++ /dev/null @@ -1,498 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -package( - default_visibility = ["//visibility:public"], - licenses = ["notice"], -) - -cc_test( - name = "ast_tests", - size = "medium", - srcs = glob( - [ - "AST/*.cpp", - "AST/*.h", - ], - allow_empty = False, - ), - shard_count = 20, - deps = [ - "//clang:ast", - "//clang:ast_matchers", - "//clang:basic", - "//clang:frontend", - "//clang:lex", - "//clang:testing", - "//clang:tooling", - "//llvm:Core", - "//llvm:Support", - "//llvm:TestingSupport", - "//llvm:gmock", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_library( - name = "ast_matchers_tests_hdrs", - testonly = 1, - hdrs = glob( - ["ASTMatchers/*.h"], - allow_empty = False, - ), - deps = [ - "//clang:ast_matchers", - "//clang:frontend", - "//clang:testing", - "//clang:tooling", - "//llvm:gtest", - ], -) - -cc_test( - name = "ast_matchers_tests", - size = "medium", - srcs = glob( - ["ASTMatchers/*.cpp"], - allow_empty = False, - ), - shard_count = 20, - deps = [ - ":ast_matchers_tests_hdrs", - "//clang:ast", - "//clang:ast_matchers", - "//clang:frontend", - "//clang:tooling", - "//llvm:Support", - "//llvm:TestingSupport", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "ast_matchers_dynamic_tests", - size = "small", - srcs = glob( - ["ASTMatchers/Dynamic/*.cpp"], - allow_empty = False, - ), - deps = [ - ":ast_matchers_tests_hdrs", - "//clang:ast_matchers", - "//clang:ast_matchers_dynamic", - "//clang:frontend", - "//clang:tooling", - "//llvm:Support", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "analysis_tests", - size = "small", - srcs = glob( - [ - "Analysis/*.cpp", - "Analysis/*.h", - ], - allow_empty = False, - ), - deps = [ - "//clang:analysis", - "//clang:ast", - "//clang:ast_matchers", - "//clang:basic", - "//clang:lex", - "//clang:parse", - "//clang:tooling", - "//llvm:Support", - "//llvm:gmock", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "basic_tests", - size = "small", - srcs = glob( - ["Basic/*.cpp"], - allow_empty = False, - ), - deps = [ - "//clang:basic", - "//clang:frontend", - "//clang:lex", - "//llvm:Support", - "//llvm:TestingSupport", - "//llvm:config", - "//llvm:gmock", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "codegen_tests", - size = "small", - srcs = glob( - [ - "CodeGen/*.cpp", - "CodeGen/*.h", - ], - allow_empty = False, - ), - deps = [ - "//clang:ast", - "//clang:basic", - "//clang:codegen", - "//clang:frontend", - "//clang:lex", - "//clang:parse", - "//clang:sema", - "//llvm:Core", - "//llvm:Support", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "format_tests", - size = "medium", - srcs = glob( - [ - "Format/*.cpp", - "Format/*.h", - "Tooling/*.h", - ], - allow_empty = False, - ), - copts = ["$(STACK_FRAME_UNLIMITED)"], - shard_count = 20, - deps = [ - "//clang:basic", - "//clang:format", - "//clang:frontend", - "//clang:tooling_core", - "//llvm:Support", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "frontend_tests", - size = "small", - srcs = glob( - ["Frontend/*.cpp"], - allow_empty = False, - ), - deps = [ - "//clang:ast", - "//clang:basic", - "//clang:codegen", - "//clang:driver_options_inc_gen", - "//clang:frontend", - "//clang:frontend_tool", - "//clang:lex", - "//clang:sema", - "//clang:serialization", - "//llvm:Support", - "//llvm:gmock", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "lex_tests", - size = "small", - srcs = glob( - [ - "Lex/*.cpp", - "Lex/*.h", - ], - allow_empty = False, - ), - copts = ["$(STACK_FRAME_UNLIMITED)"], - deps = [ - "//clang:ast", - "//clang:basic", - "//clang:lex", - "//clang:parse", - "//clang:sema", - "//clang:serialization", - "//llvm:Support", - "//llvm:gmock", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -# A library to carefully expose the tooling headers using the include prefix -# expected by the `rename_tests`. -cc_library( - name = "rename_tests_tooling_hdrs", - testonly = 1, - hdrs = glob( - ["Tooling/*.h"], - allow_empty = False, - ), - include_prefix = "unittests", - deps = [ - "//clang:ast", - "//clang:basic", - "//clang:frontend", - "//clang:rewrite", - "//clang:tooling", - "//clang:tooling_core", - "//llvm:Support", - "//llvm:gtest", - ], -) - -cc_test( - name = "rename_tests", - size = "small", - timeout = "moderate", - srcs = glob( - [ - "Rename/*.cpp", - "Rename/*.h", - ], - allow_empty = False, - ), - shard_count = 20, - deps = [ - ":rename_tests_tooling_hdrs", - "//clang:ast_matchers", - "//clang:basic", - "//clang:format", - "//clang:frontend", - "//clang:tooling", - "//clang:tooling_refactoring", - "//llvm:Support", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "rewrite_tests", - size = "small", - srcs = glob( - ["Rewrite/*.cpp"], - allow_empty = False, - ), - deps = [ - "//clang:rewrite", - "//clang:tooling", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "sema_tests", - size = "small", - srcs = glob( - ["Sema/*.cpp"], - allow_empty = False, - ), - deps = [ - ":ast_matchers_tests_hdrs", - "//clang:ast", - "//clang:ast_matchers", - "//clang:frontend", - "//clang:lex", - "//clang:parse", - "//clang:sema", - "//clang:tooling", - "//llvm:TestingSupport", - "//llvm:gmock", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_library( - name = "static_analyzer_test_headers", - testonly = 1, - hdrs = glob( - ["StaticAnalyzer/*.h"], - allow_empty = False, - ), - deps = [ - "//clang:ast_matchers", - "//clang:crosstu", - "//clang:frontend", - "//clang:static_analyzer_core", - "//clang:static_analyzer_frontend", - "//clang:testing", - "//clang:tooling", - "//llvm:gtest", - ], -) - -cc_test( - name = "static_analyzer_tests", - size = "small", - srcs = glob( - ["StaticAnalyzer/*.cpp"], - allow_empty = False, - exclude = [ - # New test has unused-variable warnings. - "StaticAnalyzer/ParamRegionTest.cpp", - ], - ), - deps = [ - ":static_analyzer_test_headers", - "//clang:basic", - "//clang:frontend", - "//clang:static_analyzer_core", - "//clang:static_analyzer_frontend", - "//clang:tooling", - "//llvm:Support", - "//llvm:config", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "tooling_tests", - size = "medium", - srcs = glob( - [ - "Tooling/*.cpp", - "Tooling/*.h", - ], - allow_empty = False, - ), - shard_count = 20, - deps = [ - "//clang:ast", - "//clang:ast_matchers", - "//clang:basic", - "//clang:format", - "//clang:frontend", - "//clang:lex", - "//clang:rewrite", - "//clang:tooling", - "//clang:tooling_core", - "//clang:tooling_dependency_scanning", - "//clang:tooling_inclusions", - "//clang:tooling_refactoring", - "//clang:transformer", - "//llvm:Support", - "//llvm:TestingSupport", - "//llvm:gmock", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -# A library to carefully expose the tooling headers using the include prefix -# expected by the `tooling_recursive_ast_visitor_tests`. -cc_library( - name = "tooling_recursive_ast_visitor_tests_tooling_hdrs", - testonly = 1, - hdrs = glob( - ["Tooling/*.h"], - allow_empty = False, - ), - strip_include_prefix = "Tooling", - deps = [ - "//clang:ast", - "//clang:basic", - "//clang:frontend", - "//clang:rewrite", - "//clang:tooling", - "//clang:tooling_core", - "//llvm:Support", - "//llvm:gtest", - ], -) - -cc_test( - name = "tooling_recursive_ast_visitor_tests", - size = "medium", - srcs = glob( - ["Tooling/RecursiveASTVisitorTests/*.cpp"], - allow_empty = False, - ) + [ - "Tooling/RecursiveASTVisitorTests/CallbacksCommon.h", - ], - deps = [ - ":tooling_recursive_ast_visitor_tests_tooling_hdrs", - "//clang:ast", - "//clang:basic", - "//clang:frontend", - "//clang:lex", - "//clang:tooling", - "//clang:tooling_syntax", - "//llvm:Support", - "//llvm:TestingSupport", - "//llvm:gmock", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "tooling_syntax_tests", - size = "medium", - srcs = glob( - [ - "Tooling/Syntax/*.cpp", - "Tooling/Syntax/*.h", - ], - allow_empty = False, - ), - shard_count = 20, - deps = [ - "//clang:ast", - "//clang:basic", - "//clang:frontend", - "//clang:lex", - "//clang:testing", - "//clang:tooling", - "//clang:tooling_core", - "//clang:tooling_syntax", - "//llvm:Support", - "//llvm:TestingSupport", - "//llvm:gmock", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "libclang_tests", - size = "small", - srcs = glob( - ["libclang/*.cpp"], - allow_empty = False, - ) + [ - "libclang/TestUtils.h", - ], - args = select({ - "@bazel_tools//src/conditions:windows": [ - # Need to disable the VFS tests that don't use Windows friendly - # paths. These are also disabled on Windows in the CMake build. - "--gtest_filter=-*VirtualFileOverlay*", - ], - "//conditions:default": [], - }), - deps = [ - "//clang:libclang", - "//llvm:Support", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel deleted file mode 100644 index 76a3a23aeacde..0000000000000 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ /dev/null @@ -1,911 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -# LLVM libc project. -load(":libc_build_rules.bzl", "libc_function", "libc_math_function") -load(":platforms.bzl", "PLATFORM_CPU_ARM64", "PLATFORM_CPU_X86_64") -load("@bazel_skylib//lib:selects.bzl", "selects") - -package( - default_visibility = ["//visibility:public"], - licenses = ["notice"], -) - -# This empty root library helps us add an include path to this directory -# using the 'includes' attribute. The strings listed in the includes attribute -# are relative paths wrt this library but are inherited by the dependents -# appropriately. Hence, using this as a root dependency avoids adding include -# paths of the kind "../../" to other libc targets. -cc_library( - name = "libc_root", - includes = ["."], -) - -############################## Support libraries ############################# - -cc_library( - name = "__support_common", - hdrs = [ - "src/__support/architectures.h", - "src/__support/common.h", - "src/__support/endian.h", - "src/__support/sanitizer.h", - ], -) - -cc_library( - name = "__support_standalone_cpp", - hdrs = [ - "src/__support/CPP/Array.h", - "src/__support/CPP/ArrayRef.h", - "src/__support/CPP/Bitset.h", - "src/__support/CPP/Functional.h", - "src/__support/CPP/Limits.h", - "src/__support/CPP/StringView.h", - "src/__support/CPP/TypeTraits.h", - ], - deps = [":libc_root"], -) - -cc_library( - name = "__support_integer_operations", - hdrs = ["src/__support/integer_operations.h"], - deps = [":__support_standalone_cpp"], -) - -cc_library( - name = "__support_ctype_utils", - hdrs = ["src/__support/ctype_utils.h"], -) - -cc_library( - name = "__support_str_to_integer", - hdrs = ["src/__support/str_to_integer.h"], - deps = [ - ":__support_ctype_utils", - ":__support_standalone_cpp", - ], -) - -fputil_common_hdrs = [ - "src/__support/FPUtil/BasicOperations.h", - "src/__support/FPUtil/DivisionAndRemainderOperations.h", - "src/__support/FPUtil/FEnvImpl.h", - "src/__support/FPUtil/FEnvUtils.h", - "src/__support/FPUtil/FPBits.h", - "src/__support/FPUtil/FloatProperties.h", - "src/__support/FPUtil/Hypot.h", - "src/__support/FPUtil/ManipulationFunctions.h", - "src/__support/FPUtil/NearestIntegerOperations.h", - "src/__support/FPUtil/NormalFloat.h", - "src/__support/FPUtil/PlatformDefs.h", -] - -fputil_hdrs = selects.with_or({ - "//conditions:default": fputil_common_hdrs, - PLATFORM_CPU_X86_64: fputil_common_hdrs + [ - "src/__support/FPUtil/x86_64/LongDoubleBits.h", - "src/__support/FPUtil/x86_64/NextAfterLongDouble.h", - "src/__support/FPUtil/x86_64/FEnvImpl.h", - ], - PLATFORM_CPU_ARM64: fputil_common_hdrs + [ - "src/__support/FPUtil/aarch64/FEnvImpl.h", - ], -}) - -cc_library( - name = "__support_fputil", - hdrs = fputil_hdrs, - deps = [ - ":__support_common", - ":__support_standalone_cpp", - ":libc_root", - ], -) - -sqrt_common_hdrs = [ - "src/__support/FPUtil/sqrt.h", - "src/__support/FPUtil/generic/sqrt.h", - "src/__support/FPUtil/generic/sqrt_80_bit_long_double.h", -] - -sqrt_hdrs = selects.with_or({ - "//conditions:default": sqrt_common_hdrs, - PLATFORM_CPU_X86_64: sqrt_common_hdrs + [ - "src/__support/FPUtil/x86_64/sqrt.h", - ], - PLATFORM_CPU_ARM64: sqrt_common_hdrs + [ - "src/__support/FPUtil/aarch64/sqrt.h", - ], -}) - -cc_library( - name = "__support_fputil_sqrt", - hdrs = sqrt_hdrs, - deps = [ - ":__support_common", - ":__support_fputil", - ":__support_standalone_cpp", - ":libc_root", - ], -) - -################################ fenv targets ################################ - -libc_function( - name = "fetestexcept", - srcs = ["src/fenv/fetestexcept.cpp"], - hdrs = ["src/fenv/fetestexcept.h"], - deps = [ - ":__support_common", - ":__support_fputil", - ], -) - -libc_function( - name = "feclearexcept", - srcs = ["src/fenv/feclearexcept.cpp"], - hdrs = ["src/fenv/feclearexcept.h"], - deps = [ - ":__support_common", - ":__support_fputil", - ], -) - -libc_function( - name = "feraiseexcept", - srcs = ["src/fenv/feraiseexcept.cpp"], - hdrs = ["src/fenv/feraiseexcept.h"], - deps = [ - ":__support_common", - ":__support_fputil", - ], -) - -libc_function( - name = "fegetround", - srcs = ["src/fenv/fegetround.cpp"], - hdrs = ["src/fenv/fegetround.h"], - deps = [ - ":__support_common", - ":__support_fputil", - ], -) - -libc_function( - name = "fesetround", - srcs = ["src/fenv/fesetround.cpp"], - hdrs = ["src/fenv/fesetround.h"], - deps = [ - ":__support_common", - ":__support_fputil", - ], -) - -libc_function( - name = "fedisableexcept", - srcs = ["src/fenv/fedisableexcept.cpp"], - hdrs = ["src/fenv/fedisableexcept.h"], - deps = [ - ":__support_common", - ":__support_fputil", - ], -) - -libc_function( - name = "feenableexcept", - srcs = ["src/fenv/feenableexcept.cpp"], - hdrs = ["src/fenv/feenableexcept.h"], - deps = [ - ":__support_common", - ":__support_fputil", - ], -) - -libc_function( - name = "fegetexcept", - srcs = ["src/fenv/fegetexcept.cpp"], - hdrs = ["src/fenv/fegetexcept.h"], - deps = [ - ":__support_common", - ":__support_fputil", - ], -) - -libc_function( - name = "fegetenv", - srcs = ["src/fenv/fegetenv.cpp"], - hdrs = ["src/fenv/fegetenv.h"], - deps = [ - ":__support_common", - ":__support_fputil", - ], -) - -libc_function( - name = "fesetenv", - srcs = ["src/fenv/fesetenv.cpp"], - hdrs = ["src/fenv/fesetenv.h"], - deps = [ - ":__support_common", - ":__support_fputil", - ], -) - -libc_function( - name = "feupdateenv", - srcs = ["src/fenv/feupdateenv.cpp"], - hdrs = ["src/fenv/feupdateenv.h"], - deps = [ - ":__support_common", - ":__support_fputil", - ], -) - -libc_function( - name = "fegetexceptflag", - srcs = ["src/fenv/fegetexceptflag.cpp"], - hdrs = ["src/fenv/fegetexceptflag.h"], - deps = [ - ":__support_common", - ":__support_fputil", - ], -) - -libc_function( - name = "fesetexceptflag", - srcs = ["src/fenv/fesetexceptflag.cpp"], - hdrs = ["src/fenv/fesetexceptflag.h"], - deps = [ - ":__support_common", - ":__support_fputil", - ], -) - -libc_function( - name = "feholdexcept", - srcs = ["src/fenv/feholdexcept.cpp"], - hdrs = ["src/fenv/feholdexcept.h"], - deps = [ - ":__support_common", - ":__support_fputil", - ], -) - -################################ math targets ################################ - -cc_library( - name = "math_utils", - srcs = ["src/math/generic/math_utils.cpp"], - hdrs = ["src/math/generic/math_utils.h"], - deps = [ - ":__support_common", - ":__support_standalone_cpp", - ":libc_root", - ], -) - -cc_library( - name = "sincosf_utils", - srcs = ["src/math/generic/sincosf_data.cpp"], - hdrs = ["src/math/generic/sincosf_utils.h"], - deps = [ - ":libc_root", - ":math_utils", - ], -) - -libc_math_function(name = "fabs") - -libc_math_function(name = "fabsf") - -libc_math_function(name = "fabsl") - -libc_math_function(name = "fdim") - -libc_math_function(name = "fdimf") - -libc_math_function(name = "fdiml") - -libc_math_function( - name = "ceil", - specializations = [ - "aarch64", - "generic", - ], -) - -libc_math_function( - name = "ceilf", - specializations = [ - "aarch64", - "generic", - ], -) - -libc_math_function( - name = "ceill", - specializations = [ - "generic", - ], -) - -libc_math_function( - name = "floor", - specializations = [ - "aarch64", - "generic", - ], -) - -libc_math_function( - name = "floorf", - specializations = [ - "aarch64", - "generic", - ], -) - -libc_math_function(name = "floorl") - -libc_math_function(name = "ldexp") - -libc_math_function(name = "ldexpf") - -libc_math_function(name = "ldexpl") - -libc_math_function( - name = "trunc", - specializations = [ - "aarch64", - "generic", - ], -) - -libc_math_function( - name = "truncf", - specializations = [ - "aarch64", - "generic", - ], -) - -libc_math_function(name = "truncl") - -libc_math_function( - name = "round", - specializations = [ - "aarch64", - "generic", - ], -) - -libc_math_function( - name = "roundf", - specializations = [ - "aarch64", - "generic", - ], -) - -libc_math_function(name = "roundl") - -libc_math_function(name = "frexp") - -libc_math_function(name = "frexpf") - -libc_math_function(name = "frexpl") - -libc_math_function(name = "hypot") - -libc_math_function(name = "hypotf") - -libc_math_function(name = "logb") - -libc_math_function(name = "logbf") - -libc_math_function(name = "logbl") - -libc_math_function(name = "modf") - -libc_math_function(name = "modff") - -libc_math_function(name = "modfl") - -libc_math_function(name = "remquo") - -libc_math_function(name = "remquof") - -libc_math_function(name = "remquol") - -libc_math_function(name = "remainder") - -libc_math_function(name = "remainderf") - -libc_math_function(name = "remainderl") - -libc_math_function(name = "fmin") - -libc_math_function(name = "fminf") - -libc_math_function(name = "fminl") - -libc_math_function(name = "fmax") - -libc_math_function(name = "fmaxf") - -libc_math_function(name = "fmaxl") - -libc_math_function( - name = "cosf", - additional_deps = [ - ":math_utils", - ":sincosf_utils", - ], -) - -libc_math_function( - name = "sincosf", - additional_deps = [ - ":math_utils", - ":sincosf_utils", - ], -) - -libc_math_function( - name = "sinf", - additional_deps = [ - ":math_utils", - ":sincosf_utils", - ], -) - -libc_math_function( - name = "sqrt", - additional_deps = [ - ":__support_fputil_sqrt", - ], -) - -libc_math_function( - name = "sqrtf", - additional_deps = [ - ":__support_fputil_sqrt", - ], -) - -libc_math_function( - name = "sqrtl", - additional_deps = [ - ":__support_fputil_sqrt", - ], -) - -libc_math_function(name = "copysign") - -libc_math_function(name = "copysignf") - -libc_math_function(name = "copysignl") - -libc_math_function(name = "ilogb") - -libc_math_function(name = "ilogbf") - -libc_math_function(name = "ilogbl") - -libc_math_function(name = "rint") - -libc_math_function(name = "rintf") - -libc_math_function(name = "rintl") - -libc_math_function(name = "lrint") - -libc_math_function(name = "lrintf") - -libc_math_function(name = "lrintl") - -libc_math_function(name = "llrint") - -libc_math_function(name = "llrintf") - -libc_math_function(name = "llrintl") - -libc_math_function(name = "lround") - -libc_math_function(name = "lroundf") - -libc_math_function(name = "lroundl") - -libc_math_function(name = "llround") - -libc_math_function(name = "llroundf") - -libc_math_function(name = "llroundl") - -libc_math_function(name = "nearbyint") - -libc_math_function(name = "nearbyintf") - -libc_math_function(name = "nearbyintl") - -libc_math_function(name = "nextafter") - -libc_math_function(name = "nextafterf") - -libc_math_function(name = "nextafterl") - -############################### stdlib targets ############################### - -libc_function( - name = "atoi", - srcs = ["src/stdlib/atoi.cpp"], - hdrs = ["src/stdlib/atoi.h"], - deps = [ - ":__support_common", - ":__support_str_to_integer", - ], -) - -libc_function( - name = "atol", - srcs = ["src/stdlib/atol.cpp"], - hdrs = ["src/stdlib/atol.h"], - deps = [ - ":__support_common", - ":__support_str_to_integer", - ], -) - -libc_function( - name = "atoll", - srcs = ["src/stdlib/atoll.cpp"], - hdrs = ["src/stdlib/atoll.h"], - deps = [ - ":__support_common", - ":__support_str_to_integer", - ], -) - -libc_function( - name = "bsearch", - srcs = ["src/stdlib/bsearch.cpp"], - hdrs = ["src/stdlib/bsearch.h"], - deps = [ - ":__support_common", - ], -) - -libc_function( - name = "qsort", - srcs = ["src/stdlib/qsort.cpp"], - hdrs = ["src/stdlib/qsort.h"], - deps = [ - ":__support_common", - ], -) - -libc_function( - name = "strtol", - srcs = ["src/stdlib/strtol.cpp"], - hdrs = ["src/stdlib/strtol.h"], - deps = [ - ":__support_common", - ":__support_str_to_integer", - ], -) - -libc_function( - name = "strtoll", - srcs = ["src/stdlib/strtoll.cpp"], - hdrs = ["src/stdlib/strtoll.h"], - deps = [ - ":__support_common", - ":__support_str_to_integer", - ], -) - -libc_function( - name = "strtoul", - srcs = ["src/stdlib/strtoul.cpp"], - hdrs = ["src/stdlib/strtoul.h"], - deps = [ - ":__support_common", - ":__support_str_to_integer", - ], -) - -libc_function( - name = "strtoull", - srcs = ["src/stdlib/strtoull.cpp"], - hdrs = ["src/stdlib/strtoull.h"], - deps = [ - ":__support_common", - ":__support_str_to_integer", - ], -) - -############################### string targets ############################### - -no_sanitize_features = [ - "-asan", - "-msan", - "-tsan", - "-ubsan", -] - -cc_library( - name = "string_utils", - hdrs = ["src/string/string_utils.h"], - deps = [ - ":__support_common", - ":__support_standalone_cpp", - ":libc_root", - ], -) - -cc_library( - name = "string_memory_utils", - hdrs = [ - "src/string/memory_utils/elements.h", - "src/string/memory_utils/elements_aarch64.h", - "src/string/memory_utils/elements_x86.h", - "src/string/memory_utils/utils.h", - ], - textual_hdrs = [ - "src/string/memory_utils/bcmp_implementations.h", - "src/string/memory_utils/memcmp_implementations.h", - "src/string/memory_utils/memcpy_implementations.h", - "src/string/memory_utils/memset_implementations.h", - ], - deps = [ - ":__support_common", - ":libc_root", - ], -) - -libc_function( - name = "memchr", - srcs = ["src/string/memchr.cpp"], - hdrs = ["src/string/memchr.h"], - deps = [ - ":__support_common", - ":string_utils", - ], -) - -libc_function( - name = "memcpy", - srcs = ["src/string/memcpy.cpp"], - hdrs = ["src/string/memcpy.h"], - copts = [ - "-fno-builtin-memcpy", - "-fno-builtin-memmove", - "-mllvm -combiner-global-alias-analysis", - "-mllvm --tail-merge-threshold=0", - ], - features = no_sanitize_features, - deps = [ - ":__support_common", - ":string_memory_utils", - ], -) - -libc_function( - name = "memset", - srcs = ["src/string/memset.cpp"], - hdrs = ["src/string/memset.h"], - copts = [ - "-fno-builtin-memset", - "-mllvm -combiner-global-alias-analysis", - ], - features = no_sanitize_features, - deps = [ - ":__support_common", - ":string_memory_utils", - ], -) - -libc_function( - name = "memmove", - srcs = ["src/string/memmove.cpp"], - hdrs = ["src/string/memmove.h"], - copts = [ - "-fno-builtin-memmove", - "-mllvm -combiner-global-alias-analysis", - ], - features = no_sanitize_features, - deps = [ - ":__support_common", - ":__support_integer_operations", - ":memcpy", - ":string_memory_utils", - ], -) - -libc_function( - name = "memcmp", - srcs = ["src/string/memcmp.cpp"], - hdrs = ["src/string/memcmp.h"], - copts = [ - "-fno-builtin-memcmp", - "-mllvm -combiner-global-alias-analysis", - ], - features = no_sanitize_features, - deps = [ - ":__support_common", - ":__support_integer_operations", - ":string_memory_utils", - ], -) - -libc_function( - name = "bcmp", - srcs = ["src/string/bcmp.cpp"], - hdrs = ["src/string/bcmp.h"], - copts = [ - "-fno-builtin-bcmp", - "-fno-builtin-memcmp", - ], - features = no_sanitize_features, - deps = [ - ":__support_common", - ":string_memory_utils", - ], -) - -libc_function( - name = "bzero", - srcs = ["src/string/bzero.cpp"], - hdrs = ["src/string/bzero.h"], - copts = [ - "-fno-builtin-bzero", - "-fno-builtin-memset", - "-mllvm -combiner-global-alias-analysis", - ], - features = no_sanitize_features, - deps = [ - ":__support_common", - ":string_memory_utils", - ], -) - -libc_function( - name = "memrchr", - srcs = ["src/string/memrchr.cpp"], - hdrs = ["src/string/memrchr.h"], - deps = [ - ":__support_common", - ":string_utils", - ], -) - -libc_function( - name = "strlen", - srcs = ["src/string/strlen.cpp"], - hdrs = ["src/string/strlen.h"], - features = no_sanitize_features, - deps = [ - ":__support_common", - ":string_utils", - ], -) - -libc_function( - name = "strcpy", - srcs = ["src/string/strcpy.cpp"], - hdrs = ["src/string/strcpy.h"], - features = no_sanitize_features, - deps = [ - ":__support_common", - ":memcpy", - ":string_memory_utils", - ":string_utils", - ], -) - -# A sanitizer instrumented flavor of strcpy to be used with unittests. -libc_function( - name = "strcpy_sanitized", - testonly = 1, - srcs = ["src/string/strcpy.cpp"], - hdrs = ["src/string/strcpy.h"], - deps = [ - ":__support_common", - ":memcpy", - ":string_memory_utils", - ":string_utils", - ], -) - -libc_function( - name = "strcmp", - srcs = ["src/string/strcmp.cpp"], - hdrs = ["src/string/strcmp.h"], - deps = [ - ":__support_common", - ":string_utils", - ], -) - -libc_function( - name = "strchr", - srcs = ["src/string/strchr.cpp"], - hdrs = ["src/string/strchr.h"], - deps = [ - ":__support_common", - ":string_utils", - ], -) - -libc_function( - name = "strrchr", - srcs = ["src/string/strrchr.cpp"], - hdrs = ["src/string/strrchr.h"], - deps = [ - ":__support_common", - ":string_utils", - ], -) - -libc_function( - name = "strstr", - srcs = ["src/string/strstr.cpp"], - hdrs = ["src/string/strstr.h"], - deps = [ - ":__support_common", - ":string_utils", - ], -) - -libc_function( - name = "strnlen", - srcs = ["src/string/strnlen.cpp"], - hdrs = ["src/string/strnlen.h"], - deps = [ - ":__support_common", - ":string_utils", - ], -) - -libc_function( - name = "strcspn", - srcs = ["src/string/strcspn.cpp"], - hdrs = ["src/string/strcspn.h"], - deps = [ - ":__support_common", - ":string_utils", - ], -) - -libc_function( - name = "strspn", - srcs = ["src/string/strspn.cpp"], - hdrs = ["src/string/strspn.h"], - deps = [ - ":__support_common", - ":__support_standalone_cpp", - ":string_utils", - ], -) - -libc_function( - name = "strpbrk", - srcs = ["src/string/strpbrk.cpp"], - hdrs = ["src/string/strpbrk.h"], - deps = [ - ":__support_common", - ":string_utils", - ], -) - -libc_function( - name = "strtok", - srcs = ["src/string/strtok.cpp"], - hdrs = ["src/string/strtok.h"], - deps = [ - ":__support_common", - ":string_utils", - ], -) diff --git a/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl b/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl deleted file mode 100644 index 8e86e8f8a9940..0000000000000 --- a/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl +++ /dev/null @@ -1,86 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -"""LLVM libc startlark rules for building individual functions.""" - -load(":platforms.bzl", "PLATFORM_CPU_ARM64", "PLATFORM_CPU_X86_64") -load("@bazel_skylib//lib:selects.bzl", "selects") - -LIBC_ROOT_TARGET = ":libc_root" -INTERNAL_SUFFIX = ".__internal__" - -def libc_function(name, srcs, deps = None, copts = None, **kwargs): - """Add target for a libc function. - - The libc function is eventually available as a cc_library target by name - "name". LLVM libc implementations of libc functions are in C++. So, this - rule internally generates a C wrapper for the C++ implementation and adds - it to the source list of the cc_library. This way, the C++ implementation - and the C wrapper are both available in the cc_library. - - Args: - name: Target name. It is normally the name of the function this target is - for. - srcs: The .cpp files which contain the function implementation. - deps: The list of target dependencies if any. - copts: The list of options to add to the C++ compilation command. - **kwargs: Other attributes relevant for a cc_library. For example, deps. - """ - deps = deps or [] - deps.append(LIBC_ROOT_TARGET) - copts = copts or [] - copts.append("-O3") - - # We compile the code twice, the first target is suffixed with ".__internal__" and contains the - # C++ functions in the "__llvm_libc" namespace. This allows us to test the function in the - # presence of another libc. - native.cc_library( - name = name + INTERNAL_SUFFIX, - srcs = srcs, - deps = deps, - copts = copts, - linkstatic = 1, - **kwargs - ) - - # This second target is the llvm libc C function. - copts.append("-DLLVM_LIBC_PUBLIC_PACKAGING") - native.cc_library( - name = name, - srcs = srcs, - deps = deps, - copts = copts, - linkstatic = 1, - **kwargs - ) - -def libc_math_function( - name, - specializations = None, - additional_deps = None): - """Add a target for a math function. - - Args: - name: The name of the function. - specializations: List of machine specializations available for this - function. Possible specializations are "generic", - "aarch64" and "x86_64". - additional_deps: Other deps like helper cc_library targes used by the - math function. - """ - additional_deps = additional_deps or [] - specializations = specializations or ["generic"] - select_map = {} - if "generic" in specializations: - select_map["//conditions:default"] = ["src/math/generic/" + name + ".cpp"] - if "aarch64" in specializations: - select_map[PLATFORM_CPU_ARM64] = ["src/math/aarch64/" + name + ".cpp"] - if "x86_64" in specializations: - select_map[PLATFORM_CPU_X86_64] = ["src/math/x86_64/" + name + ".cpp"] - libc_function( - name = name, - srcs = selects.with_or(select_map), - hdrs = ["src/math/" + name + ".h"], - deps = [":__support_common", ":__support_fputil"] + additional_deps, - ) diff --git a/utils/bazel/llvm-project-overlay/libc/platforms.bzl b/utils/bazel/llvm-project-overlay/libc/platforms.bzl deleted file mode 100644 index 7137984740e24..0000000000000 --- a/utils/bazel/llvm-project-overlay/libc/platforms.bzl +++ /dev/null @@ -1,9 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -"""Defines global variables that lists target cpus""" - -PLATFORM_CPU_ARM64 = ("@platforms//cpu:arm64") - -PLATFORM_CPU_X86_64 = ("@platforms//cpu:x86_64") diff --git a/utils/bazel/llvm-project-overlay/libunwind/BUILD.bazel b/utils/bazel/llvm-project-overlay/libunwind/BUILD.bazel deleted file mode 100644 index 718eebfb737b9..0000000000000 --- a/utils/bazel/llvm-project-overlay/libunwind/BUILD.bazel +++ /dev/null @@ -1,20 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -package( - default_visibility = ["//visibility:public"], - licenses = ["notice"], -) - -# The ld64 linker and lld-macho use the libunwind headers only for the constant -# definitions, in order to parse and convert DWARF to the compact encoding. -cc_library( - name = "unwind_headers_only", - hdrs = [ - "include/__libunwind_config.h", - "include/libunwind.h", - "include/mach-o/compact_unwind_encoding.h", - ], - strip_include_prefix = "include", -) diff --git a/utils/bazel/llvm-project-overlay/lld/BUILD.bazel b/utils/bazel/llvm-project-overlay/lld/BUILD.bazel deleted file mode 100644 index e204f7b81a0a2..0000000000000 --- a/utils/bazel/llvm-project-overlay/lld/BUILD.bazel +++ /dev/null @@ -1,284 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -load("//llvm:tblgen.bzl", "gentbl") - -package( - default_visibility = ["//visibility:public"], - licenses = ["notice"], -) - -# TODO: Actually compute version info -genrule( - name = "config_version_gen", - outs = ["include/lld/Common/Version.inc"], - cmd = "echo '#define LLD_VERSION_STRING \"14.0.0\"' > $@", -) - -genrule( - name = "vcs_version_gen", - outs = ["Common/VCSVersion.inc"], - cmd = "echo '#undef LLD_REVISION' >> $@\n" + - "echo '#undef LLD_REPOSITORY' >> $@\n", -) - -# See https://github.com/bazelbuild/bazel/issues/13803 -cc_library( - name = "vcs_version", - hdrs = ["Common/VCSVersion.inc"], - strip_include_prefix = "Common", -) - -cc_library( - name = "Common", - srcs = [":config_version_gen"] + glob(["Common/*.cpp"]), - hdrs = glob(["include/lld/Common/*.h"]), - includes = ["include"], - deps = [ - ":vcs_version", - "//llvm:CodeGen", - "//llvm:Core", - "//llvm:Option", - "//llvm:Support", - "//llvm:Target", - ], -) - -gentbl( - name = "elf_options_inc_gen", - # See https://github.com/bazelbuild/bazel/issues/13803 - strip_include_prefix = "ELF", - tbl_outs = [( - "-gen-opt-parser-defs", - "ELF/Options.inc", - )], - tblgen = "//llvm:llvm-tblgen", - td_file = "ELF/Options.td", - td_srcs = [ - "//llvm:include/llvm/Option/OptParser.td", - ], -) - -cc_library( - name = "ELF", - srcs = glob([ - "ELF/*.cpp", - "ELF/*.h", - "ELF/Arch/*.cpp", - ]), - includes = ["ELF"], - textual_hdrs = [ - "ELF/Arch/PPCInsns.def", - ], - deps = [ - ":Common", - ":elf_options_inc_gen", - "//llvm:AllTargetsAsmParsers", - "//llvm:AllTargetsCodeGens", - "//llvm:AllTargetsDisassemblers", - "//llvm:Analysis", - "//llvm:BinaryFormat", - "//llvm:BitReader", - "//llvm:BitWriter", - "//llvm:CodeGen", - "//llvm:Core", - "//llvm:DebugInfoDWARF", - "//llvm:Demangle", - "//llvm:IPO", - "//llvm:LTO", - "//llvm:Linker", - "//llvm:MC", - "//llvm:Object", - "//llvm:Option", - "//llvm:Passes", - "//llvm:Support", - "//llvm:TransformUtils", - ], -) - -gentbl( - name = "coff_options_inc_gen", - # See https://github.com/bazelbuild/bazel/issues/13803 - strip_include_prefix = "COFF", - tbl_outs = [( - "-gen-opt-parser-defs", - "COFF/Options.inc", - )], - tblgen = "//llvm:llvm-tblgen", - td_file = "COFF/Options.td", - td_srcs = [ - "//llvm:include/llvm/Option/OptParser.td", - ], -) - -cc_library( - name = "COFF", - srcs = glob([ - "COFF/*.cpp", - "COFF/*.h", - ]), - includes = ["COFF"], - deps = [ - ":Common", - ":coff_options_inc_gen", - "//llvm:AllTargetsAsmParsers", - "//llvm:AllTargetsCodeGens", - "//llvm:AllTargetsDisassemblers", - "//llvm:Analysis", - "//llvm:BitReader", - "//llvm:BitWriter", - "//llvm:Core", - "//llvm:DebugInfoPDB", - "//llvm:IPO", - "//llvm:LTO", - "//llvm:LibDriver", - "//llvm:Linker", - "//llvm:MC", - "//llvm:Object", - "//llvm:Option", - "//llvm:Support", - "//llvm:Symbolize", - "//llvm:TransformUtils", - "//llvm:WindowsManifest", - ], -) - -gentbl( - name = "mingw_options_inc_gen", - tbl_outs = [( - "-gen-opt-parser-defs", - "MinGW/Options.inc", - )], - tblgen = "//llvm:llvm-tblgen", - td_file = "MinGW/Options.td", - td_srcs = [ - "//llvm:include/llvm/Option/OptParser.td", - ], -) - -cc_library( - name = "MinGW", - srcs = glob([ - "MinGW/*.cpp", - "MinGW/*.h", - ]), - includes = ["MinGW"], - deps = [ - ":Common", - ":mingw_options_inc_gen", - "//llvm:Option", - "//llvm:Support", - ], -) - -gentbl( - name = "macho_options_inc_gen", - # See https://github.com/bazelbuild/bazel/issues/13803 - strip_include_prefix = "MachO", - tbl_outs = [( - "-gen-opt-parser-defs", - "MachO/Options.inc", - )], - tblgen = "//llvm:llvm-tblgen", - td_file = "MachO/Options.td", - td_srcs = [ - "//llvm:include/llvm/Option/OptParser.td", - ], -) - -cc_library( - name = "MachO", - srcs = glob([ - "MachO/**/*.cpp", - "MachO/**/*.h", - ]), - includes = ["MachO"], - deps = [ - ":Common", - ":macho_options_inc_gen", - "//libunwind:unwind_headers_only", - "//llvm:LTO", - ], -) - -gentbl( - name = "wasm_options_inc_gen", - # See https://github.com/bazelbuild/bazel/issues/13803 - strip_include_prefix = "wasm", - tbl_outs = [( - "-gen-opt-parser-defs", - "wasm/Options.inc", - )], - tblgen = "//llvm:llvm-tblgen", - td_file = "wasm/Options.td", - td_srcs = [ - "//llvm:include/llvm/Option/OptParser.td", - ], -) - -cc_library( - name = "Wasm", - srcs = glob([ - "wasm/*.cpp", - "wasm/*.h", - ]), - includes = ["wasm"], - deps = [ - ":Common", - ":wasm_options_inc_gen", - "//llvm:AllTargetsAsmParsers", - "//llvm:AllTargetsCodeGens", - "//llvm:BinaryFormat", - "//llvm:Core", - "//llvm:LTO", - "//llvm:Object", - "//llvm:Option", - "//llvm:Support", - ], -) - -cc_binary( - name = "lld", - srcs = glob([ - "tools/lld/*.cpp", - "tools/lld/*.h", - ]), - tags = [ - "manual", # External dependency (libxml through WindowsManifest) - "nobuildkite", # TODO(gcmn): Remote executors don't have libxml - ], - deps = [ - ":COFF", - ":Common", - ":ELF", - ":MachO", - ":MinGW", - ":Wasm", - "//llvm:Support", - ], -) - -# These are the required names for lld running under different environs. -# -# Unix/Linux require that the binary be named "ld.lld". -# macOS require that the binary be named "ld64.lld". -# Windows require that the binary be named "lld-link". -# WebAssembly builds require that the binary be named "wasm-ld". -genrule( - name = "gen_lld", - srcs = [":lld"], - outs = [ - "ld.lld", - "ld64.lld", - "lld-link", - "wasm-ld", - ], - cmd = - "target=$$(basename $<); for n in ld.lld ld64.lld lld-link wasm-ld; do ln -sf $$target $(@D)/$$n; done", - output_to_bindir = 1, - tags = [ - "manual", # External dependency (libxml through WindowsManifest) - "nobuildkite", # TODO(gcmn): Remote executors don't have libxml - ], -) diff --git a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel deleted file mode 100644 index 85d79a29b5710..0000000000000 --- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel +++ /dev/null @@ -1,4316 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -load(":template_rule.bzl", "template_rule") -load(":tblgen.bzl", "gentbl") -load(":config.bzl", "llvm_config_defines") -load(":targets.bzl", "llvm_targets") -load(":enum_targets_gen.bzl", "enum_targets_gen") -load(":binary_alias.bzl", "binary_alias") - -package( - default_visibility = ["//visibility:public"], - licenses = ["notice"], -) - -exports_files(["LICENSE.TXT"]) - -# It may be tempting to add compiler flags here, but that should be avoided. -# The necessary warnings and other compile flags should be provided by the -# toolchain or the `.bazelrc` file. This is just a workaround until we have a -# widely available feature to enable unlimited stack frame instead of using -# this `Make` variable. -llvm_copts = [ - "$(STACK_FRAME_UNLIMITED)", -] - -enum_targets_gen( - name = "targets_def_gen", - src = "include/llvm/Config/Targets.def.in", - out = "include/llvm/Config/Targets.def", - macro_name = "TARGET", - targets = llvm_targets, -) - -# Enabled targets with ASM printers. -llvm_target_asm_printers = [ - t - for t in llvm_targets - if glob(["lib/Target/{}/*AsmPrinter.cpp".format(t)]) -] - -enum_targets_gen( - name = "asm_printers_def_gen", - src = "include/llvm/Config/AsmPrinters.def.in", - out = "include/llvm/Config/AsmPrinters.def", - macro_name = "ASM_PRINTER", - targets = llvm_target_asm_printers, -) - -# Enabled targets with ASM parsers. -llvm_target_asm_parsers = [ - t - for t in llvm_targets - if glob(["lib/Target/{}/AsmParser/CMakeLists.txt".format(t)]) -] - -enum_targets_gen( - name = "asm_parsers_def_gen", - src = "include/llvm/Config/AsmParsers.def.in", - out = "include/llvm/Config/AsmParsers.def", - macro_name = "ASM_PARSER", - targets = llvm_target_asm_parsers, -) - -# Enabled targets with disassemblers. -llvm_target_disassemblers = [ - t - for t in llvm_targets - if glob(["lib/Target/{}/Disassembler/CMakeLists.txt".format(t)]) -] - -enum_targets_gen( - name = "disassemblers_def_gen", - src = "include/llvm/Config/Disassemblers.def.in", - out = "include/llvm/Config/Disassemblers.def", - macro_name = "DISASSEMBLER", - targets = llvm_target_disassemblers, -) - -# Enabled targets with MCA. -llvm_target_mcas = [ - t - for t in llvm_targets - if glob(["lib/Target/{}/MCA/CMakeLists.txt".format(t)]) -] - -enum_targets_gen( - name = "target_mca_def_gen", - src = "include/llvm/Config/TargetMCAs.def.in", - out = "include/llvm/Config/TargetMCAs.def", - macro_name = "TARGETMCA", - targets = llvm_target_mcas, -) - -# TODO: Need to replace this with something that actually extracts the git -# commit from the LLVM source (submodule or http_archive). -genrule( - name = "version_info_gen", - outs = ["include/llvm/Config/VersionInfo.h"], - cmd = "echo '#define LLVM_VERSION_INFO \"git\"' > $@", -) - -template_rule( - name = "abi_breaking_h_gen", - src = "include/llvm/Config/abi-breaking.h.cmake", - out = "include/llvm/Config/abi-breaking.h", - substitutions = { - # Define to enable checks that alter the LLVM C++ ABI - "#cmakedefine01 LLVM_ENABLE_ABI_BREAKING_CHECKS": "#define LLVM_ENABLE_ABI_BREAKING_CHECKS 0", - - # Define to enable reverse iteration of unordered llvm containers - "#cmakedefine01 LLVM_ENABLE_REVERSE_ITERATION": "#define LLVM_ENABLE_REVERSE_ITERATION 0", - }, -) - -# To enable diff testing out of tree -exports_files([ - "include/llvm/Config/config.h.cmake", - "include/llvm/Config/llvm-config.h.cmake", - "include/llvm/Config/abi-breaking.h.cmake", -]) - -cc_library( - name = "config", - hdrs = [ - "include/llvm/Config/VersionInfo.h", - "include/llvm/Config/abi-breaking.h", - "include/llvm/Config/llvm-config.h", - ], - copts = llvm_copts, - defines = llvm_config_defines, - includes = ["include"], - textual_hdrs = [ - "include/llvm/Config/AsmParsers.def", - "include/llvm/Config/AsmPrinters.def", - "include/llvm/Config/Disassemblers.def", - "include/llvm/Config/Targets.def", - "include/llvm/Config/TargetMCAs.def", - # Needed for include scanner to find execinfo.h - "include/llvm/Config/config.h", - ], -) - -cc_library( - name = "Demangle", - srcs = glob([ - "lib/Demangle/*.cpp", - "lib/Demangle/*.h", - ]), - hdrs = glob(["include/llvm/Demangle/*.h"]), - copts = llvm_copts, - deps = [":config"], -) - -genrule( - name = "generate_vcs_revision", - outs = ["include/llvm/Support/VCSRevision.h"], - cmd = "echo '#define LLVM_REVISION \"git\"' >> $@\n" + - "echo '#undef LLVM_REPOSITORY' >> $@\n", -) - -genrule( - name = "generate_static_extension_registry", - outs = ["include/llvm/Support/Extension.def"], - cmd = "echo -e '// extension handlers' >> $@\n" + - "echo -e '#undef HANDLE_EXTENSION' >> $@\n", -) - -cc_library( - name = "Support", - srcs = glob([ - "lib/Support/*.c", - "lib/Support/*.cpp", - "lib/Support/*.h", - "lib/Support/*.inc", - # To avoid a dependency cycle. - "include/llvm/Option/*.h", - ]) + select({ - "@bazel_tools//src/conditions:windows": glob([ - "lib/Support/Windows/*.h", - "lib/Support/Windows/*.inc", - ]), - "//conditions:default": glob([ - "lib/Support/Unix/*.h", - "lib/Support/Unix/*.inc", - ]), - }), - hdrs = glob([ - "include/llvm/Support/**/*.h", - "include/llvm/ADT/*.h", - ]) + [ - "include/llvm-c/Core.h", - "include/llvm-c/DataTypes.h", - "include/llvm-c/Deprecated.h", - "include/llvm-c/DisassemblerTypes.h", - "include/llvm-c/Error.h", - "include/llvm-c/ErrorHandling.h", - "include/llvm-c/ExternC.h", - "include/llvm-c/Support.h", - "include/llvm-c/Types.h", - "include/llvm/ExecutionEngine/JITSymbol.h", - "include/llvm/Support/Extension.def", - "include/llvm/Support/VCSRevision.h", - ], - copts = llvm_copts, - includes = ["include"], - linkopts = select({ - "@bazel_tools//src/conditions:windows": [], - "@bazel_tools//src/conditions:freebsd": [ - "-pthread", - "-lexecinfo", - "-ldl", - "-lm", - ], - "//conditions:default": [ - "-pthread", - "-ldl", - "-lm", - ], - }), - textual_hdrs = glob([ - "include/llvm/Support/*.def", - ]), - deps = [ - ":config", - ":Demangle", - # We unconditionally depend on the custom LLVM terminfo wrapper. This - # will be an empty library unless terminfo is enabled, in which case it - # will both provide the necessary dependencies and configuration - # defines. - "@llvm_terminfo//:terminfo", - # We unconditionally depend on the custom LLVM zlib wrapper. This will - # be an empty library unless zlib is enabled, in which case it will - # both provide the necessary dependencies and configuration defines. - "@llvm_zlib//:zlib", - ], -) - -# Note: although FileCheck (the binary) is a test utility, some non-test -# targets depend on the FileCheck library target. -cc_library( - name = "FileCheckLib", - srcs = glob([ - "lib/FileCheck/*.cpp", - "lib/FileCheck/*.h", - ]), - hdrs = glob(["include/llvm/FileCheck/*.h"]), - copts = llvm_copts, - deps = [":Support"], -) - -cc_library( - name = "LineEditor", - srcs = glob([ - "lib/LineEditor/*.cpp", - "lib/LineEditor/*.h", - ]), - hdrs = glob(["include/llvm/LineEditor/*.h"]), - copts = llvm_copts, - deps = [ - ":Support", - ":config", - ], -) - -cc_library( - name = "Option", - srcs = glob([ - "lib/Option/*.cpp", - "lib/Option/*.h", - ]), - hdrs = glob(["include/llvm/Option/*.h"]), - copts = llvm_copts, - deps = [ - ":Support", - ":config", - ], -) - -cc_library( - name = "TableGen", - srcs = glob([ - "lib/TableGen/*.cpp", - "lib/TableGen/*.h", - ]), - hdrs = glob(["include/llvm/TableGen/*.h"]), - copts = llvm_copts, - deps = [ - ":Support", - ":config", - ], -) - -# This exists to avoid circular dependencies. -cc_library( - name = "ir_headers", - hdrs = glob( - [ - "include/llvm/*.h", - "include/llvm/IR/*.h", - ], - exclude = [ - "include/llvm/LinkAllPasses.h", - ], - ) + [ - "include/llvm/IR/Value.def", - "include/llvm-c/Comdat.h", - "include/llvm-c/DebugInfo.h", - ], - copts = llvm_copts, -) - -cc_library( - name = "BinaryFormat", - srcs = glob([ - "lib/BinaryFormat/*.cpp", - "lib/BinaryFormat/*.def", - "lib/BinaryFormat/*.h", - ]), - hdrs = glob([ - "include/llvm/BinaryFormat/*.h", - ]), - copts = llvm_copts, - includes = ["include"], - textual_hdrs = glob([ - "include/llvm/BinaryFormat/*.def", - "include/llvm/BinaryFormat/ELFRelocs/*.def", - ]), - deps = [ - ":Support", - ], -) - -cc_library( - name = "DebugInfo", - hdrs = glob(["include/llvm/DebugInfo/*.h"]), - copts = llvm_copts, - deps = [ - ":Object", - ":Support", - ], -) - -cc_library( - name = "DebugInfoMSF", - srcs = glob([ - "lib/DebugInfo/MSF/*.cpp", - "lib/DebugInfo/MSF/*.h", - ]), - hdrs = glob(["include/llvm/DebugInfo/MSF/*.h"]), - copts = llvm_copts, - deps = [":Support"], -) - -cc_library( - name = "DebugInfoCodeView", - srcs = glob([ - "lib/DebugInfo/CodeView/*.cpp", - "lib/DebugInfo/CodeView/*.h", - ]), - hdrs = glob([ - "include/llvm/DebugInfo/CodeView/*.h", - ]), - copts = llvm_copts, - textual_hdrs = glob([ - "include/llvm/DebugInfo/CodeView/*.def", - ]), - deps = [ - ":BinaryFormat", - ":DebugInfoMSF", - ":Support", - ], -) - -cc_library( - name = "DebugInfoPDB", - srcs = glob([ - "lib/DebugInfo/PDB/*.cpp", - "lib/DebugInfo/PDB/*.h", - "lib/DebugInfo/PDB/Native/*.cpp", - "lib/DebugInfo/PDB/Native/*.h", - ]), - hdrs = glob([ - "include/llvm/DebugInfo/PDB/*.h", - "include/llvm/DebugInfo/PDB/Native/*.h", - ]), - copts = llvm_copts, - deps = [ - ":BinaryFormat", - ":DebugInfo", - ":DebugInfoCodeView", - ":DebugInfoMSF", - ":Object", - ":Support", - ":config", - ], -) - -cc_library( - name = "Debuginfod", - srcs = glob([ - "lib/Debuginfod/*.cpp", - ]), - hdrs = glob([ - "include/llvm/Debuginfod/*.h", - ]), - copts = llvm_copts, - deps = [ - ":Support", - ], -) - -cc_library( - name = "MC", - srcs = glob([ - "lib/MC/*.cpp", - "lib/MC/*.h", - ]), - hdrs = glob([ - "include/llvm/MC/*.h", - "include/llvm/MC/*.def", - "include/llvm/MC/*.inc", - ]), - copts = llvm_copts, - deps = [ - ":BinaryFormat", - ":DebugInfoCodeView", - ":Support", - ":config", - ":ir_headers", - ], -) - -cc_library( - name = "DebugInfoDWARF", - srcs = glob([ - "lib/DebugInfo/DWARF/*.cpp", - "lib/DebugInfo/DWARF/*.h", - ]), - hdrs = glob(["include/llvm/DebugInfo/DWARF/*.h"]), - copts = llvm_copts, - deps = [ - ":BinaryFormat", - ":DebugInfo", - ":MC", - ":Object", - ":Support", - ], -) - -cc_library( - name = "Symbolize", - srcs = glob([ - "lib/DebugInfo/Symbolize/*.cpp", - "lib/DebugInfo/Symbolize/*.h", - ]), - hdrs = glob(["include/llvm/DebugInfo/Symbolize/*.h"]), - copts = llvm_copts, - deps = [ - ":BinaryFormat", - ":DebugInfo", - ":DebugInfoDWARF", - ":DebugInfoPDB", - ":Debuginfod", - ":Demangle", - ":Object", - ":Support", - ], -) - -cc_library( - name = "tblgen", - srcs = glob([ - "utils/TableGen/*.cpp", - "utils/TableGen/GlobalISel/*.cpp", - - # Some tablegen sources include headers from MC, so these have to be - # listed here. MC uses headers produced by tablegen, so it cannot be a - # regular dependency. - "include/llvm/MC/*.h", - - # We have to include these headers here as well as in the `hdrs` below - # to allow the `.cpp` files to use file-relative-inclusion to find - # them, even though consumers of this library use inclusion relative to - # `utils/TableGen` with the `strip_includes_prefix` of this library. - # This mixture appears to be incompatible with header modules. - "utils/TableGen/*.h", - "utils/TableGen/GlobalISel/*.h", - ]), - hdrs = glob([ - "utils/TableGen/*.h", - "utils/TableGen/GlobalISel/*.h", - ]), - copts = llvm_copts, - features = ["-header_modules"], - strip_include_prefix = "utils/TableGen", - deps = [ - ":Support", - ":TableGen", - ":config", - ], -) - -cc_binary( - name = "llvm-tblgen", - copts = llvm_copts, - stamp = 0, - deps = [ - ":tblgen", - ], -) - -gentbl( - name = "intrinsic_enums_gen", - tbl_outs = [("-gen-intrinsic-enums", "include/llvm/IR/IntrinsicEnums.inc")], - tblgen = ":llvm-tblgen", - td_file = "include/llvm/IR/Intrinsics.td", - td_srcs = glob([ - "include/llvm/CodeGen/*.td", - "include/llvm/IR/Intrinsics*.td", - ]), -) - -gentbl( - name = "intrinsics_impl_gen", - tbl_outs = [("-gen-intrinsic-impl", "include/llvm/IR/IntrinsicImpl.inc")], - tblgen = ":llvm-tblgen", - td_file = "include/llvm/IR/Intrinsics.td", - td_srcs = glob([ - "include/llvm/CodeGen/*.td", - "include/llvm/IR/Intrinsics*.td", - ]), -) - -# Note that the intrinsics are not currently set up so they can be pruned for -# disabled targets. -llvm_target_intrinsics_list = [ - { - "name": "AArch64", - "intrinsic_prefix": "aarch64", - }, - { - "name": "AMDGPU", - "intrinsic_prefix": "amdgcn", - }, - { - "name": "ARM", - "intrinsic_prefix": "arm", - }, - { - "name": "BPF", - "intrinsic_prefix": "bpf", - }, - { - "name": "Hexagon", - "intrinsic_prefix": "hexagon", - }, - { - "name": "Mips", - "intrinsic_prefix": "mips", - }, - { - "name": "NVPTX", - "intrinsic_prefix": "nvvm", - }, - { - "name": "PowerPC", - "intrinsic_prefix": "ppc", - }, - { - "name": "R600", - "intrinsic_prefix": "r600", - }, - { - "name": "RISCV", - "intrinsic_prefix": "riscv", - }, - { - "name": "S390", - "intrinsic_prefix": "s390", - }, - { - "name": "VE", - "intrinsic_prefix": "ve", - }, - { - "name": "WebAssembly", - "intrinsic_prefix": "wasm", - }, - { - "name": "X86", - "intrinsic_prefix": "x86", - }, - { - "name": "XCore", - "intrinsic_prefix": "xcore", - }, -] - -[[ - gentbl( - name = "intrinsic_" + target["name"] + "_gen", - tbl_outs = [( - "-gen-intrinsic-enums -intrinsic-prefix=" + target["intrinsic_prefix"], - "include/llvm/IR/Intrinsics" + target["name"] + ".h", - )], - tblgen = ":llvm-tblgen", - td_file = "include/llvm/IR/Intrinsics.td", - td_srcs = glob([ - "include/llvm/CodeGen/*.td", - "include/llvm/IR/*.td", - ]), - ), -] for target in llvm_target_intrinsics_list] - -gentbl( - name = "attributes_gen", - tbl_outs = [("-gen-attrs", "include/llvm/IR/Attributes.inc")], - tblgen = ":llvm-tblgen", - td_file = "include/llvm/IR/Attributes.td", - td_srcs = [ - "include/llvm/IR/Attributes.td", - "include/llvm/IR/AttributesAMDGPU.td", - ], -) - -cc_library( - name = "BitstreamReader", - srcs = glob([ - "lib/Bitstream/Reader/*.cpp", - "lib/Bitstream/Reader/*.h", - ]), - hdrs = [ - "include/llvm/Bitstream/BitCodes.h", - "include/llvm/Bitstream/BitstreamReader.h", - ], - copts = llvm_copts, - deps = [ - ":Support", - ], -) - -cc_library( - name = "BitstreamWriter", - srcs = glob([ - "lib/Bitstream/Writer/*.h", - ]), - hdrs = [ - "include/llvm/Bitstream/BitCodes.h", - "include/llvm/Bitstream/BitstreamWriter.h", - ], - copts = llvm_copts, - deps = [ - ":Support", - ], -) - -cc_library( - name = "Remarks", - srcs = glob( - [ - "lib/Remarks/*.cpp", - "lib/Remarks/*.h", - ], - exclude = ["lib/Remarks/RemarkLinker.cpp"], - ), - hdrs = glob( - [ - "include/llvm/Remarks/*.h", - ], - exclude = ["include/llvm/Remarks/RemarkLinker.h"], - ) + [ - "include/llvm-c/Remarks.h", - ], - copts = llvm_copts, - deps = [ - ":BitstreamReader", - ":BitstreamWriter", - ":Support", - ], -) - -cc_library( - name = "remark_linker", - srcs = ["lib/Remarks/RemarkLinker.cpp"], - hdrs = ["include/llvm/Remarks/RemarkLinker.h"], - copts = llvm_copts, - deps = [ - ":Object", - ":Support", - ], -) - -filegroup( - name = "llvm_intrinsics_headers", - srcs = [ - "include/llvm/IR/Intrinsics" + target["name"] + ".h" - for target in llvm_target_intrinsics_list - ], -) - -cc_library( - name = "Core", - srcs = glob([ - "lib/IR/*.cpp", - "lib/IR/*.h", - ]), - hdrs = glob( - [ - "include/llvm/*.h", - "include/llvm/IR/*.h", - ], - exclude = [ - "include/llvm/LinkAllPasses.h", - ], - ) + [ - "include/llvm-c/Comdat.h", - "include/llvm-c/DebugInfo.h", - ] + [":llvm_intrinsics_headers"], - copts = llvm_copts, - textual_hdrs = glob(["include/llvm/IR/*.def"]), - deps = [ - ":BinaryFormat", - ":Remarks", - ":Support", - ":attributes_gen", - ":config", - ":intrinsic_enums_gen", - ":intrinsics_impl_gen", - ], -) - -cc_library( - name = "BitReader", - srcs = glob([ - "lib/Bitcode/Reader/*.cpp", - "lib/Bitcode/Reader/*.h", - ]), - hdrs = [ - "include/llvm-c/BitReader.h", - "include/llvm/Bitcode/BitcodeAnalyzer.h", - "include/llvm/Bitcode/BitcodeCommon.h", - "include/llvm/Bitcode/BitcodeReader.h", - "include/llvm/Bitcode/LLVMBitCodes.h", - ], - copts = llvm_copts, - deps = [ - ":BitstreamReader", - ":Core", - ":Support", - ":config", - ], -) - -cc_library( - name = "MCParser", - srcs = glob([ - "lib/MC/MCParser/*.cpp", - "lib/MC/MCParser/*.h", - ]), - hdrs = glob(["include/llvm/MC/MCParser/*.h"]), - copts = llvm_copts, - deps = [ - ":BinaryFormat", - ":MC", - ":Support", - ":config", - ], -) - -cc_library( - name = "TextAPI", - srcs = glob([ - "lib/TextAPI/**/*.cpp", - ]), - hdrs = glob([ - "include/llvm/TextAPI/**/*.h", - "include/llvm/TextAPI/**/*.def", - "lib/TextAPI/**/*.h", - ]), - copts = llvm_copts, - deps = [ - ":BinaryFormat", - ":Support", - ], -) - -cc_library( - name = "Object", - srcs = glob([ - "lib/Object/*.cpp", - "lib/Object/*.h", - ]), - hdrs = glob([ - "include/llvm/Object/*.h", - ]) + [ - "include/llvm-c/Object.h", - ], - copts = llvm_copts, - deps = [ - ":BinaryFormat", - ":BitReader", - ":Core", - ":MC", - ":MCParser", - ":Support", - ":TextAPI", - ":config", - ], -) - -cc_library( - name = "ObjectYAML", - srcs = glob([ - "lib/ObjectYAML/*.cpp", - "lib/ObjectYAML/*.h", - ]), - hdrs = glob(["include/llvm/ObjectYAML/*.h"]), - copts = llvm_copts, - deps = [ - ":BinaryFormat", - ":DebugInfoCodeView", - ":Object", - ":Support", - ], -) - -cc_library( - name = "ProfileData", - srcs = glob([ - "lib/ProfileData/*.cpp", - "lib/ProfileData/*.h", - ]), - hdrs = glob([ - "include/llvm/ProfileData/*.h", - "include/llvm/ProfileData/*.inc", - ]), - copts = llvm_copts, - deps = [ - ":Core", - ":DebugInfoDWARF", - ":Support", - ":config", - ], -) - -cc_library( - name = "Coverage", - srcs = glob([ - "lib/ProfileData/Coverage/*.cpp", - "lib/ProfileData/Coverage/*.h", - ]), - hdrs = glob(["include/llvm/ProfileData/Coverage/*.h"]), - copts = llvm_copts, - deps = [ - ":Object", - ":ProfileData", - ":Support", - ], -) - -cc_library( - name = "Analysis", - srcs = glob( - [ - "lib/Analysis/*.cpp", - "lib/Analysis/*.h", - "lib/Analysis/*.def", - ], - ), - hdrs = glob( - [ - "include/llvm/Analysis/*.h", - "include/llvm/Analysis/Utils/*.h", - ], - ) + [ - "include/llvm-c/Analysis.h", - "include/llvm-c/Initialization.h", - ], - copts = llvm_copts, - textual_hdrs = glob([ - "include/llvm/Analysis/*.def", - ]), - deps = [ - ":BinaryFormat", - ":Core", - ":Object", - ":ProfileData", - ":Support", - ":config", - ], -) - -cc_library( - name = "BitWriter", - srcs = glob([ - "lib/Bitcode/Writer/*.cpp", - "lib/Bitcode/Writer/*.h", - ]), - hdrs = [ - "include/llvm-c/BitWriter.h", - "include/llvm/Bitcode/BitcodeCommon.h", - "include/llvm/Bitcode/BitcodeWriter.h", - "include/llvm/Bitcode/BitcodeWriterPass.h", - "include/llvm/Bitcode/LLVMBitCodes.h", - ], - copts = llvm_copts, - deps = [ - ":Analysis", - ":BitstreamWriter", - ":Core", - ":MC", - ":Object", - ":Support", - ":config", - ], -) - -cc_library( - name = "Target", - srcs = glob([ - "lib/Target/*.cpp", - "lib/Target/*.h", - ]), - hdrs = glob([ - "include/llvm/Target/*.h", - ]) + [ - "include/llvm-c/Target.h", - "include/llvm-c/TargetMachine.h", - ], - copts = llvm_copts, - deps = [ - ":Analysis", - ":BinaryFormat", - ":Core", - ":MC", - ":Support", - ":config", - ], -) - -cc_library( - name = "DWP", - srcs = glob([ - "lib/DWP/*.cpp", - "lib/DWP/*.h", - ]), - hdrs = glob(["include/llvm/DWP/*.h"]), - copts = llvm_copts, - deps = [ - ":DebugInfoDWARF", - ":MC", - ":Object", - ":Support", - ":Target", - ], -) - -cc_library( - name = "TransformUtils", - srcs = glob([ - "lib/Transforms/Utils/*.cpp", - "lib/Transforms/Utils/*.h", - ]), - hdrs = glob(["include/llvm/Transforms/Utils/*.h"]) + [ - "include/llvm/Transforms/Utils.h", - "include/llvm-c/Transforms/Utils.h", - ], - copts = llvm_copts, - deps = [ - ":Analysis", - ":BinaryFormat", - ":BitWriter", - ":Core", - ":Support", - ":Target", - ":config", - ], -) - -gentbl( - name = "InstCombineTableGen", - strip_include_prefix = "lib/Target/AMDGPU", - tbl_outs = [( - "-gen-searchable-tables", - "lib/Target/AMDGPU/InstCombineTables.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "lib/Target/AMDGPU/InstCombineTables.td", - td_srcs = glob([ - "include/llvm/CodeGen/*.td", - "include/llvm/IR/Intrinsics*.td", - ]) + [ - "lib/Target/AMDGPU/InstCombineTables.td", - "include/llvm/TableGen/SearchableTable.td", - ], -) - -cc_library( - name = "InstCombine", - srcs = glob([ - "lib/Transforms/InstCombine/*.cpp", - "lib/Transforms/InstCombine/*.h", - ]), - hdrs = glob(["include/llvm/Transforms/InstCombine/*.h"]) + [ - "include/llvm-c/Transforms/InstCombine.h", - ], - copts = llvm_copts, - deps = [ - ":Analysis", - ":Core", - ":InstCombineTableGen", - ":Support", - ":Target", - ":TransformUtils", - ":config", - ], -) - -cc_library( - name = "AggressiveInstCombine", - srcs = glob([ - "lib/Transforms/AggressiveInstCombine/*.cpp", - "lib/Transforms/AggressiveInstCombine/*.h", - ]), - hdrs = [ - "include/llvm-c/Transforms/AggressiveInstCombine.h", - "include/llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h", - ], - copts = llvm_copts, - deps = [ - ":Analysis", - ":Core", - ":Support", - ":TransformUtils", - ], -) - -cc_library( - name = "Instrumentation", - srcs = glob([ - "lib/Transforms/Instrumentation/*.cpp", - "lib/Transforms/Instrumentation/*.h", - "lib/Transforms/Instrumentation/*.inc", - ]), - hdrs = glob(["include/llvm/Transforms/Instrumentation/*.h"]) + [ - "include/llvm/Transforms/Instrumentation.h", - ], - copts = llvm_copts, - deps = [ - ":Analysis", - ":BinaryFormat", - ":Core", - ":MC", - ":ProfileData", - ":Support", - ":TransformUtils", - ":config", - ], -) - -cc_library( - name = "ObjCARC", - srcs = glob([ - "lib/Transforms/ObjCARC/*.cpp", - "lib/Transforms/ObjCARC/*.h", - ]), - hdrs = ["include/llvm/Transforms/ObjCARC.h"], - copts = llvm_copts, - deps = [ - ":Analysis", - ":Core", - ":Support", - ":Target", - ":TransformUtils", - ":config", - ], -) - -cc_library( - name = "Scalar", - srcs = glob([ - "lib/Transforms/Scalar/*.cpp", - "lib/Transforms/Scalar/*.h", - ]), - hdrs = glob(["include/llvm/Transforms/Scalar/*.h"]) + [ - "include/llvm-c/Transforms/Scalar.h", - "include/llvm/Transforms/Scalar.h", - ], - copts = llvm_copts, - deps = [ - ":AggressiveInstCombine", - ":Analysis", - ":Core", - ":InstCombine", - ":ProfileData", - ":Support", - ":Target", - ":TransformUtils", - ":config", - ], -) - -cc_library( - name = "Vectorize", - srcs = glob([ - "lib/Transforms/Vectorize/*.cpp", - "lib/Transforms/Vectorize/*.h", - ]), - hdrs = glob([ - "include/llvm/Transforms/Vectorize/*.h", - ]) + [ - "include/llvm-c/Transforms/Vectorize.h", - "include/llvm/Transforms/Vectorize.h", - ], - copts = llvm_copts, - deps = [ - ":Analysis", - ":Core", - ":Support", - ":Target", - ":TransformUtils", - ":config", - ], -) - -filegroup( - name = "omp_td_files", - srcs = glob([ - "include/llvm/Frontend/OpenMP/*.td", - "include/llvm/Frontend/Directive/*.td", - ]), -) - -gentbl( - name = "omp_gen", - library = False, - tbl_outs = [ - ("--gen-directive-decl", "include/llvm/Frontend/OpenMP/OMP.h.inc"), - ], - tblgen = ":llvm-tblgen", - td_file = "include/llvm/Frontend/OpenMP/OMP.td", - td_srcs = [":omp_td_files"], -) - -gentbl( - name = "omp_gen_impl", - library = False, - tbl_outs = [ - ("--gen-directive-impl", "include/llvm/Frontend/OpenMP/OMP.inc"), - ], - tblgen = ":llvm-tblgen", - td_file = "include/llvm/Frontend/OpenMP/OMP.td", - td_srcs = [":omp_td_files"], -) - -cc_library( - name = "FrontendOpenMP", - srcs = glob([ - "lib/Frontend/OpenMP/*.cpp", - ]), - hdrs = glob([ - "include/llvm/Frontend/OpenMP/*.h", - "include/llvm/Frontend/OpenMP/OMP/*.h", - "include/llvm/Frontend/*.h", - ]) + [ - "include/llvm/Frontend/OpenMP/OMP.h.inc", - "include/llvm/Frontend/OpenMP/OMP.inc", - ], - copts = llvm_copts, - textual_hdrs = glob([ - "include/llvm/Frontend/OpenMP/*.def", - ]), - deps = [ - ":Analysis", - ":Core", - ":Scalar", - ":Support", - ":TransformUtils", - ], -) - -filegroup( - name = "acc_td_files", - srcs = glob([ - "include/llvm/Frontend/OpenACC/*.td", - "include/llvm/Frontend/Directive/*.td", - ]), -) - -gentbl( - name = "acc_gen", - library = False, - tbl_outs = [ - ("--gen-directive-decl", "include/llvm/Frontend/OpenACC/ACC.h.inc"), - ], - tblgen = ":llvm-tblgen", - td_file = "include/llvm/Frontend/OpenACC/ACC.td", - td_srcs = [":acc_td_files"], -) - -gentbl( - name = "acc_gen_impl", - library = False, - tbl_outs = [ - ("--gen-directive-impl", "include/llvm/Frontend/OpenACC/ACC.inc"), - ], - tblgen = ":llvm-tblgen", - td_file = "include/llvm/Frontend/OpenACC/ACC.td", - td_srcs = [":acc_td_files"], -) - -cc_library( - name = "FrontendOpenACC", - srcs = glob([ - "lib/Frontend/OpenACC/*.cpp", - ]) + [ - "include/llvm/Frontend/OpenACC/ACC.inc", - ], - hdrs = glob([ - "include/llvm/Frontend/OpenACC/*.h", - ]) + ["include/llvm/Frontend/OpenACC/ACC.h.inc"], - copts = llvm_copts, - deps = [ - ":Analysis", - ":Core", - ":Support", - ":TransformUtils", - ], -) - -cc_library( - name = "AsmParser", - srcs = glob([ - "lib/AsmParser/*.cpp", - "lib/AsmParser/*.h", - ]), - hdrs = glob(["include/llvm/AsmParser/*.h"]), - copts = llvm_copts, - deps = [ - ":BinaryFormat", - ":Core", - ":Support", - ], -) - -cc_library( - name = "IRReader", - srcs = glob([ - "lib/IRReader/*.cpp", - "lib/IRReader/*.h", - ]), - hdrs = glob([ - "include/llvm/IRReader/*.h", - ]) + [ - "include/llvm-c/IRReader.h", - ], - copts = llvm_copts, - deps = [ - ":AsmParser", - ":BitReader", - ":Core", - ":Support", - ":config", - ], -) - -cc_library( - name = "Linker", - srcs = glob([ - "lib/Linker/*.cpp", - "lib/Linker/*.h", - ]), - hdrs = glob([ - "include/llvm/Linker/*.h", - ]) + [ - "include/llvm-c/Linker.h", - ], - copts = llvm_copts, - deps = [ - ":Core", - ":Support", - ":TransformUtils", - ":config", - ], -) - -cc_library( - name = "IPO", - srcs = glob([ - "lib/Transforms/IPO/*.cpp", - "lib/Transforms/IPO/*.h", - ]), - hdrs = glob([ - "include/llvm/Transforms/IPO/*.h", - ]) + [ - "include/llvm-c/Transforms/IPO.h", - "include/llvm-c/Transforms/PassManagerBuilder.h", - "include/llvm/Transforms/IPO.h", - ], - copts = llvm_copts, - deps = [ - ":AggressiveInstCombine", - ":Analysis", - ":BinaryFormat", - ":BitReader", - ":BitWriter", - ":Core", - ":FrontendOpenMP", - ":IRReader", - ":InstCombine", - ":Instrumentation", - ":Linker", - ":ObjCARC", - ":Object", - ":ProfileData", - ":Scalar", - ":Support", - ":Target", - ":TransformUtils", - ":Vectorize", - ":config", - ], -) - -cc_library( - name = "CFGuard", - srcs = glob([ - "lib/Transforms/CFGuard/*.cpp", - "lib/Transforms/CFGuard/*.h", - ]), - hdrs = ["include/llvm/Transforms/CFGuard.h"], - copts = llvm_copts, - deps = [ - ":Core", - ":Support", - ], -) - -cc_library( - name = "Coroutines", - srcs = glob([ - "lib/Transforms/Coroutines/*.cpp", - "lib/Transforms/Coroutines/*.h", - ]), - hdrs = [ - "include/llvm-c/Transforms/Coroutines.h", - "include/llvm/Transforms/Coroutines.h", - "include/llvm/Transforms/Coroutines/CoroCleanup.h", - "include/llvm/Transforms/Coroutines/CoroEarly.h", - "include/llvm/Transforms/Coroutines/CoroElide.h", - "include/llvm/Transforms/Coroutines/CoroSplit.h", - ], - copts = llvm_copts, - deps = [ - ":Analysis", - ":Core", - ":IPO", - ":Scalar", - ":Support", - ":TransformUtils", - ":config", - ], -) - -# Meta-target for clients which depend on all of the transforms libraries. -cc_library( - name = "common_transforms", - deps = [ - ":AggressiveInstCombine", - ":CFGuard", - ":Coroutines", - ":IPO", - ":InstCombine", - ":Instrumentation", - ":ObjCARC", - ":Scalar", - ":Vectorize", - ], -) - -cc_library( - name = "asm_printer_defs", - copts = llvm_copts, - textual_hdrs = glob(["lib/CodeGen/AsmPrinter/*.def"]), -) - -cc_library( - name = "CodeGen", - srcs = glob( - [ - "lib/CodeGen/**/*.cpp", - "lib/CodeGen/**/*.h", - "lib/CodeGen/SelectionDAG/*.cpp", - "lib/CodeGen/SelectionDAG/*.h", - ], - ), - hdrs = [ - "include/llvm/LinkAllPasses.h", - ] + glob( - [ - "include/llvm/CodeGen/**/*.h", - ], - ), - copts = llvm_copts, - textual_hdrs = glob([ - "include/llvm/CodeGen/**/*.def", - "include/llvm/CodeGen/**/*.inc", - ]), - deps = [ - ":Analysis", - ":AsmParser", - ":BinaryFormat", - ":BitReader", - ":BitWriter", - ":Core", - ":DebugInfoCodeView", - ":DebugInfoDWARF", - ":IPO", - ":MC", - ":MCParser", - ":ProfileData", - ":Remarks", - ":Scalar", - ":Support", - ":Target", - ":TransformUtils", - ":asm_printer_defs", - ":config", - ], -) - -cc_library( - name = "MCDisassembler", - srcs = glob([ - "lib/MC/MCDisassembler/*.cpp", - "lib/MC/MCDisassembler/*.h", - ]), - hdrs = glob([ - "include/llvm/MC/MCDisassembler/*.h", - ]) + [ - "include/llvm-c/Disassembler.h", - ], - copts = llvm_copts, - deps = [ - ":MC", - ":Support", - ":config", - ], -) - -llvm_target_lib_list = [lib for lib in [ - { - "name": "AArch64", - "short_name": "AArch64", - "tbl_outs": [ - ("-gen-register-bank", "lib/Target/AArch64/AArch64GenRegisterBank.inc"), - ("-gen-register-info", "lib/Target/AArch64/AArch64GenRegisterInfo.inc"), - ("-gen-instr-info", "lib/Target/AArch64/AArch64GenInstrInfo.inc"), - ("-gen-emitter", "lib/Target/AArch64/AArch64GenMCCodeEmitter.inc"), - ("-gen-pseudo-lowering", "lib/Target/AArch64/AArch64GenMCPseudoLowering.inc"), - ("-gen-asm-writer", "lib/Target/AArch64/AArch64GenAsmWriter.inc"), - ("-gen-asm-writer -asmwriternum=1", "lib/Target/AArch64/AArch64GenAsmWriter1.inc"), - ("-gen-asm-matcher", "lib/Target/AArch64/AArch64GenAsmMatcher.inc"), - ("-gen-dag-isel", "lib/Target/AArch64/AArch64GenDAGISel.inc"), - ("-gen-fast-isel", "lib/Target/AArch64/AArch64GenFastISel.inc"), - ("-gen-global-isel", "lib/Target/AArch64/AArch64GenGlobalISel.inc"), - ("-gen-global-isel-combiner -combiners=AArch64O0PreLegalizerCombinerHelper", "lib/Target/AArch64/AArch64GenO0PreLegalizeGICombiner.inc"), - ("-gen-global-isel-combiner -combiners=AArch64PreLegalizerCombinerHelper", "lib/Target/AArch64/AArch64GenPreLegalizeGICombiner.inc"), - ("-gen-global-isel-combiner -combiners=AArch64PostLegalizerCombinerHelper", "lib/Target/AArch64/AArch64GenPostLegalizeGICombiner.inc"), - ("-gen-global-isel-combiner -combiners=AArch64PostLegalizerLoweringHelper", "lib/Target/AArch64/AArch64GenPostLegalizeGILowering.inc"), - ("-gen-callingconv", "lib/Target/AArch64/AArch64GenCallingConv.inc"), - ("-gen-subtarget", "lib/Target/AArch64/AArch64GenSubtargetInfo.inc"), - ("-gen-disassembler", "lib/Target/AArch64/AArch64GenDisassemblerTables.inc"), - ("-gen-searchable-tables", "lib/Target/AArch64/AArch64GenSystemOperands.inc"), - ], - }, - { - "name": "ARM", - "short_name": "ARM", - "tbl_outs": [ - ("-gen-register-bank", "lib/Target/ARM/ARMGenRegisterBank.inc"), - ("-gen-register-info", "lib/Target/ARM/ARMGenRegisterInfo.inc"), - ("-gen-searchable-tables", "lib/Target/ARM/ARMGenSystemRegister.inc"), - ("-gen-instr-info", "lib/Target/ARM/ARMGenInstrInfo.inc"), - ("-gen-emitter", "lib/Target/ARM/ARMGenMCCodeEmitter.inc"), - ("-gen-pseudo-lowering", "lib/Target/ARM/ARMGenMCPseudoLowering.inc"), - ("-gen-asm-writer", "lib/Target/ARM/ARMGenAsmWriter.inc"), - ("-gen-asm-matcher", "lib/Target/ARM/ARMGenAsmMatcher.inc"), - ("-gen-dag-isel", "lib/Target/ARM/ARMGenDAGISel.inc"), - ("-gen-fast-isel", "lib/Target/ARM/ARMGenFastISel.inc"), - ("-gen-global-isel", "lib/Target/ARM/ARMGenGlobalISel.inc"), - ("-gen-callingconv", "lib/Target/ARM/ARMGenCallingConv.inc"), - ("-gen-subtarget", "lib/Target/ARM/ARMGenSubtargetInfo.inc"), - ("-gen-disassembler", "lib/Target/ARM/ARMGenDisassemblerTables.inc"), - ], - }, - { - "name": "AMDGPU", - "short_name": "AMDGPU", - "tbl_outs": [ - ("-gen-register-bank", "lib/Target/AMDGPU/AMDGPUGenRegisterBank.inc"), - ("-gen-register-info", "lib/Target/AMDGPU/AMDGPUGenRegisterInfo.inc"), - ("-gen-instr-info", "lib/Target/AMDGPU/AMDGPUGenInstrInfo.inc"), - ("-gen-emitter", "lib/Target/AMDGPU/AMDGPUGenMCCodeEmitter.inc"), - ("-gen-pseudo-lowering", "lib/Target/AMDGPU/AMDGPUGenMCPseudoLowering.inc"), - ("-gen-asm-writer", "lib/Target/AMDGPU/AMDGPUGenAsmWriter.inc"), - ("-gen-asm-matcher", "lib/Target/AMDGPU/AMDGPUGenAsmMatcher.inc"), - ("-gen-dag-isel", "lib/Target/AMDGPU/AMDGPUGenDAGISel.inc"), - ("-gen-callingconv", "lib/Target/AMDGPU/AMDGPUGenCallingConv.inc"), - ("-gen-subtarget", "lib/Target/AMDGPU/AMDGPUGenSubtargetInfo.inc"), - ("-gen-disassembler", "lib/Target/AMDGPU/AMDGPUGenDisassemblerTables.inc"), - ("-gen-searchable-tables", "lib/Target/AMDGPU/AMDGPUGenSearchableTables.inc"), - ], - "tbl_deps": [ - ":amdgpu_isel_target_gen", - ":r600_target_gen", - ], - }, - { - "name": "AVR", - "short_name": "AVR", - "tbl_outs": [ - ("-gen-asm-matcher", "lib/Target/AVR/AVRGenAsmMatcher.inc"), - ("-gen-asm-writer", "lib/Target/AVR/AVRGenAsmWriter.inc"), - ("-gen-callingconv", "lib/Target/AVR/AVRGenCallingConv.inc"), - ("-gen-dag-isel", "lib/Target/AVR/AVRGenDAGISel.inc"), - ("-gen-disassembler", "lib/Target/AVR/AVRGenDisassemblerTables.inc"), - ("-gen-emitter", "lib/Target/AVR/AVRGenMCCodeEmitter.inc"), - ("-gen-instr-info", "lib/Target/AVR/AVRGenInstrInfo.inc"), - ("-gen-register-info", "lib/Target/AVR/AVRGenRegisterInfo.inc"), - ("-gen-subtarget", "lib/Target/AVR/AVRGenSubtargetInfo.inc"), - ], - }, - { - "name": "BPF", - "short_name": "BPF", - "tbl_outs": [ - ("-gen-asm-writer", "lib/Target/BPF/BPFGenAsmWriter.inc"), - ("-gen-asm-matcher", "lib/Target/BPF/BPFGenAsmMatcher.inc"), - ("-gen-callingconv", "lib/Target/BPF/BPFGenCallingConv.inc"), - ("-gen-dag-isel", "lib/Target/BPF/BPFGenDAGISel.inc"), - ("-gen-disassembler", "lib/Target/BPF/BPFGenDisassemblerTables.inc"), - ("-gen-emitter", "lib/Target/BPF/BPFGenMCCodeEmitter.inc"), - ("-gen-instr-info", "lib/Target/BPF/BPFGenInstrInfo.inc"), - ("-gen-register-info", "lib/Target/BPF/BPFGenRegisterInfo.inc"), - ("-gen-subtarget", "lib/Target/BPF/BPFGenSubtargetInfo.inc"), - ], - }, - { - "name": "Hexagon", - "short_name": "Hexagon", - "tbl_outs": [ - ("-gen-asm-matcher", "lib/Target/Hexagon/HexagonGenAsmMatcher.inc"), - ("-gen-asm-writer", "lib/Target/Hexagon/HexagonGenAsmWriter.inc"), - ("-gen-callingconv", "lib/Target/Hexagon/HexagonGenCallingConv.inc"), - ("-gen-dag-isel", "lib/Target/Hexagon/HexagonGenDAGISel.inc"), - ("-gen-dfa-packetizer", "lib/Target/Hexagon/HexagonGenDFAPacketizer.inc"), - ("-gen-disassembler", "lib/Target/Hexagon/HexagonGenDisassemblerTables.inc"), - ("-gen-instr-info", "lib/Target/Hexagon/HexagonGenInstrInfo.inc"), - ("-gen-emitter", "lib/Target/Hexagon/HexagonGenMCCodeEmitter.inc"), - ("-gen-register-info", "lib/Target/Hexagon/HexagonGenRegisterInfo.inc"), - ("-gen-subtarget", "lib/Target/Hexagon/HexagonGenSubtargetInfo.inc"), - ], - }, - { - "name": "Lanai", - "short_name": "Lanai", - "tbl_outs": [ - ("-gen-asm-matcher", "lib/Target/Lanai/LanaiGenAsmMatcher.inc"), - ("-gen-asm-writer", "lib/Target/Lanai/LanaiGenAsmWriter.inc"), - ("-gen-callingconv", "lib/Target/Lanai/LanaiGenCallingConv.inc"), - ("-gen-dag-isel", "lib/Target/Lanai/LanaiGenDAGISel.inc"), - ("-gen-disassembler", "lib/Target/Lanai/LanaiGenDisassemblerTables.inc"), - ("-gen-emitter", "lib/Target/Lanai/LanaiGenMCCodeEmitter.inc"), - ("-gen-instr-info", "lib/Target/Lanai/LanaiGenInstrInfo.inc"), - ("-gen-register-info", "lib/Target/Lanai/LanaiGenRegisterInfo.inc"), - ("-gen-subtarget", "lib/Target/Lanai/LanaiGenSubtargetInfo.inc"), - ], - }, - { - "name": "Mips", - "short_name": "Mips", - "tbl_outs": [ - ("-gen-asm-matcher", "lib/Target/Mips/MipsGenAsmMatcher.inc"), - ("-gen-asm-writer", "lib/Target/Mips/MipsGenAsmWriter.inc"), - ("-gen-callingconv", "lib/Target/Mips/MipsGenCallingConv.inc"), - ("-gen-dag-isel", "lib/Target/Mips/MipsGenDAGISel.inc"), - ("-gen-disassembler", "lib/Target/Mips/MipsGenDisassemblerTables.inc"), - ("-gen-emitter", "lib/Target/Mips/MipsGenMCCodeEmitter.inc"), - ("-gen-exegesis", "lib/Target/Mips/MipsGenExegesis.inc"), - ("-gen-fast-isel", "lib/Target/Mips/MipsGenFastISel.inc"), - ("-gen-global-isel", "lib/Target/Mips/MipsGenGlobalISel.inc"), - ("-gen-instr-info", "lib/Target/Mips/MipsGenInstrInfo.inc"), - ("-gen-pseudo-lowering", "lib/Target/Mips/MipsGenMCPseudoLowering.inc"), - ("-gen-register-bank", "lib/Target/Mips/MipsGenRegisterBank.inc"), - ("-gen-register-info", "lib/Target/Mips/MipsGenRegisterInfo.inc"), - ("-gen-subtarget", "lib/Target/Mips/MipsGenSubtargetInfo.inc"), - ], - }, - { - "name": "MSP430", - "short_name": "MSP430", - "tbl_outs": [ - ("-gen-asm-matcher", "lib/Target/MSP430/MSP430GenAsmMatcher.inc"), - ("-gen-asm-writer", "lib/Target/MSP430/MSP430GenAsmWriter.inc"), - ("-gen-callingconv", "lib/Target/MSP430/MSP430GenCallingConv.inc"), - ("-gen-dag-isel", "lib/Target/MSP430/MSP430GenDAGISel.inc"), - ("-gen-disassembler", "lib/Target/MSP430/MSP430GenDisassemblerTables.inc"), - ("-gen-emitter", "lib/Target/MSP430/MSP430GenMCCodeEmitter.inc"), - ("-gen-instr-info", "lib/Target/MSP430/MSP430GenInstrInfo.inc"), - ("-gen-register-info", "lib/Target/MSP430/MSP430GenRegisterInfo.inc"), - ("-gen-subtarget", "lib/Target/MSP430/MSP430GenSubtargetInfo.inc"), - ], - }, - { - "name": "NVPTX", - "short_name": "NVPTX", - "tbl_outs": [ - ("-gen-register-info", "lib/Target/NVPTX/NVPTXGenRegisterInfo.inc"), - ("-gen-instr-info", "lib/Target/NVPTX/NVPTXGenInstrInfo.inc"), - ("-gen-asm-writer", "lib/Target/NVPTX/NVPTXGenAsmWriter.inc"), - ("-gen-dag-isel", "lib/Target/NVPTX/NVPTXGenDAGISel.inc"), - ("-gen-subtarget", "lib/Target/NVPTX/NVPTXGenSubtargetInfo.inc"), - ], - }, - { - "name": "PowerPC", - "short_name": "PPC", - "tbl_outs": [ - ("-gen-asm-writer", "lib/Target/PowerPC/PPCGenAsmWriter.inc"), - ("-gen-asm-matcher", "lib/Target/PowerPC/PPCGenAsmMatcher.inc"), - ("-gen-emitter", "lib/Target/PowerPC/PPCGenMCCodeEmitter.inc"), - ("-gen-register-info", "lib/Target/PowerPC/PPCGenRegisterInfo.inc"), - ("-gen-instr-info", "lib/Target/PowerPC/PPCGenInstrInfo.inc"), - ("-gen-dag-isel", "lib/Target/PowerPC/PPCGenDAGISel.inc"), - ("-gen-fast-isel", "lib/Target/PowerPC/PPCGenFastISel.inc"), - ("-gen-callingconv", "lib/Target/PowerPC/PPCGenCallingConv.inc"), - ("-gen-subtarget", "lib/Target/PowerPC/PPCGenSubtargetInfo.inc"), - ("-gen-disassembler", "lib/Target/PowerPC/PPCGenDisassemblerTables.inc"), - ("-gen-register-bank", "lib/Target/PowerPC/PPCGenRegisterBank.inc"), - ("-gen-global-isel", "lib/Target/PowerPC/PPCGenGlobalISel.inc"), - ], - }, - { - "name": "Sparc", - "short_name": "Sparc", - "tbl_outs": [ - ("-gen-asm-writer", "lib/Target/Sparc/SparcGenAsmWriter.inc"), - ("-gen-asm-matcher", "lib/Target/Sparc/SparcGenAsmMatcher.inc"), - ("-gen-emitter", "lib/Target/Sparc/SparcGenMCCodeEmitter.inc"), - ("-gen-register-info", "lib/Target/Sparc/SparcGenRegisterInfo.inc"), - ("-gen-instr-info", "lib/Target/Sparc/SparcGenInstrInfo.inc"), - ("-gen-dag-isel", "lib/Target/Sparc/SparcGenDAGISel.inc"), - ("-gen-callingconv", "lib/Target/Sparc/SparcGenCallingConv.inc"), - ("-gen-subtarget", "lib/Target/Sparc/SparcGenSubtargetInfo.inc"), - ("-gen-disassembler", "lib/Target/Sparc/SparcGenDisassemblerTables.inc"), - ], - }, - { - "name": "SystemZ", - "short_name": "SystemZ", - "tbl_outs": [ - ("-gen-asm-matcher", "lib/Target/SystemZ/SystemZGenAsmMatcher.inc"), - ("-gen-asm-writer", "lib/Target/SystemZ/SystemZGenAsmWriter.inc"), - ("-gen-callingconv", "lib/Target/SystemZ/SystemZGenCallingConv.inc"), - ("-gen-dag-isel", "lib/Target/SystemZ/SystemZGenDAGISel.inc"), - ("-gen-disassembler", "lib/Target/SystemZ/SystemZGenDisassemblerTables.inc"), - ("-gen-emitter", "lib/Target/SystemZ/SystemZGenMCCodeEmitter.inc"), - ("-gen-instr-info", "lib/Target/SystemZ/SystemZGenInstrInfo.inc"), - ("-gen-register-info", "lib/Target/SystemZ/SystemZGenRegisterInfo.inc"), - ("-gen-subtarget", "lib/Target/SystemZ/SystemZGenSubtargetInfo.inc"), - ], - }, - { - "name": "RISCV", - "short_name": "RISCV", - "tbl_outs": [ - ("-gen-asm-matcher", "lib/Target/RISCV/RISCVGenAsmMatcher.inc"), - ("-gen-asm-writer", "lib/Target/RISCV/RISCVGenAsmWriter.inc"), - ("-gen-compress-inst-emitter", "lib/Target/RISCV/RISCVGenCompressInstEmitter.inc"), - ("-gen-dag-isel", "lib/Target/RISCV/RISCVGenDAGISel.inc"), - ("-gen-disassembler", "lib/Target/RISCV/RISCVGenDisassemblerTables.inc"), - ("-gen-global-isel", "lib/Target/RISCV/RISCVGenGlobalISel.inc"), - ("-gen-instr-info", "lib/Target/RISCV/RISCVGenInstrInfo.inc"), - ("-gen-emitter", "lib/Target/RISCV/RISCVGenMCCodeEmitter.inc"), - ("-gen-pseudo-lowering", "lib/Target/RISCV/RISCVGenMCPseudoLowering.inc"), - ("-gen-register-bank", "lib/Target/RISCV/RISCVGenRegisterBank.inc"), - ("-gen-register-info", "lib/Target/RISCV/RISCVGenRegisterInfo.inc"), - ("-gen-subtarget", "lib/Target/RISCV/RISCVGenSubtargetInfo.inc"), - ("-gen-searchable-tables", "lib/Target/RISCV/RISCVGenSearchableTables.inc"), - ], - }, - { - "name": "WebAssembly", - "short_name": "WebAssembly", - "tbl_outs": [ - ("-gen-disassembler", "lib/Target/WebAssembly/WebAssemblyGenDisassemblerTables.inc"), - ("-gen-asm-writer", "lib/Target/WebAssembly/WebAssemblyGenAsmWriter.inc"), - ("-gen-instr-info", "lib/Target/WebAssembly/WebAssemblyGenInstrInfo.inc"), - ("-gen-dag-isel", "lib/Target/WebAssembly/WebAssemblyGenDAGISel.inc"), - ("-gen-fast-isel", "lib/Target/WebAssembly/WebAssemblyGenFastISel.inc"), - ("-gen-emitter", "lib/Target/WebAssembly/WebAssemblyGenMCCodeEmitter.inc"), - ("-gen-register-info", "lib/Target/WebAssembly/WebAssemblyGenRegisterInfo.inc"), - ("-gen-subtarget", "lib/Target/WebAssembly/WebAssemblyGenSubtargetInfo.inc"), - ("-gen-asm-matcher", "lib/Target/WebAssembly/WebAssemblyGenAsmMatcher.inc"), - ], - }, - { - "name": "X86", - "short_name": "X86", - "tbl_outs": [ - ("-gen-register-bank", "lib/Target/X86/X86GenRegisterBank.inc"), - ("-gen-register-info", "lib/Target/X86/X86GenRegisterInfo.inc"), - ("-gen-disassembler", "lib/Target/X86/X86GenDisassemblerTables.inc"), - ("-gen-instr-info", "lib/Target/X86/X86GenInstrInfo.inc"), - ("-gen-asm-writer", "lib/Target/X86/X86GenAsmWriter.inc"), - ("-gen-asm-writer -asmwriternum=1", "lib/Target/X86/X86GenAsmWriter1.inc"), - ("-gen-asm-matcher", "lib/Target/X86/X86GenAsmMatcher.inc"), - ("-gen-dag-isel", "lib/Target/X86/X86GenDAGISel.inc"), - ("-gen-fast-isel", "lib/Target/X86/X86GenFastISel.inc"), - ("-gen-global-isel", "lib/Target/X86/X86GenGlobalISel.inc"), - ("-gen-callingconv", "lib/Target/X86/X86GenCallingConv.inc"), - ("-gen-subtarget", "lib/Target/X86/X86GenSubtargetInfo.inc"), - ("-gen-x86-EVEX2VEX-tables", "lib/Target/X86/X86GenEVEX2VEXTables.inc"), - ("-gen-exegesis", "lib/Target/X86/X86GenExegesis.inc"), - ], - }, - { - "name": "XCore", - "short_name": "XCore", - "tbl_outs": [ - ("-gen-asm-writer", "lib/Target/XCore/XCoreGenAsmWriter.inc"), - ("-gen-callingconv", "lib/Target/XCore/XCoreGenCallingConv.inc"), - ("-gen-dag-isel", "lib/Target/XCore/XCoreGenDAGISel.inc"), - ("-gen-disassembler", "lib/Target/XCore/XCoreGenDisassemblerTables.inc"), - ("-gen-instr-info", "lib/Target/XCore/XCoreGenInstrInfo.inc"), - ("-gen-register-info", "lib/Target/XCore/XCoreGenRegisterInfo.inc"), - ("-gen-subtarget", "lib/Target/XCore/XCoreGenSubtargetInfo.inc"), - ], - }, -] if lib["name"] in llvm_targets] - -cc_library( - name = "x86_target_layering_problem_hdrs", - textual_hdrs = ["lib/Target/X86/X86InstrInfo.h"], -) - -filegroup( - name = "common_target_td_sources", - srcs = glob([ - "include/llvm/CodeGen/*.td", - "include/llvm/Frontend/Directive/*.td", - "include/llvm/IR/Intrinsics*.td", - "include/llvm/TableGen/*.td", - "include/llvm/Target/*.td", - "include/llvm/Target/GlobalISel/*.td", - ]), -) - -gentbl( - name = "amdgpu_isel_target_gen", - strip_include_prefix = "lib/Target/AMDGPU", - tbl_outs = [ - ("-gen-global-isel", "lib/Target/AMDGPU/AMDGPUGenGlobalISel.inc"), - ("-gen-global-isel-combiner -combiners=AMDGPUPreLegalizerCombinerHelper", "lib/Target/AMDGPU/AMDGPUGenPreLegalizeGICombiner.inc"), - ("-gen-global-isel-combiner -combiners=AMDGPUPostLegalizerCombinerHelper", "lib/Target/AMDGPU/AMDGPUGenPostLegalizeGICombiner.inc"), - ("-gen-global-isel-combiner -combiners=AMDGPURegBankCombinerHelper", "lib/Target/AMDGPU/AMDGPUGenRegBankGICombiner.inc"), - ], - tblgen = ":llvm-tblgen", - td_file = "lib/Target/AMDGPU/AMDGPUGISel.td", - td_srcs = [ - ":common_target_td_sources", - ] + glob([ - "lib/Target/AMDGPU/*.td", - ]), -) - -gentbl( - name = "r600_target_gen", - strip_include_prefix = "lib/Target/AMDGPU", - tbl_outs = [ - ("-gen-asm-writer", "lib/Target/AMDGPU/R600GenAsmWriter.inc"), - ("-gen-callingconv", "lib/Target/AMDGPU/R600GenCallingConv.inc"), - ("-gen-dag-isel", "lib/Target/AMDGPU/R600GenDAGISel.inc"), - ("-gen-dfa-packetizer", "lib/Target/AMDGPU/R600GenDFAPacketizer.inc"), - ("-gen-instr-info", "lib/Target/AMDGPU/R600GenInstrInfo.inc"), - ("-gen-emitter", "lib/Target/AMDGPU/R600GenMCCodeEmitter.inc"), - ("-gen-register-info", "lib/Target/AMDGPU/R600GenRegisterInfo.inc"), - ("-gen-subtarget", "lib/Target/AMDGPU/R600GenSubtargetInfo.inc"), - ], - tblgen = ":llvm-tblgen", - td_file = "lib/Target/AMDGPU/R600.td", - td_srcs = [ - ":common_target_td_sources", - ] + glob([ - "lib/Target/AMDGPU/*.td", - ]), -) - -[[ - [gentbl( - name = target["name"] + "CommonTableGen", - strip_include_prefix = "lib/Target/" + target["name"], - tbl_outs = target["tbl_outs"], - tblgen = ":llvm-tblgen", - # MSVC isn't happy with long string literals, while other compilers - # which support them get significant compile time improvements with - # them enabled. Ideally this flag would only be enabled on Windows via - # a select() on `@bazel_tools//src/conditions:windows,`, but that would - # require refactoring gentbl from a macro into a rule. - # TODO(#92): Refactor gentbl to support this use - tblgen_args = "--long-string-literals=0", - td_file = "lib/Target/" + target["name"] + "/" + target["short_name"] + ".td", - td_srcs = [ - ":common_target_td_sources", - ] + glob([ - "lib/Target/" + target["name"] + "/*.td", - "lib/Target/" + target["name"] + "/GISel/*.td", - ]), - deps = target.get("tbl_deps", []), - )], - [cc_library( - name = target["name"] + "Info", - srcs = ["lib/Target/" + target["name"] + "/TargetInfo/" + target["name"] + "TargetInfo.cpp"], - hdrs = glob(["lib/Target/" + target["name"] + "/TargetInfo/*.h"]), - copts = llvm_copts, - # Workaround for https://github.com/bazelbuild/bazel/issues/3828 - # TODO(gcmn): Remove this when upgrading to a Bazel version containing - # https://github.com/bazelbuild/bazel/commit/e3b7e17b05f1 - includes = ["lib/Target/" + target["name"]], - strip_include_prefix = "lib/Target/" + target["name"], - deps = [ - ":" + target["name"] + "CommonTableGen", - ":Support", - ":Target", - ], - )], - # We cannot separate the `Utils` and `MCTargetDesc` sublibraries of - # a number of targets due to crisscrossing inclusion of headers. - [cc_library( - name = target["name"] + "UtilsAndDesc", - srcs = glob([ - "lib/Target/" + target["name"] + "/MCTargetDesc/*.cpp", - "lib/Target/" + target["name"] + "/Utils/*.cpp", - - # We have to include these headers here as well as in the `hdrs` - # below to allow the `.cpp` files to use file-relative-inclusion to - # find them, even though consumers of this library use inclusion - # relative to the target with the `strip_includes_prefix` of this - # library. This mixture is likely incompatible with header modules. - "lib/Target/" + target["name"] + "/MCTargetDesc/*.h", - "lib/Target/" + target["name"] + "/Utils/*.h", - ]), - hdrs = glob([ - "lib/Target/" + target["name"] + "/MCTargetDesc/*.h", - "lib/Target/" + target["name"] + "/Utils/*.h", - - # This a bit of a hack to allow us to expose common, internal - # target header files to other libraries within the target via - # target-relative includes. This usage of headers is inherently - # non-modular as there is a mixture of target-relative inclusion - # using this rule and file-relative inclusion using the repeated - # listing of these headers in the `srcs` of subsequent rules. - "lib/Target/" + target["name"] + "/*.h", - - # FIXME: The entries below should be `textual_hdrs` instead of - # `hdrs`, but unfortunately that doesn't work with - # `strip_include_prefix`: - # https://github.com/bazelbuild/bazel/issues/12424 - # - # Once that issue is fixed and released, we can switch this to - # `textual_hdrs` and remove the feature disabling the various Bazel - # features (both current and under-development) that motivated the - # distinction between these two. - "lib/Target/" + target["name"] + "/*.def", - "lib/Target/" + target["name"] + "/*.inc", - ]), - copts = llvm_copts, - features = [ - "-parse_headers", - "-header_modules", - ], - strip_include_prefix = "lib/Target/" + target["name"], - deps = [ - ":BinaryFormat", - # Depending on `:CodeGen` headers in this library is almost - # certainly a layering problem in numerous targets. - ":CodeGen", - ":DebugInfoCodeView", - ":MC", - ":MCDisassembler", - ":Support", - ":Target", - ":config", - ":" + target["name"] + "CommonTableGen", - ":" + target["name"] + "Info", - ], - )], - [cc_library( - name = target["name"] + "CodeGen", - srcs = glob([ - "lib/Target/" + target["name"] + "/GISel/*.cpp", - "lib/Target/" + target["name"] + "/GISel/*.h", - "lib/Target/" + target["name"] + "/*.cpp", - "lib/Target/" + target["name"] + "/*.h", - ]), - hdrs = ["lib/Target/" + target["name"] + "/" + target["short_name"] + ".h"], - copts = llvm_copts, - strip_include_prefix = "lib/Target/" + target["name"], - textual_hdrs = glob([ - "lib/Target/" + target["name"] + "/*.def", - "lib/Target/" + target["name"] + "/*.inc", - ]), - deps = [ - ":Analysis", - ":BinaryFormat", - ":CFGuard", - ":CodeGen", - ":Core", - ":IPO", - ":MC", - ":Passes", # TODO(chandlerc): Likely a layering violation. - ":ProfileData", - ":Scalar", - ":Support", - ":Target", - ":TransformUtils", - ":Vectorize", - ":config", - ":" + target["name"] + "CommonTableGen", - ":" + target["name"] + "Info", - ":" + target["name"] + "UtilsAndDesc", - ], - )], - [cc_library( - name = target["name"] + "AsmParser", - srcs = glob([ - "lib/Target/" + target["name"] + "/AsmParser/*.cpp", - "lib/Target/" + target["name"] + "/AsmParser/*.h", - ]), - copts = llvm_copts, - deps = [ - ":BinaryFormat", - ":MC", - ":MCParser", - ":Support", - ":Target", - ":" + target["name"] + "CodeGen", - ":" + target["name"] + "CommonTableGen", - ":" + target["name"] + "UtilsAndDesc", - ], - )], - # This target is a bit of a hack to allow us to expose internal - # disassembler header files via internal target-relative include paths. - # This usage of headers is inherently non-modular as there is a mixture of - # target-relative inclusion using this rule and same-directory inclusion - # using the repeated listing of these headers in the `srcs` below. - [cc_library( - name = target["name"] + "DisassemblerInternalHeaders", - # FIXME: This should be `textual_hdrs` instead of `hdrs`, but - # unfortunately that doesn't work with `strip_include_prefix`: - # https://github.com/bazelbuild/bazel/issues/12424 - # - # Once that issue is fixed and released, we can switch this to - # `textual_hdrs` and remove the feature disabling the various Bazel - # features (both current and under-development) that motivated the - # distinction between these two. - hdrs = glob([ - "lib/Target/" + target["name"] + "/Disassembler/*.h", - ]), - features = [ - "-parse_headers", - "-header_modules", - ], - strip_include_prefix = "lib/Target/" + target["name"], - )], - [cc_library( - name = target["name"] + "Disassembler", - srcs = glob([ - "lib/Target/" + target["name"] + "/Disassembler/*.cpp", - "lib/Target/" + target["name"] + "/Disassembler/*.c", - "lib/Target/" + target["name"] + "/Disassembler/*.h", - ]), - copts = llvm_copts, - deps = [ - ":CodeGen", - ":Core", - ":MC", - ":MCDisassembler", - ":Support", - ":Target", - ":" + target["name"] + "CodeGen", - ":" + target["name"] + "DisassemblerInternalHeaders", - ":" + target["name"] + "CommonTableGen", - ":" + target["name"] + "UtilsAndDesc", - ], - )], - [cc_library( - name = target["name"] + "TargetMCA", - srcs = glob([ - "lib/Target/" + target["name"] + "/MCA/*.cpp", - "lib/Target/" + target["name"] + "/MCA/*.c", - "lib/Target/" + target["name"] + "/MCA/*.h", - ]), - copts = llvm_copts, - deps = [ - ":MC", - ":MCA", - ":MCParser", - ":Support", - ":" + target["name"] + "DisassemblerInternalHeaders", - ":" + target["name"] + "Info", - ":" + target["name"] + "UtilsAndDesc", - ], - )], -] for target in llvm_target_lib_list] - -cc_library( - name = "AllTargetsCodeGens", - copts = llvm_copts, - deps = [ - target["name"] + "CodeGen" - for target in llvm_target_lib_list - ], -) - -cc_library( - name = "AllTargetsAsmParsers", - copts = llvm_copts, - deps = [ - target["name"] + "AsmParser" - for target in llvm_target_lib_list - ], -) - -cc_library( - name = "AllTargetsDisassemblers", - copts = llvm_copts, - deps = [ - target["name"] + "Disassembler" - for target in llvm_target_lib_list - ], -) - -cc_library( - name = "AllTargetsMCAs", - copts = llvm_copts, - deps = [ - target["name"] + "TargetMCA" - for target in llvm_target_lib_list - ], -) - -cc_library( - name = "pass_registry_def", - copts = llvm_copts, - textual_hdrs = ["lib/Passes/PassRegistry.def"], -) - -cc_library( - name = "MLPolicies", - srcs = glob([ - "lib/Analysis/ML/*.cpp", - "lib/Analysis/ML/*.h", - ]), - hdrs = glob([ - "include/llvm/Analysis/ML/*.h", - ]), - copts = llvm_copts, - deps = [ - ":Analysis", - ":Core", - ":Support", - ], -) - -cc_library( - name = "Passes", - srcs = glob([ - "lib/Passes/*.cpp", - "lib/Passes/*.h", - ]), - hdrs = glob(["include/llvm/Passes/*.h"]) + ["include/llvm-c/Transforms/PassBuilder.h"], - copts = llvm_copts, - deps = [ - ":Analysis", - ":CodeGen", - ":Core", - ":Coroutines", - ":MLPolicies", - ":Support", - ":Target", - ":TransformUtils", - ":common_transforms", - ":config", - ":pass_registry_def", - ], -) - -cc_library( - name = "LTO", - srcs = glob([ - "lib/LTO/*.cpp", - "lib/LTO/*.h", - ]), - hdrs = glob([ - "include/llvm/LTO/*.h", - "include/llvm/LTO/legacy/*.h", - ]) + [ - "include/llvm-c/lto.h", - ], - copts = llvm_copts, - deps = [ - ":Analysis", - ":BitReader", - ":BitWriter", - ":CodeGen", - ":Core", - ":IRReader", - ":Linker", - ":MC", - ":MCParser", - ":Object", - ":Passes", - ":Support", - ":Target", - ":TransformUtils", - ":common_transforms", - ":config", - ], -) - -cc_library( - name = "ExecutionEngine", - srcs = glob([ - "lib/ExecutionEngine/*.cpp", - "lib/ExecutionEngine/*.h", - "lib/ExecutionEngine/RuntimeDyld/*.cpp", - "lib/ExecutionEngine/RuntimeDyld/*.h", - "lib/ExecutionEngine/RuntimeDyld/Targets/*.cpp", - "lib/ExecutionEngine/RuntimeDyld/Targets/*.h", - ]), - hdrs = glob( - [ - "include/llvm/ExecutionEngine/*.h", - ], - exclude = [ - "include/llvm/ExecutionEngine/MCJIT*.h", - "include/llvm/ExecutionEngine/OProfileWrapper.h", - ], - ) + [ - "include/llvm-c/ExecutionEngine.h", - ], - copts = llvm_copts, - deps = [ - ":BinaryFormat", - ":CodeGen", - ":Core", - ":DebugInfo", - ":MC", - ":MCDisassembler", - ":Object", - ":OrcTargetProcess", - ":Passes", - ":Support", - ":Target", - ":config", - ], -) - -cc_library( - name = "Interpreter", - srcs = glob([ - "lib/ExecutionEngine/Interpreter/*.cpp", - "lib/ExecutionEngine/Interpreter/*.h", - ]), - hdrs = ["include/llvm/ExecutionEngine/Interpreter.h"], - copts = llvm_copts, - deps = [ - ":CodeGen", - ":Core", - ":ExecutionEngine", - ":Support", - ":Target", - ":config", - ], -) - -cc_library( - name = "JITLink", - srcs = glob([ - "lib/ExecutionEngine/JITLink/*.cpp", - "lib/ExecutionEngine/JITLink/*.h", - ]), - hdrs = glob([ - "include/llvm/ExecutionEngine/JITLink/*.h", - ]), - copts = llvm_copts, - deps = [ - ":ExecutionEngine", - ":Object", - ":OrcTargetProcess", - ":Support", - ":config", - ], -) - -cc_library( - name = "MCJIT", - srcs = glob([ - "lib/ExecutionEngine/MCJIT/*.cpp", - "lib/ExecutionEngine/MCJIT/*.h", - ]), - hdrs = glob(["include/llvm/ExecutionEngine/MCJIT*.h"]), - copts = llvm_copts, - deps = [ - ":CodeGen", - ":Core", - ":ExecutionEngine", - ":MC", - ":Object", - ":Support", - ":Target", - ":config", - ], -) - -cc_library( - name = "OrcJIT", - srcs = glob([ - "lib/ExecutionEngine/Orc/*.cpp", - "lib/ExecutionEngine/Orc/*.h", - ]), - hdrs = glob([ - "include/llvm/ExecutionEngine/Orc/*.h", - "include/llvm/ExecutionEngine/Orc/RPC/*.h", - ]) + [ - "include/llvm-c/LLJIT.h", - "include/llvm-c/Orc.h", - "include/llvm-c/OrcEE.h", - ], - copts = llvm_copts, - deps = [ - ":BitReader", - ":BitWriter", - ":Core", - ":ExecutionEngine", - ":JITLink", - ":MC", - ":Object", - ":OrcShared", - ":OrcTargetProcess", - ":Support", - ":Target", - ":TransformUtils", - ":config", - ], -) - -cc_library( - name = "OrcShared", - srcs = glob([ - "lib/ExecutionEngine/Orc/Shared/*.cpp", - ]), - hdrs = glob([ - "include/llvm/ExecutionEngine/Orc/Shared/*.h", - ]), - copts = llvm_copts, - deps = [ - ":BinaryFormat", - ":CodeGen", - ":Core", - ":DebugInfo", - ":MC", - ":MCDisassembler", - ":Object", - ":Passes", - ":Support", - ":Target", - ":config", - ], -) - -cc_library( - name = "OrcTargetProcess", - srcs = glob([ - "lib/ExecutionEngine/Orc/TargetProcess/*.cpp", - "lib/ExecutionEngine/Orc/TargetProcess/*.h", - ]), - hdrs = glob([ - "include/llvm/ExecutionEngine/Orc/TargetProcess/*.h", - ]), - copts = llvm_copts, - deps = [ - ":BinaryFormat", - ":CodeGen", - ":Core", - ":DebugInfo", - ":MC", - ":MCDisassembler", - ":Object", - ":OrcShared", - ":Passes", - ":Support", - ":Target", - ":config", - ], -) - -cc_library( - name = "DWARFLinker", - srcs = glob([ - "lib/DWARFLinker/*.cpp", - "lib/DWARFLinker/*.h", - ]), - hdrs = glob(["include/llvm/DWARFLinker/*.h"]), - copts = llvm_copts, - deps = [ - ":CodeGen", - ":DebugInfoDWARF", - ":Support", - ], -) - -gentbl( - name = "DllOptionsTableGen", - strip_include_prefix = "lib/ToolDrivers/llvm-dlltool", - tbl_outs = [( - "-gen-opt-parser-defs", - "lib/ToolDrivers/llvm-dlltool/Options.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "lib/ToolDrivers/llvm-dlltool/Options.td", - td_srcs = ["include/llvm/Option/OptParser.td"], -) - -cc_library( - name = "DlltoolDriver", - srcs = glob(["lib/ToolDrivers/llvm-dlltool/*.cpp"]), - hdrs = glob(["include/llvm/ToolDrivers/llvm-dlltool/*.h"]), - copts = llvm_copts, - deps = [ - ":DllOptionsTableGen", - ":Object", - ":Option", - ":Support", - ], -) - -gentbl( - name = "LibOptionsTableGen", - strip_include_prefix = "lib/ToolDrivers/llvm-lib", - tbl_outs = [( - "-gen-opt-parser-defs", - "lib/ToolDrivers/llvm-lib/Options.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "lib/ToolDrivers/llvm-lib/Options.td", - td_srcs = ["include/llvm/Option/OptParser.td"], -) - -cc_library( - name = "LibDriver", - srcs = glob(["lib/ToolDrivers/llvm-lib/*.cpp"]), - hdrs = glob(["include/llvm/ToolDrivers/llvm-lib/*.h"]), - copts = llvm_copts, - deps = [ - ":BinaryFormat", - ":LibOptionsTableGen", - ":Object", - ":Option", - ":Support", - ], -) - -cc_library( - name = "InterfaceStub", - srcs = glob([ - "lib/InterfaceStub/*.cpp", - "lib/InterfaceStub/*.h", - ]), - hdrs = glob([ - "include/llvm/InterfaceStub/*.h", - ]), - copts = llvm_copts, - deps = [ - ":Object", - ":Support", - ":config", - ], -) - -cc_library( - name = "WindowsManifest", - srcs = glob([ - "lib/WindowsManifest/*.cpp", - ]), - hdrs = glob([ - "include/llvm/WindowsManifest/*.h", - ]), - copts = llvm_copts, - linkopts = [ - # Libxml2 is required to process Windows manifests. Without this, - # lld uses Microsoft mt.exe instead, which is not cross-platform. - "-lxml2", - ], - tags = [ - "manual", # External dependency (libxml) - "nobuildkite", # TODO(gcmn): Fix remote execution and re-enable - ], - deps = [ - ":Support", - ":config", - ], -) - -# FIXME: This library should use `textual_hdrs` instead of `hdrs` as we don't -# want to parse or build modules for them (and haven't duplicated the necessary -# dependencies), but unfortunately that doesn't work with -# `strip_include_prefix`: https://github.com/bazelbuild/bazel/issues/12424 -# -# For now, we simply disable features that might rely on the headers parsing. -cc_library( - name = "llvm-objcopy-headers", - hdrs = glob(["tools/llvm-objcopy/**/*.h"]), - features = [ - "-parse_headers", - "-header_modules", - ], - strip_include_prefix = "tools/llvm-objcopy", -) - -cc_library( - name = "MCA", - srcs = glob([ - "lib/MCA/**/*.cpp", - "lib/MCA/**/*.h", - ]), - hdrs = glob([ - "include/llvm/MCA/**/*.h", - ]), - copts = llvm_copts, - deps = [ - ":MC", - ":MCDisassembler", - ":Object", - ":Support", - ], -) - -cc_library( - name = "llvm-mca-headers", - hdrs = glob([ - "tools/llvm-mca/*.h", - "tools/llvm-mca/Views/*.h", - ]), - strip_include_prefix = "tools/llvm-mca", -) - -cc_library( - name = "XRay", - srcs = glob([ - "lib/XRay/*.cpp", - "lib/XRay/*.h", - ]), - hdrs = glob(["include/llvm/XRay/*.h"]), - copts = llvm_copts, - deps = [ - ":Object", - ":Support", - ], -) - -cc_library( - name = "Exegesis", - srcs = glob([ - "tools/llvm-exegesis/lib/*.cpp", - "tools/llvm-exegesis/lib/X86/*.cpp", - "tools/llvm-exegesis/lib/X86/*.h", - # We have to include these headers here as well as in the `hdrs` below - # to allow the `.cpp` files to use file-relative-inclusion to find - # them, even though consumers of this library use inclusion relative to - # `tools/llvm-exegesis/lib` with the `strip_includes_prefix` of this - # library. This mixture appears to be incompatible with header modules. - "tools/llvm-exegesis/lib/*.h", - ]), - hdrs = glob(["tools/llvm-exegesis/lib/*.h"]), - copts = llvm_copts + ["-DHAVE_LIBPFM=1"], - defines = ["LLVM_EXEGESIS_INITIALIZE_NATIVE_TARGET=InitializeX86ExegesisTarget"], - features = ["-header_modules"], - strip_include_prefix = "tools/llvm-exegesis/lib", - tags = [ - "manual", # External dependency (libpfm4) - "nobuildkite", # TODO(chandlerc): Add support for fetching and building libpfm4 and enable this. - ], - deps = [ - ":AllTargetsAsmParsers", - ":AllTargetsCodeGens", - ":CodeGen", - ":Core", - ":ExecutionEngine", - ":MC", - ":MCDisassembler", - ":MCJIT", - ":Object", - ":ObjectYAML", - ":Support", - ":Target", - ":config", - ], -) - -################################################################################ -# LLVM toolchain and development binaries - -gentbl( - name = "DsymutilTableGen", - strip_include_prefix = "tools/dsymutil", - tbl_outs = [( - "-gen-opt-parser-defs", - "tools/dsymutil/Options.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "tools/dsymutil/Options.td", - td_srcs = ["include/llvm/Option/OptParser.td"], -) - -cc_binary( - name = "dsymutil", - srcs = glob([ - "tools/dsymutil/*.cpp", - "tools/dsymutil/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsCodeGens", - ":BinaryFormat", - ":CodeGen", - ":DWARFLinker", - ":DebugInfo", - ":DebugInfoDWARF", - ":DsymutilTableGen", - ":MC", - ":Object", - ":Option", - ":Support", - ":Target", - ":config", - ":remark_linker", - ], -) - -cc_binary( - name = "llc", - srcs = glob([ - "tools/llc/*.cpp", - "tools/llc/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsAsmParsers", - ":AllTargetsCodeGens", - ":Analysis", - ":AsmParser", - ":BitReader", - ":CodeGen", - ":Core", - ":IRReader", - ":MC", - ":Support", - ":Target", - ":TransformUtils", - ], -) - -cc_binary( - name = "lli", - srcs = glob([ - "tools/lli/*.cpp", - "tools/lli/*.h", - ]), - copts = llvm_copts, - # ll scripts rely on symbols from dependent - # libraries being resolvable. - linkopts = select({ - "@bazel_tools//src/conditions:windows": [], - "@bazel_tools//src/conditions:darwin": [], - "//conditions:default": [ - "-Wl,--undefined=_ZTIi", - "-Wl,--export-dynamic-symbol=_ZTIi", - "-Wl,--export-dynamic-symbol=__cxa_begin_catch", - "-Wl,--export-dynamic-symbol=__cxa_end_catch", - "-Wl,--export-dynamic-symbol=__gxx_personality_v0", - "-Wl,--export-dynamic-symbol=__cxa_allocate_exception", - "-Wl,--export-dynamic-symbol=__cxa_throw", - "-Wl,--export-dynamic-symbol=llvm_orc_registerJITLoaderGDBWrapper", - "-Wl,--export-dynamic-symbol=llvm_orc_registerEHFrameSectionWrapper", - "-Wl,--export-dynamic-symbol=llvm_orc_deregisterEHFrameSectionWrapper", - ], - }), - stamp = 0, - deps = [ - ":AllTargetsAsmParsers", - ":AllTargetsCodeGens", - ":AsmParser", - ":BitReader", - ":CodeGen", - ":Core", - ":ExecutionEngine", - ":IRReader", - ":Instrumentation", - ":Interpreter", - ":MCJIT", - ":Object", - ":OrcJIT", - ":Support", - ":config", - ], -) - -cc_binary( - name = "llvm-ar", - srcs = glob([ - "tools/llvm-ar/*.cpp", - "tools/llvm-ar/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsAsmParsers", - ":AllTargetsCodeGens", - ":Core", - ":DlltoolDriver", - ":LibDriver", - ":Object", - ":Support", - ], -) - -# We need to run llvm-ar with different basenames to make it run with -# different behavior. -binary_alias( - name = "llvm-dlltool", - binary = ":llvm-ar", -) - -binary_alias( - name = "llvm-lib", - binary = ":llvm-ar", -) - -binary_alias( - name = "llvm-ranlib", - binary = ":llvm-ar", -) - -cc_binary( - name = "llvm-as", - srcs = glob([ - "tools/llvm-as/*.cpp", - "tools/llvm-as/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":Analysis", - ":AsmParser", - ":BitWriter", - ":Core", - ":Support", - ], -) - -cc_binary( - name = "llvm-bcanalyzer", - srcs = glob([ - "tools/llvm-bcanalyzer/*.cpp", - "tools/llvm-bcanalyzer/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":BitReader", - ":Support", - ], -) - -cc_binary( - name = "llvm-cat", - srcs = glob([ - "tools/llvm-cat/*.cpp", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":BitReader", - ":BitWriter", - ":Core", - ":IRReader", - ":Support", - ], -) - -cc_binary( - name = "llvm-cfi-verify", - srcs = glob([ - "tools/llvm-cfi-verify/*.cpp", - "tools/llvm-cfi-verify/lib/*.cpp", - "tools/llvm-cfi-verify/lib/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsAsmParsers", - ":AllTargetsCodeGens", - ":AllTargetsDisassemblers", - ":BinaryFormat", - ":DebugInfoDWARF", - ":MC", - ":MCDisassembler", - ":MCParser", - ":Object", - ":Support", - ":Symbolize", - ], -) - -cc_binary( - name = "llvm-cov", - srcs = glob([ - "tools/llvm-cov/*.cpp", - "tools/llvm-cov/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":Coverage", - ":Instrumentation", - ":Object", - ":ProfileData", - ":Support", - ], -) - -gentbl( - name = "CvtResTableGen", - strip_include_prefix = "tools/llvm-cvtres", - tbl_outs = [( - "-gen-opt-parser-defs", - "tools/llvm-cvtres/Opts.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "tools/llvm-cvtres/Opts.td", - td_srcs = ["include/llvm/Option/OptParser.td"], -) - -cc_binary( - name = "llvm-cvtres", - srcs = glob([ - "tools/llvm-cvtres/*.cpp", - "tools/llvm-cvtres/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":CvtResTableGen", - ":Object", - ":Option", - ":Support", - ], -) - -cc_binary( - name = "llvm-cxxdump", - srcs = glob([ - "tools/llvm-cxxdump/*.cpp", - "tools/llvm-cxxdump/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsCodeGens", - ":BitReader", - ":Object", - ":Support", - ], -) - -cc_binary( - name = "llvm-cxxmap", - srcs = glob([ - "tools/llvm-cxxmap/*.cpp", - "tools/llvm-cxxmap/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":Support", - ], -) - -gentbl( - name = "CxxfiltOptsTableGen", - strip_include_prefix = "tools/llvm-cxxfilt", - tbl_outs = [( - "-gen-opt-parser-defs", - "tools/llvm-cxxfilt/Opts.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "tools/llvm-cxxfilt/Opts.td", - td_srcs = ["include/llvm/Option/OptParser.td"], -) - -cc_binary( - name = "llvm-cxxfilt", - srcs = glob([ - "tools/llvm-cxxfilt/*.cpp", - "tools/llvm-cxxfilt/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":CxxfiltOptsTableGen", - ":Demangle", - ":Option", - ":Support", - ], -) - -cc_binary( - name = "llvm-dis", - srcs = glob([ - "tools/llvm-dis/*.cpp", - "tools/llvm-dis/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":Analysis", - ":BitReader", - ":Core", - ":Support", - ], -) - -cc_binary( - name = "llvm-dwarfdump", - srcs = glob([ - "tools/llvm-dwarfdump/*.cpp", - "tools/llvm-dwarfdump/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsCodeGens", - ":BinaryFormat", - ":DebugInfo", - ":DebugInfoDWARF", - ":MC", - ":Object", - ":Support", - ], -) - -cc_binary( - name = "llvm-dwp", - srcs = glob([ - "tools/llvm-dwp/*.cpp", - "tools/llvm-dwp/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsCodeGens", - ":DWP", - ":MC", - ":Support", - ], -) - -cc_binary( - name = "llvm-exegesis", - srcs = [ - "tools/llvm-exegesis/llvm-exegesis.cpp", - ], - copts = llvm_copts + ["-DHAVE_LIBPFM=0"], - linkopts = ["-lpfm"], - stamp = 0, - tags = [ - "manual", # External dependency (libpfm4 through Exegesis) - "nobuildkite", # TODO(chandlerc): Enable when the library builds. - ], - deps = [ - ":AllTargetsAsmParsers", - ":AllTargetsCodeGens", - ":AllTargetsDisassemblers", - ":Exegesis", - ":MC", - ":MCParser", - ":Object", - ":Support", - ":config", - ], -) - -cc_binary( - name = "llvm-extract", - srcs = glob([ - "tools/llvm-extract/*.cpp", - "tools/llvm-extract/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AsmParser", - ":BitReader", - ":BitWriter", - ":Core", - ":IPO", - ":IRReader", - ":Support", - ], -) - -cc_binary( - name = "llvm-ifs", - srcs = glob([ - "tools/llvm-ifs/*.cpp", - "tools/llvm-ifs/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":InterfaceStub", - ":ObjectYAML", - ":Support", - ":TextAPI", - ], -) - -cc_binary( - name = "llvm-jitlink", - srcs = glob([ - "tools/llvm-jitlink/*.cpp", - "tools/llvm-jitlink/*.h", - ]), - copts = llvm_copts, - # Make symbols from the standard library dynamically resolvable. - linkopts = select({ - "@bazel_tools//src/conditions:windows": [], - "@bazel_tools//src/conditions:darwin": [], - "//conditions:default": [ - "-Wl,--undefined=_ZTIi", - "-Wl,--export-dynamic-symbol=_ZTIi", - "-Wl,--export-dynamic-symbol=__cxa_begin_catch", - "-Wl,--export-dynamic-symbol=__cxa_end_catch", - "-Wl,--export-dynamic-symbol=__gxx_personality_v0", - "-Wl,--export-dynamic-symbol=__cxa_allocate_exception", - "-Wl,--export-dynamic-symbol=__cxa_throw", - "-Wl,--export-dynamic-symbol=llvm_orc_registerJITLoaderGDBWrapper", - ], - }), - stamp = 0, - deps = [ - ":AllTargetsAsmParsers", - ":AllTargetsCodeGens", - ":AllTargetsDisassemblers", - ":AsmParser", - ":BitReader", - ":CodeGen", - ":ExecutionEngine", - ":MCJIT", - ":Object", - ":OrcJIT", - ":Support", - ":config", - ], -) - -cc_binary( - name = "llvm-libtool-darwin", - srcs = glob([ - "tools/llvm-libtool-darwin/*.cpp", - "tools/llvm-libtool-darwin/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":BinaryFormat", - ":Object", - ":Support", - ], -) - -cc_binary( - name = "llvm-link", - srcs = glob([ - "tools/llvm-link/*.cpp", - "tools/llvm-link/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AsmParser", - ":BitReader", - ":BitWriter", - ":Core", - ":IPO", - ":IRReader", - ":Linker", - ":Object", - ":Support", - ":TransformUtils", - ], -) - -gentbl( - name = "LipoOptsTableGen", - strip_include_prefix = "tools/llvm-lipo", - tbl_outs = [( - "-gen-opt-parser-defs", - "tools/llvm-lipo/LipoOpts.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "tools/llvm-lipo/LipoOpts.td", - td_srcs = ["include/llvm/Option/OptParser.td"], -) - -cc_binary( - name = "llvm-lipo", - srcs = [ - "tools/llvm-lipo/llvm-lipo.cpp", - ], - copts = llvm_copts, - stamp = 0, - deps = [ - ":LipoOptsTableGen", - ":Object", - ":Option", - ":Support", - ], -) - -cc_binary( - name = "llvm-lto", - srcs = glob([ - "tools/llvm-lto/*.cpp", - "tools/llvm-lto/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsAsmParsers", - ":AllTargetsCodeGens", - ":BitReader", - ":BitWriter", - ":CodeGen", - ":Core", - ":IRReader", - ":LTO", - ":Support", - ":Target", - ], -) - -cc_binary( - name = "llvm-lto2", - srcs = glob([ - "tools/llvm-lto2/*.cpp", - "tools/llvm-lto2/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsAsmParsers", - ":AllTargetsCodeGens", - ":BitReader", - ":CodeGen", - ":Core", - ":LTO", - ":Support", - ], -) - -cc_binary( - name = "llvm-mc", - srcs = glob([ - "tools/llvm-mc/*.cpp", - "tools/llvm-mc/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsAsmParsers", - ":AllTargetsCodeGens", - ":AllTargetsDisassemblers", - ":MC", - ":MCDisassembler", - ":MCParser", - ":Object", - ":Support", - ], -) - -cc_binary( - name = "llvm-mca", - srcs = glob([ - "tools/llvm-mca/*.cpp", - "tools/llvm-mca/*.h", - "tools/llvm-mca/Views/*.cpp", - "tools/llvm-mca/Views/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsAsmParsers", - ":AllTargetsCodeGens", - ":AllTargetsDisassemblers", - ":AllTargetsMCAs", - ":MC", - ":MCA", - ":MCParser", - ":Support", - ":llvm-mca-headers", - ], -) - -gentbl( - name = "MlTableGen", - strip_include_prefix = "tools/llvm-ml", - tbl_outs = [( - "-gen-opt-parser-defs", - "tools/llvm-ml/Opts.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "tools/llvm-ml/Opts.td", - td_srcs = ["include/llvm/Option/OptParser.td"], -) - -cc_binary( - name = "llvm-ml", - srcs = glob([ - "tools/llvm-ml/*.cpp", - "tools/llvm-ml/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsAsmParsers", - ":AllTargetsCodeGens", - ":AllTargetsDisassemblers", - ":MC", - ":MCParser", - ":MlTableGen", - ":Option", - ":Support", - ], -) - -cc_binary( - name = "llvm-modextract", - srcs = glob([ - "tools/llvm-modextract/*.cpp", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":BitReader", - ":BitWriter", - ":IRReader", - ":Support", - ], -) - -gentbl( - name = "MtTableGen", - strip_include_prefix = "tools/llvm-mt", - tbl_outs = [( - "-gen-opt-parser-defs", - "tools/llvm-mt/Opts.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "tools/llvm-mt/Opts.td", - td_srcs = ["include/llvm/Option/OptParser.td"], -) - -cc_binary( - name = "llvm-mt", - srcs = glob([ - "tools/llvm-mt/*.cpp", - "tools/llvm-mt/*.h", - ]), - copts = llvm_copts, - stamp = 0, - tags = [ - "manual", # TODO(gcmn): External dependency (through WindowsManifest) - "nobuildkite", # TODO(gcmn): Re-enable when WindowsManifest builds - ], - deps = [ - ":MtTableGen", - ":Option", - ":Support", - ":WindowsManifest", - ], -) - -gentbl( - name = "NmOptsTableGen", - strip_include_prefix = "tools/llvm-nm", - tbl_outs = [( - "-gen-opt-parser-defs", - "tools/llvm-nm/Opts.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "tools/llvm-nm/Opts.td", - td_srcs = ["include/llvm/Option/OptParser.td"], -) - -cc_binary( - name = "llvm-nm", - srcs = glob([ - "tools/llvm-nm/*.cpp", - "tools/llvm-nm/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsAsmParsers", - ":AllTargetsCodeGens", - ":BinaryFormat", - ":BitReader", - ":Core", - ":Demangle", - ":NmOptsTableGen", - ":Object", - ":Option", - ":Support", - ], -) - -gentbl( - name = "llvm-objcopy-opts", - strip_include_prefix = "tools/llvm-objcopy", - tbl_outs = [( - "-gen-opt-parser-defs", - "tools/llvm-objcopy/ObjcopyOpts.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "tools/llvm-objcopy/ObjcopyOpts.td", - td_srcs = [ - "include/llvm/Option/OptParser.td", - "tools/llvm-objcopy/CommonOpts.td", - ], -) - -gentbl( - name = "llvm-installnametool-opts", - strip_include_prefix = "tools/llvm-objcopy", - tbl_outs = [( - "-gen-opt-parser-defs", - "tools/llvm-objcopy/InstallNameToolOpts.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "tools/llvm-objcopy/InstallNameToolOpts.td", - td_srcs = [ - "include/llvm/Option/OptParser.td", - "tools/llvm-objcopy/CommonOpts.td", - ], -) - -gentbl( - name = "llvm-strip-opts", - strip_include_prefix = "tools/llvm-objcopy", - tbl_outs = [( - "-gen-opt-parser-defs", - "tools/llvm-objcopy/StripOpts.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "tools/llvm-objcopy/StripOpts.td", - td_srcs = [ - "include/llvm/Option/OptParser.td", - "tools/llvm-objcopy/CommonOpts.td", - ], -) - -gentbl( - name = "llvm-bitcode-strip-opts", - strip_include_prefix = "tools/llvm-objcopy", - tbl_outs = [( - "-gen-opt-parser-defs", - "tools/llvm-objcopy/BitcodeStripOpts.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "tools/llvm-objcopy/BitcodeStripOpts.td", - td_srcs = [ - "include/llvm/Option/OptParser.td", - "tools/llvm-objcopy/CommonOpts.td", - ], -) - -cc_binary( - name = "llvm-stress", - srcs = glob([ - "tools/llvm-stress/*.cpp", - "tools/llvm-stress/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":Core", - ":Support", - ], -) - -cc_binary( - name = "llvm-objcopy", - srcs = glob([ - "tools/llvm-objcopy/**/*.cpp", - # Note that we redundantly include the headers here to allow files to - # include same-directory headers in addition to including headers via - # the `llvm-objcopy-headers` rule's stripped include prefix. - "tools/llvm-objcopy/**/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":BinaryFormat", - ":MC", - ":Object", - ":ObjectYAML", - ":Option", - ":Support", - ":Target", - ":llvm-bitcode-strip-opts", - ":llvm-installnametool-opts", - ":llvm-objcopy-headers", - ":llvm-objcopy-opts", - ":llvm-strip-opts", - ], -) - -binary_alias( - name = "llvm-strip", - binary = ":llvm-objcopy", -) - -binary_alias( - name = "llvm-bitcode-strip", - binary = ":llvm-objcopy", -) - -binary_alias( - name = "llvm-install-name-tool", - binary = ":llvm-objcopy", -) - -cc_binary( - name = "llvm-objdump", - srcs = glob([ - "tools/llvm-objdump/*.cpp", - "tools/llvm-objdump/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsAsmParsers", - ":AllTargetsCodeGens", - ":AllTargetsDisassemblers", - ":BinaryFormat", - ":CodeGen", - ":DebugInfo", - ":DebugInfoDWARF", - ":Demangle", - ":MC", - ":MCDisassembler", - ":ObjdumpOptsTableGen", - ":Object", - ":Option", - ":OtoolOptsTableGen", - ":Support", - ":Symbolize", - ":config", - ], -) - -gentbl( - name = "ObjdumpOptsTableGen", - strip_include_prefix = "tools/llvm-objdump", - tbl_outs = [( - "-gen-opt-parser-defs", - "tools/llvm-objdump/ObjdumpOpts.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "tools/llvm-objdump/ObjdumpOpts.td", - td_srcs = ["include/llvm/Option/OptParser.td"], -) - -binary_alias( - name = "llvm-otool", - binary = ":llvm-objdump", -) - -gentbl( - name = "OtoolOptsTableGen", - strip_include_prefix = "tools/llvm-objdump", - tbl_outs = [( - "-gen-opt-parser-defs", - "tools/llvm-objdump/OtoolOpts.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "tools/llvm-objdump/OtoolOpts.td", - td_srcs = ["include/llvm/Option/OptParser.td"], -) - -cc_binary( - name = "llvm-opt-report", - srcs = glob([ - "tools/llvm-opt-report/*.cpp", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsCodeGens", - ":Demangle", - ":Remarks", - ":Support", - ], -) - -cc_binary( - name = "llvm-pdbutil", - srcs = glob([ - "tools/llvm-pdbutil/*.cpp", - "tools/llvm-pdbutil/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":BinaryFormat", - ":DebugInfoCodeView", - ":DebugInfoMSF", - ":DebugInfoPDB", - ":Object", - ":ObjectYAML", - ":Support", - ":config", - ], -) - -cc_binary( - name = "llvm-profdata", - srcs = glob([ - "tools/llvm-profdata/*.cpp", - "tools/llvm-profdata/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":Core", - ":ProfileData", - ":Support", - ], -) - -cc_binary( - name = "llvm-profgen", - srcs = glob([ - "tools/llvm-profgen/*.cpp", - "tools/llvm-profgen/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsCodeGens", - ":AllTargetsDisassemblers", - ":Symbolize", - ], -) - -gentbl( - name = "RcTableGen", - strip_include_prefix = "tools/llvm-rc", - tbl_outs = [( - "-gen-opt-parser-defs", - "tools/llvm-rc/Opts.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "tools/llvm-rc/Opts.td", - td_srcs = ["include/llvm/Option/OptParser.td"], -) - -gentbl( - name = "WindresTableGen", - strip_include_prefix = "tools/llvm-rc", - tbl_outs = [( - "-gen-opt-parser-defs", - "tools/llvm-rc/WindresOpts.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "tools/llvm-rc/WindresOpts.td", - td_srcs = ["include/llvm/Option/OptParser.td"], -) - -# Workaround inability to put `.def` files into `srcs` with a library. -cc_library( - name = "llvm-rc-defs-lib", - textual_hdrs = glob(["tools/llvm-rc/*.def"]), -) - -cc_binary( - name = "llvm-rc", - srcs = glob([ - "tools/llvm-rc/*.cpp", - "tools/llvm-rc/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":Object", - ":Option", - ":RcTableGen", - ":Support", - ":WindresTableGen", - ":llvm-rc-defs-lib", - ], -) - -binary_alias( - name = "llvm-windres", - binary = ":llvm-rc", -) - -gentbl( - name = "ReadobjOptsTableGen", - strip_include_prefix = "tools/llvm-readobj", - tbl_outs = [( - "-gen-opt-parser-defs", - "tools/llvm-readobj/Opts.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "tools/llvm-readobj/Opts.td", - td_srcs = ["include/llvm/Option/OptParser.td"], -) - -cc_binary( - name = "llvm-readobj", - srcs = glob([ - "tools/llvm-readobj/*.cpp", - "tools/llvm-readobj/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsCodeGens", - ":BinaryFormat", - ":BitReader", - ":DebugInfoCodeView", - ":DebugInfoDWARF", - ":Demangle", - ":Object", - ":Option", - ":ReadobjOptsTableGen", - ":Support", - ], -) - -# Create an 'llvm-readelf' named binary from the 'llvm-readobj' tool. -binary_alias( - name = "llvm-readelf", - binary = ":llvm-readobj", -) - -cc_binary( - name = "llvm-reduce", - srcs = glob([ - "tools/llvm-reduce/**/*.cpp", - "tools/llvm-reduce/**/*.h", - ]), - copts = llvm_copts, - includes = ["tools/llvm-reduce"], - stamp = 0, - deps = [ - ":AllTargetsAsmParsers", - ":AllTargetsCodeGens", - ":BitReader", - ":Core", - ], -) - -cc_binary( - name = "llvm-rtdyld", - srcs = glob([ - "tools/llvm-rtdyld/*.cpp", - "tools/llvm-rtdyld/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsCodeGens", - ":AllTargetsDisassemblers", - ":DebugInfo", - ":DebugInfoDWARF", - ":ExecutionEngine", - ":MC", - ":MCDisassembler", - ":Object", - ":Support", - ], -) - -gentbl( - name = "SizeOptsTableGen", - strip_include_prefix = "tools/llvm-size", - tbl_outs = [( - "-gen-opt-parser-defs", - "tools/llvm-size/Opts.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "tools/llvm-size/Opts.td", - td_srcs = ["include/llvm/Option/OptParser.td"], -) - -cc_binary( - name = "llvm-size", - srcs = glob([ - "tools/llvm-size/*.cpp", - "tools/llvm-size/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":Object", - ":Option", - ":SizeOptsTableGen", - ":Support", - ], -) - -cc_binary( - name = "llvm-split", - srcs = glob([ - "tools/llvm-split/*.cpp", - "tools/llvm-split/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":BitWriter", - ":Core", - ":IRReader", - ":Support", - ":TransformUtils", - ], -) - -gentbl( - name = "StringsOptsTableGen", - strip_include_prefix = "tools/llvm-strings", - tbl_outs = [( - "-gen-opt-parser-defs", - "tools/llvm-strings/Opts.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "tools/llvm-strings/Opts.td", - td_srcs = ["include/llvm/Option/OptParser.td"], -) - -cc_binary( - name = "llvm-strings", - srcs = glob([ - "tools/llvm-strings/*.cpp", - "tools/llvm-strings/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":Object", - ":Option", - ":StringsOptsTableGen", - ":Support", - ], -) - -gentbl( - name = "SymbolizerOptsTableGen", - strip_include_prefix = "tools/llvm-symbolizer", - tbl_outs = [( - "-gen-opt-parser-defs", - "tools/llvm-symbolizer/Opts.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "tools/llvm-symbolizer/Opts.td", - td_srcs = ["include/llvm/Option/OptParser.td"], -) - -cc_binary( - name = "llvm-symbolizer", - srcs = glob([ - "tools/llvm-symbolizer/*.cpp", - "tools/llvm-symbolizer/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":DebugInfoDWARF", - ":DebugInfoPDB", - ":Debuginfod", - ":Object", - ":Option", - ":Support", - ":Symbolize", - ":SymbolizerOptsTableGen", - ], -) - -binary_alias( - name = "llvm-addr2line", - binary = ":llvm-symbolizer", -) - -cc_binary( - name = "llvm-undname", - srcs = glob([ - "tools/llvm-undname/*.cpp", - "tools/llvm-undname/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":Demangle", - ":Support", - ], -) - -cc_binary( - name = "llvm-xray", - srcs = glob([ - "tools/llvm-xray/*.cpp", - "tools/llvm-xray/*.cc", - "tools/llvm-xray/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":DebugInfoDWARF", - ":Object", - ":Support", - ":Symbolize", - ":XRay", - ], -) - -cc_binary( - name = "opt", - srcs = glob([ - "tools/opt/*.cpp", - "tools/opt/*.h", - ]), - copts = llvm_copts, - linkopts = select({ - "@bazel_tools//src/conditions:windows": [], - "@bazel_tools//src/conditions:darwin": [], - "//conditions:default": ["-Wl,--export-dynamic"], - }), - stamp = 0, - deps = [ - ":AllTargetsAsmParsers", - ":AllTargetsCodeGens", - ":Analysis", - ":AsmParser", - ":BitReader", - ":BitWriter", - ":CodeGen", - ":Core", - ":IRReader", - ":MC", - ":Passes", - ":Support", - ":Target", - ":TransformUtils", - ":common_transforms", - ":config", - ], -) - -cc_binary( - name = "sancov", - srcs = glob([ - "tools/sancov/*.cpp", - "tools/sancov/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsCodeGens", - ":AllTargetsDisassemblers", - ":DebugInfoDWARF", - ":DebugInfoPDB", - ":MC", - ":MCDisassembler", - ":Object", - ":Support", - ":Symbolize", - ], -) - -cc_binary( - name = "sanstats", - srcs = glob([ - "tools/sanstats/*.cpp", - "tools/sanstats/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":Support", - ":Symbolize", - ":TransformUtils", - ], -) - -cc_binary( - name = "split-file", - srcs = glob([ - "tools/split-file/*.cpp", - "tools/split-file/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":Support", - ], -) - -################################################################################ -# Begin testonly libraries - -cc_library( - name = "FuzzMutate", - testonly = True, - srcs = glob(["lib/FuzzMutate/*.cpp"]), - hdrs = glob(["include/llvm/FuzzMutate/*.h"]), - copts = llvm_copts, - includes = ["include"], - deps = [ - ":Analysis", - ":BitReader", - ":BitWriter", - ":Core", - ":Scalar", - ":Support", - ], -) - -cc_library( - name = "Diff", - testonly = True, - srcs = glob(["tools/llvm-diff/lib/*.cpp"]), - hdrs = glob(["tools/llvm-diff/lib/*.h"]), - deps = [ - ":Core", - ":Support", - ], -) - -# A hacky library to expose some internal headers of gtest to its own -# implementation source files using a stripped include prefix rather than -# file-relative-inclusion. -# -# FIXME: This file should be in `textual_hdrs` instead of `hdrs`, but -# unfortunately that doesn't work with `strip_include_prefix`: -# https://github.com/bazelbuild/bazel/issues/12424 -# -# For now, simply disable parsing and header modules. -cc_library( - name = "gtest_internal_headers", - testonly = True, - hdrs = ["utils/unittest/googletest/src/gtest-internal-inl.h"], - features = [ - "-parse_headers", - "-header_modules", - ], - strip_include_prefix = "utils/unittest/googletest", -) - -cc_library( - name = "gtest", - testonly = True, - srcs = glob( - [ - "utils/unittest/googletest/include/**/*.h", - "utils/unittest/googletest/src/*.cc", - ], - exclude = [ - "utils/unittest/googletest/src/gtest-all.cc", - "utils/unittest/googletest/include/gtest/gtest_pred_impl.h", - ], - ) + [ - ], - hdrs = ["utils/unittest/googletest/include/gtest/gtest.h"], - copts = llvm_copts, - defines = [ - "GTEST_HAS_RTTI=0", - "__STDC_LIMIT_MACROS", - "__STDC_CONSTANT_MACROS", - ] + select({ - "@bazel_tools//src/conditions:windows": ["GTEST_USE_OWN_TR1_TUPLE=0"], - "//conditions:default": ["GTEST_USE_OWN_TR1_TUPLE=1"], - }), - includes = [ - "include", - "utils/unittest/googletest/include", - ], - textual_hdrs = [ - "utils/unittest/googletest/include/gtest/gtest_pred_impl.h", - ], - deps = [ - ":Support", - ":gtest_internal_headers", - ], -) - -cc_library( - name = "gtest_main", - testonly = True, - srcs = ["utils/unittest/UnitTestMain/TestMain.cpp"], - copts = llvm_copts, - deps = [ - ":Support", - ":gmock", - ":gtest", - ], -) - -cc_library( - name = "gmock", - testonly = True, - srcs = glob( - [ - "utils/unittest/googlemock/include/**/*.h", - "utils/unittest/googlemock/src/*.cc", - ], - exclude = ["utils/unittest/googlemock/src/gmock-all.cc"], - ), - hdrs = [ - "utils/unittest/googlemock/include/gmock/gmock.h", - "utils/unittest/googlemock/include/gmock/gmock-matchers.h", - ], - copts = llvm_copts, - includes = [ - "include", - "utils/unittest/googlemock/include", - ], - deps = [":gtest"], -) - -py_binary( - name = "lit", - testonly = True, - srcs = ["utils/lit/lit.py"] + glob(["utils/lit/lit/**/*.py"]), -) - -cc_library( - name = "TestingSupport", - testonly = True, - srcs = glob([ - "lib/Testing/Support/*.cpp", - "lib/Testing/Support/*.h", - ]), - hdrs = glob([ - "include/llvm/Testing/Support/*.h", - ]), - copts = llvm_copts, - deps = [ - ":Support", - ":config", - ":gmock", - ":gtest", - ], -) - -################################################################################ -# Begin testonly binary utilities - -cc_binary( - name = "FileCheck", - testonly = True, - srcs = glob([ - "utils/FileCheck/*.cpp", - "utils/FileCheck/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [":FileCheckLib"], -) - -cc_binary( - name = "bugpoint", - srcs = glob([ - "tools/bugpoint/*.cpp", - "tools/bugpoint/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsAsmParsers", - ":AllTargetsCodeGens", - ":Analysis", - ":AsmParser", - ":BitReader", - ":BitWriter", - ":CodeGen", - ":Core", - ":IRReader", - ":Linker", - ":Passes", - ":Support", - ":TransformUtils", - ":common_transforms", - ":config", - ], -) - -cc_binary( - name = "count", - testonly = True, - srcs = glob([ - "utils/count/*.c", - "utils/count/*.h", - ]), - stamp = 0, -) - -cc_binary( - name = "lli-child-target", - testonly = True, - srcs = glob([ - "tools/lli/ChildTarget/*.cpp", - "tools/lli/ChildTarget/*.h", - ]), - copts = llvm_copts, - # The tests load code into this binary that expect to see symbols - # from libstdc++ such as __cxa_begin_catch and _ZTIi. The latter - # isn't even used in the main binary, so we also need to force it - # to be included. - linkopts = select({ - "@bazel_tools//src/conditions:windows": [], - "@bazel_tools//src/conditions:darwin": [], - "//conditions:default": [ - "-rdynamic", - "-u_ZTIi", - ], - }), - stamp = 0, - deps = [ - ":OrcJIT", - ":Support", - ":attributes_gen", - ":config", - ":intrinsic_enums_gen", - ], -) - -cc_binary( - name = "llvm-c-test", - testonly = True, - srcs = glob([ - "tools/llvm-c-test/*.c", - "tools/llvm-c-test/*.cpp", - "tools/llvm-c-test/*.h", - ]), - stamp = 0, - deps = [ - ":AllTargetsAsmParsers", - ":AllTargetsCodeGens", - ":AllTargetsDisassemblers", - ":Analysis", - ":BitReader", - ":BitWriter", - ":Core", - ":ExecutionEngine", - ":IPO", - ":LTO", - ":Linker", - ":MCDisassembler", - ":Object", - ":OrcJIT", - ":Scalar", - ":Support", - ":Target", - ":Vectorize", - ], -) - -cc_binary( - name = "llvm-diff", - testonly = True, - srcs = glob([ - "tools/llvm-diff/*.cpp", - "tools/llvm-diff/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":Core", - ":Diff", - ":IRReader", - ":Support", - ], -) - -cc_binary( - name = "llvm-isel-fuzzer", - testonly = True, - srcs = glob([ - "tools/llvm-isel-fuzzer/*.cpp", - "tools/llvm-isel-fuzzer/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsAsmParsers", - ":AllTargetsCodeGens", - ":Analysis", - ":BitReader", - ":BitWriter", - ":CodeGen", - ":Core", - ":FuzzMutate", - ":IRReader", - ":Support", - ":Target", - ], -) - -# This is really a Python script, but call it sh_binary to ignore the hyphen in -# the path, which py_binary does not allow. -# Also, note: llvm-locstats expects llvm-dwarfdump to be in the same directory -# when executed. -sh_binary( - name = "llvm-locstats", - testonly = True, - srcs = glob([ - "utils/llvm-locstats/*.py", - ]), - # llvm-locstats is a thin wrapper around llvm-dwarfdump. - data = [":llvm-dwarfdump"], -) - -sh_binary( - name = "llvm-original-di-preservation", - testonly = True, - srcs = ["utils/llvm-original-di-preservation.py"], -) - -cc_binary( - name = "not", - testonly = True, - srcs = glob([ - "utils/not/*.cpp", - "utils/not/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [":Support"], -) - -cc_binary( - name = "llvm-opt-fuzzer", - testonly = True, - srcs = glob([ - "tools/llvm-opt-fuzzer/*.cpp", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AllTargetsCodeGens", - ":Analysis", - ":BitReader", - ":BitWriter", - ":CodeGen", - ":Core", - ":Coroutines", - ":FuzzMutate", - ":Passes", - ":Support", - ], -) - -cc_binary( - name = "llvm-tapi-diff", - testonly = True, - srcs = glob([ - "tools/llvm-tapi-diff/*.cpp", - "tools/llvm-tapi-diff/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":Object", - ":Support", - ":TextAPI", - ], -) - -gentbl( - name = "TLICheckerOptsTableGen", - strip_include_prefix = "tools/llvm-tli-checker", - tbl_outs = [( - "-gen-opt-parser-defs", - "tools/llvm-tli-checker/Opts.inc", - )], - tblgen = ":llvm-tblgen", - td_file = "tools/llvm-tli-checker/Opts.td", - td_srcs = ["include/llvm/Option/OptParser.td"], -) - -cc_binary( - name = "llvm-tli-checker", - testonly = True, - srcs = glob([ - "tools/llvm-tli-checker/*.cpp", - "tools/llvm-tli-checker/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":Analysis", - ":BinaryFormat", - ":BitReader", - ":BitstreamReader", - ":Core", - ":Demangle", - ":MC", - ":MCParser", - ":Object", - ":Option", - ":Remarks", - ":Support", - ":TextAPI", - ":TLICheckerOptsTableGen", - ], -) - -cc_binary( - name = "obj2yaml", - testonly = True, - srcs = glob([ - "tools/obj2yaml/*.cpp", - "tools/obj2yaml/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":BinaryFormat", - ":DebugInfoCodeView", - ":DebugInfoDWARF", - ":Object", - ":ObjectYAML", - ":Support", - ], -) - -cc_binary( - name = "verify-uselistorder", - srcs = glob([ - "tools/verify-uselistorder/*.cpp", - "tools/verify-uselistorder/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":AsmParser", - ":BitReader", - ":BitWriter", - ":Core", - ":IRReader", - ":Support", - ], -) - -cc_binary( - name = "yaml2obj", - testonly = True, - srcs = glob([ - "tools/yaml2obj/*.cpp", - "tools/yaml2obj/*.h", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":BinaryFormat", - ":DebugInfoCodeView", - ":MC", - ":Object", - ":ObjectYAML", - ":Support", - ], -) - -cc_binary( - name = "yaml-bench", - testonly = True, - srcs = glob([ - "utils/yaml-bench/*.cpp", - ]), - copts = llvm_copts, - stamp = 0, - deps = [ - ":Support", - ], -) diff --git a/utils/bazel/llvm-project-overlay/llvm/binary_alias.bzl b/utils/bazel/llvm-project-overlay/llvm/binary_alias.bzl deleted file mode 100644 index 0108742f345ed..0000000000000 --- a/utils/bazel/llvm-project-overlay/llvm/binary_alias.bzl +++ /dev/null @@ -1,35 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -"""Creates a copy of a binary, giving it a different basename. - -binary_alias( - name = "my_binary_other_name", - binary = ":some_cc_binary", -) -""" - -def _binary_alias_impl(ctx): - ctx.actions.symlink( - target_file = ctx.executable.binary, - output = ctx.outputs.executable, - is_executable = True, - ) - - return [DefaultInfo( - executable = ctx.outputs.executable, - runfiles = ctx.attr.binary[DefaultInfo].default_runfiles, - )] - -binary_alias = rule( - _binary_alias_impl, - attrs = { - "binary": attr.label( - mandatory = True, - executable = True, - cfg = "target", - ), - }, - executable = True, -) diff --git a/utils/bazel/llvm-project-overlay/llvm/cc_plugin_library.bzl b/utils/bazel/llvm-project-overlay/llvm/cc_plugin_library.bzl deleted file mode 100644 index 2ebd39c630dcb..0000000000000 --- a/utils/bazel/llvm-project-overlay/llvm/cc_plugin_library.bzl +++ /dev/null @@ -1,75 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -"""A macro to produce a loadable plugin library for the target OS. - -This macro produces a set of platform-specific `cc_binary` rules, by appending -the platform suffix (`.dll`, `.dylib`, or `.so`) to the provided `name`. It then -connects these to a `cc_import` rule with `name` exactly and `hdrs` that can be -used by other Bazel rules to depend on the plugin library. - -The `srcs` attribute for the `cc_binary` rules is `srcs + hdrs`. Other explicit -arguments are passed to all of the rules where they apply, and can be used to -configure generic aspects of all generated rules such as `testonly`. Lastly, -`kwargs` is expanded into all the `cc_binary` rules. -""" - -load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_import", "cc_library") - -def cc_plugin_library(name, srcs, hdrs, include_prefix = None, strip_include_prefix = None, alwayslink = False, features = [], tags = [], testonly = False, **kwargs): - # Neither the name of the plugin binary nor tags on whether it is built are - # configurable. Instead, we build a `cc_binary` with each name and - # selectively depend on them based on platform. - # - # All-in-all, this is a pretty poor workaround. I think this is part of the - # Bazel issue: https://github.com/bazelbuild/bazel/issues/7538 - so_name = name + ".so" - dll_name = name + ".dll" - dylib_name = name + ".dylib" - interface_output_name = name + "_interface_output" - import_name = name + "_import" - for impl_name in [dll_name, dylib_name, so_name]: - cc_binary( - name = impl_name, - srcs = srcs + hdrs, - linkshared = True, - linkstatic = True, - features = features, - tags = ["manual"] + tags, - testonly = testonly, - **kwargs - ) - native.filegroup( - name = interface_output_name, - srcs = select({ - "@bazel_tools//src/conditions:windows": [":" + dll_name], - "@bazel_tools//src/conditions:darwin": [":" + dylib_name], - "//conditions:default": [":" + so_name], - }), - output_group = "interface_library", - ) - cc_import( - name = import_name, - interface_library = ":" + interface_output_name, - shared_library = select({ - "@bazel_tools//src/conditions:windows": ":" + dll_name, - "@bazel_tools//src/conditions:darwin": ":" + dylib_name, - "//conditions:default": ":" + so_name, - }), - alwayslink = alwayslink, - features = features, - tags = tags, - testonly = testonly, - ) - cc_library( - name = name, - hdrs = hdrs, - include_prefix = include_prefix, - strip_include_prefix = strip_include_prefix, - deps = [":" + import_name], - alwayslink = alwayslink, - features = features, - tags = tags, - testonly = testonly, - ) diff --git a/utils/bazel/llvm-project-overlay/llvm/config.bzl b/utils/bazel/llvm-project-overlay/llvm/config.bzl deleted file mode 100644 index 2046b2645362f..0000000000000 --- a/utils/bazel/llvm-project-overlay/llvm/config.bzl +++ /dev/null @@ -1,99 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -"""Defines variables that use selects to configure LLVM based on platform.""" - -def native_arch_defines(arch, triple): - return [ - r'LLVM_NATIVE_ARCH=\"{}\"'.format(arch), - "LLVM_NATIVE_ASMPARSER=LLVMInitialize{}AsmParser".format(arch), - "LLVM_NATIVE_ASMPRINTER=LLVMInitialize{}AsmPrinter".format(arch), - "LLVM_NATIVE_DISASSEMBLER=LLVMInitialize{}Disassembler".format(arch), - "LLVM_NATIVE_TARGET=LLVMInitialize{}Target".format(arch), - "LLVM_NATIVE_TARGETINFO=LLVMInitialize{}TargetInfo".format(arch), - "LLVM_NATIVE_TARGETMC=LLVMInitialize{}TargetMC".format(arch), - "LLVM_NATIVE_TARGETMCA=LLVMInitialize{}TargetMCA".format(arch), - r'LLVM_HOST_TRIPLE=\"{}\"'.format(triple), - r'LLVM_DEFAULT_TARGET_TRIPLE=\"{}\"'.format(triple), - ] - -posix_defines = [ - "LLVM_ON_UNIX=1", - "HAVE_BACKTRACE=1", - "BACKTRACE_HEADER=", - r'LTDL_SHLIB_EXT=\".so\"', - r'LLVM_PLUGIN_EXT=\".so\"', - "LLVM_ENABLE_THREADS=1", - "HAVE_DEREGISTER_FRAME=1", - "HAVE_LIBPTHREAD=1", - "HAVE_PTHREAD_GETNAME_NP=1", - "HAVE_PTHREAD_GETSPECIFIC=1", - "HAVE_PTHREAD_H=1", - "HAVE_PTHREAD_SETNAME_NP=1", - "HAVE_REGISTER_FRAME=1", - "HAVE_SETENV_R=1", - "HAVE_STRERROR_R=1", - "HAVE_SYSEXITS_H=1", - "HAVE_UNISTD_H=1", -] - -linux_defines = posix_defines + [ - "_GNU_SOURCE", - "HAVE_LINK_H=1", - "HAVE_LSEEK64=1", - "HAVE_MALLINFO=1", - "HAVE_SBRK=1", - "HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC=1", -] - -macos_defines = posix_defines + [ - "HAVE_MACH_MACH_H=1", - "HAVE_MALLOC_MALLOC_H=1", - "HAVE_MALLOC_ZONE_STATISTICS=1", - "HAVE_PROC_PID_RUSAGE=1", - "HAVE_UNW_ADD_DYNAMIC_FDE=1", -] - -win32_defines = [ - # Windows system library specific defines. - "_CRT_SECURE_NO_DEPRECATE", - "_CRT_SECURE_NO_WARNINGS", - "_CRT_NONSTDC_NO_DEPRECATE", - "_CRT_NONSTDC_NO_WARNINGS", - "_SCL_SECURE_NO_DEPRECATE", - "_SCL_SECURE_NO_WARNINGS", - "UNICODE", - "_UNICODE", - - # LLVM features - r'LTDL_SHLIB_EXT=\".dll\"', - r'LLVM_PLUGIN_EXT=\".dll\"', -] - -# TODO: We should switch to platforms-based config settings to make this easier -# to express. -os_defines = select({ - "@bazel_tools//src/conditions:windows": win32_defines, - "@bazel_tools//src/conditions:darwin": macos_defines, - "@bazel_tools//src/conditions:freebsd": posix_defines, - "//conditions:default": linux_defines, -}) - -# TODO: We should split out host vs. target here. -llvm_config_defines = os_defines + select({ - "@bazel_tools//src/conditions:windows": native_arch_defines("X86", "x86_64-pc-win32"), - "@bazel_tools//src/conditions:darwin_arm64": native_arch_defines("AArch64", "arm64-apple-darwin"), - "@bazel_tools//src/conditions:darwin_x86_64": native_arch_defines("X86", "x86_64-unknown-darwin"), - "@bazel_tools//src/conditions:linux_aarch64": native_arch_defines("AArch64", "aarch64-unknown-linux-gnu"), - "//conditions:default": native_arch_defines("X86", "x86_64-unknown-linux-gnu"), -}) + [ - # These shouldn't be needed by the C++11 standard, but are for some - # platforms (e.g. glibc < 2.18. See - # https://sourceware.org/bugzilla/show_bug.cgi?id=15366). These are also - # included unconditionally in the CMake build: - # https://github.com/llvm/llvm-project/blob/cd0dd8ece8e/llvm/cmake/modules/HandleLLVMOptions.cmake#L907-L909 - "__STDC_LIMIT_MACROS", - "__STDC_CONSTANT_MACROS", - "__STDC_FORMAT_MACROS", -] diff --git a/utils/bazel/llvm-project-overlay/llvm/enum_targets_gen.bzl b/utils/bazel/llvm-project-overlay/llvm/enum_targets_gen.bzl deleted file mode 100644 index cf25fe62046dd..0000000000000 --- a/utils/bazel/llvm-project-overlay/llvm/enum_targets_gen.bzl +++ /dev/null @@ -1,64 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -"""A rule to expand LLVM target enumerations. - -Replaces in a text file a single variable of the style `@LLVM_ENUM_FOOS@` with a -list of macro invocations, one for each target on its own line: - -``` -LLVM_FOO(TARGET1) -LLVM_FOO(TARGET2) -// ... -``` - -Example: -load(":enum_targets_gen.bzl", "enum_targets_gen") - -enum_targets_gen( - name = "disassemblers_def_gen", - src = "include/llvm/Config/Disassemblers.def.in", - out = "include/llvm/Config/Disassemblers.def", - macro_name = "DISASSEMBLER", - targets = llvm_target_disassemblers, -) - -This rule provides a slightly more semantic API than template_rule, but the main -reason it exists is to permit a list with selects to be passed for `targets` as -a select is not allowed to be passed to a rule within another data structure. -""" - -def enum_targets_gen_impl(ctx): - to_replace = "@LLVM_ENUM_{}S@".format(ctx.attr.macro_name) - replacement = "\n".join([ - "LLVM_{}({})\n".format(ctx.attr.macro_name, t) - for t in ctx.attr.targets - ]) - - ctx.actions.expand_template( - template = ctx.file.src, - output = ctx.outputs.out, - substitutions = {to_replace: replacement}, - ) - -enum_targets_gen = rule( - attrs = { - "src": attr.label( - mandatory = True, - allow_single_file = True, - ), - "out": attr.output(mandatory = True), - "targets": attr.string_list(mandatory = True), - "macro_name": attr.string( - mandatory = True, - doc = "The name of the enumeration. This is the suffix of the" + - " placeholder being replaced `@LLVM_ENUM_{}S@` and of the" + - " macro invocations generated `LLVM_{}(TARGET)`. Should be" + - " all caps and singular, e.g. 'DISASSEMBLER'", - ), - }, - # output_to_genfiles is required for header files. - output_to_genfiles = True, - implementation = enum_targets_gen_impl, -) diff --git a/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h b/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h deleted file mode 100644 index 45945510d02bc..0000000000000 --- a/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h +++ /dev/null @@ -1,385 +0,0 @@ -/*===------- llvm/Config/config.h - llvm configuration ------------*- C -*-===*/ -/* */ -/* Part of the LLVM Project, under the Apache License v2.0 with LLVM */ -/* Exceptions. */ -/* See https://llvm.org/LICENSE.txt for license information. */ -/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -/* */ -/*===----------------------------------------------------------------------===*/ - -/* This is a manual port of config.h.cmake for the symbols that do not change - based on platform. Those that do change should not be defined here and - instead use Bazel cc_library defines. Some attempt has been made to extract - such symbols that do vary based on platform (for the platforms we care about) - into Bazel defines, but it is by no means complete, so if you see something - that looks wrong, it probably is. */ - -#ifndef CONFIG_H -#define CONFIG_H - -// Include this header only under the llvm source tree. -// This is a private header. - -/* Exported configuration */ -#include "llvm/Config/llvm-config.h" - -/* Bug report URL. */ -#define BUG_REPORT_URL "https://github.com/llvm/llvm-project/issues/" - -/* Define to 1 to enable backtraces, and to 0 otherwise. */ -#define ENABLE_BACKTRACES 1 - -/* Define to 1 to enable crash overrides, and to 0 otherwise. */ -#define ENABLE_CRASH_OVERRIDES 1 - -/* Define to 1 to enable crash memory dumps, and to 0 otherwise. */ -#define LLVM_ENABLE_CRASH_DUMPS 0 - -/* Define to 1 to prefer forward slashes on Windows, and to 0 prefer - backslashes. */ -#define LLVM_WINDOWS_PREFER_FORWARD_SLASH 0 - -/* Define to 1 if you have the `backtrace' function. */ -/* HAVE_BACKTRACE defined in Bazel */ - -/* BACKTRACE_HEADER defined in Bazel */ - -/* Define to 1 if you have the header file. */ -/* HAVE_CRASHREPORTERCLIENT_H defined in Bazel */ - -/* can use __crashreporter_info__ */ -/* HAVE_CRASHREPORTER_INFO defined in Bazel */ - -/* Define to 1 if you have the declaration of `arc4random', and to 0 if you - don't. */ -#define HAVE_DECL_ARC4RANDOM 0 - -/* Define to 1 if you have the declaration of `FE_ALL_EXCEPT', and to 0 if you - don't. */ -#define HAVE_DECL_FE_ALL_EXCEPT 1 - -/* Define to 1 if you have the declaration of `FE_INEXACT', and to 0 if you - don't. */ -#define HAVE_DECL_FE_INEXACT 1 - -/* Define to 1 if you have the declaration of `strerror_s', and to 0 if you - don't. */ -#define HAVE_DECL_STRERROR_S 0 - -/* Define to 1 if you have the DIA SDK installed, and to 0 if you don't. */ -#define LLVM_ENABLE_DIA_SDK 0 - -/* Define to 1 if you have the header file. */ -#define HAVE_DLFCN_H 1 - -/* Define if dlopen() is available on this platform. */ -#define HAVE_DLOPEN 1 - -/* Define if dladdr() is available on this platform. */ -/* #undef HAVE_DLADDR */ - -/* Define to 1 if we can register EH frames on this platform. */ -/* HAVE_REGISTER_FRAME defined in Bazel*/ - -/* Define to 1 if we can deregister EH frames on this platform. */ -/* HAVE_DEREGISTER_FRAME defined in Bazel*/ - -/* Define if __unw_add_dynamic_fde() is available on this platform. */ -/* HAVE_UNW_ADD_DYNAMIC_FDE defined in Bazel */ - -/* Define to 1 if you have the header file. */ -#define HAVE_ERRNO_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_FCNTL_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_FENV_H 1 - -/* Define if libffi is available on this platform. */ -/* #undef HAVE_FFI_CALL */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_FFI_FFI_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_FFI_H */ - -/* Define to 1 if you have the `futimens' function. */ -#define HAVE_FUTIMENS 1 - -/* Define to 1 if you have the `futimes' function. */ -#define HAVE_FUTIMES 1 - -/* Define to 1 if you have the `getpagesize' function. */ -#define HAVE_GETPAGESIZE 1 - -/* Define to 1 if you have the `getrlimit' function. */ -#define HAVE_GETRLIMIT 1 - -/* Define to 1 if you have the `getrusage' function. */ -#define HAVE_GETRUSAGE 1 - -/* Define to 1 if you have the `isatty' function. */ -#define HAVE_ISATTY 1 - -/* Define to 1 if you have the `edit' library (-ledit). */ -/* #undef HAVE_LIBEDIT */ - -/* Define to 1 if you have the `pfm' library (-lpfm). */ -/* #undef HAVE_LIBPFM */ - -/* Define to 1 if the `perf_branch_entry' struct has field cycles. */ -/* #undef LIBPFM_HAS_FIELD_CYCLES */ - -/* Define to 1 if you have the `psapi' library (-lpsapi). */ -/* #undef HAVE_LIBPSAPI */ - -/* Define to 1 if you have the `pthread' library (-lpthread). */ -#define HAVE_LIBPTHREAD 1 - -/* Define to 1 if you have the `pthread_getname_np' function. */ -#define HAVE_PTHREAD_GETNAME_NP 1 - -/* Define to 1 if you have the `pthread_setname_np' function. */ -#define HAVE_PTHREAD_SETNAME_NP 1 - -/* Define to 1 if you have the header file. */ -/* HAVE_LINK_H defined in Bazel */ - -/* Define to 1 if you have the `lseek64' function. */ -/* HAVE_LSEEK64 defined in Bazel */ - -/* Define to 1 if you have the header file. */ -/* HAVE_MACH_MACH_H defined in Bazel */ - -/* Define to 1 if you have the `mallctl' function. */ -/* #undef HAVE_MALLCTL */ - -/* Define to 1 if you have the `mallinfo' function. */ -/* HAVE_MALLINFO defined in Bazel */ - -/* Define to 1 if you have the header file. */ -/* HAVE_MALLOC_MALLOC_H defined in Bazel */ - -/* Define to 1 if you have the `malloc_zone_statistics' function. */ -/* HAVE_MALLOC_ZONE_STATISTICS defined in Bazel */ - -/* Define to 1 if you have the `posix_spawn' function. */ -#define HAVE_POSIX_SPAWN 1 - -/* Define to 1 if you have the `pread' function. */ -#define HAVE_PREAD 1 - -/* Have pthread_getspecific */ -#define HAVE_PTHREAD_GETSPECIFIC 1 - -/* Define to 1 if you have the header file. */ -/* HAVE_PTHREAD_H defined in Bazel */ - -/* Have pthread_mutex_lock */ -#define HAVE_PTHREAD_MUTEX_LOCK 1 - -/* Have pthread_rwlock_init */ -#define HAVE_PTHREAD_RWLOCK_INIT 1 - -/* Define to 1 if you have the `sbrk' function. */ -/* HAVE_SBRK defined in Bazel */ - -/* Define to 1 if you have the `setenv' function. */ -/* HAVE_SETENV defined in Bazel */ - -/* Define to 1 if you have the `setrlimit' function. */ -#define HAVE_SETRLIMIT 1 - -/* Define to 1 if you have the `sigaltstack' function. */ -#define HAVE_SIGALTSTACK 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SIGNAL_H 1 - -/* Define to 1 if you have the `strerror' function. */ -#define HAVE_STRERROR 1 - -/* Define to 1 if you have the `strerror_r' function. */ -/* HAVE_STRERROR_R defined in Bazel */ - -/* Define to 1 if you have the `sysconf' function. */ -#define HAVE_SYSCONF 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_IOCTL_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_MMAN_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_PARAM_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_RESOURCE_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TIME_H 1 - -/* Define to 1 if stat struct has st_mtimespec member .*/ -/* #undef HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC */ - -/* Define to 1 if stat struct has st_mtim member. */ -/* HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC defined in Bazel */ - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define if the setupterm() function is supported this platform. */ -/* LLVM_ENABLE_TERMINFO defined in Bazel */ - -/* Define to 1 if you have the header file. */ -#define HAVE_TERMIOS_H 1 - -/* Define to 1 if you have the header file. */ -/* HAVE_UNISTD_H defined in Bazel */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_VALGRIND_VALGRIND_H */ - -/* Have host's _alloca */ -/* #undef HAVE__ALLOCA */ - -/* Define to 1 if you have the `_chsize_s' function. */ -/* #undef HAVE__CHSIZE_S */ - -/* Define to 1 if you have the `_Unwind_Backtrace' function. */ -#define HAVE__UNWIND_BACKTRACE 1 - -/* Have host's __alloca */ -/* #undef HAVE___ALLOCA */ - -/* Have host's __ashldi3 */ -/* #undef HAVE___ASHLDI3 */ - -/* Have host's __ashrdi3 */ -/* #undef HAVE___ASHRDI3 */ - -/* Have host's __chkstk */ -/* #undef HAVE___CHKSTK */ - -/* Have host's __chkstk_ms */ -/* #undef HAVE___CHKSTK_MS */ - -/* Have host's __cmpdi2 */ -/* #undef HAVE___CMPDI2 */ - -/* Have host's __divdi3 */ -/* #undef HAVE___DIVDI3 */ - -/* Have host's __fixdfdi */ -/* #undef HAVE___FIXDFDI */ - -/* Have host's __fixsfdi */ -/* #undef HAVE___FIXSFDI */ - -/* Have host's __floatdidf */ -/* #undef HAVE___FLOATDIDF */ - -/* Have host's __lshrdi3 */ -/* #undef HAVE___LSHRDI3 */ - -/* Have host's __main */ -/* #undef HAVE___MAIN */ - -/* Have host's __moddi3 */ -/* #undef HAVE___MODDI3 */ - -/* Have host's __udivdi3 */ -/* #undef HAVE___UDIVDI3 */ - -/* Have host's __umoddi3 */ -/* #undef HAVE___UMODDI3 */ - -/* Have host's ___chkstk */ -/* #undef HAVE____CHKSTK */ - -/* Have host's ___chkstk_ms */ -/* #undef HAVE____CHKSTK_MS */ - -/* Linker version detected at compile time. */ -/* #undef HOST_LINK_VERSION */ - -/* Target triple LLVM will generate code for by default */ -/* Doesn't use `cmakedefine` because it is allowed to be empty. */ -/* LLVM_DEFAULT_TARGET_TRIPLE defined in Bazel */ - -/* Define if zlib compression is available */ -/* LLVM_ENABLE_ZLIB defined in Bazel */ - -/* Define if overriding target triple is enabled */ -/* #undef LLVM_TARGET_TRIPLE_ENV */ - -/* LLVM version information */ -/* #undef LLVM_VERSION_INFO */ - -/* Whether tools show host and target info when invoked with --version */ -#define LLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO 1 - -/* Define if libxml2 is supported on this platform. */ -/* #undef LLVM_ENABLE_LIBXML2 */ - -/* Define to the extension used for shared libraries, say, ".so". */ -/* LTDL_SHLIB_EXT defined in Bazel */ - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "https://github.com/llvm/llvm-project/issues/" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "LLVM" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING PACKAGE_NAME " " LLVM_VERSION_STRING - -/* Define to the version of this package. */ -#define PACKAGE_VERSION LLVM_VERSION_STRING - -/* Define to the vendor of this package. */ -/* #undef PACKAGE_VENDOR */ - -/* Define as the return type of signal handlers (`int' or `void'). */ -#define RETSIGTYPE void - -/* Define if std::is_trivially_copyable is supported */ -#define HAVE_STD_IS_TRIVIALLY_COPYABLE 1 - -/* Define to a function implementing stricmp */ -/* stricmp defined conditionally below. */ - -/* Define to a function implementing strdup */ -/* strdup defined conditionally below. */ - -/* Whether GlobalISel rule coverage is being collected */ -#define LLVM_GISEL_COV_ENABLED 0 - -/* Define to the default GlobalISel coverage file prefix */ -/* #undef LLVM_GISEL_COV_PREFIX */ - -/* Whether Timers signpost passes in Xcode Instruments */ -#define LLVM_SUPPORT_XCODE_SIGNPOSTS 0 - -/* HAVE_PROC_PID_RUSAGE defined in Bazel */ - -/* Directly provide definitions here behind platform preprocessor definitions. - * The preprocessor conditions are sufficient to handle all of the configuration - * on platforms targeted by Bazel, and defining these here more faithfully - * matches how the users of this header expect things to work with CMake. - * FIXME: We should consider moving other platform defines to use this technique - * as well. - */ - -#ifdef _WIN32 -#define stricmp _stricmp -#define strdup _strdup -#endif - -#endif diff --git a/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h b/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h deleted file mode 100644 index 5aeceb4ac1cca..0000000000000 --- a/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h +++ /dev/null @@ -1,120 +0,0 @@ -/*===------- llvm/Config/llvm-config.h - llvm configuration -------*- C -*-===*/ -/* */ -/* Part of the LLVM Project, under the Apache License v2.0 with LLVM */ -/* Exceptions. */ -/* See https://llvm.org/LICENSE.txt for license information. */ -/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -/* */ -/*===----------------------------------------------------------------------===*/ - -/* This is a manual port of config.h.cmake for the symbols that do not change - based on platform. Those that do change should not be defined here and - instead use Bazel cc_library defines. Some attempt has been made to extract - such symbols that do vary based on platform (for the platforms we care about) - into Bazel defines, but it is by no means complete, so if you see something - that looks wrong, it probably is. */ - - -/* This file enumerates variables from the LLVM configuration so that they - can be in exported headers and won't override package specific directives. - This is a C header that can be included in the llvm-c headers. */ - -#ifndef LLVM_CONFIG_H -#define LLVM_CONFIG_H - -/* Define if LLVM_ENABLE_DUMP is enabled */ -/* #undef LLVM_ENABLE_DUMP */ - -/* Target triple LLVM will generate code for by default */ -/* LLVM_DEFAULT_TARGET_TRIPLE defined in Bazel */ - -/* Define if threads enabled */ -#define LLVM_ENABLE_THREADS 1 - -/* Has gcc/MSVC atomic intrinsics */ -#define LLVM_HAS_ATOMICS 1 - -/* Host triple LLVM will be executed on */ -/* LLVM_HOST_TRIPLE defined in Bazel */ - -/* LLVM architecture name for the native architecture, if available */ -/* LLVM_NATIVE_ARCH defined in Bazel */ - -/* LLVM name for the native AsmParser init function, if available */ -/* LLVM_NATIVE_ASMPARSER defined in Bazel */ - -/* LLVM name for the native AsmPrinter init function, if available */ -/* LLVM_NATIVE_ASMPRINTER defined in Bazel */ - -/* LLVM name for the native Disassembler init function, if available */ -/* LLVM_NATIVE_DISASSEMBLER defined in Bazel */ - -/* LLVM name for the native Target init function, if available */ -/* LLVM_NATIVE_TARGET defined in Bazel */ - -/* LLVM name for the native TargetInfo init function, if available */ -/* LLVM_NATIVE_TARGETINFO defined in Bazel */ - -/* LLVM name for the native target MC init function, if available */ -/* LLVM_NATIVE_TARGETMC defined in Bazel */ - -/* LLVM name for the native target MCA init function, if available */ -/* LLVM_NATIVE_TARGETMCA defined in Bazel */ - -/* Define if this is Unixish platform */ -/* LLVM_ON_UNIX defined in Bazel */ - -/* Define if we have the Intel JIT API runtime support library */ -#define LLVM_USE_INTEL_JITEVENTS 0 - -/* Define if we have the oprofile JIT-support library */ -#define LLVM_USE_OPROFILE 0 - -/* Define if we have the perf JIT-support library */ -#define LLVM_USE_PERF 0 - -/* Major version of the LLVM API */ -#define LLVM_VERSION_MAJOR 14 - -/* Minor version of the LLVM API */ -#define LLVM_VERSION_MINOR 0 - -/* Patch version of the LLVM API */ -#define LLVM_VERSION_PATCH 0 - -/* LLVM version string */ -#define LLVM_VERSION_STRING "14.0.0git" - -/* Whether LLVM records statistics for use with GetStatistics(), - * PrintStatistics() or PrintStatisticsJSON() - */ -#define LLVM_FORCE_ENABLE_STATS 0 - -/* Define if we have z3 and want to build it */ -/* #undef LLVM_WITH_Z3 */ - -/* Define if we have curl and want to use it */ -/* #undef LLVM_ENABLE_CURL */ - -/* Define if LLVM was built with a dependency to the libtensorflow dynamic library */ -/* #undef LLVM_HAVE_TF_API */ - -/* Define if LLVM was built with a dependency to the tensorflow compiler */ -/* #undef LLVM_HAVE_TF_AOT */ - -/* Define to 1 if you have the header file. */ -/* HAVE_SYSEXITS_H defined in Bazel */ - -/* Define to 1 to enable the experimental new pass manager by default */ -#define LLVM_ENABLE_NEW_PASS_MANAGER 0 - -/* Define if the xar_open() function is supported this platform. */ -/* #undef HAVE_LIBXAR */ - -/* Define if building libLLVM shared library */ -/* #undef LLVM_BUILD_LLVM_DYLIB */ - -/* Define if building LLVM with BUILD_SHARED_LIBS */ -/* #undef LLVM_BUILD_SHARED_LIBS */ - -#endif diff --git a/utils/bazel/llvm-project-overlay/llvm/tblgen.bzl b/utils/bazel/llvm-project-overlay/llvm/tblgen.bzl deleted file mode 100644 index d43390918e390..0000000000000 --- a/utils/bazel/llvm-project-overlay/llvm/tblgen.bzl +++ /dev/null @@ -1,81 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -"""This file contains BUILD extensions for generating source code from LLVM's -table definition files using the TableGen tool. - -See http://llvm.org/cmds/tblgen.html for more information on the TableGen -tool. -TODO(chandlerc): Currently this expresses include-based dependencies as -"sources", and has no transitive understanding due to these files not being -correctly understood by the build system. -""" - -def gentbl( - name, - tblgen, - td_file, - td_srcs, - tbl_outs, - library = True, - tblgen_args = "", - **kwargs): - """gentbl() generates tabular code from a table definition file. - - Args: - name: The name of the build rule for use in dependencies. - tblgen: The binary used to produce the output. - td_file: The primary table definitions file. - td_srcs: A list of table definition files included transitively. - tbl_outs: A list of tuples (opts, out), where each opts is a string of - options passed to tblgen, and the out is the corresponding output file - produced. - library: Whether to bundle the generated files into a library. - tblgen_args: Extra arguments string to pass to the tblgen binary. - **kwargs: Keyword arguments to pass to subsidiary cc_library() rule. - """ - llvm_project_execroot_path = Label("//llvm:tblgen.bzl").workspace_root - - if td_file not in td_srcs: - td_srcs += [td_file] - for (opts, out) in tbl_outs: - rule_suffix = "_".join(opts.replace("-", "_").replace("=", "_").split(" ")) - native.genrule( - name = "%s_%s_genrule" % (name, rule_suffix), - srcs = td_srcs, - outs = [out], - tools = [tblgen], - message = "Generating code from table: %s" % td_file, - cmd = (("$(location %s) -I %s/llvm/include " + - "-I %s/clang/include " + - "-I $$(dirname $(location %s)) " + - "%s $(location %s) %s -o $@") % ( - tblgen, - llvm_project_execroot_path, - llvm_project_execroot_path, - td_file, - opts, - td_file, - tblgen_args, - )), - ) - - # For now, all generated files can be assumed to comprise public interfaces. - # If this is not true, you should specify library = False - # and list the generated '.inc' files in "srcs". - if library: - native.cc_library( - name = name, - # FIXME: This should be `textual_hdrs` instead of `hdrs`, but - # unfortunately that doesn't work with `strip_include_prefix`: - # https://github.com/bazelbuild/bazel/issues/12424 - # - # Once that issue is fixed and released, we can switch this to - # `textual_hdrs` and remove the feature disabling the various Bazel - # features (both current and under-development) that motivated the - # distinction between these two. - hdrs = [f for (_, f) in tbl_outs], - features = ["-parse_headers", "-header_modules"], - **kwargs - ) diff --git a/utils/bazel/llvm-project-overlay/llvm/template_rule.bzl b/utils/bazel/llvm-project-overlay/llvm/template_rule.bzl deleted file mode 100644 index b453e7e4d8cbc..0000000000000 --- a/utils/bazel/llvm-project-overlay/llvm/template_rule.bzl +++ /dev/null @@ -1,46 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -# Rule for simple expansion of template files. This performs a simple -# search over the template file for the keys in substitutions, -# and replaces them with the corresponding values. -# -# Typical usage: -# load("/tools/build_rules/template_rule", "expand_header_template") -# template_rule( -# name = "ExpandMyTemplate", -# src = "my.template", -# out = "my.txt", -# substitutions = { -# "$VAR1": "foo", -# "$VAR2": "bar", -# } -# ) -# -# Args: -# name: The name of the rule. -# template: The template file to expand -# out: The destination of the expanded file -# substitutions: A dictionary mapping strings to their substitutions - -def template_rule_impl(ctx): - ctx.actions.expand_template( - template = ctx.file.src, - output = ctx.outputs.out, - substitutions = ctx.attr.substitutions, - ) - -template_rule = rule( - attrs = { - "src": attr.label( - mandatory = True, - allow_single_file = True, - ), - "substitutions": attr.string_dict(mandatory = True), - "out": attr.output(mandatory = True), - }, - # output_to_genfiles is required for header files. - output_to_genfiles = True, - implementation = template_rule_impl, -) diff --git a/utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel deleted file mode 100644 index 4d730eff7b96b..0000000000000 --- a/utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel +++ /dev/null @@ -1,683 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -load("//llvm:tblgen.bzl", "gentbl") - -package( - default_visibility = ["//visibility:public"], - licenses = ["notice"], -) - -cc_test( - name = "adt_tests", - size = "medium", - srcs = glob( - [ - "ADT/*.cpp", - "ADT/*.h", - ], - allow_empty = False, - ), - shard_count = 20, - deps = [ - "//llvm:Core", - "//llvm:Support", - "//llvm:TestingSupport", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "analysis_tests", - size = "small", - srcs = glob( - ["Analysis/*.cpp"], - allow_empty = False, - exclude = [ - # TODO: Add this file to the build. - "Analysis/TFUtilsTest.cpp", - "Analysis/MLModelRunnerTest.cpp", - ], - ), - deps = [ - "//llvm:Analysis", - "//llvm:AsmParser", - "//llvm:Core", - "//llvm:Support", - "//llvm:TestingSupport", - "//llvm:TransformUtils", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "asm_parser_tests", - size = "small", - srcs = glob( - ["AsmParser/*.cpp"], - allow_empty = False, - ), - deps = [ - "//llvm:AsmParser", - "//llvm:Core", - "//llvm:Support", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "bitcode_tests", - size = "small", - srcs = glob( - ["Bitcode/*.cpp"], - allow_empty = False, - ), - deps = [ - "//llvm:AsmParser", - "//llvm:BitReader", - "//llvm:BitWriter", - "//llvm:Core", - "//llvm:Support", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "bitstream_tests", - size = "small", - srcs = glob( - ["Bitstream/*.cpp"], - allow_empty = False, - ), - deps = [ - "//llvm:BitstreamReader", - "//llvm:BitstreamWriter", - "//llvm:Support", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_library( - name = "codegen_tests_includes", - textual_hdrs = glob( - ["CodeGen/*.inc"], - allow_empty = False, - ), -) - -cc_test( - name = "codegen_tests", - size = "medium", - srcs = glob( - [ - "CodeGen/*.cpp", - "CodeGen/*.h", - ], - allow_empty = False, - ), - deps = [ - ":codegen_tests_includes", - "//llvm:AllTargetsAsmParsers", - "//llvm:AllTargetsCodeGens", - "//llvm:Analysis", - "//llvm:AsmParser", - "//llvm:BinaryFormat", - "//llvm:CodeGen", - "//llvm:Core", - "//llvm:MC", - "//llvm:Passes", - "//llvm:Support", - "//llvm:Target", - "//llvm:TestingSupport", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "codegen_globalisel_tests", - size = "small", - srcs = glob( - [ - "CodeGen/GlobalISel/*.cpp", - "CodeGen/GlobalISel/*.h", - ], - allow_empty = False, - ), - copts = [ - "$(STACK_FRAME_UNLIMITED)", - ], - deps = [ - "//llvm:AllTargetsAsmParsers", - "//llvm:AllTargetsCodeGens", - "//llvm:CodeGen", - "//llvm:Core", - "//llvm:FileCheckLib", - "//llvm:Support", - "//llvm:Target", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "debuginfo_tests", - size = "medium", - srcs = glob( - [ - "DebugInfo/DWARF/*.cpp", - "DebugInfo/DWARF/*.h", - # TODO: Re-enable these when they stop crashing. - #"DebugInfo/PDB/*.cpp", - #"DebugInfo/PDB/*.h", - ], - allow_empty = False, - ), - args = [ - # Skip a test that relies on reading files in a way that doesn't easily - # work with Bazel. - "--gtest_filter=-NativeSymbolReuseTest.*", - ], - deps = [ - "//llvm:AllTargetsAsmParsers", - "//llvm:AllTargetsCodeGens", - "//llvm:CodeGen", - "//llvm:Core", - "//llvm:DebugInfoDWARF", - "//llvm:DebugInfoPDB", - "//llvm:ObjectYAML", - "//llvm:Support", - "//llvm:TestingSupport", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "debuginfod_tests", - srcs = glob(["Debuginfod/*.cpp"]), - deps = [ - "//llvm:Debuginfod", - "//llvm:TestingSupport", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "execution_engine_tests", - size = "small", - srcs = glob( - ["ExecutionEngine/*.cpp"], - allow_empty = False, - ), - deps = [ - "//llvm:AllTargetsCodeGens", - "//llvm:AsmParser", - "//llvm:Core", - "//llvm:ExecutionEngine", - "//llvm:Interpreter", - "//llvm:Support", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "execution_engine_mcjit_tests", - size = "medium", - srcs = glob( - [ - "ExecutionEngine/MCJIT/*.cpp", - "ExecutionEngine/MCJIT/*.h", - ], - allow_empty = False, - ), - copts = [ - "$(STACK_FRAME_UNLIMITED)", - ], - deps = [ - "//llvm:AllTargetsCodeGens", - "//llvm:AsmParser", - "//llvm:Core", - "//llvm:ExecutionEngine", - "//llvm:MCJIT", - "//llvm:Passes", - "//llvm:Support", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "execution_engine_orc_tests", - size = "medium", - srcs = glob( - [ - "ExecutionEngine/Orc/*.cpp", - "ExecutionEngine/Orc/*.h", - ], - allow_empty = False, - ), - args = ["--gtest_filter=-ObjectLinkingLayerTest.TestSetProcessAllSections"], - deps = [ - "//llvm:AllTargetsAsmParsers", - "//llvm:AllTargetsCodeGens", - "//llvm:AsmParser", - "//llvm:Core", - "//llvm:ExecutionEngine", - "//llvm:OrcJIT", - "//llvm:Support", - "//llvm:TestingSupport", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "filecheck_tests", - size = "small", - srcs = glob( - ["FileCheck/*.cpp"], - allow_empty = False, - ), - deps = [ - "//llvm:FileCheckLib", - "//llvm:Support", - "//llvm:TestingSupport", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "ir_tests", - size = "medium", - timeout = "long", # ConstantRangeTest cases may take several seconds each. - srcs = glob( - [ - "IR/*.cpp", - "IR/*.h", - "Support/KnownBitsTest.h", - ], - allow_empty = False, - ), - shard_count = 20, - deps = [ - "//llvm:Analysis", - "//llvm:AsmParser", - "//llvm:BinaryFormat", - "//llvm:Core", - "//llvm:Passes", - "//llvm:Scalar", - "//llvm:Support", - "//llvm:TestingSupport", - "//llvm:config", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "line_editor_tests", - size = "small", - srcs = glob( - ["LineEditor/*.cpp"], - allow_empty = False, - ), - deps = [ - "//llvm:LineEditor", - "//llvm:Support", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "frontend_tests", - size = "small", - srcs = glob( - ["Frontend/*.cpp"], - allow_empty = False, - ), - deps = [ - "//llvm:Analysis", - "//llvm:FrontendOpenACC", - "//llvm:FrontendOpenMP", - "//llvm:Passes", - "//llvm:Support", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "linker_tests", - size = "small", - srcs = glob( - ["Linker/*.cpp"], - allow_empty = False, - ), - deps = [ - "//llvm:AsmParser", - "//llvm:Core", - "//llvm:Linker", - "//llvm:Support", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "mc_tests", - size = "small", - srcs = glob( - ["MC/*.cpp"], - allow_empty = False, - ), - deps = [ - "//llvm:AllTargetsCodeGens", - "//llvm:AllTargetsDisassemblers", - "//llvm:MC", - "//llvm:MCDisassembler", - "//llvm:Support", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "mi_tests", - size = "medium", - srcs = glob( - ["MI/*.cpp"], - allow_empty = False, - ), - deps = [ - "//llvm:AllTargetsAsmParsers", - "//llvm:AllTargetsCodeGens", - "//llvm:CodeGen", - "//llvm:Core", - "//llvm:Support", - "//llvm:Target", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "object_tests", - size = "small", - srcs = glob( - ["Object/*.cpp"], - allow_empty = False, - ), - deps = [ - "//llvm:Object", - "//llvm:ObjectYAML", - "//llvm:TestingSupport", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "object_yaml_tests", - size = "small", - srcs = glob( - ["ObjectYAML/*.cpp"], - allow_empty = False, - ), - deps = [ - "//llvm:DebugInfoCodeView", - "//llvm:Object", - "//llvm:ObjectYAML", - "//llvm:Support", - "//llvm:TestingSupport", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -gentbl( - name = "option_tests_gen", - strip_include_prefix = "Option", - tbl_outs = [( - "-gen-opt-parser-defs", - "Option/Opts.inc", - )], - tblgen = "//llvm:llvm-tblgen", - td_file = "Option/Opts.td", - td_srcs = [ - "//llvm:include/llvm/Option/OptParser.td", - ], -) - -gentbl( - name = "automata_automata_gen", - strip_include_prefix = "TableGen", - tbl_outs = [( - "-gen-automata", - "TableGen/AutomataAutomata.inc", - )], - tblgen = "//llvm:llvm-tblgen", - td_file = "TableGen/Automata.td", - td_srcs = ["//llvm:common_target_td_sources"] + [ - "TableGen/Automata.td", - ], -) - -gentbl( - name = "automata_tables_gen", - strip_include_prefix = "TableGen", - tbl_outs = [( - "-gen-searchable-tables", - "TableGen/AutomataTables.inc", - )], - tblgen = "//llvm:llvm-tblgen", - td_file = "TableGen/Automata.td", - td_srcs = ["//llvm:common_target_td_sources"] + [ - "TableGen/Automata.td", - ], -) - -cc_test( - name = "option_tests", - size = "small", - srcs = glob( - ["Option/*.cpp"], - allow_empty = False, - ), - deps = [ - ":option_tests_gen", - "//llvm:Option", - "//llvm:Support", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "remarks_tests", - size = "small", - srcs = glob( - ["Remarks/*.cpp"], - allow_empty = False, - ), - deps = [ - "//llvm:BitReader", - "//llvm:Remarks", - "//llvm:Support", - "//llvm:gtest", - "//llvm:gtest_main", - "//llvm:remark_linker", - ], -) - -cc_test( - name = "profile_data_tests", - size = "small", - srcs = glob( - ["ProfileData/*.cpp"], - allow_empty = False, - ), - deps = [ - "//llvm:Core", - "//llvm:Coverage", - "//llvm:ProfileData", - "//llvm:Support", - "//llvm:TestingSupport", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -# Note that the name of this test is important as it is used in the test itself. -cc_test( - name = "SupportTests", - size = "medium", - srcs = glob( - [ - "Support/*.cpp", - "Support/*.h", - ], - allow_empty = False, - exclude = [ - "Support/ParallelTest.cpp", - ], - ), - args = ["--gtest_filter=-ProgramTest.CreateProcessTrailingSlash"], - copts = [ - "$(STACK_FRAME_UNLIMITED)", - ], - linkstatic = 1, - tags = [ - "local", # Not compatible with the sandbox on MacOS - ], - deps = [ - "//llvm:AllTargetsCodeGens", - "//llvm:BinaryFormat", - "//llvm:Core", - "//llvm:Support", - "//llvm:TestingSupport", - "//llvm:config", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "support_parallel_tests", - size = "small", - srcs = ["Support/ParallelTest.cpp"], - copts = [ - "$(STACK_FRAME_UNLIMITED)", - ], - linkstatic = 1, - deps = [ - "//llvm:AllTargetsCodeGens", - "//llvm:Support", - "//llvm:config", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "tablegen_tests", - size = "small", - srcs = glob( - [ - "TableGen/*.cpp", - ], - allow_empty = False, - ), - deps = [ - ":automata_automata_gen", - ":automata_tables_gen", - "//llvm:Support", - "//llvm:TableGen", - "//llvm:gtest", - "//llvm:gtest_main", - "//llvm:tblgen", - ], -) - -cc_test( - name = "target_aarch64_tests", - size = "small", - srcs = glob( - ["Target/AArch64/*.cpp"], - allow_empty = False, - ), - copts = [ - "$(STACK_FRAME_UNLIMITED)", - ], - deps = [ - "//llvm:AArch64CodeGen", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "transforms_tests", - size = "small", - srcs = glob( - [ - "Transforms/IPO/*.cpp", - "Transforms/IPO/*.h", - "Transforms/Utils/*.cpp", - ], - allow_empty = False, - ), - deps = [ - "//llvm:Analysis", - "//llvm:AsmParser", - "//llvm:Core", - "//llvm:IPO", - "//llvm:Support", - "//llvm:TestingSupport", - "//llvm:TransformUtils", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) - -cc_test( - name = "llvm_exegesis_tests", - size = "small", - srcs = glob( - [ - "tools/llvm-exegesis/*.cpp", - "tools/llvm-exegesis/X86/*.cpp", - "tools/llvm-exegesis/X86/*.h", - ], - allow_empty = False, - ) + [ - "tools/llvm-exegesis/Common/AssemblerUtils.h", - ], - copts = ["-DHAVE_LIBPFM=1"], - linkopts = ["-lpfm"], - tags = [ - "manual", # External dependency (libpfm4) - "nobuildkite", # TODO(chandlerc): Add support for fetching and building libpfm4 and enable this. - ], - deps = [ - "//llvm:AllTargetsCodeGens", - "//llvm:AllTargetsDisassemblers", - "//llvm:Exegesis", - "//llvm:MC", - "//llvm:MCDisassembler", - "//llvm:Support", - "//llvm:TestingSupport", - "//llvm:gtest", - "//llvm:gtest_main", - ], -) diff --git a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel deleted file mode 100644 index 5e0e3a69ece86..0000000000000 --- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel +++ /dev/null @@ -1,8259 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -# Description: -# The MLIR "Multi-Level Intermediate Representation" Compiler Infrastructure - -load(":tblgen.bzl", "gentbl_cc_library", "td_library") -load(":linalggen.bzl", "genlinalg") -load( - ":build_defs.bzl", - "cc_headers_only", - "if_cuda_available", - "mlir_c_api_cc_library", -) - -package( - default_visibility = ["//visibility:public"], - features = ["layering_check"], - licenses = ["notice"], -) - -exports_files([ - "LICENSE.TXT", - "include/mlir/Dialect/LLVMIR/LLVMOps.td", - "run_lit.sh", -]) - -filegroup( - name = "c_headers", - srcs = glob(["include/mlir-c/**/*"]), # <== i.e. match the entire tree -) - -filegroup( - name = "ConversionPassDetail", - srcs = [ - "include/mlir/Conversion/GPUToROCDL/Runtimes.h", - "lib/Conversion/PassDetail.h", - ], -) - -exports_files(glob(["include/**/*.td"])) - -[ - gentbl_cc_library( - name = name + "IncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/IR/" + name + ".h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/IR/" + name + ".cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/IR/" + name + ".td", - deps = [":OpBaseTdFiles"], - ) - for name in [ - "OpAsmInterface", - "RegionKindInterface", - "SymbolInterfaces", - ] -] - -gentbl_cc_library( - name = "TensorEncodingIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-attr-interface-decls"], - "include/mlir/IR/TensorEncInterfaces.h.inc", - ), - ( - ["-gen-attr-interface-defs"], - "include/mlir/IR/TensorEncInterfaces.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/IR/TensorEncoding.td", - deps = [":TensorOpsTdFiles"], -) - -td_library( - name = "SubElementInterfacesTdFiles", - srcs = ["include/mlir/IR/SubElementInterfaces.td"], - includes = ["include"], - deps = [":OpBaseTdFiles"], -) - -gentbl_cc_library( - name = "SubElementInterfacesIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-attr-interface-decls"], - "include/mlir/IR/SubElementAttrInterfaces.h.inc", - ), - ( - ["-gen-attr-interface-defs"], - "include/mlir/IR/SubElementAttrInterfaces.cpp.inc", - ), - ( - ["-gen-type-interface-decls"], - "include/mlir/IR/SubElementTypeInterfaces.h.inc", - ), - ( - ["-gen-type-interface-defs"], - "include/mlir/IR/SubElementTypeInterfaces.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/IR/SubElementInterfaces.td", - deps = [":SubElementInterfacesTdFiles"], -) - -td_library( - name = "BuiltinDialectTdFiles", - srcs = [ - "include/mlir/IR/BuiltinAttributeInterfaces.td", - "include/mlir/IR/BuiltinAttributes.td", - "include/mlir/IR/BuiltinDialect.td", - "include/mlir/IR/BuiltinLocationAttributes.td", - "include/mlir/IR/BuiltinOps.td", - "include/mlir/IR/BuiltinTypeInterfaces.td", - "include/mlir/IR/BuiltinTypes.td", - ], - includes = ["include"], - deps = [ - ":CallInterfacesTdFiles", - ":CastInterfacesTdFiles", - ":DataLayoutInterfacesTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ":SubElementInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "BuiltinDialectIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-dialect-decls"], - "include/mlir/IR/BuiltinDialect.h.inc", - ), - ( - ["-gen-dialect-defs"], - "include/mlir/IR/BuiltinDialect.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/IR/BuiltinDialect.td", - deps = [":BuiltinDialectTdFiles"], -) - -gentbl_cc_library( - name = "BuiltinAttributesIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["--gen-attrdef-decls"], - "include/mlir/IR/BuiltinAttributes.h.inc", - ), - ( - ["--gen-attrdef-defs"], - "include/mlir/IR/BuiltinAttributes.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/IR/BuiltinAttributes.td", - deps = [":BuiltinDialectTdFiles"], -) - -gentbl_cc_library( - name = "BuiltinAttributeInterfacesIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["--gen-attr-interface-decls"], - "include/mlir/IR/BuiltinAttributeInterfaces.h.inc", - ), - ( - ["--gen-attr-interface-defs"], - "include/mlir/IR/BuiltinAttributeInterfaces.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/IR/BuiltinAttributeInterfaces.td", - deps = [":BuiltinDialectTdFiles"], -) - -gentbl_cc_library( - name = "BuiltinLocationAttributesIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["--gen-attrdef-decls"], - "include/mlir/IR/BuiltinLocationAttributes.h.inc", - ), - ( - ["--gen-attrdef-defs"], - "include/mlir/IR/BuiltinLocationAttributes.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/IR/BuiltinLocationAttributes.td", - deps = [":BuiltinDialectTdFiles"], -) - -gentbl_cc_library( - name = "BuiltinOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/IR/BuiltinOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/IR/BuiltinOps.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/IR/BuiltinOps.td", - deps = [ - ":BuiltinDialectTdFiles", - ":FunctionInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "BuiltinTypesIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["--gen-typedef-decls"], - "include/mlir/IR/BuiltinTypes.h.inc", - ), - ( - ["--gen-typedef-defs"], - "include/mlir/IR/BuiltinTypes.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/IR/BuiltinTypes.td", - deps = [":BuiltinDialectTdFiles"], -) - -gentbl_cc_library( - name = "BuiltinTypeInterfacesIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["--gen-type-interface-decls"], - "include/mlir/IR/BuiltinTypeInterfaces.h.inc", - ), - ( - ["--gen-type-interface-defs"], - "include/mlir/IR/BuiltinTypeInterfaces.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/IR/BuiltinTypeInterfaces.td", - deps = [ - ":BuiltinDialectTdFiles", - ], -) - -td_library( - name = "FunctionInterfacesTdFiles", - srcs = ["include/mlir/IR/FunctionInterfaces.td"], - includes = ["include"], - deps = [":OpBaseTdFiles"], -) - -gentbl_cc_library( - name = "FunctionInterfacesIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/IR/FunctionOpInterfaces.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/IR/FunctionOpInterfaces.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/IR/FunctionInterfaces.td", - deps = [ - ":OpBaseTdFiles", - ], -) - -cc_library( - name = "IR", - srcs = glob([ - "lib/IR/*.cpp", - "lib/IR/*.h", - ]), - hdrs = glob([ - "include/mlir/IR/*.h", - ]) + [ - "include/mlir/Interfaces/CallInterfaces.h", - "include/mlir/Interfaces/CastInterfaces.h", - "include/mlir/Interfaces/SideEffectInterfaces.h", - "include/mlir/Interfaces/DataLayoutInterfaces.h", - "include/mlir/Interfaces/DecodeAttributesInterfaces.h", - "include/mlir/Interfaces/FoldInterfaces.h", - ], - includes = ["include"], - deps = [ - ":BuiltinAttributeInterfacesIncGen", - ":BuiltinAttributesIncGen", - ":BuiltinDialectIncGen", - ":BuiltinLocationAttributesIncGen", - ":BuiltinOpsIncGen", - ":BuiltinTypeInterfacesIncGen", - ":BuiltinTypesIncGen", - ":CallOpInterfacesIncGen", - ":CastOpInterfacesIncGen", - ":DataLayoutInterfacesIncGen", - ":FunctionInterfacesIncGen", - ":InferTypeOpInterfaceIncGen", - ":OpAsmInterfaceIncGen", - ":RegionKindInterfaceIncGen", - ":SideEffectInterfacesIncGen", - ":SubElementInterfacesIncGen", - ":Support", - ":SymbolInterfacesIncGen", - ":TensorEncodingIncGen", - "//llvm:Support", - ], -) - -cc_library( - name = "Pass", - srcs = glob([ - "lib/Pass/*.cpp", - "lib/Pass/*.h", - ]), - hdrs = glob([ - "include/mlir/Pass/*.h", - ]), - includes = ["include"], - deps = [ - ":IR", - ":Support", - "//llvm:Support", - ], -) - -mlir_c_api_cc_library( - name = "CAPIIR", - srcs = [ - "lib/CAPI/Dialect/Standard.cpp", - "lib/CAPI/IR/AffineExpr.cpp", - "lib/CAPI/IR/AffineMap.cpp", - "lib/CAPI/IR/BuiltinAttributes.cpp", - "lib/CAPI/IR/BuiltinTypes.cpp", - "lib/CAPI/IR/Diagnostics.cpp", - "lib/CAPI/IR/DialectHandle.cpp", - "lib/CAPI/IR/IR.cpp", - "lib/CAPI/IR/IntegerSet.cpp", - "lib/CAPI/IR/Pass.cpp", - "lib/CAPI/IR/Support.cpp", - ], - hdrs = [ - "include/mlir-c/AffineExpr.h", - "include/mlir-c/AffineMap.h", - "include/mlir-c/BuiltinAttributes.h", - "include/mlir-c/BuiltinTypes.h", - "include/mlir-c/Diagnostics.h", - "include/mlir-c/Dialect/Standard.h", - "include/mlir-c/ExecutionEngine.h", - "include/mlir-c/IR.h", - "include/mlir-c/IntegerSet.h", - "include/mlir-c/Interfaces.h", - "include/mlir-c/Pass.h", - "include/mlir-c/Registration.h", - "include/mlir-c/Support.h", - "include/mlir/CAPI/AffineExpr.h", - "include/mlir/CAPI/AffineMap.h", - "include/mlir/CAPI/Diagnostics.h", - "include/mlir/CAPI/IR.h", - "include/mlir/CAPI/IntegerSet.h", - "include/mlir/CAPI/Pass.h", - "include/mlir/CAPI/Registration.h", - "include/mlir/CAPI/Support.h", - "include/mlir/CAPI/Utils.h", - "include/mlir/CAPI/Wrap.h", - ], - header_deps = [ - ":IR", - ":Pass", - ":Support", - "//llvm:Support", - ], - includes = ["include"], - deps = [ - ":ConversionPassIncGen", - ":InferTypeOpInterface", - ":Parser", - ":StandardOps", - ], -) - -mlir_c_api_cc_library( - name = "CAPIInterfaces", - srcs = [ - "lib/CAPI/Interfaces/Interfaces.cpp", - ], - capi_deps = [ - ":CAPIIR", - ], - includes = ["include"], - deps = [ - ":IR", - ":InferTypeOpInterface", - "//llvm:Support", - ], -) - -mlir_c_api_cc_library( - name = "CAPIAsync", - srcs = [ - "lib/CAPI/Dialect/Async.cpp", - "lib/CAPI/Dialect/AsyncPasses.cpp", - ], - hdrs = ["include/mlir-c/Dialect/Async.h"], - capi_deps = [ - ":CAPIIR", - ], - header_deps = [ - ":AsyncPassIncGen", - ], - includes = ["include"], - deps = [ - ":Async", - ":AsyncTransforms", - ":Pass", - ], -) - -mlir_c_api_cc_library( - name = "CAPILinalg", - srcs = [ - "lib/CAPI/Dialect/Linalg.cpp", - "lib/CAPI/Dialect/LinalgPasses.cpp", - ], - hdrs = [ - "include/mlir-c/Dialect/Linalg.h", - ], - capi_deps = [ - ":CAPIIR", - ], - header_deps = [ - ":LinalgPassIncGen", - ], - includes = ["include"], - deps = [ - ":LinalgOps", - ":LinalgTransforms", - ":Pass", - ], -) - -mlir_c_api_cc_library( - name = "CAPILLVM", - srcs = [ - "lib/CAPI/Dialect/LLVM.cpp", - ], - hdrs = [ - "include/mlir-c/Dialect/LLVM.h", - ], - capi_deps = [ - ":CAPIIR", - ], - includes = ["include"], - deps = [ - ":LLVMDialect", - ], -) - -mlir_c_api_cc_library( - name = "CAPIGPU", - srcs = [ - "lib/CAPI/Dialect/GPU.cpp", - "lib/CAPI/Dialect/GPUPasses.cpp", - ], - hdrs = [ - "include/mlir-c/Dialect/GPU.h", - ], - capi_deps = [ - ":CAPIIR", - ], - header_deps = [ - ":GPUPassIncGen", - ], - includes = ["include"], - deps = [ - ":GPUDialect", - ":GPUTransforms", - ":Pass", - ], -) - -mlir_c_api_cc_library( - name = "CAPISparseTensor", - srcs = [ - "lib/CAPI/Dialect/SparseTensor.cpp", - "lib/CAPI/Dialect/SparseTensorPasses.cpp", - ], - hdrs = [ - "include/mlir-c/Dialect/SparseTensor.h", - ], - capi_deps = [ - ":CAPIIR", - ], - header_deps = [ - ":SparseTensorPassIncGen", - ], - includes = ["include"], - deps = [ - ":Pass", - ":SparseTensor", - ":SparseTensorTransforms", - ":Support", - ], -) - -mlir_c_api_cc_library( - name = "CAPIQuant", - srcs = [ - "lib/CAPI/Dialect/Quant.cpp", - ], - hdrs = [ - "include/mlir-c/Dialect/Quant.h", - ], - capi_deps = [ - ":CAPIIR", - ], - includes = ["include"], - deps = [ - ":QuantOps", - ], -) - -mlir_c_api_cc_library( - name = "CAPIPDL", - srcs = [ - "lib/CAPI/Dialect/PDL.cpp", - ], - hdrs = [ - "include/mlir-c/Dialect/PDL.h", - ], - header_deps = [ - ":CAPIIRHeaders", - ], - includes = ["include"], - deps = [ - ":CAPIIR", - ":PDLDialect", - ":PDLOpsIncGen", - ":PDLTypesIncGen", - ], -) - -mlir_c_api_cc_library( - name = "CAPIConversion", - srcs = ["lib/CAPI/Conversion/Passes.cpp"], - hdrs = ["include/mlir-c/Conversion.h"], - capi_deps = [ - ":CAPIIR", - ], - header_deps = [ - ":ConversionPassIncGen", - ], - includes = ["include"], - deps = [ - ":ConversionPasses", - ":Pass", - ], -) - -mlir_c_api_cc_library( - name = "CAPIDebug", - srcs = ["lib/CAPI/Debug/Debug.cpp"], - hdrs = ["include/mlir-c/Debug.h"], - capi_deps = [ - ":CAPIIR", - ], - includes = ["include"], - deps = [ - ":Support", - "//llvm:Support", - ], -) - -mlir_c_api_cc_library( - name = "CAPIExecutionEngine", - srcs = ["lib/CAPI/ExecutionEngine/ExecutionEngine.cpp"], - hdrs = [ - "include/mlir-c/ExecutionEngine.h", - "include/mlir/CAPI/ExecutionEngine.h", - ], - capi_deps = [ - ":CAPIIR", - ], - header_deps = [ - ":ExecutionEngine", - ], - includes = ["include"], - deps = [ - ":ExecutionEngineUtils", - ":LLVMToLLVMIRTranslation", - "//llvm:OrcJIT", - "//llvm:Support", - ], -) - -mlir_c_api_cc_library( - name = "CAPITransforms", - srcs = ["lib/CAPI/Transforms/Passes.cpp"], - hdrs = ["include/mlir-c/Transforms.h"], - capi_deps = [ - ":CAPIIR", - ], - header_deps = [ - ":TransformsPassIncGen", - ], - includes = ["include"], - deps = [ - ":Pass", - ":Transforms", - ], -) - -mlir_c_api_cc_library( - name = "CAPIRegistration", - srcs = ["lib/CAPI/Registration/Registration.cpp"], - hdrs = ["include/mlir-c/Registration.h"], - capi_deps = [ - ":CAPIIR", - ], - includes = ["include"], - deps = [ - ":AllPassesAndDialects", - ":LLVMToLLVMIRTranslation", - ], -) - -##---------------------------------------------------------------------------## -# Sources of Python bindings. -#----------------------------------------------------------------------------## - -exports_files( - glob(["lib/Bindings/Python/**/*.cpp"]), -) - -MLIR_BINDINGS_PYTHON_HEADERS = [ - "lib/Bindings/Python/*.h", - "include/mlir-c/Bindings/Python/*.h", - "include/mlir/Bindings/Python/*.h", -] - -cc_library( - name = "MLIRBindingsPythonHeaders", - includes = [ - "include", - "lib/Bindings/Python", - ], - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - textual_hdrs = glob(MLIR_BINDINGS_PYTHON_HEADERS), - deps = [ - ":CAPIIRHeaders", - "@pybind11", - "@python_runtime//:headers", - ], -) - -cc_library( - name = "MLIRBindingsPythonHeadersAndDeps", - includes = [ - "include", - "lib/Bindings/Python", - ], - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - textual_hdrs = glob(MLIR_BINDINGS_PYTHON_HEADERS), - deps = [ - ":CAPIIR", - "@pybind11", - "@python_runtime//:headers", - ], -) - -# These flags are needed for pybind11 to work. -PYBIND11_COPTS = [ - "-fexceptions", - "-frtti", -] - -PYBIND11_FEATURES = [ - # Cannot use header_modules (parse_headers feature fails). - "-use_header_modules", -] - -MLIR_PYTHON_BINDINGS_SOURCES = [ - "lib/Bindings/Python/IRAffine.cpp", - "lib/Bindings/Python/IRAttributes.cpp", - "lib/Bindings/Python/IRCore.cpp", - "lib/Bindings/Python/IRInterfaces.cpp", - "lib/Bindings/Python/IRModule.cpp", - "lib/Bindings/Python/IRTypes.cpp", - "lib/Bindings/Python/Pass.cpp", - "lib/Bindings/Python/PybindUtils.cpp", -] - -cc_library( - name = "MLIRBindingsPythonCore", - srcs = MLIR_PYTHON_BINDINGS_SOURCES, - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIAsync", - ":CAPIDebug", - ":CAPIGPU", - ":CAPIIR", - ":CAPIInterfaces", - ":CAPIRegistration", - ":MLIRBindingsPythonHeadersAndDeps", - "//llvm:Support", - "@pybind11", - "@python_runtime//:headers", - ], -) - -cc_library( - name = "MLIRBindingsPythonCoreNoCAPI", - srcs = MLIR_PYTHON_BINDINGS_SOURCES, - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIAsyncHeaders", - ":CAPIDebugHeaders", - ":CAPIGPUHeaders", - ":CAPIIRHeaders", - ":CAPIRegistrationHeaders", - ":MLIRBindingsPythonHeaders", - "//llvm:Support", - "@pybind11", - "@python_runtime//:headers", - ], -) - -# Target that bundles together the CAPI objects needed for -# MLIRBindingsPythonCoreNoCAPI. -cc_library( - name = "MLIRBindingsPythonCAPIObjects", - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIAsyncObjects", - ":CAPIDebugObjects", - ":CAPIGPUObjects", - ":CAPIIRObjects", - ":CAPIInterfacesObjects", - ":CAPIRegistrationObjects", - ], -) - -# Dynamic library with the MLIR Python extension. -cc_binary( - name = "_mlir.so", - srcs = ["lib/Bindings/Python/MainModule.cpp"], - # These flags are needed for pybind11 to work. - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - linkshared = 1, - linkstatic = 0, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":MLIRBindingsPythonCore", - ":MLIRBindingsPythonHeadersAndDeps", - ], -) - -cc_binary( - name = "_mlirDialectsLinalg.so", - srcs = ["lib/Bindings/Python/DialectLinalg.cpp"], - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - linkshared = 1, - linkstatic = 0, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIIR", - ":CAPILinalg", - ":CAPIRegistration", - ":MLIRBindingsPythonHeadersAndDeps", - ], -) - -cc_binary( - name = "_mlirDialectsQuant.so", - srcs = ["lib/Bindings/Python/DialectQuant.cpp"], - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - linkshared = 1, - linkstatic = 0, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIIR", - ":CAPIQuant", - ":CAPIRegistration", - ":MLIRBindingsPythonHeadersAndDeps", - ], -) - -cc_binary( - name = "_mlirDialectsSparseTensor.so", - srcs = ["lib/Bindings/Python/DialectSparseTensor.cpp"], - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - linkshared = 1, - linkstatic = 0, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIIR", - ":CAPIRegistration", - ":CAPISparseTensor", - ":MLIRBindingsPythonHeadersAndDeps", - ], -) - -# Dynamic library with the MLIR Conversions Python extension. -cc_binary( - name = "_mlirConversions.so", - srcs = ["lib/Bindings/Python/Conversions/Conversions.cpp"], - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - linkshared = 1, - linkstatic = 0, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIConversion", - ":MLIRBindingsPythonHeadersAndDeps", - "@pybind11", - "@python_runtime//:headers", - ], -) - -# Dynamic library with the MLIR Conversions Python extension. -cc_binary( - name = "_mlirExecutionEngine.so", - srcs = ["lib/Bindings/Python/ExecutionEngineModule.cpp"], - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - linkshared = 1, - linkstatic = 0, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPIExecutionEngine", - ":MLIRBindingsPythonHeadersAndDeps", - "@pybind11", - "@python_runtime//:headers", - ], -) - -# Dynamic library with the MLIR Transforms Python extension. -cc_binary( - name = "_mlirTransforms.so", - srcs = ["lib/Bindings/Python/Transforms/Transforms.cpp"], - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - linkshared = 1, - linkstatic = 0, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPITransforms", - ":MLIRBindingsPythonHeadersAndDeps", - "@pybind11", - "@python_runtime//:headers", - ], -) - -# Dynamic library with the MLIR Linalg dialect+passes Python extension. -cc_binary( - name = "_mlirLinalgPasses.so", - srcs = ["lib/Bindings/Python/LinalgPasses.cpp"], - copts = PYBIND11_COPTS, - features = PYBIND11_FEATURES, - linkshared = 1, - linkstatic = 0, - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":CAPILinalg", - ":MLIRBindingsPythonHeadersAndDeps", - "@pybind11", - "@python_runtime//:headers", - ], -) - -##---------------------------------------------------------------------------## - -td_library( - name = "OpBaseTdFiles", - srcs = [ - "include/mlir/IR/EnumAttr.td", - "include/mlir/IR/OpAsmInterface.td", - "include/mlir/IR/OpBase.td", - "include/mlir/IR/RegionKindInterface.td", - "include/mlir/IR/SymbolInterfaces.td", - "include/mlir/IR/TensorEncoding.td", - ], - includes = ["include"], -) - -td_library( - name = "CallInterfacesTdFiles", - srcs = ["include/mlir/Interfaces/CallInterfaces.td"], - includes = ["include"], - deps = [":OpBaseTdFiles"], -) - -td_library( - name = "CastInterfacesTdFiles", - srcs = ["include/mlir/Interfaces/CastInterfaces.td"], - includes = ["include"], - deps = [":OpBaseTdFiles"], -) - -td_library( - name = "ControlFlowInterfacesTdFiles", - srcs = ["include/mlir/Interfaces/ControlFlowInterfaces.td"], - includes = ["include"], - deps = [":OpBaseTdFiles"], -) - -td_library( - name = "CopyOpInterfaceTdFiles", - srcs = ["include/mlir/Interfaces/CopyOpInterface.td"], - includes = ["include"], - deps = [":OpBaseTdFiles"], -) - -td_library( - name = "DerivedAttributeOpInterfaceTdFiles", - srcs = ["include/mlir/Interfaces/DerivedAttributeOpInterface.td"], - includes = ["include"], - deps = [":OpBaseTdFiles"], -) - -td_library( - name = "InferTypeOpInterfaceTdFiles", - srcs = ["include/mlir/Interfaces/InferTypeOpInterface.td"], - includes = ["include"], - deps = [":OpBaseTdFiles"], -) - -td_library( - name = "LoopLikeInterfaceTdFiles", - srcs = ["include/mlir/Interfaces/LoopLikeInterface.td"], - includes = ["include"], - deps = [":OpBaseTdFiles"], -) - -td_library( - name = "SideEffectInterfacesTdFiles", - srcs = [ - "include/mlir/Interfaces/SideEffectInterfaceBase.td", - "include/mlir/Interfaces/SideEffectInterfaces.td", - ], - includes = ["include"], - deps = [":OpBaseTdFiles"], -) - -alias( - name = "SideEffectTdFiles", - actual = ":SideEffectInterfacesTdFiles", -) - -td_library( - name = "TilingInterfaceTdFiles", - srcs = ["include/mlir/Interfaces/TilingInterface.td"], - includes = ["include"], - deps = [":OpBaseTdFiles"], -) - -td_library( - name = "VectorInterfacesTdFiles", - srcs = ["include/mlir/Interfaces/VectorInterfaces.td"], - includes = ["include"], - deps = [":OpBaseTdFiles"], -) - -td_library( - name = "ViewLikeInterfaceTdFiles", - srcs = ["include/mlir/Interfaces/ViewLikeInterface.td"], - includes = ["include"], - deps = [":OpBaseTdFiles"], -) - -td_library( - name = "ReducerTdFiles", - srcs = ["include/mlir/Reducer/Passes.td"], - includes = ["include"], - deps = [":OpBaseTdFiles"], -) - -##---------------------------------------------------------------------------## -# Affine dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "PassBaseTdFiles", - srcs = ["include/mlir/Pass/PassBase.td"], - includes = ["include"], -) - -td_library( - name = "RewritePassBaseTdFiles", - srcs = ["include/mlir/Rewrite/PassUtil.td"], - includes = ["include"], -) - -td_library( - name = "AffineOpsTdFiles", - srcs = [ - "include/mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.td", - "include/mlir/Dialect/Affine/IR/AffineOps.td", - ], - includes = ["include"], - deps = [ - ":ArithmeticOpsTdFiles", - ":LoopLikeInterfaceTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ":StdOpsTdFiles", - ], -) - -gentbl_cc_library( - name = "AffineOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/Affine/IR/AffineOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/Affine/IR/AffineOps.cpp.inc", - ), - ( - [ - "-gen-dialect-decls", - "-dialect=affine", - ], - "include/mlir/Dialect/Affine/IR/AffineOpsDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=affine", - ], - "include/mlir/Dialect/Affine/IR/AffineOpsDialect.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Affine/IR/AffineOps.td", - deps = [":AffineOpsTdFiles"], -) - -gentbl_cc_library( - name = "AffineMemoryOpInterfacesIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.td", - deps = [":AffineOpsTdFiles"], -) - -##---------------------------------------------------------------------------## -# EmitC dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "EmitCTdFiles", - srcs = [ - "include/mlir/Dialect/EmitC/IR/EmitC.td", - "include/mlir/Dialect/EmitC/IR/EmitCAttributes.td", - "include/mlir/Dialect/EmitC/IR/EmitCBase.td", - "include/mlir/Dialect/EmitC/IR/EmitCTypes.td", - ], - includes = ["include"], - deps = [ - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "EmitCAttributesIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["--gen-attrdef-decls"], - "include/mlir/Dialect/EmitC/IR/EmitCAttributes.h.inc", - ), - ( - ["--gen-attrdef-defs"], - "include/mlir/Dialect/EmitC/IR/EmitCAttributes.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/EmitC/IR/EmitCAttributes.td", - deps = [":EmitCTdFiles"], -) - -gentbl_cc_library( - name = "EmitCOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-dialect-decls"], - "include/mlir/Dialect/EmitC/IR/EmitCDialect.h.inc", - ), - ( - ["-gen-dialect-defs"], - "include/mlir/Dialect/EmitC/IR/EmitCDialect.cpp.inc", - ), - ( - ["-gen-op-decls"], - "include/mlir/Dialect/EmitC/IR/EmitC.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/EmitC/IR/EmitC.cpp.inc", - ), - ( - ["-gen-typedef-decls"], - "include/mlir/Dialect/EmitC/IR/EmitCTypes.h.inc", - ), - ( - ["-gen-typedef-defs"], - "include/mlir/Dialect/EmitC/IR/EmitCTypes.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/EmitC/IR/EmitC.td", - deps = [":EmitCTdFiles"], -) - -cc_library( - name = "TargetCpp", - srcs = glob([ - "lib/Target/Cpp/*.cpp", - "lib/Target/Cpp/*.h", - ]), - hdrs = glob(["include/mlir/Target/Cpp/*.h"]), - deps = [ - ":ArithmeticDialect", - ":EmitC", - ":IR", - ":MathDialect", - ":SCFDialect", - ":StandardOps", - ":Support", - ":Translation", - "//llvm:Support", - ], -) - -##---------------------------------------------------------------------------## -# Async dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "AsyncOpsTdFiles", - srcs = [ - "include/mlir/Dialect/Async/IR/AsyncDialect.td", - "include/mlir/Dialect/Async/IR/AsyncOps.td", - "include/mlir/Dialect/Async/IR/AsyncTypes.td", - ], - includes = ["include"], - deps = [ - ":ControlFlowInterfacesTdFiles", - ":InferTypeOpInterfaceTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "AsyncOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/Async/IR/AsyncOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/Async/IR/AsyncOps.cpp.inc", - ), - ( - ["-gen-dialect-decls"], - "include/mlir/Dialect/Async/IR/AsyncOpsDialect.h.inc", - ), - ( - ["-gen-dialect-defs"], - "include/mlir/Dialect/Async/IR/AsyncOpsDialect.cpp.inc", - ), - ( - ["-gen-typedef-decls"], - "include/mlir/Dialect/Async/IR/AsyncOpsTypes.h.inc", - ), - ( - ["-gen-typedef-defs"], - "include/mlir/Dialect/Async/IR/AsyncOpsTypes.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Async/IR/AsyncOps.td", - deps = [":AsyncOpsTdFiles"], -) - -gentbl_cc_library( - name = "AsyncPassIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-pass-decls", - "-name=Async", - ], - "include/mlir/Dialect/Async/Passes.h.inc", - ), - ( - [ - "-gen-pass-capi-header", - "--prefix=Async", - ], - "include/mlir/Dialect/Async/Passes.capi.h.inc", - ), - ( - [ - "-gen-pass-capi-impl", - "--prefix=Async", - ], - "include/mlir/Dialect/Async/Passes.capi.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Async/Passes.td", - deps = [":PassBaseTdFiles"], -) - -##---------------------------------------------------------------------------## -# ArmNeon dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "ArmNeonTdFiles", - srcs = ["include/mlir/Dialect/ArmNeon/ArmNeon.td"], - includes = ["include"], - deps = [ - ":LLVMOpsTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "ArmNeonIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-dialect-decls", - "-dialect=arm_neon", - ], - "include/mlir/Dialect/ArmNeon/ArmNeonDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=arm_neon", - ], - "include/mlir/Dialect/ArmNeon/ArmNeonDialect.cpp.inc", - ), - ( - ["-gen-op-decls"], - "include/mlir/Dialect/ArmNeon/ArmNeon.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/ArmNeon/ArmNeon.cpp.inc", - ), - ( - ["-gen-op-doc"], - "g3doc/Dialects/ArmNeon/ArmNeon.md", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/ArmNeon/ArmNeon.td", - deps = [":ArmNeonTdFiles"], -) - -cc_library( - name = "ArmNeon", - srcs = ["lib/Dialect/ArmNeon/IR/ArmNeonDialect.cpp"], - hdrs = ["include/mlir/Dialect/ArmNeon/ArmNeonDialect.h"], - includes = ["include"], - deps = [ - ":ArmNeonIncGen", - ":IR", - ":SideEffectInterfaces", - ":VectorOps", - "//llvm:Core", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "ArmNeonConversionIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-llvmir-conversions"], - "include/mlir/Dialect/ArmNeon/ArmNeonConversions.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/ArmNeon/ArmNeon.td", - deps = [":ArmNeonTdFiles"], -) - -cc_library( - name = "ArmNeon2dToIntr", - srcs = glob([ - "lib/Conversion/ArmNeon2dToIntr/*.cpp", - "lib/Conversion/ArmNeon2dToIntr/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/ArmNeon2dToIntr/*.h", - ]), - includes = ["include"], - deps = [ - ":ArmNeon", - ":ConversionPassIncGen", - ":IR", - ":MemRefDialect", - ":OpenACCDialect", - ":Pass", - ":SCFDialect", - ":StandardOps", - ":Support", - ":Transforms", - ":VectorOps", - ], -) - -##---------------------------------------------------------------------------## -# ArmSVE dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "ArmSVETdFiles", - srcs = [ - "include/mlir/Dialect/ArmSVE/ArmSVE.td", - ], - includes = ["include"], - deps = [ - ":ArithmeticOpsTdFiles", - ":LLVMOpsTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ":StdOpsTdFiles", - ], -) - -gentbl_cc_library( - name = "ArmSVEIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/ArmSVE/ArmSVE.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/ArmSVE/ArmSVE.cpp.inc", - ), - ( - ["-gen-typedef-decls"], - "include/mlir/Dialect/ArmSVE/ArmSVETypes.h.inc", - ), - ( - ["-gen-typedef-defs"], - "include/mlir/Dialect/ArmSVE/ArmSVETypes.cpp.inc", - ), - ( - [ - "-gen-dialect-decls", - "-dialect=arm_sve", - ], - "include/mlir/Dialect/ArmSVE/ArmSVEDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=arm_sve", - ], - "include/mlir/Dialect/ArmSVE/ArmSVEDialect.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/ArmSVE/ArmSVE.td", - deps = [":ArmSVETdFiles"], -) - -cc_library( - name = "ArmSVE", - srcs = ["lib/Dialect/ArmSVE/IR/ArmSVEDialect.cpp"], - hdrs = ["include/mlir/Dialect/ArmSVE/ArmSVEDialect.h"], - includes = ["include"], - deps = [ - ":ArmSVEIncGen", - ":IR", - ":LLVMDialect", - ":SideEffectInterfaces", - ":StandardOps", - ":VectorOps", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "ArmSVETransforms", - srcs = glob(["lib/Dialect/ArmSVE/Transforms/*.cpp"]), - hdrs = ["include/mlir/Dialect/ArmSVE/Transforms.h"], - includes = ["include"], - deps = [ - ":ArmSVE", - ":IR", - ":LLVMCommonConversion", - ":LLVMDialect", - ":Pass", - ":StandardOps", - ":TransformUtils", - "//llvm:Core", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "ArmSVEConversionIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-llvmir-conversions"], - "include/mlir/Dialect/ArmSVE/ArmSVEConversions.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/ArmSVE/ArmSVE.td", - deps = [":ArmSVETdFiles"], -) - -##---------------------------------------------------------------------------## -# AMX dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "AMXTdFiles", - srcs = ["include/mlir/Dialect/AMX/AMX.td"], - includes = ["include"], - deps = [ - ":LLVMOpsTdFiles", - ":SideEffectInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "AMXIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-dialect-decls", - "-dialect=amx", - ], - "include/mlir/Dialect/AMX/AMXDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=amx", - ], - "include/mlir/Dialect/AMX/AMXDialect.cpp.inc", - ), - ( - ["-gen-op-decls"], - "include/mlir/Dialect/AMX/AMX.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/AMX/AMX.cpp.inc", - ), - ( - ["-gen-op-doc"], - "g3doc/Dialects/AMX/AMX.md", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/AMX/AMX.td", - deps = [":AMXTdFiles"], -) - -cc_library( - name = "AMX", - srcs = ["lib/Dialect/AMX/IR/AMXDialect.cpp"], - hdrs = ["include/mlir/Dialect/AMX/AMXDialect.h"], - includes = ["include"], - deps = [ - ":AMXIncGen", - ":IR", - ":LLVMDialect", - ":SideEffectInterfaces", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "AMXTransforms", - srcs = glob(["lib/Dialect/AMX/Transforms/*.cpp"]), - hdrs = ["include/mlir/Dialect/AMX/Transforms.h"], - includes = ["include"], - deps = [ - ":AMX", - ":IR", - ":LLVMCommonConversion", - ":LLVMDialect", - ":StandardOps", - "//llvm:Core", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "AMXConversionIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-llvmir-conversions"], - "include/mlir/Dialect/AMX/AMXConversions.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/AMX/AMX.td", - deps = [":AMXTdFiles"], -) - -##---------------------------------------------------------------------------## -# X86Vector dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "X86VectorTdFiles", - srcs = ["include/mlir/Dialect/X86Vector/X86Vector.td"], - includes = ["include"], - deps = [ - ":InferTypeOpInterfaceTdFiles", - ":LLVMOpsTdFiles", - ":SideEffectInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "X86VectorIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-dialect-decls", - "-dialect=x86vector", - ], - "include/mlir/Dialect/X86Vector/X86VectorDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=x86vector", - ], - "include/mlir/Dialect/X86Vector/X86VectorDialect.cpp.inc", - ), - ( - ["-gen-op-decls"], - "include/mlir/Dialect/X86Vector/X86Vector.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/X86Vector/X86Vector.cpp.inc", - ), - ( - ["-gen-op-doc"], - "g3doc/Dialects/X86Vector/X86Vector.md", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/X86Vector/X86Vector.td", - deps = [":X86VectorTdFiles"], -) - -cc_library( - name = "X86Vector", - srcs = ["lib/Dialect/X86Vector/IR/X86VectorDialect.cpp"], - hdrs = ["include/mlir/Dialect/X86Vector/X86VectorDialect.h"], - includes = ["include"], - deps = [ - ":IR", - ":InferTypeOpInterface", - ":LLVMDialect", - ":SideEffectInterfaces", - ":X86VectorIncGen", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "X86VectorTransforms", - srcs = glob(["lib/Dialect/X86Vector/Transforms/*.cpp"]), - hdrs = ["include/mlir/Dialect/X86Vector/Transforms.h"], - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":IR", - ":LLVMCommonConversion", - ":LLVMDialect", - ":StandardOps", - ":VectorOps", - ":X86Vector", - "//llvm:Core", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "X86VectorConversionIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-llvmir-conversions"], - "include/mlir/Dialect/X86Vector/X86VectorConversions.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/X86Vector/X86Vector.td", - deps = [":X86VectorTdFiles"], -) - -##---------------------------------------------------------------------------## -# SCF dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "SCFTdFiles", - srcs = ["include/mlir/Dialect/SCF/SCFOps.td"], - includes = ["include"], - deps = [ - ":ControlFlowInterfacesTdFiles", - ":LoopLikeInterfaceTdFiles", - ":SideEffectInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "SCFIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/SCF/SCFOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/SCF/SCFOps.cpp.inc", - ), - ( - ["-gen-dialect-decls"], - "include/mlir/Dialect/SCF/SCFOpsDialect.h.inc", - ), - ( - ["-gen-dialect-defs"], - "include/mlir/Dialect/SCF/SCFOpsDialect.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/SCF/SCFOps.td", - deps = [":SCFTdFiles"], -) - -gentbl_cc_library( - name = "SCFPassIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-pass-decls", - "-name=SCF", - ], - "include/mlir/Dialect/SCF/Passes.h.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/SCF/Passes.td", - deps = [":PassBaseTdFiles"], -) - -cc_library( - name = "SCFTransforms", - srcs = glob([ - "lib/Dialect/SCF/Transforms/*.cpp", - "lib/Dialect/SCF/Transforms/*.h", - ]), - hdrs = [ - "include/mlir/Dialect/SCF/BufferizableOpInterfaceImpl.h", - "include/mlir/Dialect/SCF/Passes.h", - "include/mlir/Dialect/SCF/Transforms.h", - ], - includes = ["include"], - deps = [ - ":Affine", - ":AffineAnalysis", - ":Analysis", - ":ArithmeticDialect", - ":BufferizationDialect", - ":BufferizationTransforms", - ":DialectUtils", - ":IR", - ":MemRefDialect", - ":Pass", - ":SCFDialect", - ":SCFPassIncGen", - ":SCFUtils", - ":StandardOps", - ":Support", - ":TensorDialect", - ":Transforms", - "//llvm:Support", - ], -) - -##---------------------------------------------------------------------------## -# SparseTensor dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "SparseTensorTdFiles", - srcs = [ - "include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.td", - "include/mlir/Dialect/SparseTensor/IR/SparseTensorBase.td", - "include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td", - ], - includes = ["include"], - deps = [ - ":InferTypeOpInterfaceTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "SparseTensorAttrDefsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["--gen-attrdef-decls"], - "include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.h.inc", - ), - ( - ["--gen-attrdef-defs"], - "include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.td", - deps = [":SparseTensorTdFiles"], -) - -gentbl_cc_library( - name = "SparseTensorOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-dialect-decls", - "-dialect=sparse_tensor", - ], - "include/mlir/Dialect/SparseTensor/IR/SparseTensorOpsDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=sparse_tensor", - ], - "include/mlir/Dialect/SparseTensor/IR/SparseTensorOpsDialect.cpp.inc", - ), - ( - ["-gen-op-decls"], - "include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.cpp.inc", - ), - ( - ["-gen-op-doc"], - "g3doc/Dialects/SparseTensor/SparseTensor.md", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td", - deps = [":SparseTensorTdFiles"], -) - -gentbl_cc_library( - name = "SparseTensorPassIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-pass-decls", - "-name=SparseTensor", - ], - "include/mlir/Dialect/SparseTensor/Transforms/Passes.h.inc", - ), - ( - [ - "-gen-pass-capi-header", - "--prefix=SparseTensor", - ], - "include/mlir/Dialect/SparseTensor/Transforms/Passes.capi.h.inc", - ), - ( - [ - "-gen-pass-capi-impl", - "--prefix=SparseTensor", - ], - "include/mlir/Dialect/SparseTensor/Transforms/Passes.capi.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/SparseTensor/Transforms/Passes.td", - deps = [":PassBaseTdFiles"], -) - -cc_library( - name = "SparseTensor", - srcs = glob([ - "lib/Dialect/SparseTensor/IR/*.cpp", - ]), - hdrs = ["include/mlir/Dialect/SparseTensor/IR/SparseTensor.h"], - includes = ["include"], - deps = [ - ":IR", - ":SparseTensorAttrDefsIncGen", - ":SparseTensorOpsIncGen", - "//llvm:Support", - ], -) - -cc_library( - name = "SparseTensorUtils", - srcs = glob(["lib/Dialect/SparseTensor/Utils/*.cpp"]), - hdrs = glob(["include/mlir/Dialect/SparseTensor/Utils/*.h"]), - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":IR", - ":LinalgOps", - ":SparseTensor", - "//llvm:Support", - ], -) - -cc_library( - name = "SparseTensorTransforms", - srcs = glob([ - "lib/Dialect/SparseTensor/Transforms/*.cpp", - "lib/Dialect/SparseTensor/Transforms/*.h", - ]), - hdrs = [ - "include/mlir/Dialect/SparseTensor/Transforms/Passes.h", - "include/mlir/ExecutionEngine/SparseTensorUtils.h", - ], - includes = ["include"], - deps = [ - ":Affine", - ":ArithmeticDialect", - ":BufferizationDialect", - ":IR", - ":LLVMDialect", - ":LinalgOps", - ":LinalgTransforms", - ":MemRefDialect", - ":Pass", - ":SCFDialect", - ":SCFTransforms", - ":SCFUtils", - ":SparseTensor", - ":SparseTensorPassIncGen", - ":SparseTensorUtils", - ":StandardOps", - ":StandardOpsTransforms", - ":TensorDialect", - ":Transforms", - ":VectorOps", - "//llvm:Support", - ], -) - -cc_library( - name = "SparseTensorPipelines", - srcs = glob(["lib/Dialect/SparseTensor/Pipelines/*.cpp"]), - hdrs = ["include/mlir/Dialect/SparseTensor/Pipelines/Passes.h"], - includes = ["include"], - deps = [ - ":ArithmeticTransforms", - ":BufferizationTransforms", - ":ConversionPasses", - ":LinalgTransforms", - ":Pass", - ":SparseTensor", - ":SparseTensorTransforms", - ":StandardOpsTransforms", - ":TensorTransforms", - ], -) - -td_library( - name = "StdOpsTdFiles", - srcs = [ - "include/mlir/Dialect/StandardOps/IR/Ops.td", - ], - includes = ["include"], - deps = [ - ":CallInterfacesTdFiles", - ":CastInterfacesTdFiles", - ":ControlFlowInterfacesTdFiles", - ":InferTypeOpInterfaceTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ":VectorInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "StandardOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/StandardOps/IR/Ops.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/StandardOps/IR/Ops.cpp.inc", - ), - ( - ["-gen-dialect-decls"], - "include/mlir/Dialect/StandardOps/IR/OpsDialect.h.inc", - ), - ( - ["-gen-dialect-defs"], - "include/mlir/Dialect/StandardOps/IR/OpsDialect.cpp.inc", - ), - ( - ["-gen-enum-decls"], - "include/mlir/Dialect/StandardOps/IR/OpsEnums.h.inc", - ), - ( - ["-gen-enum-defs"], - "include/mlir/Dialect/StandardOps/IR/OpsEnums.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/StandardOps/IR/Ops.td", - deps = [":StdOpsTdFiles"], -) - -cc_library( - name = "Dialect", - srcs = glob([ - "lib/Dialect/*.cpp", - "lib/Dialect/*.h", - ]), - hdrs = glob([ - "include/mlir/Dialect/*.h", - ]), - includes = ["include"], - deps = [ - ":IR", - "//llvm:Support", - ], -) - -cc_library( - name = "DialectUtils", - srcs = glob([ - "lib/Dialect/Utils/*.cpp", - "lib/Dialect/Utils/*.h", - ]), - hdrs = glob([ - "include/mlir/Dialect/Utils/*.h", - ]), - includes = ["include"], - deps = [ - ":IR", - ":Support", - "//llvm:Support", - ], -) - -cc_library( - name = "Affine", - srcs = glob( - [ - "lib/Dialect/Affine/IR/*.cpp", - "lib/Dialect/Affine/IR/*.h", - ], - ) + ["include/mlir/Transforms/InliningUtils.h"], - hdrs = glob([ - "include/mlir/Dialect/Affine/IR/*.h", - ]), - includes = ["include"], - deps = [ - ":AffineMemoryOpInterfacesIncGen", - ":AffineOpsIncGen", - ":ArithmeticDialect", - ":IR", - ":LoopLikeInterface", - ":MemRefDialect", - ":SideEffectInterfaces", - ":StandardOps", - ":Support", - ":TensorDialect", - "//llvm:Support", - ], -) - -cc_library( - name = "EmitC", - srcs = glob([ - "lib/Dialect/EmitC/IR/*.cpp", - ]), - hdrs = glob([ - "include/mlir/Dialect/EmitC/IR/*.h", - ]), - includes = ["include"], - deps = [ - ":Dialect", - ":EmitCAttributesIncGen", - ":EmitCOpsIncGen", - ":IR", - ":SideEffectInterfaces", - "//llvm:Support", - ], -) - -cc_library( - name = "Async", - srcs = glob([ - "lib/Dialect/Async/IR/*.cpp", - ]), - hdrs = glob([ - "include/mlir/Dialect/Async/IR/*.h", - ]), - includes = ["include"], - deps = [ - ":AsyncOpsIncGen", - ":ControlFlowInterfaces", - ":Dialect", - ":IR", - ":InferTypeOpInterface", - ":SideEffectInterfaces", - ":StandardOps", - ":Support", - "//llvm:Support", - ], -) - -cc_library( - name = "AsyncTransforms", - srcs = glob([ - "lib/Dialect/Async/Transforms/*.cpp", - "lib/Dialect/Async/Transforms/*.h", - ]), - hdrs = [ - "include/mlir/Dialect/Async/Passes.h", - "include/mlir/Dialect/Async/Transforms.h", - ], - includes = ["include"], - deps = [ - ":Analysis", - ":ArithmeticDialect", - ":Async", - ":AsyncPassIncGen", - ":IR", - ":Pass", - ":SCFDialect", - ":SCFToStandard", - ":StandardOps", - ":Support", - ":TransformUtils", - ":Transforms", - ":TransformsPassIncGen", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "AffineAnalysis", - srcs = glob([ - "lib/Dialect/Affine/Analysis/*.cpp", - "lib/Dialect/Affine/Analysis/*.h", - ]), - hdrs = glob(["include/mlir/Dialect/Affine/Analysis/*.h"]), - includes = ["include"], - deps = [ - ":Affine", - ":Analysis", - ":ArithmeticDialect", - ":IR", - ":StandardOps", - ":Support", - "//llvm:Support", - ], -) - -cc_library( - name = "AffineUtils", - srcs = glob( - [ - "lib/Dialect/Affine/Utils/*.cpp", - "lib/Dialect/Affine/Utils/*.h", - ], - ), - hdrs = [ - "include/mlir/Dialect/Affine/LoopFusionUtils.h", - "include/mlir/Dialect/Affine/LoopUtils.h", - "include/mlir/Dialect/Affine/Utils.h", - ], - includes = ["include"], - deps = [ - ":Affine", - ":AffineAnalysis", - ":Analysis", - ":IR", - ":MemRefDialect", - ":SCFDialect", - ":Support", - ":TransformUtils", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "AffinePassIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-pass-decls", - "-name=Affine", - ], - "include/mlir/Dialect/Affine/Passes.h.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Affine/Passes.td", - deps = [":PassBaseTdFiles"], -) - -cc_library( - name = "AffineTransforms", - srcs = glob([ - "lib/Dialect/Affine/Transforms/*.cpp", - "lib/Dialect/Affine/Transforms/*.h", - ]), - hdrs = ["include/mlir/Dialect/Affine/Passes.h"], - includes = ["include"], - deps = [ - ":Affine", - ":AffineAnalysis", - ":AffinePassIncGen", - ":AffineUtils", - ":Analysis", - ":ArithmeticDialect", - ":IR", - ":MemRefDialect", - ":Pass", - ":SCFDialect", - ":SCFUtils", - ":StandardOps", - ":Support", - ":Transforms", - ":VectorOps", - ":VectorUtils", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "ConversionPassIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-pass-decls", - "-name=Conversion", - ], - "include/mlir/Conversion/Passes.h.inc", - ), - ( - [ - "-gen-pass-capi-header", - "--prefix=Conversion", - ], - "include/mlir/Conversion/Passes.capi.h.inc", - ), - ( - [ - "-gen-pass-capi-impl", - "--prefix=Conversion", - ], - "include/mlir/Conversion/Passes.capi.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Conversion/Passes.td", - deps = [":PassBaseTdFiles"], -) - -cc_library( - name = "ConversionPasses", - hdrs = ["include/mlir/Conversion/Passes.h"], - includes = ["include"], - deps = [ - ":AffineToStandard", - ":ArithmeticToLLVM", - ":ArithmeticToSPIRV", - ":ArmNeon2dToIntr", - ":AsyncToLLVM", - ":BufferizationToMemRef", - ":ComplexToLLVM", - ":ComplexToStandard", - ":ConversionPassIncGen", - ":GPUToGPURuntimeTransforms", - ":GPUToNVVMTransforms", - ":GPUToROCDLTransforms", - ":GPUToSPIRV", - ":GPUToVulkanTransforms", - ":LinalgToLLVM", - ":LinalgToSPIRV", - ":LinalgToStandard", - ":MathToLLVM", - ":MathToLibm", - ":MathToSPIRV", - ":MemRefToLLVM", - ":MemRefToSPIRV", - ":OpenACCToLLVM", - ":OpenACCToSCF", - ":OpenMPToLLVM", - ":PDLToPDLInterp", - ":ReconcileUnrealizedCasts", - ":SCFToGPUPass", - ":SCFToOpenMP", - ":SCFToSPIRV", - ":SCFToStandard", - ":SPIRVToLLVM", - ":ShapeToStandard", - ":StandardToLLVM", - ":StandardToSPIRV", - ":TosaToLinalg", - ":TosaToSCF", - ":TosaToStandard", - ":VectorToGPU", - ":VectorToLLVM", - ":VectorToROCDL", - ":VectorToSCF", - ":VectorToSPIRV", - ], -) - -cc_library( - name = "AsyncToLLVM", - srcs = glob([ - "lib/Conversion/AsyncToLLVM/*.cpp", - "lib/Conversion/AsyncToLLVM/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob(["include/mlir/Conversion/AsyncToLLVM/*.h"]), - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":Async", - ":ConversionPassIncGen", - ":IR", - ":LLVMCommonConversion", - ":LLVMDialect", - ":Pass", - ":StandardOps", - ":StandardOpsTransforms", - ":StandardToLLVM", - ":Support", - ":Transforms", - "//llvm:Support", - ], -) - -cc_library( - name = "AffineToStandard", - srcs = glob([ - "lib/Conversion/AffineToStandard/*.cpp", - "lib/Conversion/AffineToStandard/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob(["include/mlir/Conversion/AffineToStandard/*.h"]), - includes = ["include"], - deps = [ - ":Affine", - ":ArithmeticDialect", - ":ConversionPassIncGen", - ":IR", - ":MemRefDialect", - ":Pass", - ":SCFDialect", - ":StandardOps", - ":Support", - ":Transforms", - ":VectorOps", - ], -) - -alias( - name = "AffineToStandardTransforms", - actual = "AffineToStandard", -) - -# SDBM dialect only contains attribute components that can be constructed given -# a dialect object, so whenever it is used it must also be registered. Therefore -# we don't split out the registration library for it. -cc_library( - name = "SDBM", - srcs = glob([ - "lib/Dialect/SDBM/*.cpp", - "lib/Dialect/SDBM/*.h", - ]), - hdrs = glob([ - "include/mlir/Dialect/SDBM/*.h", - ]), - includes = ["include"], - deps = [ - ":IR", - ":Support", - "//llvm:Support", - ], -) - -cc_library( - name = "SCFDialect", - srcs = glob( - [ - "lib/Dialect/SCF/*.cpp", - "lib/Dialect/SCF/*.h", - ], - ), - hdrs = glob( - [ - "include/mlir/Dialect/SCF/*.h", - ], - exclude = [ - "include/mlir/Dialect/SCF/BufferizableOpInterfaceImpl.h", - "include/mlir/Dialect/SCF/Transforms.h", - ], - ), - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":BufferizationDialect", - ":ControlFlowInterfaces", - ":IR", - ":LoopLikeInterface", - ":Pass", - ":SCFIncGen", - ":SCFPassIncGen", - ":StandardOps", - ":Support", - "//llvm:Support", - ], -) - -cc_library( - name = "SCFUtils", - srcs = glob( - [ - "lib/Dialect/SCF/Utils/*.cpp", - ], - ), - hdrs = glob( - [ - "include/mlir/Dialect/SCF/Utils/*.h", - ], - ), - includes = ["include"], - deps = [ - ":Affine", - ":AffineAnalysis", - ":Analysis", - ":ArithmeticDialect", - ":DialectUtils", - ":IR", - ":SCFDialect", - ":StandardOps", - ":Support", - ":Transforms", - "//llvm:Support", - ], -) - -cc_library( - name = "LinalgInterfaces", - srcs = ["lib/Dialect/Linalg/IR/LinalgInterfaces.cpp"], - hdrs = ["include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h"], - includes = ["include"], - deps = [ - ":Affine", - ":ArithmeticDialect", - ":DialectUtils", - ":IR", - ":InferTypeOpInterface", - ":LinalgInterfacesIncGen", - ":LinalgStructuredOpsIncGen", - ":MemRefDialect", - ":TensorDialect", - ":ViewLikeInterface", - "//llvm:Support", - ], -) - -cc_library( - name = "DataLayoutInterfaces", - srcs = ["lib/Interfaces/DataLayoutInterfaces.cpp"], - hdrs = ["include/mlir/Interfaces/DataLayoutInterfaces.h"], - includes = ["include"], - deps = [ - ":DataLayoutInterfacesIncGen", - ":IR", - "//llvm:Support", - ], -) - -cc_library( - name = "LoopLikeInterface", - srcs = ["lib/Interfaces/LoopLikeInterface.cpp"], - hdrs = ["include/mlir/Interfaces/LoopLikeInterface.h"], - includes = ["include"], - deps = [ - ":IR", - ":LoopLikeInterfaceIncGen", - "//llvm:Support", - ], -) - -cc_library( - name = "VectorInterfaces", - srcs = ["lib/Interfaces/VectorInterfaces.cpp"], - hdrs = ["include/mlir/Interfaces/VectorInterfaces.h"], - includes = ["include"], - deps = [ - ":IR", - ":VectorInterfacesIncGen", - ], -) - -cc_library( - name = "ViewLikeInterface", - srcs = ["lib/Interfaces/ViewLikeInterface.cpp"], - hdrs = ["include/mlir/Interfaces/ViewLikeInterface.h"], - includes = ["include"], - deps = [ - ":DialectUtils", - ":IR", - ":ViewLikeInterfaceIncGen", - ], -) - -cc_library( - name = "CopyOpInterface", - srcs = ["lib/Interfaces/CopyOpInterface.cpp"], - hdrs = ["include/mlir/Interfaces/CopyOpInterface.h"], - includes = ["include"], - deps = [ - ":CopyOpInterfaceIncGen", - ":IR", - ], -) - -td_library( - name = "ShapeOpsTdFiles", - srcs = [ - "include/mlir/Dialect/Shape/IR/ShapeBase.td", - "include/mlir/Dialect/Shape/IR/ShapeOps.td", - ], - includes = ["include"], - deps = [ - ":ControlFlowInterfacesTdFiles", - ":InferTypeOpInterfaceTdFiles", - ":SideEffectInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "ShapeOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/Shape/IR/ShapeOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/Shape/IR/ShapeOps.cpp.inc", - ), - ( - ["-gen-dialect-decls"], - "include/mlir/Dialect/Shape/IR/ShapeOpsDialect.h.inc", - ), - ( - ["-gen-dialect-defs"], - "include/mlir/Dialect/Shape/IR/ShapeOpsDialect.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Shape/IR/ShapeOps.td", - deps = [":ShapeOpsTdFiles"], -) - -gentbl_cc_library( - name = "MLIRShapeCanonicalizationIncGen", - strip_include_prefix = "include/mlir/Dialect/Shape/IR", - tbl_outs = [ - ( - ["-gen-rewriters"], - "include/mlir/Dialect/Shape/IR/ShapeCanonicalization.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "lib/Dialect/Shape/IR/ShapeCanonicalization.td", - deps = [ - ":ShapeOpsTdFiles", - ":StdOpsTdFiles", - ":TensorOpsTdFiles", - ], -) - -cc_library( - name = "Shape", - srcs = glob(["lib/Dialect/Shape/IR/*.cpp"]), - hdrs = ["include/mlir/Dialect/Shape/IR/Shape.h"], - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":ControlFlowInterfaces", - ":Dialect", - ":IR", - ":InferTypeOpInterface", - ":MLIRShapeCanonicalizationIncGen", - ":ShapeOpsIncGen", - ":SideEffectInterfaces", - ":TensorDialect", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "ShapeToStandardGen", - strip_include_prefix = "lib/Conversion/ShapeToStandard", - tbl_outs = [ - ( - ["-gen-rewriters"], - "lib/Conversion/ShapeToStandard/ShapeToStandard.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "lib/Conversion/ShapeToStandard/ShapeToStandard.td", - deps = [":ShapeOpsTdFiles"], -) - -cc_library( - name = "ShapeToStandard", - srcs = glob([ - "lib/Conversion/ShapeToStandard/*.cpp", - "lib/Conversion/ShapeToStandard/*.h", - ]) + [":ConversionPassDetail"], - hdrs = ["include/mlir/Conversion/ShapeToStandard/ShapeToStandard.h"], - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":ConversionPassIncGen", - ":IR", - ":MemRefDialect", - ":Pass", - ":SCFDialect", - ":Shape", - ":ShapeToStandardGen", - ":StandardOps", - ":Support", - ":TensorDialect", - ":Transforms", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "ShapeTransformsPassIncGen", - strip_include_prefix = "include", - tbl_outs = [( - [ - "-gen-pass-decls", - "-name=Shape", - ], - "include/mlir/Dialect/Shape/Transforms/Passes.h.inc", - )], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Shape/Transforms/Passes.td", - deps = [":PassBaseTdFiles"], -) - -cc_library( - name = "ShapeTransforms", - srcs = glob([ - "lib/Dialect/Shape/Transforms/*.cpp", - "lib/Dialect/Shape/Transforms/*.h", - ]), - hdrs = ["include/mlir/Dialect/Shape/Transforms/Passes.h"], - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":BufferizationDialect", - ":BufferizationTransforms", - ":IR", - ":MemRefDialect", - ":Pass", - ":Shape", - ":ShapeTransformsPassIncGen", - ":StandardOps", - ":Transforms", - ], -) - -cc_library( - name = "StandardOps", - srcs = glob( - [ - "lib/Dialect/StandardOps/IR/*.cpp", - "lib/Dialect/StandardOps/IR/*.h", - "lib/Dialect/StandardOps/Utils/*.cpp", - ], - ), - hdrs = glob([ - "include/mlir/Dialect/StandardOps/IR/*.h", - "include/mlir/Dialect/StandardOps/Utils/*.h", - ]) + ["include/mlir/Transforms/InliningUtils.h"], - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":CallOpInterfaces", - ":CastOpInterfaces", - ":CommonFolders", - ":ControlFlowInterfaces", - ":IR", - ":InferTypeOpInterface", - ":SideEffectInterfaces", - ":StandardOpsIncGen", - ":Support", - ":VectorInterfaces", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "StandardOpsTransformsPassIncGen", - strip_include_prefix = "include", - tbl_outs = [( - [ - "-gen-pass-decls", - "-name=Standard", - ], - "include/mlir/Dialect/StandardOps/Transforms/Passes.h.inc", - )], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/StandardOps/Transforms/Passes.td", - deps = [":PassBaseTdFiles"], -) - -cc_library( - name = "StandardOpsTransforms", - srcs = glob([ - "lib/Dialect/StandardOps/Transforms/*.cpp", - "lib/Dialect/StandardOps/Transforms/*.h", - ]), - hdrs = glob(["include/mlir/Dialect/StandardOps/Transforms/*.h"]), - includes = ["include"], - deps = [ - ":Affine", - ":ArithmeticDialect", - ":ArithmeticTransforms", - ":BufferizationDialect", - ":BufferizationTransforms", - ":IR", - ":MemRefDialect", # TODO: Remove dependency on MemRef dialect - ":Pass", - ":SCFDialect", - ":StandardOps", - ":StandardOpsTransformsPassIncGen", - ":Support", - ":TensorDialect", - ":Transforms", - "//llvm:Support", - ], -) - -cc_library( - name = "VectorOps", - srcs = glob( - [ - "lib/Dialect/Vector/IR/*.cpp", - ], - ), - hdrs = glob([ - "include/mlir/Dialect/Vector/IR/*.h", - ]), - includes = ["include"], - deps = [ - ":Affine", - ":AffineAnalysis", - ":ArithmeticDialect", - ":DialectUtils", - ":IR", - ":MemRefDialect", - ":SideEffectInterfaces", - ":StandardOps", - ":Support", - ":TensorDialect", - ":VectorInterfaces", - ":VectorOpsIncGen", - ":ViewLikeInterface", - "//llvm:Support", - ], -) - -cc_library( - name = "VectorTransforms", - srcs = glob( - [ - "lib/Dialect/Vector/Transforms/*.cpp", - ], - ), - hdrs = glob([ - "include/mlir/Dialect/Vector/Transforms/*.h", - ]), - includes = ["include"], - deps = [ - ":Affine", - ":AffineAnalysis", - ":Analysis", - ":ArithmeticDialect", - ":BufferizationDialect", - ":DialectUtils", - ":IR", - ":LinalgOps", - ":MemRefDialect", - ":SCFDialect", - ":StandardOps", - ":Support", - ":TensorDialect", - ":VectorInterfaces", - ":VectorOps", - ":VectorUtils", - "//llvm:Support", - ], -) - -cc_library( - name = "VectorUtils", - srcs = glob( - [ - "lib/Dialect/Vector/Utils/*.cpp", - ], - ), - hdrs = glob([ - "include/mlir/Dialect/Vector/Utils/*.h", - ]), - includes = ["include"], - deps = [ - ":Affine", - ":AffineAnalysis", - ":ArithmeticDialect", - ":DialectUtils", - ":IR", - ":MemRefDialect", - ":StandardOps", - ":Support", - ":TensorDialect", - ":VectorInterfaces", - ":VectorOps", - "//llvm:Support", - ], -) - -cc_library( - name = "Support", - srcs = glob( - [ - "lib/Support/*.cpp", - "lib/Support/*.h", - ], - exclude = [ - # TODO(jpienaar): Move this out, else Support depends on Analysis/ - "lib/Support/MlirOptMain.cpp", - ], - ), - hdrs = glob( - ["include/mlir/Support/*.h"], - exclude = ["include/mlir/Support/MlirOptMain.h"], - ), - includes = ["include"], - deps = ["//llvm:Support"], -) - -cc_library( - name = "MlirLspServerLib", - srcs = glob( - [ - "lib/Tools/mlir-lsp-server/*.cpp", - "lib/Tools/mlir-lsp-server/*.h", - "lib/Tools/mlir-lsp-server/lsp/*.cpp", - "lib/Tools/mlir-lsp-server/lsp/*.h", - ], - ), - hdrs = glob( - ["include/mlir/Tools/mlir-lsp-server/*.h"], - ), - includes = ["include"], - deps = [ - ":IR", - ":Parser", - ":Support", - "//llvm:Support", - ], -) - -cc_library( - name = "ParserTokenKinds", - # strip_include_prefix does not apply to textual_hdrs. - hdrs = ["lib/Parser/TokenKinds.def"], - strip_include_prefix = "lib/Parser", - textual_hdrs = ["lib/Parser/TokenKinds.def"], -) - -cc_library( - name = "Parser", - srcs = glob([ - "lib/Parser/*.cpp", - "lib/Parser/*.h", - ]), - hdrs = glob([ - "include/mlir/Parser/*.h", - ]) + [ - "include/mlir/Parser.h", - ], - includes = ["include"], - deps = [ - ":IR", - ":ParserTokenKinds", - ":Support", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "LLVMDialectInterfaceIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/Dialect/LLVMIR/LLVMOpsInterfaces.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/Dialect/LLVMIR/LLVMOpsInterfaces.cpp.inc", - ), - ( - ["-gen-type-interface-decls"], - "include/mlir/Dialect/LLVMIR/LLVMTypeInterfaces.h.inc", - ), - ( - ["-gen-type-interface-defs"], - "include/mlir/Dialect/LLVMIR/LLVMTypeInterfaces.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/LLVMIR/LLVMOpsInterfaces.td", - deps = [":LLVMOpsTdFiles"], -) - -gentbl_cc_library( - name = "LLVMDialectAttributesIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["--gen-attrdef-decls"], - "include/mlir/Dialect/LLVMIR/LLVMOpsAttrDefs.h.inc", - ), - ( - ["--gen-attrdef-defs"], - "include/mlir/Dialect/LLVMIR/LLVMOpsAttrDefs.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td", - deps = [":LLVMOpsTdFiles"], -) - -cc_library( - name = "LLVMDialect", - srcs = glob( - [ - "lib/Dialect/LLVMIR/IR/*.cpp", - "lib/Dialect/LLVMIR/IR/*.h", - ], - exclude = [ - "lib/Dialect/LLVMIR/IR/*AMX*.cpp", - "lib/Dialect/LLVMIR/IR/*AMX*.h", - "lib/Dialect/LLVMIR/IR/*ArmSVE*.cpp", - "lib/Dialect/LLVMIR/IR/*ArmSVE*.h", - "lib/Dialect/LLVMIR/IR/NVVM*.cpp", - "lib/Dialect/LLVMIR/IR/NVVM*.h", - "lib/Dialect/LLVMIR/IR/ROCDL*.cpp", - "lib/Dialect/LLVMIR/IR/ROCDL*.h", - "lib/Dialect/LLVMIR/IR/*X86Vector*.cpp", - "lib/Dialect/LLVMIR/IR/*X86Vector*.h", - ], - ), - hdrs = glob( - ["include/mlir/Dialect/LLVMIR/*.h"], - exclude = [ - "include/mlir/Dialect/LLVMIR/*AMX*.h", - "include/mlir/Dialect/LLVMIR/*ArmSVE*.h", - "include/mlir/Dialect/LLVMIR/NVVM*.h", - "include/mlir/Dialect/LLVMIR/ROCDL*.h", - "include/mlir/Dialect/LLVMIR/*X86Vector*.h", - ], - ), - includes = ["include"], - deps = [ - ":ControlFlowInterfaces", - ":DataLayoutInterfaces", - ":IR", - ":InferTypeOpInterface", - ":LLVMDialectAttributesIncGen", - ":LLVMDialectInterfaceIncGen", - ":LLVMOpsIncGen", - ":SideEffectInterfaces", - ":Support", - "//llvm:AsmParser", - "//llvm:BitReader", - "//llvm:BitWriter", - "//llvm:Core", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "LLVMPassIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-pass-decls", - "-name=LLVM", - ], - "include/mlir/Dialect/LLVMIR/Transforms/Passes.h.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/LLVMIR/Transforms/Passes.td", - deps = [":PassBaseTdFiles"], -) - -cc_library( - name = "LLVMIRTransforms", - srcs = glob([ - "lib/Dialect/LLVMIR/Transforms/*.cpp", - "lib/Dialect/LLVMIR/Transforms/*.h", - ]), - hdrs = glob(["include/mlir/Dialect/LLVMIR/Transforms/*.h"]), - includes = ["include"], - deps = [ - ":IR", - ":LLVMDialect", - ":LLVMPassIncGen", - ":Pass", - ], -) - -td_library( - name = "GPUOpsTdFiles", - srcs = [ - "include/mlir/Dialect/GPU/GPUBase.td", - "include/mlir/Dialect/GPU/GPUOps.td", - ], - includes = ["include"], - deps = [ - ":DLTIDialectTdFiles", - ":DataLayoutInterfacesTdFiles", - ":FunctionInterfacesTdFiles", - ":LLVMOpsTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "ParallelLoopMapperAttrGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-struct-attr-decls"], - "include/mlir/Dialect/GPU/ParallelLoopMapperAttr.h.inc", - ), - ( - ["-gen-struct-attr-defs"], - "include/mlir/Dialect/GPU/ParallelLoopMapperAttr.cpp.inc", - ), - ( - ["-gen-enum-decls"], - "include/mlir/Dialect/GPU/ParallelLoopMapperEnums.h.inc", - ), - ( - ["-gen-enum-defs"], - "include/mlir/Dialect/GPU/ParallelLoopMapperEnums.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/GPU/ParallelLoopMapperAttr.td", - deps = [":GPUOpsTdFiles"], -) - -gentbl_cc_library( - name = "GPUBaseIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/Dialect/GPU/GPUOpInterfaces.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/Dialect/GPU/GPUOpInterfaces.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/GPU/GPUBase.td", - deps = [":GPUOpsTdFiles"], -) - -gentbl_cc_library( - name = "GPUOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-dialect-decls", - "-dialect=gpu", - ], - "include/mlir/Dialect/GPU/GPUOpsDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=gpu", - ], - "include/mlir/Dialect/GPU/GPUOpsDialect.cpp.inc", - ), - ( - ["-gen-op-decls"], - "include/mlir/Dialect/GPU/GPUOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/GPU/GPUOps.cpp.inc", - ), - ( - ["-gen-enum-decls"], - "include/mlir/Dialect/GPU/GPUOpsEnums.h.inc", - ), - ( - ["-gen-enum-defs"], - "include/mlir/Dialect/GPU/GPUOpsEnums.cpp.inc", - ), - ( - ["-gen-attrdef-decls"], - "include/mlir/Dialect/GPU/GPUOpsAttributes.h.inc", - ), - ( - ["-gen-attrdef-defs"], - "include/mlir/Dialect/GPU/GPUOpsAttributes.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/GPU/GPUOps.td", - deps = [ - ":DLTIDialectTdFiles", - ":GPUOpsTdFiles", - ], -) - -cc_library( - name = "GPUDialect", - srcs = glob( - [ - "lib/Dialect/GPU/IR/*.cpp", - "lib/Dialect/GPU/IR/*.h", - ], - ), - hdrs = ["include/mlir/Dialect/GPU/GPUDialect.h"], - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":DLTIDialect", - ":GPUBaseIncGen", - ":GPUOpsIncGen", - ":IR", - ":InferTypeOpInterface", - ":LLVMDialect", - ":MemRefDialect", - ":SideEffectInterfaces", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "GPUPassIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-pass-decls", - "-name=GPU", - ], - "include/mlir/Dialect/GPU/Passes.h.inc", - ), - ( - [ - "-gen-pass-capi-header", - "--prefix=GPU", - ], - "include/mlir/Dialect/GPU/Passes.capi.h.inc", - ), - ( - [ - "-gen-pass-capi-impl", - "--prefix=GPU", - ], - "include/mlir/Dialect/GPU/Passes.capi.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/GPU/Passes.td", - deps = [":PassBaseTdFiles"], -) - -cc_library( - name = "GPUTransforms", - srcs = glob( - [ - "lib/Dialect/GPU/Transforms/*.cpp", - "lib/Dialect/GPU/Transforms/*.h", - ], - ), - hdrs = [ - "include/mlir/Dialect/GPU/MemoryPromotion.h", - "include/mlir/Dialect/GPU/ParallelLoopMapper.h", - "include/mlir/Dialect/GPU/Passes.h", - "include/mlir/Dialect/GPU/Utils.h", - ], - defines = if_cuda_available(["MLIR_GPU_TO_CUBIN_PASS_ENABLE"]), - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":Async", - ":DLTIDialect", - ":AffineUtils", - ":GPUDialect", - ":GPUPassIncGen", - ":MemRefDialect", - ":IR", - ":ParallelLoopMapperAttrGen", - ":Parser", - ":Pass", - ":ROCDLToLLVMIRTranslation", - ":SCFDialect", - ":StandardOps", - ":Support", - ":Transforms", - ":ToLLVMIRTranslation", - ":LLVMToLLVMIRTranslation", - "//llvm:Core", - "//llvm:MC", - "//llvm:Support", - "//llvm:Target", - ] + if_cuda_available([ - # Dependencies for SerializeToCubin.cpp with - # -DMLIR_GPU_TO_CUBIN_PASS_ENABLE - ":NVVMToLLVMIRTranslation", - "//llvm:NVPTXCodeGen", - "@cuda//:cuda_headers", - "@cuda//:libcuda", - ]), -) - -td_library( - name = "LLVMOpsTdFiles", - srcs = [ - "include/mlir/Dialect/LLVMIR/LLVMOpBase.td", - "include/mlir/Dialect/LLVMIR/LLVMOps.td", - "include/mlir/Dialect/LLVMIR/LLVMOpsInterfaces.td", - ], - includes = ["include"], - deps = [ - ":ControlFlowInterfacesTdFiles", - ":FunctionInterfacesTdFiles", - ":InferTypeOpInterfaceTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ], -) - -cc_library( - name = "GPUCommonTransforms", - srcs = [ - "lib/Conversion/GPUCommon/GPUOpsLowering.cpp", - ], - hdrs = [ - "lib/Conversion/GPUCommon/GPUOpsLowering.h", - "lib/Conversion/GPUCommon/IndexIntrinsicsOpLowering.h", - "lib/Conversion/GPUCommon/OpToFuncCallLowering.h", - ], - deps = [ - ":GPUDialect", - ":IR", - ":LLVMCommonConversion", - ":LLVMDialect", - ":StandardOps", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "GPUToNVVMGen", - strip_include_prefix = "lib/Conversion/GPUToNVVM", - tbl_outs = [ - ( - ["-gen-rewriters"], - "lib/Conversion/GPUToNVVM/GPUToNVVM.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "lib/Conversion/GPUToNVVM/GPUToNVVM.td", - deps = [ - ":GPUOpsTdFiles", - ":NVVMOpsTdFiles", - ], -) - -cc_library( - name = "GPUToNVVMTransforms", - srcs = glob([ - "lib/Conversion/GPUToNVVM/*.cpp", - "lib/Conversion/GPUToNVVM/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/GPUToNVVM/*.h", - ]), - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":ArithmeticToLLVM", - ":ConversionPassIncGen", - ":GPUCommonTransforms", - ":GPUDialect", - ":GPUToNVVMGen", - ":GPUTransforms", - ":IR", - ":LLVMCommonConversion", - ":LLVMDialect", - ":MathDialect", - ":MemRefDialect", - ":MemRefToLLVM", - ":NVVMDialect", - ":Pass", - ":StandardToLLVM", - ":Transforms", - "//llvm:Support", - ], -) - -cc_library( - name = "VectorToROCDL", - srcs = [ - "lib/Conversion/VectorToROCDL/VectorToROCDL.cpp", - ":ConversionPassDetail", - ], - hdrs = ["include/mlir/Conversion/VectorToROCDL/VectorToROCDL.h"], - includes = ["include"], - deps = [ - ":ConversionPassIncGen", - ":GPUDialect", - ":LLVMCommonConversion", - ":LLVMDialect", - ":MemRefToLLVM", - ":Pass", - ":ROCDLDialect", - ":StandardOps", - ":StandardToLLVM", - ":Transforms", - ":VectorOps", - ], -) - -cc_library( - name = "VectorToSPIRV", - srcs = glob([ - "lib/Conversion/VectorToSPIRV/*.cpp", - "lib/Conversion/VectorToSPIRV/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/VectorToSPIRV/*.h", - ]), - includes = ["include"], - deps = [ - ":ConversionPassIncGen", - ":Pass", - ":SPIRVConversion", - ":SPIRVDialect", - ":Transforms", - ":VectorOps", - ], -) - -gentbl_cc_library( - name = "GPUToROCDLTGen", - strip_include_prefix = "lib/Conversion/GPUToROCDL", - tbl_outs = [ - ( - ["-gen-rewriters"], - "lib/Conversion/GPUToROCDL/GPUToROCDL.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "lib/Conversion/GPUToROCDL/GPUToROCDL.td", - deps = [ - ":GPUOpsTdFiles", - ":ROCDLOpsTdFiles", - ], -) - -cc_library( - name = "GPUToROCDLTransforms", - srcs = [ - "lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp", - ":ConversionPassDetail", - ], - hdrs = ["include/mlir/Conversion/GPUToROCDL/GPUToROCDLPass.h"], - includes = ["include"], - deps = [ - ":ArithmeticToLLVM", - ":ConversionPassIncGen", - ":GPUCommonTransforms", - ":GPUDialect", - ":GPUToROCDLTGen", - ":GPUTransforms", - ":LLVMCommonConversion", - ":MathDialect", - ":MemRefToLLVM", - ":Pass", - ":ROCDLDialect", - ":StandardToLLVM", - ":Transforms", - ":VectorOps", - ":VectorToLLVM", - ":VectorToROCDL", - ":VectorToSCF", - "//llvm:Support", - ], -) - -cc_library( - name = "GPUToVulkanTransforms", - srcs = [ - "lib/Conversion/GPUToVulkan/ConvertGPULaunchFuncToVulkanLaunchFunc.cpp", - "lib/Conversion/GPUToVulkan/ConvertLaunchFuncToVulkanCalls.cpp", - ":ConversionPassDetail", - ], - hdrs = ["include/mlir/Conversion/GPUToVulkan/ConvertGPUToVulkanPass.h"], - includes = ["include"], - deps = [ - ":ConversionPassIncGen", - ":GPUDialect", - ":IR", - ":LLVMDialect", - ":Pass", - ":SPIRVDialect", - ":SPIRVSerialization", - ":StandardOps", - ":Support", - "//llvm:Support", - ], -) - -cc_library( - name = "GPUToGPURuntimeTransforms", - srcs = [ - "lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp", - ":ConversionPassDetail", - ], - hdrs = ["include/mlir/Conversion/GPUCommon/GPUCommonPass.h"], - includes = ["include"], - deps = [ - ":ArithmeticToLLVM", - ":Async", - ":AsyncToLLVM", - ":ConversionPassIncGen", - ":GPUDialect", - ":GPUTransforms", - ":IR", - ":LLVMCommonConversion", - ":LLVMDialect", - ":MemRefToLLVM", - ":NVVMToLLVMIRTranslation", - ":Pass", - ":StandardToLLVM", - ":Support", - ":VectorToLLVM", - "//llvm:Support", - ], -) - -cc_library( - name = "GPUToSPIRV", - srcs = glob([ - "lib/Conversion/GPUToSPIRV/*.cpp", - "lib/Conversion/GPUToSPIRV/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/GPUToSPIRV/*.h", - ]), - includes = [ - "include", - "lib/Conversions/GPUToSPIRV", - ], - deps = [ - ":ArithmeticToSPIRV", - ":ConversionPassIncGen", - ":GPUDialect", - ":IR", - ":MemRefToSPIRV", - ":Pass", - ":SCFDialect", - ":SCFToSPIRV", - ":SPIRVConversion", - ":SPIRVDialect", - ":StandardToSPIRV", - ":Support", - ":Transforms", - ":VectorToSPIRV", - "//llvm:Support", - ], -) - -cc_library( - name = "PDLToPDLInterp", - srcs = glob([ - "lib/Conversion/PDLToPDLInterp/*.cpp", - "lib/Conversion/PDLToPDLInterp/*.h", - ]) + [":ConversionPassDetail"], - hdrs = ["include/mlir/Conversion/PDLToPDLInterp/PDLToPDLInterp.h"], - includes = ["include"], - deps = [ - ":ConversionPassIncGen", - ":IR", - ":InferTypeOpInterface", - ":PDLDialect", - ":PDLInterpDialect", - ":Pass", - ":Support", - "//llvm:Support", - ], -) - -cc_library( - name = "SPIRVToLLVM", - srcs = glob([ - "lib/Conversion/SPIRVToLLVM/*.cpp", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/SPIRVToLLVM/*.h", - ]), - includes = ["include"], - deps = [ - ":ArithmeticToLLVM", - ":ConversionPassIncGen", - ":GPUDialect", - ":IR", - ":LLVMCommonConversion", - ":LLVMDialect", - ":MemRefToLLVM", - ":Pass", - ":SPIRVDialect", - ":SPIRVUtils", - ":StandardOps", - ":StandardToLLVM", - ":Support", - ":Transforms", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "LLVMOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/LLVMIR/LLVMOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/LLVMIR/LLVMOps.cpp.inc", - ), - ( - ["-gen-dialect-decls"], - "include/mlir/Dialect/LLVMIR/LLVMOpsDialect.h.inc", - ), - ( - ["-gen-dialect-defs"], - "include/mlir/Dialect/LLVMIR/LLVMOpsDialect.cpp.inc", - ), - ( - ["-gen-enum-decls"], - "include/mlir/Dialect/LLVMIR/LLVMOpsEnums.h.inc", - ), - ( - ["-gen-enum-defs"], - "include/mlir/Dialect/LLVMIR/LLVMOpsEnums.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/LLVMIR/LLVMOps.td", - deps = [":LLVMOpsTdFiles"], -) - -gentbl_cc_library( - name = "LLVMConversionIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-llvmir-conversions"], - "include/mlir/Dialect/LLVMIR/LLVMConversions.inc", - ), - ( - ["-gen-enum-to-llvmir-conversions"], - "include/mlir/Dialect/LLVMIR/LLVMConversionEnumsToLLVM.inc", - ), - ( - ["-gen-enum-from-llvmir-conversions"], - "include/mlir/Dialect/LLVMIR/LLVMConversionEnumsFromLLVM.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/LLVMIR/LLVMOps.td", - deps = [":LLVMOpsTdFiles"], -) - -cc_library( - name = "NVVMDialect", - srcs = ["lib/Dialect/LLVMIR/IR/NVVMDialect.cpp"], - hdrs = ["include/mlir/Dialect/LLVMIR/NVVMDialect.h"], - includes = ["include"], - deps = [ - ":IR", - ":LLVMDialect", - ":NVVMOpsIncGen", - ":SideEffectInterfaces", - ":StandardOps", - ":Support", - "//llvm:AsmParser", - "//llvm:Core", - "//llvm:Support", - ], -) - -td_library( - name = "NVVMOpsTdFiles", - srcs = ["include/mlir/Dialect/LLVMIR/NVVMOps.td"], - includes = ["include"], - deps = [ - ":LLVMOpsTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "NVVMOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/LLVMIR/NVVMOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/LLVMIR/NVVMOps.cpp.inc", - ), - ( - [ - "-gen-dialect-decls", - "-dialect=nvvm", - ], - "include/mlir/Dialect/LLVMIR/NVVMOpsDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=nvvm", - ], - "include/mlir/Dialect/LLVMIR/NVVMOpsDialect.cpp.inc", - ), - ( - ["-gen-enum-decls"], - "include/mlir/Dialect/LLVMIR/NVVMOpsEnums.h.inc", - ), - ( - ["-gen-enum-defs"], - "include/mlir/Dialect/LLVMIR/NVVMOpsEnums.cpp.inc", - ), - ( - [ - "-gen-attrdef-decls", - "-attrdefs-dialect=nvvm", - ], - "include/mlir/Dialect/LLVMIR/NVVMOpsAttributes.h.inc", - ), - ( - [ - "-gen-attrdef-defs", - "-attrdefs-dialect=nvvm", - ], - "include/mlir/Dialect/LLVMIR/NVVMOpsAttributes.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/LLVMIR/NVVMOps.td", - deps = [":NVVMOpsTdFiles"], -) - -gentbl_cc_library( - name = "NVVMConversionIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-llvmir-conversions"], - "include/mlir/Dialect/LLVMIR/NVVMConversions.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/LLVMIR/NVVMOps.td", - deps = [":NVVMOpsTdFiles"], -) - -cc_library( - name = "ROCDLDialect", - srcs = ["lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp"], - hdrs = ["include/mlir/Dialect/LLVMIR/ROCDLDialect.h"], - includes = ["include"], - deps = [ - ":IR", - ":LLVMDialect", - ":ROCDLOpsIncGen", - ":SideEffectInterfaces", - ":StandardOps", - ":Support", - "//llvm:AsmParser", - "//llvm:Core", - "//llvm:Support", - ], -) - -td_library( - name = "ROCDLOpsTdFiles", - srcs = ["include/mlir/Dialect/LLVMIR/ROCDLOps.td"], - includes = ["include"], - deps = [ - ":LLVMOpsTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "ROCDLOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/LLVMIR/ROCDLOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/LLVMIR/ROCDLOps.cpp.inc", - ), - ( - [ - "-gen-dialect-decls", - "-dialect=rocdl", - ], - "include/mlir/Dialect/LLVMIR/ROCDLOpsDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=rocdl", - ], - "include/mlir/Dialect/LLVMIR/ROCDLOpsDialect.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/LLVMIR/ROCDLOps.td", - deps = [":ROCDLOpsTdFiles"], -) - -gentbl_cc_library( - name = "ROCDLConversionIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-llvmir-conversions"], - "include/mlir/Dialect/LLVMIR/ROCDLConversions.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/LLVMIR/ROCDLOps.td", - deps = [":ROCDLOpsTdFiles"], -) - -cc_library( - name = "PDLDialect", - srcs = glob([ - "lib/Dialect/PDL/IR/*.cpp", - "lib/Dialect/PDL/IR/*.h", - ]), - hdrs = glob([ - "include/mlir/Dialect/PDL/IR/*.h", - ]), - includes = ["include"], - deps = [ - ":IR", - ":InferTypeOpInterface", - ":PDLOpsIncGen", - ":PDLTypesIncGen", - ":SideEffects", - ":Support", - "//llvm:Support", - ], -) - -td_library( - name = "PDLDialectTdFiles", - srcs = [ - "include/mlir/Dialect/PDL/IR/PDLDialect.td", - "include/mlir/Dialect/PDL/IR/PDLOps.td", - "include/mlir/Dialect/PDL/IR/PDLTypes.td", - ], - deps = [ - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "PDLOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/PDL/IR/PDLOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/PDL/IR/PDLOps.cpp.inc", - ), - ( - ["-gen-dialect-decls"], - "include/mlir/Dialect/PDL/IR/PDLOpsDialect.h.inc", - ), - ( - ["-gen-dialect-defs"], - "include/mlir/Dialect/PDL/IR/PDLOpsDialect.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/PDL/IR/PDLOps.td", - deps = [":PDLDialectTdFiles"], -) - -gentbl_cc_library( - name = "PDLTypesIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-typedef-decls"], - "include/mlir/Dialect/PDL/IR/PDLOpsTypes.h.inc", - ), - ( - ["-gen-typedef-defs"], - "include/mlir/Dialect/PDL/IR/PDLOpsTypes.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/PDL/IR/PDLTypes.td", - deps = [":PDLDialectTdFiles"], -) - -cc_library( - name = "PDLInterpDialect", - srcs = glob([ - "lib/Dialect/PDLInterp/IR/*.cpp", - "lib/Dialect/PDLInterp/IR/*.h", - ]), - hdrs = glob([ - "include/mlir/Dialect/PDLInterp/IR/*.h", - ]), - includes = ["include"], - deps = [ - ":IR", - ":InferTypeOpInterface", - ":PDLDialect", - ":PDLInterpOpsIncGen", - ":SideEffects", - ":Support", - "//llvm:Support", - ], -) - -td_library( - name = "PDLInterpOpsTdFiles", - srcs = ["include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td"], - includes = ["include"], - deps = [ - ":OpBaseTdFiles", - ":PDLDialectTdFiles", - ":SideEffectInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "PDLInterpOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.cpp.inc", - ), - ( - [ - "-gen-dialect-decls", - "-dialect=pdl_interp", - ], - "include/mlir/Dialect/PDLInterp/IR/PDLInterpOpsDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=pdl_interp", - ], - "include/mlir/Dialect/PDLInterp/IR/PDLInterpOpsDialect.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td", - deps = [":PDLInterpOpsTdFiles"], -) - -td_library( - name = "SPIRVOpsTdFiles", - srcs = glob(["include/mlir/Dialect/SPIRV/IR/*.td"]), - includes = ["include"], - deps = [ - ":CallInterfacesTdFiles", - ":ControlFlowInterfacesTdFiles", - ":FunctionInterfacesTdFiles", - ":InferTypeOpInterfaceTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "SPIRVOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/SPIRV/IR/SPIRVOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/SPIRV/IR/SPIRVOps.cpp.inc", - ), - ( - ["-gen-dialect-decls"], - "include/mlir/Dialect/SPIRV/IR/SPIRVOpsDialect.h.inc", - ), - ( - ["-gen-dialect-defs"], - "include/mlir/Dialect/SPIRV/IR/SPIRVOpsDialect.cpp.inc", - ), - ( - ["-gen-op-doc"], - "g3doc/Dialects/SPIRV/SPIRVOps.md", - ), - ( - ["-gen-enum-decls"], - "include/mlir/Dialect/SPIRV/IR/SPIRVEnums.h.inc", - ), - ( - ["-gen-enum-defs"], - "include/mlir/Dialect/SPIRV/IR/SPIRVEnums.cpp.inc", - ), - ( - ["-gen-spirv-enum-avail-decls"], - "include/mlir/Dialect/SPIRV/IR/SPIRVEnumAvailability.h.inc", - ), - ( - ["-gen-spirv-enum-avail-defs"], - "include/mlir/Dialect/SPIRV/IR/SPIRVEnumAvailability.cpp.inc", - ), - ( - ["-gen-spirv-capability-implication"], - "include/mlir/Dialect/SPIRV/IR/SPIRVCapabilityImplication.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/SPIRV/IR/SPIRVOps.td", - deps = [":SPIRVOpsTdFiles"], -) - -gentbl_cc_library( - name = "SPIRVCanonicalizationIncGen", - strip_include_prefix = "lib/Dialect/SPIRV/IR", - tbl_outs = [ - ( - ["-gen-rewriters"], - "lib/Dialect/SPIRV/IR/SPIRVCanonicalization.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "lib/Dialect/SPIRV/IR/SPIRVCanonicalization.td", - deps = [":SPIRVOpsTdFiles"], -) - -gentbl_cc_library( - name = "SPIRVAvailabilityIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-avail-interface-decls"], - "include/mlir/Dialect/SPIRV/IR/SPIRVAvailability.h.inc", - ), - ( - ["-gen-avail-interface-defs"], - "include/mlir/Dialect/SPIRV/IR/SPIRVAvailability.cpp.inc", - ), - ( - ["-gen-spirv-avail-impls"], - "include/mlir/Dialect/SPIRV/IR/SPIRVOpAvailabilityImpl.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/SPIRV/IR/SPIRVOps.td", - deps = [":SPIRVOpsTdFiles"], -) - -gentbl_cc_library( - name = "SPIRVTargetAndABIStructGen", - tbl_outs = [ - ( - ["-gen-struct-attr-decls"], - "include/mlir/Dialect/SPIRV/IR/TargetAndABI.h.inc", - ), - ( - ["-gen-struct-attr-defs"], - "include/mlir/Dialect/SPIRV/IR/TargetAndABI.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/SPIRV/IR/TargetAndABI.td", - deps = [":SPIRVOpsTdFiles"], -) - -gentbl_cc_library( - name = "SPIRVAttrUtilsGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-spirv-attr-utils"], - "include/mlir/Dialect/SPIRV/IR/SPIRVAttrUtils.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/SPIRV/IR/SPIRVBase.td", - deps = [":SPIRVOpsTdFiles"], -) - -gentbl_cc_library( - name = "SPIRVSerializationGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-spirv-serialization"], - "include/mlir/Dialect/SPIRV/IR/SPIRVSerialization.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/SPIRV/IR/SPIRVOps.td", - deps = [":SPIRVOpsTdFiles"], -) - -cc_library( - name = "SPIRVDialect", - srcs = glob([ - "lib/Dialect/SPIRV/IR/*.cpp", - "lib/Dialect/SPIRV/IR/*.h", - ]) + ["include/mlir/Transforms/InliningUtils.h"], - hdrs = glob([ - "include/mlir/Dialect/SPIRV/IR/*.h", - ]), - includes = ["include"], - deps = [ - ":CommonFolders", - ":ControlFlowInterfaces", - ":IR", - ":InferTypeOpInterface", - ":Parser", - ":Pass", - ":SPIRVAttrUtilsGen", - ":SPIRVAvailabilityIncGen", - ":SPIRVCanonicalizationIncGen", - ":SPIRVOpsIncGen", - ":SPIRVSerializationGen", - ":SPIRVTargetAndABIStructGen", - ":SideEffectInterfaces", - ":Support", - ":Transforms", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "SPIRVPassIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-pass-decls", - "-name=SPIRV", - ], - "include/mlir/Dialect/SPIRV/Transforms/Passes.h.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/SPIRV/Transforms/Passes.td", - deps = [":PassBaseTdFiles"], -) - -cc_library( - name = "SPIRVUtils", - srcs = glob([ - "lib/Dialect/SPIRV/Utils/*.cpp", - ]), - hdrs = glob([ - "include/mlir/Dialect/SPIRV/Utils/*.h", - ]), - includes = ["include"], - deps = [ - ":SPIRVDialect", - ":Support", - "//llvm:Support", - ], -) - -cc_library( - name = "SPIRVConversion", - srcs = ["lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp"], - hdrs = ["include/mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h"], - includes = ["include"], - deps = [ - ":SPIRVDialect", - ":Support", - ":TransformUtils", - "//llvm:Support", - ], -) - -cc_library( - name = "SPIRVTransforms", - srcs = glob( - [ - "lib/Dialect/SPIRV/Transforms/*.cpp", - "lib/Dialect/SPIRV/Transforms/*.h", - ], - exclude = ["lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp"], - ), - hdrs = glob( - ["include/mlir/Dialect/SPIRV/Transforms/*.h"], - exclude = ["include/mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h"], - ), - includes = ["include"], - deps = [ - ":IR", - ":Pass", - ":SPIRVConversion", - ":SPIRVDialect", - ":SPIRVPassIncGen", - ":SPIRVUtils", - ":Support", - ":Transforms", - "//llvm:Support", - ], -) - -cc_library( - name = "SPIRVCommonConversion", - hdrs = ["lib/Conversion/SPIRVCommon/Pattern.h"], - includes = ["include"], - deps = [ - ":IR", - ":SPIRVDialect", - ":Support", - ":Transforms", - ], -) - -cc_library( - name = "MathToSPIRV", - srcs = glob([ - "lib/Conversion/MathToSPIRV/*.cpp", - "lib/Conversion/MathToSPIRV/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/MathToSPIRV/*.h", - ]), - includes = [ - "include", - "lib/Conversion/MathToSPIRV", - ], - deps = [ - ":ConversionPassIncGen", - ":IR", - ":MathDialect", - ":Pass", - ":SPIRVCommonConversion", - ":SPIRVConversion", - ":SPIRVDialect", - ":Support", - ":Transforms", - "//llvm:Support", - ], -) - -cc_library( - name = "StandardToSPIRV", - srcs = glob([ - "lib/Conversion/StandardToSPIRV/*.cpp", - "lib/Conversion/StandardToSPIRV/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/StandardToSPIRV/*.h", - ]), - includes = [ - "include", - "lib/Conversion/StandardToSPIRV", - ], - deps = [ - ":ArithmeticToSPIRV", - ":ConversionPassIncGen", - ":IR", - ":MathToSPIRV", - ":Pass", - ":SPIRVCommonConversion", - ":SPIRVConversion", - ":SPIRVDialect", - ":SPIRVUtils", - ":StandardOps", - ":Support", - ":TensorDialect", - ":Transforms", - ":VectorOps", - "//llvm:Support", - ], -) - -cc_library( - name = "SPIRVBinaryUtils", - srcs = ["lib/Target/SPIRV/SPIRVBinaryUtils.cpp"], - hdrs = ["include/mlir/Target/SPIRV/SPIRVBinaryUtils.h"], - includes = ["include"], - deps = [ - ":IR", - ":SPIRVAttrUtilsGen", - ":SPIRVDialect", - ":SPIRVOpsIncGen", - ":Support", - "//llvm:Support", - ], -) - -cc_library( - name = "SPIRVSerialization", - srcs = [ - "lib/Target/SPIRV/Serialization/Serialization.cpp", - "lib/Target/SPIRV/Serialization/SerializeOps.cpp", - "lib/Target/SPIRV/Serialization/Serializer.cpp", - "lib/Target/SPIRV/Serialization/Serializer.h", - ], - hdrs = ["include/mlir/Target/SPIRV/Serialization.h"], - includes = ["include"], - deps = [ - ":IR", - ":SPIRVAttrUtilsGen", - ":SPIRVBinaryUtils", - ":SPIRVDialect", - ":SPIRVOpsIncGen", - ":SPIRVSerializationGen", - ":Support", - ":Transforms", - "//llvm:Support", - ], -) - -cc_library( - name = "SPIRVDeserialization", - srcs = glob([ - "lib/Target/SPIRV/Deserialization/*.cpp", - "lib/Target/SPIRV/Deserialization/*.h", - ]), - hdrs = ["include/mlir/Target/SPIRV/Deserialization.h"], - includes = ["include"], - deps = [ - ":IR", - ":SPIRVAttrUtilsGen", - ":SPIRVBinaryUtils", - ":SPIRVDialect", - ":SPIRVOpsIncGen", - ":SPIRVSerializationGen", - ":Support", - ":Transforms", - "//llvm:Support", - ], -) - -cc_library( - name = "SPIRVModuleCombiner", - srcs = glob( - ["lib/Dialect/SPIRV/Linking/ModuleCombiner/*.cpp"], - ), - hdrs = ["include/mlir/Dialect/SPIRV/Linking/ModuleCombiner.h"], - includes = ["include"], - deps = [ - ":IR", - ":SPIRVDialect", - ":Support", - "//llvm:Support", - ], -) - -cc_library( - name = "SPIRVTranslateRegistration", - srcs = ["lib/Target/SPIRV/TranslateRegistration.cpp"], - includes = ["include"], - deps = [ - ":IR", - ":Parser", - ":SPIRVDeserialization", - ":SPIRVDialect", - ":SPIRVSerialization", - ":Support", - ":Translation", - "//llvm:Support", - ], -) - -td_library( - name = "TensorOpsTdFiles", - srcs = [ - "include/mlir/Dialect/Tensor/IR/TensorBase.td", - "include/mlir/Dialect/Tensor/IR/TensorOps.td", - ], - includes = ["include"], - deps = [ - ":CastInterfacesTdFiles", - ":ControlFlowInterfacesTdFiles", - ":InferTypeOpInterfaceTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ":TilingInterfaceTdFiles", - ":ViewLikeInterfaceTdFiles", - ], -) - -gentbl_cc_library( - name = "TensorOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-dialect-decls", - "-dialect=tensor", - ], - "include/mlir/Dialect/Tensor/IR/TensorOpsDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=tensor", - ], - "include/mlir/Dialect/Tensor/IR/TensorOpsDialect.cpp.inc", - ), - ( - ["-gen-op-decls"], - "include/mlir/Dialect/Tensor/IR/TensorOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/Tensor/IR/TensorOps.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Tensor/IR/TensorOps.td", - deps = [":TensorOpsTdFiles"], -) - -cc_library( - name = "TensorDialect", - srcs = [ - "include/mlir/Transforms/InliningUtils.h", - "lib/Dialect/Tensor/IR/TensorDialect.cpp", - "lib/Dialect/Tensor/IR/TensorOps.cpp", - ], - hdrs = ["include/mlir/Dialect/Tensor/IR/Tensor.h"], - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":CastOpInterfaces", - ":ComplexDialect", - ":ControlFlowInterfaces", - ":DialectUtils", - ":IR", - ":InferTypeOpInterface", - ":SideEffectInterfaces", - ":StandardOps", - ":Support", - ":TensorOpsIncGen", - ":TilingInterface", - ":ViewLikeInterface", - "//llvm:Support", - ], -) - -cc_library( - name = "TensorInferTypeOpInterfaceImpl", - srcs = ["lib/Dialect/Tensor/IR/TensorInferTypeOpInterfaceImpl.cpp"], - hdrs = ["include/mlir/Dialect/Tensor/IR/TensorInferTypeOpInterfaceImpl.h"], - includes = ["include"], - deps = [ - ":Affine", - ":IR", - ":InferTypeOpInterface", - ":StandardOps", - ":TensorDialect", - "//llvm:Support", - ], -) - -cc_library( - name = "TensorTilingInterfaceImpl", - srcs = ["lib/Dialect/Tensor/IR/TensorTilingInterfaceImpl.cpp"], - hdrs = ["include/mlir/Dialect/Tensor/IR/TensorTilingInterfaceImpl.h"], - includes = ["include"], - deps = [ - ":Affine", - ":IR", - ":LinalgOps", - ":SCFDialect", - ":StandardOps", - ":TensorDialect", - ":TilingInterface", - "//llvm:Support", - ], -) - -cc_library( - name = "TensorUtils", - srcs = ["lib/Dialect/Tensor/Utils/Utils.cpp"], - hdrs = ["include/mlir/Dialect/Tensor/Utils/Utils.h"], - includes = ["include"], - deps = [ - ":Affine", - ":ArithmeticDialect", - ":IR", - ":Support", - ":TensorDialect", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "TensorPassIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-pass-decls", - "-name=Tensor", - ], - "include/mlir/Dialect/Tensor/Transforms/Passes.h.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Tensor/Transforms/Passes.td", - deps = [":PassBaseTdFiles"], -) - -cc_library( - name = "TensorTransforms", - srcs = glob( - [ - "lib/Dialect/Tensor/Transforms/*.cpp", - "lib/Dialect/Tensor/Transforms/*.h", - ], - ), - hdrs = [ - "include/mlir/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.h", - "include/mlir/Dialect/Tensor/Transforms/Passes.h", - ], - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":Async", - ":BufferizationDialect", - ":BufferizationTransforms", - ":IR", - ":MemRefDialect", - ":ParallelLoopMapperAttrGen", - ":Pass", - ":SCFDialect", - ":StandardOps", - ":Support", - ":TensorDialect", - ":TensorPassIncGen", - ":Transforms", - "//llvm:Support", - ], -) - -cc_library( - name = "Rewrite", - srcs = glob([ - "lib/Rewrite/*.cpp", - "lib/Rewrite/*.h", - ]), - hdrs = glob(["include/mlir/Rewrite/*.h"]), - includes = ["include"], - deps = [ - ":Analysis", - ":IR", - ":PDLDialect", - ":PDLInterpDialect", - ":PDLToPDLInterp", - ":Pass", - ":SideEffectInterfaces", - "//llvm:Support", - ], -) - -cc_library( - name = "TransformUtils", - srcs = glob([ - "lib/Transforms/Utils/*.cpp", - "lib/Transforms/Utils/*.h", - ]), - hdrs = glob([ - "include/mlir/Transforms/*.h", - ]), - includes = ["include"], - deps = [ - ":Affine", - ":AffineAnalysis", - ":Analysis", - ":ArithmeticDialect", - ":ControlFlowInterfaces", - ":IR", - ":MemRefDialect", - ":Pass", - ":Rewrite", - ":SCFDialect", - ":SideEffectInterfaces", - ":StandardOps", - ":Support", - ":TransformsPassIncGen", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "DerivedAttributeOpInterfaceIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/Interfaces/DerivedAttributeOpInterface.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/Interfaces/DerivedAttributeOpInterface.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Interfaces/DerivedAttributeOpInterface.td", - deps = [":DerivedAttributeOpInterfaceTdFiles"], -) - -cc_library( - name = "DerivedAttributeOpInterface", - srcs = ["lib/Interfaces/DerivedAttributeOpInterface.cpp"], - hdrs = ["include/mlir/Interfaces/DerivedAttributeOpInterface.h"], - includes = ["include"], - deps = [ - ":DerivedAttributeOpInterfaceIncGen", - ":IR", - ":Support", - "//llvm:Support", - ], -) - -td_library( - name = "DataLayoutInterfacesTdFiles", - srcs = ["include/mlir/Interfaces/DataLayoutInterfaces.td"], - includes = ["include"], -) - -gentbl_cc_library( - name = "DataLayoutInterfacesIncGen", - tbl_outs = [ - ( - ["-gen-attr-interface-decls"], - "include/mlir/Interfaces/DataLayoutAttrInterface.h.inc", - ), - ( - ["-gen-attr-interface-defs"], - "include/mlir/Interfaces/DataLayoutAttrInterface.cpp.inc", - ), - ( - ["-gen-op-interface-decls"], - "include/mlir/Interfaces/DataLayoutOpInterface.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/Interfaces/DataLayoutOpInterface.cpp.inc", - ), - ( - ["-gen-type-interface-decls"], - "include/mlir/Interfaces/DataLayoutTypeInterface.h.inc", - ), - ( - ["-gen-type-interface-defs"], - "include/mlir/Interfaces/DataLayoutTypeInterface.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Interfaces/DataLayoutInterfaces.td", - deps = [":OpBaseTdFiles"], -) - -gentbl_cc_library( - name = "LoopLikeInterfaceIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/Interfaces/LoopLikeInterface.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/Interfaces/LoopLikeInterface.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Interfaces/LoopLikeInterface.td", - deps = [":LoopLikeInterfaceTdFiles"], -) - -gentbl_cc_library( - name = "VectorInterfacesIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/Interfaces/VectorInterfaces.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/Interfaces/VectorInterfaces.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Interfaces/VectorInterfaces.td", - deps = [":VectorInterfacesTdFiles"], -) - -gentbl_cc_library( - name = "ViewLikeInterfaceIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/Interfaces/ViewLikeInterface.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/Interfaces/ViewLikeInterface.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Interfaces/ViewLikeInterface.td", - deps = [":ViewLikeInterfaceTdFiles"], -) - -gentbl_cc_library( - name = "CopyOpInterfaceIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/Interfaces/CopyOpInterface.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/Interfaces/CopyOpInterface.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Interfaces/CopyOpInterface.td", - deps = [":CopyOpInterfaceTdFiles"], -) - -gentbl_cc_library( - name = "TransformsPassIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-pass-decls", - "-name=Transforms", - ], - "include/mlir/Transforms/Passes.h.inc", - ), - ( - [ - "-gen-pass-capi-header", - "--prefix=Transforms", - ], - "include/mlir/Transforms/Transforms.capi.h.inc", - ), - ( - [ - "-gen-pass-capi-impl", - "--prefix=Transforms", - ], - "include/mlir/Transforms/Transforms.capi.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Transforms/Passes.td", - deps = [ - ":PassBaseTdFiles", - ":RewritePassBaseTdFiles", - ], -) - -cc_library( - name = "Transforms", - srcs = glob([ - "lib/Transforms/*.cpp", - "lib/Transforms/*.h", - ]), - hdrs = glob(["include/mlir/Transforms/*.h"]), - includes = ["include"], - deps = [ - ":Affine", - ":AffineAnalysis", - ":AllocationOpInterface", - ":Analysis", - ":ArithmeticDialect", - ":BufferizationDialect", - ":ControlFlowInterfaces", - ":CopyOpInterface", - ":IR", - ":LinalgOps", - ":LoopLikeInterface", - ":MemRefDialect", - ":Pass", - ":Rewrite", - ":SCFDialect", - ":SideEffectInterfaces", - ":StandardOps", - ":Support", - ":TensorDialect", - ":TransformUtils", - ":TransformsPassIncGen", - "//llvm:Support", - ], -) - -cc_library( - name = "CommonFolders", - srcs = [ - ], - hdrs = ["include/mlir/Dialect/CommonFolders.h"], - includes = ["include"], - deps = [ - ":IR", - "//llvm:Support", - ], -) - -cc_library( - name = "SCFToGPU", - srcs = ["lib/Conversion/SCFToGPU/SCFToGPU.cpp"], - hdrs = ["include/mlir/Conversion/SCFToGPU/SCFToGPU.h"], - includes = ["include"], - deps = [ - ":Affine", - ":AffineToStandard", - ":ArithmeticDialect", - ":ConversionPassIncGen", - ":GPUDialect", - ":GPUTransforms", - ":IR", - ":MemRefDialect", - ":Pass", - ":SCFDialect", - ":StandardOps", - ":Support", - ":TransformUtils", - ":Transforms", - "//llvm:Support", - ], -) - -cc_library( - name = "SCFToGPUPass", - srcs = [ - "lib/Conversion/SCFToGPU/SCFToGPUPass.cpp", - ":ConversionPassDetail", - ], - hdrs = ["include/mlir/Conversion/SCFToGPU/SCFToGPUPass.h"], - includes = ["include"], - deps = [ - ":Affine", - ":ArithmeticDialect", - ":ComplexDialect", - ":ConversionPassIncGen", - ":GPUDialect", - ":Pass", - ":SCFDialect", - ":SCFToGPU", - ":StandardOps", - ":Support", - ":Transforms", - "//llvm:Support", - ], -) - -cc_library( - name = "SCFToSPIRV", - srcs = glob([ - "lib/Conversion/SCFToSPIRV/*.cpp", - "lib/Conversion/SCFToSPIRV/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/SCFToSPIRV/*.h", - ]), - includes = ["include"], - deps = [ - ":Affine", - ":ArithmeticToSPIRV", - ":ConversionPassIncGen", - ":IR", - ":MemRefToSPIRV", - ":Pass", - ":SCFDialect", - ":SPIRVConversion", - ":SPIRVDialect", - ":StandardOps", - ":StandardToSPIRV", - ":Support", - ":TransformUtils", - ":Transforms", - "//llvm:Support", - ], -) - -cc_library( - name = "SCFToOpenMP", - srcs = [ - "lib/Conversion/SCFToOpenMP/SCFToOpenMP.cpp", - ":ConversionPassDetail", - ], - hdrs = ["include/mlir/Conversion/SCFToOpenMP/SCFToOpenMP.h"], - includes = ["include"], - deps = [ - ":AffineAnalysis", - ":Analysis", - ":ArithmeticDialect", - ":ConversionPassIncGen", - ":IR", - ":LLVMDialect", - ":OpenMPDialect", - ":Pass", - ":SCFDialect", - ":StandardOps", - ":Support", - ":Transforms", - ], -) - -cc_library( - name = "SCFToStandard", - srcs = [ - "lib/Conversion/SCFToStandard/SCFToStandard.cpp", - ":ConversionPassDetail", - ], - hdrs = ["include/mlir/Conversion/SCFToStandard/SCFToStandard.h"], - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":ConversionPassIncGen", - ":IR", - ":LLVMDialect", - ":Pass", - ":SCFDialect", - ":StandardOps", - ":Support", - ":TransformUtils", - ":Transforms", - ], -) - -alias( - name = "CFGTransforms", - actual = "SCFToStandard", -) - -cc_library( - name = "LLVMCommonConversion", - srcs = glob([ - "lib/Conversion/LLVMCommon/*.cpp", - ]) + ["lib/Conversion/LLVMCommon/MemRefDescriptor.h"], - hdrs = glob(["include/mlir/Conversion/LLVMCommon/*.h"]), - includes = ["include"], - deps = [ - ":IR", - ":LLVMDialect", - ":Support", - ":Transforms", - "//llvm:Core", - ], -) - -cc_library( - name = "ReconcileUnrealizedCasts", - srcs = glob(["lib/Conversion/ReconcileUnrealizedCasts/*.cpp"]) + [":ConversionPassDetail"], - hdrs = glob(["include/mlir/Conversion/ReconcileUnrealizedCasts/*.h"]), - includes = ["include"], - deps = [ - ":ConversionPassIncGen", - ":IR", - ":Pass", - ":TransformUtils", - ], -) - -cc_library( - name = "StandardToLLVM", - srcs = [ - "lib/Conversion/StandardToLLVM/StandardToLLVM.cpp", - ":ConversionPassDetail", - ], - hdrs = [ - "include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h", - "include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h", - ], - includes = ["include"], - deps = [ - ":Analysis", - ":ArithmeticToLLVM", - ":ConversionPassIncGen", - ":DataLayoutInterfaces", - ":DialectUtils", - ":IR", - ":LLVMCommonConversion", - ":LLVMDialect", - ":MathDialect", - ":MemRefDialect", - ":Parser", - ":Pass", - ":StandardOps", - ":StandardOpsTransforms", - ":Support", - ":TransformUtils", - ":Transforms", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "MemRefToLLVM", - srcs = glob(["lib/Conversion/MemRefToLLVM/*.cpp"]) + [":ConversionPassDetail"], - hdrs = glob(["include/mlir/Conversion/MemRefToLLVM/*.h"]), - includes = ["include"], - deps = [ - ":Analysis", - ":ConversionPassIncGen", - ":DataLayoutInterfaces", - ":IR", - ":LLVMCommonConversion", - ":LLVMDialect", - ":MemRefDialect", - ":Pass", - ":Support", - ":Transforms", - ], -) - -cc_library( - name = "MemRefToSPIRV", - srcs = glob([ - "lib/Conversion/MemRefToSPIRV/*.cpp", - "lib/Conversion/MemRefToSPIRV/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/MemRefToSPIRV/*.h", - ]), - includes = [ - "include", - "lib/Conversion/MemRefToSPIRV", - ], - deps = [ - ":ConversionPassIncGen", - ":IR", - ":MemRefDialect", - ":Pass", - ":SPIRVConversion", - ":SPIRVDialect", - ":Support", - ":Transforms", - "//llvm:Support", - ], -) - -cc_library( - name = "ArithmeticToLLVM", - srcs = glob(["lib/Conversion/ArithmeticToLLVM/*.cpp"]) + [":ConversionPassDetail"], - hdrs = glob(["include/mlir/Conversion/ArithmeticToLLVM/*.h"]), - includes = ["include"], - deps = [ - ":Analysis", - ":ArithmeticDialect", - ":ConversionPassIncGen", - ":IR", - ":LLVMCommonConversion", - ":LLVMDialect", - ":Pass", - ":Support", - ":Transforms", - ], -) - -cc_library( - name = "ArithmeticToSPIRV", - srcs = glob(["lib/Conversion/ArithmeticToSPIRV/*.cpp"]) + [":ConversionPassDetail"], - hdrs = glob(["include/mlir/Conversion/ArithmeticToSPIRV/*.h"]), - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":ConversionPassIncGen", - ":IR", - ":Pass", - ":SPIRVCommonConversion", - ":SPIRVConversion", - ":SPIRVDialect", - ":Support", - ":Transforms", - "//llvm:Support", - ], -) - -cc_library( - name = "MathToLLVM", - srcs = glob(["lib/Conversion/MathToLLVM/*.cpp"]) + [":ConversionPassDetail"], - hdrs = glob(["include/mlir/Conversion/MathToLLVM/*.h"]), - includes = ["include"], - deps = [ - ":Analysis", - ":ConversionPassIncGen", - ":DataLayoutInterfaces", - ":IR", - ":LLVMCommonConversion", - ":LLVMDialect", - ":MathDialect", - ":Pass", - ":Support", - ":Transforms", - ], -) - -alias( - name = "LLVMTransforms", - actual = "StandardToLLVM", -) - -gentbl_cc_library( - name = "CallOpInterfacesIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/Interfaces/CallInterfaces.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/Interfaces/CallInterfaces.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Interfaces/CallInterfaces.td", - deps = [":CallInterfacesTdFiles"], -) - -cc_library( - name = "CallOpInterfaces", - srcs = ["lib/Interfaces/CallInterfaces.cpp"], - hdrs = ["include/mlir/Interfaces/CallInterfaces.h"], - includes = ["include"], - deps = [ - ":CallOpInterfacesIncGen", - ":IR", - ":Support", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "CastOpInterfacesIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/Interfaces/CastInterfaces.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/Interfaces/CastInterfaces.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Interfaces/CastInterfaces.td", - deps = [":CastInterfacesTdFiles"], -) - -cc_library( - name = "CastOpInterfaces", - srcs = ["lib/Interfaces/CastInterfaces.cpp"], - hdrs = ["include/mlir/Interfaces/CastInterfaces.h"], - includes = ["include"], - deps = [ - ":CastOpInterfacesIncGen", - ":IR", - ":Support", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "ControlFlowInterfacesIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/Interfaces/ControlFlowInterfaces.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/Interfaces/ControlFlowInterfaces.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Interfaces/ControlFlowInterfaces.td", - deps = [":ControlFlowInterfacesTdFiles"], -) - -cc_library( - name = "ControlFlowInterfaces", - srcs = ["lib/Interfaces/ControlFlowInterfaces.cpp"], - hdrs = ["include/mlir/Interfaces/ControlFlowInterfaces.h"], - includes = ["include"], - deps = [ - ":ControlFlowInterfacesIncGen", - ":IR", - ":Support", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "InferTypeOpInterfaceIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/Interfaces/InferTypeOpInterface.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/Interfaces/InferTypeOpInterface.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Interfaces/InferTypeOpInterface.td", - deps = [":InferTypeOpInterfaceTdFiles"], -) - -cc_library( - name = "InferTypeOpInterface", - srcs = ["lib/Interfaces/InferTypeOpInterface.cpp"], - hdrs = ["include/mlir/Interfaces/InferTypeOpInterface.h"], - includes = ["include"], - deps = [ - ":IR", - ":InferTypeOpInterfaceIncGen", - ":Support", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "SideEffectInterfacesIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/Interfaces/SideEffectInterfaces.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/Interfaces/SideEffectInterfaces.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Interfaces/SideEffectInterfaces.td", - deps = [":SideEffectInterfacesTdFiles"], -) - -cc_library( - name = "SideEffectInterfaces", - srcs = ["lib/Interfaces/SideEffectInterfaces.cpp"], - hdrs = ["include/mlir/Interfaces/SideEffectInterfaces.h"], - includes = ["include"], - deps = [ - ":IR", - ":SideEffectInterfacesIncGen", - ":Support", - "//llvm:Support", - ], -) - -alias( - name = "SideEffects", - actual = "SideEffectInterfaces", -) - -gentbl_cc_library( - name = "TilingInterfaceIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/Interfaces/TilingInterface.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/Interfaces/TilingInterface.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Interfaces/TilingInterface.td", - deps = [":TilingInterfaceTdFiles"], -) - -cc_library( - name = "Analysis", - srcs = glob( - [ - "lib/Analysis/*.cpp", - "lib/Analysis/*.h", - "lib/Analysis/*/*.cpp", - "lib/Analysis/*/*.h", - ], - exclude = [ - "lib/Analysis/Vector*.cpp", - "lib/Analysis/Vector*.h", - ], - ), - hdrs = glob( - [ - "include/mlir/Analysis/*.h", - "include/mlir/Analysis/*/*.h", - ], - exclude = ["include/mlir/Analysis/Vector*.h"], - ), - includes = ["include"], - deps = [ - ":Affine", - ":ArithmeticDialect", - ":BufferizationDialect", - ":CallOpInterfaces", - ":ControlFlowInterfaces", - ":DataLayoutInterfaces", - ":IR", - ":LinalgOps", - ":SCFDialect", - ":SideEffectInterfaces", - ":StandardOps", - ":Support", - ":ViewLikeInterface", - "//llvm:Support", - ], -) - -cc_library( - name = "Translation", - srcs = glob([ - "lib/Translation/*.cpp", - "lib/Translation/*.h", - ]), - hdrs = ["include/mlir/Translation.h"], - includes = ["include"], - deps = [ - ":Analysis", - ":IR", - ":Parser", - ":Support", - "//llvm:Support", - ], -) - -cc_library( - name = "ToLLVMIRTranslation", - srcs = [ - "lib/Target/LLVMIR/DebugTranslation.cpp", - "lib/Target/LLVMIR/DebugTranslation.h", - "lib/Target/LLVMIR/ModuleTranslation.cpp", - "lib/Target/LLVMIR/TypeToLLVM.cpp", - ], - hdrs = [ - "include/mlir/Target/LLVMIR/Export.h", - "include/mlir/Target/LLVMIR/LLVMTranslationInterface.h", - "include/mlir/Target/LLVMIR/ModuleTranslation.h", - "include/mlir/Target/LLVMIR/TypeToLLVM.h", - ], - includes = ["include"], - deps = [ - ":IR", - ":LLVMConversionIncGen", - ":LLVMDialect", - ":LLVMIRTransforms", - ":OpenMPDialect", - ":Support", - "//llvm:Core", - "//llvm:FrontendOpenMP", - "//llvm:Support", - "//llvm:TransformUtils", - ], -) - -cc_library( - name = "AMXToLLVMIRTranslation", - srcs = glob(["lib/Target/LLVMIR/Dialect/AMX/*.cpp"]), - hdrs = glob(["include/mlir/Target/LLVMIR/Dialect/AMX/*.h"]), - includes = ["include"], - deps = [ - ":AMX", - ":AMXConversionIncGen", - ":IR", - ":Support", - ":ToLLVMIRTranslation", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "X86VectorToLLVMIRTranslation", - srcs = glob(["lib/Target/LLVMIR/Dialect/X86Vector/*.cpp"]), - hdrs = glob(["include/mlir/Target/LLVMIR/Dialect/X86Vector/*.h"]), - includes = ["include"], - deps = [ - ":IR", - ":Support", - ":ToLLVMIRTranslation", - ":X86Vector", - ":X86VectorConversionIncGen", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "ArmNeonToLLVMIRTranslation", - srcs = glob(["lib/Target/LLVMIR/Dialect/ArmNeon/*.cpp"]), - hdrs = glob(["include/mlir/Target/LLVMIR/Dialect/ArmNeon/*.h"]), - includes = ["include"], - deps = [ - ":ArmNeon", - ":ArmNeonConversionIncGen", - ":ArmNeonIncGen", - ":IR", - ":Support", - ":ToLLVMIRTranslation", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "ArmSVEToLLVMIRTranslation", - srcs = glob(["lib/Target/LLVMIR/Dialect/ArmSVE/*.cpp"]), - hdrs = glob(["include/mlir/Target/LLVMIR/Dialect/ArmSVE/*.h"]), - includes = ["include"], - deps = [ - ":ArmSVE", - ":ArmSVEConversionIncGen", - ":IR", - ":Support", - ":ToLLVMIRTranslation", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "NVVMToLLVMIRTranslation", - srcs = glob(["lib/Target/LLVMIR/Dialect/NVVM/*.cpp"]), - hdrs = glob(["include/mlir/Target/LLVMIR/Dialect/NVVM/*.h"]), - includes = ["include"], - deps = [ - ":IR", - ":NVVMConversionIncGen", - ":NVVMDialect", - ":Support", - ":ToLLVMIRTranslation", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "ROCDLToLLVMIRTranslation", - srcs = glob(["lib/Target/LLVMIR/Dialect/ROCDL/*.cpp"]), - hdrs = glob(["include/mlir/Target/LLVMIR/Dialect/ROCDL/*.h"]), - includes = ["include"], - deps = [ - ":IR", - ":ROCDLConversionIncGen", - ":ROCDLDialect", - ":Support", - ":ToLLVMIRTranslation", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "LLVMToLLVMIRTranslation", - srcs = glob(["lib/Target/LLVMIR/Dialect/LLVMIR/*.cpp"]), - hdrs = glob(["include/mlir/Target/LLVMIR/Dialect/LLVMIR/*.h"]), - includes = ["include"], - deps = [ - ":IR", - ":LLVMConversionIncGen", - ":LLVMDialect", - ":Support", - ":ToLLVMIRTranslation", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "OpenACCToLLVMIRTranslation", - srcs = glob(["lib/Target/LLVMIR/Dialect/OpenACC/*.cpp"]), - hdrs = glob(["include/mlir/Target/LLVMIR/Dialect/OpenACC/*.h"]), - includes = ["include"], - deps = [ - ":IR", - ":LLVMDialect", - ":OpenACCDialect", - ":OpenACCToLLVM", - ":Support", - ":ToLLVMIRTranslation", - "//llvm:Core", - "//llvm:FrontendOpenMP", - "//llvm:Support", - ], -) - -cc_library( - name = "OpenMPToLLVMIRTranslation", - srcs = glob(["lib/Target/LLVMIR/Dialect/OpenMP/*.cpp"]), - hdrs = glob(["include/mlir/Target/LLVMIR/Dialect/OpenMP/*.h"]), - includes = ["include"], - deps = [ - ":IR", - ":OpenMPDialect", - ":Support", - ":ToLLVMIRTranslation", - "//llvm:Core", - "//llvm:FrontendOpenMP", - "//llvm:Support", - ], -) - -cc_library( - name = "AllToLLVMIRTranslations", - hdrs = ["include/mlir/Target/LLVMIR/Dialect/All.h"], - includes = ["include"], - deps = [ - ":AMXToLLVMIRTranslation", - ":ArmNeonToLLVMIRTranslation", - ":ArmSVEToLLVMIRTranslation", - ":LLVMToLLVMIRTranslation", - ":NVVMToLLVMIRTranslation", - ":OpenACCToLLVMIRTranslation", - ":OpenMPToLLVMIRTranslation", - ":ROCDLToLLVMIRTranslation", - ":X86VectorToLLVMIRTranslation", - ], -) - -cc_library( - name = "ToLLVMIRTranslationRegistration", - srcs = ["lib/Target/LLVMIR/ConvertToLLVMIR.cpp"], - includes = ["include"], - deps = [ - ":AllToLLVMIRTranslations", - ":IR", - ":ToLLVMIRTranslation", - ":Translation", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "FromLLVMIRTranslation", - srcs = [ - "lib/Target/LLVMIR/ConvertFromLLVMIR.cpp", - "lib/Target/LLVMIR/TypeFromLLVM.cpp", - ], - hdrs = [ - "include/mlir/Target/LLVMIR/Import.h", - "include/mlir/Target/LLVMIR/TypeFromLLVM.h", - ], - includes = ["include"], - deps = [ - ":IR", - ":LLVMConversionIncGen", - ":LLVMDialect", - ":Support", - ":Translation", - "//llvm:Core", - "//llvm:IRReader", - "//llvm:Support", - ], -) - -cc_library( - name = "ExecutionEngine", - srcs = [ - "include/mlir/ExecutionEngine/CRunnerUtils.h", - "lib/ExecutionEngine/ExecutionEngine.cpp", - ], - hdrs = [ - "include/mlir/ExecutionEngine/ExecutionEngine.h", - "include/mlir/ExecutionEngine/MemRefUtils.h", - ], - includes = ["include"], - deps = [ - ":AllToLLVMIRTranslations", - ":IR", - ":LLVMDialect", - ":Support", - ":ToLLVMIRTranslation", - ":Translation", - "//llvm:AllTargetsAsmParsers", - "//llvm:BitReader", - "//llvm:BitWriter", - "//llvm:Core", - "//llvm:ExecutionEngine", - "//llvm:MC", - "//llvm:OrcJIT", - "//llvm:Support", - "//llvm:Target", # fixdeps: keep - "//llvm:TransformUtils", - "//llvm:X86CodeGen", # fixdeps: keep - "//llvm:X86Disassembler", # fixdeps: keep - ], -) - -cc_library( - name = "ExecutionEngineUtils", - srcs = ["lib/ExecutionEngine/OptUtils.cpp"], - hdrs = ["include/mlir/ExecutionEngine/OptUtils.h"], - includes = ["include"], - deps = [ - "//llvm:Analysis", - "//llvm:Core", - "//llvm:Coroutines", - "//llvm:IPO", - "//llvm:Support", - "//llvm:Target", - "//llvm:common_transforms", - ], -) - -# TODO(jpienaar): Update this. -cc_library( - name = "MlirOptLib", - srcs = ["lib/Support/MlirOptMain.cpp"], - hdrs = ["include/mlir/Support/MlirOptMain.h"], - includes = ["include"], - deps = [ - ":Analysis", - ":ConversionPasses", - ":GPUToGPURuntimeTransforms", - ":GPUToNVVMTransforms", - ":GPUToROCDLTransforms", - ":GPUToSPIRV", - ":GPUTransforms", - ":IR", - ":Parser", - ":Pass", - ":SCFTransforms", - ":ShapeToStandard", - ":ShapeTransforms", - ":StandardOpsTransforms", - ":StandardToLLVM", - ":StandardToSPIRV", - ":Support", - "//llvm:Support", - ], -) - -cc_library( - name = "AllTranslations", - hdrs = ["include/mlir/InitAllTranslations.h"], - deps = [ - ":FromLLVMIRTranslation", - ":SPIRVTranslateRegistration", - ":TargetCpp", - ":ToLLVMIRTranslationRegistration", - ], -) - -cc_library( - name = "MlirTranslateMain", - srcs = ["tools/mlir-translate/mlir-translate.cpp"], - deps = [ - ":AllPassesAndDialects", - ":AllTranslations", - ":IR", - ":Parser", - ":Support", - ":Translation", - "//llvm:Support", - ], -) - -cc_binary( - name = "mlir-translate", - deps = [":MlirTranslateMain"], -) - -cc_library( - name = "AllPassesAndDialects", - hdrs = [ - "include/mlir/InitAllDialects.h", - "include/mlir/InitAllPasses.h", - ], - deps = [ - ":AMX", - ":AMXTransforms", - ":Affine", - ":AffinePassIncGen", - ":AffineToStandard", - ":AffineTransforms", - ":ArithmeticDialect", - ":ArithmeticToLLVM", - ":ArithmeticToSPIRV", - ":ArithmeticTransforms", - ":ArmNeon", - ":ArmSVE", - ":ArmSVETransforms", - ":Async", - ":AsyncPassIncGen", - ":AsyncToLLVM", - ":AsyncTransforms", - ":BufferizationDialect", - ":BufferizationTransforms", - ":ComplexDialect", - ":ComplexToLLVM", - ":ConversionPasses", - ":DLTIDialect", - ":EmitC", - ":GPUDialect", - ":GPUPassIncGen", - ":GPUToGPURuntimeTransforms", - ":GPUToNVVMTransforms", - ":GPUToROCDLTransforms", - ":GPUToSPIRV", - ":GPUToVulkanTransforms", - ":GPUTransforms", - ":IR", - ":LLVMDialect", - ":LLVMIRTransforms", - ":LLVMPassIncGen", - ":LinalgOps", - ":LinalgPassIncGen", - ":LinalgToLLVM", - ":LinalgToSPIRV", - ":LinalgToStandard", - ":LinalgTransforms", - ":MathDialect", - ":MathToLLVM", - ":MathToLibm", - ":MathToSPIRV", - ":MathTransforms", - ":MemRefDialect", - ":MemRefToLLVM", - ":MemRefToSPIRV", - ":MemRefTransforms", - ":NVVMDialect", - ":OpenACCDialect", - ":OpenMPDialect", - ":OpenMPToLLVM", - ":PDLDialect", - ":PDLInterpDialect", - ":PDLToPDLInterp", - ":QuantOps", - ":QuantPassIncGen", - ":ROCDLDialect", - ":ReconcileUnrealizedCasts", - ":SCFDialect", - ":SCFPassIncGen", - ":SCFToGPUPass", - ":SCFToStandard", - ":SCFTransforms", - ":SDBM", - ":SPIRVDialect", - ":SPIRVPassIncGen", - ":SPIRVToLLVM", - ":SPIRVTransforms", - ":Shape", - ":ShapeToStandard", - ":ShapeTransforms", - ":ShapeTransformsPassIncGen", - ":SparseTensor", - ":SparseTensorPipelines", - ":SparseTensorTransforms", - ":StandardOps", - ":StandardOpsTransforms", - ":StandardOpsTransformsPassIncGen", - ":StandardToLLVM", - ":StandardToSPIRV", - ":TensorDialect", - ":TensorInferTypeOpInterfaceImpl", - ":TensorTilingInterfaceImpl", - ":TensorTransforms", - ":TosaDialect", - ":TosaToLinalg", - ":Transforms", - ":TransformsPassIncGen", - ":VectorOps", - ":VectorToLLVM", - ":VectorToROCDL", - ":VectorToSCF", - ":VectorToSPIRV", - ":X86Vector", - ":X86VectorTransforms", - ], -) - -cc_binary( - name = "mlir-lsp-server", - srcs = ["tools/mlir-lsp-server/mlir-lsp-server.cpp"], - includes = ["include"], - deps = [ - ":AllPassesAndDialects", - ":IR", - ":MlirLspServerLib", - ], -) - -cc_binary( - name = "mlir-opt", - srcs = ["tools/mlir-opt/mlir-opt.cpp"], - local_defines = ["MLIR_INCLUDE_TESTS"], - deps = [ - ":AllPassesAndDialects", - ":Analysis", - ":IR", - ":MlirOptLib", - ":OpenMPDialect", - ":Pass", - ":QuantOps", - ":SCFToGPUPass", - ":Support", - ":Transforms", - "//llvm:AllTargetsCodeGens", - "//llvm:Support", - "//mlir/test:TestAffine", - "//mlir/test:TestAnalysis", - "//mlir/test:TestDLTI", - "//mlir/test:TestDialect", - "//mlir/test:TestGPU", - "//mlir/test:TestIR", - "//mlir/test:TestLinalg", - "//mlir/test:TestMath", - "//mlir/test:TestMemRef", - "//mlir/test:TestPass", - "//mlir/test:TestReducer", - "//mlir/test:TestRewrite", - "//mlir/test:TestSCF", - "//mlir/test:TestSPIRV", - "//mlir/test:TestShapeDialect", - "//mlir/test:TestStandardOps", - "//mlir/test:TestStandardToLLVM", - "//mlir/test:TestTosaDialect", - "//mlir/test:TestTransforms", - "//mlir/test:TestTypeDialect", - "//mlir/test:TestVector", - ], -) - -cc_library( - name = "MlirJitRunner", - srcs = ["lib/ExecutionEngine/JitRunner.cpp"], - hdrs = ["include/mlir/ExecutionEngine/JitRunner.h"], - includes = ["include"], - deps = [ - ":AllPassesAndDialects", - ":ExecutionEngine", - ":ExecutionEngineUtils", - ":IR", - ":LLVMDialect", - ":LLVMToLLVMIRTranslation", - ":OpenACCToLLVMIRTranslation", - ":OpenMPToLLVMIRTranslation", - ":Parser", - ":Pass", - ":SCFToStandard", - ":Support", - "//llvm:Core", - "//llvm:OrcJIT", - "//llvm:Support", - ], -) - -cc_library( - name = "mlir_c_runner_utils", - srcs = [ - "lib/ExecutionEngine/CRunnerUtils.cpp", - "lib/ExecutionEngine/SparseTensorUtils.cpp", - ], - hdrs = [ - "include/mlir/ExecutionEngine/CRunnerUtils.h", - "include/mlir/ExecutionEngine/SparseTensorUtils.h", - ], - includes = ["include"], -) - -cc_library( - name = "mlir_async_runtime_api", - hdrs = ["include/mlir/ExecutionEngine/AsyncRuntime.h"], - includes = ["include"], -) - -cc_library( - name = "mlir_async_runtime", - srcs = ["lib/ExecutionEngine/AsyncRuntime.cpp"], - copts = ["-Dmlir_async_runtime_EXPORTS"], - deps = [ - ":mlir_async_runtime_api", - "//llvm:Support", - ], -) - -cc_library( - name = "mlir_runner_utils", - srcs = ["lib/ExecutionEngine/RunnerUtils.cpp"], - hdrs = ["include/mlir/ExecutionEngine/RunnerUtils.h"], - includes = ["include"], - deps = [":mlir_c_runner_utils"], -) - -cc_binary( - name = "mlir-cpu-runner", - srcs = ["tools/mlir-cpu-runner/mlir-cpu-runner.cpp"], - deps = [ - ":AllToLLVMIRTranslations", - ":ExecutionEngineUtils", - ":IR", - ":LLVMDialect", - ":LLVMToLLVMIRTranslation", - ":MlirJitRunner", - ":OpenACCToLLVMIRTranslation", - ":OpenMPToLLVMIRTranslation", - ":ToLLVMIRTranslation", - "//llvm:AsmParser", - "//llvm:Support", - "//llvm:X86AsmParser", - ], -) - -# This target provides the headers from LLVM's Support target without any of -# the symbols. In particular, it does not contain the static registration code -# which may be executed by at most one shared library loaded by ORCJit. Direct -# dependencies need to avoid requiring symbols from LLVMSupport by adding -# copts = ["-DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1"]. -# -# Bazel links the dependencies' object files instead of the archives, which -# means that symbols are linked in even if none are used. The LLVM cmake build -# on the other hand links archives (or shared libraries, depending on -# BUILD_SHARED_LIBS), skipping them if none of the symbols are used. -# See also https://reviews.llvm.org/D95613. -cc_headers_only( - name = "LLVMSupportHeaders", - src = "//llvm:Support", -) - -cc_library( - name = "mlir_cuda_runtime", - srcs = ["lib/ExecutionEngine/CudaRuntimeWrappers.cpp"], - # Prevent needing EnableABIBreakingChecks symbol from LLVMSupport. - copts = ["-DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1"], - tags = [ - "manual", # External dependency - "nobuildkite", # TODO(gcmn): Add support for this target - ], - deps = [ - ":LLVMSupportHeaders", - ":mlir_c_runner_utils", - "@cuda//:cuda_headers", - "@cuda//:libcuda", - ], -) - -cc_library( - name = "VulkanRuntime", - srcs = ["tools/mlir-vulkan-runner/VulkanRuntime.cpp"], - hdrs = ["tools/mlir-vulkan-runner/VulkanRuntime.h"], - tags = [ - "manual", # External dependency - ], - deps = [ - ":IR", - ":Pass", - ":SPIRVDialect", - ":SideEffectInterfaces", - ":StandardOps", - ":Support", - "//llvm:Support", - "@vulkan_headers", - "@vulkan_sdk//:sdk", - ], -) - -cc_binary( - name = "tools/libvulkan-runtime-wrappers.so", - srcs = ["tools/mlir-vulkan-runner/vulkan-runtime-wrappers.cpp"], - linkshared = True, - tags = [ - "manual", # External dependency - ], - deps = [ - ":VulkanRuntime", - "//llvm:Support", - ], -) - -cc_binary( - name = "mlir-vulkan-runner", - srcs = ["tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp"], - deps = [ - ":ArithmeticDialect", - ":ExecutionEngineUtils", - ":GPUDialect", - ":GPUToSPIRV", - ":GPUToVulkanTransforms", - ":GPUTransforms", - ":LLVMCommonConversion", - ":LLVMDialect", - ":LLVMToLLVMIRTranslation", - ":MemRefDialect", - ":MemRefToLLVM", - ":MemRefTransforms", - ":MlirJitRunner", - ":Pass", - ":ReconcileUnrealizedCasts", - ":SPIRVDialect", - ":SPIRVTransforms", - ":StandardOps", - ":StandardToLLVM", - ":StandardToSPIRV", - ":ToLLVMIRTranslation", - "//llvm:Support", - ], -) - -cc_binary( - name = "mlir-spirv-cpu-runner", - srcs = ["tools/mlir-spirv-cpu-runner/mlir-spirv-cpu-runner.cpp"], - deps = [ - ":ArithmeticDialect", - ":ExecutionEngineUtils", - ":GPUDialect", - ":GPUToSPIRV", - ":GPUTransforms", - ":IR", - ":LLVMDialect", - ":LLVMToLLVMIRTranslation", - ":MemRefDialect", - ":MlirJitRunner", - ":Pass", - ":SPIRVConversion", - ":SPIRVDialect", - ":SPIRVToLLVM", - ":SPIRVTransforms", - ":StandardOps", - ":StandardToLLVM", - ":ToLLVMIRTranslation", - "//llvm:Core", - "//llvm:Linker", - "//llvm:Support", - ], -) - -cc_library( - name = "TableGen", - srcs = glob(["lib/TableGen/*.cpp"]), - hdrs = glob(["include/mlir/TableGen/*.h"]), - includes = ["include"], - deps = [ - ":Support", - "//llvm:Support", - "//llvm:TableGen", - ], -) - -cc_library( - name = "MlirTableGenMain", - srcs = ["tools/mlir-tblgen/mlir-tblgen.cpp"], - includes = ["include"], - deps = [ - ":Support", - ":TableGen", - "//llvm:Support", - "//llvm:TableGen", - "//llvm:config", - ], -) - -cc_binary( - name = "mlir-tblgen", - srcs = glob([ - "tools/mlir-tblgen/*.h", - "tools/mlir-tblgen/*.cpp", - ]), - deps = [ - ":MlirTableGenMain", - ":Support", - ":TableGen", - "//llvm:Support", - "//llvm:TableGen", - "//llvm:config", - ], -) - -cc_binary( - name = "mlir-linalg-ods-yaml-gen", - srcs = [ - "tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp", - ], - deps = [ - ":IR", - ":Parser", - ":Support", - "//llvm:Support", - "//llvm:TableGen", - "//llvm:config", - ], -) - -## OpenACC dialect - -# TODO(gcmn): This is sticking td files in a cc_library -gentbl_cc_library( - name = "AccCommonGen", - includes = ["/llvm/include"], - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-directive-decl", - "-directives-dialect=OpenACC", - ], - "include/mlir/Dialect/OpenACC/AccCommon.td", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "//llvm:include/llvm/Frontend/OpenACC/ACC.td", - deps = ["//llvm:acc_td_files"], -) - -td_library( - name = "OpenAccOpsTdFiles", - srcs = [ - "include/mlir/Dialect/OpenACC/AccCommon.td", - "include/mlir/Dialect/OpenACC/OpenACCOps.td", - ], - includes = ["include"], - deps = [":OpBaseTdFiles"], -) - -gentbl_cc_library( - name = "OpenACCOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-dialect-decls", - "-dialect=acc", - ], - "include/mlir/Dialect/OpenACC/OpenACCOpsDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=acc", - ], - "include/mlir/Dialect/OpenACC/OpenACCOpsDialect.cpp.inc", - ), - ( - ["-gen-op-decls"], - "include/mlir/Dialect/OpenACC/OpenACCOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/OpenACC/OpenACCOps.cpp.inc", - ), - ( - ["-gen-enum-decls"], - "include/mlir/Dialect/OpenACC/OpenACCOpsEnums.h.inc", - ), - ( - ["-gen-enum-defs"], - "include/mlir/Dialect/OpenACC/OpenACCOpsEnums.cpp.inc", - ), - ( - [ - "-gen-attrdef-decls", - "-attrdefs-dialect=acc", - ], - "include/mlir/Dialect/OpenACC/OpenACCOpsAttributes.h.inc", - ), - ( - [ - "-gen-attrdef-defs", - "-attrdefs-dialect=acc", - ], - "include/mlir/Dialect/OpenACC/OpenACCOpsAttributes.cpp.inc", - ), - ( - ["-gen-op-doc"], - "g3doc/Dialects/OpenACC/OpenACCOps.md", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/OpenACC/OpenACCOps.td", - deps = [":OpenAccOpsTdFiles"], -) - -cc_library( - name = "OpenACCDialect", - srcs = glob( - [ - "lib/Dialect/OpenACC/IR/*.cpp", - "lib/Dialect/OpenACC/IR/*.h", - ], - ), - hdrs = glob([ - "include/mlir/Dialect/OpenACC/*.h", - ]), - includes = ["include"], - deps = [ - ":IR", - ":OpenACCOpsIncGen", - ":Transforms", - "//llvm:Support", - ], -) - -## OpenMP dialect - -# TODO(gcmn): This is sticking td files in a cc_library -gentbl_cc_library( - name = "OmpCommonTdGen", - includes = ["/llvm/include"], - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-directive-decl", - "-directives-dialect=OpenMP", - ], - "include/mlir/Dialect/OpenMP/OmpCommon.td", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "//llvm:include/llvm/Frontend/OpenMP/OMP.td", - deps = [ - ":OpBaseTdFiles", - "//llvm:omp_td_files", - ], -) - -td_library( - name = "OpenMPOpsTdFiles", - srcs = [ - "include/mlir/Dialect/OpenMP/OmpCommon.td", - "include/mlir/Dialect/OpenMP/OpenMPOps.td", - "include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td", - ], - deps = [ - ":LLVMOpsTdFiles", - ":OpBaseTdFiles", - ], -) - -gentbl_cc_library( - name = "OpenMPOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/OpenMP/OpenMPOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/OpenMP/OpenMPOps.cpp.inc", - ), - ( - ["-gen-enum-decls"], - "include/mlir/Dialect/OpenMP/OpenMPOpsEnums.h.inc", - ), - ( - ["-gen-enum-defs"], - "include/mlir/Dialect/OpenMP/OpenMPOpsEnums.cpp.inc", - ), - ( - [ - "-gen-dialect-decls", - "-dialect=omp", - ], - "include/mlir/Dialect/OpenMP/OpenMPOpsDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=omp", - ], - "include/mlir/Dialect/OpenMP/OpenMPOpsDialect.cpp.inc", - ), - ( - ["-gen-type-interface-decls"], - "include/mlir/Dialect/OpenMP/OpenMPTypeInterfaces.h.inc", - ), - ( - ["-gen-type-interface-defs"], - "include/mlir/Dialect/OpenMP/OpenMPTypeInterfaces.cpp.inc", - ), - ( - [ - "-gen-attrdef-decls", - "-attrdefs-dialect=omp", - ], - "include/mlir/Dialect/OpenMP/OpenMPOpsAttributes.h.inc", - ), - ( - [ - "-gen-attrdef-defs", - "-attrdefs-dialect=omp", - ], - "include/mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc", - ), - ( - ["-gen-op-doc"], - "g3doc/Dialects/OpenMP/OpenMPOps.md", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/OpenMP/OpenMPOps.td", - deps = [":OpenMPOpsTdFiles"], -) - -gentbl_cc_library( - name = "OpenMPInterfacesIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td", - deps = [":OpenMPOpsTdFiles"], -) - -cc_library( - name = "OpenMPDialect", - srcs = glob( - [ - "lib/Dialect/OpenMP/IR/*.cpp", - "lib/Dialect/OpenMP/IR/*.h", - ], - ), - hdrs = glob([ - "include/mlir/Dialect/OpenMP/*.h", - ]), - includes = ["include"], - deps = [ - ":ControlFlowInterfaces", - ":IR", - ":LLVMDialect", - ":OpenMPInterfacesIncGen", - ":OpenMPOpsIncGen", - "//llvm:Support", - ], -) - -cc_library( - name = "OpenACCToSCF", - srcs = glob([ - "lib/Conversion/OpenACCToSCF/*.cpp", - "lib/Conversion/OpenACCToSCF/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/OpenACCToSCF/*.h", - ]), - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":ConversionPassIncGen", - ":IR", - ":OpenACCDialect", - ":Pass", - ":SCFDialect", - ":StandardOps", - ":Transforms", - ], -) - -cc_library( - name = "OpenACCToLLVM", - srcs = glob([ - "lib/Conversion/OpenACCToLLVM/*.cpp", - "lib/Conversion/OpenACCToLLVM/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/OpenACCToLLVM/*.h", - ]), - includes = ["include"], - deps = [ - ":ConversionPassIncGen", - ":IR", - ":LLVMCommonConversion", - ":LLVMDialect", - ":OpenACCDialect", - ":Pass", - ":StandardOps", - ":Transforms", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "OpenMPToLLVM", - srcs = glob([ - "lib/Conversion/OpenMPToLLVM/*.cpp", - "lib/Conversion/OpenMPToLLVM/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/OpenMPToLLVM/*.h", - ]), - includes = ["include"], - deps = [ - ":ArithmeticToLLVM", - ":ConversionPassIncGen", - ":IR", - ":LLVMCommonConversion", - ":LLVMDialect", - ":MemRefToLLVM", - ":OpenMPDialect", - ":Pass", - ":StandardOps", - ":StandardToLLVM", - ":Transforms", - "//llvm:Core", - "//llvm:Support", - ], -) - -td_library( - name = "QuantizationOpsTdFiles", - srcs = [ - "include/mlir/Dialect/Quant/QuantOps.td", - "include/mlir/Dialect/Quant/QuantOpsBase.td", - ], - includes = ["include"], - deps = [ - ":InferTypeOpInterfaceTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "QuantOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/Quant/QuantOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/Quant/QuantOps.cpp.inc", - ), - ( - ["-gen-dialect-decls"], - "include/mlir/Dialect/Quant/QuantOpsDialect.h.inc", - ), - ( - ["-gen-dialect-defs"], - "include/mlir/Dialect/Quant/QuantOpsDialect.cpp.inc", - ), - ( - ["-gen-op-doc"], - "g3doc/Dialects/QuantOps/QuantOps.md", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Quant/QuantOps.td", - deps = [":QuantizationOpsTdFiles"], -) - -gentbl_cc_library( - name = "QuantPassIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-pass-decls", - "-name=Quant", - ], - "include/mlir/Dialect/Quant/Passes.h.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Quant/Passes.td", - deps = [":PassBaseTdFiles"], -) - -cc_library( - name = "QuantOps", - srcs = [ - "lib/Dialect/Quant/IR/QuantOps.cpp", - "lib/Dialect/Quant/IR/QuantTypes.cpp", - "lib/Dialect/Quant/IR/TypeDetail.h", - "lib/Dialect/Quant/IR/TypeParser.cpp", - "lib/Dialect/Quant/Transforms/ConvertConst.cpp", - "lib/Dialect/Quant/Transforms/ConvertSimQuant.cpp", - "lib/Dialect/Quant/Transforms/PassDetail.h", - "lib/Dialect/Quant/Utils/FakeQuantSupport.cpp", - "lib/Dialect/Quant/Utils/QuantizeUtils.cpp", - "lib/Dialect/Quant/Utils/UniformSupport.cpp", - ], - hdrs = [ - "include/mlir/Dialect/Quant/FakeQuantSupport.h", - "include/mlir/Dialect/Quant/Passes.h", - "include/mlir/Dialect/Quant/QuantOps.h", - "include/mlir/Dialect/Quant/QuantTypes.h", - "include/mlir/Dialect/Quant/QuantizeUtils.h", - "include/mlir/Dialect/Quant/UniformSupport.h", - ], - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":IR", - ":Pass", - ":QuantOpsIncGen", - ":QuantPassIncGen", - ":SideEffectInterfaces", - ":TransformUtils", - "//llvm:Support", - ], -) - -td_library( - name = "LinalgOpsTdFiles", - srcs = [ - "include/mlir/Dialect/Linalg/IR/LinalgBase.td", - "include/mlir/Dialect/Linalg/IR/LinalgOps.td", - ], - includes = ["include"], - deps = [ - ":ControlFlowInterfacesTdFiles", - ":InferTypeOpInterfaceTdFiles", - ":LoopLikeInterfaceTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ":TilingInterfaceTdFiles", - ":ViewLikeInterfaceTdFiles", - ], -) - -gentbl_cc_library( - name = "LinalgOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/Linalg/IR/LinalgOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/Linalg/IR/LinalgOps.cpp.inc", - ), - ( - [ - "-gen-dialect-decls", - "-dialect=linalg", - ], - "include/mlir/Dialect/Linalg/IR/LinalgOpsDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=linalg", - ], - "include/mlir/Dialect/Linalg/IR/LinalgOpsDialect.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Linalg/IR/LinalgOps.td", - deps = [":LinalgOpsTdFiles"], -) - -genlinalg( - name = "LinalgNamedStructuredOpsYamlIncGen", - src = "include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml", - linalg_outs = [ - ( - "-o-impl=$@", - "include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yamlgen.cpp.inc", - ), - ( - "-o-ods-decl=$@", - "include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yamlgen.td", - ), - ], - linalggen = ":mlir-linalg-ods-yaml-gen", -) - -td_library( - name = "LinalgStructuredOpsTdFiles", - srcs = [ - "include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td", - "include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yamlgen.td", - "include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td", - ], - includes = ["include"], - deps = [ - ":CopyOpInterfaceTdFiles", - ":LinalgOpsTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "LinalgStructuredOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td", - deps = [":LinalgStructuredOpsTdFiles"], -) - -gentbl_cc_library( - name = "LinalgInterfacesIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/Dialect/Linalg/IR/LinalgInterfaces.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td", - deps = [":LinalgStructuredOpsTdFiles"], -) - -td_library( - name = "BufferizableOpInterfaceTdFiles", - srcs = [ - "include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.td", - ], - includes = ["include"], - deps = [ - ":OpBaseTdFiles", - ], -) - -gentbl_cc_library( - name = "BufferizableOpInterfaceIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.td", - deps = [ - ":BufferizableOpInterfaceTdFiles", - ], -) - -cc_library( - name = "AffineBufferizableOpInterfaceImpl", - srcs = [ - "lib/Dialect/Linalg/ComprehensiveBufferize/AffineInterfaceImpl.cpp", - ], - hdrs = [ - "include/mlir/Dialect/Linalg/ComprehensiveBufferize/AffineInterfaceImpl.h", - ], - includes = ["include"], - deps = [ - ":Affine", - ":BufferizationDialect", - "//llvm:Support", - ], -) - -cc_library( - name = "LinalgBufferizableOpInterfaceImpl", - srcs = [ - "lib/Dialect/Linalg/ComprehensiveBufferize/LinalgInterfaceImpl.cpp", - ], - hdrs = [ - "include/mlir/Dialect/Linalg/ComprehensiveBufferize/LinalgInterfaceImpl.h", - ], - includes = ["include"], - deps = [ - ":BufferizationDialect", - ":BufferizationTransforms", - ":IR", - ":LinalgOps", - ":LinalgStructuredOpsIncGen", - ":TensorDialect", - ], -) - -td_library( - name = "LinalgDocTdFiles", - srcs = ["include/mlir/Dialect/Linalg/IR/LinalgDoc.td"], - includes = ["include"], - deps = [ - ":LinalgOpsTdFiles", - ":LinalgStructuredOpsTdFiles", - ], -) - -gentbl_cc_library( - name = "LinalgDocIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-doc"], - "g3doc/Dialects/Linalg/LinalgOps.md", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Linalg/IR/LinalgDoc.td", - deps = [":LinalgDocTdFiles"], -) - -cc_library( - name = "LinalgToLLVM", - srcs = glob([ - "lib/Conversion/LinalgToLLVM/*.cpp", - "lib/Conversion/LinalgToLLVM/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/LinalgToLLVM/*.h", - ]), - includes = ["include"], - deps = [ - ":AffineToStandard", - ":Analysis", - ":ConversionPassIncGen", - ":IR", - ":LLVMCommonConversion", - ":LLVMDialect", - ":LinalgOps", - ":LinalgTransforms", - ":MemRefToLLVM", - ":Pass", - ":SCFDialect", - ":SCFToStandard", - ":StandardOps", - ":Support", - ":Transforms", - ":VectorToLLVM", - ":VectorToSCF", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "LinalgToStandard", - srcs = glob([ - "lib/Conversion/LinalgToStandard/*.cpp", - "lib/Conversion/LinalgToStandard/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/LinalgToStandard/*.h", - ]), - includes = ["include"], - deps = [ - ":Affine", - ":ConversionPassIncGen", - ":IR", - ":LinalgOps", - ":LinalgTransforms", - ":MemRefDialect", - ":Pass", - ":SCFDialect", - ":StandardOps", - ":Support", - ":Transforms", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "LinalgToSPIRV", - srcs = glob([ - "lib/Conversion/LinalgToSPIRV/*.cpp", - "lib/Conversion/LinalgToSPIRV/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/LinalgToSPIRV/*.h", - ]), - includes = ["include"], - deps = [ - ":ConversionPassIncGen", - ":DialectUtils", - ":IR", - ":LinalgOps", - ":LinalgTransforms", - ":Pass", - ":SPIRVConversion", - ":SPIRVDialect", - ":StandardOps", - ":TransformUtils", - ], -) - -cc_library( - name = "LinalgOps", - srcs = [ - "lib/Dialect/Linalg/IR/LinalgDialect.cpp", - "lib/Dialect/Linalg/IR/LinalgOps.cpp", - ], - hdrs = [ - "include/mlir/Dialect/Linalg/IR/Linalg.h", - ], - includes = ["include"], - deps = [ - ":Affine", - ":ArithmeticDialect", - ":BufferizationDialect", - ":CopyOpInterface", - ":DialectUtils", - ":IR", - ":InferTypeOpInterface", - ":LinalgInterfaces", - ":LinalgInterfacesIncGen", - ":LinalgNamedStructuredOpsYamlIncGen", - ":LinalgOpsIncGen", - ":LinalgStructuredOpsIncGen", - ":MathDialect", - ":MemRefDialect", - ":Parser", - ":SCFDialect", - ":SideEffectInterfaces", - ":StandardOps", - ":Support", - ":TensorDialect", - ":TilingInterface", - ":ViewLikeInterface", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "LinalgPassIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-pass-decls", - "-name=Linalg", - ], - "include/mlir/Dialect/Linalg/Passes.h.inc", - ), - ( - [ - "-gen-pass-capi-header", - "--prefix=Linalg", - ], - "include/mlir/Dialect/Linalg/Passes.capi.h.inc", - ), - ( - [ - "-gen-pass-capi-impl", - "--prefix=Linalg", - ], - "include/mlir/Dialect/Linalg/Passes.capi.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Linalg/Passes.td", - deps = [":PassBaseTdFiles"], -) - -cc_library( - name = "LinalgTransforms", - srcs = glob([ - "lib/Dialect/Linalg/Transforms/*.cpp", - "lib/Dialect/Linalg/Transforms/*.h", - ]) + [ - "lib/Dialect/Linalg/Analysis/DependenceAnalysis.cpp", - "lib/Dialect/Linalg/Utils/Utils.cpp", - ], - hdrs = [ - "include/mlir/Dialect/Linalg/Analysis/DependenceAnalysis.h", - "include/mlir/Dialect/Linalg/Passes.h", - "include/mlir/Dialect/Linalg/Transforms/CodegenStrategy.h", - "include/mlir/Dialect/Linalg/Transforms/HoistPadding.h", - "include/mlir/Dialect/Linalg/Transforms/Hoisting.h", - "include/mlir/Dialect/Linalg/Transforms/Transforms.h", - "include/mlir/Dialect/Linalg/Utils/Utils.h", - ], - includes = ["include"], - deps = [ - ":Affine", - ":AffineAnalysis", - ":AffineBufferizableOpInterfaceImpl", - ":AffineUtils", - ":Analysis", - ":ArithmeticDialect", - ":ArithmeticTransforms", - ":BufferizationDialect", - ":BufferizationTransforms", - ":ComplexDialect", - ":DialectUtils", - ":IR", - ":InferTypeOpInterface", - ":LinalgBufferizableOpInterfaceImpl", - ":LinalgOps", - ":LinalgPassIncGen", - ":LinalgStructuredOpsIncGen", - ":MathDialect", - ":MemRefDialect", - ":ModuleBufferization", - ":Pass", - ":SCFDialect", - ":SCFTransforms", - ":SCFUtils", - ":StandardOps", - ":StandardOpsTransforms", - ":Support", - ":TensorDialect", - ":TensorTransforms", - ":TensorUtils", - ":TransformUtils", - ":VectorOps", - ":VectorToSCF", - ":VectorTransforms", - ":VectorUtils", - ":X86VectorTransforms", - "//llvm:Support", - ], -) - -cc_library( - name = "ModuleBufferization", - srcs = [ - "lib/Dialect/Linalg/ComprehensiveBufferize/ModuleBufferization.cpp", - ], - hdrs = [ - "include/mlir/Dialect/Linalg/ComprehensiveBufferize/ModuleBufferization.h", - ], - includes = ["include"], - deps = [ - ":BufferizationDialect", - ":BufferizationTransforms", - ":DialectUtils", - ":IR", - ":MemRefDialect", - ":StandardOps", - ":Support", - "//llvm:Support", - ], -) - -cc_library( - name = "TilingInterface", - srcs = ["lib/Interfaces/TilingInterface.cpp"], - hdrs = ["include/mlir/Interfaces/TilingInterface.h"], - includes = ["include"], - deps = [ - ":IR", - ":Support", - ":TilingInterfaceIncGen", - ":ViewLikeInterface", - "//llvm:Support", - ], -) - -td_library( - name = "VectorOpsTdFiles", - srcs = ["include/mlir/Dialect/Vector/IR/VectorOps.td"], - includes = ["include"], - deps = [ - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ":VectorInterfacesTdFiles", - ":ViewLikeInterfaceTdFiles", - ], -) - -gentbl_cc_library( - name = "VectorOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/Vector/IR/VectorOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/Vector/IR/VectorOps.cpp.inc", - ), - ( - [ - "-gen-dialect-decls", - "-dialect=vector", - ], - "include/mlir/Dialect/Vector/IR/VectorOpsDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=vector", - ], - "include/mlir/Dialect/Vector/IR/VectorOpsDialect.cpp.inc", - ), - ( - ["-gen-enum-decls"], - "include/mlir/Dialect/Vector/IR/VectorOpsEnums.h.inc", - ), - ( - ["-gen-enum-defs"], - "include/mlir/Dialect/Vector/IR/VectorOpsEnums.cpp.inc", - ), - ( - ["-gen-op-doc"], - "g3doc/Dialects/Vector/VectorOps.md", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Vector/IR/VectorOps.td", - deps = [":VectorOpsTdFiles"], -) - -cc_library( - name = "VectorToLLVM", - srcs = glob([ - "lib/Conversion/VectorToLLVM/*.cpp", - "lib/Conversion/VectorToLLVM/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/VectorToLLVM/*.h", - ]), - includes = ["include"], - deps = [ - ":AMX", - ":AMXTransforms", - ":ArithmeticDialect", - ":ArmNeon", - ":ArmSVE", - ":ArmSVETransforms", - ":ConversionPassIncGen", - ":DialectUtils", - ":IR", - ":LLVMCommonConversion", - ":LLVMDialect", - ":MemRefDialect", - ":Pass", - ":StandardOps", - ":Support", - ":ToLLVMIRTranslation", - ":Transforms", - ":VectorOps", - ":VectorTransforms", - ":X86Vector", - ":X86VectorTransforms", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "VectorToGPU", - srcs = glob([ - "lib/Conversion/VectorToGPU/*.cpp", - "lib/Conversion/VectorToGPU/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/VectorToGPU/*.h", - ]), - includes = ["include"], - deps = [ - ":Affine", - ":Analysis", - ":ArithmeticDialect", - ":ConversionPassIncGen", - ":DialectUtils", - ":GPUDialect", - ":IR", - ":LLVMDialect", - ":MemRefDialect", - ":Pass", - ":SCFDialect", - ":StandardOps", - ":StandardToLLVM", - ":Support", - ":Transforms", - ":VectorOps", - ":VectorUtils", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "VectorToSCF", - srcs = glob([ - "lib/Conversion/VectorToSCF/*.cpp", - "lib/Conversion/VectorToSCF/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/VectorToSCF/*.h", - ]), - includes = ["include"], - deps = [ - ":Affine", - ":AffineUtils", - ":ArithmeticDialect", - ":ConversionPassIncGen", - ":IR", - ":LLVMDialect", - ":MemRefDialect", - ":Pass", - ":SCFDialect", - ":StandardOps", - ":StandardToLLVM", - ":Support", - ":Transforms", - ":VectorOps", - ":VectorTransforms", - "//llvm:Core", - "//llvm:Support", - ], -) - -td_library( - name = "TosaDialectTdFiles", - srcs = glob(["include/mlir/Dialect/Tosa/IR/*.td"]), - deps = [ - ":InferTypeOpInterfaceTdFiles", - ":LoopLikeInterfaceTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "TosaDialectIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/Tosa/IR/TosaOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/Tosa/IR/TosaOps.cpp.inc", - ), - ( - ["-gen-struct-attr-decls"], - "include/mlir/Dialect/Tosa/IR/TosaStructs.h.inc", - ), - ( - ["-gen-struct-attr-defs"], - "include/mlir/Dialect/Tosa/IR/TosaStructs.cpp.inc", - ), - ( - ["-gen-dialect-decls"], - "include/mlir/Dialect/Tosa/IR/TosaOpsDialect.h.inc", - ), - ( - ["-gen-dialect-defs"], - "include/mlir/Dialect/Tosa/IR/TosaOpsDialect.cpp.inc", - ), - ( - ["-gen-op-doc"], - "g3doc/Dialects/Tosa/TosaOps.md", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Tosa/IR/TosaOps.td", - deps = [":TosaDialectTdFiles"], -) - -gentbl_cc_library( - name = "TosaInterfacesIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/Dialect/Tosa/IR/TosaInterfaces.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/Dialect/Tosa/IR/TosaInterfaces.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Tosa/IR/TosaInterfaces.td", - deps = [":TosaDialectTdFiles"], -) - -gentbl_cc_library( - name = "TosaPassIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-pass-decls", - "-name=TosaOpt", - ], - "include/mlir/Dialect/Tosa/Transforms/Passes.h.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Tosa/Transforms/Passes.td", - deps = [":PassBaseTdFiles"], -) - -cc_library( - name = "TosaDialect", - srcs = glob([ - "lib/Dialect/Tosa/IR/*.cpp", - "lib/Dialect/Tosa/IR/*.h", - "lib/Dialect/Tosa/Utils/*.cpp", - "lib/Dialect/Tosa/Transforms/*.cpp", - ]), - hdrs = glob([ - "include/mlir/Dialect/Tosa/IR/*.h", - "include/mlir/Dialect/Tosa/Utils/*.h", - "include/mlir/Dialect/Tosa/Transforms/*.h", - ]), - includes = ["include"], - deps = [ - ":Analysis", - ":ArithmeticDialect", - ":Dialect", - ":DialectUtils", - ":IR", - ":InferTypeOpInterface", - ":LoopLikeInterface", - ":Pass", - ":QuantOps", - ":StandardOps", - ":TensorDialect", - ":TosaDialectIncGen", - ":TosaInterfacesIncGen", - ":TosaPassIncGen", - ":TransformUtils", - "//llvm:Support", - ], -) - -cc_library( - name = "TosaToLinalg", - srcs = glob([ - "lib/Conversion/TosaToLinalg/*.cpp", - "lib/Conversion/TosaToLinalg/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/TosaToLinalg/*.h", - ]), - includes = [ - "include", - "lib/Conversion/TosaToLinalg", - ], - deps = [ - ":ArithmeticDialect", - ":ConversionPassIncGen", - ":DialectUtils", - ":IR", - ":LinalgOps", - ":MathDialect", - ":Pass", - ":SCFDialect", - ":StandardOps", - ":TensorDialect", - ":TensorUtils", - ":TosaDialect", - ":Transforms", - ], -) - -cc_library( - name = "TosaToSCF", - srcs = glob([ - "lib/Conversion/TosaToSCF/*.cpp", - "lib/Conversion/TosaToSCF/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/TosaToSCF/*.h", - ]), - includes = [ - "include", - "lib/Conversion/TosaToSCF", - ], - deps = [ - ":ConversionPassIncGen", - ":IR", - ":Pass", - ":SCFDialect", - ":TensorDialect", - ":TosaDialect", - ":Transforms", - ], -) - -cc_library( - name = "TosaToStandard", - srcs = glob([ - "lib/Conversion/TosaToStandard/*.cpp", - "lib/Conversion/TosaToStandard/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/TosaToStandard/*.h", - ]), - includes = [ - "include", - "lib/Conversion/TosaToStandard", - ], - deps = [ - ":ArithmeticDialect", - ":ConversionPassIncGen", - ":IR", - ":Pass", - ":StandardOps", - ":TensorDialect", - ":TosaDialect", - ":Transforms", - ], -) - -td_library( - name = "ComplexOpsTdFiles", - srcs = [ - "include/mlir/Dialect/Complex/IR/ComplexBase.td", - "include/mlir/Dialect/Complex/IR/ComplexOps.td", - ], - includes = ["include"], - deps = [ - ":InferTypeOpInterfaceTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "ComplexBaseIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-dialect-decls", - "-dialect=complex", - ], - "include/mlir/Dialect/Complex/IR/ComplexOpsDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=complex", - ], - "include/mlir/Dialect/Complex/IR/ComplexOpsDialect.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Complex/IR/ComplexBase.td", - deps = [":ComplexOpsTdFiles"], -) - -gentbl_cc_library( - name = "ComplexOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/Complex/IR/ComplexOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/Complex/IR/ComplexOps.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Complex/IR/ComplexOps.td", - deps = [":ComplexOpsTdFiles"], -) - -cc_library( - name = "ComplexDialect", - srcs = glob( - [ - "lib/Dialect/Complex/IR/*.cpp", - "lib/Dialect/Complex/IR/*.h", - ], - ), - hdrs = ["include/mlir/Dialect/Complex/IR/Complex.h"], - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":ComplexBaseIncGen", - ":ComplexOpsIncGen", - ":IR", - ":InferTypeOpInterface", - ":SideEffectInterfaces", - ":Support", - ":VectorInterfaces", - "//llvm:Support", - ], -) - -cc_library( - name = "ComplexToLLVM", - srcs = glob([ - "lib/Conversion/ComplexToLLVM/*.cpp", - "lib/Conversion/ComplexToLLVM/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/ComplexToLLVM/*.h", - ]), - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":ComplexDialect", - ":ConversionPassIncGen", - ":IR", - ":LLVMCommonConversion", - ":LLVMDialect", - ":Pass", - ":StandardOps", - ":Support", - ":Transforms", - "//llvm:Core", - "//llvm:Support", - ], -) - -cc_library( - name = "ComplexToStandard", - srcs = glob([ - "lib/Conversion/ComplexToStandard/*.cpp", - "lib/Conversion/ComplexToStandard/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/ComplexToStandard/*.h", - ]), - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":ComplexDialect", - ":ConversionPassIncGen", - ":IR", - ":MathDialect", - ":Pass", - ":StandardOps", - ":Transforms", - ], -) - -exports_files([ - "include/mlir/Interfaces/CallInterfaces.h", - "include/mlir/Interfaces/CastInterfaces.h", - "include/mlir/Interfaces/ControlFlowInterfaces.h", - "include/mlir/Transforms/InliningUtils.h", -]) - -td_library( - name = "ArithmeticOpsTdFiles", - srcs = [ - "include/mlir/Dialect/Arithmetic/IR/ArithmeticBase.td", - "include/mlir/Dialect/Arithmetic/IR/ArithmeticOps.td", - ], - includes = ["include"], - deps = [ - ":CastInterfacesTdFiles", - ":InferTypeOpInterfaceTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ":VectorInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "ArithmeticBaseIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-dialect-decls", - "-dialect=arith", - ], - "include/mlir/Dialect/Arithmetic/IR/ArithmeticOpsDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=arith", - ], - "include/mlir/Dialect/Arithmetic/IR/ArithmeticOpsDialect.cpp.inc", - ), - ( - ["-gen-enum-decls"], - "include/mlir/Dialect/Arithmetic/IR/ArithmeticOpsEnums.h.inc", - ), - ( - ["-gen-enum-defs"], - "include/mlir/Dialect/Arithmetic/IR/ArithmeticOpsEnums.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Arithmetic/IR/ArithmeticBase.td", - deps = [":ArithmeticOpsTdFiles"], -) - -gentbl_cc_library( - name = "ArithmeticOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/Arithmetic/IR/ArithmeticOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/Arithmetic/IR/ArithmeticOps.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Arithmetic/IR/ArithmeticOps.td", - deps = [ - ":ArithmeticOpsTdFiles", - ], -) - -gentbl_cc_library( - name = "ArithmeticCanonicalizationIncGen", - strip_include_prefix = "include/mlir/Dialect/Arithmetic/IR", - tbl_outs = [ - ( - ["-gen-rewriters"], - "include/mlir/Dialect/Arithmetic/IR/ArithmeticCanonicalization.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "lib/Dialect/Arithmetic/IR/ArithmeticCanonicalization.td", - deps = [ - ":ArithmeticOpsTdFiles", - ":CastInterfacesTdFiles", - ":StdOpsTdFiles", - ], -) - -cc_library( - name = "ArithmeticDialect", - srcs = glob( - [ - "lib/Dialect/Arithmetic/IR/*.cpp", - "lib/Dialect/Arithmetic/IR/*.h", - ], - ), - hdrs = [ - "include/mlir/Dialect/Arithmetic/IR/Arithmetic.h", - "include/mlir/Transforms/InliningUtils.h", - ], - includes = ["include"], - deps = [ - ":ArithmeticBaseIncGen", - ":ArithmeticCanonicalizationIncGen", - ":ArithmeticOpsIncGen", - ":CommonFolders", - ":IR", - ":SideEffectInterfaces", - ":Support", - ":VectorInterfaces", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "ArithmeticPassIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-pass-decls", - "-name=Arithmetic", - ], - "include/mlir/Dialect/Arithmetic/Transforms/Passes.h.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Arithmetic/Transforms/Passes.td", - deps = [":PassBaseTdFiles"], -) - -cc_library( - name = "ArithmeticTransforms", - srcs = glob([ - "lib/Dialect/Arithmetic/Transforms/*.cpp", - "lib/Dialect/Arithmetic/Transforms/*.h", - ]), - hdrs = [ - "include/mlir/Dialect/Arithmetic/Transforms/BufferizableOpInterfaceImpl.h", - "include/mlir/Dialect/Arithmetic/Transforms/Passes.h", - ], - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":ArithmeticPassIncGen", - ":BufferizationDialect", - ":BufferizationTransforms", - ":IR", - ":MemRefDialect", - ":Pass", - ":StandardOps", - ":Support", - ":TransformUtils", - ":Transforms", - "//llvm:Support", - ], -) - -td_library( - name = "MathOpsTdFiles", - srcs = [ - "include/mlir/Dialect/Math/IR/MathBase.td", - "include/mlir/Dialect/Math/IR/MathOps.td", - ], - includes = ["include"], - deps = [ - ":InferTypeOpInterfaceTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ":VectorInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "MathBaseIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-dialect-decls", - "-dialect=math", - ], - "include/mlir/Dialect/Math/IR/MathOpsDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=math", - ], - "include/mlir/Dialect/Math/IR/MathOpsDialect.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Math/IR/MathBase.td", - deps = [":MathOpsTdFiles"], -) - -gentbl_cc_library( - name = "MathOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/Math/IR/MathOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/Math/IR/MathOps.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Math/IR/MathOps.td", - deps = [":MathOpsTdFiles"], -) - -cc_library( - name = "MathDialect", - srcs = glob( - [ - "lib/Dialect/Math/IR/*.cpp", - "lib/Dialect/Math/IR/*.h", - ], - ), - hdrs = [ - "include/mlir/Dialect/Math/IR/Math.h", - "include/mlir/Transforms/InliningUtils.h", - ], - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":IR", - ":MathBaseIncGen", - ":MathOpsIncGen", - ":SideEffectInterfaces", - ":Support", - ":VectorInterfaces", - "//llvm:Support", - ], -) - -cc_library( - name = "MathTransforms", - srcs = glob([ - "lib/Dialect/Math/Transforms/*.cpp", - "lib/Dialect/Math/Transforms/*.h", - ]), - hdrs = glob(["include/mlir/Dialect/Math/Transforms/*.h"]), - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":DialectUtils", - ":IR", - ":MathDialect", - ":Pass", - ":SCFDialect", - ":StandardOps", - ":Support", - ":Transforms", - ":VectorOps", - ":VectorUtils", - ":X86Vector", - "//llvm:Support", - ], -) - -cc_library( - name = "MathToLibm", - srcs = glob([ - "lib/Conversion/MathToLibm/*.cpp", - "lib/Conversion/MathToLibm/*.h", - ]) + [":ConversionPassDetail"], - hdrs = glob([ - "include/mlir/Conversion/MathToLibm/*.h", - ]), - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":ConversionPassIncGen", - ":DialectUtils", - ":IR", - ":LLVMDialect", - ":MathDialect", - ":Pass", - ":StandardOps", - ":Support", - ":Transforms", - ":VectorOps", - ":VectorUtils", - "//llvm:Core", - "//llvm:Support", - ], -) - -td_library( - name = "MemRefOpsTdFiles", - srcs = [ - "include/mlir/Dialect/MemRef/IR/MemRefBase.td", - "include/mlir/Dialect/MemRef/IR/MemRefOps.td", - ], - includes = ["include"], - deps = [ - ":ArithmeticOpsTdFiles", - ":CastInterfacesTdFiles", - ":ControlFlowInterfacesTdFiles", - ":CopyOpInterfaceTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ":ViewLikeInterfaceTdFiles", - ], -) - -gentbl_cc_library( - name = "MemRefBaseIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-dialect-decls", - "-dialect=memref", - ], - "include/mlir/Dialect/MemRef/IR/MemRefOpsDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=memref", - ], - "include/mlir/Dialect/MemRef/IR/MemRefOpsDialect.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/MemRef/IR/MemRefBase.td", - deps = [":MemRefOpsTdFiles"], -) - -gentbl_cc_library( - name = "MemRefOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/MemRef/IR/MemRefOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/MemRef/IR/MemRefOps.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/MemRef/IR/MemRefOps.td", - deps = [":MemRefOpsTdFiles"], -) - -cc_library( - name = "MemRefDialect", - srcs = glob( - [ - "lib/Dialect/MemRef/IR/*.cpp", - "lib/Dialect/MemRef/IR/*.h", - "lib/Dialect/MemRef/Utils/*.cpp", - ], - ), - hdrs = [ - "include/mlir/Dialect/MemRef/IR/MemRef.h", - "include/mlir/Dialect/MemRef/Utils/MemRefUtils.h", - ], - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":ControlFlowInterfaces", - ":CopyOpInterface", - ":DialectUtils", - ":IR", - ":InferTypeOpInterface", - ":MemRefBaseIncGen", - ":MemRefOpsIncGen", - ":StandardOps", - ":ViewLikeInterface", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "MemRefPassIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-pass-decls", - "-name=MemRef", - ], - "include/mlir/Dialect/MemRef/Transforms/Passes.h.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/MemRef/Transforms/Passes.td", - deps = [":PassBaseTdFiles"], -) - -cc_library( - name = "MemRefTransforms", - srcs = glob( - [ - "lib/Dialect/MemRef/Transforms/*.cpp", - "lib/Dialect/MemRef/Transforms/*.h", - ], - ), - hdrs = glob(["include/mlir/Dialect/MemRef/Transforms/*.h"]), - includes = ["include"], - deps = [ - ":Affine", - ":AffineUtils", - ":ArithmeticDialect", - ":ArithmeticTransforms", - ":IR", - ":InferTypeOpInterface", - ":MemRefDialect", - ":MemRefPassIncGen", - ":Pass", - ":StandardOps", - ":Support", - ":TensorDialect", - ":Transforms", - ":VectorOps", - "//llvm:Support", - ], -) - -td_library( - name = "AllocationOpInterfaceTdFiles", - srcs = ["include/mlir/Dialect/Bufferization/IR/AllocationOpInterface.td"], - includes = ["include"], - deps = [":OpBaseTdFiles"], -) - -gentbl_cc_library( - name = "AllocationOpInterfaceIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-interface-decls"], - "include/mlir/Dialect/Bufferization/IR/AllocationOpInterface.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "include/mlir/Dialect/Bufferization/IR/AllocationOpInterface.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Bufferization/IR/AllocationOpInterface.td", - deps = [":AllocationOpInterfaceTdFiles"], -) - -cc_library( - name = "AllocationOpInterface", - srcs = ["lib/Dialect/Bufferization/IR/AllocationOpInterface.cpp"], - hdrs = ["include/mlir/Dialect/Bufferization/IR/AllocationOpInterface.h"], - includes = ["include"], - deps = [ - ":AllocationOpInterfaceIncGen", - ":IR", - ], -) - -td_library( - name = "BufferizationOpsTdFiles", - srcs = [ - "include/mlir/Dialect/Bufferization/IR/BufferizationBase.td", - "include/mlir/Dialect/Bufferization/IR/BufferizationOps.td", - ], - includes = ["include"], - deps = [ - ":AllocationOpInterfaceTdFiles", - ":CopyOpInterfaceTdFiles", - ":OpBaseTdFiles", - ":SideEffectInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "BufferizationBaseIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-dialect-decls", - "-dialect=bufferization", - ], - "include/mlir/Dialect/Bufferization/IR/BufferizationOpsDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=bufferization", - ], - "include/mlir/Dialect/Bufferization/IR/BufferizationOpsDialect.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Bufferization/IR/BufferizationBase.td", - deps = [":BufferizationOpsTdFiles"], -) - -gentbl_cc_library( - name = "BufferizationOpsIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - ["-gen-op-decls"], - "include/mlir/Dialect/Bufferization/IR/BufferizationOps.h.inc", - ), - ( - ["-gen-op-defs"], - "include/mlir/Dialect/Bufferization/IR/BufferizationOps.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Bufferization/IR/BufferizationOps.td", - deps = [ - ":BufferizableOpInterfaceTdFiles", - ":BufferizationOpsTdFiles", - ], -) - -cc_library( - name = "BufferizationDialect", - srcs = [ - "lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp", - "lib/Dialect/Bufferization/IR/BufferizationDialect.cpp", - "lib/Dialect/Bufferization/IR/BufferizationOps.cpp", - ], - hdrs = [ - "include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h", - "include/mlir/Dialect/Bufferization/IR/Bufferization.h", - ], - includes = ["include"], - deps = [ - ":AllocationOpInterface", - ":BufferizableOpInterfaceIncGen", - ":BufferizationBaseIncGen", - ":BufferizationOpsIncGen", - ":ControlFlowInterfaces", - ":CopyOpInterface", - ":IR", - ":InferTypeOpInterface", - ":MemRefDialect", - ":StandardOps", - ":Support", - ":TensorDialect", - ":ViewLikeInterface", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "BufferizationPassIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-pass-decls", - "-name=Bufferization", - ], - "include/mlir/Dialect/Bufferization/Transforms/Passes.h.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/Bufferization/Transforms/Passes.td", - deps = [":PassBaseTdFiles"], -) - -cc_library( - name = "BufferizationTransforms", - srcs = glob( - [ - "lib/Dialect/Bufferization/Transforms/*.cpp", - "lib/Dialect/Bufferization/Transforms/*.h", - ], - ), - hdrs = glob(["include/mlir/Dialect/Bufferization/Transforms/*.h"]), - includes = ["include"], - deps = [ - ":AllocationOpInterface", - ":Analysis", - ":ArithmeticDialect", - ":BufferizationDialect", - ":BufferizationPassIncGen", - ":ControlFlowInterfaces", - ":DialectUtils", - ":IR", - ":InferTypeOpInterface", - ":LoopLikeInterface", - ":MemRefDialect", - ":Pass", - ":StandardOps", - ":Support", - ":Transforms", - "//llvm:Support", - ], -) - -cc_library( - name = "BufferizationToMemRef", - srcs = [ - "lib/Conversion/BufferizationToMemRef/BufferizationToMemRef.cpp", - ":ConversionPassDetail", - ], - hdrs = [ - "include/mlir/Conversion/BufferizationToMemRef/BufferizationToMemRef.h", - ], - includes = ["include"], - deps = [ - ":ArithmeticDialect", - ":BufferizationDialect", - ":ConversionPassIncGen", - ":IR", - ":MemRefDialect", - ":Pass", - ":StandardOps", - ":Support", - ":Transforms", - ], -) - -td_library( - name = "DLTIDialectTdFiles", - srcs = [ - "include/mlir/Dialect/DLTI/DLTI.td", - "include/mlir/Dialect/DLTI/DLTIBase.td", - ], - includes = ["include"], - deps = [":OpBaseTdFiles"], -) - -gentbl_cc_library( - name = "DLTIBaseIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-dialect-decls", - "-dialect=dlti", - ], - "include/mlir/Dialect/DLTI/DLTIDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=dlti", - ], - "include/mlir/Dialect/DLTI/DLTIDialect.cpp.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Dialect/DLTI/DLTIBase.td", - deps = [":OpBaseTdFiles"], -) - -cc_library( - name = "DLTIDialect", - srcs = glob(["lib/Dialect/DLTI/*.cpp"]), - hdrs = glob(["include/mlir/Dialect/DLTI/*.h"]), - includes = ["include"], - deps = [ - ":DLTIBaseIncGen", - ":DataLayoutInterfaces", - ":IR", - "//llvm:Support", - ], -) - -gentbl_cc_library( - name = "ReducerIncGen", - strip_include_prefix = "include", - tbl_outs = [ - ( - [ - "-gen-pass-decls", - "-name=Reducer", - ], - "include/mlir/Reducer/Passes.h.inc", - ), - ], - tblgen = ":mlir-tblgen", - td_file = "include/mlir/Reducer/Passes.td", - deps = [ - ":PassBaseTdFiles", - ":ReducerTdFiles", - ], -) - -cc_library( - name = "Reducer", - srcs = glob(["lib/Reducer/*.cpp"]), - hdrs = glob(["include/mlir/Reducer/*.h"]), - includes = ["include"], - deps = [ - ":IR", - ":Pass", - ":ReducerIncGen", - ":Rewrite", - ":Support", - ":TransformUtils", - "//llvm:Support", - ], -) - -cc_library( - name = "MlirReduceLib", - srcs = ["lib/Tools/mlir-reduce/MlirReduceMain.cpp"], - hdrs = ["include/mlir/Tools/mlir-reduce/MlirReduceMain.h"], - includes = ["include"], - deps = [ - ":IR", - ":Parser", - ":Pass", - ":Reducer", - ":Rewrite", - ":Support", - "//llvm:Support", - ], -) - -cc_binary( - name = "mlir-reduce", - srcs = ["tools/mlir-reduce/mlir-reduce.cpp"], - includes = ["include"], - local_defines = ["MLIR_INCLUDE_TESTS"], - stamp = 0, - deps = [ - ":AllPassesAndDialects", - ":IR", - ":MlirReduceLib", - ":Pass", - "//llvm:Support", - "//mlir/test:TestDialect", - ], -) - -cc_library( - name = "PDLLAST", - srcs = glob( - [ - "lib/Tools/PDLL/AST/*.cpp", - "lib/Tools/PDLL/AST/*.h", - ], - ), - hdrs = glob(["include/mlir/Tools/PDLL/AST/*.h"]), - includes = ["include"], - deps = [ - ":Support", - "//llvm:Support", - ], -) - -cc_library( - name = "PDLLParser", - srcs = glob( - [ - "lib/Tools/PDLL/Parser/*.cpp", - "lib/Tools/PDLL/Parser/*.h", - ], - ), - hdrs = glob(["include/mlir/Tools/PDLL/Parser/*.h"]), - includes = ["include"], - deps = [ - ":PDLLAST", - ":Support", - ":TableGen", - "//llvm:Support", - ], -) - -cc_binary( - name = "mlir-pdll", - srcs = [ - "tools/mlir-pdll/mlir-pdll.cpp", - ], - deps = [ - ":PDLLAST", - ":PDLLParser", - ":Support", - "//llvm:Support", - "//llvm:config", - ], -) diff --git a/utils/bazel/llvm-project-overlay/mlir/build_defs.bzl b/utils/bazel/llvm-project-overlay/mlir/build_defs.bzl deleted file mode 100644 index fe39dbe21e339..0000000000000 --- a/utils/bazel/llvm-project-overlay/mlir/build_defs.bzl +++ /dev/null @@ -1,71 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -"""Rules and macros for MLIR""" - -def if_cuda_available(if_true, if_false = []): - return select({ - # CUDA is not yet supported. - "//conditions:default": if_false, - }) - -def _cc_headers_only_impl(ctx): - return CcInfo(compilation_context = ctx.attr.src[CcInfo].compilation_context) - -cc_headers_only = rule( - implementation = _cc_headers_only_impl, - attrs = { - "src": attr.label( - mandatory = True, - providers = [CcInfo], - ), - }, - doc = "Provides the headers from 'src' without linking anything.", - provides = [CcInfo], -) - -def mlir_c_api_cc_library( - name, - srcs = [], - hdrs = [], - deps = [], - header_deps = [], - capi_deps = [], - **kwargs): - """Macro that generates three targets for MLIR C API libraries. - - * A standard cc_library target ("Name"), - * A header-only cc_library target ("NameHeaders") - * An implementation cc_library target tagged `alwayslink` suitable for - inclusion in a shared library built with cc_binary() ("NameObjects"). - - In order to avoid duplicate symbols, it is important that - mlir_c_api_cc_library targets only depend on other mlir_c_api_cc_library - targets via the "capi_deps" parameter. This makes it so that "FooObjects" - depend on "BarObjects" targets and "Foo" targets depend on "Bar" targets. - Don't cross the streams. - """ - capi_header_deps = ["%sHeaders" % d for d in capi_deps] - capi_object_deps = ["%sObjects" % d for d in capi_deps] - native.cc_library( - name = name, - srcs = srcs, - hdrs = hdrs, - deps = deps + capi_deps + header_deps, - **kwargs - ) - native.cc_library( - name = name + "Headers", - hdrs = hdrs, - deps = header_deps + capi_header_deps, - **kwargs - ) - native.cc_library( - name = name + "Objects", - srcs = srcs, - hdrs = hdrs, - deps = deps + capi_object_deps + capi_header_deps + header_deps, - alwayslink = True, - **kwargs - ) diff --git a/utils/bazel/llvm-project-overlay/mlir/linalggen.bzl b/utils/bazel/llvm-project-overlay/mlir/linalggen.bzl deleted file mode 100644 index d893471e6249f..0000000000000 --- a/utils/bazel/llvm-project-overlay/mlir/linalggen.bzl +++ /dev/null @@ -1,42 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -"""BUILD extensions for MLIR linalg generation.""" - -def genlinalg(name, linalggen, src, linalg_outs): - """genlinalg() generates code from a tc spec file. - - Args: - name: The name of the build rule for use in dependencies. - linalggen: The binary used to produce the output. - src: The tc spec file. - linalg_outs: A list of tuples (opts, out), where each opts is a string of - options passed to linalggen, and the out is the corresponding output file - produced. - """ - - for (opts, out) in linalg_outs: - # All arguments to generate the output except output destination. - base_args = [ - "$(location %s)" % linalggen, - "%s" % opts, - "$(location %s)" % src, - ] - rule_suffix = "_".join(opts.replace("-", "_").replace("=", "_").split(" ")) - - # Rule to generate code using generated shell script. - native.genrule( - name = "%s_%s_genrule" % (name, rule_suffix), - srcs = [src], - outs = [out], - tools = [linalggen], - cmd = (" ".join(base_args)), - ) - - hdrs = [f for (opts, f) in linalg_outs] - native.cc_library( - name = name, - hdrs = hdrs, - textual_hdrs = hdrs, - ) diff --git a/utils/bazel/llvm-project-overlay/mlir/python/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/python/BUILD.bazel deleted file mode 100644 index bc8eaecff2855..0000000000000 --- a/utils/bazel/llvm-project-overlay/mlir/python/BUILD.bazel +++ /dev/null @@ -1,621 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -# Description: -# Python bindings for MLIR. -# -# We define separate filegroups for files in different directories so -# that downstream users can mirror the tree in their own py_library() rules. - -load("//mlir:tblgen.bzl", "gentbl_filegroup", "td_library") - -package( - default_visibility = [ - "//visibility:public", - ], - licenses = ["notice"], -) - -##---------------------------------------------------------------------------## -# Core IR modules. -##---------------------------------------------------------------------------## - -filegroup( - name = "ConversionsPyFiles", - srcs = glob([ - "mlir/conversions/*.py", - ]), -) - -filegroup( - name = "DialectCorePyFiles", - srcs = [ - "mlir/dialects/_ods_common.py", - ], -) - -filegroup( - name = "ExecutionEnginePyFiles", - srcs = [ - "mlir/execution_engine.py", - ], -) - -filegroup( - name = "IRPyFiles", - srcs = [ - "mlir/ir.py", - ], -) - -filegroup( - name = "PassManagerPyFiles", - srcs = [ - "mlir/passmanager.py", - ], -) - -filegroup( - name = "RuntimePyFiles", - srcs = glob([ - "mlir/runtime/*.py", - ]), -) - -filegroup( - name = "TransformsPyFiles", - srcs = glob([ - "mlir/transforms/*.py", - ]), -) - -filegroup( - name = "AllPassesRegistrationPyFiles", - srcs = glob([ - "mlir/all_passes_registration/*.py", - ]), -) - -##---------------------------------------------------------------------------## -# Builtin dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "BuiltinOpsPyTdFiles", - srcs = [ - "mlir/dialects/BuiltinOps.td", - "//mlir:include/mlir/Bindings/Python/Attributes.td", - ], - deps = [ - "//mlir:BuiltinDialectTdFiles", - "//mlir:FunctionInterfacesTdFiles", - "//mlir:OpBaseTdFiles", - ], -) - -gentbl_filegroup( - name = "BuiltinOpsPyGen", - tbl_outs = [ - ( - [ - "-gen-python-op-bindings", - "-bind-dialect=builtin", - ], - "mlir/dialects/_builtin_ops_gen.py", - ), - ], - tblgen = "//mlir:mlir-tblgen", - td_file = "mlir/dialects/BuiltinOps.td", - deps = [ - ":BuiltinOpsPyTdFiles", - ], -) - -filegroup( - name = "BuiltinOpsPyFiles", - srcs = [ - "mlir/dialects/_builtin_ops_ext.py", - "mlir/dialects/builtin.py", - ":BuiltinOpsPyGen", - ], -) - -##---------------------------------------------------------------------------## -# Linalg dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "LinalgOpsPyTdFiles", - srcs = [ - "mlir/dialects/LinalgOps.td", - "//mlir:include/mlir/Bindings/Python/Attributes.td", - ], - deps = [ - "//mlir:LinalgOpsTdFiles", - "//mlir:LinalgStructuredOpsTdFiles", - "//mlir:OpBaseTdFiles", - ], -) - -gentbl_filegroup( - name = "LinalgOpsPyGen", - tbl_outs = [ - ( - [ - "-gen-python-op-bindings", - "-bind-dialect=linalg", - ], - "mlir/dialects/_linalg_ops_gen.py", - ), - ], - tblgen = "//mlir:mlir-tblgen", - td_file = "mlir/dialects/LinalgOps.td", - deps = [ - ":LinalgOpsPyTdFiles", - ], -) - -filegroup( - name = "LinalgOpsPyFiles", - srcs = [ - "mlir/dialects/_linalg_ops_ext.py", - ":LinalgOpsPyGen", - ], -) - -filegroup( - name = "LinalgOpsPackagePyFiles", - srcs = glob(["mlir/dialects/linalg/*.py"]), -) - -filegroup( - name = "LinalgOpsPackageOpDSLPyFiles", - srcs = glob(["mlir/dialects/linalg/opdsl/*.py"]), -) - -filegroup( - name = "LinalgOpsPackageOpDSLLangPyFiles", - srcs = glob(["mlir/dialects/linalg/opdsl/lang/*.py"]), -) - -filegroup( - name = "LinalgOpsPackageOpDSLOpsPyFiles", - srcs = glob(["mlir/dialects/linalg/opdsl/ops/*.py"]), -) - -filegroup( - name = "LinalgOpsPackagePassesPyFiles", - srcs = glob(["mlir/dialects/linalg/passes/*.py"]), -) - -##---------------------------------------------------------------------------## -# Arithmetic dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "ArithmeticOpsPyTdFiles", - srcs = [ - "//mlir:include/mlir/Bindings/Python/Attributes.td", - ], - includes = ["../include"], - deps = [ - "//mlir:ArithmeticOpsTdFiles", - "//mlir:OpBaseTdFiles", - ], -) - -gentbl_filegroup( - name = "ArithmeticOpsPyGen", - tbl_outs = [ - ( - [ - "-gen-python-op-bindings", - "-bind-dialect=arith", - ], - "mlir/dialects/_arith_ops_gen.py", - ), - ], - tblgen = "//mlir:mlir-tblgen", - td_file = "mlir/dialects/ArithmeticOps.td", - deps = [ - ":ArithmeticOpsPyTdFiles", - ], -) - -filegroup( - name = "ArithmeticOpsPyFiles", - srcs = [ - "mlir/dialects/_arith_ops_ext.py", - "mlir/dialects/arith.py", - ":ArithmeticOpsPyGen", - ], -) - -##---------------------------------------------------------------------------## -# Math dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "MathOpsPyTdFiles", - srcs = [ - "//mlir:include/mlir/Bindings/Python/Attributes.td", - ], - includes = ["../include"], - deps = [ - "//mlir:MathOpsTdFiles", - "//mlir:OpBaseTdFiles", - ], -) - -gentbl_filegroup( - name = "MathOpsPyGen", - tbl_outs = [ - ( - [ - "-gen-python-op-bindings", - "-bind-dialect=math", - ], - "mlir/dialects/_math_ops_gen.py", - ), - ], - tblgen = "//mlir:mlir-tblgen", - td_file = "mlir/dialects/MathOps.td", - deps = [ - ":MathOpsPyTdFiles", - ], -) - -filegroup( - name = "MathOpsPyFiles", - srcs = [ - "mlir/dialects/math.py", - ":MathOpsPyGen", - ], -) - -##---------------------------------------------------------------------------## -# MemRef dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "MemRefOpsPyTdFiles", - srcs = [ - "//mlir:include/mlir/Bindings/Python/Attributes.td", - ], - includes = ["../include"], - deps = [ - "//mlir:MemRefOpsTdFiles", - "//mlir:OpBaseTdFiles", - ], -) - -gentbl_filegroup( - name = "MemRefOpsPyGen", - tbl_outs = [ - ( - [ - "-gen-python-op-bindings", - "-bind-dialect=memref", - ], - "mlir/dialects/_memref_ops_gen.py", - ), - ], - tblgen = "//mlir:mlir-tblgen", - td_file = "mlir/dialects/MemRefOps.td", - deps = [ - ":MemRefOpsPyTdFiles", - ], -) - -filegroup( - name = "MemRefOpsPyFiles", - srcs = [ - "mlir/dialects/_memref_ops_ext.py", - "mlir/dialects/memref.py", - ":MemRefOpsPyGen", - ], -) - -##---------------------------------------------------------------------------## -# Quant dialect. -##---------------------------------------------------------------------------## - -filegroup( - name = "QuantPyFiles", - srcs = [ - "mlir/dialects/quant.py", - ], -) - -##---------------------------------------------------------------------------## -# PythonTest dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "PythonTestPyTdFiles", - srcs = [ - "//mlir:include/mlir/Bindings/Python/Attributes.td", - ], - deps = [ - "//mlir:InferTypeOpInterfaceTdFiles", - "//mlir:OpBaseTdFiles", - ], -) - -gentbl_filegroup( - name = "PythonTestPyGen", - tbl_outs = [ - ( - [ - "-gen-python-op-bindings", - "-bind-dialect=python_test", - ], - "mlir/dialects/_python_test_ops_gen.py", - ), - ], - tblgen = "//mlir:mlir-tblgen", - td_file = "//mlir/test/python:python_test_ops.td", - deps = [ - ":PythonTestPyTdFiles", - ], -) - -filegroup( - name = "PythonTestPyFiles", - srcs = [ - "mlir/dialects/python_test.py", - ":PythonTestPyGen", - ], -) - -##---------------------------------------------------------------------------## -# SCF dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "SCFPyTdFiles", - srcs = [ - "//mlir:include/mlir/Bindings/Python/Attributes.td", - ], - includes = ["../include"], - deps = [ - "//mlir:OpBaseTdFiles", - "//mlir:SCFTdFiles", - ], -) - -gentbl_filegroup( - name = "SCFPyGen", - tbl_outs = [ - ( - [ - "-gen-python-op-bindings", - "-bind-dialect=scf", - ], - "mlir/dialects/_scf_ops_gen.py", - ), - ], - tblgen = "//mlir:mlir-tblgen", - td_file = "mlir/dialects/SCFOps.td", - deps = [ - ":SCFPyTdFiles", - ], -) - -filegroup( - name = "SCFPyFiles", - srcs = [ - "mlir/dialects/_scf_ops_ext.py", - "mlir/dialects/scf.py", - ":SCFPyGen", - ], -) - -##---------------------------------------------------------------------------## -# Shape dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "ShapeOpsPyTdFiles", - srcs = [ - "//mlir:include/mlir/Bindings/Python/Attributes.td", - ], - includes = ["../include"], - deps = [ - "//mlir:OpBaseTdFiles", - "//mlir:ShapeOpsTdFiles", - ], -) - -gentbl_filegroup( - name = "ShapeOpsPyGen", - tbl_outs = [ - ( - [ - "-gen-python-op-bindings", - "-bind-dialect=shape", - ], - "mlir/dialects/_shape_ops_gen.py", - ), - ], - tblgen = "//mlir:mlir-tblgen", - td_file = "mlir/dialects/ShapeOps.td", - deps = [ - ":ShapeOpsPyTdFiles", - ], -) - -filegroup( - name = "ShapeOpsPyFiles", - srcs = [ - "mlir/dialects/shape.py", - ":ShapeOpsPyGen", - ], -) - -##---------------------------------------------------------------------------## -# Standard dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "StandardOpsPyTdFiles", - srcs = [ - "//mlir:include/mlir/Bindings/Python/Attributes.td", - ], - deps = [ - "//mlir:OpBaseTdFiles", - "//mlir:StdOpsTdFiles", - ], -) - -gentbl_filegroup( - name = "StandardOpsPyGen", - tbl_outs = [ - ( - [ - "-gen-python-op-bindings", - "-bind-dialect=std", - ], - "mlir/dialects/_std_ops_gen.py", - ), - ], - tblgen = "//mlir:mlir-tblgen", - td_file = "mlir/dialects/StandardOps.td", - deps = [ - ":StandardOpsPyTdFiles", - ], -) - -filegroup( - name = "StandardOpsPyFiles", - srcs = [ - "mlir/dialects/_std_ops_ext.py", - "mlir/dialects/std.py", - ":StandardOpsPyGen", - ], -) - -##---------------------------------------------------------------------------## -# SparseTensor dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "SparseTensorOpsPyTdFiles", - srcs = [ - "//mlir:include/mlir/Bindings/Python/Attributes.td", - ], - deps = [ - "//mlir:OpBaseTdFiles", - "//mlir:SparseTensorTdFiles", - ], -) - -gentbl_filegroup( - name = "SparseTensorOpsPyGen", - tbl_outs = [ - ( - [ - "-gen-python-op-bindings", - "-bind-dialect=sparse_tensor", - ], - "mlir/dialects/_sparse_tensor_ops_gen.py", - ), - ], - tblgen = "//mlir:mlir-tblgen", - td_file = "mlir/dialects/SparseTensorOps.td", - deps = [ - ":SparseTensorOpsPyTdFiles", - ], -) - -filegroup( - name = "SparseTensorOpsPyFiles", - srcs = [ - "mlir/dialects/sparse_tensor.py", - ":SparseTensorOpsPyGen", - ], -) - -##---------------------------------------------------------------------------## -# Tosa dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "TosaOpsPyTdFiles", - srcs = [ - "//mlir:include/mlir/Bindings/Python/Attributes.td", - ], - deps = [ - "//mlir:OpBaseTdFiles", - "//mlir:TosaDialectTdFiles", - ], -) - -gentbl_filegroup( - name = "TosaOpsPyGen", - tbl_outs = [ - ( - [ - "-gen-python-op-bindings", - "-bind-dialect=tosa", - ], - "mlir/dialects/_tosa_ops_gen.py", - ), - ], - tblgen = "//mlir:mlir-tblgen", - td_file = "mlir/dialects/TosaOps.td", - deps = [ - ":TosaOpsPyTdFiles", - ], -) - -filegroup( - name = "TosaOpsPyFiles", - srcs = [ - "mlir/dialects/tosa.py", - ":TosaOpsPyGen", - ], -) - -##---------------------------------------------------------------------------## -# Vector dialect. -##---------------------------------------------------------------------------## - -td_library( - name = "VectorOpsPyTdFiles", - srcs = [ - "//mlir:include/mlir/Bindings/Python/Attributes.td", - ], - includes = ["../include"], - deps = [ - "//mlir:OpBaseTdFiles", - "//mlir:VectorOpsTdFiles", - ], -) - -gentbl_filegroup( - name = "VectorOpsPyGen", - tbl_outs = [ - ( - [ - "-gen-python-op-bindings", - "-bind-dialect=vector", - ], - "mlir/dialects/_vector_ops_gen.py", - ), - ], - tblgen = "//mlir:mlir-tblgen", - td_file = "mlir/dialects/VectorOps.td", - deps = [ - ":VectorOpsPyTdFiles", - ], -) - -filegroup( - name = "VectorOpsPyFiles", - srcs = [ - "mlir/dialects/vector.py", - ":VectorOpsPyGen", - ], -) diff --git a/utils/bazel/llvm-project-overlay/mlir/tblgen.bzl b/utils/bazel/llvm-project-overlay/mlir/tblgen.bzl deleted file mode 100644 index 0c2aaf3a25525..0000000000000 --- a/utils/bazel/llvm-project-overlay/mlir/tblgen.bzl +++ /dev/null @@ -1,433 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -"""BUILD extensions for MLIR table generation.""" - -load("@bazel_skylib//lib:paths.bzl", "paths") - -TdInfo = provider( - "Holds TableGen files and the dependencies and include paths necessary to" + - " build them.", - fields = { - "transitive_sources": "td files transitively used by this rule.", - "transitive_includes": ( - "include arguments to add to the final TableGen invocation. These" + - " are the absolute directory paths that will be added with '-I'." - ), - }, -) - -# For now we allow anything that provides DefaultInfo to just forward its files. -# In particular, this allows filegroups to be used. This is mostly to ease -# transition. In the future, the TdInfo provider will be required. -# TODO(gcmn): Switch to enforcing TdInfo provider. -def _get_dep_transitive_srcs(dep): - """Extract TdInfo.transitive_sources, falling back to DefaultInfo.files.""" - if TdInfo in dep: - return dep[TdInfo].transitive_sources - return dep[DefaultInfo].files - -def _get_dep_transitive_includes(dep): - """Extract TdInfo.transitive_includes, falling back to an empty depset().""" - if TdInfo in dep: - return dep[TdInfo].transitive_includes - return depset() - -def _get_transitive_srcs(srcs, deps): - """Obtain the source files for a target and its transitive dependencies. - - Args: - srcs: a list of source files - deps: a list of targets that are direct dependencies - Returns: - a collection of the transitive sources - """ - return depset( - direct = srcs, - transitive = [_get_dep_transitive_srcs(dep) for dep in deps], - ) - -def _get_transitive_includes(includes, deps): - """Obtain the includes paths for a target and its transitive dependencies. - - Args: - includes: a list of include paths - deps: a list of targets that are direct dependencies - Returns: - a collection of the transitive include paths - """ - return depset( - direct = includes, - transitive = [_get_dep_transitive_includes(dep) for dep in deps], - ) - -def _prefix_roots(ctx, includes): - """Map the given includes to be relative to all root directories. - - This will expand them to be relative to all the root directories available - in the execution environment for ctx.run (bin and genfiles in addition to - the normal source root) - """ - prefixed_includes = [] - for include in includes: - prefixed_includes.append(include) - prefixed_includes.append(paths.join(ctx.genfiles_dir.path, include)) - prefixed_includes.append(paths.join(ctx.bin_dir.path, include)) - return prefixed_includes - -def _resolve_includes(ctx, includes): - """Resolves include paths to paths relative to the execution root. - - Relative paths are interpreted as relative to the current label's package. - Absolute paths are interpreted as relative to the current label's workspace - root.""" - package = ctx.label.package - workspace_root = ctx.label.workspace_root - workspace_root = workspace_root if workspace_root else "." - resolved_includes = [] - for include in includes: - if paths.is_absolute(include): - include = include.lstrip("/") - else: - include = paths.join(package, include) - include = paths.join(workspace_root, include) - resolved_includes.extend(_prefix_roots(ctx, [include])) - return resolved_includes - -def _td_library_impl(ctx): - trans_srcs = _get_transitive_srcs(ctx.files.srcs, ctx.attr.deps) - trans_includes = _get_transitive_includes( - _resolve_includes(ctx, ctx.attr.includes), - ctx.attr.deps, - ) - - # Note that we include srcs in runfiles. A td_library doesn't compile to - # produce an output: it's just a depset of source files and include - # directories. So if it is needed for execution of some rule (likely - # something running tblgen as a test action), the files needed are the same - # as the source files. - # Note: not using merge_all, as that is not available in Bazel 4.0 - runfiles = ctx.runfiles(ctx.files.srcs) - for src in ctx.attr.srcs: - runfiles = runfiles.merge(src[DefaultInfo].default_runfiles) - for dep in ctx.attr.deps: - runfiles = runfiles.merge(dep[DefaultInfo].default_runfiles) - - return [ - DefaultInfo(files = trans_srcs, runfiles = runfiles), - TdInfo( - transitive_sources = trans_srcs, - transitive_includes = trans_includes, - ), - ] - -td_library = rule( - _td_library_impl, - attrs = { - "srcs": attr.label_list(allow_files = True), - "includes": attr.string_list( - doc = "Include paths to be added to the final TableGen tool" + - " invocation. Relative paths are interpreted as relative to" + - " the current label's package. Absolute paths are" + - " interpreted as relative to the current label's workspace", - ), - # TODO(gcmn): limit to TdInfo providers. - "deps": attr.label_list( - doc = "Dependencies providing TableGen source files and include" + - " paths.", - ), - }, -) - -def _gentbl_rule_impl(ctx): - td_file = ctx.file.td_file - - trans_srcs = _get_transitive_srcs( - ctx.files.td_srcs + [td_file], - ctx.attr.deps, - ) - - # Note that the td_file.dirname is already relative to the execution root, - # i.e. may contain an `external/` prefix if the current - # workspace is not the main workspace. Therefore it is not included in the - # _resolve_includes call that prepends this prefix. - trans_includes = _get_transitive_includes( - _resolve_includes(ctx, ctx.attr.includes + ["/"]) + - _prefix_roots(ctx, [td_file.dirname]), - ctx.attr.deps, - ) - - args = ctx.actions.args() - args.add_all(ctx.attr.opts) - args.add(td_file) - args.add_all(trans_includes, before_each = "-I") - - args.add("-o", ctx.outputs.out.path) - - ctx.actions.run( - outputs = [ctx.outputs.out], - inputs = trans_srcs, - executable = ctx.executable.tblgen, - arguments = [args], - # Make sure action_env settings are honored so the env is the same as - # when the tool was built. Important for locating shared libraries with - # a custom LD_LIBRARY_PATH. - use_default_shell_env = True, - mnemonic = "TdGenerate", - ) - - return [DefaultInfo()] - -gentbl_rule = rule( - _gentbl_rule_impl, - doc = "Generates tabular code from a table definition file.", - # Match genrule behavior - output_to_genfiles = True, - attrs = { - "tblgen": attr.label( - doc = "The TableGen executable with which to generate `out`.", - executable = True, - cfg = "exec", - ), - "td_file": attr.label( - doc = "The TableGen file to run through `tblgen`.", - allow_single_file = True, - mandatory = True, - ), - "td_srcs": attr.label_list( - doc = "Additional TableGen files included by `td_file`. It is not" + - " necessary to list td_file here (though not an error).", - allow_files = True, - ), - # TODO(gcmn): limit to TdInfo providers. - "deps": attr.label_list( - doc = "Dependencies providing TableGen source files and include" + - " paths.", - ), - "out": attr.output( - doc = "The output file for the TableGen invocation.", - mandatory = True, - ), - "opts": attr.string_list( - doc = "Additional command line options to add to the TableGen" + - " invocation. For include arguments, prefer to use" + - " `includes`.", - ), - "includes": attr.string_list( - doc = "Include paths to be added to the final TableGen tool" + - " invocation. Relative paths are interpreted as relative to" + - " the current label's package. Absolute paths are" + - " interpreted as relative to the current label's workspace." + - " Includes are applied from all roots available in the" + - " execution environment (source, genfiles, and bin" + - " directories). The execution roots themselves and the " + - " directory of td_file are always added.", - ), - }, -) - -# TODO(gcmn): Figure out how to reduce duplication with _gentbl_rule_impl -def _gentbl_test_impl(ctx): - td_file = ctx.file.td_file - - # Note that the td_file.dirname is already relative to the execution root, - # i.e. may contain an `external/` prefix if the current - # workspace is not the main workspace. Therefore it is not included in the - # _resolve_includes call that prepends this prefix. - trans_includes = _get_transitive_includes( - _resolve_includes(ctx, ctx.attr.includes + ["/"]) + - _prefix_roots(ctx, [td_file.dirname]), - ctx.attr.deps, - ) - - test_args = [ctx.executable.tblgen.short_path] - test_args.extend(ctx.attr.opts) - test_args.append(td_file.path) - test_args.extend(["-I " + include for include in trans_includes.to_list()]) - - test_args.extend(["-o", "/dev/null"]) - - ctx.actions.write( - ctx.outputs.executable, - content = " ".join(test_args), - is_executable = True, - ) - - # Note: not using merge_all, as that is not available in Bazel 4.0 - runfiles = ctx.runfiles( - files = [ctx.executable.tblgen], - transitive_files = _get_transitive_srcs( - ctx.files.td_srcs + [td_file], - ctx.attr.deps, - ), - ) - for src in ctx.attr.td_srcs: - runfiles = runfiles.merge(src[DefaultInfo].default_runfiles) - for dep in ctx.attr.deps: - runfiles = runfiles.merge(dep[DefaultInfo].default_runfiles) - - return [ - coverage_common.instrumented_files_info( - ctx, - source_attributes = ["td_file", "td_srcs"], - dependency_attributes = ["tblgen", "deps"], - ), - DefaultInfo(runfiles = runfiles), - ] - -gentbl_test = rule( - _gentbl_test_impl, - test = True, - doc = "A shell test that tests the given TablegGen invocation. Note" + - " that unlike gentbl_rule, this builds and invokes `tblgen` in the" + - " target configuration. Takes all the same arguments as gentbl_rule" + - " except for `out` (as it does not generate any output)", - attrs = { - "tblgen": attr.label( - doc = "The TableGen executable run in the shell command. Note" + - " that this is built in the target configuration.", - executable = True, - cfg = "target", - ), - "td_file": attr.label( - doc = "See gentbl_rule.td_file", - allow_single_file = True, - mandatory = True, - ), - "td_srcs": attr.label_list( - doc = "See gentbl_rule.td_srcs", - allow_files = True, - ), - "deps": attr.label_list(doc = "See gentbl_rule.deps"), - "opts": attr.string_list(doc = "See gentbl_rule.opts"), - "includes": attr.string_list(doc = "See gentbl_rule.includes"), - }, -) - -def gentbl_filegroup( - name, - tblgen, - td_file, - tbl_outs, - td_srcs = [], - includes = [], - deps = [], - test = False, - skip_opts = [], - **kwargs): - """Create multiple TableGen generated files using the same tool and input. - - All generated outputs are bundled in a file group with the given name. - - Args: - name: The name of the generated filegroup rule for use in dependencies. - tblgen: The binary used to produce the output. - td_file: The primary table definitions file. - tbl_outs: A list of tuples ([opts], out), where each 'opts' is a list of - options passed to tblgen, each option being a string, and 'out' is the - corresponding output file produced. - td_srcs: See gentbl_rule.td_srcs - includes: See gentbl_rule.includes - deps: See gentbl_rule.deps - test: Whether to create a shell test that invokes the tool too. - skip_opts: Files generated using these opts in tbl_outs will be excluded - from the generated filegroup. - **kwargs: Extra keyword arguments to pass to all generated rules. - """ - - for (opts, out) in tbl_outs: - first_opt = opts[0] if opts else "" - rule_suffix = "_{}_{}".format( - first_opt.replace("-", "_").replace("=", "_"), - str(hash(" ".join(opts))), - ) - gentbl_name = "%s_%s_genrule" % (name, rule_suffix) - gentbl_rule( - name = gentbl_name, - td_file = td_file, - tblgen = tblgen, - opts = opts, - td_srcs = td_srcs, - deps = deps, - includes = includes, - out = out, - **kwargs - ) - - if test: - # Also run the generator in the target configuration as a test. This - # means it gets run with asserts and sanitizers and such when they - # are enabled and is counted in coverage. - gentbl_test( - name = "%s_test" % (gentbl_name,), - td_file = td_file, - tblgen = tblgen, - opts = opts, - td_srcs = td_srcs, - deps = deps, - includes = includes, - # Shell files not executable on Windows. - # TODO(gcmn): Support windows. - tags = ["no_windows"], - **kwargs - ) - - included_srcs = [f for (opts, f) in tbl_outs if not any([skip_opt in opts for skip_opt in skip_opts])] - native.filegroup( - name = name, - srcs = included_srcs, - **kwargs - ) - -def gentbl_cc_library( - name, - tblgen, - td_file, - tbl_outs, - td_srcs = [], - includes = [], - deps = [], - strip_include_prefix = None, - test = False, - **kwargs): - """Create multiple TableGen generated files using the same tool and input. - - All generated outputs are bundled in a cc_library rule. - - Args: - name: The name of the generated cc_library rule for use in dependencies. - tblgen: The binary used to produce the output. - td_file: The primary table definitions file. - tbl_outs: A list of tuples ([opts], out), where each 'opts' is a list of - options passed to tblgen, each option being a string, and 'out' is the - corresponding output file produced. - td_srcs: See gentbl_rule.td_srcs - includes: See gentbl_rule.includes - deps: See gentbl_rule.deps - strip_include_prefix: attribute to pass through to cc_library. - test: whether to create a shell test that invokes the tool too. - **kwargs: Extra keyword arguments to pass to all generated rules. - """ - - filegroup_name = name + "_filegroup" - gentbl_filegroup( - name = filegroup_name, - tblgen = tblgen, - td_file = td_file, - tbl_outs = tbl_outs, - td_srcs = td_srcs, - includes = includes, - deps = deps, - test = test, - skip_opts = ["-gen-op-doc"], - **kwargs - ) - native.cc_library( - name = name, - # strip_include_prefix does not apply to textual_hdrs. - # https://github.com/bazelbuild/bazel/issues/12424 - hdrs = [":" + filegroup_name] if strip_include_prefix else [], - strip_include_prefix = strip_include_prefix, - textual_hdrs = [":" + filegroup_name], - **kwargs - ) diff --git a/utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel deleted file mode 100644 index 0f00fdf2c2301..0000000000000 --- a/utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel +++ /dev/null @@ -1,560 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -load("//mlir:tblgen.bzl", "gentbl_cc_library", "td_library") - -package( - default_visibility = ["//visibility:public"], - features = ["layering_check"], - licenses = ["notice"], -) - -cc_library( - name = "IRProducingAPITest", - hdrs = ["APITest.h"], - includes = ["."], -) - -cc_library( - name = "TestAnalysis", - srcs = glob(["lib/Analysis/*.cpp"]), - includes = ["lib/Dialect/Test"], - deps = [ - ":TestDialect", - "//llvm:Support", - "//mlir:Affine", - "//mlir:AffineAnalysis", - "//mlir:Analysis", - "//mlir:IR", - "//mlir:MemRefDialect", - "//mlir:Pass", - "//mlir:Support", - ], -) - -td_library( - name = "TestOpTdFiles", - srcs = glob(["lib/Dialect/Test/*.td"]), - deps = [ - "//mlir:BuiltinDialectTdFiles", - "//mlir:CallInterfacesTdFiles", - "//mlir:ControlFlowInterfacesTdFiles", - "//mlir:CopyOpInterfaceTdFiles", - "//mlir:DLTIDialectTdFiles", - "//mlir:DataLayoutInterfacesTdFiles", - "//mlir:InferTypeOpInterfaceTdFiles", - "//mlir:LinalgStructuredOpsTdFiles", - "//mlir:OpBaseTdFiles", - "//mlir:SideEffectTdFiles", - ], -) - -gentbl_cc_library( - name = "TestOpsIncGen", - strip_include_prefix = "lib/Dialect/Test", - tbl_outs = [ - ( - ["-gen-op-decls"], - "lib/Dialect/Test/TestOps.h.inc", - ), - ( - ["-gen-op-defs"], - "lib/Dialect/Test/TestOps.cpp.inc", - ), - ( - [ - "-gen-dialect-decls", - "-dialect=test", - ], - "lib/Dialect/Test/TestOpsDialect.h.inc", - ), - ( - [ - "-gen-dialect-defs", - "-dialect=test", - ], - "lib/Dialect/Test/TestOpsDialect.cpp.inc", - ), - ( - ["-gen-enum-decls"], - "lib/Dialect/Test/TestOpEnums.h.inc", - ), - ( - ["-gen-enum-defs"], - "lib/Dialect/Test/TestOpEnums.cpp.inc", - ), - ( - ["-gen-struct-attr-decls"], - "lib/Dialect/Test/TestOpStructs.h.inc", - ), - ( - ["-gen-struct-attr-defs"], - "lib/Dialect/Test/TestOpStructs.cpp.inc", - ), - ( - ["-gen-rewriters"], - "lib/Dialect/Test/TestPatterns.inc", - ), - ], - tblgen = "//mlir:mlir-tblgen", - td_file = "lib/Dialect/Test/TestOps.td", - test = True, - deps = [ - ":TestOpTdFiles", - ], -) - -gentbl_cc_library( - name = "TestInterfacesIncGen", - strip_include_prefix = "lib/Dialect/Test", - tbl_outs = [ - ( - ["-gen-attr-interface-decls"], - "lib/Dialect/Test/TestAttrInterfaces.h.inc", - ), - ( - ["-gen-attr-interface-defs"], - "lib/Dialect/Test/TestAttrInterfaces.cpp.inc", - ), - ( - ["-gen-type-interface-decls"], - "lib/Dialect/Test/TestTypeInterfaces.h.inc", - ), - ( - ["-gen-type-interface-defs"], - "lib/Dialect/Test/TestTypeInterfaces.cpp.inc", - ), - ( - ["-gen-op-interface-decls"], - "lib/Dialect/Test/TestOpInterfaces.h.inc", - ), - ( - ["-gen-op-interface-defs"], - "lib/Dialect/Test/TestOpInterfaces.cpp.inc", - ), - ], - tblgen = "//mlir:mlir-tblgen", - td_file = "lib/Dialect/Test/TestInterfaces.td", - test = True, - deps = [ - "//mlir:OpBaseTdFiles", - "//mlir:SideEffectInterfacesTdFiles", - ], -) - -gentbl_cc_library( - name = "TestAttrDefsIncGen", - strip_include_prefix = "lib/Dialect/Test", - tbl_outs = [ - ( - ["-gen-attrdef-decls"], - "lib/Dialect/Test/TestAttrDefs.h.inc", - ), - ( - ["-gen-attrdef-defs"], - "lib/Dialect/Test/TestAttrDefs.cpp.inc", - ), - ], - tblgen = "//mlir:mlir-tblgen", - td_file = "lib/Dialect/Test/TestOps.td", - test = True, - deps = [ - ":TestOpTdFiles", - ], -) - -gentbl_cc_library( - name = "TestTypeDefsIncGen", - strip_include_prefix = "lib/Dialect/Test", - tbl_outs = [ - ( - [ - "-gen-typedef-decls", - "--typedefs-dialect=test", - ], - "lib/Dialect/Test/TestTypeDefs.h.inc", - ), - ( - [ - "-gen-typedef-defs", - "--typedefs-dialect=test", - ], - "lib/Dialect/Test/TestTypeDefs.cpp.inc", - ), - ], - tblgen = "//mlir:mlir-tblgen", - td_file = "lib/Dialect/Test/TestTypeDefs.td", - test = True, - deps = [ - ":TestOpTdFiles", - "//mlir:BuiltinDialectTdFiles", - ], -) - -cc_library( - name = "TestDialect", - srcs = glob(["lib/Dialect/Test/*.cpp"]), - hdrs = glob(["lib/Dialect/Test/*.h"]), - includes = [ - "lib/Dialect/Test", - ], - deps = [ - ":TestAttrDefsIncGen", - ":TestInterfacesIncGen", - ":TestOpsIncGen", - ":TestTypeDefsIncGen", - "//llvm:Support", - "//mlir:ArithmeticDialect", - "//mlir:ControlFlowInterfaces", - "//mlir:CopyOpInterface", - "//mlir:DLTIDialect", - "//mlir:DataLayoutInterfaces", - "//mlir:DerivedAttributeOpInterface", - "//mlir:Dialect", - "//mlir:IR", - "//mlir:InferTypeOpInterface", - "//mlir:LLVMDialect", - "//mlir:LinalgInterfaces", - "//mlir:LinalgOps", - "//mlir:Pass", - "//mlir:Reducer", - "//mlir:SideEffects", - "//mlir:StandardOps", - "//mlir:StandardOpsTransforms", - "//mlir:Support", - "//mlir:TensorDialect", - "//mlir:TransformUtils", - "//mlir:Transforms", - ], -) - -cc_library( - name = "TestIR", - srcs = glob(["lib/IR/*.cpp"]), - deps = [ - ":TestDialect", - "//llvm:Support", - "//mlir:Analysis", - "//mlir:IR", - "//mlir:LinalgOps", - "//mlir:Pass", - "//mlir:StandardOps", - "//mlir:Support", - ], -) - -cc_library( - name = "TestPass", - srcs = glob(["lib/Pass/*.cpp"]), - deps = [ - "//llvm:Support", - "//mlir:IR", - "//mlir:Pass", - "//mlir:Support", - ], -) - -cc_library( - name = "TestRewrite", - srcs = [ - "lib/Rewrite/TestPDLByteCode.cpp", - ], - deps = [ - "//mlir:IR", - "//mlir:PDLInterpDialect", - "//mlir:Pass", - "//mlir:Support", - "//mlir:TransformUtils", - ], -) - -cc_library( - name = "TestReducer", - srcs = [ - "lib/Reducer/MLIRTestReducer.cpp", - ], - deps = [ - "//mlir:IR", - "//mlir:Pass", - "//mlir:Support", - ], -) - -cc_library( - name = "TestTransforms", - srcs = glob(["lib/Transforms/*.cpp"]), - defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"], - includes = ["lib/Dialect/Test"], - deps = [ - ":TestDialect", - "//llvm:Support", - "//mlir:Affine", - "//mlir:AffineAnalysis", - "//mlir:Analysis", - "//mlir:ArithmeticDialect", - "//mlir:IR", - "//mlir:MathDialect", - "//mlir:Pass", - "//mlir:SCFDialect", - "//mlir:SPIRVDialect", - "//mlir:StandardOps", - "//mlir:TransformUtils", - ], -) - -cc_library( - name = "TestStandardToLLVM", - srcs = glob(["lib/Conversion/StandardToLLVM/*.cpp"]), - defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"], - includes = ["lib/Dialect/Test"], - deps = [ - ":TestDialect", - "//mlir:LLVMCommonConversion", - "//mlir:LLVMDialect", - "//mlir:Pass", - "//mlir:StandardOps", - "//mlir:StandardToLLVM", - ], -) - -cc_library( - name = "TestAffine", - srcs = glob([ - "lib/Dialect/Affine/*.cpp", - ]), - deps = [ - "//llvm:Support", - "//mlir:Affine", - "//mlir:AffineAnalysis", - "//mlir:AffineTransforms", - "//mlir:AffineUtils", - "//mlir:Analysis", - "//mlir:IR", - "//mlir:MemRefDialect", - "//mlir:Pass", - "//mlir:SCFDialect", - "//mlir:StandardOps", - "//mlir:Support", - "//mlir:Transforms", - "//mlir:VectorOps", - "//mlir:VectorUtils", - ], -) - -cc_library( - name = "TestDLTI", - srcs = glob(["lib/Dialect/DLTI/*.cpp"]), - defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"], - includes = ["lib/Dialect/Test"], - deps = [ - ":TestDialect", - "//mlir:Analysis", - "//mlir:DLTIDialect", - "//mlir:IR", - "//mlir:Pass", - ], -) - -cc_library( - name = "TestGPU", - srcs = glob(["lib/Dialect/GPU/*.cpp"]), - defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"], - includes = ["lib/Dialect/Test"], - deps = [ - "//llvm:NVPTXCodeGen", - "//llvm:Support", - "//mlir:Affine", - "//mlir:ArithmeticDialect", - "//mlir:GPUDialect", - "//mlir:GPUTransforms", - "//mlir:IR", - "//mlir:MemRefDialect", - "//mlir:NVVMToLLVMIRTranslation", - "//mlir:Pass", - "//mlir:ROCDLToLLVMIRTranslation", - "//mlir:SCFDialect", - "//mlir:SPIRVDialect", - "//mlir:StandardOps", - "//mlir:ToLLVMIRTranslation", - "//mlir:TransformUtils", - ], -) - -cc_library( - name = "TestLinalg", - srcs = glob(["lib/Dialect/Linalg/*.cpp"]), - defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"], - includes = ["lib/Dialect/Test"], - deps = [ - "//llvm:Support", - "//mlir:Affine", - "//mlir:AffineBufferizableOpInterfaceImpl", - "//mlir:ArithmeticDialect", - "//mlir:ArithmeticTransforms", - "//mlir:BufferizationDialect", - "//mlir:BufferizationTransforms", - "//mlir:GPUDialect", - "//mlir:IR", - "//mlir:LinalgBufferizableOpInterfaceImpl", - "//mlir:LinalgOps", - "//mlir:LinalgTransforms", - "//mlir:MemRefDialect", - "//mlir:Pass", - "//mlir:SCFDialect", - "//mlir:SCFTransforms", - "//mlir:StandardOps", - "//mlir:StandardOpsTransforms", - "//mlir:TensorDialect", - "//mlir:TensorTransforms", - "//mlir:TransformUtils", - "//mlir:VectorOps", - "//mlir:VectorToSCF", - "//mlir:VectorTransforms", - ], -) - -cc_library( - name = "TestMath", - srcs = glob(["lib/Dialect/Math/*.cpp"]), - defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"], - includes = ["lib/Dialect/Test"], - deps = [ - "//mlir:ArithmeticDialect", - "//mlir:MathDialect", - "//mlir:MathTransforms", - "//mlir:Pass", - "//mlir:TransformUtils", - "//mlir:VectorOps", - "//mlir:X86Vector", - ], -) - -cc_library( - name = "TestMemRef", - srcs = glob(["lib/Dialect/MemRef/*.cpp"]), - defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"], - includes = ["lib/Dialect/Test"], - deps = [ - ":TestDialect", - "//mlir:Affine", - "//mlir:MemRefTransforms", - "//mlir:Pass", - "//mlir:Transforms", - ], -) - -cc_library( - name = "TestSCF", - srcs = glob(["lib/Dialect/SCF/*.cpp"]), - defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"], - includes = ["lib/Dialect/Test"], - deps = [ - "//llvm:Support", - "//mlir:ArithmeticDialect", - "//mlir:IR", - "//mlir:MathDialect", - "//mlir:Pass", - "//mlir:SCFDialect", - "//mlir:SCFTransforms", - "//mlir:SCFUtils", - "//mlir:StandardOps", - "//mlir:TransformUtils", - ], -) - -cc_library( - name = "TestShapeDialect", - srcs = [ - "lib/Dialect/Shape/TestShapeFunctions.cpp", - ], - deps = [ - "//llvm:Support", - "//mlir:IR", - "//mlir:InferTypeOpInterface", - "//mlir:Pass", - "//mlir:Shape", - ], -) - -cc_library( - name = "TestSPIRV", - srcs = glob([ - "lib/Dialect/SPIRV/*.cpp", - ]), - deps = [ - "//mlir:GPUDialect", - "//mlir:IR", - "//mlir:Pass", - "//mlir:SPIRVConversion", - "//mlir:SPIRVDialect", - "//mlir:SPIRVModuleCombiner", - "//mlir:Transforms", - ], -) - -cc_library( - name = "TestStandardOps", - srcs = glob(["lib/Dialect/StandardOps/*.cpp"]), - defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"], - includes = ["lib/Dialect/Test"], - deps = [ - ":TestDialect", - "//mlir:Affine", - "//mlir:IR", - "//mlir:Pass", - "//mlir:StandardOps", - "//mlir:StandardOpsTransforms", - "//mlir:TransformUtils", - ], -) - -cc_library( - name = "TestVector", - srcs = glob(["lib/Dialect/Vector/*.cpp"]), - defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"], - includes = ["lib/Dialect/Test"], - deps = [ - "//mlir:Affine", - "//mlir:Analysis", - "//mlir:LLVMDialect", - "//mlir:LinalgOps", - "//mlir:LinalgTransforms", - "//mlir:MemRefDialect", - "//mlir:Pass", - "//mlir:SCFDialect", - "//mlir:StandardOps", - "//mlir:TransformUtils", - "//mlir:VectorOps", - "//mlir:VectorToSCF", - "//mlir:VectorTransforms", - "//mlir:X86Vector", - ], -) - -cc_library( - name = "TestTypeDialect", - srcs = glob([ - "lib/Dialect/LLVMIR/*.cpp", - ]), - deps = [ - ":TestDialect", - "//mlir:IR", - "//mlir:LLVMDialect", - ], -) - -cc_library( - name = "TestTosaDialect", - srcs = glob([ - "lib/Dialect/Tosa/*.cpp", - ]), - deps = [ - "//mlir:IR", - "//mlir:Pass", - "//mlir:StandardOps", - "//mlir:TensorDialect", - "//mlir:TosaDialect", - "//mlir:Transforms", - ], -) diff --git a/utils/bazel/llvm-project-overlay/mlir/test/python/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/test/python/BUILD.bazel deleted file mode 100644 index 74eaa33a2faa2..0000000000000 --- a/utils/bazel/llvm-project-overlay/mlir/test/python/BUILD.bazel +++ /dev/null @@ -1,10 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -licenses(["notice"]) - -exports_files( - srcs = ["python_test_ops.td"], - visibility = ["//visibility:public"], -) diff --git a/utils/bazel/llvm-project-overlay/mlir/unittests/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/unittests/BUILD.bazel deleted file mode 100644 index 9092d53e9fe2b..0000000000000 --- a/utils/bazel/llvm-project-overlay/mlir/unittests/BUILD.bazel +++ /dev/null @@ -1,335 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -load("//mlir:tblgen.bzl", "gentbl_cc_library") - -package( - default_visibility = ["//visibility:public"], - licenses = ["notice"], -) - -cc_test( - name = "ir_tests", - size = "small", - srcs = glob([ - "IR/*.cpp", - "IR/*.h", - ]), - deps = [ - "//llvm:TestingSupport", - "//llvm:gtest_main", - "//mlir:IR", - "//mlir/test:TestDialect", - ], -) - -cc_test( - name = "interface_tests", - size = "small", - srcs = glob([ - "Interfaces/*.cpp", - "Interfaces/*.h", - ]), - deps = [ - "//llvm:TestingSupport", - "//llvm:gtest_main", - "//mlir:ControlFlowInterfaces", - "//mlir:DLTIDialect", - "//mlir:DataLayoutInterfaces", - "//mlir:IR", - "//mlir:InferTypeOpInterface", - "//mlir:Parser", - "//mlir:StandardOps", - ], -) - -cc_test( - name = "support_tests", - size = "small", - srcs = glob([ - "Support/*.cpp", - "Support/*.h", - ]), - deps = [ - "//llvm:Support", - "//llvm:TestingSupport", - "//llvm:gtest_main", - "//mlir:Support", - ], -) - -cc_test( - name = "pass_tests", - size = "small", - srcs = glob([ - "Pass/*.cpp", - "Pass/*.h", - ]), - deps = [ - "//llvm:TestingSupport", - "//llvm:gtest_main", - "//mlir:Analysis", - "//mlir:IR", - "//mlir:Pass", - ], -) - -cc_test( - name = "rewrite_tests", - size = "small", - srcs = glob([ - "Rewrite/*.cpp", - "Rewrite/*.h", - ]), - deps = [ - "//llvm:gtest_main", - "//mlir:IR", - "//mlir:Rewrite", - ], -) - -cc_test( - name = "dialect_tests", - size = "small", - srcs = glob([ - "Dialect/*.cpp", - "Dialect/*.h", - ]), - deps = [ - "//llvm:TestingSupport", - "//llvm:gtest_main", - "//mlir:Dialect", - ], -) - -cc_test( - name = "quantops_tests", - size = "small", - srcs = glob([ - "Dialect/Quant/*.cpp", - "Dialect/Quant/*.h", - ]), - deps = [ - "//llvm:TestingSupport", - "//llvm:gtest_main", - "//mlir:QuantOps", - "//mlir:Transforms", - ], -) - -cc_test( - name = "scf_tests", - size = "small", - srcs = glob([ - "Dialect/SCF/*.cpp", - "Dialect/SCF/*.h", - ]), - deps = [ - "//llvm:gtest_main", - "//mlir:Parser", - "//mlir:SCFDialect", - "//mlir:StandardOps", - ], -) - -cc_test( - name = "sparse_tensor_tests", - size = "small", - srcs = glob([ - "Dialect/SparseTensor/*.cpp", - "Dialect/SparseTensor/*.h", - ]), - deps = [ - "//llvm:TestingSupport", - "//llvm:gtest_main", - "//mlir:SparseTensorUtils", - ], -) - -cc_test( - name = "spirv_tests", - size = "small", - srcs = glob([ - "Dialect/SPIRV/*.cpp", - "Dialect/SPIRV/*.h", - ]), - deps = [ - "//llvm:TestingSupport", - "//llvm:gtest_main", - "//mlir:SPIRVDeserialization", - "//mlir:SPIRVDialect", - "//mlir:SPIRVSerialization", - ], -) - -cc_test( - name = "dialect_utils_tests", - size = "small", - srcs = glob([ - "Dialect/Utils/*.cpp", - "Dialect/Utils/*.h", - ]), - deps = [ - "//llvm:TestingSupport", - "//llvm:gtest_main", - "//mlir:DialectUtils", - ], -) - -gentbl_cc_library( - name = "EnumsIncGen", - tbl_outs = [ - ( - ["-gen-enum-decls"], - "TableGen/EnumsGenTest.h.inc", - ), - ( - ["-gen-enum-defs"], - "TableGen/EnumsGenTest.cpp.inc", - ), - ], - tblgen = "//mlir:mlir-tblgen", - td_file = "TableGen/enums.td", - deps = [ - "//mlir:OpBaseTdFiles", - ], -) - -gentbl_cc_library( - name = "PassIncGen", - tbl_outs = [ - ( - ["-gen-pass-decls"], - "TableGen/PassGenTest.h.inc", - ), - ], - tblgen = "//mlir:mlir-tblgen", - td_file = "TableGen/passes.td", - deps = [ - "//mlir:PassBaseTdFiles", - "//mlir:RewritePassBaseTdFiles", - ], -) - -gentbl_cc_library( - name = "StructsIncGen", - tbl_outs = [ - ( - ["-gen-struct-attr-decls"], - "TableGen/StructAttrGenTest.h.inc", - ), - ( - ["-gen-struct-attr-defs"], - "TableGen/StructAttrGenTest.cpp.inc", - ), - ], - tblgen = "//mlir:mlir-tblgen", - td_file = "TableGen/structs.td", - deps = [ - "//mlir:OpBaseTdFiles", - ], -) - -cc_test( - name = "tablegen_tests", - size = "small", - srcs = glob([ - "TableGen/*.cpp", - "TableGen/*.h", - ]) + [ - "TableGen/EnumsGenTest.cpp.inc", - "TableGen/EnumsGenTest.h.inc", - "TableGen/StructAttrGenTest.cpp.inc", - "TableGen/StructAttrGenTest.h.inc", - ], - includes = ["TableGen/"], - deps = [ - ":EnumsIncGen", - ":PassIncGen", - ":StructsIncGen", - "//llvm:Support", - "//llvm:TestingSupport", - "//llvm:gtest_main", - "//mlir:IR", - "//mlir:TableGen", - "//mlir/test:TestDialect", - ], -) - -cc_test( - name = "transforms_test", - size = "small", - srcs = glob([ - "Transforms/*.cpp", - "Transforms/*.h", - ]), - deps = [ - "//llvm:gtest_main", - "//mlir:AffineAnalysis", - "//mlir:IR", - "//mlir:Parser", - "//mlir:Pass", - "//mlir:TransformUtils", - "//mlir:Transforms", - ], -) - -cc_test( - name = "analysis_tests", - size = "small", - srcs = glob([ - "Analysis/*.cpp", - "Analysis/*.h", - "Analysis/*/*.cpp", - "Analysis/*/*.h", - "Dialect/Affine/Analysis/AffineStructuresParser.*", - ]), - deps = [ - "//llvm:TestingSupport", - "//llvm:gtest_main", - "//mlir:AffineAnalysis", - "//mlir:Analysis", - "//mlir:IR", - ], -) - -cc_test( - name = "conversion_tests", - size = "small", - srcs = glob([ - "Conversion/*.cpp", - "Conversion/*.h", - "Conversion/*/*.cpp", - "Conversion/*/*.h", - ]), - deps = [ - "//llvm:gtest_main", - "//mlir:ArithmeticDialect", - "//mlir:PDLToPDLInterp", - ], -) - -cc_test( - name = "execution_engine_tests", - size = "small", - srcs = glob([ - "ExecutionEngine/*.cpp", - ]), - tags = [ - # MSAN does not work with JIT. - "nomsan", - ], - deps = [ - "//llvm:TestingSupport", - "//llvm:gtest_main", - "//mlir:AllPassesAndDialects", - "//mlir:Analysis", - "//mlir:ExecutionEngine", - "//mlir:IR", - "//mlir:LinalgToLLVM", - "//mlir:MemRefToLLVM", - "//mlir:mlir_c_runner_utils", - "//mlir:mlir_runner_utils", - ], -) diff --git a/utils/bazel/llvm_configs/BUILD.bazel b/utils/bazel/llvm_configs/BUILD.bazel deleted file mode 100644 index 5a4f9970c0636..0000000000000 --- a/utils/bazel/llvm_configs/BUILD.bazel +++ /dev/null @@ -1,30 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -# These diff tests ensure that the current Bazel configuration does not drift -# from the configuration in the .cmake files, since we don't alway use them -# directly (and even if we did we wouldn't necessarily pick up changes there). -# These are literal change-detector tests. We perform diff testing here since -# it isn't really part of building LLVM and we don't want to include the config -# copies in the workspace used by dependent projects. - -load("@bazel_skylib//rules:diff_test.bzl", "diff_test") - -diff_test( - name = "diff_config.h.cmake", - file1 = "@llvm-project//llvm:include/llvm/Config/config.h.cmake", - file2 = "config.h.cmake", -) - -diff_test( - name = "diff_llvm-config.h.cmake", - file1 = "@llvm-project//llvm:include/llvm/Config/llvm-config.h.cmake", - file2 = "llvm-config.h.cmake", -) - -diff_test( - name = "diff_abi-breaking.h.cmake", - file1 = "@llvm-project//llvm:include/llvm/Config/abi-breaking.h.cmake", - file2 = "abi-breaking.h.cmake", -) diff --git a/utils/bazel/llvm_configs/abi-breaking.h.cmake b/utils/bazel/llvm_configs/abi-breaking.h.cmake deleted file mode 100644 index 2d27e02b1d545..0000000000000 --- a/utils/bazel/llvm_configs/abi-breaking.h.cmake +++ /dev/null @@ -1,62 +0,0 @@ -/*===------- llvm/Config/abi-breaking.h - llvm configuration -------*- C -*-===*/ -/* */ -/* Part of the LLVM Project, under the Apache License v2.0 with LLVM */ -/* Exceptions. */ -/* See https://llvm.org/LICENSE.txt for license information. */ -/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -/* */ -/*===----------------------------------------------------------------------===*/ - -/* This file controls the C++ ABI break introduced in LLVM public header. */ - -#ifndef LLVM_ABI_BREAKING_CHECKS_H -#define LLVM_ABI_BREAKING_CHECKS_H - -/* Define to enable checks that alter the LLVM C++ ABI */ -#cmakedefine01 LLVM_ENABLE_ABI_BREAKING_CHECKS - -/* Define to enable reverse iteration of unordered llvm containers */ -#cmakedefine01 LLVM_ENABLE_REVERSE_ITERATION - -/* Allow selectively disabling link-time mismatch checking so that header-only - ADT content from LLVM can be used without linking libSupport. */ -#if !defined(LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING) || !LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING - -// ABI_BREAKING_CHECKS protection: provides link-time failure when clients build -// mismatch with LLVM -#if defined(_MSC_VER) -// Use pragma with MSVC -#define LLVM_XSTR(s) LLVM_STR(s) -#define LLVM_STR(s) #s -#pragma detect_mismatch("LLVM_ENABLE_ABI_BREAKING_CHECKS", LLVM_XSTR(LLVM_ENABLE_ABI_BREAKING_CHECKS)) -#undef LLVM_XSTR -#undef LLVM_STR -#elif defined(_WIN32) || defined(__CYGWIN__) // Win32 w/o #pragma detect_mismatch -// FIXME: Implement checks without weak. -#elif defined(__cplusplus) -#if !(defined(_AIX) && defined(__GNUC__) && !defined(__clang__)) -#define LLVM_HIDDEN_VISIBILITY __attribute__ ((visibility("hidden"))) -#else -// GCC on AIX does not support visibility attributes. Symbols are not -// exported by default on AIX. -#define LLVM_HIDDEN_VISIBILITY -#endif -namespace llvm { -#if LLVM_ENABLE_ABI_BREAKING_CHECKS -extern int EnableABIBreakingChecks; -LLVM_HIDDEN_VISIBILITY -__attribute__((weak)) int *VerifyEnableABIBreakingChecks = - &EnableABIBreakingChecks; -#else -extern int DisableABIBreakingChecks; -LLVM_HIDDEN_VISIBILITY -__attribute__((weak)) int *VerifyDisableABIBreakingChecks = - &DisableABIBreakingChecks; -#endif -} -#undef LLVM_HIDDEN_VISIBILITY -#endif // _MSC_VER - -#endif // LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING - -#endif diff --git a/utils/bazel/llvm_configs/config.h.cmake b/utils/bazel/llvm_configs/config.h.cmake deleted file mode 100644 index 064d2f27dc18b..0000000000000 --- a/utils/bazel/llvm_configs/config.h.cmake +++ /dev/null @@ -1,362 +0,0 @@ -#ifndef CONFIG_H -#define CONFIG_H - -// Include this header only under the llvm source tree. -// This is a private header. - -/* Exported configuration */ -#include "llvm/Config/llvm-config.h" - -/* Bug report URL. */ -#define BUG_REPORT_URL "${BUG_REPORT_URL}" - -/* Define to 1 to enable backtraces, and to 0 otherwise. */ -#cmakedefine01 ENABLE_BACKTRACES - -/* Define to 1 to enable crash overrides, and to 0 otherwise. */ -#cmakedefine01 ENABLE_CRASH_OVERRIDES - -/* Define to 1 to enable crash memory dumps, and to 0 otherwise. */ -#cmakedefine01 LLVM_ENABLE_CRASH_DUMPS - -/* Define to 1 to prefer forward slashes on Windows, and to 0 prefer - backslashes. */ -#cmakedefine01 LLVM_WINDOWS_PREFER_FORWARD_SLASH - -/* Define to 1 if you have the `backtrace' function. */ -#cmakedefine HAVE_BACKTRACE ${HAVE_BACKTRACE} - -#define BACKTRACE_HEADER <${BACKTRACE_HEADER}> - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_CRASHREPORTERCLIENT_H - -/* can use __crashreporter_info__ */ -#cmakedefine01 HAVE_CRASHREPORTER_INFO - -/* Define to 1 if you have the declaration of `arc4random', and to 0 if you - don't. */ -#cmakedefine01 HAVE_DECL_ARC4RANDOM - -/* Define to 1 if you have the declaration of `FE_ALL_EXCEPT', and to 0 if you - don't. */ -#cmakedefine01 HAVE_DECL_FE_ALL_EXCEPT - -/* Define to 1 if you have the declaration of `FE_INEXACT', and to 0 if you - don't. */ -#cmakedefine01 HAVE_DECL_FE_INEXACT - -/* Define to 1 if you have the declaration of `strerror_s', and to 0 if you - don't. */ -#cmakedefine01 HAVE_DECL_STRERROR_S - -/* Define to 1 if you have the DIA SDK installed, and to 0 if you don't. */ -#cmakedefine01 LLVM_ENABLE_DIA_SDK - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_DLFCN_H ${HAVE_DLFCN_H} - -/* Define if dlopen() is available on this platform. */ -#cmakedefine HAVE_DLOPEN ${HAVE_DLOPEN} - -/* Define if dladdr() is available on this platform. */ -#cmakedefine HAVE_DLADDR ${HAVE_DLADDR} - -/* Define to 1 if we can register EH frames on this platform. */ -#cmakedefine HAVE_REGISTER_FRAME ${HAVE_REGISTER_FRAME} - -/* Define to 1 if we can deregister EH frames on this platform. */ -#cmakedefine HAVE_DEREGISTER_FRAME ${HAVE_DEREGISTER_FRAME} - -/* Define if __unw_add_dynamic_fde() is available on this platform. */ -#cmakedefine HAVE_UNW_ADD_DYNAMIC_FDE ${HAVE_UNW_ADD_DYNAMIC_FDE} - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_ERRNO_H ${HAVE_ERRNO_H} - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_FCNTL_H ${HAVE_FCNTL_H} - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_FENV_H ${HAVE_FENV_H} - -/* Define if libffi is available on this platform. */ -#cmakedefine HAVE_FFI_CALL ${HAVE_FFI_CALL} - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_FFI_FFI_H ${HAVE_FFI_FFI_H} - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_FFI_H ${HAVE_FFI_H} - -/* Define to 1 if you have the `futimens' function. */ -#cmakedefine HAVE_FUTIMENS ${HAVE_FUTIMENS} - -/* Define to 1 if you have the `futimes' function. */ -#cmakedefine HAVE_FUTIMES ${HAVE_FUTIMES} - -/* Define to 1 if you have the `getpagesize' function. */ -#cmakedefine HAVE_GETPAGESIZE ${HAVE_GETPAGESIZE} - -/* Define to 1 if you have the `getrlimit' function. */ -#cmakedefine HAVE_GETRLIMIT ${HAVE_GETRLIMIT} - -/* Define to 1 if you have the `getrusage' function. */ -#cmakedefine HAVE_GETRUSAGE ${HAVE_GETRUSAGE} - -/* Define to 1 if you have the `isatty' function. */ -#cmakedefine HAVE_ISATTY 1 - -/* Define to 1 if you have the `edit' library (-ledit). */ -#cmakedefine HAVE_LIBEDIT ${HAVE_LIBEDIT} - -/* Define to 1 if you have the `pfm' library (-lpfm). */ -#cmakedefine HAVE_LIBPFM ${HAVE_LIBPFM} - -/* Define to 1 if the `perf_branch_entry' struct has field cycles. */ -#cmakedefine LIBPFM_HAS_FIELD_CYCLES ${LIBPFM_HAS_FIELD_CYCLES} - -/* Define to 1 if you have the `psapi' library (-lpsapi). */ -#cmakedefine HAVE_LIBPSAPI ${HAVE_LIBPSAPI} - -/* Define to 1 if you have the `pthread' library (-lpthread). */ -#cmakedefine HAVE_LIBPTHREAD ${HAVE_LIBPTHREAD} - -/* Define to 1 if you have the `pthread_getname_np' function. */ -#cmakedefine HAVE_PTHREAD_GETNAME_NP ${HAVE_PTHREAD_GETNAME_NP} - -/* Define to 1 if you have the `pthread_setname_np' function. */ -#cmakedefine HAVE_PTHREAD_SETNAME_NP ${HAVE_PTHREAD_SETNAME_NP} - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_LINK_H ${HAVE_LINK_H} - -/* Define to 1 if you have the `lseek64' function. */ -#cmakedefine HAVE_LSEEK64 ${HAVE_LSEEK64} - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_MACH_MACH_H ${HAVE_MACH_MACH_H} - -/* Define to 1 if you have the `mallctl' function. */ -#cmakedefine HAVE_MALLCTL ${HAVE_MALLCTL} - -/* Define to 1 if you have the `mallinfo' function. */ -#cmakedefine HAVE_MALLINFO ${HAVE_MALLINFO} - -/* Define to 1 if you have the `mallinfo2' function. */ -#cmakedefine HAVE_MALLINFO2 ${HAVE_MALLINFO2} - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_MALLOC_MALLOC_H ${HAVE_MALLOC_MALLOC_H} - -/* Define to 1 if you have the `malloc_zone_statistics' function. */ -#cmakedefine HAVE_MALLOC_ZONE_STATISTICS ${HAVE_MALLOC_ZONE_STATISTICS} - -/* Define to 1 if you have the `posix_spawn' function. */ -#cmakedefine HAVE_POSIX_SPAWN ${HAVE_POSIX_SPAWN} - -/* Define to 1 if you have the `pread' function. */ -#cmakedefine HAVE_PREAD ${HAVE_PREAD} - -/* Have pthread_getspecific */ -#cmakedefine HAVE_PTHREAD_GETSPECIFIC ${HAVE_PTHREAD_GETSPECIFIC} - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_PTHREAD_H ${HAVE_PTHREAD_H} - -/* Have pthread_mutex_lock */ -#cmakedefine HAVE_PTHREAD_MUTEX_LOCK ${HAVE_PTHREAD_MUTEX_LOCK} - -/* Have pthread_rwlock_init */ -#cmakedefine HAVE_PTHREAD_RWLOCK_INIT ${HAVE_PTHREAD_RWLOCK_INIT} - -/* Define to 1 if you have the `sbrk' function. */ -#cmakedefine HAVE_SBRK ${HAVE_SBRK} - -/* Define to 1 if you have the `setenv' function. */ -#cmakedefine HAVE_SETENV ${HAVE_SETENV} - -/* Define to 1 if you have the `setrlimit' function. */ -#cmakedefine HAVE_SETRLIMIT ${HAVE_SETRLIMIT} - -/* Define to 1 if you have the `sigaltstack' function. */ -#cmakedefine HAVE_SIGALTSTACK ${HAVE_SIGALTSTACK} - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SIGNAL_H ${HAVE_SIGNAL_H} - -/* Define to 1 if you have the `strerror' function. */ -#cmakedefine HAVE_STRERROR ${HAVE_STRERROR} - -/* Define to 1 if you have the `strerror_r' function. */ -#cmakedefine HAVE_STRERROR_R ${HAVE_STRERROR_R} - -/* Define to 1 if you have the `sysconf' function. */ -#cmakedefine HAVE_SYSCONF ${HAVE_SYSCONF} - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_IOCTL_H ${HAVE_SYS_IOCTL_H} - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_MMAN_H ${HAVE_SYS_MMAN_H} - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_PARAM_H ${HAVE_SYS_PARAM_H} - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_RESOURCE_H ${HAVE_SYS_RESOURCE_H} - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_STAT_H ${HAVE_SYS_STAT_H} - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_TIME_H ${HAVE_SYS_TIME_H} - -/* Define to 1 if stat struct has st_mtimespec member .*/ -#cmakedefine HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC ${HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC} - -/* Define to 1 if stat struct has st_mtim member. */ -#cmakedefine HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC ${HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC} - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES_H} - -/* Define if the setupterm() function is supported this platform. */ -#cmakedefine LLVM_ENABLE_TERMINFO ${LLVM_ENABLE_TERMINFO} - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_TERMIOS_H ${HAVE_TERMIOS_H} - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_UNISTD_H ${HAVE_UNISTD_H} - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_VALGRIND_VALGRIND_H ${HAVE_VALGRIND_VALGRIND_H} - -/* Have host's _alloca */ -#cmakedefine HAVE__ALLOCA ${HAVE__ALLOCA} - -/* Define to 1 if you have the `_chsize_s' function. */ -#cmakedefine HAVE__CHSIZE_S ${HAVE__CHSIZE_S} - -/* Define to 1 if you have the `_Unwind_Backtrace' function. */ -#cmakedefine HAVE__UNWIND_BACKTRACE ${HAVE__UNWIND_BACKTRACE} - -/* Have host's __alloca */ -#cmakedefine HAVE___ALLOCA ${HAVE___ALLOCA} - -/* Have host's __ashldi3 */ -#cmakedefine HAVE___ASHLDI3 ${HAVE___ASHLDI3} - -/* Have host's __ashrdi3 */ -#cmakedefine HAVE___ASHRDI3 ${HAVE___ASHRDI3} - -/* Have host's __chkstk */ -#cmakedefine HAVE___CHKSTK ${HAVE___CHKSTK} - -/* Have host's __chkstk_ms */ -#cmakedefine HAVE___CHKSTK_MS ${HAVE___CHKSTK_MS} - -/* Have host's __cmpdi2 */ -#cmakedefine HAVE___CMPDI2 ${HAVE___CMPDI2} - -/* Have host's __divdi3 */ -#cmakedefine HAVE___DIVDI3 ${HAVE___DIVDI3} - -/* Have host's __fixdfdi */ -#cmakedefine HAVE___FIXDFDI ${HAVE___FIXDFDI} - -/* Have host's __fixsfdi */ -#cmakedefine HAVE___FIXSFDI ${HAVE___FIXSFDI} - -/* Have host's __floatdidf */ -#cmakedefine HAVE___FLOATDIDF ${HAVE___FLOATDIDF} - -/* Have host's __lshrdi3 */ -#cmakedefine HAVE___LSHRDI3 ${HAVE___LSHRDI3} - -/* Have host's __main */ -#cmakedefine HAVE___MAIN ${HAVE___MAIN} - -/* Have host's __moddi3 */ -#cmakedefine HAVE___MODDI3 ${HAVE___MODDI3} - -/* Have host's __udivdi3 */ -#cmakedefine HAVE___UDIVDI3 ${HAVE___UDIVDI3} - -/* Have host's __umoddi3 */ -#cmakedefine HAVE___UMODDI3 ${HAVE___UMODDI3} - -/* Have host's ___chkstk */ -#cmakedefine HAVE____CHKSTK ${HAVE____CHKSTK} - -/* Have host's ___chkstk_ms */ -#cmakedefine HAVE____CHKSTK_MS ${HAVE____CHKSTK_MS} - -/* Linker version detected at compile time. */ -#cmakedefine HOST_LINK_VERSION "${HOST_LINK_VERSION}" - -/* Target triple LLVM will generate code for by default */ -/* Doesn't use `cmakedefine` because it is allowed to be empty. */ -#define LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}" - -/* Define if zlib compression is available */ -#cmakedefine01 LLVM_ENABLE_ZLIB - -/* Define if overriding target triple is enabled */ -#cmakedefine LLVM_TARGET_TRIPLE_ENV "${LLVM_TARGET_TRIPLE_ENV}" - -/* LLVM version information */ -#cmakedefine LLVM_VERSION_INFO "${LLVM_VERSION_INFO}" - -/* Whether tools show host and target info when invoked with --version */ -#cmakedefine01 LLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO - -/* Define if libxml2 is supported on this platform. */ -#cmakedefine LLVM_ENABLE_LIBXML2 ${LLVM_ENABLE_LIBXML2} - -/* Define to the extension used for shared libraries, say, ".so". */ -#cmakedefine LTDL_SHLIB_EXT "${LTDL_SHLIB_EXT}" - -/* Define to the extension used for plugin libraries, say, ".so". */ -#cmakedefine LLVM_PLUGIN_EXT "${LLVM_PLUGIN_EXT}" - -/* Define to the address where bug reports for this package should be sent. */ -#cmakedefine PACKAGE_BUGREPORT "${PACKAGE_BUGREPORT}" - -/* Define to the full name of this package. */ -#cmakedefine PACKAGE_NAME "${PACKAGE_NAME}" - -/* Define to the full name and version of this package. */ -#cmakedefine PACKAGE_STRING "${PACKAGE_STRING}" - -/* Define to the version of this package. */ -#cmakedefine PACKAGE_VERSION "${PACKAGE_VERSION}" - -/* Define to the vendor of this package. */ -#cmakedefine PACKAGE_VENDOR "${PACKAGE_VENDOR}" - -/* Define as the return type of signal handlers (`int' or `void'). */ -#cmakedefine RETSIGTYPE ${RETSIGTYPE} - -/* Define if std::is_trivially_copyable is supported */ -#cmakedefine HAVE_STD_IS_TRIVIALLY_COPYABLE ${HAVE_STD_IS_TRIVIALLY_COPYABLE} - -/* Define to a function implementing stricmp */ -#cmakedefine stricmp ${stricmp} - -/* Define to a function implementing strdup */ -#cmakedefine strdup ${strdup} - -/* Whether GlobalISel rule coverage is being collected */ -#cmakedefine01 LLVM_GISEL_COV_ENABLED - -/* Define to the default GlobalISel coverage file prefix */ -#cmakedefine LLVM_GISEL_COV_PREFIX "${LLVM_GISEL_COV_PREFIX}" - -/* Whether Timers signpost passes in Xcode Instruments */ -#cmakedefine01 LLVM_SUPPORT_XCODE_SIGNPOSTS - -#cmakedefine HAVE_PROC_PID_RUSAGE 1 - -#endif diff --git a/utils/bazel/llvm_configs/llvm-config.h.cmake b/utils/bazel/llvm_configs/llvm-config.h.cmake deleted file mode 100644 index ec18b40fe04d9..0000000000000 --- a/utils/bazel/llvm_configs/llvm-config.h.cmake +++ /dev/null @@ -1,109 +0,0 @@ -/*===------- llvm/Config/llvm-config.h - llvm configuration -------*- C -*-===*/ -/* */ -/* Part of the LLVM Project, under the Apache License v2.0 with LLVM */ -/* Exceptions. */ -/* See https://llvm.org/LICENSE.txt for license information. */ -/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -/* */ -/*===----------------------------------------------------------------------===*/ - -/* This file enumerates variables from the LLVM configuration so that they - can be in exported headers and won't override package specific directives. - This is a C header that can be included in the llvm-c headers. */ - -#ifndef LLVM_CONFIG_H -#define LLVM_CONFIG_H - -/* Define if LLVM_ENABLE_DUMP is enabled */ -#cmakedefine LLVM_ENABLE_DUMP - -/* Target triple LLVM will generate code for by default */ -#cmakedefine LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}" - -/* Define if threads enabled */ -#cmakedefine01 LLVM_ENABLE_THREADS - -/* Has gcc/MSVC atomic intrinsics */ -#cmakedefine01 LLVM_HAS_ATOMICS - -/* Host triple LLVM will be executed on */ -#cmakedefine LLVM_HOST_TRIPLE "${LLVM_HOST_TRIPLE}" - -/* LLVM architecture name for the native architecture, if available */ -#cmakedefine LLVM_NATIVE_ARCH ${LLVM_NATIVE_ARCH} - -/* LLVM name for the native AsmParser init function, if available */ -#cmakedefine LLVM_NATIVE_ASMPARSER LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser - -/* LLVM name for the native AsmPrinter init function, if available */ -#cmakedefine LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter - -/* LLVM name for the native Disassembler init function, if available */ -#cmakedefine LLVM_NATIVE_DISASSEMBLER LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler - -/* LLVM name for the native Target init function, if available */ -#cmakedefine LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target - -/* LLVM name for the native TargetInfo init function, if available */ -#cmakedefine LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo - -/* LLVM name for the native target MC init function, if available */ -#cmakedefine LLVM_NATIVE_TARGETMC LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC - -/* LLVM name for the native target MCA init function, if available */ -#cmakedefine LLVM_NATIVE_TARGETMCA LLVMInitialize${LLVM_NATIVE_ARCH}TargetMCA - -/* Define if this is Unixish platform */ -#cmakedefine LLVM_ON_UNIX ${LLVM_ON_UNIX} - -/* Define if we have the Intel JIT API runtime support library */ -#cmakedefine01 LLVM_USE_INTEL_JITEVENTS - -/* Define if we have the oprofile JIT-support library */ -#cmakedefine01 LLVM_USE_OPROFILE - -/* Define if we have the perf JIT-support library */ -#cmakedefine01 LLVM_USE_PERF - -/* Major version of the LLVM API */ -#define LLVM_VERSION_MAJOR ${LLVM_VERSION_MAJOR} - -/* Minor version of the LLVM API */ -#define LLVM_VERSION_MINOR ${LLVM_VERSION_MINOR} - -/* Patch version of the LLVM API */ -#define LLVM_VERSION_PATCH ${LLVM_VERSION_PATCH} - -/* LLVM version string */ -#define LLVM_VERSION_STRING "${PACKAGE_VERSION}" - -/* Whether LLVM records statistics for use with GetStatistics(), - * PrintStatistics() or PrintStatisticsJSON() - */ -#cmakedefine01 LLVM_FORCE_ENABLE_STATS - -/* Define if we have z3 and want to build it */ -#cmakedefine LLVM_WITH_Z3 ${LLVM_WITH_Z3} - -/* Define if we have curl and want to use it */ -#cmakedefine LLVM_ENABLE_CURL ${LLVM_ENABLE_CURL} - -/* Define if LLVM was built with a dependency to the libtensorflow dynamic library */ -#cmakedefine LLVM_HAVE_TF_API - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYSEXITS_H ${HAVE_SYSEXITS_H} - -/* Define to 1 to enable the experimental new pass manager by default */ -#cmakedefine01 LLVM_ENABLE_NEW_PASS_MANAGER - -/* Define if the xar_open() function is supported on this platform. */ -#cmakedefine LLVM_HAVE_LIBXAR ${LLVM_HAVE_LIBXAR} - -/* Define if building libLLVM shared library */ -#cmakedefine LLVM_BUILD_LLVM_DYLIB - -/* Define if building LLVM with BUILD_SHARED_LIBS */ -#cmakedefine LLVM_BUILD_SHARED_LIBS - -#endif diff --git a/utils/bazel/overlay_directories.py b/utils/bazel/overlay_directories.py deleted file mode 100755 index 6cf1a078df6c0..0000000000000 --- a/utils/bazel/overlay_directories.py +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/python3 - -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -"""Overlays two directories into a target directory using symlinks. - -Tries to minimize the number of symlinks created (that is, does not symlink -every single file). Symlinks every file in the overlay directory. Only symlinks -individual files in the source directory if their parent directory is also -contained in the overlay directory tree. -""" - -import argparse -import errno -import os -import sys - - -def _check_python_version(): - if sys.version_info[0] < 3: - raise RuntimeError( - "Must be invoked with a python 3 interpreter but was %s" % - sys.executable) - - -def _check_dir_exists(path): - if not os.path.isdir(path): - raise OSError(errno.ENOENT, os.strerror(errno.ENOENT), path) - - -def parse_arguments(): - parser = argparse.ArgumentParser(description=""" - Overlays two directories into a target directory using symlinks. - - Tries to minimize the number of symlinks created (that is, does not symlink - every single file). Symlinks every file in the overlay directory. Only - symlinks individual files in the source directory if their parent directory - is also contained in the overlay directory tree. - """) - parser.add_argument( - "--src", - required=True, - help="Directory that contains most of the content to symlink.") - parser.add_argument( - "--overlay", - required=True, - help="Directory to overlay on top of the source directory.") - parser.add_argument( - "--target", - required=True, - help="Directory in which to place the fused symlink directories.") - - args = parser.parse_args() - - _check_dir_exists(args.target) - _check_dir_exists(args.overlay) - _check_dir_exists(args.src) - - return args - - -def _symlink_abs(from_path, to_path): - os.symlink(os.path.abspath(from_path), os.path.abspath(to_path)) - - -def main(args): - for root, dirs, files in os.walk(args.overlay): - # We could do something more intelligent here and only symlink individual - # files if the directory is present in both overlay and src. This could also - # be generalized to an arbitrary number of directories without any - # "src/overlay" distinction. In the current use case we only have two and - # the overlay directory is always small, so putting that off for now. - rel_root = os.path.relpath(root, start=args.overlay) - if rel_root != ".": - os.mkdir(os.path.join(args.target, rel_root)) - - for file in files: - relpath = os.path.join(rel_root, file) - _symlink_abs(os.path.join(args.overlay, relpath), - os.path.join(args.target, relpath)) - - for src_entry in os.listdir(os.path.join(args.src, rel_root)): - if src_entry not in dirs: - relpath = os.path.join(rel_root, src_entry) - _symlink_abs(os.path.join(args.src, relpath), - os.path.join(args.target, relpath)) - - -if __name__ == "__main__": - _check_python_version() - main(parse_arguments()) diff --git a/utils/bazel/terminfo.bzl b/utils/bazel/terminfo.bzl deleted file mode 100644 index 70281e1119656..0000000000000 --- a/utils/bazel/terminfo.bzl +++ /dev/null @@ -1,203 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -"""Repository rules to configure the terminfo used by LLVM. - -Most users should pick one of the explicit rules to configure their use of terminfo -with LLVM: -- `llvm_terminfo_system` will detect and link against a terminfo-implementing - system library (non-hermetically). -- 'llvm_terminfo_disable` will disable terminfo completely. - -If you would like to make your build configurable, you can use -`llvm_terminfo_from_env`. By default, this will disable terminfo, but will -inspect the environment variable (most easily set with a `--repo_env` flag to -the Bazel invocation) `BAZEL_LLVM_TERMINFO_STRATEGY`. If it is set to -`system` then it will behave the same as `llvm_terminfo_system`. Any other -setting will disable terminfo the same as not setting it at all. -""" - -def _llvm_terminfo_disable_impl(repository_ctx): - repository_ctx.template( - "BUILD", - repository_ctx.attr._disable_build_template, - executable = False, - ) - -_terminfo_disable_attrs = { - "_disable_build_template": attr.label( - default = Label("//utils/bazel/deps_impl:terminfo_disable.BUILD"), - allow_single_file = True, - ), -} - -llvm_terminfo_disable = repository_rule( - implementation = _llvm_terminfo_disable_impl, - attrs = _terminfo_disable_attrs, -) - -def _find_c_compiler(repository_ctx): - """Returns the path to a plausible C compiler. - - This routine will only reliably work on roughly POSIX-y systems as it - ultimately falls back on the `cc` binary. Fortunately, the thing we are - trying to use it for (detecting if a trivial source file can compile and - link against a particular library) requires very little. - """ - cc_env = repository_ctx.os.environ.get("CC") - cc = None - if cc_env: - if "/" in cc_env: - return repository_ctx.path(cc_env) - else: - return repository_ctx.which(cc_env) - - # Look for Clang, GCC, and the POSIX / UNIX specified C compiler - # binaries. - for compiler in ["clang", "gcc", "c99", "c89", "cc"]: - cc = repository_ctx.which(compiler) - if cc: - return cc - - return None - -def _try_link(repository_ctx, cc, source, linker_flags): - """Returns `True` if able to link the source with the linker flag. - - Given a source file that contains references to library routines, this - will check that when linked with the provided linker flag, those - references are successfully resolved. This routine assumes a generally - POSIX-y and GCC-ish compiler and environment and shouldn't be expected to - work outside of that. - """ - cmd = [ - cc, - # Force discard the linked executable. - "-o", - "/dev/null", - # Leave language detection to the compiler. - source, - ] - - # The linker flag must be valid for a compiler invocation of the link step, - # so just append them to the command. - cmd += linker_flags - exec_result = repository_ctx.execute(cmd, timeout = 20) - return exec_result.return_code == 0 - -def _llvm_terminfo_system_impl(repository_ctx): - # LLVM doesn't need terminfo support on Windows, so just disable it. - if repository_ctx.os.name.lower().find("windows") != -1: - _llvm_terminfo_disable_impl(repository_ctx) - return - - if len(repository_ctx.attr.system_linkopts) > 0: - linkopts = repository_ctx.attr.system_linkopts - else: - required = repository_ctx.attr.system_required - - # Find a C compiler we can use to detect viable linkopts on this system. - cc = _find_c_compiler(repository_ctx) - if not cc: - if required: - fail("Failed to find a C compiler executable") - else: - _llvm_terminfo_disable_impl(repository_ctx) - return - - # Get the source file we use to detect successful linking of terminfo. - source = repository_ctx.path(repository_ctx.attr._terminfo_test_source) - - # Collect the candidate linkopts and wrap them into a list. Ideally, - # these would be provided as lists, but Bazel doesn't currently - # support that. See: https://github.com/bazelbuild/bazel/issues/12178 - linkopts_candidates = [[x] for x in repository_ctx.attr.candidate_system_linkopts] - linkopts = None - - # For each candidate, try to use it to link our test source file. - for linkopts_candidate in linkopts_candidates: - if _try_link(repository_ctx, cc, source, linkopts_candidate): - linkopts = linkopts_candidate - break - - # If we never found a viable linkopts candidate, either error or disable - # terminfo for LLVM. - if not linkopts: - if required: - fail("Failed to detect which linkopt would successfully provide the " + - "necessary terminfo functionality") - else: - _llvm_terminfo_disable_impl(repository_ctx) - return - - repository_ctx.template( - "BUILD", - repository_ctx.attr._system_build_template, - substitutions = { - "{TERMINFO_LINKOPTS}": str(linkopts), - }, - executable = False, - ) - -def _merge_attrs(attrs_list): - attrs = {} - for input_attrs in attrs_list: - attrs.update(input_attrs) - return attrs - -_terminfo_system_attrs = _merge_attrs([_terminfo_disable_attrs, { - "_system_build_template": attr.label( - default = Label("//utils/bazel/deps_impl:terminfo_system.BUILD"), - allow_single_file = True, - ), - "_terminfo_test_source": attr.label( - default = Label("//utils/bazel/deps_impl:terminfo_test.c"), - allow_single_file = True, - ), - "candidate_system_linkopts": attr.string_list( - default = [ - "-lterminfo", - "-ltinfo", - "-lcurses", - "-lncurses", - "-lncursesw", - ], - doc = "Candidate linkopts to test and see if they can link " + - "successfully.", - ), - "system_required": attr.bool( - default = False, - doc = "Require that one of the candidates is detected successfully on POSIX platforms where it is needed.", - ), - "system_linkopts": attr.string_list( - default = [], - doc = "If non-empty, a specific array of linkopts to use to " + - "successfully link against the terminfo library. No " + - "detection is performed if this option is provided, it " + - "directly forces the use of these link options. No test is " + - "run to determine if they are valid or work correctly either.", - ), -}]) - -llvm_terminfo_system = repository_rule( - implementation = _llvm_terminfo_system_impl, - configure = True, - local = True, - attrs = _terminfo_system_attrs, -) - -def _llvm_terminfo_from_env_impl(repository_ctx): - terminfo_strategy = repository_ctx.os.environ.get("BAZEL_LLVM_TERMINFO_STRATEGY") - if terminfo_strategy == "system": - _llvm_terminfo_system_impl(repository_ctx) - else: - _llvm_terminfo_disable_impl(repository_ctx) - -llvm_terminfo_from_env = repository_rule( - implementation = _llvm_terminfo_from_env_impl, - configure = True, - local = True, - attrs = _merge_attrs([_terminfo_disable_attrs, _terminfo_system_attrs]), - environ = ["BAZEL_LLVM_TERMINFO_STRATEGY", "CC"], -) diff --git a/utils/bazel/third_party_build/BUILD b/utils/bazel/third_party_build/BUILD deleted file mode 100644 index 98077a0651d9d..0000000000000 --- a/utils/bazel/third_party_build/BUILD +++ /dev/null @@ -1,5 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -licenses(["notice"]) diff --git a/utils/bazel/third_party_build/vulkan_headers.BUILD b/utils/bazel/third_party_build/vulkan_headers.BUILD deleted file mode 100644 index 33c0d98f53493..0000000000000 --- a/utils/bazel/third_party_build/vulkan_headers.BUILD +++ /dev/null @@ -1,30 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -package( - default_visibility = ["//visibility:public"], - licenses = ["notice"], -) - -# Exports all headers but defining VK_NO_PROTOTYPES to disable the -# inclusion of C function prototypes. Useful if dynamically loading -# all symbols via dlopen/etc. -# Not all headers are hermetic, so they are just included as textual -# headers to disable additional validation. -cc_library( - name = "vulkan_headers_no_prototypes", - defines = ["VK_NO_PROTOTYPES"], - includes = ["include"], - textual_hdrs = glob(["include/vulkan/*.h"]), -) - -# Exports all headers, including C function prototypes. Useful if statically -# linking against the Vulkan SDK. -# Not all headers are hermetic, so they are just included as textual -# headers to disable additional validation. -cc_library( - name = "vulkan_headers", - includes = ["include"], - textual_hdrs = glob(["include/vulkan/*.h"]), -) diff --git a/utils/bazel/third_party_build/zlib.BUILD b/utils/bazel/third_party_build/zlib.BUILD deleted file mode 100644 index 7206e7f1f7fe2..0000000000000 --- a/utils/bazel/third_party_build/zlib.BUILD +++ /dev/null @@ -1,46 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -package( - default_visibility = ["//visibility:public"], - # BSD/MIT-like license (for zlib) - licenses = ["notice"], -) - -cc_library( - name = "zlib", - srcs = [ - "adler32.c", - "compress.c", - "crc32.c", - "crc32.h", - "deflate.c", - "deflate.h", - "gzclose.c", - "gzguts.h", - "gzlib.c", - "gzread.c", - "gzwrite.c", - "infback.c", - "inffast.c", - "inffast.h", - "inffixed.h", - "inflate.c", - "inflate.h", - "inftrees.c", - "inftrees.h", - "trees.c", - "trees.h", - "uncompr.c", - "zconf.h", - "zutil.c", - "zutil.h", - ], - hdrs = ["zlib.h"], - copts = [ - "-Wno-shift-negative-value", - "-DZ_HAVE_UNISTD_H", - ], - includes = ["."], -) diff --git a/utils/bazel/vulkan_sdk.bzl b/utils/bazel/vulkan_sdk.bzl deleted file mode 100644 index 1252ccd2147df..0000000000000 --- a/utils/bazel/vulkan_sdk.bzl +++ /dev/null @@ -1,43 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -"""Repository rule to statically link against the Vulkan SDK. - -Requires installing the Vulkan SDK from https://vulkan.lunarg.com/. - -If the Vulkan SDK is not installed, this generates an empty rule and you may -encounter linker errors like `error: undefined reference to 'vkCreateInstance'`. -""" - -def _impl(repository_ctx): - if "VULKAN_SDK" in repository_ctx.os.environ: - sdk_path = repository_ctx.os.environ["VULKAN_SDK"] - repository_ctx.symlink(sdk_path, "vulkan-sdk") - - repository_ctx.file("BUILD", """ -cc_library( - name = "sdk", - srcs = select({ - "@bazel_tools//src/conditions:windows": [ - "vulkan-sdk/Lib/vulkan-1.lib" - ], - "//conditions:default": [ - "vulkan-sdk/lib/libvulkan.so.1", - ], - }), - visibility = ["//visibility:public"], -)""") - else: - # Empty rule. Will fail to link for just targets that use Vulkan. - repository_ctx.file("BUILD", """ -cc_library( - name = "sdk", - srcs = [], - visibility = ["//visibility:public"], -)""") - -vulkan_sdk_setup = repository_rule( - implementation = _impl, - local = True, -) diff --git a/utils/bazel/zlib.bzl b/utils/bazel/zlib.bzl deleted file mode 100644 index 18f8a0023481e..0000000000000 --- a/utils/bazel/zlib.bzl +++ /dev/null @@ -1,112 +0,0 @@ -# This file is licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -"""Repository rules to configure the zlib used by LLVM. - -Most users should pick one of the explicit rules to configure their use of zlib -with LLVM: -- `llvm_zlib_external` will link against an external Bazel zlib repository. -- `llvm_zlib_system` will link against the system zlib (non-hermetically). -- 'llvm_zlib_disable` will disable zlib completely. - -If you would like to make your build configurable, you can use -`llvm_zlib_from_env`. By default, this will disable zlib, but will inspect -the environment variable (most easily set with a `--repo_env` flag to the -Bazel invocation) `BAZEL_LLVM_ZLIB_STRATEGY`. If it is set to `external`, -then it will behave the same as `llvm_zlib_external`. If it is set to -`system` then it will behave the same as `llvm_zlib_system`. Any other -setting will disable zlib the same as not setting it at all. -""" - -def _llvm_zlib_external_impl(repository_ctx): - repository_ctx.template( - "BUILD", - repository_ctx.attr._external_build_template, - substitutions = { - "@external_zlib_repo//:zlib_rule": repository_ctx.attr.external_zlib, - }, - executable = False, - ) - -llvm_zlib_external = repository_rule( - implementation = _llvm_zlib_external_impl, - attrs = { - "_external_build_template": attr.label( - default = Label("//utils/bazel/deps_impl:zlib_external.BUILD"), - allow_single_file = True, - ), - "external_zlib": attr.string( - doc = "The dependency that should be used for the external zlib library.", - mandatory = True, - ), - }, -) - -def _llvm_zlib_system_impl(repository_ctx): - repository_ctx.template( - "BUILD", - repository_ctx.attr._system_build_template, - executable = False, - ) - -# While it may seem like this needs to be local, it doesn't actually inspect -# any local state, it just configures to build against that local state. -llvm_zlib_system = repository_rule( - implementation = _llvm_zlib_system_impl, - attrs = { - "_system_build_template": attr.label( - default = Label("//utils/bazel/deps_impl:zlib_system.BUILD"), - allow_single_file = True, - ), - }, -) - -def _llvm_zlib_disable_impl(repository_ctx): - repository_ctx.template( - "BUILD", - repository_ctx.attr._disable_build_template, - executable = False, - ) - -llvm_zlib_disable = repository_rule( - implementation = _llvm_zlib_disable_impl, - attrs = { - "_disable_build_template": attr.label( - default = Label("//utils/bazel/deps_impl:zlib_disable.BUILD"), - allow_single_file = True, - ), - }, -) - -def _llvm_zlib_from_env_impl(repository_ctx): - zlib_strategy = repository_ctx.os.environ.get("BAZEL_LLVM_ZLIB_STRATEGY") - if zlib_strategy == "external": - _llvm_zlib_external_impl(repository_ctx) - elif zlib_strategy == "system": - _llvm_zlib_system_impl(repository_ctx) - else: - _llvm_zlib_disable_impl(repository_ctx) - -llvm_zlib_from_env = repository_rule( - implementation = _llvm_zlib_from_env_impl, - attrs = { - "_disable_build_template": attr.label( - default = Label("//utils/bazel/deps_impl:zlib_disable.BUILD"), - allow_single_file = True, - ), - "_external_build_template": attr.label( - default = Label("//utils/bazel/deps_impl:zlib_external.BUILD"), - allow_single_file = True, - ), - "_system_build_template": attr.label( - default = Label("//utils/bazel/deps_impl:zlib_system.BUILD"), - allow_single_file = True, - ), - "external_zlib": attr.label( - doc = "The dependency that should be used for the external zlib library.", - mandatory = True, - ), - }, - environ = ["BAZEL_LLVM_ZLIB_STRATEGY"], -)