Always set private code when generating code from wayland protocols

David Redondo kde at david-redondo.de
Wed Aug 14 15:57:51 BST 2024


Hi,

you may have seen me pushing changes specifying specifying PRIVATE_CODE for 
CMake functions that generate code from wayland protocols xml sources. 
I failed to explain why that's recommended and why you should do so as well.
This serves both as an explanation and a heads up:
If you look at wayland-scanner usage notes it states:

>  wayland-scanner --help usage: wayland-scanner [OPTION] [client-header|
server-header|private-code|public-code] [input_file output_file] 
>  Converts XML protocol descriptions supplied on stdin or input file to 
client headers, server headers, or protocol marshalling code.  
>  Use "public-code" only if the marshalling code will be public - aka DSO 
will export it while other components will be using it.
>  Using "private-code" is strongly recommended

In practice if public-code is used the wl_interface defintions are exported 
from the shared. This is problematic if another shared library or plugin
also exports these symbols but of a different protocol version: The one that 
the linker ends up choosing is out of our control. If the definition of an
older protocol version wins the program will be terminated sooner or later
if it encounters something from the newer version which it didn't expect.

This is not only a theoretical concern, we hit this problem on some distros
around 6.0 release, Kwin was affected on Debian last month, and 
QtWaylandCompositor also hit this last week. Which prompted us to add the 
possibility to specify private-code everywhere and do so:

- qt_generate_wayland_protocol_client_sources and  
  qt_generate_wayland_protocol_server_sources accept a PRIVATE_CODE option 
starting with Qt 6.8 (and PUBLIC_CODE for symmetry, which is the default)
- ecm_add_wayland_client_protocol accepts PRIVATE_CODE since 6.5
- ecm_add_wayland_server_protocol, ecm_add_qtwayland_client_protocol and
  ecm_add_qtwayland_server_protocol will accept PRIVATE_CODE starting with 6.6

Why not make PRIVATE_CODE the default?
To preserve backwards compatibility. In the past wayland-scanner only
had a 'code' option which was deprecated but also exported the interface 
definitions. So public-code was chosen in ECM and Qt to preserve
backwards compatibility.

David




More information about the kde-devel mailing list