-
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
CC Macro name conflict when two packages have the same name #414
Comments
After a discussion with @mboes, we'll go with This solution is based on the invariant that inside a mono repository you don't care about version number of your dependencies for local packages, because the version number is implitly fixed by the repository. The design will be as such:
The designed |
@guibou that approach sounds good and should work fine for Hazel. |
580ea82 is a unit test reproducing the issue
Problem statment
The haskell package name of an
haskell_library
is based on the bazel rule name, so//tests:bytestring
and//tests/cpp_macro_conflict:bytestring
have the same namebytestring
.When enabling haskell extension
CPP
, ghc is exporting macrosVERSION_pkgname
(e.g.VERSION_bytestring
), this results in macro name conflicts when ahaskell_library
orhaskell_binary
have twodeps
with the same bazel name.Using code from 580ea82, I got this error when building with
bazel build //tests/cpp_macro_conflict/...
Note: this is an error due to
-Warn
, but usually that's just annoying warnings.One simple workaround is to tell user to avoid package name conflict when using
CPP
.Discussion
Version name is useful for library from the outside world (i.e. hackage) because they may implement different behaviors depending on some version of their dependencies, which are also coming from the outside world. These external libraries can still be built inside our bazel repository (i.e. using Hazel). These external libraries depends on these macro and on the correct package name. For them we need to export the version macro and keep the official package name. External libraries have a version number (and hazel exposes it using
version
attribute).Libraries defined in a bazel repository may not be concerned by version number, that the point of a mega repo, you control all your dependencies and everything must be coherent inside the mega repo. Hence users won't need these macros for local libraries and we can disable them.
The undocumented option
-fno-macro-version
(https://ghc.haskell.org/trac/ghc/ticket/11763) works for all the macros during one build operation. This does not allow a per-package choice. For example, if a rule depends on both the "hackage"bytestring
and a localbytestring
, we cannot enable macro generation for the former and not for the later.Design proposal
Each package controls if its macro version will be exported when the package is used as a dependency. Using for example an
export_macros
attribute. The exported macro depends on theversion
attribute.Users will still have to change their naming scheme but only if they want to export the version macro of two packages with the same name.
For example:
Here,
bar
will be built with version macro forbytestring
but not forfoo
.Implementation details
We'll have to use
-fno-macro-version
for all build and then manually export the needed macros.We'll have to manually replicate the macro export mechanisms, AFAIK there is no flag to tell GHC to export the version macro per package.
Alternative design 0
We can tell user that, if they want to use CPP macro, they need to avoid package name conflict. They will need to change their naming scheme, but there is no work from our side (except documentation).
Simple, but forces the user to change its naming scheme.
Design 1: disable all macros on a rule
This is the solution with the simplest implementation, using
-fno-macro-version
, we can disable all the macro generation during the rule execution. For example:Here
bytestring
will be built with the macro version forlens
andtext
. Howeverfoo
will be built without any macro version.I don't like this approach, because disabling all the macro for a build changes nothing compared to the current status of rules_haskell, except that it will disable the warnings.
The text was updated successfully, but these errors were encountered: