Skip to content

Build Hooks & Build Lifecycle

Work-in-Progress Documentation

The content on this page is not yet fully finished.

Tracking issue: https://github.com/WebFreak001/dub-docs-v2/issues/14

Recipe Build Commands

Order of build commands in the general case:

  1. preGenerateCommands
    • dub.json/dub.sdl may be reevaluated - currently only folders are re-listed for settings such as sourceFiles, the recipe is not reparsed, so nothing else is updated yet (see DUB#2666)
    • reevaluation of the recipe will not happen if a dependency touches any other already-loaded recipe
  2. if re-build is triggered:
    1. preBuildCommands
    2. compiler running
    3. postBuildCommands
  3. postGenerateCommands
  4. if run or test is triggered:
    1. preRunCommands
    2. app or test running
    3. postRunCommands

Injecting compilation files into dependent projects

targetType "sourceLibrary"

Recipe details

This section details values for a DUB recipe setting.

For syntax, see build settings

This target type does not generate a binary, but rather forces dub to add all source files directly to the same compiler invocation as the dependent project.

This means all the D files within this project act like they have been copy-pasted into the dependent project, with sourceFiles matching them.

Warning

Project defined compiler flags and build settings may not apply to these files, caution is needed and application tests and unittests should be written to ensure correctness.

You may want to use this in a variety of cases:

  • small libraries may work better this way, especially if they are entirely templates (generated object files will be empty in that case)
  • you need access to the project that depends on this project
    • this may be used to implement patterns such as Inversion of Control on a per-file basis
    • however this may also cause anti-patterns, making dependencies hard to understand and reason about

injectSourceFiles

Recipe details

This section details values for a DUB recipe setting.

For syntax, see build settings

WIP synposis: check build settings for example - this works like targetType "sourceLibrary", but only for specific files. The primary reason why this was added by the original PR author was for dynamic libraries to register themselves automatically in some loader in the host application. Use-cases extend beyond that however.

TODO: need to document how this works with dependencies of dependencies

TODO: need to document if there is any use-case paired with targetType "sourceLibrary"


Last update: August 5, 2023
Created: August 5, 2022