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

cabal-hooks: Demand rules that produce libraries #10791

Open
alt-romes opened this issue Feb 12, 2025 · 1 comment
Open

cabal-hooks: Demand rules that produce libraries #10791

alt-romes opened this issue Feb 12, 2025 · 1 comment

Comments

@alt-romes
Copy link
Collaborator

Describe the feature request
Currently, Cabal-hooks rules will only be demanded under the following condition, as specified in the RFC:

A rule is considered demanded if:

  • it generates a Haskell module that is declared to be an autogenerated module of the component we are building, or
    another rule that is itself demanded depends on the output of the rule.

[…]

The issue is, as of now, both the specification and implementation will not demand rules that produce libraries (e.g. for extra bundled libs). Originally we were worried about the relative order in which other rules would be run relative to Haskell modules – but libraries don’t matter for those considerations because they will only get included in the last step (the linking invocation).

We should rectify the specification and implementation to accept rules producing libraries, something along the lines of a new bullet like:

  • it generates a static or dynamic library that is declared to be an extra.(static|dynamic|bundled)-library of the component we are building, or
    another rule that is itself demanded depends on the output of the rule.

This came up in the context of a user having trouble with Cabal-hooks in Discourse: https://discourse.haskell.org/t/well-typed-blog-an-introduction-to-cabal-hooks-for-package-authors/11319/10?u=romes

@alt-romes
Copy link
Collaborator Author

Sam pointed out the change should happen in these lines and should be somewhat simple.

    -- Compute demanded rules.
    --
    -- SetupHooks TODO: maybe requiring all generated modules to appear
    -- in autogen-modules is excessive; we can look through all modules instead.
    autogenModPaths =
      map (\m -> moduleNameSymbolicPath m <.> "hs") $
        autogenModules $
          componentBuildInfo $
            targetComponent tgtInfo
    leafRule_maybe (rId, r) =
      if any ((r `ruleOutputsLocation`) . (Location compAutogenDir)) autogenModPaths
        then vertexFromRuleId rId
        else Nothing
    leafRules = mapMaybe leafRule_maybe $ Map.toList allRules
    demandedRuleVerts = Set.fromList $ concatMap (Graph.reachable ruleGraph) leafRules
    nonDemandedRuleVerts = Set.fromList (Graph.vertices ruleGraph) Set.\\ demandedRuleVerts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant