Skip to content

Commit

Permalink
Define default GHC version
Browse files Browse the repository at this point in the history
This makes the default GHC version publicly accessible and introduces a new
repository which uses the default GHC version if not already defined.
  • Loading branch information
avdv committed Aug 8, 2023
1 parent bb63b4d commit 83e19de
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
9 changes: 8 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ rules_haskell_dependencies = use_extension(
use_repo(
rules_haskell_dependencies,
"os_info",
"rules_haskell_ghc_version",
"rules_haskell_worker_dependencies",
"rules_haskell_stack_update",
"rules_haskell_stack",
Expand Down Expand Up @@ -286,6 +285,7 @@ register_toolchains(
stack_snapshots = use_extension(
"@rules_haskell//extensions:stack_snapshot.bzl",
"stack_snapshot",
dev_dependency = True,
)

[
Expand Down Expand Up @@ -344,6 +344,13 @@ stack_snapshots.package(
]
]

ghc_version = use_extension("@rules_haskell//extensions:ghc_version.bzl", "ghc_version", dev_dependency=True)

use_repo(
ghc_version,
"rules_haskell_ghc_version",
)

stack_snapshots.stack_snapshot_json(label = "@rules_haskell//:stackage_snapshot.json")

stack_snapshots.snapshot(
Expand Down
6 changes: 6 additions & 0 deletions haskell/ghc.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

# If you change this, change stackage's version in the start script
# (see stackage.org).

# Currently, we are using GHC 9.2.x as default.
DEFAULT_GHC_VERSION = "9.2.5"
5 changes: 2 additions & 3 deletions haskell/ghc_bindist.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ load(
)
load(":private/validate_attrs.bzl", "check_deprecated_attribute_usage")
load(":private/ghc_bindist_generated.bzl", "GHC_BINDIST")
load("//haskell:ghc.bzl", "DEFAULT_GHC_VERSION")

# If you change this, change stackage's version in the start script
# (see stackage.org).
_GHC_DEFAULT_VERSION = "9.2.5"
_GHC_DEFAULT_VERSION = DEFAULT_GHC_VERSION

GHC_BINDIST_STRIP_PREFIX = \
{
Expand Down
23 changes: 18 additions & 5 deletions haskell/private/ghc_ci.bzl
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
load("@rules_haskell//haskell:ghc.bzl", "DEFAULT_GHC_VERSION")

def _init_ghc_version_repository(repository_ctx, GHC_VERSION):
repository_ctx.file("BUILD")
repository_ctx.file("ghc_version.bzl", content = "GHC_VERSION = {}".format(repr(GHC_VERSION)))

def _ghc_version_impl(repository_ctx):
ghc_version = repository_ctx.os.environ.get("GHC_VERSION")
GHC_VERSION = repository_ctx.os.environ.get("GHC_VERSION")

if ghc_version:
print("Using GHC version {} from env variable `GHC_VERSION`".format(ghc_version))
if GHC_VERSION:
print("Using GHC version {} from env variable `GHC_VERSION`".format(GHC_VERSION))

repository_ctx.file("BUILD")
repository_ctx.file("ghc_version.bzl", content = "GHC_VERSION = {}".format(repr(ghc_version)))
_init_ghc_version_repository(repository_ctx, GHC_VERSION)

ghc_version = repository_rule(
implementation = _ghc_version_impl,
environ = ["GHC_VERSION"],
configure = True,
)


def _ghc_default_version_impl(repository_ctx):
_init_ghc_version_repository(repository_ctx, DEFAULT_GHC_VERSION)

ghc_default_version = repository_rule(
implementation = _ghc_default_version_impl,
)
7 changes: 5 additions & 2 deletions haskell/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ load(
":private/versions.bzl",
"check_bazel_version_compatible",
)
load(":private/ghc_ci.bzl", "ghc_version")
load(":private/ghc_ci.bzl", "ghc_default_version")

_rules_nixpkgs_version = "0c1f8f5470c7f292b7620762e224f53d837929d3"
_rules_nixpkgs_sha256 = "9e3898a33c5f21f634aa9e2d45620e7c4b6d54d16d473571a891193bbd4725ca"
Expand All @@ -18,7 +18,10 @@ _rules_sh_sha256 = "d668bb32f112ead69c58bde2cae62f6b8acefe759a8c95a2d80ff6a85af5
def rules_haskell_dependencies_bzlmod():
"""Provide rules_haskell dependencies which are not available as bzlmod modules."""

ghc_version(name = "rules_haskell_ghc_version")
maybe(
ghc_default_version,
name = "rules_haskell_ghc_version"
)

# Dependency of com_google_protobuf.
# TODO(judahjacobson): this is a bit of a hack.
Expand Down

0 comments on commit 83e19de

Please sign in to comment.