autoload -Uz is-at-least log_debug log_warning

if (( ${+commands[ccache]} )) {
  log_debug "Found ccache at ${commands[ccache]}"

  local ccache_version=$(ccache --version | head -1 | cut -d ' ' -f 3)
  if ! is-at-least 4.12 ${ccache_version}; then
    ccache --set-config=run_second_cpp=true
  fi

  ccache --set-config=direct_mode=true
  ccache --set-config=inode_cache=true
  ccache --set-config=compiler_check=content
  ccache --set-config=file_clone=true

  local -a sloppiness=(
    include_file_mtime
    include_file_ctime
    file_stat_matches
    system_headers
  )

  if [[ ${host_os} == macos ]] {
    sloppiness+=(
      modules
      clang_index_store
    )

    ccache --set-config=sloppiness=${(j:,:)sloppiness}
  }

  ccache --set-config=cache_dir="${GITHUB_WORKSPACE:-${HOME}}/.ccache"
  ccache --set-config=max_size="${CCACHE_SIZE:-1G}"
  ccache -z > /dev/null
} else {
  log_warning "Ccache not available"
}
