|
| 1 | +name: Fetch Clang |
| 2 | +description: Puts clang's path into the output |
| 3 | + |
| 4 | +inputs: |
| 5 | + version: |
| 6 | + description: Version of Clang to fetch |
| 7 | + required: true |
| 8 | + base-directory: |
| 9 | + description: Directory in which to install clang |
| 10 | +outputs: |
| 11 | + clang: |
| 12 | + description: Path of clang executable |
| 13 | + value: ${{ steps.script.outputs.clang }} |
| 14 | + clangxx: |
| 15 | + description: Path of clang++ executable |
| 16 | + value: ${{ steps.script.outputs.clangxx }} |
| 17 | + |
| 18 | +runs: |
| 19 | + using: composite |
| 20 | + steps: |
| 21 | + - id: script |
| 22 | + shell: pwsh |
| 23 | + working-directory: ${{ inputs.base-directory }} |
| 24 | + run: | |
| 25 | + $version = ${{ inputs.version }} |
| 26 | + function Invoke-NativeCommand { |
| 27 | + $command = $args[0] |
| 28 | + $arguments = $args[1..($args.Length)] |
| 29 | + & $command @arguments |
| 30 | + if ($LastExitCode -ne 0) { |
| 31 | + Write-Error "Exit code $LastExitCode while running $command $arguments" |
| 32 | + } |
| 33 | + } |
| 34 | + if ($IsMacOs) { |
| 35 | + } elseif ($IsLinux) { |
| 36 | + $tmp = New-TemporaryFile |
| 37 | + Invoke-WebRequest -Uri 'https://apt.llvm.org/llvm-snapshot.gpg.key' -OutFile $tmp |
| 38 | + Invoke-NativeCommand sudo apt-key add $tmp |
| 39 | + $tmp | Remove-Item |
| 40 | + Invoke-NativeCommand sudo add-apt-repository -y "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-${version} main" |
| 41 | + Invoke-NativeCommand sudo apt-get update |
| 42 | + $pkgs = @("clang-${version}", "libc++-${version}-dev", "libc++abi-${version}-dev") |
| 43 | + if (${version} -eq 12) { |
| 44 | + $pkgs += "libunwind-${version}-dev" |
| 45 | + } |
| 46 | + if (${version} -ge 14) { |
| 47 | + $pkgs += "libclang-rt-${version}-dev" |
| 48 | + } |
| 49 | + Invoke-NativeCommand sudo apt-get install -y $pkgs |
| 50 | + Add-Content "${env:GITHUB_OUTPUT}" "clang=$((Get-Command clang-${version}).Source)" |
| 51 | + Add-Content "${env:GITHUB_OUTPUT}" "clangxx=$((Get-Command clang++-${version}).Source)" |
| 52 | + } elseif ($IsWindows) { |
| 53 | + $release = Invoke-WebRequest -Uri 'https://api.github.com/repos/llvm/llvm-project/releases' -UseBasicParsing | |
| 54 | + ConvertFrom-Json | |
| 55 | + Select-Object -Property @{Name = 'version'; Expression = {[System.Management.Automation.SemanticVersion]$_.tag_name.Substring('llvmorg-'.Length)}},assets | |
| 56 | + Where-Object {$_.version.Major -eq $version -and ($_.assets | Where-Object {$_.name -like "LLVM-*-win64.exe"})} | |
| 57 | + Sort-Object | |
| 58 | + Select-Object -First 1 |
| 59 | + $uri = ($release.assets | Where-Object {$_.name -eq "LLVM-$($release.version)-win64.exe"}).browser_download_url |
| 60 | + $tmp = New-TemporaryFile | Rename-Item -NewName { $_ -replace 'tmp$', 'exe' } –PassThru |
| 61 | + Invoke-WebRequest -Uri $uri -OutFile $tmp |
| 62 | + Start-Process "$tmp" -Wait -NoNewWindow -ArgumentList /S,"/D=$(Join-Path (Get-Location) LLVM)" |
| 63 | + $tmp | Remove-Item |
| 64 | + Add-Content "${env:GITHUB_OUTPUT}" "clang=$(Join-Path (Get-Location) LLVM bin clang)" |
| 65 | + Add-Content "${env:GITHUB_OUTPUT}" "clangxx=$(Join-Path (Get-Location) LLVM bin clang++)" |
| 66 | + } |
0 commit comments