Bug 278858

Summary: [GTK] [2.45.91] Fails to build in armhf: expected identifier before numeric constant
Product: WebKit Reporter: Alberto Garcia <berto>
Component: WebKitGTKAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: bugs-noreply, cgarcia, dpino, mcatanzaro
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch none

Description Alberto Garcia 2024-08-29 07:46:39 PDT
This is the error message:

In file included from /usr/include/X11/Xlib.h:44,
                 from Source/WebKit/UIProcess/gtk/PointerLockManagerX11.cpp:32:
build-soup3/bmalloc/Headers/bmalloc/EligibilityResult.h:35:5: error: expected identifier before numeric constant
   35 |     Success,
      |     ^~~~~~~
build-soup3/bmalloc/Headers/bmalloc/EligibilityResult.h:35:5: error: expected ‘}’ before numeric constant


I think that the 'Success' macro in X11/X.h conflicts with the same value in the EligibilityKind enum:

https://gitlab.freedesktop.org/xorg/proto/xorgproto/-/blob/xorgproto-2024.1/include/X11/X.h?ref_type=tags#L350

https://github.com/WebKit/WebKit/blob/webkitgtk-2.45.91/Source/bmalloc/bmalloc/EligibilityResult.h#L35

I haven't investigated yet why this is not happening in other architectures.
Comment 1 Alberto Garcia 2024-08-30 06:58:52 PDT
FWIW I can work around this by using the system malloc in this build.
Comment 2 Alberto Garcia 2024-09-19 07:43:15 PDT
Disabling bmalloc seems to be causing problems on armhf, see bug 279883

I managed to fix the build by changing the order of the Xlib.h include, but I still haven't checked why other architectures are not affected:

--- a/Source/WebKit/UIProcess/gtk/PointerLockManagerX11.cpp
+++ b/Source/WebKit/UIProcess/gtk/PointerLockManagerX11.cpp
@@ -29,10 +29,10 @@
 #if PLATFORM(X11)
 
 #include "WebPageProxy.h"
-#include <X11/Xlib.h>
 #include <gtk/gtk.h>
 #include <wtf/TZoneMallocInlines.h>
 #include <wtf/glib/GRefPtr.h>
+#include <X11/Xlib.h>
 
 #if USE(GTK4)
 #include <gdk/x11/gdkx.h>
Comment 3 Alberto Garcia 2024-09-19 08:01:21 PDT
And this is almost certainly the commit that introduced this build failure:

https://commits.webkit.org/282294@main

(the changes to PointerLockManagerX11.cpp)
Comment 4 Diego Pino 2024-09-29 23:44:49 PDT
This a common error that happens when a header defining 'Success' collides with 'Xlib.h', which includes 'X11/X.h' which defines Success.
 
One way of solving is undefining 'Success' before including 'Xlib.h':

```
#ifdef Success
#undef Success
#endif
```

Another way of solving it is by adding the .c source file that triggers the inclusion of headers until the collide happens as no-unify. In this case, the file would be 'UIProcess/gtk/PointerLockManagerX11.cpp', but that file is already marked as no-unify: https://github.com/webkit/webkit/blob/main/Source/WebKit/SourcesGTK.txt#L283, so this solution won't work in your case.

It seems that right now there's no code in WebKit codebase that uses the former solution (undefining Success). So, if rearranging the order of the header fixes the issue I would go for that solution. Perhaps adding a comment explaining why 'Xlib.h' has to go after 'TZoneMallocInlines.h'.
Comment 5 Alberto Garcia 2024-10-23 03:30:46 PDT
Created attachment 473016 [details]
Patch

FYI this is the patch that I'm using downstream in Debian, I don't have time to create a merge request right now but feel free to take this patch if you think it's appropriate.