buildtype not derived from debug and optimization options, with surprising results
- Dominant language
- Python
- Stars
- 6.6k
- Forks
- 1.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 33
Description
The documentation states that the `buildtype` option, when not explicitly provided, is calculated from the `debug` and `buildtype` options:
> For setting optimization levels and toggling debug, you can either set the buildtype option, or you can set the optimization and debug options which give finer control over the same. Whichever you decide to use, the other will be deduced from it. For example, -Dbuildtype=debugoptimized is the same as -Ddebug=true -Doptimization=2 and vice-versa.
However, this is not the case.
To reproduce, configure any Meson project withe `meson setup -Ddebug=false` and run `meson configure` to observe that `buildtype` is still reported as `debug`.
If Meson behavior would be based only on the `debug` and `optimization` options, this would be maybe only a cosmetic issue. However, the `b_vscrt` option default value is `static_from_buildtype`, which, as the name suggests, looks at `buildtype` for deriving which runtime library to link with. This results in `debug=false` builds to be linked with the debug version of the runtime library, unless the `buildype` is also explicitly changed. Another possibly confusing option is `b_ndebug` when set to `if-release`. It results in `-DNDEBUG` being passed to the compiler only when `buildtype` is explicitly set to `release` however I've seen multiple instances where it was believed that `if-release` is synonym with `debug=false`. I think there are other places where `buildtype` may be used for behavior decisions.
This would not be too bad if Meson would not steer users away from using the `buildtype` and either of `debug` and `optimization` options at the same time with a warning: there are instances where just setting `debug` or `optimization` is not enough to obtain the desired behavior.
I think it is already recognized that the `buildtype` concept is flawed and it is kept around for backward compatibility (correct me if I'm wrong) see for example https://github.com/mesonbuild/meson/discussions/10808 (I also remember a blog post from Jussi, but I could be making this up) but we are stuck with it.
I wish that Meson could base all its decision based only on the `debug` and `optimization` flags, converting the `buildtype` option to values for these two when parsing options and then forgetting about it. I don't know if this is feasible. Failing that, the documentation needs some updates (see above the missing translation from `debug` and `optimization` to `buildtype` advertised in the documentation) and needs some more flashy warnings for the foot guns above.
Contributor guide
Research direction
Start by reproducing the issue with `meson setup -Ddebug=false` on a Meson project, then inspect the result from `meson configure`. Trace how `buildtype`, `debug`, `optimization`, `b_vscrt`, and `b_ndebug` interact; the issue names no files or tests. Done requires an agreed behavioral or documentation fix covering the reported inconsistencies.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100