name: "Setup LLGO Dependencies"
description: "Install all required dependencies for LLGO"
inputs:
  llvm-version:
    description: "LLVM version to install"
    required: true
    default: "19"

runs:
  using: "composite"
  steps:
    - name: Install macOS dependencies
      if: runner.os == 'macOS'
      shell: bash
      run: |
        brew update
        brew install llvm@${{inputs.llvm-version}} lld@${{inputs.llvm-version}} bdw-gc openssl libffi libuv
        brew link --overwrite llvm@${{inputs.llvm-version}} lld@${{inputs.llvm-version}} libffi
        echo "$(brew --prefix llvm@${{inputs.llvm-version}})/bin" >> $GITHUB_PATH

        # Install optional deps for demos.
        #
        # NOTE: Keep this list updated as new deps are introduced.
        opt_deps=(
          cjson       # for github.com/goplus/lib/c/cjson
          sqlite      # for github.com/goplus/lib/c/sqlite
          python@3.12 # for github.com/goplus/lib/py
        )
        brew install "${opt_deps[@]}"
    - name: Install Ubuntu dependencies
      if: runner.os == 'Linux'
      shell: bash
      run: |
        echo "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-${{inputs.llvm-version}} main" | sudo tee /etc/apt/sources.list.d/llvm.list
        wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
        sudo apt-get update
        sudo apt-get install -y llvm-${{inputs.llvm-version}}-dev clang-${{inputs.llvm-version}} libclang-${{inputs.llvm-version}}-dev lld-${{inputs.llvm-version}} pkg-config libgc-dev libssl-dev zlib1g-dev libffi-dev libcjson-dev libunwind-dev libuv1-dev
        echo "PATH=/usr/lib/llvm-${{inputs.llvm-version}}/bin:$PATH" >> $GITHUB_ENV

        # Install optional deps for demos.
        #
        # NOTE: Keep this list updated as new deps are introduced.
        opt_deps=(
          libcjson-dev   # for github.com/goplus/lib/c/cjson
          libsqlite3-dev # for github.com/goplus/lib/c/sqlite
          python3.12-dev # for github.com/goplus/lib/py
        )
        sudo apt-get install -y "${opt_deps[@]}"
