How to add my own extension ? #554
-
Hi ! I am sure I have previously asked this, but I cannot find the question (and answer) - so here we go again :) At my company we have a couple of extensions developed in-house. We would like to add them to static-php (phpmicro). Can someone please give some guidance as to how we would accomplish this ? I imagine I could use something like this: patcher.php as <?php
define('MYEXTENSION_SOURCE_PATH', '/some/local/dir/for/myextension_files');
// Copy myextension in place when `after-php-extract` is executed
if (patch_point() === 'after-php-extract') {
// PATCH SWOOLE
\SPC\store\FileSystem::copyDir(
MYEXTENSION_SOURCE_PATH',
SOURCE_PATH . '/php-src/ext/myextension',
);
} And then build using # ./spc build --build-micro "ctype,curl,dom,fileinfo,filter,ftp,gd,igbinary,inotify,libxml,mbstring,memcache,msgpack,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pgsql,phar,posix,readline,redis,shmop,simplexml,sockets,sodium,spx,sqlite3,ssh2,swoole,swoole-hook-mysql,swoole-hook-pgsql,swoole-hook-sqlite,sysvmsg,sysvsem,sysvshm,uuid,xml,xmlreader,zip,zlib,zstd,myextension" --with-upx-pack -I "foo=bar" -I "baz=boo" -P patcher.php Is this the way to include my own extension ? Thanks ! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I now tried to add my 'nodeid' extension - It can be downloaded from https://pub-4abdc3c79de8493e996731572a0de617.r2.dev/ext-nodeid.tar I added "nodeid": {
"support": {
"Windows": "no",
"BSD": "wip"
},
"type": "external",
"source": "nodeid",
"arg-type": "custom"
}, to src/ext.json and added: "nodeid": {
"type": "url",
"url": "https://pub-4abdc3c79de8493e996731572a0de617.r2.dev/ext-nodeid.tar",
"path": "php-src/ext/nodeid",
"provide-pre-built": false,
"license": {
"type": "text",
"text": "Closed-source SECUNO extension"
}
}, to src/source.json I then added the file 'src/SPC/builder/extension/nodeid.php' <?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\util\CustomExt;
#[CustomExt('nodeid')]
class nodeid extends Extension
{
public function getUnixConfigureArg(): string
{
return '--enable-nodeid';
}
} And then rebuildt the PHAR with composer build:phar Uploaded spc.phar to a server And then downloaded spc.phar: # wget -O spc <url_to_spc.phar>
# chmod +x ./spc and then: ./spc build --build-micro "ctype,curl,dom,fileinfo,filter,ftp,gd,igbinary,inotify,libxml,mbstring,memcache,msgpack,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pgsql,phar,posix,readline,redis,shmop,simplexml,sockets,sodium,spx,sqlite3,ssh2,swoole,swoole-hook-mysql,swoole-hook-pgsql,swoole-hook-sqlite,sysvmsg,sysvsem,sysvshm,uuid,xml,xmlreader,zip,zlib,zstd,nodeid" --with-upx-pack -I "foo=bar" -I "baz=boo" --debug And then I get this error: /usr/local/musl/bin/../lib/gcc/x86_64-linux-musl/13.2.0/../../../../x86_64-linux-musl/bin/ld: ext/nodeid/sid.o:/tmp/source/php-src/ext/nodeid/sid.h:43: multiple definition of `mData'; ext/nodeid/nodeid.o:/tmp/source/php-src/ext/nodeid/sid.h:43: first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:293: sapi/micro/micro.sfx] Error 1
s.lo Zend/zend_opcode.lo Zend/zend_operators.lo Zend/zend_ptr_stack.lo Zend/zend_stack.lo Zend/zend_variables.lo Zend/zend.lo Zend/zend_API.lo Zend/zend_extensions.lo Zend/zend_hash.lo Zend/zend_list.lo Zend/zend_builtin_functions.lo Zend/zend_attributes.lo Zend/zend_execute.lo Zend/zend_ini.lo Zend/zend_sort.lo Zend/zend_multibyte.lo Zend/zend_stream.lo Zend/zend_iterators.lo Zend/zend_interfaces.lo Zend/zend_exceptions.lo Zend/zend_strtod.lo Zend/zend_gc.lo Zend/zend_closures.lo Zend/zend_weakrefs.lo Zend/zend_float.lo Zend/zend_string.lo Zend/zend_signal.lo Zend/zend_generators.lo Zend/zend_virtual_cwd.lo Zend/zend_ast.lo Zend/zend_objects.lo Zend/zend_object_handlers.lo Zend/zend_objects_API.lo Zend/zend_default_classes.lo Zend/zend_inheritance.lo Zend/zend_smart_str.lo Zend/zend_cpuinfo.lo Zend/zend_gdb.lo Zend/zend_observer.lo Zend/zend_system_id.lo Zend/zend_enum.lo Zend/zend_fibers.lo Zend/zend_max_execution_timer.lo Zend/Optimizer/zend_optimizer.lo Zend/Optimizer/pass1.lo Zend/Optimizer/pass3.lo Zend/Optimizer/optimize_func_calls.lo Zend/Optimizer/block_pass.lo Zend/Optimizer/optimize_temp_vars_5.lo Zend/Optimizer/nop_removal.lo Zend/Optimizer/compact_literals.lo Zend/Optimizer/zend_cfg.lo Zend/Optimizer/zend_dfg.lo Zend/Optimizer/dfa_pass.lo Zend/Optimizer/zend_ssa.lo Zend/Optimizer/zend_inference.lo Zend/Optimizer/zend_func_info.lo Zend/Optimizer/zend_call_graph.lo Zend/Optimizer/sccp.lo Zend/Optimizer/scdf.lo Zend/Optimizer/dce.lo Zend/Optimizer/escape_analysis.lo Zend/Optimizer/compact_vars.lo Zend/Optimizer/zend_dump.lo main/internal_functions_cli.lo sapi/micro/php_micro.lo sapi/micro/php_micro_helper.lo sapi/micro/php_micro_hooks.lo sapi/micro/php_micro_fileinfo.lo sapi/cli/php_cli_process_title.lo sapi/cli/ps_title.lo /tmp/buildroot/lib/libzip.a /tmp/buildroot/lib/libuuid.a /tmp/buildroot/lib/libsqlite3.a /tmp/buildroot/lib/libpq.a /tmp/buildroot/lib/libpgport.a /tmp/buildroot/lib/libpgcommon.a /tmp/buildroot/lib/libsodium.a /tmp/buildroot/lib/libreadline.a /tmp/buildroot/lib/libncurses.a /tmp/buildroot/lib/libpng16.a /tmp/buildroot/lib/libcurl.a /tmp/buildroot/lib/libcares.a /tmp/buildroot/lib/libzstd.a /tmp/buildroot/lib/libnghttp2.a /tmp/buildroot/lib/libxml2.a /tmp/buildroot/lib/libiconv.a /tmp/buildroot/lib/libcharset.a /tmp/buildroot/lib/libbrotlidec.a /tmp/buildroot/lib/libbrotlienc.a /tmp/buildroot/lib/libbrotlicommon.a /tmp/buildroot/lib/libssh2.a /tmp/buildroot/lib/libssl.a /tmp/buildroot/lib/libcrypto.a /tmp/buildroot/lib/libz.a -lstdc++ -o sapi/micro/micro.sfx
[13:54:09] [ERRO] Uncaught SPC\exception\RuntimeException: Command run failed with code[2]: cd '/tmp/source/php-src' && $SPC_CMD_PREFIX_PHP_MAKE EXTRA_CFLAGS='-g -Os -fno-ident -fPIE' EXTRA_LIBS='/tmp/buildroot/lib/libzip.a /tmp/buildroot/lib/libuuid.a /tmp/buildroot/lib/libsqlite3.a /tmp/buildroot/lib/libpq.a /tmp/buildroot/lib/libpgport.a /tmp/buildroot/lib/libpgcommon.a /tmp/buildroot/lib/libsodium.a /tmp/buildroot/lib/libreadline.a /tmp/buildroot/lib/libncurses.a /tmp/buildroot/lib/libpng16.a /tmp/buildroot/lib/libcurl.a /tmp/buildroot/lib/libcares.a /tmp/buildroot/lib/libzstd.a /tmp/buildroot/lib/libnghttp2.a /tmp/buildroot/lib/libxml2.a /tmp/buildroot/lib/libiconv.a /tmp/buildroot/lib/libcharset.a /tmp/buildroot/lib/libbrotlidec.a /tmp/buildroot/lib/libbrotlienc.a /tmp/buildroot/lib/libbrotlicommon.a /tmp/buildroot/lib/libssh2.a /tmp/buildroot/lib/libssl.a /tmp/buildroot/lib/libcrypto.a /tmp/buildroot/lib/libz.a -lstdc++ ' EXTRA_LDFLAGS_PROGRAM='-all-static' micro at phar:///tmp/spc/src/globals/functions.php(152)
[13:54:09] [ERRO] #0 phar:///tmp/spc/src/SPC/util/UnixShell.php(51): f_passthru()
#1 phar:///tmp/spc/src/SPC/builder/linux/LinuxBuilder.php(255): SPC\util\UnixShell->exec()
#2 phar:///tmp/spc/src/SPC/builder/linux/LinuxBuilder.php(189): SPC\builder\linux\LinuxBuilder->buildMicro()
#3 phar:///tmp/spc/src/SPC/command/BuildCliCommand.php(173): SPC\builder\linux\LinuxBuilder->buildPHP()
#4 phar:///tmp/spc/src/SPC/command/BaseCommand.php(107): SPC\command\BuildCliCommand->handle()
#5 phar:///tmp/spc/vendor/symfony/console/Command/Command.php(326): SPC\command\BaseCommand->execute()
#6 phar:///tmp/spc/vendor/symfony/console/Application.php(1078): Symfony\Component\Console\Command\Command->run()
#7 phar:///tmp/spc/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand()
#8 phar:///tmp/spc/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun()
#9 phar:///tmp/spc/bin/spc(20): Symfony\Component\Console\Application->run()
#10 /tmp/spc(9): require('...' What am I doing wrong ? |
Beta Was this translation helpful? Give feedback.
-
Sorry for late reply. @henrywood I just tested your build command, and I changed config only like this: With following command, I built successfully on my debian vm: bin/spc download --prefer-pre-built --debug --for-extensions=ctype,curl,dom,fileinfo,filter,ftp,gd,igbinary,inotify,libxml,mbstring,memcache,msgpack,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pgsql,phar,posix,readline,redis,shmop,simplexml,sockets,sodium,spx,sqlite3,ssh2,swoole,swoole-hook-mysql,swoole-hook-pgsql,swoole-hook-sqlite,sysvmsg,sysvsem,sysvshm,uuid,xml,xmlreader,zip,zlib,zstd,nodeid
bin/spc build --build-cli --build-micro --debug ctype,curl,dom,fileinfo,filter,ftp,gd,igbinary,inotify,libxml,mbstring,memcache,msgpack,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pgsql,phar,posix,readline,redis,shmop,simplexml,sockets,sodium,spx,sqlite3,ssh2,swoole,swoole-hook-mysql,swoole-hook-pgsql,swoole-hook-sqlite,sysvmsg,sysvsem,sysvshm,uuid,xml,xmlreader,zip,zlib,zstd,nodeid I don't use patch because it (nodeid extension you provided) can be extracted correctly. But I couldn't build on my mac, seems nodeid is not compatible with macOS (error message shows that it uses linux headers). For every time build tests, remember deleting |
Beta Was this translation helpful? Give feedback.
Sorry for late reply. @henrywood
I just tested your build command, and I changed config only like this:
With following command, I built successfully on my debian vm: