[webkit-gtk] glib-mkenums and preprocessor conditionals

jralls at ceridwen.fremont.ca.us jralls at ceridwen.fremont.ca.us
Sun May 28 08:30:17 PDT 2023


Hi all,

I'm trying to get the current main 0ee37c4333 to build for Gtk3 on macOS using ninja and clang. It's failing because  glib-mkenums (version 2.77.0 ignores preprocessor conditionals. For example 
#if ENABLE(2022_GLIB_API)
typedef enum {
/*…*/
} WebKitWebsiteDataTypes;
#else
typedef enum {
/*…*/
} WebKitWebsiteDataTypes;
#endif
in Source/WebKit/UIProcess/API/glib/WebKitWebsiteData.h.in line 34.
Since that's a template glib-mkenums correctly writes the whole thing into ${CMAKE_BUILD_DIR}/WebKit/DerivedSources/WebKitWebsiteData.h, but that's passed as a header input in a second call with the result
// Enumerations from /Users/john/Development/gtk-build/gtk-unstable-11-arm64/build/WebKit/WebKitGTK/DerivedSources/webkit/WebKitWebsiteData.h.
GType webkit_website_data_types_get_type()
{
    static const GFlagsValue values[] = {
        { WEBKIT_WEBSITE_DATA_MEMORY_CACHE, "WEBKIT_WEBSITE_DATA_MEMORY_CACHE", "memory-cache" },
/*…*/
        { 0, NULL, NULL }
    };

    static GType type = 0;
    if (G_UNLIKELY(!type))
        type = g_flags_register_static("WebKitWebsiteDataTypes", values);

    return type;
}
GType webkit_website_data_types_get_type()
{
    static const GFlagsValue values[] = {
        { WEBKIT_WEBSITE_DATA_MEMORY_CACHE, "WEBKIT_WEBSITE_DATA_MEMORY_CACHE", "memory-cache" },
/*…*/
        { 0, NULL, NULL }
    };

    static GType type = 0;
    if (G_UNLIKELY(!type))
        type = g_flags_register_static("WebKitWebsiteDataTypes", values);

    return type;
}

in ${CMAKE_BUILD_DIR}/WebKit/WebKitGTK/DerivedSources/webkit/WebKitEnumTypes.cpp. Compiling that fails with error: redefinition of 'webkit_website_data_types_get_type'.
Another example:
#if ENABLE(2022_GLIB_API)
#define WEBKIT_MEDIA_ERROR               webkit_media_error_quark ()
#endif
#if ENABLE(2022_GLIB_API)
/**
 * WebKitMediaError:
 * @WEBKIT_MEDIA_ERROR_WILL_HANDLE_LOAD: Preliminary load failure for media content types. A new load will be started to perform the media load. Since: 2.40
 *
 * Enum values used to denote the various media errors.
 *
 * Since: 2.40
 */
typedef enum {
    WEBKIT_MEDIA_ERROR_WILL_HANDLE_LOAD = 204
} WebKitMediaError;
#endif
in Source/WebKit/UIProcess/API/glib/WebKitError.h.in
turns into

WEBKIT_API GType
webkit_user_content_filter_error_get_type (void);
#define WEBKIT_TYPE_MEDIA_ERROR webkit_media_error_get_type ()

in WebKitGTK/DerivedSources/webkit/WebKitEnumTypes.h and
GType webkit_media_error_get_type()
{
    static const GEnumValue values[] = {
        { WEBKIT_MEDIA_ERROR_WILL_HANDLE_LOAD, "WEBKIT_MEDIA_ERROR_WILL_HANDLE_LOAD", "load" },
        { 0, NULL, NULL }
    };

    static GType type = 0;
    if (G_UNLIKELY(!type))
        type = g_enum_register_static("WebKitMediaError", values);

    return type;
}
in WebKitGTK/DerivedSources/webkit/WebKitEnumTypes.cpp producing error: use of undeclared identifier 'WEBKIT_MEDIA_ERROR_WILL_HANDLE_LOAD'; did you mean 'WEBKIT_PLUGIN_ERROR_WILL_HANDLE_LOAD'.

This looks suspiciously like https://gitlab.gnome.org/GNOME/glib/-/issues/744, which has been ignored since Behdad filed it in 2013, before the python migration.

It was introduced in https://github.com/WebKit/WebKit/commit/bd6aa66739fa6820fab57aab174d141f6bb67894#diff-e5d9b39e6fe26871de083fee45056778d1d58eba76206cf3691bdf2fde4bb649 that points to https://bugs.webkit.org/show_bug.cgi?id=249476. There's some discussion there about a WPE build issue there on a clean build, but there doesn't seem to be any resolution. I'm puzzled by why the first case would build with or without ENABLE(2022_GLIB_API) so I wonder if there's some dfference between your CI builds and what I'm doing.

Regards,
John Ralls

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-gtk/attachments/20230528/18123059/attachment.htm>


More information about the webkit-gtk mailing list