diff --git a/extensions/haskell_toolchains.bzl b/extensions/haskell_toolchains.bzl index 1d01eb8dd..96ca170d4 100644 --- a/extensions/haskell_toolchains.bzl +++ b/extensions/haskell_toolchains.bzl @@ -8,6 +8,7 @@ load( "ghc_bindists_toolchain_declarations", "haskell_register_ghc_bindists", ) +load("@rules_haskell_ghc_version//:ghc_version.bzl", "GHC_VERSION") _bindists_tag = tag_class( attrs = { @@ -118,7 +119,7 @@ def _haskell_toolchains_impl(mctx): bindist_targets.append(bindist_tag.target) ghc_bindist( name = name, - version = bindist_tag.version, + version = bindist_tag.version or GHC_VERSION, target = bindist_tag.target, ghcopts = bindist_tag.ghcopts, haddock_flags = bindist_tag.haddock_flags, @@ -152,7 +153,7 @@ def _haskell_toolchains_impl(mctx): targets = bindist_info_for_version(mctx, bindists_tag.version).keys() haskell_register_ghc_bindists( - version = bindists_tag.version, + version = bindists_tag.version or GHC_VERSION, ghcopts = bindists_tag.ghcopts, haddock_flags = bindists_tag.haddock_flags, repl_ghci_args = bindists_tag.repl_ghci_args, diff --git a/extensions/rules_haskell_dependencies.bzl b/extensions/rules_haskell_dependencies.bzl index 1f25f9e45..2a4ec96fe 100644 --- a/extensions/rules_haskell_dependencies.bzl +++ b/extensions/rules_haskell_dependencies.bzl @@ -1,6 +1,5 @@ """ This module extension contains rules_haskell dependencies that are not available as modules """ -load("@rules_haskell//haskell:repositories.bzl", "rules_haskell_dependencies_bzlmod") load("@rules_haskell//tools:repositories.bzl", "rules_haskell_worker_dependencies") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") @@ -8,8 +7,6 @@ load("@rules_haskell//tools:os_info.bzl", "os_info") load("@rules_haskell_ghc_version//:ghc_version.bzl", "GHC_VERSION") def repositories(*, bzlmod): - rules_haskell_dependencies_bzlmod() - # Some helpers for platform-dependent configuration maybe( os_info, diff --git a/extensions/stack_snapshot.bzl b/extensions/stack_snapshot.bzl index 855935774..e7c36740c 100644 --- a/extensions/stack_snapshot.bzl +++ b/extensions/stack_snapshot.bzl @@ -2,7 +2,7 @@ This module extension gathers packages and configuration from all the modules that use it, in order to make a unique call to `stack_snapshot` to generate a "stackage" shared repository. -Most of the configuration can only be made by the root module, and +Most of the configuration can only be made by the root module, and other modules can declare the packages they want installed. The rules_haskell module itself has more permissions, so that it can @@ -13,6 +13,23 @@ snapshot to use. load("@rules_haskell//haskell:cabal.bzl", _stack_snapshot = "stack_snapshot") load("@bazel_skylib//lib:new_sets.bzl", "sets") load("@os_info//:os_info.bzl", "cpu_value", "is_darwin", "is_linux", "is_windows") +load("@rules_haskell_ghc_version//:ghc_version.bzl", "GHC_VERSION") + +def _ghc_versioned(label, is_rules_haskell): + """ + Add the GHC version to the name of the given label. + """ + if not GHC_VERSION or not is_rules_haskell: + return label + + name, ext = label.name.split(".") + versioned = ":{name}_{version}.{ext}".format( + name = name, + version = GHC_VERSION, + ext = ext, + ) + + return label.relative(versioned) _snapshot_tag = tag_class( doc = "The stack snapshot to use.", @@ -241,7 +258,7 @@ def _stack_snapshot_impl(mctx): snapshot_tag = module.tags.snapshot[0] if "snapshot" not in kwargs and "local_snapshot" not in kwargs: if snapshot_tag.local_snapshot: - kwargs["local_snapshot"] = snapshot_tag.local_snapshot + kwargs["local_snapshot"] = _ghc_versioned(snapshot_tag.local_snapshot, is_rules_haskell = module in rules_haskell_modules) if snapshot_tag.name: kwargs["snapshot"] = snapshot_tag.name else: @@ -260,7 +277,7 @@ def _stack_snapshot_impl(mctx): cpu_value in os_list, ]) ): - kwargs["stack_snapshot_json"] = stack_snapshot_json_tag.label + kwargs["stack_snapshot_json"] = _ghc_versioned(stack_snapshot_json_tag.label, is_rules_haskell = module in rules_haskell_modules) break if module.tags.verbose: diff --git a/haskell/repositories.bzl b/haskell/repositories.bzl index fd32c337c..c676b27c6 100644 --- a/haskell/repositories.bzl +++ b/haskell/repositories.bzl @@ -15,14 +15,6 @@ _rules_nixpkgs_sha256 = "980edfceef2e59e1122d9be6c52413bc298435f0a3d452532b8a48d _rules_sh_version = "v0.3.0" _rules_sh_sha256 = "d668bb32f112ead69c58bde2cae62f6b8acefe759a8c95a2d80ff6a85af5ac5e" -def rules_haskell_dependencies_bzlmod(): - """Provide rules_haskell dependencies which are not available as bzlmod modules.""" - - maybe( - ghc_default_version, - name = "rules_haskell_ghc_version", - ) - def rules_haskell_dependencies(): """Provide all repositories that are necessary for `rules_haskell` to function.""" if "bazel_version" in dir(native): @@ -132,8 +124,6 @@ def rules_haskell_dependencies(): url = "https://github.com/aspect-build/rules_js/releases/download/v1.33.1/rules_js-v1.33.1.tar.gz", ) - rules_haskell_dependencies_bzlmod() - # Dependency of com_google_protobuf. # TODO(judahjacobson): this is a bit of a hack. # We can't call that repository's protobuf_deps() function diff --git a/tools/repositories.bzl b/tools/repositories.bzl index 346c79d7f..4d4457351 100644 --- a/tools/repositories.bzl +++ b/tools/repositories.bzl @@ -13,6 +13,7 @@ def rules_haskell_worker_dependencies(**stack_kwargs): if "rules_haskell_worker_dependencies" not in excludes: snapshot_suffix = "_{}".format(GHC_VERSION) if GHC_VERSION else "" + stack_snapshot( name = "rules_haskell_worker_dependencies", local_snapshot = "//:stackage_snapshot{}.yaml".format(snapshot_suffix),