version: "3"
internal: true

includes:
  vars: ./vars.yml

vars:
  EXE_EXT:
    sh: |
      if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "win32" ]]; then
        echo ".exe"
      else
        echo ""
      fi

  LIB_EXT:
    sh: |
      if [[ "$OSTYPE" == "darwin"* ]]; then
        echo "dylib"
      elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "win32" ]]; then
        echo "dll"
      else
        echo "so"
      fi

  LIB_PREFIX:
    sh: |
      if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "win32" ]]; then
        echo ""
      else
        echo "lib"
      fi

  RUST_TARGET:
    sh: |
      ARCH=$(uname -m)
      OS_TYPE="$OSTYPE"
      case "$ARCH" in
        x86_64|x64)
          ARCH_STR="x86_64"
          ;;
        aarch64|arm64)
          ARCH_STR="aarch64"
          ;;
        armv7l|armv7)
          ARCH_STR="armv7"
          ;;
        *)
          ARCH_STR="$ARCH"
          ;;
      esac

      if [[ "$OS_TYPE" == "darwin"* ]]; then
        echo "${ARCH_STR}-apple-darwin"
      elif [[ "$OS_TYPE" == "linux-gnu"* ]] || [[ "$OS_TYPE" == "linux"* ]]; then
        echo "${ARCH_STR}-unknown-linux-gnu"
      elif [[ "$OS_TYPE" == "msys" ]] || [[ "$OS_TYPE" == "cygwin" ]] || [[ "$OS_TYPE" == "win32" ]]; then
        echo "${ARCH_STR}-pc-windows-msvc"
      else
        echo "${ARCH_STR}-unknown-unknown"
      fi

  IS_WINDOWS: "{{.IS_WINDOWS}}"
  IS_MACOS: "{{.IS_MACOS}}"
  IS_LINUX: "{{.IS_LINUX}}"

  RUBY_FULL_PATH:
    sh: |
      if command -v ruby >/dev/null 2>&1; then
        command -v ruby
      elif [[ "$OSTYPE" == "darwin"* ]] && [[ -f "/opt/homebrew/opt/ruby/bin/ruby" ]]; then
        echo "/opt/homebrew/opt/ruby/bin/ruby"
      else
        echo "ruby"
      fi

  CARGO_BIN:
    sh: command -v cargo 2>/dev/null || echo "cargo"

  RUSTC_BIN:
    sh: command -v rustc 2>/dev/null || echo "rustc"

  SHELL_EXT:
    sh: |
      if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "win32" ]]; then
        echo ".ps1"
      else
        echo ".sh"
      fi
