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

Asterius toolchain declarations #1619

Merged
merged 3 commits into from
Oct 28, 2021

Conversation

ylecornec
Copy link
Member

Depends on #1618

This PR contains the declarations of the asterius toolchains.

Declarations alongside regular toolchains.

Asterius is not able to implement a full haskell toolchain by itself and needs to rely on a regular one (in particular we need runghc for cabal support).

In order to declare asterius and regular haskell toolchains together there is a new optional asterius_version attribute to haskell_register_ghc_nixpkgs and haskell_register_ghc_bindists: if it is present, we try to also declare asterius versions of the variours haskell toolchains.

At the moment only linux is supported.

The bundle.

For both nix and bindists, we download the same bundle made using the proverbial daml script.
This bundle contains asterius, Tweag's fork of wasi-sdk (the cc toolchain targetting WebAssembly) and the needed dynamic libraries.
It is temporariy uploded to this repository, the plan is to recover it later from the asterius repository once it can build in its ci.

Asterius toolchain type.

We declare a new toolchain type for asterius binaries that are not part of the regular haskell toolchain. It only contains the ahc-dist binary which generates .js files from a haskell "binary" built with the asterius based haskell toolchain.

@ylecornec ylecornec requested a review from aherrmann October 22, 2021 12:25
Base automatically changed from ylecornec/asterius_haskell_toolchain to master October 26, 2021 09:37
@dpulls
Copy link

dpulls bot commented Oct 26, 2021

🎉 All dependencies have been resolved !

Copy link
Member

@aherrmann aherrmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

A couple comments.

Asterius is not able to implement a full haskell toolchain by itself and needs to rely on a regular one (in particular we need runghc for cabal support).

Just to be sure I understand correctly. This is not something that the Asterius toolchain needs to track itself explicitly. Instead this is taken care of by the changes introduced in #1510. Correct?

# Toolchain type for asterius specific tools such as ahc-dist,
# which are not part of the regular haskell toolchain.
toolchain_type(
name = "asterius-toolchain",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = "asterius-toolchain",
name = "toolchain_type",

The documented convention is to use the name toolchain_type for toolchain_type targets. (I know the Haskell toolchain doesn't follow it either, but that's only for historical reasons)
Is there a good reason not to follow this convention with this new toolchain?

Comment on lines 37 to 41
def default_exec_constraints(repository_ctx):
(_, exec_constraints) = default_constraints(repository_ctx)
return [Label(c) for c in exec_constraints]

def labels_from_bundle_name(bundle_repo_name, asterius_version):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything that doesn't start with _ is publically exposed. These look more like local helpers, correct? If so, better to prefix _ and not expose them.

@@ -0,0 +1,323 @@
load("@bazel_skylib//lib:paths.bzl", "paths")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can follow the rule author guidelines here as well. This file should then be named repositories.bzl.

sha256 = sha256,
)

asterius_bundle = repository_rule(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this one meant to be public? Otherwise, also prefix with _.

doc = "Defines the haskell toolchain using asterius, as well as the asterius toolchain which contains asterius specific tools.",
)

def ahc(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps rules_haskell_asterius_toolchains would be a better name for this. Following the pattern recommended here and also the naming here.

),
]

asterius_toolchain = rule(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a regular rule, so probably better placed into haskell/asterius/defs.bzl. Then the ghc.BUILD.tpl also doesn't have to import asterius_workspace_rules.bzl (or repositories.bzl) which would be a strange import for a BUILD file.

cabalopts = None,
locale = None,
nix = False):
""" Define and registers asterius related toolchains. """
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the user facing function, then all the attributes should be documented in the docstring here.

Comment on lines 133 to 136
"nix": attr.bool(
mandatory = True,
doc = "Whether this toolchain depends on nix",
),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand the following comment

For both nix and bindists, we download the same bundle made using the proverbial daml script.

the Asterius bindist is a self contained bundle. So, under which circumstances would the nix attribute need to be True?

repl_ghci_args,
cabalopts,
locale,
nix = True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. The asterius toolchain is attached to a Haskell toolchain (either bindist or nixpkgs) and the nix parameter is used to select the correct one out of those two.
Yes, that's a valid approach.

If I understand correctly the Asterius toolchain does not itself directly depend on the regular GHC toolchain. It only depends on it indirectly through the runghc attribute on the Cabal rules.

Would it be possible to define only one Asterius toolchain in the WORKSPACE by directly calling a user exposed rules_haskell_asterius_toolchains and leave it to Bazel's toolchain resolution to find the correct regular GHC toolchain for the Cabal rules? That would drop the need for the nix parameter and would seem a bit more modular.

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this would be better.
I was under the impression that this was not possible, because the asterius haskell toolchain would depend on another toolchain of the same type (but targeting another platform) so it looked a bit like a circular dependency.
But I just tried it and it seems to work 👍

@ylecornec ylecornec force-pushed the ylecornec/asterius_toolchain_declarations branch 3 times, most recently from 60ac6d6 to 17ef182 Compare October 27, 2021 16:23
@ylecornec
Copy link
Member Author

Just to be sure I understand correctly. This is not something that the Asterius toolchain needs to track itself explicitly. Instead this is taken care of by the changes introduced in #1510. Correct?

Yes it seems so. I was not aware of this so I assumed the runghc from the toolchain was used.

So at the moment tools from the regular haskell toolchain are used to complete the asterius toolchain.
But in the end, ahc and ahc_pkg are the only tools of this toolchain that are actually executed.
(Since haddock is not supported, and I did not look into coverage or repl support yet).

For later, I think that hsc2hs should be useful once asterius supports C interop.
And I am also thinking about making the unlit binary explicit in the toolchain, to make it available to asterius for litterate haskell.

Readthedoc

The build fail looks quite similar to This issue. I will try to look into it.

About the diff

  • I addressed the various comments.
  • Renamed asterius/asterius_workspace_rules.bzl to asterius/repositories.bzl
  • Renamed asterius/asterius_repositories to asterius_dependencies.bzl and reexported functions asterius_dependencies_nix and asterius_dependencies_bindist from asterius/repositories.bzl
  • The documentation for asterius functions is not built with stardoc yet. Some of them depend on rules_nodejs so I encountered this issue and it seems hard to work around.
  • The Nixpkgs platform constraints fix commit is there because the constraints are never actually None inside the repository rule (event if the rule is called with None the default value [] is then used). If we want to distinguish None and [] (to be able to explicitly set empty constraints sometime ?) then we need a different fix.

@ylecornec ylecornec force-pushed the ylecornec/asterius_toolchain_declarations branch from 5447533 to 17ef182 Compare October 28, 2021 06:58
@aherrmann
Copy link
Member

  • The documentation for asterius functions is not built with stardoc yet. Some of them depend on rules_nodejs so I encountered this issue and it seems hard to work around.

Ah, yes, that looks tricky. Good call to skip for now.

  • The Nixpkgs platform constraints fix commit is there because the constraints are never actually None inside the repository rule (event if the rule is called with None the default value [] is then used). If we want to distinguish None and [] (to be able to explicitly set empty constraints sometime ?) then we need a different fix.

Good catch!

Copy link
Member

@aherrmann aherrmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Great work!

@ylecornec ylecornec force-pushed the ylecornec/asterius_toolchain_declarations branch from 17ef182 to b64079d Compare October 28, 2021 11:34
@ylecornec ylecornec added the merge-queue merge on green CI label Oct 28, 2021
@mergify mergify bot merged commit b6ac6ee into master Oct 28, 2021
@mergify mergify bot deleted the ylecornec/asterius_toolchain_declarations branch October 28, 2021 12:27
@mergify mergify bot removed the merge-queue merge on green CI label Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants