mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-17 20:34:51 +08:00
Add gnu based static binary support
This commit is contained in:
parent
878e17ddb4
commit
09c0e43501
@ -136,5 +136,6 @@ echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil -lrt"'
|
|||||||
# shellcheck disable=SC2068
|
# shellcheck disable=SC2068
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
# shellcheck disable=SC2090
|
# shellcheck disable=SC2090
|
||||||
|
$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH bin/spc $@
|
||||||
|
|
||||||
$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH # bin/spc $@
|
$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH # bin/spc $@
|
||||||
|
|||||||
14
config/env.custom.ini
Normal file
14
config/env.custom.ini
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
; Modify this file name to `env.custom.ini`, and run `bin/spc-gnu-docker`,
|
||||||
|
; you can compile a GNU libc based static binary !
|
||||||
|
[global]
|
||||||
|
SPC_SKIP_DOCTOR_CHECK_ITEMS="if musl-wrapper is installed,if musl-cross-make is installed"
|
||||||
|
|
||||||
|
[linux]
|
||||||
|
CC=gcc
|
||||||
|
CXX=g++
|
||||||
|
AR=ar
|
||||||
|
LD=ld
|
||||||
|
SPC_DEFAULT_C_FLAGS=-fPIC
|
||||||
|
SPC_NO_MUSL_PATH=yes
|
||||||
|
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie"
|
||||||
|
SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil"
|
||||||
@ -37,7 +37,7 @@ class LinuxBuilder extends UnixBuilderBase
|
|||||||
GlobalEnvManager::init($this);
|
GlobalEnvManager::init($this);
|
||||||
|
|
||||||
// set library path, some libraries need it. (We cannot use `putenv` here, because cmake will be confused)
|
// set library path, some libraries need it. (We cannot use `putenv` here, because cmake will be confused)
|
||||||
if (!filter_var(getenv('SPC_NO_MUSL_PATH'), FILTER_VALIDATE_BOOLEAN)) {
|
if (!filter_var(getenv('SPC_NO_MUSL_PATH'), FILTER_VALIDATE_BOOLEAN) && $this->libc !== LIBC_GLIBC) {
|
||||||
$this->setOptionIfNotExist('library_path', "LIBRARY_PATH=\"/usr/local/musl/{$arch}-linux-musl/lib\"");
|
$this->setOptionIfNotExist('library_path', "LIBRARY_PATH=\"/usr/local/musl/{$arch}-linux-musl/lib\"");
|
||||||
$this->setOptionIfNotExist('ld_library_path', "LD_LIBRARY_PATH=\"/usr/local/musl/{$arch}-linux-musl/lib\"");
|
$this->setOptionIfNotExist('ld_library_path', "LD_LIBRARY_PATH=\"/usr/local/musl/{$arch}-linux-musl/lib\"");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,7 +44,11 @@ class libpng extends LinuxLibraryBase
|
|||||||
shell()->cd($this->source_dir)
|
shell()->cd($this->source_dir)
|
||||||
->exec('chmod +x ./configure')
|
->exec('chmod +x ./configure')
|
||||||
->exec('chmod +x ./install-sh')
|
->exec('chmod +x ./install-sh')
|
||||||
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LIBS' => $this->getLibExtraLibs()])
|
->setEnv([
|
||||||
|
'CFLAGS' => trim($this->getLibExtraCFlags() . ' ' . $this->builder->arch_c_flags),
|
||||||
|
'LDFLAGS' => $this->getLibExtraLdFlags(),
|
||||||
|
'LIBS' => $this->getLibExtraLibs()
|
||||||
|
])
|
||||||
->execWithEnv(
|
->execWithEnv(
|
||||||
'LDFLAGS="-L' . BUILD_LIB_PATH . '" ' .
|
'LDFLAGS="-L' . BUILD_LIB_PATH . '" ' .
|
||||||
'./configure ' .
|
'./configure ' .
|
||||||
|
|||||||
@ -4,6 +4,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace SPC\builder\unix\library;
|
namespace SPC\builder\unix\library;
|
||||||
|
|
||||||
|
use SPC\builder\linux\library\LinuxLibraryBase;
|
||||||
|
use SPC\builder\linux\LinuxBuilder;
|
||||||
use SPC\exception\FileSystemException;
|
use SPC\exception\FileSystemException;
|
||||||
use SPC\exception\RuntimeException;
|
use SPC\exception\RuntimeException;
|
||||||
use SPC\store\FileSystem;
|
use SPC\store\FileSystem;
|
||||||
@ -52,9 +54,14 @@ trait curl
|
|||||||
|
|
||||||
FileSystem::resetDir($this->source_dir . '/build');
|
FileSystem::resetDir($this->source_dir . '/build');
|
||||||
|
|
||||||
|
$cflags = $this instanceof LinuxLibraryBase && $this->builder->libc === 'glibc' ? '-fPIC' : '';
|
||||||
// compile!
|
// compile!
|
||||||
shell()->cd($this->source_dir . '/build')
|
shell()->cd($this->source_dir . '/build')
|
||||||
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
|
->setEnv([
|
||||||
|
'CFLAGS' => trim($this->getLibExtraCFlags() . ' ' . $cflags),
|
||||||
|
'LDFLAGS' => $this->getLibExtraLdFlags(),
|
||||||
|
'LIBS' => $this->getLibExtraLibs()
|
||||||
|
])
|
||||||
->exec('sed -i.save s@\${CMAKE_C_IMPLICIT_LINK_LIBRARIES}@@ ../CMakeLists.txt')
|
->exec('sed -i.save s@\${CMAKE_C_IMPLICIT_LINK_LIBRARIES}@@ ../CMakeLists.txt')
|
||||||
->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF -DBUILD_LIBCURL_DOCS=OFF {$extra} ..")
|
->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF -DBUILD_LIBCURL_DOCS=OFF {$extra} ..")
|
||||||
->execWithEnv("make -j{$this->builder->concurrency}")
|
->execWithEnv("make -j{$this->builder->concurrency}")
|
||||||
|
|||||||
@ -10,7 +10,7 @@ trait pkgconfig
|
|||||||
{
|
{
|
||||||
protected function build(): void
|
protected function build(): void
|
||||||
{
|
{
|
||||||
$cflags = PHP_OS_FAMILY !== 'Linux' ? '-Wimplicit-function-declaration -Wno-int-conversion' : '';
|
$cflags = PHP_OS_FAMILY !== 'Linux' ? "{$this->builder->arch_c_flags} -Wimplicit-function-declaration -Wno-int-conversion" : '';
|
||||||
$ldflags = !($this instanceof LinuxLibraryBase) || $this->builder->libc === 'glibc' ? '' : '--static';
|
$ldflags = !($this instanceof LinuxLibraryBase) || $this->builder->libc === 'glibc' ? '' : '--static';
|
||||||
|
|
||||||
shell()->cd($this->source_dir)
|
shell()->cd($this->source_dir)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user