Index LLVM project #1411
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Workflow to index LLVM project. | |
# | |
# Because the indexing takes more than an hour, our GITHUB_TOKEN credentials may | |
# expire. A token `secrets.RELEASE_TOKEN` must exist with public_repo scope. | |
name: Index LLVM project | |
on: | |
# Run daily at 0:20 (UTC) (arbitrary time) | |
schedule: | |
- cron: "20 0 * * *" | |
# Allow triggering manually: | |
# curl -XPOST -d '{"event_type":"index"}' \ | |
# "-HAuthorization: Bearer <token>" \ | |
# https://api.github.com/repos/clangd/llvm-remote-index/dispatches | |
repository_dispatch: { types: index } | |
jobs: | |
index: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Clone scripts | |
uses: actions/checkout@v2 | |
- name: Install system tools | |
run: sudo apt-get install ninja-build build-essential swig python3-dev libedit-dev libncurses5-dev | |
- name: Set environment variables | |
run: | | |
echo "CMAKE_BUILD_DIR=llvm-project/build" >> $GITHUB_ENV | |
- name: Fetch clangd-indexer | |
run: > | |
ASSET_PREFIX="clangd_indexing_tools-linux" | |
./download_latest_release_assets.py | |
--repository clangd/clangd | |
--output-name $ASSET_PREFIX.zip | |
--asset-prefix $ASSET_PREFIX | |
unzip $ASSET_PREFIX.zip | |
echo "CLANGD_INDEXER_BIN=$(find . -name 'clangd-indexer')" | |
>> $GITHUB_ENV | |
- name: Clone LLVM | |
uses: actions/checkout@v2 | |
with: | |
repository: llvm/llvm-project | |
path: llvm-project | |
# Use clangd/actions/pick after https://github.com/ramasilveyra/last-successful-gh-commit/issues/2 has been addressed. | |
ref: main | |
- name: Compute release info | |
run: | | |
echo "RELEASE_COMMIT=$(git -C llvm-project rev-parse HEAD)" >> $GITHUB_ENV | |
echo "RELEASE_COMMIT_SHORT=$(printf '%.12s' $(git -C llvm-project rev-parse HEAD))" >> $GITHUB_ENV | |
echo "RELEASE_DATE=$(date -u +%Y%m%d)" >> $GITHUB_ENV | |
# Build generated files. | |
- name: CMake | |
run: > | |
mkdir ${{ env.CMAKE_BUILD_DIR }} | |
cmake -G Ninja -S llvm-project/llvm -B ${{ env.CMAKE_BUILD_DIR }} | |
"-DLLVM_ENABLE_PROJECTS=all" | |
"-DCMAKE_BUILD_TYPE=Release" | |
"-DCMAKE_C_COMPILER=clang" | |
"-DCMAKE_CXX_COMPILER=clang++" | |
- name: Build generated files to ensure valid index | |
run: > | |
ninja -C ${{ env.CMAKE_BUILD_DIR }} -t targets rule CUSTOM_COMMAND | | |
grep -E "\.(cpp|h|inc)\$" | | |
xargs ninja -C ${{ env.CMAKE_BUILD_DIR }} | |
# Create compile_commands.json for the indexer: Debug build type is needed | |
# to index code behind #ifndef NDEBUG and enable assertions. At this point | |
# all source files were generated and all we need is new | |
# compile_commands.json. | |
- name: Generate compile_commands | |
run: > | |
cmake -G Ninja -S llvm-project/llvm -B ${{ env.CMAKE_BUILD_DIR }} | |
"-DLLVM_ENABLE_PROJECTS=all" | |
"-DCMAKE_BUILD_TYPE=Debug" | |
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON" | |
- name: Run clangd-indexer | |
run: > | |
${{ env.CLANGD_INDEXER_BIN }} --executor=all-TUs | |
${{env.CMAKE_BUILD_DIR}}/compile_commands.json > llvm.idx | |
- name: Archive LLVM index | |
run: > | |
7z a llvm-index.zip llvm.idx | |
- name: Create release | |
uses: actions/create-release@v1 | |
id: create_release | |
env: | |
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} | |
with: | |
tag_name: index/${{ env.RELEASE_DATE }} | |
release_name: ${{ env.RELEASE_DATE }} | |
body: | | |
Index snapshot built from llvm/llvm-project@${{ env.RELEASE_COMMIT }} on ${{ env.RELEASE_DATE }}. | |
- name: Upload generated index to release | |
uses: actions/upload-release-asset@v1 | |
env: { GITHUB_TOKEN: "${{ secrets.RELEASE_TOKEN }}" } | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_name: llvm-index-${{ env.RELEASE_DATE }}.zip | |
asset_path: llvm-index.zip | |
asset_content_type: application/zip |