name: build-dependencies
description: Installs build dependencies for Serai

runs:
  using: "composite"
  steps:
    - name: Remove unused packages
      shell: bash
      run: |
        sudo apt remove -y "*msbuild*" "*powershell*" "*nuget*" "*bazel*" "*ansible*" "*terraform*" "*heroku*" "*aws*" azure-cli
        sudo apt remove -y "*nodejs*" "*npm*" "*yarn*" "*java*" "*kotlin*" "*golang*" "*swift*" "*julia*" "*fortran*" "*android*"
        sudo apt remove -y "*apache2*" "*nginx*" "*firefox*" "*chromium*" "*chrome*" "*edge*"
        sudo apt remove -y "*qemu*" "*sql*" "*texinfo*" "*imagemagick*"
        sudo apt autoremove -y
        sudo apt clean
        docker system prune -a --volumes
      if: runner.os == 'Linux'

    - name: Remove unused packages
      shell: bash
      run: |
        (gem uninstall -aIx) || (exit 0)
        brew uninstall --force "*msbuild*" "*powershell*" "*nuget*" "*bazel*" "*ansible*" "*terraform*" "*heroku*" "*aws*" azure-cli
        brew uninstall --force "*nodejs*" "*npm*" "*yarn*" "*java*" "*kotlin*" "*golang*" "*swift*" "*julia*" "*fortran*" "*android*"
        brew uninstall --force "*apache2*" "*nginx*" "*firefox*" "*chromium*" "*chrome*" "*edge*"
        brew uninstall --force "*qemu*" "*sql*" "*texinfo*" "*imagemagick*"
        brew cleanup
      if: runner.os == 'macOS'

    - name: Install dependencies
      shell: bash
      run: |
        if [ "$RUNNER_OS" == "Linux" ]; then
          sudo apt install -y ca-certificates protobuf-compiler
        elif [ "$RUNNER_OS" == "Windows" ]; then
          choco install protoc
        elif [ "$RUNNER_OS" == "macOS" ]; then
          brew install protobuf
        fi

    - name: Install solc
      shell: bash
      run: |
        cargo install svm-rs
        svm install 0.8.16
        svm use 0.8.16

    # - name: Cache Rust
    #   uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43