build_llvm_libraries.yml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. permissions:
  29. contents: read
  30. jobs:
  31. build_llvm_libraries:
  32. runs-on: ${{ inputs.os }}
  33. # Using given container image if it is specified.
  34. # Otherwise, it will be ignored by the runner.
  35. container:
  36. image: ${{ inputs.container_image }}
  37. outputs:
  38. key: ${{ steps.create_lib_cache_key.outputs.key}}
  39. permissions:
  40. contents: read
  41. actions: write # for uploading cached artifact
  42. steps:
  43. - name: checkout
  44. uses: actions/checkout@v4
  45. - name: install dependencies for non macos-14
  46. if: inputs.os != 'macos-14'
  47. shell: bash
  48. run: /usr/bin/env python3 -m pip install -r requirements.txt
  49. working-directory: build-scripts
  50. - name: install dependencies for macos-14
  51. if: inputs.os == 'macos-14'
  52. run: /usr/bin/env python3 -m pip install -r requirements.txt --break-system-packages
  53. working-directory: build-scripts
  54. - name: Retrieve the last commit ID
  55. id: get_last_commit
  56. env:
  57. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  58. shell: bash
  59. run: |
  60. echo "last_commit=$(GH_TOKEN=${{ secrets.GITHUB_TOKEN }} /usr/bin/env python3 ./build_llvm.py ${{ inputs.extra_build_llvm_options }} --llvm-ver)" >> $GITHUB_OUTPUT
  61. # Bump the prefix number to evict all previous caches and
  62. # enforce a clean build, in the unlikely case that some
  63. # weird build error occur and llvm/build becomes a potential
  64. # suspect.
  65. - name: form the cache key of libraries
  66. id: create_lib_cache_key
  67. shell: bash
  68. run: |
  69. echo "key=0-llvm-libraries-${{ inputs.os }}-${{ inputs.arch }}-${{ steps.get_last_commit.outputs.last_commit }}${{ inputs.cache_key_suffix }}" >> $GITHUB_OUTPUT
  70. - name: Cache LLVM libraries
  71. id: retrieve_llvm_libs
  72. uses: actions/cache@v4
  73. with:
  74. path: |
  75. ./core/deps/llvm/build/bin
  76. ./core/deps/llvm/build/include
  77. ./core/deps/llvm/build/lib
  78. ./core/deps/llvm/build/libexec
  79. ./core/deps/llvm/build/share
  80. key: ${{ steps.create_lib_cache_key.outputs.key}}
  81. - uses: actions/cache@v4
  82. with:
  83. path: ~/.ccache
  84. key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }}
  85. restore-keys: |
  86. 0-ccache-${{ inputs.os }}
  87. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'ubuntu-20.04'
  88. - uses: actions/cache@v4
  89. with:
  90. path: ~/.cache/ccache
  91. key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }}
  92. restore-keys: |
  93. 0-ccache-${{ inputs.os }}
  94. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'ubuntu-22.04'
  95. # Don't install dependencies if the cache is hit or running in docker container
  96. - run: sudo apt install -y ccache ninja-build
  97. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && startsWith(inputs.os, 'ubuntu') && inputs.container_image == ''
  98. - uses: actions/cache@v4
  99. with:
  100. path: ~/Library/Caches/ccache
  101. key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }}
  102. restore-keys: |
  103. 0-ccache-${{ inputs.os }}
  104. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && startsWith(inputs.os, 'macos')
  105. - run: brew install ccache ninja
  106. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && startsWith(inputs.os, 'macos')
  107. - uses: actions/cache@v4
  108. with:
  109. path: ~/.cache/ccache
  110. key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }}
  111. restore-keys: |
  112. 0-ccache-${{ inputs.os }}
  113. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'windows-latest'
  114. # Install tools on Windows
  115. - run: choco install -y ccache ninja
  116. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'windows-latest'
  117. - name: Build LLVM libraries
  118. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true'
  119. shell: bash
  120. run: /usr/bin/env python3 ./build_llvm.py ${{ inputs.extra_build_llvm_options }} --arch ${{ inputs.arch }}
  121. working-directory: build-scripts