Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Add gnu based static binary support #592

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

crazywhalecc
Copy link
Owner

@crazywhalecc crazywhalecc commented Jan 28, 2025

What does this PR do?

  • Add gnu based static binary support, fix Optional GNU C Library support #376
  • Add CentOS 7.x doctor command support
  • Add env override file config/env.custom.ini
  • Fix openssl extension sanity check

Basic usage:

# run as CentOS 7 based docker image
bin/spc-gnu-docker --libc=glibc <command> ...

Checklist before merging

If your PR involves the changes mentioned below and completed the action, please tick the corresponding option.
If a modification is not involved, please skip it directly.

  • If it's an extension or dependency update, make sure adding related extensions in src/global/test-extensions.php.
  • If you changed the behavior of static-php-cli, update docs in ./docs/.
  • If you updated config/xxx.json content, run bin/spc dev:sort-config xxx.

@crazywhalecc crazywhalecc added new feature New feature or request os/linux Things only for Linux OS mixed PR This PR contains multiple updates labels Jan 28, 2025
@crazywhalecc crazywhalecc marked this pull request as draft January 28, 2025 11:41
@crazywhalecc crazywhalecc changed the title Add gnu based static binary support [feat] Add gnu based static binary support Jan 28, 2025
@crazywhalecc crazywhalecc marked this pull request as ready for review February 4, 2025 08:19
@crazywhalecc
Copy link
Owner Author

crazywhalecc commented Feb 4, 2025

@dunglas Building some extension combinations with glibc is pretty smooth at the moment, but I'm not sure there are any hidden issues I haven't discovered yet. Docs are also in this PR.

It would be great if you'd like to provide some suggestions or feedback, and I'll merge to the main branch later.

@dunglas
Copy link
Contributor

dunglas commented Feb 4, 2025

Thank you for this!!

I had a (very) quick look and the patch looks good to me.

I'll try to build FrankenPHP with it to see if it works, but as I'll be in vacation for 10 days, it may take some time.

@ptondereau
Copy link

Hey 👋🏻
I tried your branch on my frankenphp's fork branch and test is against the ./build-static.sh (updated for purpose) and you can see the result on this GHA here

As you can see, it still fails with:

[11:22:21] [I] musl-cross-make not installed, please install it first. (You can use `doctor` command to install it)

I'm available for any help if needed, of course.

@crazywhalecc
Copy link
Owner Author

crazywhalecc commented Feb 20, 2025

@ptondereau You should use env.custom.ini as document wrote:

Build glibc Compatible Linux Binary

The latest version of static-php-cli includes the bin/spc-gnu-docker script,
which can create a CentOS 7.x (glibc-2.17) Docker container with one click and build a glibc compatible PHP static binary in the container.

First, clone the repository of this project and add the following content to the config/env.custom.ini file:

; 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"

Then, run the following command once.
The first run will take a long time because it needs to download the CentOS 7.x image and some build tools.

bin/spc-gnu-docker

After the image is built, you will see the same command help menu as bin/spc, which means the container is ready.

After the container is ready, you can refer to the local build section to build your PHP static binary.
Just replace bin/spc or ./spc with bin/spc-gnu-docker.

Unlike the default build, when building in the glibc environment, you must add the parameter --libc=glibc, such as:

bin/spc-gnu-docker --libc=glibc build bcmath,ctype,openssl,pdo,phar,posix,session,tokenizer,xml,zip --build-cli --debug

Notes

In rare cases, glibc-based static PHP may encounter segment faults and other errors, but there are currently few examples.
If you encounter any issues, please submit an issue.

glibc build is an extended feature and is not part of the default static-php support.
If you have related issues or requirements, please indicate that you are building based on glibc when submitting an issue.

If you need to build glibc-based binaries without using Docker,
please refer to the bin/spc-gnu-docker script to manually create a similar environment.

Since glibc binaries are not the main goal of the project,
we generally do not test the compatibility of various libraries and extensions under glibc.
If any specific library builds successfully on musl-libc but fails on glibc, please submit an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mixed PR This PR contains multiple updates new feature New feature or request os/linux Things only for Linux OS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optional GNU C Library support
3 participants