build_llvm_libraries.yml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. run: /usr/bin/env python3 -m pip install -r requirements.txt
  43. working-directory: build-scripts
  44. - name: install dependencies for macos-14
  45. if: inputs.os == 'macos-14'
  46. run: /usr/bin/env python3 -m pip install -r requirements.txt --break-system-packages
  47. working-directory: build-scripts
  48. - name: retrieve the last commit ID
  49. id: get_last_commit
  50. run: echo "last_commit=$(GH_TOKEN=${{ secrets.GITHUB_TOKEN }} /usr/bin/env python3 ./build_llvm.py ${{ inputs.extra_build_llvm_options }} --llvm-ver)" >> $GITHUB_OUTPUT
  51. working-directory: build-scripts
  52. # Bump the prefix number to evict all previous caches and
  53. # enforce a clean build, in the unlikely case that some
  54. # weird build error occur and llvm/build becomes a potential
  55. # suspect.
  56. - name: form the cache key of libraries
  57. id: create_lib_cache_key
  58. run: echo "key=0-llvm-libraries-${{ inputs.os }}-${{ inputs.arch }}-${{ steps.get_last_commit.outputs.last_commit }}${{ inputs.cache_key_suffix }}" >> $GITHUB_OUTPUT
  59. - name: Cache LLVM libraries
  60. id: retrieve_llvm_libs
  61. uses: actions/cache@v4
  62. with:
  63. path: |
  64. ./core/deps/llvm/build/bin
  65. ./core/deps/llvm/build/include
  66. ./core/deps/llvm/build/lib
  67. ./core/deps/llvm/build/libexec
  68. ./core/deps/llvm/build/share
  69. key: ${{ steps.create_lib_cache_key.outputs.key}}
  70. - uses: actions/cache@v4
  71. with:
  72. path: ~/.ccache
  73. key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }}
  74. restore-keys: |
  75. 0-ccache-${{ inputs.os }}
  76. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'ubuntu-20.04'
  77. - uses: actions/cache@v4
  78. with:
  79. path: ~/.cache/ccache
  80. key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }}
  81. restore-keys: |
  82. 0-ccache-${{ inputs.os }}
  83. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'ubuntu-22.04'
  84. # Don't install dependencies if the cache is hit or running in docker container
  85. - run: sudo apt install -y ccache ninja-build
  86. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && startsWith(inputs.os, 'ubuntu') && inputs.container_image == ''
  87. - uses: actions/cache@v4
  88. with:
  89. path: ~/Library/Caches/ccache
  90. key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }}
  91. restore-keys: |
  92. 0-ccache-${{ inputs.os }}
  93. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && startsWith(inputs.os, 'macos')
  94. - run: brew install ccache ninja
  95. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && startsWith(inputs.os, 'macos')
  96. - name: Build LLVM libraries
  97. if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true'
  98. run: /usr/bin/env python3 ./build_llvm.py ${{ inputs.extra_build_llvm_options }} --arch ${{ inputs.arch }}
  99. working-directory: build-scripts