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

sublibraries in stack_snapshot rule #1636

Merged
merged 5 commits into from
Nov 25, 2021
Merged

Conversation

ylecornec
Copy link
Member

@ylecornec ylecornec commented Nov 22, 2021

Depends on #1641.

This PR adds support for sublibraries in stack_snapshot.

  • They can now be added to the components attribute as lib:<sublib-name>.
  • As for the main library and executables, the dependencies returned by stack ls snapshot json are also added to those of the sublibraries. These dependencies seem to be the union of the dependencies of the components, so there may be to many of them.

The components_dependencies attribute.

This new attribute enables declaring internal dependencies between components.
This is most often needed when the main library depends on a sublibrary, as in the example.

Since the types of bazel's attributes are is a bit limited, I went for a dict of json strings, but maybe there is a better interface for this.

    ```
    components_dependencies = {
      "package-name": \"""{"lib:package-name": ["lib:sublib1", "lib:sublib2"]}\""",
    },
    ```

Aliases

  • The sublibraries are named @<stack_snapshot_name>//:_<package_name>_lib_<sublib_name> and aliases are created (in the same repository) so that they can be referenced from BUILD files as @<stack_snapshot_name>//<package_name>:<sublib_name>.

  • For now there is also a new alias for the main library: @<stack_snapshot_name>//<package_name>.
    But if I believe the conclusion of Build executables in stack_snapshot and use them as tools #1306 maybe it's not a good idea.

  • Maybe these aliases could be in an other repository (@<stack_snapshot_name>-libs or @<stack_snapshot_name>-sublibs) to mimic what is done with the executables. But, as @kczulko pointed out, it is natural to have them in the same repository as the main library, and I don't see any possible naming conflict.

Tests

  • An archive made from the tests/haskell_cabal_library_sublibrary_name test is imported in a custom stack snapshot. Since stack resolves local archives to absolute paths, this archive is downloaded from an ealier commit of the rules_haskell repository.

  • The new tests/stackage_sublibrary test adds a binary that directly depends on the sublibrary of this package via the stackage repository.

  • I was not sure in which stack_snapshot rule to add the test, or if it's better to create a new one ?
    So I added this to the @stackage-pinning-test workspace for now.

Setup_deps attribute

I noticed that setup_deps was present in the parameters to format but not used in the generated haskell_cabal_binary rules. It looks like it may also concern the binary rules so I added it.

@ylecornec ylecornec force-pushed the ylecornec/stack_snapshot_sublibs branch 3 times, most recently from c05850d to e0e363b Compare November 24, 2021 11:04
@ylecornec ylecornec marked this pull request as ready for review November 24, 2021 12:48
@aherrmann
Copy link
Member

Since the types of bazel's attributes are is a bit limited, I went for a dict of json strings, but maybe there is a better interface for this.

An idea that was discussed here in the past is to have packages accept a struct that can be used to pass more information in a more structured way. As you rightly point out, Bazel's attribute types are quite limited, so in this case the stack_snapshot Starlark function would have to go through all these structs and distribute their fields across the appropriate attributes of the underlying repository rule.

That said, I'd consider this orthogonal to this PR. Let's go with components_dependencies for now. I think the better solution here would be to extend stack ls dependencies json to produce all the information that we need.

IIUC this means that all executables go into @<stackage>-exe//<package-name>:<exe-name> and all libraries into @<stackage>//<package-name>:<lib-name> while the main library also goes into @<stackage>//:<package-name>, correct? I think a question was whether the use of <package-name> as both a Bazel package name (//<package-name>) and a target name (//:<package-name>) at the same time would be an issue. Did you test if this causes any problems? If not, then this seems like a good naming scheme for the aliases.

  • I was not sure in which stack_snapshot rule to add the test, or if it's better to create a new one ?
    So I added this to the @stackage-pinning-test workspace for now.

That's fair. Once we have bazel-in-bazel integration tests available, it would be good to have a dedicated one in there.

I noticed that setup_deps was present in the parameters to format but not used in the generated haskell_cabal_binary rules. It looks like it may also concern the binary rules so I added it.

Good catch, that looks like an oversight.

@ylecornec
Copy link
Member Author

ylecornec commented Nov 24, 2021

IIUC this means that all executables go into @<stackage>-exe//<package-name>:<exe-name> and all libraries into @<stackage>//<package-name>:<lib-name> while the main library also goes into @<stackage>//:<package-name>, correct? I think a question was whether the use of <package-name> as both a Bazel package name (//<package-name>) and a target name (//:<package-name>) at the same time would be an issue. Did you test if this causes any problems? If not, then this seems like a good naming scheme for the aliases.

Yes that's it, from what I tested it does not seem to cause any problems, and the :stackage_sublibrary-repl of the test works fine.

@dpulls
Copy link

dpulls bot commented Nov 24, 2021

🎉 All dependencies have been resolved !

@ylecornec
Copy link
Member Author

It should be good to go, I have updated the url of the package1.tar archive to a commit that won't be garbage collected.

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!

@aherrmann aherrmann added the merge-queue merge on green CI label Nov 25, 2021
@ylecornec ylecornec force-pushed the ylecornec/stack_snapshot_sublibs branch from 159137e to aa77ffc Compare November 25, 2021 08:54
@mergify mergify bot merged commit 688e330 into master Nov 25, 2021
@mergify mergify bot deleted the ylecornec/stack_snapshot_sublibs branch November 25, 2021 09:37
@mergify mergify bot removed the merge-queue merge on green CI label Nov 25, 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