-
Notifications
You must be signed in to change notification settings - Fork 81
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
haskell_toolchains extension #1914
Conversation
9cf5ed4
to
26926db
Compare
8d445fa
to
8877ccc
Compare
26926db
to
ff84233
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work, that looks great!
Only a couple small comments.
Btw, I really appreciate how easy this PR and #1912 are to review commit by commit. Thank you!
test_ghc_version = "9.2.5" | ||
|
||
test_ghcopts = [ | ||
"-XStandaloneDeriving", # Flag used at compile time | ||
"-threaded", # Flag used at link time | ||
# Used by `tests/repl-flags` | ||
"-DTESTS_TOOLCHAIN_COMPILER_FLAGS", | ||
# this is the default, so it does not harm other tests | ||
"-XNoOverloadedStrings", | ||
] | ||
|
||
test_haddock_flags = ["-U"] | ||
|
||
test_repl_ghci_args = [ | ||
# The repl test will need this flag, but set by the local | ||
# `repl_ghci_args`. | ||
"-UTESTS_TOOLCHAIN_REPL_FLAGS", | ||
# The repl test will need OverloadedString | ||
"-XOverloadedStrings", | ||
] | ||
|
||
test_cabalopts = [ | ||
# Used by `tests/cabal-toolchain-flags` | ||
"--ghc-option=-DTESTS_TOOLCHAIN_CABALOPTS", | ||
"--haddock-option=--optghc=-DTESTS_TOOLCHAIN_CABALOPTS", | ||
] | ||
|
||
cabalopts_windows = test_cabalopts + [ | ||
# To avoid ghcide linking errors with heapsize on Windows of the form | ||
# | ||
# unknown symbol `heap_view_closurePtrs' | ||
# | ||
# See https://github.com/haskell/ghcide/pull/954 | ||
"--disable-library-for-ghci", | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The configuration variables such as
test_repl_ghci_args
are duplicated inside the MODULE.bazel file because it is not possible toload
them at the moment (see bazelbuild/bazel#17880). For the same reason it is not possible to rely onis_windows
to configure thecabalops
variable so the windows toolchains are declared separately in this file.
Perhaps another approach could be for the module extension/tags to accept a label to a JSON file holding this configuration? (Either way, out of scope for this PR)
extensions/haskell_toolchains.bzl
Outdated
), | ||
}, | ||
doc = """ Used to generate the `all_bindist_toolchains` external repository. | ||
We can then invoque `register_toolchains("@all_bindist_toolchains//:all")` in the MODULE.bazel file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo invoque --> invoke
.
extensions/haskell_toolchains.bzl
Outdated
attrs = { | ||
"name": attr.string( | ||
mandatory = True, | ||
doc = "A unique name for the repository", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs a bit more explanation. As I understand it, it's only a unique name for the tag within the calling module. I.e. it doesn't have to be a globally unique name, correct?
extensions/haskell_toolchains.bzl
Outdated
found_bindists = False | ||
for module in mctx.modules: | ||
for bindist_tag in module.tags.bindist: | ||
name = "bindist_{}_{}_{}".format(module.name, module.version, bindist_tag.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is bindist_tag.name
actually needed, or could it be replaced by an autogenerated unique suffix (e.g. a counter, or perhaps a hash
plus collision counter to reduce invalidation)? Asking in the spirit of this discussion. Since the name is scoped to within the calling MODULE and not global it doesn't seem too onerous, but, maybe it can be avoided altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah indeed I think we can do without the name attribute (and without auto-generated suffixes).
I updated the code to rely on the target
attribute instead.
Before, if two bindist
tags shared the same target
attribute, the toolchains would have the same constraints so the second one would be effectively ignored. So now, a module is not allowed to use two bindist
tags with the same target
, and (module.name, module.version, bindist_tag.target)
can be used as an identifier.
extensions/haskell_toolchains.bzl
Outdated
for bindists_tag in module.tags.bindists: | ||
# We only consider the first `bindists` tag, because subsequent | ||
# ones would have the same constraints and lower priority. | ||
if not found_bindists: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be simplified to something along the lines of the following?
if module.tags.bindists:
bindists_tag = module.tags.bindists[0]
...
I.e. drop the found_bindists
boolean.
🎉 All dependencies have been resolved ! |
These are not needed anymore in bzlmod because of the haskell_toolchains module extension.
This helps the haskell_toolchains module extensions to declare all of its toolchains in one BUILD file.
ff84233
to
b0659bf
Compare
This extension is used to register the haskell bindists with bzlmod.
b0659bf
to
eefde79
Compare
Depends on #1912
This PR adds the
haskell_toolchains
module extension which is used to configure and register the haskell bindists, via thebindist
andbindists
tags.bindists
tag corresponds tohaskell_register_ghc_bindists
and registers toolchains for all platforms.bindist
tag corresponds toghc_bindist
and is used to register toolchains one at a time. Inside the same module, the toolchains declared withbindist
take precedence over thebindists
ones.The
rules_haskell
module calls thebindists
tag itself to register default toolchains that can be used without any configuration. Alternatively, we can register customized toolchains, as done by therules_haskell_test
module (the priority of toolchains respects bazel's iteration order over modules where the root module comes first).We cannot use load in the
MODULE.bazel
files at the momentThe configuration variables such as
test_repl_ghci_args
are duplicated inside the MODULE.bazel file because it is not possible toload
them at the moment (see bazelbuild/bazel#17880). For the same reason it is not possible to rely onis_windows
to configure thecabalops
variable so the windows toolchains are declared separately in this file.Documentation
The documentation is not generated because stardoc does not support it yet (bazelbuild/stardoc#123).
Toolchain declaration
It is not possible to register aliases to toolchain with bzlmod yet (bazelbuild/bazel#16298), so
ghc_bindist.bzl
was refactored a bit to makeghc_bindist_toolchain_declaration
public. This way thehaskell_toolchains
module extension can call it to build its own toolchain declarations.