static-php-cli
static-php-cli copied to clipboard
Add an option to build all libraries with debug symbols
This would be super useful to have the ability to build everything with debug symbols. This would make debugging issues such as https://github.com/php/php-src/issues/13648 easier.
To implement this, we could add a new cflags option, that will automatically set the CFLAGS env var for all built libs.
Then, something like spc build --cflags='-g -O0' --no-strip should allow to get good stack traces of everything.
Would you accept such a patch?
Another option, probably better, would be to enable the debug mode in every library (if supported), if the --no-strip option is passed. This can be done as and when we need it.
This may related to #331 .
Actually I have no idea for this because there are too many libs. If we just add options for PHP, it would be easy: such as --php-cflags=xxx --php-ldflags=xxx.
I prefer to inject customization points into the compilation command and make a series of modifications with the -P command. But this also seems to require adding many customizable fill-in-the-blanks for shell()->exec() for almost every library.
haha, I literally came here to ask the exact same question! Personally, I'd prefer a way to generically set CFLAGS and CXXFLAGS.
I haven't confirmed this is the cause, but it appears that the built libraries lack any optimizations -O2, for example, and thus statically compiled php appears to be orders of magnitudes slower than expected.
I was originally going to add SPC_XXX series to static-php-cli (EnvManager). First, we will cover common global variables, such as:
SPC_LIBS_EXTRA_CFLAGS: for every library default extra cflags, default is empty. (will add for every lib build command before)SPC_PHP_CFLAGS: for php library default extra cflags, default is current state (maybe we need to initialize them before build, e.g.-g -Os).SPC_LIB_LIBEVENT_CFLAGS: for specific lib cflags.
But this will have some problems:
- We need to repeatedly define a bunch of very long environment variable names that may never be used.
- Some libraries can be directly passed to CMake or Makefile through
exportbefore compilation, without the need to define SPC again. - The variable passing method does not solve part of the customization of the compilation command.
- Like @withinboredom's patch, we can only insert variables or functions before every build command strings, some libs. Some libraries require some additional compilation variables by default, and they cannot be modified and overwritten by direct insertion.
- Another option is to allow customizing any command executed by
shell()->exec()through variables or passing arguments.
I still don't know what is best for spc. There may not be a perfect solution: because we cannot allow all parameters to be customized, it will greatly increase the complexity of the builder. 😢 Although I now have the time to quickly implement this customization, I am not good at designing good project structure.
After a month of trying, I finally decided to customize only some of the compile flags as needed. See #403
This might not be a great solution, but I also don't want to get stuck in infinite customization hell.
Finished, docs: https://static-php.dev/en/guide/env-vars.html