-
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
Make package names more similar to the rule name. #246
Conversation
As of #222, both the package name and ID are z-encoded. However, GHC only needs the package *ID* to be unique, as long as you call `-package-id` instead of `-package`. As a result we can simplify how package-names are encoded: we can keep them the same as the rule name, other than fixing underscores. In addition to (I think) making error messages nicer, this paves the way for some improvements in Hazel (or similar tools), now that the rule and package names can be identical: - It helps support the PackageImports extension. - GHC >= 8.0 generates the Cabal macros (e.g., `MIN_VERSION_*`) automatically. Prebuilt dependencies are still passed with `-package` since their IDs are internal details of GHC.
It turns out they're generated automatically by GHC since version 8.0, as long as we pass the right package name and version. That's now possible as of tweag/rules_haskell#246. I'll hold off merging this PR until that one goes in, then I'll rebase to `rules_haskell` master.
It turns out they're generated automatically by GHC since version 8.0, as long as we pass the right package name and version. That's now possible as of tweag/rules_haskell#246. I'll hold off merging this PR until that one goes in, then I'll rebase to `rules_haskell` master.
It turns out they're generated automatically by GHC since version 8.0, as long as we pass the right package name and version. That's now possible as of tweag/rules_haskell#246. I'll hold off merging this PR until that one goes in, then I'll rebase to `rules_haskell` master.
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.
Overall, LGTM. Only change I'd prefer to see is a nicer encoding for underscores given that this will appear in source code, or even no encoding at all.
As it stands, the current implementation of the package name encoding isn't injective anyways.
@@ -866,35 +862,41 @@ def _zencode(s): | |||
return s.replace("Z", "ZZ").replace("_", "ZU").replace("/", "ZS") | |||
|
|||
def get_pkg_name(ctx): | |||
"""Get package name. Package name includes Bazel package and name of the |
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.
You point out that funny package names won't just be visible in documentation, but much worse, in source code too (if using -XPackageImports
). Funny names in documentation is less bad because if the names change, nothing breaks. Fortunately, we can separate package-id from package-name, it's just that underscores are still illegal.
If so then I'd lean towards banning underscores outright. That way no encoding necessary, no funny names in package imports. Either that or s/_/-/
, which yes, is technically a non-injective encoding, but since package names don't need to be unique (only package-id's), that should be ok. And it lets users keep to Bazel-conventional package naming style if desired (i.e. underscores everywhere, no hyphens).
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.
LGTM, just a few minor issues.
haskell/actions.bzl
Outdated
"""Get package name. | ||
|
||
The name is not required to be unique/injective; however it must be a valid | ||
GHC package name (i.e., no underscores). This encoding is not aims to |
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 not aim"?
haskell/cc.bzl
Outdated
@@ -187,6 +187,7 @@ def _cc_haskell_import(ctx): | |||
if dbin != None: | |||
set.mutable_insert(dyn_libs, dbin) | |||
|
|||
print(dyn_libs) |
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.
Should this be removed?
haskell/providers.bzl
Outdated
@@ -15,7 +15,7 @@ HaskellBuildInfo = provider( | |||
HaskellLibraryInfo = provider( | |||
doc = "Library-specific information.", | |||
fields = { | |||
"package_name": "Package name, usually of the form name-version.", | |||
"package_id": "Package name, usually of the form name-version.", |
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.
Let's say "package id" here?
It turns out they're generated automatically by GHC since version 8.0, as long as we pass the right package name and version. That's now possible as of tweag/rules_haskell#246. (So bump `rules_haskell` accordingly.) Also add network back since the new `rules_haskell` handles `cc_library` `defines` attributes better.
As of #222, both the package name and ID are z-encoded. However,
GHC only needs the package ID to be unique, as long as you
call
-package-id
instead of-package
. As a result we cansimplify how package-names are encoded: we can keep them the same
as the rule name, other than fixing underscores.
In addition to (I think) making error messages nicer, this paves the way for
some improvements in Hazel (or similar tools), now that the rule and package
names can be identical:
MIN_VERSION_*
) automatically.Prebuilt dependencies are still passed with
-package
since their IDs are internal details of GHC.