Skip to content

Commit

Permalink
compile.sh: enable optimizations by default
Browse files Browse the repository at this point in the history
this is no longer risky, and we provide binaries built with optimizations already anyway. No one wants a slow binary...

-f is now deprecated by this change
  • Loading branch information
dktapps committed Jul 7, 2023
1 parent b5a642d commit 8381781
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
# Used "set -ex" instead of hashbang since script isn't executed with hashbang
set -ex
trap "exit 1" ERR
./compile.sh -t linux64 -j 4 -f -g -P ${{ matrix.pm-version-major }} -c ./download_cache
./compile.sh -t linux64 -j 4 -g -P ${{ matrix.pm-version-major }} -c ./download_cache
- name: Create tarball
run: tar -czf ./PHP-Linux-x86_64-PM${{ matrix.pm-version-major }}.tar.gz bin
Expand Down Expand Up @@ -95,7 +95,7 @@ jobs:
export PATH="/usr/local/opt/bison/bin:$PATH"
set -ex
trap "exit 1" ERR
./compile.sh -t mac-x86-64 -j4 -f -g -P ${{ matrix.pm-version-major }} -c ./download_cache
./compile.sh -t mac-x86-64 -j4 -g -P ${{ matrix.pm-version-major }} -c ./download_cache
- name: Create tarball
run: tar -czf ./PHP-MacOS-x86_64-PM${{ matrix.pm-version-major }}.tar.gz bin
Expand Down
40 changes: 19 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
Bash script used to compile PHP on MacOS and Linux platforms. Make sure you have ``make autoconf automake libtool m4 wget getconf gzip bzip2 bison g++ git cmake pkg-config re2c ca-certificates``.

### Recommendations
- `-f` makes the compiled binary much faster, don't forget to use it if you're targeting production.
- If you're going to use the compiled binary only on the machine you're build it on, remove the `-t` option for best performance - this will allow the script to optimize for the current machine rather than a generic one.
- [`ext-gd2`](https://www.php.net/manual/en/book.image.php) is NOT included unless the `-g` flag is provided, as PocketMine-MP doesn't need it. However, if your plugins need it, don't forget to enable it using `-g`.
- The `-c` and `-l` options can be used to specify cache folders to speed up recompiling if you're recompiling many times (e.g. to improve the script).
Expand All @@ -26,29 +25,28 @@ Bash script used to compile PHP on MacOS and Linux platforms. Make sure you have
- The `aarch64-linux-musl` toolchain is required. You can compile and install it using https://github.com/pmmp/musl-cross-make (PMMP fork includes musl-libc patches for DNS resolver config path and increasing stack size limit for LevelDB)
- It is strongly recommended that you enable abusive optimizations for Android targets (`-f` flag) for best performance.

| Script flags | Description |
|--------------|----------------------------------------------------------------------------------------------------|
| -c | Uses the folder specified for caching downloaded tarballs, zipballs etc. |
| -d | Will compile with debug and the xdebug PHP extension |
| -f | Enable optimizations (increases compile time, but improves performance) |
| -g | Will compile GD2 |
| -j | Set make threads to # |
| -l | Uses the folder specified for caching compilation artifacts (useful for rapid rebuild and testing) |
| -n | Don't remove sources after completing compilation |
| -s | Will compile everything statically |
| -t | Set target |
| -v | Enable Valgrind support in PHP |
| -x | Specifies we are doing cross-compile |
| -P | Compiles extensions for the major PocketMine-MP version specified (can be `4` or `5`) |
| Script flags | Description |
|--------------|-------------------------------------------------------------------------------------------------------|
| -c | Uses the folder specified for caching downloaded tarballs, zipballs etc. |
| -d | Compiles with debugging symbols and disables optimizations (slow, but useful for debugging segfaults) |
| -g | Will compile GD2 |
| -j | Set make threads to # |
| -l | Uses the folder specified for caching compilation artifacts (useful for rapid rebuild and testing) |
| -n | Don't remove sources after completing compilation |
| -s | Will compile everything statically |
| -t | Set target |
| -v | Enable Valgrind support in PHP |
| -x | Specifies we are doing cross-compile |
| -P | Compiles extensions for the major PocketMine-MP version specified (can be `4` or `5`) |

### Example:

| Target | Arguments |
|-----------------|--------------------------------------|
| linux64 | ``-t linux64 -j4 -P5 -f`` |
| linux64, PM4 | ``-t linux64 -j4 -P4 -f`` |
| mac64 | ``-t mac-x86-64 -j4 -P5 -f`` |
| android-aarch64 | ``-t android-aarch64 -x -j4 -P5 -f`` |
| Target | Arguments |
|-----------------|-----------------------------------|
| linux64 | ``-t linux64 -j4 -P5`` |
| linux64, PM4 | ``-t linux64 -j4 -P4`` |
| mac64 | ``-t mac-x86-64 -j4 -P5`` |
| android-aarch64 | ``-t android-aarch64 -x -j4 -P5`` |

## windows-compile-vs.bat

Expand Down
11 changes: 3 additions & 8 deletions compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ HAVE_MYSQLI="--enable-mysqlnd --with-mysqli=mysqlnd"
COMPILE_TARGET=""
IS_CROSSCOMPILE="no"
IS_WINDOWS="no"
DO_OPTIMIZE="no"
DO_OPTIMIZE="yes"
DO_STATIC="no"
DO_CLEANUP="yes"
COMPILE_DEBUG="no"
Expand Down Expand Up @@ -176,6 +176,7 @@ while getopts "::t:j:sdxfgnva:P:c:l:Ji" OPTION; do
write_out "opt" "Will compile everything with debugging symbols, will not remove sources"
COMPILE_DEBUG="yes"
DO_CLEANUP="no"
DO_OPTIMIZE="no"
CFLAGS="$CFLAGS -g"
CXXFLAGS="$CXXFLAGS -g"
;;
Expand All @@ -189,8 +190,7 @@ while getopts "::t:j:sdxfgnva:P:c:l:Ji" OPTION; do
CFLAGS="$CFLAGS -static"
;;
f)
write_out "opt" "Enabling abusive optimizations..."
DO_OPTIMIZE="yes"
write_out "deprecated" "The -f flag is deprecated, as optimizations are now enabled by default unless -d (debug mode) is specified"
;;
g)
write_out "opt" "Will enable GD2"
Expand Down Expand Up @@ -1049,11 +1049,6 @@ get_github_extension "arraydebug" "$EXT_ARRAYDEBUG_VERSION" "pmmp" "ext-arraydeb

write_library "PHP" "$PHP_VERSION"

if [ "$DO_OPTIMIZE" != "no" ]; then
PHP_OPTIMIZATION="--enable-inline-optimization "
else
PHP_OPTIMIZATION="--disable-inline-optimization "
fi
write_configure
cd php
rm -f ./aclocal.m4 >> "$DIR/install.log" 2>&1
Expand Down

0 comments on commit 8381781

Please sign in to comment.