Skip to content

Commit

Permalink
Merge pull request #1 from alganet/php-ext-1
Browse files Browse the repository at this point in the history
Enable Zend PHP extensions that have no dependencies
  • Loading branch information
alganet committed Jul 7, 2024
2 parents 9ec10df + 15991ed commit 7d59280
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 8 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cosmocc
ph7
php
target
/cosmocc
/ph7
/php
/target
*.zip
*.gz
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ carthage uses the [cosmopolitan libc][cosmo] to build [αcτµαlly pδrταblε

We offer two flavors:

- The latest official [PHP][php], compiled barebones (`--disable-all`) **~13MB ape**
- The embedded [PH7][PH7] engine. **~2MB ape**
- The latest official [PHP][php]. **~30MB ape**

Please note that _BOTH BUILDS ARE EXPERIMENTAL_.

### Extensions

PH7 has no extensions, Zend PHP is built with these enabled:

- ctype filter fileinfo ftp gmp pcntl posix session sockets tokenizer

### Building Locally

You'll need wget, unzip and make. Then:
Expand Down
23 changes: 20 additions & 3 deletions carthage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export PKG_CONFIG="pkg-config --with-path=$PWD/cosmocc/lib/pkgconfig"
export INSTALL="cosmoinstall"
export AR="cosmoar"

if ! test -f target/bin/ph7
if ! test -f target/bin/ph7-2.1.4
then
cd ph7
$CC -o ph7 ph7.c examples/ph7_interp.c -W -Wunused -Wall -I.
Expand All @@ -61,11 +61,28 @@ then
cd ..
fi

if ! test -f target/bin/php
if ! test -f target/bin/php-8.3.9
then
cd php

patch -Np0 -i ../patches/php-8.3.9/cosmo-multicast.patch

./buildconf --force
./configure --prefix=$PWD/../target --disable-all --disable-shared --disable-fiber-asm
./configure --prefix=$PWD/../target \
--disable-all \
--disable-shared \
--disable-fiber-asm \
--enable-ctype \
--enable-filter \
--enable-fileinfo \
--enable-ftp \
--enable-gmp \
--enable-pcntl \
--enable-posix \
--enable-session \
--enable-sockets \
--enable-tokenizer

make -j $(nproc)
make install-cli install-phpdbg
mv ../target/bin/php ../target/bin/php-8.3.9
Expand Down
49 changes: 49 additions & 0 deletions patches/php-8.3.9/cosmo-multicast.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright (c) Alexandre Gomes Gaigalas <[email protected]>
# SPDX-License-Identifier: ISC

--- ext/sockets/multicast.h.orig 2024-07-07 10:15:00.221335337 -0300
+++ ext/sockets/multicast.h 2024-07-07 10:15:03.599347501 -0300
@@ -14,11 +14,11 @@
+----------------------------------------------------------------------+
*/

-#if defined(MCAST_JOIN_GROUP) && !defined(__APPLE__)
+#if defined(MCAST_JOIN_GROUP) && !defined(__APPLE__) && !defined(__COSMOCC__)
# define RFC3678_API 1
/* has block/unblock and source membership, in this case for both IPv4 and IPv6 */
# define HAS_MCAST_EXT 1
-#elif defined(IP_ADD_SOURCE_MEMBERSHIP) && !defined(__APPLE__)
+#elif defined(IP_ADD_SOURCE_MEMBERSHIP) && !defined(__APPLE__) && !defined(__COSMOCC__)
/* has block/unblock and source membership, but only for IPv4 */
# define HAS_MCAST_EXT 1
#endif

--- ext/sockets/multicast.c.orig 2024-07-07 09:19:04.467193555 -0300
+++ ext/sockets/multicast.c 2024-07-07 10:01:31.563897681 -0300
@@ -722,7 +722,7 @@
#define ifr_ifindex ifr_index
#endif

-#if defined(SIOCGIFNAME)
+#if defined(SIOCGIFNAME) || defined(__COSMOCC__)
if_req.ifr_ifindex = if_index;
if (ioctl(php_sock->bsd_socket, SIOCGIFNAME, &if_req) == -1) {
#elif defined(HAVE_IF_INDEXTONAME)
@@ -801,7 +801,7 @@
if ((((struct sockaddr*)&cur_req.ifr_addr)->sa_family == AF_INET) &&
(((struct sockaddr_in*)&cur_req.ifr_addr)->sin_addr.s_addr ==
addr->s_addr)) {
-#if defined(SIOCGIFINDEX)
+#if defined(SIOCGIFINDEX)|| defined(__COSMOCC__)
if (ioctl(php_sock->bsd_socket, SIOCGIFINDEX, (char*)&cur_req)
== -1) {
#elif defined(HAVE_IF_NAMETOINDEX)
@@ -815,7 +815,7 @@
errno);
goto err;
} else {
-#if defined(SIOCGIFINDEX)
+#if defined(SIOCGIFINDEX) || defined(__COSMOCC__)
*if_index = cur_req.ifr_ifindex;
#else
*if_index = index_tmp;

0 comments on commit 7d59280

Please sign in to comment.