Bug #100397 MySQL 5.7.31 doesn't use bundled libevent when we don't find libevent of system
Submitted: 31 Jul 2020 8:01 Modified: 4 Aug 2020 1:07
Reporter: Yasuhiro Horimoto Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:5.7.31 OS:Ubuntu (18.04)
Assigned to: CPU Architecture:x86

[31 Jul 2020 8:01] Yasuhiro Horimoto
Description:
If we build MySQL 5.7.31 from source, MySQL occurs a below error.

In file included from /<<PKGBUILDDIR>>/./mysql-5.7.31/libbinlogevents/include/table_id.h:31:0,
                 from /<<PKGBUILDDIR>>/./mysql-5.7.31/sql/table.h:37,
                 from /<<PKGBUILDDIR>>/./mysql-5.7.31/sql/field.h:37,
                 from /<<PKGBUILDDIR>>/./mysql-5.7.31/sql/protocol_classic.h:27,
                 from /<<PKGBUILDDIR>>/./mysql-5.7.31/sql/sql_class.h:40,
                 from ../mrn_mysql.h:58,
                 from mrn_path_mapper.cpp:22:
/<<PKGBUILDDIR>>/./mysql-5.7.31/libbinlogevents/include/wrapper_functions.h:35:10: fatal error: binlog_config.h: No such file or directory
 #include "binlog_config.h"
          ^~~~~~~~~~~~~~~~~
This error occurs when the libevent-dev package doesn't install in our system.

CMake options when we build are as below.

	cmake -DCMAKE_INSTALL_PREFIX=/usr \
	-DCMAKE_VERBOSE_MAKEFILE=ON \
	-DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock \
	-DCMAKE_BUILD_TYPE=RelWithDebInfo \
	-DBUILD_CONFIG=mysql_release \
	-DWITH_LIBWRAP=ON \
	-DWITH_ZLIB=system \
	-DWITH_LZ4=system \
	-DWITH_EDITLINE=system \
	-DWITH_LIBEVENT=system \
	-DWITH_BOOST=../boost \
	-DCOMPILATION_COMMENT="(Ubuntu)" \
	-DMYSQL_SERVER_SUFFIX="-0ubuntu0.18.04.1" \
	-DINSTALL_LAYOUT=DEB \
	-DINSTALL_DOCDIR=share/mysql/docs \
	-DINSTALL_DOCREADMEDIR=share/mysql \
	-DINSTALL_INCLUDEDIR=include/mysql \
	-DINSTALL_INFODIR=share/mysql/docs \
	-DINSTALL_LIBDIR=lib/x86_64-linux-gnu \
	-DINSTALL_MANDIR=share/man \
	-DINSTALL_MYSQLSHAREDIR=share/mysql \
	-DINSTALL_MYSQLTESTDIR=lib/mysql-test \
	-DINSTALL_PLUGINDIR=lib/mysql/plugin \
	-DINSTALL_SBINDIR=sbin \
	-DINSTALL_SCRIPTDIR=bin \
	-DINSTALL_SUPPORTFILESDIR=share/mysql \
	-DSYSCONFDIR=/etc/mysql \
	-DWITH_EMBEDDED_SERVER=ON \
	-DWITH_ARCHIVE_STORAGE_ENGINE=ON \
	-DWITH_BLACKHOLE_STORAGE_ENGINE=ON \
	-DWITH_FEDERATED_STORAGE_ENGINE=ON \
	-DWITH_INNODB_MEMCACHED=1 \
	-DWITH_EXTRA_CHARSETS=all ..'

We specify "system" in "-DWITH_EDITLINE" option.
However, the reference manual is explained as below about if we specify "system" in  "-DWITH_EDITLINE".

"If the system library is not found, the bundled libevent library is used."

https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html#option_cmake_wit...

In fact, If the system library is not found, the bundled libevent library isn't used.

We also understand from the following source code that the bundled libevent library isn't used.

https://github.com/mysql/mysql-server/blob/5.7/cmake/libevent.cmake#L116-L125

Is this a bug? Or are we just not updating the reference manual?

This modification is pushed by the following commit.

https://github.com/mysql/mysql-server/commit/4b17b700a97d5baf8a9f9fba3fd362c6a44f4458

The above commit includes the following commit. 

https://github.com/mysql/mysql-server/commit/c3263859219f54cce9153d9cb550e2158ddcf816

How to repeat:
1.
wget http://security.ubuntu.com/ubuntu/pool/main/m/mysql-5.7/mysql-5.7_5.7.31.orig.tar.gz

2.
tar -zxvf mysql-5.7_5.7.31.orig.tar.gz

3.
cd mysql-5.7.31

4.
cmake -DCMAKE_INSTALL_PREFIX=/usr \
	-DCMAKE_VERBOSE_MAKEFILE=ON \
	-DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock \
	-DCMAKE_BUILD_TYPE=RelWithDebInfo \
	-DBUILD_CONFIG=mysql_release \
	-DWITH_LIBWRAP=ON \
	-DWITH_ZLIB=system \
	-DWITH_LZ4=system \
	-DWITH_EDITLINE=system \
	-DWITH_LIBEVENT=system \
	-DWITH_BOOST=../boost \
	-DCOMPILATION_COMMENT="(Ubuntu)" \
	-DMYSQL_SERVER_SUFFIX="-0ubuntu0.18.04.1" \
	-DINSTALL_LAYOUT=DEB \
	-DINSTALL_DOCDIR=share/mysql/docs \
	-DINSTALL_DOCREADMEDIR=share/mysql \
	-DINSTALL_INCLUDEDIR=include/mysql \
	-DINSTALL_INFODIR=share/mysql/docs \
	-DINSTALL_LIBDIR=lib/x86_64-linux-gnu \
	-DINSTALL_MANDIR=share/man \
	-DINSTALL_MYSQLSHAREDIR=share/mysql \
	-DINSTALL_MYSQLTESTDIR=lib/mysql-test \
	-DINSTALL_PLUGINDIR=lib/mysql/plugin \
	-DINSTALL_SBINDIR=sbin \
	-DINSTALL_SCRIPTDIR=bin \
	-DINSTALL_SUPPORTFILESDIR=share/mysql \
	-DSYSCONFDIR=/etc/mysql \
	-DWITH_EMBEDDED_SERVER=ON \
	-DWITH_ARCHIVE_STORAGE_ENGINE=ON \
	-DWITH_BLACKHOLE_STORAGE_ENGINE=ON \
	-DWITH_FEDERATED_STORAGE_ENGINE=ON \
	-DWITH_INNODB_MEMCACHED=1 \
	-DWITH_EXTRA_CHARSETS=all .

Suggested fix:
We suggest that we use "MYSQL_USE_BUNDLED_LIBEVENT" as below.

  IF(WITH_LIBEVENT STREQUAL "bundled")
    MYSQL_USE_BUNDLED_LIBEVENT()
  ELSEIF(WITH_LIBEVENT STREQUAL "system")
    FIND_SYSTEM_LIBEVENT()
    IF(NOT LIBEVENT_FOUND)
      MESSAGE(SEND_ERROR "Cannot find appropriate system libraries for libevent. Use bundled libevent")
      MYSQL_USE_BUNDLED_LIBEVENT()
    ENDIF()
  ELSE()
    MESSAGE(FATAL_ERROR "WITH_LIBEVENT must be bundled or system")
  ENDIF()
[3 Aug 2020 9:11] Tor Didriksen
There is some confusion in the bug report, mixing EDITLINE and LIBEVENT.
I assume it is LIBEVENT which causes problems. Building on a host without system libevent, I get:
CMake Error at cmake/libevent.cmake:121 (MESSAGE):
  Cannot find system libevent libraries.
Call Stack (most recent call first):
  CMakeLists.txt:584 (MYSQL_CHECK_LIBEVENT)

Which is the desired behaviour. Silent fallback to "bundled" is simply wrong: any non-interactive build would then be building something else than what was requested. And even in an interactive build, I doubt anyone would notice any cmake message like "choosing bundled, rather than system, libevent"

So the build should break at configure-time when a system library is missing. We could have been slightly more user friendly though, and output the name of the package which is missing: libevent-devel on my desktop, probably something else on other Linux variants.

As for the missing generated header file: you cannot expect to be able to build anything if the configure stage fails.
[4 Aug 2020 1:07] Yasuhiro Horimoto
> There is some confusion in the bug report, mixing EDITLINE and LIBEVENT.

Ah... I'm sorry. This is a typo.
It’s just as you said. it is LIBEVENT which causes problems.

> Which is the desired behaviour. Silent fallback to "bundled" is simply wrong: any non-interactive build would then be building something else than what was requested. And even in an interactive build, I doubt anyone would notice any cmake message like "choosing bundled, rather than system, libevent"

I see.
I understand that this is not a bug.

Thank you very much for your comment.
[4 Aug 2020 19:52] Jon Stephens
See BUG#100417, BUG#98679.