build_llvm_libraries.yml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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@v6.0.1
  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. working-directory: build-scripts
  62. # Bump the prefix number to evict all previous caches and
  63. # enforce a clean build, in the unlikely case that some
  64. # weird build error occur and llvm/build becomes a potential
  65. # suspect.
  66. - name: form the cache key of libraries
  67. id: create_lib_cache_key
  68. shell: bash
  69. run: |
  70. echo "key=0-llvm-libraries-${{ inputs.os }}-${{ inputs.arch }}-${{ steps.get_last_commit.outputs.last_commit }}${{ inputs.cache_key_suffix }}" >> $GITHUB_OUTPUT
  71. - name: Cache LLVM libraries
  72. id: retrieve_llvm_libs
  73. uses: actions/cache@v5
  74. with:
  75. path: |
  76. ./core/deps/llvm/build/bin
  77. ./core/deps/llvm/build/include
  78. ./core/deps/llvm/build/lib
  79. ./core/deps/llvm/build/libexec
  80. ./core/deps/llvm/build/share
  81. key: ${{ steps.create_lib_cache_key.outputs.key}}
  82. - uses: actions/cache@v5
  83. with:
  84. path: ~/.cache/ccache
  85. key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }}
  86. restore-keys: |
  87. 0-ccache-${{ inputs.os }}
  88. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'ubuntu-22.04'
  89. # Don't install dependencies if the cache is hit or running in docker container
  90. - run: sudo apt install -y ccache ninja-build
  91. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && startsWith(inputs.os, 'ubuntu') && inputs.container_image == ''
  92. - uses: actions/cache@v5
  93. with:
  94. path: ~/Library/Caches/ccache
  95. key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }}
  96. restore-keys: |
  97. 0-ccache-${{ inputs.os }}
  98. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && startsWith(inputs.os, 'macos')
  99. - run: brew install ccache ninja
  100. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && startsWith(inputs.os, 'macos')
  101. - uses: actions/cache@v5
  102. with:
  103. path: ~/.cache/ccache
  104. key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }}
  105. restore-keys: |
  106. 0-ccache-${{ inputs.os }}
  107. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'windows-2022'
  108. # Install tools on Windows
  109. - run: choco install -y ccache ninja
  110. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'windows-2022'
  111. - name: Build LLVM libraries
  112. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true'
  113. shell: bash
  114. run: /usr/bin/env python3 ./build_llvm.py ${{ inputs.extra_build_llvm_options }} --arch ${{ inputs.arch }}
  115. working-directory: build-scripts