build_llvm_libraries.yml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  2. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  3. name: Reusable workflow-build_llvm_libraries
  4. on:
  5. workflow_call:
  6. inputs:
  7. os:
  8. required: true
  9. type: string
  10. arch:
  11. required: true
  12. type: string
  13. container_image:
  14. required: false
  15. type: string
  16. extra_build_llvm_options:
  17. required: false
  18. type: string
  19. default: ""
  20. cache_key_suffix:
  21. required: false
  22. type: string
  23. default: ""
  24. outputs:
  25. cache_key:
  26. description: "A cached key of LLVM libraries"
  27. value: ${{ jobs.build_llvm_libraries.outputs.key}}
  28. jobs:
  29. build_llvm_libraries:
  30. runs-on: ${{ inputs.os }}
  31. # Using given container image if it is specified.
  32. # Otherwise, it will be ignored by the runner.
  33. container:
  34. image: ${{ inputs.container_image }}
  35. outputs:
  36. key: ${{ steps.create_lib_cache_key.outputs.key}}
  37. steps:
  38. - name: checkout
  39. uses: actions/checkout@v4
  40. - name: install dependencies for non macos-14
  41. if: inputs.os != 'macos-14'
  42. shell: bash
  43. run: /usr/bin/env python3 -m pip install -r requirements.txt
  44. working-directory: build-scripts
  45. - name: install dependencies for macos-14
  46. if: inputs.os == 'macos-14'
  47. run: /usr/bin/env python3 -m pip install -r requirements.txt --break-system-packages
  48. working-directory: build-scripts
  49. - name: Retrieve the last commit ID
  50. id: get_last_commit
  51. env:
  52. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  53. shell: bash
  54. run: |
  55. echo "last_commit=$(GH_TOKEN=${{ secrets.GITHUB_TOKEN }} /usr/bin/env python3 ./build_llvm.py ${{ inputs.extra_build_llvm_options }} --llvm-ver)" >> $GITHUB_OUTPUT
  56. # Bump the prefix number to evict all previous caches and
  57. # enforce a clean build, in the unlikely case that some
  58. # weird build error occur and llvm/build becomes a potential
  59. # suspect.
  60. - name: form the cache key of libraries
  61. id: create_lib_cache_key
  62. shell: bash
  63. run: |
  64. echo "key=0-llvm-libraries-${{ inputs.os }}-${{ inputs.arch }}-${{ steps.get_last_commit.outputs.last_commit }}${{ inputs.cache_key_suffix }}" >> $GITHUB_OUTPUT
  65. - name: Cache LLVM libraries
  66. id: retrieve_llvm_libs
  67. uses: actions/cache@v4
  68. with:
  69. path: |
  70. ./core/deps/llvm/build/bin
  71. ./core/deps/llvm/build/include
  72. ./core/deps/llvm/build/lib
  73. ./core/deps/llvm/build/libexec
  74. ./core/deps/llvm/build/share
  75. key: ${{ steps.create_lib_cache_key.outputs.key}}
  76. - uses: actions/cache@v4
  77. with:
  78. path: ~/.ccache
  79. key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }}
  80. restore-keys: |
  81. 0-ccache-${{ inputs.os }}
  82. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'ubuntu-20.04'
  83. - uses: actions/cache@v4
  84. with:
  85. path: ~/.cache/ccache
  86. key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }}
  87. restore-keys: |
  88. 0-ccache-${{ inputs.os }}
  89. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'ubuntu-22.04'
  90. # Don't install dependencies if the cache is hit or running in docker container
  91. - run: sudo apt install -y ccache ninja-build
  92. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && startsWith(inputs.os, 'ubuntu') && inputs.container_image == ''
  93. - uses: actions/cache@v4
  94. with:
  95. path: ~/Library/Caches/ccache
  96. key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }}
  97. restore-keys: |
  98. 0-ccache-${{ inputs.os }}
  99. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && startsWith(inputs.os, 'macos')
  100. - run: brew install ccache ninja
  101. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && startsWith(inputs.os, 'macos')
  102. - uses: actions/cache@v4
  103. with:
  104. path: ~/.cache/ccache
  105. key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }}
  106. restore-keys: |
  107. 0-ccache-${{ inputs.os }}
  108. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'windows-latest'
  109. # Install tools on Windows
  110. - run: choco install -y ccache ninja
  111. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'windows-latest'
  112. - name: Build LLVM libraries
  113. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true'
  114. shell: bash
  115. run: /usr/bin/env python3 ./build_llvm.py ${{ inputs.extra_build_llvm_options }} --arch ${{ inputs.arch }}
  116. working-directory: build-scripts