Skip to content

Commit

Permalink
Fix X32 build (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-lb authored Oct 25, 2024
1 parent 6c1a72c commit 3cdcdf5
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 96 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ jobs:
librdkafka: 'v1.9.2'
memcheck: '1'

# X32
- php: '8.3.0'
librdkafka: 'v2.6.0'
arch: 'X32'

# Latest librdkafka 2.x
- php: '8.3.0'
librdkafka: 'v2.3.0'
Expand Down Expand Up @@ -172,6 +177,7 @@ jobs:
SKIP_OAUTH: ${{ matrix.skipoauth }}
TEST_KAFKA_BROKERS: kafka:9092
TEST_KAFKA_BROKER_VERSION: 2.6
ARCH: ${{ matrix.arch }}
steps:
- name: 'Check out repository'
uses: 'actions/checkout@v2'
Expand All @@ -181,12 +187,15 @@ jobs:
- uses: actions/cache@v2
with:
path: ~/build-cache/php
key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.memcheck }}
key: ${{ runner.os }}-${{ matrix.arch }}-${{ matrix.php }}-${{ matrix.memcheck }}

- uses: actions/cache@v2
with:
path: ~/build-cache/librdkafka
key: ${{ runner.os }}-${{ matrix.librdkafka }}
key: ${{ runner.os }}-${{ matrix.arch }}-${{ matrix.librdkafka }}

- name: 'Install dependencies'
run: './php-rdkafka/.github/workflows/test/install-dependencies.sh'

- name: 'Build librdkafka'
run: './php-rdkafka/.github/workflows/test/build-librdkafka.sh'
Expand Down
16 changes: 13 additions & 3 deletions .github/workflows/test/build-librdkafka.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@ if ! [ -f ~/build-cache/librdkafka/usr/local/include/librdkafka/rdkafka.h ] || !

git clone --depth 1 --branch "${LIBRDKAFKA_VERSION:-v2.3.0}" "${LIBRDKAFKA_REPOSITORY_URL:-https://github.com/edenhill/librdkafka.git}"

LIBRDKAFKA_BUILD_FLAGS=

if [ "$ARCH" = "X32" ]; then
export CC="${CC:-gcc} -m32"
export CFLAGS="$CFLAGS -m32"
export CXXFLAGS="$CXXFLAGS -m32"
export LDFLAGS="$LDFLAGS -m32"
LIBRDKAFKA_BUILD_FLAGS="$LIBRDKAFKA_BUILD_FLAGS --build=i686-pc-linux-gnu"
fi

cd librdkafka
./configure
make
./configure $LIBRDKAFKA_BUILD_FLAGS
make -j $(nproc)
mkdir -p ~/build-cache/librdkafka
sudo make install DESTDIR=$HOME/build-cache/librdkafka
test -f ~/build-cache/librdkafka/usr/local/include/librdkafka/rdkafka.h || echo "librdkafka build failed"
Expand All @@ -22,7 +32,7 @@ if ! [ -f ~/build-cache/librdkafka/usr/local/include/librdkafka/rdkafka.h ] || !

cd kafkacat
./configure
make
make -j $(nproc)
sudo make install DESTDIR=$HOME/build-cache/librdkafka

else
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/test/build-php-rdkafka.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ PACKAGE_VERSION="$(grep -m 1 '<release>' package.xml|cut -d'>' -f2|cut -d'<' -f1

pecl package

if [ $MEMORY_CHECK -eq 1 ]; then
PHP_RDKAFKA_CFLAGS="-Wall -Werror -Wno-deprecated-declarations"
if [ $MEMORY_CHECK -eq 1 ] || [ "$ARCH" = "X32" ]; then
export CFLAGS="$CFLAGS -Wall -Werror -Wno-deprecated-declarations"
fi

sudo CFLAGS="$PHP_RDKAFKA_CFLAGS" pecl install "./rdkafka-$PACKAGE_VERSION.tgz"
if [ "$ARCH" = "X32" ]; then
export CC="${CC:-gcc} -m32"
export CFLAGS="$CFLAGS -m32"
export CXXFLAGS="$CXXFLAGS -m32"
export LDFLAGS="$LDFLAGS -m32"
fi

sudo -E pecl install "./rdkafka-$PACKAGE_VERSION.tgz"

echo "extension=rdkafka.so"|sudo tee /usr/local/etc/php/rdkafka.ini >/dev/null
12 changes: 8 additions & 4 deletions .github/workflows/test/build-php.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

set -ex

if [ $MEMORY_CHECK -eq 1 ]; then
sudo apt-get -y install valgrind
fi

if ! [ -f ~/build-cache/php/usr/local/bin/php ]; then
echo "PHP build is not cached"

Expand All @@ -29,6 +25,14 @@ if ! [ -f ~/build-cache/php/usr/local/bin/php ]; then
esac
fi

if [ "$ARCH" = "X32" ]; then
export CC="${CC:-gcc} -m32"
export CFLAGS="$CFLAGS -m32"
export CXXFLAGS="$CXXFLAGS -m32"
export LDFLAGS="$LDFLAGS -m32"
PHP_BUILD_FLAGS="$PHP_BUILD_FLAGS --build=i686-pc-linux-gnu"
fi

./configure $PHP_BUILD_FLAGS $PHP_BUILD_EXTRA_FLAGS
make -j $(nproc)
mkdir -p ~/build-cache/php
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/test/install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

set -ex

export DEBIAN_FRONTEND=noninteractive

DEPS="zlib1g-dev libssl-dev"

if [ "$ARCH" = "X32" ]; then
sudo dpkg --add-architecture i386
sudo apt-get update
DEPS="$DEPS gcc-multilib g++-multilib zlib1g-dev:i386 libssl-dev:i386"
fi

if [ "$MEMORY_CHECK" = "1" ]; then
DEPS="$DEPS valgrind"
fi

if [ -n "$DEPS" ]; then
sudo apt-get -y install $DEPS
fi
4 changes: 2 additions & 2 deletions conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ static void kafka_conf_log_cb(const rd_kafka_t *rk, int level, const char *facil
zval_ptr_dtor(&args[3]);
}

#ifdef HAS_RD_KAFKA_OAUTHBEARER
/*
void rd_kafka_conf_set_oauthbearer_token_refresh_cb(
rd_kafka_conf_t *conf,
Expand Down Expand Up @@ -371,8 +372,7 @@ static void kafka_conf_set_oauthbearer_token_refresh_cb(rd_kafka_t *rk, const ch
zval_ptr_dtor(&args[0]);
zval_ptr_dtor(&args[1]);
}


#endif

/* {{{ proto RdKafka\Conf::__construct() */
PHP_METHOD(RdKafka_Conf, __construct)
Expand Down
6 changes: 3 additions & 3 deletions kafka_consumer.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ PHP_METHOD(RdKafka_KafkaConsumer, queryWatermarkOffsets)
object_intern *intern;
char *topic;
size_t topic_length;
long low, high;
int64_t low, high;
zend_long partition, timeout;
zval *lowResult, *highResult;
rd_kafka_resp_err_t err;
Expand All @@ -791,8 +791,8 @@ PHP_METHOD(RdKafka_KafkaConsumer, queryWatermarkOffsets)
return;
}

ZVAL_LONG(lowResult, low);
ZVAL_LONG(highResult, high);
ZVAL_LONG(lowResult, (zend_long) low);
ZVAL_LONG(highResult, (zend_long) high);
}
/* }}} */

Expand Down
34 changes: 28 additions & 6 deletions rdkafka.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ PHP_METHOD(RdKafka, setLogLevel)
/* }}} */

#ifdef HAS_RD_KAFKA_OAUTHBEARER
/* {{{ proto void RdKafka::oauthbearerSetToken(string $token_value, int $lifetime_ms, string $principal_name, array $extensions = [])
/* {{{ proto void RdKafka::oauthbearerSetToken(string $token_value, int|float|string $lifetime_ms, string $principal_name, array $extensions = [])
* Set SASL/OAUTHBEARER token and metadata
*
* The SASL/OAUTHBEARER token refresh callback or event handler should cause
Expand All @@ -449,18 +449,40 @@ PHP_METHOD(RdKafka, oauthbearerSetToken)
kafka_object *intern;
char *token_value;
size_t token_value_len;
zend_long lifetime_ms;
zval *zlifetime_ms;
int64_t lifetime_ms;
char *principal_name;
size_t principal_len;
HashTable *extensions_hash = NULL;

char errstr[512];
rd_kafka_resp_err_t ret = 0;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "sls|h", &token_value, &token_value_len, &lifetime_ms, &principal_name, &principal_len, &extensions_hash) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "szs|h", &token_value, &token_value_len, &zlifetime_ms, &principal_name, &principal_len, &extensions_hash) == FAILURE) {
return;
}

/* On 32-bits, it might be required to pass $lifetime_ms as a float or a
* string */
switch (Z_TYPE_P(zlifetime_ms)) {
case IS_LONG:
lifetime_ms = (int64_t) Z_LVAL_P(zlifetime_ms);
break;
case IS_DOUBLE:
lifetime_ms = (int64_t) Z_DVAL_P(zlifetime_ms);
break;
case IS_STRING:;
char *str = Z_STRVAL_P(zlifetime_ms);
char *end;
lifetime_ms = (int64_t) strtoll(str, &end, 10);
if (end != str + Z_STRLEN_P(zlifetime_ms)) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Argument #2 ($lifetime_ms) must be a valid integer");
return;
}
break;
EMPTY_SWITCH_DEFAULT_CASE();
}

intern = get_kafka_object(getThis());
if (!intern) {
return;
Expand Down Expand Up @@ -721,7 +743,7 @@ PHP_METHOD(RdKafka, queryWatermarkOffsets)
kafka_object *intern;
char *topic;
size_t topic_length;
long low, high;
int64_t low, high;
zend_long partition, timeout;
zval *lowResult, *highResult;
rd_kafka_resp_err_t err;
Expand All @@ -745,8 +767,8 @@ PHP_METHOD(RdKafka, queryWatermarkOffsets)
return;
}

ZVAL_LONG(lowResult, low);
ZVAL_LONG(highResult, high);
ZVAL_LONG(lowResult, (zend_long) low);
ZVAL_LONG(highResult, (zend_long) high);
}
/* }}} */

Expand Down
2 changes: 1 addition & 1 deletion rdkafka.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function resumePartitions(array $topic_partitions): array {}

#ifdef HAS_RD_KAFKA_OAUTHBEARER
/** @tentative-return-type */
public function oauthbearerSetToken(string $token_value, int $lifetime_ms, string $principal_name, array $extensions = []): void {}
public function oauthbearerSetToken(string $token_value, int|float|string $lifetime_ms, string $principal_name, array $extensions = []): void {}

/** @tentative-return-type */
public function oauthbearerSetTokenFailure(string $error): void {}
Expand Down
Loading

0 comments on commit 3cdcdf5

Please sign in to comment.