[glib/mcatanzaro/build-best-practices] Improve default value of glib_debug option
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/mcatanzaro/build-best-practices] Improve default value of glib_debug option
- Date: Wed, 3 Aug 2022 22:05:00 +0000 (UTC)
commit 19fc76f53f7d56a5f51808ee8bdc1cb3a70df1bf
Author: Michael Catanzaro <mcatanzaro redhat com>
Date: Wed Aug 3 16:58:42 2022 -0500
Improve default value of glib_debug option
glib_debug is an auto option. This is clever because it allows us to
guess the best default based on the build type, while also allowing an
easy way to override if the guess is not good. Sadly, the attempt to
guess based on the build type does not work well. For example, it
considers debugoptimized builds to be debug builds, but despite the
name, it is definitely a release build type (except on Windows, which
we'll ignore here). The minsize build type has the exact same problem.
The debug option is true for both build types, but this only controls
whether debuginfo is enabled, not whether debug extras are enabled.
The plain build type has a different problem: debug is off, but the
optimization option is off too, even though plain builds are distro
builds are will almost always use optimization.
I've outlined an argument for why we should make these changes here:
https://blogs.gnome.org/mcatanzaro/2022/07/15/best-practices-for-build-options/
Specifically, Rule #4 shows all the build types and whether they
correspond to release builds or debug builds. Rule #6 argues that we
should provide good defaults for plain builds.
docs/reference/glib/building.xml | 11 +++--------
meson.build | 8 +++++---
2 files changed, 8 insertions(+), 11 deletions(-)
---
diff --git a/docs/reference/glib/building.xml b/docs/reference/glib/building.xml
index 62f1c3bc23..f8a71db7d6 100644
--- a/docs/reference/glib/building.xml
+++ b/docs/reference/glib/building.xml
@@ -205,15 +205,10 @@
<para>
This is a standard <application>Meson</application> option which
specifies how much debugging and optimization to enable. If the build
- type starts with <literal>debug</literal>,
+ type is <literal>debug</literal>,
<literal>G_ENABLE_DEBUG</literal> will be defined and GLib will be built
- with additional debug code enabled.
- </para>
- <para>
- If the build type is <literal>plain</literal>, GLib will not enable any
- optimization or debug options by default, and will leave it entirely to
- the user to choose their options. To build with the options recommended
- by GLib developers, choose <literal>release</literal>.
+ with additional debug code enabled. You can override this behavior using
+ <option>-Dglib_debug</option>.
</para>
</formalpara>
diff --git a/meson.build b/meson.build
index 1d11226270..ede31b7259 100644
--- a/meson.build
+++ b/meson.build
@@ -294,13 +294,15 @@ elif vs_crt_opt == 'from_buildtype'
endif
# Use debug/optimization flags to determine whether to enable debug or disable
-# cast checks
+# cast checks. We have a non-production (debug) build if debug is true and if
+# optimization is 0 or g; otherwise, we have a production build.
glib_debug_cflags = []
glib_debug = get_option('glib_debug')
-if glib_debug.enabled() or (glib_debug.auto() and get_option('debug'))
+optimized_build = get_option('optimization') not in [ '0', 'g' ]
+if glib_debug.enabled() or (glib_debug.auto() and get_option('debug') and not optimized_build)
glib_debug_cflags += ['-DG_ENABLE_DEBUG']
message('Enabling various debug infrastructure')
-elif get_option('optimization') in ['2', '3', 's']
+elif optimized_build
glib_debug_cflags += ['-DG_DISABLE_CAST_CHECKS']
message('Disabling cast checks')
endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]