Skip to content

Commit 3cdcdf5

Browse files
authored
Fix X32 build (#565)
1 parent 6c1a72c commit 3cdcdf5

14 files changed

+188
-96
lines changed

.github/workflows/test.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ jobs:
4040
librdkafka: 'v1.9.2'
4141
memcheck: '1'
4242

43+
# X32
44+
- php: '8.3.0'
45+
librdkafka: 'v2.6.0'
46+
arch: 'X32'
47+
4348
# Latest librdkafka 2.x
4449
- php: '8.3.0'
4550
librdkafka: 'v2.3.0'
@@ -172,6 +177,7 @@ jobs:
172177
SKIP_OAUTH: ${{ matrix.skipoauth }}
173178
TEST_KAFKA_BROKERS: kafka:9092
174179
TEST_KAFKA_BROKER_VERSION: 2.6
180+
ARCH: ${{ matrix.arch }}
175181
steps:
176182
- name: 'Check out repository'
177183
uses: 'actions/checkout@v2'
@@ -181,12 +187,15 @@ jobs:
181187
- uses: actions/cache@v2
182188
with:
183189
path: ~/build-cache/php
184-
key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.memcheck }}
190+
key: ${{ runner.os }}-${{ matrix.arch }}-${{ matrix.php }}-${{ matrix.memcheck }}
185191

186192
- uses: actions/cache@v2
187193
with:
188194
path: ~/build-cache/librdkafka
189-
key: ${{ runner.os }}-${{ matrix.librdkafka }}
195+
key: ${{ runner.os }}-${{ matrix.arch }}-${{ matrix.librdkafka }}
196+
197+
- name: 'Install dependencies'
198+
run: './php-rdkafka/.github/workflows/test/install-dependencies.sh'
190199

191200
- name: 'Build librdkafka'
192201
run: './php-rdkafka/.github/workflows/test/build-librdkafka.sh'

.github/workflows/test/build-librdkafka.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@ if ! [ -f ~/build-cache/librdkafka/usr/local/include/librdkafka/rdkafka.h ] || !
77

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

10+
LIBRDKAFKA_BUILD_FLAGS=
11+
12+
if [ "$ARCH" = "X32" ]; then
13+
export CC="${CC:-gcc} -m32"
14+
export CFLAGS="$CFLAGS -m32"
15+
export CXXFLAGS="$CXXFLAGS -m32"
16+
export LDFLAGS="$LDFLAGS -m32"
17+
LIBRDKAFKA_BUILD_FLAGS="$LIBRDKAFKA_BUILD_FLAGS --build=i686-pc-linux-gnu"
18+
fi
19+
1020
cd librdkafka
11-
./configure
12-
make
21+
./configure $LIBRDKAFKA_BUILD_FLAGS
22+
make -j $(nproc)
1323
mkdir -p ~/build-cache/librdkafka
1424
sudo make install DESTDIR=$HOME/build-cache/librdkafka
1525
test -f ~/build-cache/librdkafka/usr/local/include/librdkafka/rdkafka.h || echo "librdkafka build failed"
@@ -22,7 +32,7 @@ if ! [ -f ~/build-cache/librdkafka/usr/local/include/librdkafka/rdkafka.h ] || !
2232

2333
cd kafkacat
2434
./configure
25-
make
35+
make -j $(nproc)
2636
sudo make install DESTDIR=$HOME/build-cache/librdkafka
2737

2838
else

.github/workflows/test/build-php-rdkafka.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ PACKAGE_VERSION="$(grep -m 1 '<release>' package.xml|cut -d'>' -f2|cut -d'<' -f1
1111

1212
pecl package
1313

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

18-
sudo CFLAGS="$PHP_RDKAFKA_CFLAGS" pecl install "./rdkafka-$PACKAGE_VERSION.tgz"
18+
if [ "$ARCH" = "X32" ]; then
19+
export CC="${CC:-gcc} -m32"
20+
export CFLAGS="$CFLAGS -m32"
21+
export CXXFLAGS="$CXXFLAGS -m32"
22+
export LDFLAGS="$LDFLAGS -m32"
23+
fi
24+
25+
sudo -E pecl install "./rdkafka-$PACKAGE_VERSION.tgz"
1926

2027
echo "extension=rdkafka.so"|sudo tee /usr/local/etc/php/rdkafka.ini >/dev/null

.github/workflows/test/build-php.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
set -ex
44

5-
if [ $MEMORY_CHECK -eq 1 ]; then
6-
sudo apt-get -y install valgrind
7-
fi
8-
95
if ! [ -f ~/build-cache/php/usr/local/bin/php ]; then
106
echo "PHP build is not cached"
117

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

28+
if [ "$ARCH" = "X32" ]; then
29+
export CC="${CC:-gcc} -m32"
30+
export CFLAGS="$CFLAGS -m32"
31+
export CXXFLAGS="$CXXFLAGS -m32"
32+
export LDFLAGS="$LDFLAGS -m32"
33+
PHP_BUILD_FLAGS="$PHP_BUILD_FLAGS --build=i686-pc-linux-gnu"
34+
fi
35+
3236
./configure $PHP_BUILD_FLAGS $PHP_BUILD_EXTRA_FLAGS
3337
make -j $(nproc)
3438
mkdir -p ~/build-cache/php
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
3+
set -ex
4+
5+
export DEBIAN_FRONTEND=noninteractive
6+
7+
DEPS="zlib1g-dev libssl-dev"
8+
9+
if [ "$ARCH" = "X32" ]; then
10+
sudo dpkg --add-architecture i386
11+
sudo apt-get update
12+
DEPS="$DEPS gcc-multilib g++-multilib zlib1g-dev:i386 libssl-dev:i386"
13+
fi
14+
15+
if [ "$MEMORY_CHECK" = "1" ]; then
16+
DEPS="$DEPS valgrind"
17+
fi
18+
19+
if [ -n "$DEPS" ]; then
20+
sudo apt-get -y install $DEPS
21+
fi

conf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ static void kafka_conf_log_cb(const rd_kafka_t *rk, int level, const char *facil
340340
zval_ptr_dtor(&args[3]);
341341
}
342342

343+
#ifdef HAS_RD_KAFKA_OAUTHBEARER
343344
/*
344345
void rd_kafka_conf_set_oauthbearer_token_refresh_cb(
345346
rd_kafka_conf_t *conf,
@@ -371,8 +372,7 @@ static void kafka_conf_set_oauthbearer_token_refresh_cb(rd_kafka_t *rk, const ch
371372
zval_ptr_dtor(&args[0]);
372373
zval_ptr_dtor(&args[1]);
373374
}
374-
375-
375+
#endif
376376

377377
/* {{{ proto RdKafka\Conf::__construct() */
378378
PHP_METHOD(RdKafka_Conf, __construct)

kafka_consumer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ PHP_METHOD(RdKafka_KafkaConsumer, queryWatermarkOffsets)
767767
object_intern *intern;
768768
char *topic;
769769
size_t topic_length;
770-
long low, high;
770+
int64_t low, high;
771771
zend_long partition, timeout;
772772
zval *lowResult, *highResult;
773773
rd_kafka_resp_err_t err;
@@ -791,8 +791,8 @@ PHP_METHOD(RdKafka_KafkaConsumer, queryWatermarkOffsets)
791791
return;
792792
}
793793

794-
ZVAL_LONG(lowResult, low);
795-
ZVAL_LONG(highResult, high);
794+
ZVAL_LONG(lowResult, (zend_long) low);
795+
ZVAL_LONG(highResult, (zend_long) high);
796796
}
797797
/* }}} */
798798

rdkafka.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ PHP_METHOD(RdKafka, setLogLevel)
432432
/* }}} */
433433

434434
#ifdef HAS_RD_KAFKA_OAUTHBEARER
435-
/* {{{ proto void RdKafka::oauthbearerSetToken(string $token_value, int $lifetime_ms, string $principal_name, array $extensions = [])
435+
/* {{{ proto void RdKafka::oauthbearerSetToken(string $token_value, int|float|string $lifetime_ms, string $principal_name, array $extensions = [])
436436
* Set SASL/OAUTHBEARER token and metadata
437437
*
438438
* The SASL/OAUTHBEARER token refresh callback or event handler should cause
@@ -449,18 +449,40 @@ PHP_METHOD(RdKafka, oauthbearerSetToken)
449449
kafka_object *intern;
450450
char *token_value;
451451
size_t token_value_len;
452-
zend_long lifetime_ms;
452+
zval *zlifetime_ms;
453+
int64_t lifetime_ms;
453454
char *principal_name;
454455
size_t principal_len;
455456
HashTable *extensions_hash = NULL;
456457

457458
char errstr[512];
458459
rd_kafka_resp_err_t ret = 0;
459460

460-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sls|h", &token_value, &token_value_len, &lifetime_ms, &principal_name, &principal_len, &extensions_hash) == FAILURE) {
461+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "szs|h", &token_value, &token_value_len, &zlifetime_ms, &principal_name, &principal_len, &extensions_hash) == FAILURE) {
461462
return;
462463
}
463464

465+
/* On 32-bits, it might be required to pass $lifetime_ms as a float or a
466+
* string */
467+
switch (Z_TYPE_P(zlifetime_ms)) {
468+
case IS_LONG:
469+
lifetime_ms = (int64_t) Z_LVAL_P(zlifetime_ms);
470+
break;
471+
case IS_DOUBLE:
472+
lifetime_ms = (int64_t) Z_DVAL_P(zlifetime_ms);
473+
break;
474+
case IS_STRING:;
475+
char *str = Z_STRVAL_P(zlifetime_ms);
476+
char *end;
477+
lifetime_ms = (int64_t) strtoll(str, &end, 10);
478+
if (end != str + Z_STRLEN_P(zlifetime_ms)) {
479+
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Argument #2 ($lifetime_ms) must be a valid integer");
480+
return;
481+
}
482+
break;
483+
EMPTY_SWITCH_DEFAULT_CASE();
484+
}
485+
464486
intern = get_kafka_object(getThis());
465487
if (!intern) {
466488
return;
@@ -721,7 +743,7 @@ PHP_METHOD(RdKafka, queryWatermarkOffsets)
721743
kafka_object *intern;
722744
char *topic;
723745
size_t topic_length;
724-
long low, high;
746+
int64_t low, high;
725747
zend_long partition, timeout;
726748
zval *lowResult, *highResult;
727749
rd_kafka_resp_err_t err;
@@ -745,8 +767,8 @@ PHP_METHOD(RdKafka, queryWatermarkOffsets)
745767
return;
746768
}
747769

748-
ZVAL_LONG(lowResult, low);
749-
ZVAL_LONG(highResult, high);
770+
ZVAL_LONG(lowResult, (zend_long) low);
771+
ZVAL_LONG(highResult, (zend_long) high);
750772
}
751773
/* }}} */
752774

rdkafka.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function resumePartitions(array $topic_partitions): array {}
8282

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

8787
/** @tentative-return-type */
8888
public function oauthbearerSetTokenFailure(string $error): void {}

0 commit comments

Comments
 (0)