Skip to content

Allow pre-build rules to generate autogen extra sources files#11573

Open
sheaf wants to merge 2 commits into
haskell:masterfrom
sheaf:hooks-extra-sources
Open

Allow pre-build rules to generate autogen extra sources files#11573
sheaf wants to merge 2 commits into
haskell:masterfrom
sheaf:hooks-extra-sources

Conversation

@sheaf
Copy link
Copy Markdown
Collaborator

@sheaf sheaf commented Mar 4, 2026

This PR fixes #11607 and #10791, making it possible to write pre-build rules that generate files other
than Haskell files: non-Haskell source files and extra library files.

Because there is no counterpart to autogen-modules for non-Haskell source
files, authors of pre-build rules will need to proceed in two steps:

  1. In a per-component pre-configure hook, the files the author desires to generate
    must be added to the relevant fields, e.g. the cSources field of BuildInfo.

    These files must be relative to autogenCompModulesDir.

  2. Pre-build rules generating these files will now be demanded. This avoids
    getting an error message "The following pre-build rules are not demanded
    and will not be run".

Note that include files (such as .h files) are a bit different: any files
listed under includes/autogen-includes are required at configure time.
This gives SetupHooks authors two choices: either list the include files in
autogen-includes but generate them in a pre-configure hook, or don't list them
there and generate them in a pre-build rule, relying on the files getting picked
up from included directories (this may be brittle).


Template Α: This PR modifies behaviour or interface

@sheaf sheaf force-pushed the hooks-extra-sources branch 3 times, most recently from 91b3755 to 3b46b10 Compare March 12, 2026 12:03
@sheaf sheaf marked this pull request as ready for review March 12, 2026 12:04
@sheaf sheaf changed the title WIP: improve support for .c/.h files in pre-build rules Allow pre-build rules to generate autogen extra sources files Mar 12, 2026
@sheaf sheaf marked this pull request as draft March 26, 2026 10:05
@sheaf sheaf force-pushed the hooks-extra-sources branch 4 times, most recently from 5169edc to 78d6613 Compare May 5, 2026 11:43
@sheaf sheaf marked this pull request as ready for review May 5, 2026 11:44
@sheaf sheaf force-pushed the hooks-extra-sources branch from 78d6613 to 4548738 Compare May 15, 2026 14:01
Comment thread Cabal/src/Distribution/Simple/SetupHooks/Internal.hs Outdated
Comment thread Cabal-syntax/src/Distribution/Utils/Path.hs
Comment thread Cabal/src/Distribution/Simple/SetupHooks/Internal.hs
Comment thread Cabal/src/Distribution/Simple/SetupHooks/Internal.hs Outdated
@sheaf sheaf force-pushed the hooks-extra-sources branch from 4548738 to 00ab6d5 Compare May 27, 2026 12:59
With this commit, the SetupHooks API now considers all extra source
files placed in the autogen directory for the component to be additional
demands on pre-build rules.

For example, a pre-build rule that generates a C or JavaScript source
file (putting it in the appropriate autogen module for the component)
will now be run, while it used to not be run before (as it used to be
considered "not demanded").

In addition, 'extra-bundled-libraries' also add demands. Any file in the
autogenerated directory for the component whose name matches with a
library name specified in 'extra-bundled-libraries' (ignoring file
extension) will provide a rule demand.

Fixes haskell#10791
Fixes haskell#11607
@sheaf sheaf force-pushed the hooks-extra-sources branch 3 times, most recently from 32a772c to 0a10884 Compare May 27, 2026 16:16
@sheaf sheaf force-pushed the hooks-extra-sources branch from 0a10884 to 3d6cb13 Compare May 27, 2026 16:22
@sheaf sheaf added merge me Tell Mergify Bot to merge and removed attention: needs-review labels May 27, 2026
@mergify mergify Bot added the ready and waiting Mergify is waiting out the cooldown period label May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge me Tell Mergify Bot to merge ready and waiting Mergify is waiting out the cooldown period

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow pre-build rules to generate extra source files

3 participants