Skip to content

Commit e0499f0

Browse files
committed
Create a universal build for linux-x64 using the system-provided sasl2 library
1 parent 21aea8c commit e0499f0

File tree

6 files changed

+63
-13
lines changed

6 files changed

+63
-13
lines changed

setup.py

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22

3+
import ctypes.util
34
import os
45
from setuptools import setup
56
from setuptools import Extension
@@ -16,13 +17,44 @@
1617
else:
1718
librdkafka_libname = 'rdkafka'
1819

19-
module = Extension('confluent_kafka.cimpl',
20-
libraries=[librdkafka_libname],
21-
sources=[os.path.join(ext_dir, 'confluent_kafka.c'),
22-
os.path.join(ext_dir, 'Producer.c'),
23-
os.path.join(ext_dir, 'Consumer.c'),
24-
os.path.join(ext_dir, 'Metadata.c'),
25-
os.path.join(ext_dir, 'AdminTypes.c'),
26-
os.path.join(ext_dir, 'Admin.c')])
20+
# Define the default module to build, without external dependencies.
21+
module_defs = [
22+
{
23+
'name': 'confluent_kafka.cimpl.nodeps.cimpl',
24+
'libname': librdkafka_libname,
25+
}
26+
]
2727

28-
setup(ext_modules=[module])
28+
# Check for GSSAPI support and add the appropriate module definitions.
29+
if ctypes.util.find_library('rdkafka_sasl2_2'):
30+
module_defs.append(
31+
{
32+
'name': 'confluent_kafka.cimpl.sasl2_2.cimpl',
33+
'libname': 'rdkafka_sasl2_2',
34+
}
35+
)
36+
if ctypes.util.find_library('rdkafka_sasl2_3'):
37+
module_defs.append(
38+
{
39+
'name': 'confluent_kafka.cimpl.sasl2_3.cimpl',
40+
'libname': 'rdkafka_sasl2_3',
41+
}
42+
)
43+
44+
setup(
45+
ext_modules=[
46+
Extension(
47+
mod_def['name'],
48+
libraries=[mod_def['libname']],
49+
sources=[
50+
os.path.join(ext_dir, 'confluent_kafka.c'),
51+
os.path.join(ext_dir, 'Producer.c'),
52+
os.path.join(ext_dir, 'Consumer.c'),
53+
os.path.join(ext_dir, 'Metadata.c'),
54+
os.path.join(ext_dir, 'AdminTypes.c'),
55+
os.path.join(ext_dir, 'Admin.c'),
56+
],
57+
)
58+
for mod_def in module_defs
59+
]
60+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
try:
2+
from .sasl2_3.cimpl import *
3+
variant = "sasl2_3"
4+
except ImportError:
5+
try:
6+
from .sasl2_2.cimpl import *
7+
variant = "sasl2_2"
8+
except ImportError:
9+
from .nodeps.cimpl import *
10+
variant = "nodeps"

src/confluent_kafka/cimpl/nodeps/__init__.py

Whitespace-only changes.

src/confluent_kafka/cimpl/sasl2_2/__init__.py

Whitespace-only changes.

src/confluent_kafka/cimpl/sasl2_3/__init__.py

Whitespace-only changes.

tools/wheels/install-librdkafka.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,23 @@ ARCH=${ARCH:-x64}
3939

4040
if [[ $OSTYPE == linux* ]]; then
4141
# Linux
42+
LIBDIR=runtimes/linux-$ARCH/native
4243

4344
# Copy the librdkafka build with least dependencies to librdkafka.so.1
4445
if [[ $ARCH == arm64* ]]; then
45-
cp -v runtimes/linux-$ARCH/native/{librdkafka.so,librdkafka.so.1}
46+
cp -v $LIBDIR/{librdkafka.so,librdkafka.so.1}
4647
else
47-
# GR: Include the build with SASL2 support
48-
cp -v runtimes/linux-$ARCH/native/{librdkafka.so,librdkafka.so.1}
48+
cp -v $LIBDIR/{centos8-librdkafka.so,librdkafka.so.1}
49+
# Copy the librdkafka build with sasl2 support to 2 versions:
50+
# librdkafka_sasl2_2.so.1 for debian-based distros
51+
# librdkafka_sasl2_3.so.1 for rpm-based distros
52+
patchelf --set-soname librdkafka_sasl2_2.so.1 --output $LIBDIR/{librdkafka_sasl2_2.so.1,librdkafka.so}
53+
patchelf --replace-needed libsasl2.so.3 libsasl2.so.2 $LIBDIR/librdkafka_sasl2_2.so.1
54+
ln -s librdkafka_sasl2_2.so.1 $LIBDIR/librdkafka_sasl2_2.so
55+
patchelf --set-soname librdkafka_sasl2_3.so.1 --output $LIBDIR/{librdkafka_sasl2_3.so.1,librdkafka.so}
56+
ln -s librdkafka_sasl2_3.so.1 $LIBDIR/librdkafka_sasl2_3.so
4957
fi
50-
ldd runtimes/linux-$ARCH/native/librdkafka.so.1
58+
ldd $LIBDIR/librdkafka.so.1
5159

5260
elif [[ $OSTYPE == darwin* ]]; then
5361
# MacOS X

0 commit comments

Comments
 (0)