You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在不下载GHC的情况下查询对应快照的GHC版本

How to get a Stack snapshot's associated GHC version without downloading GHC

I totally get where you're coming from—using stack query compiler wanted in CI is a non-starter because it triggers a full GHC download, which completely defeats the purpose of using the GHC version as a cache key. Here are a few reliable, lightweight ways to get the GHC version tied to your target snapshot without pulling down the compiler itself:

Method 1: Use stack resolver info (simplest approach)

This command queries Stack's resolver metadata directly, no GHC download required. It returns basic details about the resolver, including the exact GHC version.

For a specific hardcoded resolver:

stack resolver info lts-20.13

For the resolver defined in your project's stack.yaml:

Automatically pull the resolver from your config and extract the GHC version:

RESOLVER=$(stack resolver show)
stack resolver info "$RESOLVER" | grep "GHC version:" | awk '{print $3}'

Method 2: Parse snapshot metadata with JSON

If you prefer structured data (ideal for scripting in CI), use stack ls snapshots with JSON output and a tool like jq to filter the result:

# For a hardcoded resolver
stack ls snapshots --json | jq '.[] | select(.resolver == "lts-20.13") | .ghc_version'

# For your project's resolver
RESOLVER=$(stack resolver show)
stack ls snapshots --json | jq --arg res "$RESOLVER" '.[] | select(.resolver == $res) | .ghc_version'

This pulls the full list of available snapshots (a tiny metadata payload) and extracts the GHC version for your target resolver—no heavy downloads involved.

Method 3: Optimize CI with resolver index caching

In CI environments, cache the Stack resolver index directory (~/.stack/index) to speed up these metadata queries even more. The index is small and rarely changes, so caching it avoids re-fetching resolver details on every build, making your cache key lookup nearly instant.

Why these work (and stack query compiler wanted doesn't)

The stack query compiler wanted command is designed to resolve and prepare the compiler for active use, which includes downloading it if it's missing from your system. The methods above only interact with Stack's resolver metadata—lightweight files that map snapshots to GHC versions, package sets, and other metadata—so they never trigger a GHC download.

内容的提问来源于stack exchange,提问作者John Ky

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:46:20