WL#13126: Dynamic linking of Protobuf

Affects: Server-8.0   —   Status: Complete

Protobuf is currently used only by the XPlugin. MySQL developers desire to use
Protobuf outside XPlugin as well. This currently not doable because Protobuf
cannot be statically linked with more than one component due to internal state.
The proposed solution is to make link it dynamically.

The main changes of the worklog are about installation, i.e. where to
put the new libraries when doing 'make install'. For RPM/DEB packages
it is important to *not* install the shared protobuf libraries in a
public directory (i.e. not together with libmysqlclient.so) since the
protobuf libraries are private to the mysql server. For other UNIX
installation layouts, the actual placement isn't really important.

There are no functional changes introduced by the worklog, all changes are
build/install only.

The only visible change is the layout of installation packages.
Current installation packages have libraries, and plugins installed like this:

Public libs (mysqlclient)
-------------------------
RPM: /usr/lib64/mysql/
DEB: /usr/lib/x86_64-linux-gnu/
TAR: lib/

Plugins
-------
RPM: /usr/lib64/mysql/plugin/
DEB: /usr/lib/mysql/plugin/
TAR: lib/plugin/

This worklog adds private shared libraries, like this:

Private libs (should be similar to plugin, not libs)
----------------------------------------------------
RPM: /usr/lib64/mysql/private/
DEB: /usr/lib/mysql/private/
TAR: lib/private/

A new cmake variable called NSTALL_PRIV_LIBDIR is used to control exact location.


As the new protobuf lib will be in private location, loader (e.g. ld-linux.so on
Linux) will not find the libprotobuf.so files without some help.

To guide loader, RPATH with value $ORIGIN/../$INSTALL_PRIV_LIBDIR is added to
mysqld and mysqlxtest.

This works fine for most cases, however when using the Resource Group feature,
mysqld is setsuid and then loader ignores RPATH which contains $ORIGIN.

To overcome this, explicit full path to directory is set in DEB and RPM variants
of mysqld, this is possible due to known target destination. For tarball installs
patching of mysqld with tool like patchelf is required. Instructions to do so
correctly should be added to RG documentation:
  https://dev.mysql.com/doc/refman/8.0/en/resource-groups.html

Router notes:
-------------
For Router libprotobuf.so files are installed into router plugin dir, 
this works at present as it's Router plugins that uses these files.

Router already ships private libs (e.g. libmysqlharness.so) in *public*
locations as /usr/lib64.

Both these problems should be fixed in later changesets.
Shipped protobuf on some platforms:

+--------------+---------+----------------+-----------------+
| OS           | Version | lib            | Devel           |
+--------------+---------+----------------+-----------------+
| EL6          | n/a     | n/a            | n/a             |
| EL7          | 2.5.0   | protobuf       | protobuf-devel  |
| EL8          | 3.5.0   | protobuf       | protobuf-devel  |
| Ubuntu 16.04 | 2.6.1   | libprotobuf9v5 | libprotobuf-dev |
| Ubuntu 18.04 | 3.0.0   | libprotobuf10  | libprotobuf-dev |
| Ubuntu 19.04 | 3.6.1   | libprotobuf17  | libprotobuf-dev |
| SLES 12      | 2.6.1   | libprotobuf9   | protobuf-devel  |
| SLES 15      | 3.5.0   | libprotobuf15  | protobuf-devel  |
| Debian 8     | 2.6.1   | libprotobuf9   | libprotobuf-dev |
| Debian 9     | 3.0.0   | libprotobuf10  | libprotobuf-dev |
| Debian 10    | 3.6.1   | libprotobuf17  | libprotobuf-dev |
| Fedora 28    | 3.5.0   | protobuf       | protobuf-devel  |
| Fedora 29    | 3.5.0   | protobuf       | protobuf-devel  |
| Fedora 30    | 3.6.1   | protobuf       | protobuf-devel  |
| FreeBSD 12   | 3.6.1   | protobuf       | protobuf        |
| Alpine Linux | 3.6.1   | protobuf       | protobuf-dev    |
| Arch Linux   | 3.7.0   | protobuf       | protobuf        |
+--------------+---------+----------------+-----------------+