-
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
Asterius rules #1621
Asterius rules #1621
Conversation
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.
Great work! Really exciting to see so many tests pass already.
I left a couple comments / questions.
haskell/asterius/defs.bzl
Outdated
] | ||
|
||
# Label of the template file to use for the webpack config. | ||
_TEMPLATE = "//haskell/asterius:asterius_webpack_config.js.tpl" |
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.
_TEMPLATE = "//haskell/asterius:asterius_webpack_config.js.tpl" | |
_TEMPLATE = "@rules_haskell//haskell/asterius:asterius_webpack_config.js.tpl" |
I'd expect that this needs to be fully qualified for uses outside of rules_haskell
itself.
haskell/asterius/defs.bzl
Outdated
# ctx.file.dep was generated in the asterius platform configuration, | ||
# and we want to generate js files in the current configuration. | ||
# So we will copy it to the folder corresponding to the current platform. | ||
file_copy_path = paths.join(output_tar_file.dirname, ctx.file.dep.basename) |
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.
Does this cause collisions if one sets --platforms @rules_haskell//haskell/asterius:asterius_platform
globally? (Assuming that that's possible.) If so, this may need a check to only issue a copy action if the paths are actually different.
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.
This should be fine now that we output files in a subfolder.
At the moment, it is not possible to set --platforms @rules_haskell//haskell/asterius:asterius_platform
globally when compiling a ahc_dist
target because it depends on the rules_nodejs
toolchain that sets a target constraint (and maybe should not). But only the dependencies of this target need to be built for the asterius_platform.
haskell/asterius/BUILD.bazel
Outdated
@@ -1,5 +1,11 @@ | |||
load("@npm_rules_haskell//webpack-cli:index.bzl", webpack = "webpack_cli") |
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.
Does this mean that we impose a specific npm_install
or yarn_install
on the user? If so, perhaps this could use an indirection similar to what gazelle_cabal does to not impose that.
haskell/asterius/defs.bzl
Outdated
options = " ".join(ctx.attr.options) | ||
command = " && ".join([ | ||
"cp $2 $3", | ||
"$1 --input-exe $3 {} --verbose --output-prefix {} {} {}".format(options, output_prefix, input_mjs, browser), |
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.
"$1 --input-exe $3 {} --verbose --output-prefix {} {} {}".format(options, output_prefix, input_mjs, browser), | |
"$1 --input-exe $3 {} --output-prefix {} {} {}".format(options, output_prefix, input_mjs, browser), |
In other build actions we default to -v0
. Is there a reason this should be --verbose
or is it a debugging left over?
haskell/asterius/defs.bzl
Outdated
command = " && ".join([ | ||
"cp $2 $3", | ||
"$1 --input-exe $3 {} --verbose --output-prefix {} {} {}".format(options, output_prefix, input_mjs, browser), | ||
"tar cf {output_tar} --exclude=./{output_tar_name} -C {workdir} . -h".format( |
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.
tar
is not deterministic by default. In particular, timestamps and other file metadata as well as the order of files are not deterministic. See here for the necessary command-line flags to make it deterministic. See here for some more information.
Alternatively, perhaps you could use pkg_tar
or the underlying tool it uses.
haskell/asterius/defs.bzl
Outdated
"ahc_dist_dep": attr.label( | ||
mandatory = True, | ||
allow_single_file = True, | ||
doc = """ |
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.
doc = """ | |
doc = """\ |
So that it's still the first line of the docstring? IIRC that has meaning in Startdoc.
haskell/asterius/defs.bzl
Outdated
"testonly", | ||
] | ||
|
||
def asterius_common_impl(is_asterius_test, name, ahc_dist_dep, entry_point, subfolder_prefix = "asterius_untar", data = [], **kwargs): |
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.
def asterius_common_impl(is_asterius_test, name, ahc_dist_dep, entry_point, subfolder_prefix = "asterius_untar", data = [], **kwargs): | |
def _asterius_common_impl(is_asterius_test, name, ahc_dist_dep, entry_point, subfolder_prefix = "asterius_untar", data = [], **kwargs): |
Looks like it should be private.
haskell/asterius/defs.bzl
Outdated
# Copied from https://github.com/tweag/asterius/blob/9f2574d9c2b50aa83d105741799e2f65b05e2023/asterius/test/ghc-testsuite.hs | ||
# The node options required to execute outputs from asterius. | ||
|
||
node_options = [ |
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.
node_options = [ | |
_node_options = [ |
Do these need to be public?
Cabal | ||
, base | ||
base |
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.
What's the reason for this change?
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 Cabal
library is not actually needed here and I thought that it was not compatible with asterius.
Because the asterius test failed with: Cabal is not a toolchain library
.
But now that I looked into it deeper I think it was a mistake.
We try to use Cabal as a toolchain library because it is in this list, but this list seems wrong in the case of asterius. So maybe we could recover the Cabal package via some other way in this case ?
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.
Oh, I see. Thanks for looking into this.
I think we can remove that list and instead use the location information provided by stack here. IIRC if there is no location
field in the spec then it is a core package.
Though, I think this is orthogonal to this PR and perhaps better addressed in a separate PR.
172a6e5
to
6c004d5
Compare
Thank you, I addressed the various comments.
|
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.
Thank you! Great work!
6c004d5
to
0314425
Compare
CI is failing after rebase. Perhaps due to the changes in #1623. |
c079738
to
01b6d5f
Compare
This PR contains the following asterius related rules as well as the tests.
The
ahc_dist
rule converts a haskell binary target (haskell_test
,haskell_binary
orhaskell_cabal_binary
) produced with the asterius haskell toolchain into an archive containing multiple javascript files.There is a transition on its
dep
attribute so that this binary target is built using the asterius haskell toolchain.The
asterius_binary
andasterius_test
rules can then run these files using node (if theahc_dist
target is built withtarget="node"
).The
asterius_webpack
rule can bundle all of these file into a unique js file (if theahc_dist
target is built withtarget="browser"
).Tests
The
tests/asterius/asterius_tests_utils.bzl
file contains a macro used for the asterius tests which we use to call the above rules on existing binary targets from the tests folder.We call this macro for almost all the binaries which do not depend on C code or use GHC specific toolchains libraries.
There are three exceptions which need more investigation:
tests/lhs
needs to call theunlit
binary, which should maybe be made explicit in the haskell toolchain first.tests/haskell_cabal_package
imports its main function fromLib
, and it is not visible as such in the asterius generated javascript files. This example also fails when callingahc-cabal
directly.tests/binary_with_main
is a bit similar because it makes use of themain_function
attribute.Logs
I am unsure what to do about the logs of
ahc-build
(which always outputs some build info).Such as :
Should a flag be added to
ahc-build
in order to disable them?