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

stack_snapshot build executable components #1304

Merged
merged 5 commits into from
Jun 5, 2020
Merged

Conversation

aherrmann
Copy link
Member

@aherrmann aherrmann commented Apr 20, 2020

Depends on #1303.

Adds a new attribute components to stack_snapshot which allows users to specify which Cabal components to build for a given package in the snapshot (defaults to building the library component). E.g. for the proto-lens-protoc package a user could specify the following to build both the library and executable components.

    components = {
        "proto-lens-protoc": [
            "lib",
            "exe",
        ],
    },

This reduces the need for dedicated http_archive definitions for executable components of Cabal packages.

The executable targets are available under labels of the form @<snapshot>-exe//<package_name>:<exe_name>, as discussed in #1306. For executable components that share the package's name the short form @<snapshot>-exe//<package> applies. For technical reasons (described in #1306) these executable targets are aliases pointing to haskell_cabal_binary targets of the form @<snapshot>//:_<package>_exe_<exe_name>. These labels are considered an implementation detail and not publicly visible.

The dependency graph generated by stack captures the library and executable dependencies of a package. When generating haskell_cabal_binary targets based on declared exe components, we pass in all package dependencies as well as the library component (if present).

The dependency graph generated by stack does not provide information on which components a package includes. Therefore, there is no easy way to automatically determine the set of components. However, only few packages define executable components, so it is feasible for users to manually define them as needed.

A set of known executable components is included in rules_haskell for common packages such as alex or happy.

proto-lens-protoc is converted from a dedicated http_archive to use the components attribute instead. This functions as a test-case for this feature.

ghcide is also converted from a dedicated http_archive to use the components attribute. The ghcide use-case documentation is updated accordingly.

Note, this PR does not yet inject executable components into the tools attribute of generated Cabal targets. E.g. alex and happy still have to be passed into stack_snapshot using the tools attribute. This will be addressed in a follow-up PR.

@@ -845,6 +900,10 @@ def _compute_dependency_graph(repository_ctx, snapshot, core_packages, versioned
is_core_package = name in _CORE_PACKAGES
all_packages[name] = struct(
name = name,
components = _parse_components(
name,
remaining_components.pop(name, ["lib"]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only "lib"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That forms the default set of package components. I.e. by default we say a package only has a library component. (dict.pop(key, default=unbound))

Base automatically changed from cabal-exe-name to master June 2, 2020 10:40
@dpulls
Copy link

dpulls bot commented Jun 2, 2020

🎉 All dependencies have been resolved !

Defines a separate external workspace `@stackage-exe` for a
`stack_snapshot` named `@stackage` that will contain aliases pointing to
the Cabal executable targets to packages in `@stackage`.
@dpulls
Copy link

dpulls bot commented Jun 5, 2020

💔 Pull request #1303's state different from open.

@aherrmann aherrmann marked this pull request as ready for review June 5, 2020 08:47
@aherrmann aherrmann requested a review from guibou June 5, 2020 08:48
@Profpatsch
Copy link
Contributor

broken_heart Pull request #1303's state different from open.

Hm, what does this message mean?

@aherrmann
Copy link
Member Author

broken_heart Pull request #1303's state different from open.

Hm, what does this message mean?

I updated the PR message and didn't remove the "depends on" line. The PR that this one depends on has since been merged, so dpulls complains about depending on a closed PR. However, the status dpulls emits is green, so it can be ignored.

@aherrmann aherrmann added the merge-queue merge on green CI label Jun 5, 2020
@mergify mergify bot merged commit 98e3fb7 into master Jun 5, 2020
@mergify mergify bot deleted the stack-components branch June 5, 2020 12:48
@mergify mergify bot removed the merge-queue merge on green CI label Jun 5, 2020
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.

3 participants