Unable to build on Amazon Linux 2 (it worked with 2.1.1)
matejsp opened this issue · comments
Describe the bug
When trying to build with latest mysqlclient on amazon linux I get:
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC "-Dversion_info=(2, 2, 0, 'final', 0)" -D__version__=2.2.0 -I/usr/include/python3.8 -c src/MySQLdb/_mysql.c -o build/temp.linux-x86_64-cpython-38/src/MySQLdb/_mysql.o -I/usr/include/mysql/ -std=c99
src/MySQLdb/_mysql.c: In function ‘_mysql_ConnectionObject_Initialize’:
src/MySQLdb/_mysql.c:536:13: warning: implicit declaration of function ‘mysql_optionsv’; did you mean ‘mysql_options’? [-Wimplicit-function-declaration]
mysql_optionsv(&(self->connection), MYSQL_OPT_SSL_ENFORCE, (void *)&enforce_tls);
^~~~~~~~~~~~~~
mysql_options
src/MySQLdb/_mysql.c:536:49: error: ‘MYSQL_OPT_SSL_ENFORCE’ undeclared (first use in this function); did you mean ‘MYSQL_OPT_LOCAL_INFILE’?
mysql_optionsv(&(self->connection), MYSQL_OPT_SSL_ENFORCE, (void *)&enforce_tls);
^~~~~~~~~~~~~~~~~~~~~
MYSQL_OPT_LOCAL_INFILE
src/MySQLdb/_mysql.c:536:49: note: each undeclared identifier is reported only once for each function it appears in
/tmp/pip-build-env-33p06j_i/overlay/lib/python3.8/site-packages/setuptools/config/pyprojecttoml.py:66: _BetaConfiguration: Support for `[tool.setuptools]` in `pyproject.toml` is still *beta*.
config = read_configuration(filepath, True, ignore_option_errors, dist)
error: command '/usr/bin/gcc' failed with exit code 1
----------------------------------------
ERROR: Failed building wheel for mysqlclient
Even after changing the header file and commenting out:
sed -i 's/#define MARIADB_BASE_VERSION "mariadb-5.5"///#define MARIADB_BASE_VERSION "mariadb-5.5"/g' /usr/include/mysql/mysql_version.h
I get then
CE -fPIC -fwrapv -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC "-Dversion_info=(2, 2, 0, 'final', 0)" -D__version__=2.2.0 -I/source/python38x86_64al2/include -I/usr/include/python3.8 -c src/MySQLdb/_mysql.c -o build/temp.linux-x86_64-cpython-38/src/MySQLdb/_mysql.o -I/usr/include/mysql/ -std=c99
src/MySQLdb/_mysql.c: In function ‘_mysql_ConnectionObject_Initialize’:
src/MySQLdb/_mysql.c:528:44: error: ‘MYSQL_OPT_SSL_MODE’ undeclared (first use in this function); did you mean ‘MYSQL_OPT_NONBLOCK’?
mysql_options(&(self->connection), MYSQL_OPT_SSL_MODE, &ssl_mode_num);
^~~~~~~~~~~~~~~~~~
MYSQL_OPT_NONBLOCK
src/MySQLdb/_mysql.c:528:44: note: each undeclared identifier is reported only once for each function it appears in
/tmp/pip-build-env-a_qs8ndy/overlay/lib/python3.8/site-packages/setuptools/config/pyprojecttoml.py:108: _BetaConfiguration: Support for `[tool.setuptools]` in `pyproject.toml` is still *beta*.
warnings.warn(msg, _BetaConfiguration)
error: command '/usr/bin/gcc' failed with exit code 1
[end of output]
Environment
Amazon Linux 2
MariaDB 5.5.
How did you install libmysqlclient libraries?
No response
What version of mysqlclient do you use?
No response
Docker command to start MySQL server
docker run -it amazonlinux:2 bash
> amazon-linux-extras install python3.8
> yum install mariadb-devel gcc python38-devel
> pip3.8 install wheel
> pip3.8 install mysqlclient==2.2.0
Minimum but complete code to reproduce
# Write Python code here.
import MySQLdb
conn = MySQLdb.connect(host='127.0.0.1', port=3306, user='root')
...
Schema and initial data required to reproduce.
-- Write SQL here.
-- e.g. CREATE TABLE ...
Commands, and any other step required to reproduce your issue.
amazon-linux-extras install python3.8
yum install mariadb-devel gcc python38-devel
pip3.8 install wheel
pip3.8 install mysqlclient==2.2.0
I have prepared a patch that checks if MYSQL_OPT_SSL_ENFORCE is defined otherwise it falls back to old 2.1.1 behaviour.
bash-4.2# git diff
diff --git a/src/MySQLdb/_mysql.c b/src/MySQLdb/_mysql.c
index cc41977..b27299c 100644
--- a/src/MySQLdb/_mysql.c
+++ b/src/MySQLdb/_mysql.c
@@ -476,10 +476,15 @@ _mysql_ConnectionObject_Initialize(
_stringsuck(cipher, value, ssl);
}
if (ssl_mode) {
+#if defined(MYSQL_OPT_SSL_MODE) || defined(MYSQL_OPT_SSL_ENFORCE)
if ((ssl_mode_num = _get_ssl_mode_num(ssl_mode)) <= 0) {
PyErr_SetString(_mysql_NotSupportedError, "Unknown ssl_mode specification");
return -1;
}
+#else
+ PyErr_SetString(_mysql_NotSupportedError, "MySQL client library does not support ssl_mode specification");
+ return -1;
+#endif
}
conn = mysql_init(&(self->connection));
@@ -526,7 +531,7 @@ _mysql_ConnectionObject_Initialize(
if (ssl_mode) {
#ifdef HAVE_ENUM_MYSQL_OPT_SSL_MODE
mysql_options(&(self->connection), MYSQL_OPT_SSL_MODE, &ssl_mode_num);
-#else
+#elif defined(MYSQL_OPT_SSL_ENFORCE)
// MariaDB doesn't support MYSQL_OPT_SSL_MODE.
// See https://github.com/PyMySQL/mysqlclient/issues/474
// TODO: Does MariaDB supports PREFERRED and VERIFY_CA?
bash-4.2# pip3.8 wheel .
Processing /root/tmp/mysqlclient
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing wheel metadata ... done
Building wheels for collected packages: mysqlclient
Building wheel for mysqlclient (PEP 517) ... done
Created wheel for mysqlclient: filename=mysqlclient-2.2.0-cp38-cp38-linux_x86_64.whl size=120205 sha256=38d85ff1fd6e67f3ae3a360a8c373f87351326f12b86cf1ebc8c2f0ab0c80a4c
Stored in directory: /tmp/pip-ephem-wheel-cache-px5jugoj/wheels/0b/66/a1/8893aba11a58f544b4257ff10dd21ea0eda6172df97a51299d
Successfully built mysqlclient
bash-4.2#
Duplicate of #627.
I understand that it is not supported upstream. If I prepare PR would you accept it ? since it is such a simple fix to get it running? We are stuck on AL2 for time being and upstream support is https://endoflife.date/amazon-linux (2025).
I can prepare a PR if you would be willing to accept it?
No. I don't increase code that I can not maintain.
User need to install newer client library, or keep old mysqlclient version.