summaryrefslogtreecommitdiff
path: root/.github/actions/setup_toolchain/download/action.yml
blob: 77d3bcf194882bf86204a673012b2c4ff094f1df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Download Toolchain

inputs:
  toolchain:
    description: 'Toolchain name'
    required: true
  toolchain_url:
    description: 'Toolchain URL'
    required: true

runs:
  using: "composite"
  steps:
    - name: Cache Toolchain
      if: ${{ !startsWith(inputs.toolchain_url, 'https://github.com') }}
      uses: actions/cache@v5
      id: cache-toolchain-download
      with:
        path: ~/cache/${{ inputs.toolchain }}
        key: ${{ runner.os }}-${{ inputs.toolchain }}-${{ inputs.toolchain_url }}

    - name: Install Toolchain
      if: steps.cache-toolchain-download.outputs.cache-hit != 'true'
      env:
        TOOLCHAIN: ${{ inputs.toolchain }}
        TOOLCHAIN_URL: ${{ inputs.toolchain_url }}
      run: |
        mkdir -p ~/cache/${TOOLCHAIN}
        FILE_EXT="${TOOLCHAIN_URL##*.}"

        if [[ ${TOOLCHAIN} == rx-gcc ]]; then
          wget --progress=dot:giga ${TOOLCHAIN_URL} -O toolchain.run
          chmod +x toolchain.run
          ./toolchain.run -p ~/cache/${TOOLCHAIN}/gnurx -y
        elif [[ ${TOOLCHAIN} == ft9xx-gcc ]]; then
          wget --progress=dot:giga ${TOOLCHAIN_URL} -O ~/cache/${TOOLCHAIN}/ft9xxtoolchain.deb
        elif [[ ${TOOLCHAIN} == arm-iar ]]; then
          wget --progress=dot:giga https://netstorage.iar.com/FileStore/STANDARD/001/003/926/iar-lmsc-tools_1.8_amd64.deb -O ~/cache/${TOOLCHAIN}/iar-lmsc-tools.deb
          wget --progress=dot:giga ${TOOLCHAIN_URL} -O ~/cache/${TOOLCHAIN}/cxarm.deb
        elif [[ ${FILE_EXT} == zip ]]; then
          curl -L "$TOOLCHAIN_URL" -o toolchain.zip
          unzip -q toolchain.zip -d ~/cache/${TOOLCHAIN}
          ~/cache/${TOOLCHAIN}/xpack-arm-none-eabi-gcc-14.2.1-1.1/bin/arm-none-eabi-gcc.exe --version
        elif [[ ${FILE_EXT} == gz ]]; then
          wget --progress=dot:giga ${TOOLCHAIN_URL} -O toolchain.tar.gz
          tar -C ~/cache/${TOOLCHAIN} -xaf toolchain.tar.gz
        else
          echo "Unsupported toolchain file extension: ${FILE_EXT}"
          exit 1
        fi
      shell: bash

    - name: Setup Toolchain
      env:
        TOOLCHAIN: ${{ inputs.toolchain }}
      run: |
        if [[ ${TOOLCHAIN} == arm-iar ]]; then
          sudo dpkg -i ~/cache/${TOOLCHAIN}/iar-lmsc-tools.deb
          sudo apt install -y ~/cache/${TOOLCHAIN}/cxarm.deb
          TOOLCHAIN_PATH="/opt/iar/cxarm/arm/bin"
        elif [[ ${TOOLCHAIN} == ft9xx-gcc ]]; then
          sudo apt install -y ~/cache/${TOOLCHAIN}/ft9xxtoolchain.deb
          TOOLCHAIN_PATH="/opt/ft32/bin"
        else
          # Find the single toolchain bin directory
          TOOLCHAIN_BIN_DIRS=(~/cache/${TOOLCHAIN}/*/bin)
          if [[ ${#TOOLCHAIN_BIN_DIRS[@]} -ne 1 ]]; then
            echo "Error: Expected exactly one toolchain bin directory, found ${#TOOLCHAIN_BIN_DIRS[@]}"
            exit 1
          fi
          TOOLCHAIN_PATH="${TOOLCHAIN_BIN_DIRS[0]}"
        fi
        # Convert to native path for Windows compatibility
        if [[ "$RUNNER_OS" == "Windows" ]]; then
          TOOLCHAIN_PATH=$(cygpath -w "$TOOLCHAIN_PATH")
        fi
        echo "$TOOLCHAIN_PATH" >> $GITHUB_PATH
      shell: bash