| 
 | 1 | +name: Reusable Sanitizer  | 
 | 2 | + | 
 | 3 | +on:  | 
 | 4 | +  workflow_call:  | 
 | 5 | +    inputs:  | 
 | 6 | +      sanitizer:  | 
 | 7 | +        required: true  | 
 | 8 | +        type: string  | 
 | 9 | +      config_hash:  | 
 | 10 | +        required: true  | 
 | 11 | +        type: string  | 
 | 12 | +      free-threading:  | 
 | 13 | +        description: Whether to use free-threaded mode  | 
 | 14 | +        required: false  | 
 | 15 | +        type: boolean  | 
 | 16 | +        default: false  | 
 | 17 | + | 
 | 18 | +env:  | 
 | 19 | +  FORCE_COLOR: 1  | 
 | 20 | + | 
 | 21 | +jobs:  | 
 | 22 | +  build-san-reusable:  | 
 | 23 | +    name: >-  | 
 | 24 | +      ${{ inputs.sanitizer }}${{  | 
 | 25 | +        inputs.free-threading  | 
 | 26 | +        && ' (free-threading)'  | 
 | 27 | +        || ''  | 
 | 28 | +      }}  | 
 | 29 | +    runs-on: ubuntu-24.04  | 
 | 30 | +    timeout-minutes: 60  | 
 | 31 | +    steps:  | 
 | 32 | +    - uses: actions/checkout@v4  | 
 | 33 | +      with:  | 
 | 34 | +        persist-credentials: false  | 
 | 35 | +    - name: Runner image version  | 
 | 36 | +      run: echo "IMAGE_OS_VERSION=${ImageOS}-${ImageVersion}" >> "$GITHUB_ENV"  | 
 | 37 | +    - name: Restore config.cache  | 
 | 38 | +      uses: actions/cache@v4  | 
 | 39 | +      with:  | 
 | 40 | +        path: config.cache  | 
 | 41 | +        key: ${{ github.job }}-${{ env.IMAGE_OS_VERSION }}-${{ inputs.sanitizer }}-${{ inputs.config_hash }}  | 
 | 42 | +    - name: Install dependencies  | 
 | 43 | +      run: |  | 
 | 44 | +        sudo ./.github/workflows/posix-deps-apt.sh  | 
 | 45 | +        # Install clang  | 
 | 46 | +        wget https://apt.llvm.org/llvm.sh  | 
 | 47 | +        chmod +x llvm.sh  | 
 | 48 | +
  | 
 | 49 | +        if [ "${SANITIZER}" = "TSan" ]; then  | 
 | 50 | +          sudo ./llvm.sh 17  # gh-121946: llvm-18 package is temporarily broken  | 
 | 51 | +          sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-17 100  | 
 | 52 | +          sudo update-alternatives --set clang /usr/bin/clang-17  | 
 | 53 | +          sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-17 100  | 
 | 54 | +          sudo update-alternatives --set clang++ /usr/bin/clang++-17  | 
 | 55 | +          # Reduce ASLR to avoid TSan crashing  | 
 | 56 | +          sudo sysctl -w vm.mmap_rnd_bits=28  | 
 | 57 | +        else  | 
 | 58 | +          sudo ./llvm.sh 20  | 
 | 59 | +        fi  | 
 | 60 | +
  | 
 | 61 | +    - name: Sanitizer option setup  | 
 | 62 | +      run: |  | 
 | 63 | +        if [ "${SANITIZER}" = "TSan" ]; then  | 
 | 64 | +          echo "TSAN_OPTIONS=${SAN_LOG_OPTION} suppressions=${GITHUB_WORKSPACE}/Tools/tsan/suppressions${{  | 
 | 65 | +              fromJSON(inputs.free-threading)  | 
 | 66 | +              && '_free_threading'  | 
 | 67 | +              || ''  | 
 | 68 | +            }}.txt handle_segv=0" >> "$GITHUB_ENV"  | 
 | 69 | +        else  | 
 | 70 | +          echo "UBSAN_OPTIONS=${SAN_LOG_OPTION}" >> "$GITHUB_ENV"  | 
 | 71 | +        fi  | 
 | 72 | +        echo "CC=clang" >> "$GITHUB_ENV"  | 
 | 73 | +        echo "CXX=clang++" >> "$GITHUB_ENV"  | 
 | 74 | +      env:  | 
 | 75 | +        SANITIZER: ${{ inputs.sanitizer }}  | 
 | 76 | +        SAN_LOG_OPTION: log_path=${{ github.workspace }}/san_log  | 
 | 77 | +    - name: Add ccache to PATH  | 
 | 78 | +      run: |  | 
 | 79 | +        echo "PATH=/usr/lib/ccache:$PATH" >> "$GITHUB_ENV"  | 
 | 80 | +    - name: Configure ccache action  | 
 | 81 | +      uses:  hendrikmuhs/[email protected]  | 
 | 82 | +      with:  | 
 | 83 | +        save: ${{ github.event_name == 'push' }}  | 
 | 84 | +        max-size: "200M"  | 
 | 85 | +    - name: Configure CPython  | 
 | 86 | +      run: >-  | 
 | 87 | +        ./configure  | 
 | 88 | +        --config-cache  | 
 | 89 | +        ${{  | 
 | 90 | +          inputs.sanitizer == 'TSan'  | 
 | 91 | +          && '--with-thread-sanitizer'  | 
 | 92 | +          || '--with-undefined-behavior-sanitizer'  | 
 | 93 | +        }}  | 
 | 94 | +        --with-pydebug  | 
 | 95 | +        ${{ fromJSON(inputs.free-threading) && '--disable-gil' || '' }}  | 
 | 96 | +    - name: Build CPython  | 
 | 97 | +      run: make -j4  | 
 | 98 | +    - name: Display build info  | 
 | 99 | +      run: make pythoninfo  | 
 | 100 | +    - name: Tests  | 
 | 101 | +      run: >-  | 
 | 102 | +        ./python -m test  | 
 | 103 | +        ${{ inputs.sanitizer == 'TSan' && '--tsan' || '' }}  | 
 | 104 | +        -j4  | 
 | 105 | +    - name: Display logs  | 
 | 106 | +      if: always()  | 
 | 107 | +      run: find "${GITHUB_WORKSPACE}" -name 'san_log.*' | xargs head -n 1000  | 
 | 108 | +    - name: Archive logs  | 
 | 109 | +      if: always()  | 
 | 110 | +      uses: actions/upload-artifact@v4  | 
 | 111 | +      with:  | 
 | 112 | +        name: >-  | 
 | 113 | +          ${{ inputs.sanitizer }}-logs-${{  | 
 | 114 | +            fromJSON(inputs.free-threading)  | 
 | 115 | +            && 'free-threading'  | 
 | 116 | +            || 'default'  | 
 | 117 | +          }}  | 
 | 118 | +        path: san_log.*  | 
 | 119 | +        if-no-files-found: ignore  | 
0 commit comments