From 61a843564de7a4727b9707f205649f848125ba91 Mon Sep 17 00:00:00 2001 From: Michael Catanzaro Date: Wed, 3 Aug 2022 16:58:42 -0500 Subject: [PATCH] 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 62f1c3bc2..f8a71db7d 100644 --- a/docs/reference/glib/building.xml +++ b/docs/reference/glib/building.xml @@ -205,15 +205,10 @@ This is a standard Meson option which specifies how much debugging and optimization to enable. If the build - type starts with debug, + type is debug, G_ENABLE_DEBUG will be defined and GLib will be built - with additional debug code enabled. - - - If the build type is plain, 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 release. + with additional debug code enabled. You can override this behavior using + . diff --git a/meson.build b/meson.build index 1d1122627..ede31b725 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