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

Add an option to build all libraries with debug symbols #377

Closed
dunglas opened this issue Mar 11, 2024 · 6 comments · Fixed by #403
Closed

Add an option to build all libraries with debug symbols #377

dunglas opened this issue Mar 11, 2024 · 6 comments · Fixed by #403
Labels
enhancement New feature or request kind/framework Issues related to CLI app framework
Milestone

Comments

@dunglas
Copy link
Contributor

dunglas commented Mar 11, 2024

This would be super useful to have the ability to build everything with debug symbols. This would make debugging issues such as php/php-src#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?

@dunglas
Copy link
Contributor Author

dunglas commented Mar 11, 2024

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.

@crazywhalecc crazywhalecc added enhancement New feature or request kind/framework Issues related to CLI app framework labels Mar 11, 2024
@crazywhalecc
Copy link
Owner

crazywhalecc commented Mar 11, 2024

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.

@withinboredom
Copy link

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.

@crazywhalecc
Copy link
Owner

crazywhalecc commented Mar 22, 2024

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:

  1. We need to repeatedly define a bunch of very long environment variable names that may never be used.
  2. Some libraries can be directly passed to CMake or Makefile through export before compilation, without the need to define SPC again.
  3. The variable passing method does not solve part of the customization of the compilation command.
  4. 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.
  5. 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.

@crazywhalecc
Copy link
Owner

crazywhalecc commented Apr 7, 2024

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.

@crazywhalecc
Copy link
Owner

Finished, docs: https://static-php.dev/en/guide/env-vars.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request kind/framework Issues related to CLI app framework
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants