Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable bzlmod with GHC 9.4.x #2030

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ jobs:
exclude:
- module: rules_haskell_nix
bzlmod: false
# TODO: in a MODULE.bazel file we declare version specific dependencies, would need to use stack snapshot json
# and stack config per GHC version
- ghc: 9.4.5
bzlmod: true
runs-on: ${{ matrix.os }}
steps:
- if: ${{ matrix.os == 'ubuntu-latest' }}
Expand Down
5 changes: 3 additions & 2 deletions extensions/haskell_toolchains.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions extensions/rules_haskell_dependencies.bzl
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
""" 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")
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,
Expand Down
23 changes: 20 additions & 3 deletions extensions/stack_snapshot.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.",
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
10 changes: 0 additions & 10 deletions haskell/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tools/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Loading