tweag / gazelle_cabal

A gazelle extension to produce Haskell rules from cabal files
Apache License 2.0
13 stars 5 forks source link

stack_snapshot -exe suffix incompatible with bzlmod name remapping. #61

Open aherrmann opened 1 year ago

aherrmann commented 1 year ago

Describe the bug The naming of the stack_snapshot generated external workspace for executable targets interacts badly with bzlmod name mapping.

rules_haskell's stack_snapshot module extension generates a main workspace for library targets named stackage and a secondary workspace exposing executable components using the same name with an -exe suffix, i.e. stackage-exe. To use third-party libraries or tools a user must invoke use_repo(stack_snapshot, "stackage", "stackage-exe"). So far, so good.

Now let's say that a user wants to import a secondary Stack snapshot, e.g. stackage-b as illustrated in the gazelle_cabal test suite. To translate this use-case to bzlmod we can use an isolated extension.

However, the stack_snapshot module extension always uses the external workspace names stackage and stackage-exe, instead of accepting a name attribute, see https://github.com/tweag/rules_haskell/pull/1962 and https://github.com/bazel-contrib/rules-template/pull/46#discussion_r1096605096 for motivation. So, we must use repo name mapping to avoid name collision with the main stackage workspace. But, for module extension generated external workspaces repo name mapping is declared using keyword argument syntax on the use_repo function, e.g. use_repo(stack_snapshot_b, stackage_b = "stackage").

That means that the target workspace name must be a valid Starlark identifier. To my knowledge there is no way to construct a valid identifier equaling stackage-b or stackage-b-exe. So, instead we would have to fall back to a syntax like stackage_b and stackage_b_exe. However, Gazelle Cabal can currently only be configured in the main workspace name and hard-codes a -exe suffix for the executables workspace (e.g. here and elsewhere). This is incompatible with bzlmod repo name remapping.

To Reproduce Try to run the alternative-deps tests with bzlmod enabled as of commit https://github.com/tweag/gazelle_cabal/commit/086fffedbf1bdec51ca8dc55552c1fdc54801b6a.

Expected behavior It should be possible to apply bzlmod repo renaming to a stackage snapshot and still access both the main library workspace and the executables workspace.

Environment

Additional context Bazel Slack discussion.

aherrmann commented 1 year ago

Possible solutions that come to mind: