mesonbuild / mesonbuild/meson

Feature request: add 'extra_depends' option to executable

Open
#8,034 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
6.6k
Forks
1.9k
Avg merge
2d 6h
Merged PRs (30d)
33

Description

Source module in D language generated by `custom_target` can be passed to `executable` directly for compilation.

However, if another module imports the generated module, there is a race between the `custom_target` code generation and the other file compilation, because the dependency relationship is not established between both.

Consider the following, where `app.d` imports `gen.d`:

```meson
gen_src = custom_target('gen.d', output: 'gen.d' ...)
app = executable('app', ['app.d', gen_src], ...)
```
The compiler can start compiling `app.d`, even though `gen.d` is not finialized.

My proposal would be as follow:
```meson
gen_src = custom_target('gen.d', output: 'gen.d' ...)
app = executable('app', ['app.d', gen_src], extra_depends: gen_src ...)
```
In that case, a dependency is introduced between `gen_src`'s target and **all** object files of the compiled executable.
As a result, ninja waits that the generation of `gen.d` is finalized before starting the compilation of `app.d`.

Custom dependency specification is somewhat a very generic thing for a build tool. I'm sure it can serve many other purposes than this one.

Contributor guide

Open the contributing guide

Research direction

Start from the custom_target and executable entry points, then trace how target dependencies are represented and emitted to Ninja. Define done as an extra_depends option that makes the executable's generated dependency wait before compiling all object files, and add coverage for the demonstrated generated-module race.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.