Skip to content

Commit c9363d2

Browse files
committed
Use local_snapshot and snapshot_json per GHC version
1 parent 0b0c3dd commit c9363d2

5 files changed

+25
-18
lines changed

extensions/haskell_toolchains.bzl

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ load(
88
"ghc_bindists_toolchain_declarations",
99
"haskell_register_ghc_bindists",
1010
)
11+
load("@rules_haskell_ghc_version//:ghc_version.bzl", "GHC_VERSION")
1112

1213
_bindists_tag = tag_class(
1314
attrs = {
@@ -118,7 +119,7 @@ def _haskell_toolchains_impl(mctx):
118119
bindist_targets.append(bindist_tag.target)
119120
ghc_bindist(
120121
name = name,
121-
version = bindist_tag.version,
122+
version = bindist_tag.version or GHC_VERSION,
122123
target = bindist_tag.target,
123124
ghcopts = bindist_tag.ghcopts,
124125
haddock_flags = bindist_tag.haddock_flags,
@@ -152,7 +153,7 @@ def _haskell_toolchains_impl(mctx):
152153
targets = bindist_info_for_version(mctx, bindists_tag.version).keys()
153154

154155
haskell_register_ghc_bindists(
155-
version = bindists_tag.version,
156+
version = bindists_tag.version or GHC_VERSION,
156157
ghcopts = bindists_tag.ghcopts,
157158
haddock_flags = bindists_tag.haddock_flags,
158159
repl_ghci_args = bindists_tag.repl_ghci_args,

extensions/rules_haskell_dependencies.bzl

-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
""" This module extension contains rules_haskell dependencies that are not available as modules """
22

3-
load("@rules_haskell//haskell:repositories.bzl", "rules_haskell_dependencies_bzlmod")
43
load("@rules_haskell//tools:repositories.bzl", "rules_haskell_worker_dependencies")
54
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
65
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
76
load("@rules_haskell//tools:os_info.bzl", "os_info")
87
load("@rules_haskell_ghc_version//:ghc_version.bzl", "GHC_VERSION")
98

109
def repositories(*, bzlmod):
11-
rules_haskell_dependencies_bzlmod()
12-
1310
# Some helpers for platform-dependent configuration
1411
maybe(
1512
os_info,

extensions/stack_snapshot.bzl

+21-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
This module extension gathers packages and configuration from all the modules that use it,
33
in order to make a unique call to `stack_snapshot` to generate a "stackage" shared repository.
44
5-
Most of the configuration can only be made by the root module, and
5+
Most of the configuration can only be made by the root module, and
66
other modules can declare the packages they want installed.
77
88
The rules_haskell module itself has more permissions, so that it can
@@ -13,6 +13,23 @@ snapshot to use.
1313
load("@rules_haskell//haskell:cabal.bzl", _stack_snapshot = "stack_snapshot")
1414
load("@bazel_skylib//lib:new_sets.bzl", "sets")
1515
load("@os_info//:os_info.bzl", "cpu_value", "is_darwin", "is_linux", "is_windows")
16+
load("@rules_haskell_ghc_version//:ghc_version.bzl", "GHC_VERSION")
17+
18+
def _ghc_versioned(label, is_rules_haskell):
19+
"""
20+
Add the GHC version to the name of the given label.
21+
"""
22+
if not GHC_VERSION or not is_rules_haskell:
23+
return label
24+
25+
name, ext = label.name.split(".")
26+
versioned = ":{name}_{version}.{ext}".format(
27+
name = name,
28+
version = GHC_VERSION,
29+
ext = ext,
30+
)
31+
32+
return label.relative(versioned)
1633

1734
_snapshot_tag = tag_class(
1835
doc = "The stack snapshot to use.",
@@ -228,6 +245,7 @@ def _stack_snapshot_impl(mctx):
228245
rules_haskell_modules = []
229246
kwargs = {}
230247
for module in mctx.modules:
248+
print(module)
231249
if module.is_root:
232250
root_module = module
233251
if module.name == "rules_haskell":
@@ -241,7 +259,7 @@ def _stack_snapshot_impl(mctx):
241259
snapshot_tag = module.tags.snapshot[0]
242260
if "snapshot" not in kwargs and "local_snapshot" not in kwargs:
243261
if snapshot_tag.local_snapshot:
244-
kwargs["local_snapshot"] = snapshot_tag.local_snapshot
262+
kwargs["local_snapshot"] = _ghc_versioned(snapshot_tag.local_snapshot, is_rules_haskell = module in rules_haskell_modules)
245263
if snapshot_tag.name:
246264
kwargs["snapshot"] = snapshot_tag.name
247265
else:
@@ -260,7 +278,7 @@ def _stack_snapshot_impl(mctx):
260278
cpu_value in os_list,
261279
])
262280
):
263-
kwargs["stack_snapshot_json"] = stack_snapshot_json_tag.label
281+
kwargs["stack_snapshot_json"] = _ghc_versioned(stack_snapshot_json_tag.label, is_rules_haskell = module in rules_haskell_modules)
264282
break
265283

266284
if module.tags.verbose:

haskell/repositories.bzl

-10
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ _rules_nixpkgs_sha256 = "980edfceef2e59e1122d9be6c52413bc298435f0a3d452532b8a48d
1515
_rules_sh_version = "v0.3.0"
1616
_rules_sh_sha256 = "d668bb32f112ead69c58bde2cae62f6b8acefe759a8c95a2d80ff6a85af5ac5e"
1717

18-
def rules_haskell_dependencies_bzlmod():
19-
"""Provide rules_haskell dependencies which are not available as bzlmod modules."""
20-
21-
maybe(
22-
ghc_default_version,
23-
name = "rules_haskell_ghc_version",
24-
)
25-
2618
def rules_haskell_dependencies():
2719
"""Provide all repositories that are necessary for `rules_haskell` to function."""
2820
if "bazel_version" in dir(native):
@@ -132,8 +124,6 @@ def rules_haskell_dependencies():
132124
url = "https://github.com/aspect-build/rules_js/releases/download/v1.33.1/rules_js-v1.33.1.tar.gz",
133125
)
134126

135-
rules_haskell_dependencies_bzlmod()
136-
137127
# Dependency of com_google_protobuf.
138128
# TODO(judahjacobson): this is a bit of a hack.
139129
# We can't call that repository's protobuf_deps() function

tools/repositories.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def rules_haskell_worker_dependencies(**stack_kwargs):
1313

1414
if "rules_haskell_worker_dependencies" not in excludes:
1515
snapshot_suffix = "_{}".format(GHC_VERSION) if GHC_VERSION else ""
16+
#xfail(snapshot_suffix)
1617
stack_snapshot(
1718
name = "rules_haskell_worker_dependencies",
1819
local_snapshot = "//:stackage_snapshot{}.yaml".format(snapshot_suffix),

0 commit comments

Comments
 (0)