├── .gitattributes ├── .gitignore ├── tests ├── generic │ ├── run.sh │ ├── pthreads.sh │ └── curl-ssl.sh ├── android │ └── static.sh └── test.sh ├── .github ├── dependabot.yml └── workflows │ ├── main.yml │ └── main-pm-matrix.yml ├── README.md ├── windows-compile-vs.ps1 └── compile.sh /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sh text eol=lf 2 | *.bat text eol=crlf 3 | *.ps1 text eol=crlf 4 | *.patch binary -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | install_data/ 3 | install.log 4 | temp_data/ 5 | compile.log 6 | /*.zip 7 | /*.exe 8 | -------------------------------------------------------------------------------- /tests/generic/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | OUTPUT=$("$PHP_BINARIES" -r 'echo 1;') 4 | 5 | if [ "$OUTPUT" != "1" ]; then 6 | exit 1 7 | fi 8 | 9 | exit 0 -------------------------------------------------------------------------------- /tests/android/static.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | OUTPUT=$(readelf -d "$PHP_BINARIES/bin/php") 4 | 5 | if [ "$OUTPUT" != "There is no dynamic section in this file." ]; then 6 | exit 1 7 | fi 8 | 9 | exit 0 -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: github-actions 4 | directory: "/" 5 | schedule: 6 | interval: monthly 7 | groups: 8 | github-actions: 9 | patterns: ["*"] 10 | -------------------------------------------------------------------------------- /tests/generic/pthreads.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | OUTPUT=$("$PHP_BINARIES" -r 'class MyThread extends Thread{ public function run(){ echo 1; }} $t = new MyThread; $t->start(); $t->join(); echo "1";') 4 | 5 | if [ "$OUTPUT" != "1" ]; then 6 | exit 1 7 | fi 8 | 9 | exit 0 -------------------------------------------------------------------------------- /tests/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export PHP_BINARIES="$2" 4 | chmod +x "$PHP_BINARIES" 5 | DIR="$(cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd)" 6 | export TEST_DIR="$DIR/$1/" 7 | 8 | TEST_NUMBER=("$TEST_DIR"*) 9 | TEST_NUMBER=${#TEST_NUMBER[@]} 10 | 11 | set +e 12 | 13 | INCREMENT=0 14 | FAILED=0 15 | 16 | cd "$TEST_DIR" 17 | echo "Doing tests on $TEST_DIR" 18 | 19 | for f in *; do 20 | INCREMENT=$((INCREMENT+1)) 21 | echo -n "[$INCREMENT/$TEST_NUMBER] $f ... " 22 | chmod +x "$f" 23 | "./$f" 24 | STATUS=$? 25 | if [ $STATUS != 0 ]; then 26 | echo "FAILED!" 27 | FAILED=$((FAILED+1)) 28 | else 29 | echo "OK" 30 | fi 31 | done 32 | 33 | echo "Ran $INCREMENT tests, $FAILED failed." 34 | 35 | exit 0 -------------------------------------------------------------------------------- /tests/generic/curl-ssl.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cat > curl-ssl.php <<'EOF' 4 | > changelog.md 56 | echo "Build number: ${{ github.run_number }}" >> changelog.md 57 | echo -e "\n\n\n" >> changelog.md 58 | echo ":information_source: **Linux/MacOS users**: Please see [this page](https://doc.pmmp.io/en/rtfd/faq/installation/opcache.so.html) to fix extension loading errors. Also, check out the [PocketMine-MP Linux/MacOS installer](https://doc.pmmp.io/en/rtfd/installation/get-dot-pmmp-dot-io.html)." >> changelog.md 59 | echo ":warning: **Windows users**: Don't forget to install [Visual C++ Redistributable](https://aka.ms/vs/17/release/vc_redist.x64.exe) or the binary will not work!" >> changelog.md 60 | echo -e "\n\n\n" >> changelog.md 61 | 62 | - name: Create release 63 | uses: ncipollo/release-action@v1.20.0 64 | with: 65 | artifacts: | 66 | ${{ github.workspace }}/*PHP-*-PM*/*.tar.gz 67 | ${{ github.workspace }}/*PHP-*-Windows-PM*/*.zip 68 | ${{ github.workspace }}/*PHP-*.gdbinit/*.gdbinit 69 | 70 | name: PHP (Build ${{ github.run_number }}) - Archive 71 | tag: php-build-${{ github.run_number }} 72 | commit: ${{ github.sha }} 73 | allowUpdates: false 74 | bodyFile: ${{ github.workspace }}/changelog.md 75 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHP binaries & PHP build scripts for PocketMine-MP 2 | [![Build status](https://github.com/pmmp/php-build-scripts/actions/workflows/main.yml/badge.svg)](https://github.com/pmmp/php-build-scripts/actions/workflows/main.yml) 3 | 4 | ## Prebuilt binaries 5 | ### Actively updated "latest" URLs 6 | - [PM5 default](https://github.com/pmmp/PHP-Binaries/releases/tag/pm5-latest) 7 | - [PM5 PHP 8.2](https://github.com/pmmp/PHP-Binaries/releases/tag/pm5-php-8.2-latest) (default for PM 5.10+) 8 | - [PM5 PHP 8.3](https://github.com/pmmp/PHP-Binaries/releases/tag/pm5-php-8.3-latest) (not officially supported, but works in PM 5.9+) 9 | - [PM5 PHP 8.4](https://github.com/pmmp/PHP-Binaries/releases/tag/pm5-php-8.4-latest) (not officially supported, but works in PM 5.33+) 10 | 11 | ### Legacy binaries, no longer updated 12 | - [PM4 PHP 8.0](https://github.com/pmmp/PHP-Binaries/releases/tag/pm4-php-8.0-latest) (default for PM 4.0+) 13 | - [PM4 PHP 8.1](https://github.com/pmmp/PHP-Binaries/releases/tag/pm4-php-8.1-latest) (default for PM 4.21+) 14 | - [PM4 PHP 8.2](https://github.com/pmmp/PHP-Binaries/releases/tag/pm4-php-8.2-latest) (never officially supported, but works in PM 4.12+) 15 | - [PM5 PHP 8.0](https://github.com/pmmp/PHP-Binaries/releases/tag/pm5-php-8.0-latest) (default for PM 5.0 alpha) 16 | - [PM5 PHP 8.1](https://github.com/pmmp/PHP-Binaries/releases/tag/pm5-php-8.1-latest) (default for PM 5.0+) 17 | 18 | ## compile.sh 19 | 20 | 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``. 21 | 22 | ### Recommendations 23 | - 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. 24 | - [`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`. 25 | - 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). 26 | 27 | ### Common pitfalls 28 | - Avoid using the script in directory trees containing spaces. Some libraries don't like trying to be built in directory trees containing spaces, e.g. `/home/user/my folder/pocketmine-mp/` might experience problems. 29 | - Avoid directory trees containing special (non-English) symbols. For example, `Développement` might cause issues. 30 | 31 | ### Additional notes 32 | #### Mac OSX (native compile) 33 | - Most dependencies can be installed using Homebrew 34 | - You will additionally need `glibtool` (GNU libtool, xcode libtool won't work) 35 | 36 | #### Android 64-bit (cross-compile) 37 | - Only aarch64 targets are supported for Android cross-compile. 38 | - 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) 39 | 40 | | Script flags | Description | 41 | |--------------|-------------------------------------------------------------------------------------------------------------| 42 | | -c | Uses the folder specified for caching downloaded tarballs, zipballs etc. | 43 | | -d | Compiles with debugging symbols and disables optimizations (slow, but useful for debugging segfaults) | 44 | | -D | Compiles with separated debugging symbols, but leaves optimizations enabled (used for distributed binaries) | 45 | | -g | Will compile GD2 | 46 | | -j | Set make threads to # | 47 | | -l | Uses the folder specified for caching compilation artifacts (useful for rapid rebuild and testing) | 48 | | -n | Don't remove sources after completing compilation | 49 | | -s | Will compile everything statically | 50 | | -t | Set target | 51 | | -v | Enable Valgrind support in PHP | 52 | | -x | Specifies we are doing cross-compile | 53 | | -P | Set target to the specified major PocketMine-MP version specified (currently only `5` is supported) | 54 | | -z | PHP version to build, e.g `8.2` (optional, if not specified, will be auto-selected by PM version) | 55 | 56 | ### Example: 57 | 58 | | Target | Arguments | 59 | |-----------------|-----------------------------------| 60 | | linux64 | ``-t linux64 -j4 -P5`` | 61 | | linux64, PM4 | ``-t linux64 -j4 -P4`` | 62 | | mac64 | ``-t mac-x86-64 -j4 -P5`` | 63 | | android-aarch64 | ``-t android-aarch64 -x -j4 -P5`` | 64 | 65 | ## windows-compile-vs.ps1 66 | 67 | Uses Visual Studio toolsets to compile PHP binaries on Windows. 68 | You need to install `git`, `cmake` and Visual Studio 2019 to use this script. 69 | 70 | This script doesn't accept parameters, but the following environment variables are influential: 71 | 72 | | Variable | Description | 73 | | -------- |---------------------------------------------------------------------------------------------------------------------| 74 | | `PHP_DEBUG_BUILD` | Disables optimisations and builds PHP with detailed debugging information (useful for debugging segfaults)| 75 | | `SOURCES_PATH` | Where to put the downloaded sources for compilation | 76 | | `PM_VERSION_MAJOR` | Major version of PocketMine-MP to build for (currently only `5` is supported) | 77 | | `PHP_VERSION_BASE` | PHP version to build, e.g `8.2` (optional, if not specified, will be auto-selected by PM version) | 78 | | `PHP_JIT_SUPPORT` | Whether to compile with OPcache JIT, set to `1` for yes | 79 | 80 | ## For developers: Version info sources 81 | ### Libraries 82 | 83 | | Link to package | Needed for | Notes | 84 | |:----------------|:-----------|:------| 85 | | [zlib](https://github.com/madler/zlib/tags) | Compression | | 86 | | [gmp](https://gmplib.org/) | Big integer math for Bedrock packet encryption | Hosted at [DependencyMirror](https://github.com/pmmp/DependencyMirror/releases) to avoid service outages | 87 | | [curl](https://github.com/curl/curl/releases) | Web requests | | 88 | | [libyaml](https://github.com/yaml/libyaml/releases) | Parsing YAML config files | | 89 | | [leveldb](https://github.com/pmmp/leveldb/commits/mojang-compatible/) | Bedrock world support | Custom version based on google/leveldb with minimum required changes to support MCPE worlds | 90 | | [libxml](https://gitlab.gnome.org/GNOME/libxml2/-/releases) | XML parsing support for UPnP | Hosted at [DependencyMirror](https://github.com/pmmp/DependencyMirror/releases) to avoid service outages | 91 | | [libpng](https://sourceforge.net/projects/libpng/files/libpng16/) | php-gd, plugin use only | Hosted at [DependencyMirror](https://github.com/pmmp/DependencyMirror/releases) to avoid service outages | 92 | | [libjpeg](https://ijg.org/) | php-gd, plugin use only | Hosted at [DependencyMirror](https://github.com/pmmp/DependencyMirror/releases) to avoid service outages | 93 | | [openssl](https://github.com/openssl/openssl/releases) | Bedrock packet encryption, secure web requests | | 94 | | [libzip](https://github.com/nih-at/libzip/releases) | Resource packs | | 95 | | [sqlite3](https://sqlite.org/download.html) | Plugin use only | Hosted at [DependencyMirror](https://github.com/pmmp/DependencyMirror/releases) to avoid service outages | 96 | | [libdeflate](https://github.com/ebiggers/libdeflate/blob/master/NEWS.md) | Faster alternative to zlib for network use | | 97 | | [pthreads4w](https://sourceforge.net/projects/pthreads4w/files/) | Needed by ext-pmmpthread on Windows | Hosted at [DependencyMirror](https://github.com/pmmp/DependencyMirror/releases) to avoid service outages | 98 | 99 | ### PHP & extensions 100 | 101 | | Link to package | Needed for | Notes | 102 | |:----------------|:-----------|:------| 103 | | [PHP](https://www.php.net/releases/?json&version=8.2) | Everything | Replace 8.2 in the URL with your chosen version | 104 | | [pmmpthread](https://github.com/pmmp/ext-pmmpthread/releases) | PHP threading | | 105 | | [yaml](https://github.com/php/pecl-file_formats-yaml/tags) | YAML config parsing | Yes, the mix of - and _ is intentional. Don't ask me. | 106 | | [leveldb](https://github.com/pmmp/php-leveldb/commits/pmmp-mojang-compatible/) | Bedrock world support | Custom version to provide `LEVELDB_ZLIB_RAW_COMPRESSION` support | 107 | | [chunkutils2](https://github.com/pmmp/ext-chunkutils2/releases) | `PalettedBlockArray` and other low-level stuff | | 108 | | [xdebug](https://github.com/xdebug/xdebug/releases) | Debugging | Not needed for production | 109 | | [igbinary](https://github.com/igbinary/igbinary/releases) | Faster serialization, mostly for moving stuff between threads | Non-essential, could be ditched if necessary | 110 | | [crypto](https://github.com/bukka/php-crypto/tags) | Bedrock packet encryption | | 111 | | [recursionguard](https://github.com/pmmp/ext-recursionguard/releases) | Debugging | Not needed for production | 112 | | [libdeflate](https://github.com/pmmp/ext-libdeflate/releases) | Faster network compression | Non-essential but provides significant performance advantage over zlib | 113 | | [morton](https://github.com/pmmp/ext-morton) | Packing X/Z and X/Y/Z coordinates into ints in a format suitable for PHP array keys | Needed for performance | 114 | | [xxhash](https://github.com/pmmp/ext-xxhash/releases) | Not currently used | Could be replaced by `hash()` in recent versions of PHP but this extension has much better performance | 115 | | [arraydebug](https://github.com/pmmp/ext-arraydebug/tags) | Debugging array hash collisions | | 116 | | [encoding](https://github.com/pmmp/ext-encoding/releases) | Disk & network data encoding & decoding | Significantly faster alternative to [BinaryUtils](https://github.com/pmmp/BinaryUtils) | 117 | 118 | ### Misc 119 | 120 | | Link to package | Needed for | Notes | 121 | |:----------------|:-----------|:------| 122 | | [php-sdk-binary-tools](https://github.com/php/php-sdk-binary-tools/releases) | Building PHP on Windows | | 123 | -------------------------------------------------------------------------------- /.github/workflows/main-pm-matrix.yml: -------------------------------------------------------------------------------- 1 | name: Build PHP binaries 2 | 3 | on: 4 | workflow_call: 5 | inputs: 6 | pm-version-major: 7 | description: 'PocketMine-MP major version' 8 | required: true 9 | type: number 10 | php-version-base: 11 | description: 'PHP base version' 12 | required: true 13 | type: string 14 | special-release: 15 | description: 'Special release type to create (pm-default-latest, pm-default, none)' 16 | required: true 17 | type: string 18 | pm-preview: 19 | description: "Mark releases as pre-release" 20 | required: true 21 | type: boolean 22 | 23 | env: 24 | MUSL_CROSS_MAKE_VERSION: 43fcb1e63786b96add78f89d7454709ae0159fa0 25 | 26 | jobs: 27 | android: 28 | name: Android arm64 29 | runs-on: ubuntu-22.04 30 | 31 | steps: 32 | - uses: actions/checkout@v5 33 | 34 | - name: Install tools and dependencies 35 | run: | 36 | sudo apt-get update 37 | sudo apt-get install make autoconf automake libtool libtool-bin m4 wget libc-bin gzip bzip2 bison g++ git re2c 38 | 39 | - name: Prepare compile.sh download cache 40 | id: download-cache 41 | uses: actions/cache@v4 42 | with: 43 | path: ./download_cache 44 | key: compile-sh-cache-ssl-https-${{ hashFiles('./compile.sh') }} 45 | restore-keys: compile-sh-cache-ssl-https- 46 | 47 | - name: Fetch compiler cache 48 | id: compiler-cache 49 | uses: actions/cache@v4 50 | with: 51 | path: ${{ github.workspace }}/compiler 52 | key: musl-cross-make-${{ env.MUSL_CROSS_MAKE_VERSION }} 53 | 54 | - name: Checkout musl-cross-make 55 | if: steps.compiler-cache.outputs.cache-hit != 'true' 56 | uses: actions/checkout@v5 57 | with: 58 | repository: pmmp/musl-cross-make 59 | path: musl-cross-make 60 | ref: ${{ env.MUSL_CROSS_MAKE_VERSION }} 61 | 62 | - name: Build compiler 63 | if: steps.compiler-cache.outputs.cache-hit != 'true' 64 | working-directory: musl-cross-make 65 | run: | 66 | echo "TARGET = aarch64-linux-musl" > config.mak 67 | make -j$(nproc) 68 | make install 69 | mv ./output "${{ github.workspace }}/compiler" 70 | 71 | - name: Compile PHP 72 | run: | 73 | export PATH="${{ github.workspace }}/compiler/bin:$PATH" 74 | 75 | # Used "set -ex" instead of hashbang since script isn't executed with hashbang 76 | set -ex 77 | trap "exit 1" ERR 78 | ./compile.sh -t android-aarch64 -x -j 4 -g -P ${{ inputs.pm-version-major }} -c ./download_cache -D -z ${{ inputs.php-version-base }} 79 | 80 | 81 | - name: Create tarball 82 | run: | 83 | tar -czf ./PHP-${{ inputs.php-version-base }}-Android-arm64-PM${{ inputs.pm-version-major }}.tar.gz bin 84 | tar -czf ./Z-PHP-${{ inputs.php-version-base }}-Android-arm64-PM${{ inputs.pm-version-major }}-debugging-symbols.tar.gz bin-debug 85 | 86 | - name: Upload artifacts 87 | uses: actions/upload-artifact@v5 88 | if: always() 89 | with: 90 | name: PHP-${{ inputs.php-version-base }}-Android-PM${{ inputs.pm-version-major }} 91 | path: | 92 | ./*PHP-${{ inputs.php-version-base }}-Android-arm64-PM${{ inputs.pm-version-major }}*.tar.gz 93 | install.log 94 | compile.sh 95 | if-no-files-found: error 96 | 97 | - name: Prepare workspace for upload 98 | if: failure() 99 | run: tar -czf workspace.tar.gz install_data 100 | 101 | - name: Upload workspace 102 | uses: actions/upload-artifact@v5 103 | if: failure() 104 | with: 105 | name: PHP-${{ inputs.php-version-base }}-Android-workspace-PM${{ inputs.pm-version-major }} 106 | path: | 107 | workspace.tar.gz 108 | if-no-files-found: error 109 | 110 | linux: 111 | name: Linux 112 | runs-on: ubuntu-22.04 113 | 114 | steps: 115 | - uses: actions/checkout@v5 116 | 117 | - name: Install tools and dependencies 118 | run: | 119 | sudo apt-get update 120 | sudo apt-get install make autoconf automake libtool libtool-bin m4 wget libc-bin gzip bzip2 bison g++ git re2c 121 | 122 | - name: Prepare compile.sh download cache 123 | id: download-cache 124 | uses: actions/cache@v4 125 | with: 126 | path: ./download_cache 127 | key: compile-sh-cache-ssl-https-${{ hashFiles('./compile.sh') }} 128 | restore-keys: compile-sh-cache-ssl-https- 129 | 130 | - name: Compile PHP 131 | run: | 132 | # Used "set -ex" instead of hashbang since script isn't executed with hashbang 133 | set -ex 134 | trap "exit 1" ERR 135 | ./compile.sh -t linux64 -j 4 -g -P ${{ inputs.pm-version-major }} -c ./download_cache -D -z ${{ inputs.php-version-base }} 136 | 137 | - name: Create tarball 138 | run: | 139 | tar -czf ./PHP-${{ inputs.php-version-base }}-Linux-x86_64-PM${{ inputs.pm-version-major }}.tar.gz bin 140 | tar -czf ./Z-PHP-${{ inputs.php-version-base }}-Linux-x86_64-PM${{ inputs.pm-version-major }}-debugging-symbols.tar.gz bin-debug 141 | 142 | - name: Upload artifacts 143 | uses: actions/upload-artifact@v5 144 | if: always() 145 | with: 146 | name: PHP-${{ inputs.php-version-base }}-Linux-PM${{ inputs.pm-version-major }} 147 | path: | 148 | ./*PHP-${{ inputs.php-version-base }}-Linux-x86_64-PM${{ inputs.pm-version-major }}*.tar.gz 149 | install.log 150 | compile.sh 151 | if-no-files-found: error 152 | 153 | - name: Prepare workspace for upload 154 | if: failure() 155 | run: tar -czf workspace.tar.gz install_data 156 | 157 | - name: Upload workspace 158 | uses: actions/upload-artifact@v5 159 | if: failure() 160 | with: 161 | name: PHP-${{ inputs.php-version-base }}-Linux-workspace-PM${{ inputs.pm-version-major }} 162 | path: | 163 | workspace.tar.gz 164 | if-no-files-found: error 165 | 166 | macos: 167 | name: MacOS ${{ matrix.artifact-name }} 168 | runs-on: ${{ matrix.image }} 169 | strategy: 170 | matrix: 171 | include: 172 | - target-name: mac-x86-64 173 | artifact-name: x86_64 174 | image: macos-13 175 | - target-name: mac-arm64 176 | artifact-name: arm64 177 | image: macos-14 178 | 179 | steps: 180 | - uses: actions/checkout@v5 181 | 182 | - name: Install tools and dependencies 183 | run: | 184 | #workaround github actions default image providing outdated pkg-config 185 | brew uninstall --ignore-dependencies --force pkg-config@0.29.2 || true 186 | brew install libtool autoconf automake pkg-config bison re2c 187 | 188 | - name: Prepare compile.sh download cache 189 | id: download-cache 190 | uses: actions/cache@v4 191 | with: 192 | path: ./download_cache 193 | key: compile-sh-cache-ssl-https-${{ hashFiles('./compile.sh') }} 194 | restore-keys: compile-sh-cache-ssl-https- 195 | 196 | - name: Compile PHP 197 | run: | 198 | export PATH="/usr/local/opt/bison/bin:$PATH" 199 | set -ex 200 | trap "exit 1" ERR 201 | ./compile.sh -t ${{ matrix.target-name }} -j4 -g -P ${{ inputs.pm-version-major }} -c ./download_cache -D -z ${{ inputs.php-version-base }} 202 | 203 | - name: Create tarball 204 | run: | 205 | tar -czf ./PHP-${{ inputs.php-version-base }}-MacOS-${{ matrix.artifact-name }}-PM${{ inputs.pm-version-major }}.tar.gz bin 206 | tar -czf ./Z-PHP-${{ inputs.php-version-base }}-MacOS-${{ matrix.artifact-name }}-PM${{ inputs.pm-version-major }}-debugging-symbols.tar.gz bin-debug 207 | 208 | - name: Upload artifacts 209 | uses: actions/upload-artifact@v5 210 | if: always() 211 | with: 212 | name: PHP-${{ inputs.php-version-base }}-MacOS-${{ matrix.artifact-name }}-PM${{ inputs.pm-version-major }} 213 | path: | 214 | ./*PHP-${{ inputs.php-version-base }}-MacOS-${{ matrix.artifact-name}}-PM${{ inputs.pm-version-major }}*.tar.gz 215 | install.log 216 | compile.sh 217 | if-no-files-found: error 218 | 219 | - name: Prepare workspace for upload 220 | if: failure() 221 | run: tar -czf workspace.tar.gz install_data 222 | 223 | - name: Upload workspace 224 | uses: actions/upload-artifact@v5 225 | if: failure() 226 | with: 227 | name: PHP-${{ inputs.php-version-base }}-MacOS-${{ matrix.artifact-name }}-workspace-PM${{ inputs.pm-version-major }} 228 | path: | 229 | workspace.tar.gz 230 | if-no-files-found: error 231 | 232 | windows: 233 | name: Windows 234 | runs-on: windows-2022 235 | 236 | steps: 237 | - uses: actions/checkout@v5 238 | 239 | - name: Prepare download cache 240 | id: download-cache 241 | uses: actions/cache@v4 242 | with: 243 | path: ./download_cache 244 | key: windows-cache-${{ hashFiles('./windows-compile-vs.ps1') }} 245 | restore-keys: windows-cache- 246 | 247 | - name: Compile PHP 248 | run: .\windows-compile-vs.ps1 249 | env: 250 | SOURCES_PATH: ${{ github.workspace }}\pocketmine-php-sdk 251 | PM_VERSION_MAJOR: ${{ inputs.pm-version-major }} 252 | PHP_VERSION_BASE: ${{ inputs.php-version-base }} 253 | 254 | - name: Prepare artifacts 255 | run: | 256 | mkdir temp 257 | Compress-Archive -Path .\bin -DestinationPath "PHP-${{ inputs.php-version-base }}-Windows-x64-PM${{ inputs.pm-version-major }}.zip" 258 | move php-debug-pack-*.zip temp/Z-PHP-${{ inputs.php-version-base }}-Windows-x64-PM${{ inputs.pm-version-major }}-debugging-symbols.zip 259 | move temp\*.zip . 260 | 261 | - name: Upload artifacts 262 | uses: actions/upload-artifact@v5 263 | if: always() 264 | with: 265 | name: PHP-${{ inputs.php-version-base }}-Windows-PM${{ inputs.pm-version-major }} 266 | path: | 267 | *PHP-${{ inputs.php-version-base }}-Windows-x64-PM${{ inputs.pm-version-major }}*.zip 268 | compile.log 269 | windows-compile-vs.bat 270 | if-no-files-found: error 271 | 272 | 273 | publish: 274 | name: Publish binaries 275 | needs: [linux, macos, windows, android] 276 | runs-on: ubuntu-22.04 277 | if: ${{ github.ref_name == 'stable' && github.ref_type == 'branch' && !contains(github.event.head_commit.message, '[no release]') }} 278 | concurrency: release-${{ inputs.php-version-base }}-pm${{ inputs.pm-version-major }} 279 | 280 | permissions: 281 | contents: write 282 | 283 | steps: 284 | - uses: actions/checkout@v5 285 | 286 | - name: Update latest tag target 287 | run: | 288 | git tag -f pm${{ inputs.pm-version-major }}-php-${{ inputs.php-version-base }}-latest 289 | git push -f origin pm${{ inputs.pm-version-major }}-php-${{ inputs.php-version-base }}-latest 290 | git tag -f pm${{ inputs.pm-version-major }}-latest 291 | git push -f origin pm${{ inputs.pm-version-major }}-latest 292 | 293 | - name: Download artifacts 294 | uses: actions/download-artifact@v6 295 | with: 296 | path: ${{ github.workspace }} 297 | pattern: "*PHP-${{ inputs.php-version-base }}-*-PM${{ inputs.pm-version-major }}" 298 | 299 | - name: Download .gdbinit for this PHP version 300 | run: | 301 | curl -L https://raw.githubusercontent.com/php/php-src/refs/heads/PHP-${{ inputs.php-version-base }}/.gdbinit -o Z-PHP-${{ inputs.php-version-base }}.gdbinit 302 | 303 | - name: Upload .gdbinit artifact 304 | uses: actions/upload-artifact@v5 305 | with: 306 | name: PHP-${{ inputs.php-version-base }}.gdbinit 307 | path: | 308 | ${{ github.workspace }}/*.gdbinit 309 | 310 | - name: Generate release notes 311 | run: | 312 | echo "### PHP ${{ inputs.php-version-base }} for PocketMine-MP ${{ inputs.pm-version-major }}.x" > changelog.md 313 | echo "Last updated on **$(date -u +'%d %b %Y at %H:%M:%S %Z')**" >> changelog.md 314 | echo -e "\n\n" >> changelog.md 315 | echo "Built by: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> changelog.md 316 | echo "Build number: ${{ github.run_number }}" >> changelog.md 317 | echo -e "\n\n\n" >> changelog.md 318 | echo ":information_source: **Linux/MacOS users**: Please see [this page](https://doc.pmmp.io/en/rtfd/faq/installation/opcache.so.html) to fix extension loading errors. Also, check out the [PocketMine-MP Linux/MacOS installer](https://doc.pmmp.io/en/rtfd/installation/get-dot-pmmp-dot-io.html)." >> changelog.md 319 | echo ":warning: **Windows users**: Don't forget to install [Visual C++ Redistributable](https://aka.ms/vs/17/release/vc_redist.x64.exe) or the binary will not work!" >> changelog.md 320 | echo -e "\n\n\n" >> changelog.md 321 | 322 | if [[ "${{ inputs.special-release }}" != "none" ]]; then 323 | echo ":white_check_mark: At the time of publication, this version is recommended for PocketMine-MP ${{ inputs.pm-version-major }}.x production servers." >> changelog.md 324 | else 325 | echo ":warning: WARNING! :warning:" >> changelog.md 326 | echo "At the time of publication, plugins for PocketMine-MP ${{ inputs.pm-version-major }}.x may not work this PHP version." >> changelog.md 327 | echo "If you have problems, try the [recommended PM${{ inputs.pm-version-major }} release](${{ github.server_url }}/${{ github.repository }}/releases/pm${{ inputs.pm-version-major }}-latest) instead." >> changelog.md 328 | fi 329 | 330 | - name: Get date 331 | id: date 332 | run: | 333 | echo DATE=$(date -u +'%d %b %Y') >> $GITHUB_OUTPUT 334 | 335 | - name: Update recommended PM release 336 | uses: ncipollo/release-action@v1.20.0 337 | if: ${{ inputs.special-release != 'none' }} 338 | with: 339 | artifacts: | 340 | ${{ github.workspace }}/*PHP-*-PM*/*.tar.gz 341 | ${{ github.workspace }}/*PHP-*-Windows-PM*/*.zip 342 | ${{ github.workspace }}/*.gdbinit 343 | name: PM ${{ inputs.pm-version-major }}.x (${{ steps.date.outputs.DATE }}) - Recommended 344 | tag: pm${{ inputs.pm-version-major }}-latest 345 | commit: ${{ github.sha }} 346 | allowUpdates: true 347 | removeArtifacts: true 348 | bodyFile: ${{ github.workspace }}/changelog.md 349 | makeLatest: ${{ inputs.special-release == 'default-latest' }} 350 | prerelease: ${{ inputs.pm-preview == true }} 351 | 352 | - name: Update php-version PM release 353 | uses: ncipollo/release-action@v1.20.0 354 | with: 355 | artifacts: | 356 | ${{ github.workspace }}/*PHP-*-PM*/*.tar.gz 357 | ${{ github.workspace }}/*PHP-*-Windows-PM*/*.zip 358 | ${{ github.workspace }}/*.gdbinit 359 | name: PM ${{ inputs.pm-version-major }}.x (${{ steps.date.outputs.DATE }}) - PHP ${{ inputs.php-version-base }} 360 | tag: pm${{ inputs.pm-version-major }}-php-${{ inputs.php-version-base }}-latest 361 | commit: ${{ github.sha }} 362 | allowUpdates: true 363 | removeArtifacts: true 364 | bodyFile: ${{ github.workspace }}/changelog.md 365 | makeLatest: false 366 | prerelease: ${{ inputs.pm-preview == true }} 367 | 368 | -------------------------------------------------------------------------------- /windows-compile-vs.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference="Stop" 2 | $ProgressPreference="SilentlyContinue" 3 | 4 | $PHP_VERSIONS=@("8.1.33", "8.2.29", "8.3.27", "8.4.14", "8.5.0RC3") 5 | 6 | $PHP_SDK_VER="2.4.0" 7 | $ARCH="x64" 8 | 9 | #### NOTE: Tags with "v" prefixes behave weirdly in the GitHub API. They'll be stripped in some places but not others. 10 | #### Use commit hashes to avoid this. 11 | 12 | $LIBYAML_VER="0.2.5" 13 | $PTHREAD_W32_VER="3.0.0" 14 | $LEVELDB_MCPE_VER="1c7564468b41610da4f498430e795ca4de0931ff" #release not tagged 15 | $LIBDEFLATE_VER="96836d7d9d10e3e0d53e6edb54eb908514e336c4" #1.24 - see above note about "v" prefixes 16 | 17 | $PHP_PMMPTHREAD_VER="6.2.0" 18 | $PHP_YAML_VER="2.2.5" 19 | $PHP_CHUNKUTILS2_VER="0.3.5" 20 | $PHP_IGBINARY_VER="3.2.16" 21 | $PHP_LEVELDB_VER="88071eb1b1eae96af043229104b9d813f7cbe40c" #release not tagged 22 | $PHP_CRYPTO_VER="999b3c7edbc7f8ca4fdeb0bb4bbae488ad0daf07" #release not tagged 23 | $PHP_RECURSIONGUARD_VER="0.1.0" 24 | $PHP_MORTON_VER="0.1.2" 25 | $PHP_LIBDEFLATE_VER="0.2.1" 26 | $PHP_XXHASH_VER="0.2.0" 27 | $PHP_XDEBUG_VER="3.4.7" 28 | $PHP_ARRAYDEBUG_VER="0.2.1" 29 | $PHP_ENCODING_VER="1.0.0" 30 | 31 | $PHP_PMMPTHREAD_VER_PHP85="4aa34a27feaa43adba5f1e93939828d1d7afdefc" 32 | $PHP_IGBINARY_VER_PHP85="8f8b7175c7859f1845bcdee6f7d0baeea7d07cb8" 33 | $PHP_XDEBUG_VER_PHP85="b8bc9425390ca7745abdc715a359d2f369c1a07b" #needs https://github.com/xdebug/xdebug/pull/1040 because of glob changes 34 | 35 | function pm-echo { 36 | param ([string] $message) 37 | 38 | echo "[PocketMine] $message" 39 | echo "[PocketMine] $message" >> "$log_file" 40 | } 41 | 42 | function pm-echo-error { 43 | param ([string] $message) 44 | 45 | pm-echo "[ERROR] $message" 46 | } 47 | 48 | function pm-fatal-error { 49 | param ([string] $message) 50 | 51 | pm-echo-error $message 52 | exit 1 53 | } 54 | 55 | $library = "" 56 | $library_version = "" 57 | function write-library { 58 | param ([string] $library, [string] $version) 59 | 60 | Write-Host -NoNewline "[$library $version]" 61 | $script:library = $library 62 | $script:library_version = $version 63 | } 64 | function write-status { 65 | param ([string] $status) 66 | 67 | Write-Host -NoNewline " $status..." 68 | echo "[$library $library_version] $status..." >> $log_file 69 | } 70 | function write-download { 71 | write-status "downloading" 72 | } 73 | function write-extracting { 74 | write-status "extracting" 75 | } 76 | function write-configure { 77 | write-status "configuring" 78 | } 79 | function write-compile { 80 | write-status "compiling" 81 | } 82 | function write-install { 83 | write-status "installing" 84 | } 85 | function write-done { 86 | echo " done!" 87 | $script:library = "" 88 | $script:library_version = "" 89 | } 90 | function write-cached { 91 | write-status "using cache" 92 | } 93 | 94 | $log_file="$pwd\compile.log" 95 | echo "" > "$log_file" 96 | $outpath="$pwd" 97 | 98 | pm-echo "PHP compiler for Windows" 99 | date >> "$log_file" 100 | 101 | pm-echo "Checking dependencies" 102 | 103 | $script_dependencies = @("git", "cmake") 104 | foreach ($dep in $script_dependencies) { 105 | $depInfo = Get-Command "$dep" -ErrorAction SilentlyContinue 106 | if ($depInfo -eq $null) { 107 | pm-fatal-error "$dep is required but can't be found in your PATH" 108 | } else { 109 | pm-echo "Found $dep in $($depInfo.Source)" 110 | } 111 | } 112 | 113 | 114 | 115 | pm-echo "Checking configuration options" 116 | 117 | $PHP_VERSION_BASE="auto" 118 | $PHP_VER="" 119 | if ($env:PHP_VERSION_BASE -ne $null) { 120 | $PHP_VERSION_BASE=$env:PHP_VERSION_BASE 121 | } 122 | 123 | $PHP_DEBUG_BUILD=0 124 | if ($env:PHP_DEBUG_BUILD -eq 1) { 125 | $PHP_DEBUG_BUILD=1 126 | } 127 | 128 | $MSBUILD_CONFIGURATION="RelWithDebInfo" 129 | 130 | if ($PHP_DEBUG_BUILD -eq 0) { 131 | $OUT_PATH_REL="Release" 132 | $PHP_HAVE_DEBUG="enable-debug-pack" 133 | pm-echo "Building release binaries with debugging symbols" 134 | } else { 135 | $OUT_PATH_REL="Debug" 136 | $PHP_HAVE_DEBUG="enable-debug" 137 | 138 | #I don't like this, but YAML will crash if it's not built with the same target as PHP 139 | $MSBUILD_CONFIGURATION="Debug" 140 | pm-echo "Building debug binaries" 141 | } 142 | 143 | 144 | function php-version-id { 145 | param ([string] $version) 146 | 147 | $parts = $version.Split(".") 148 | 149 | #TODO: patch is a pain because of suffixes and we don't really need it anyway 150 | $result = (([int]$parts[0]) * 10000) + (([int]$parts[1]) * 100) 151 | return $result 152 | } 153 | 154 | $PREFERRED_PHP_VERSION_BASE="" 155 | switch ($env:PM_VERSION_MAJOR) { 156 | 5 { $PREFERRED_PHP_VERSION_BASE="8.2" } 157 | $null { pm-fatal-error "Please specify PocketMine-MP major version by setting the PM_VERSION_MAJOR environment variable" } 158 | default { pm-fatal-error "PocketMine-MP $PM_VERSION_MAJOR is not supported by this version of the build script" } 159 | } 160 | 161 | $PM_VERSION_MAJOR=$env:PM_VERSION_MAJOR 162 | pm-echo "Compiling with configuration for PocketMine-MP $PM_VERSION_MAJOR" 163 | 164 | if ($PHP_VERSION_BASE -eq "auto") { 165 | $PHP_VERSION_BASE=$PREFERRED_PHP_VERSION_BASE 166 | } elseif ($PHP_VERSION_BASE -ne $PREFERRED_PHP_VERSION_BASE) { 167 | pm-echo "[WARNING] $PHP_VERSION_BASE is not the default for PocketMine-MP $PM_VERSION_MAJOR" 168 | pm-echo "[WARNING] The build may fail, or you may not be able to use the resulting PHP binary" 169 | } 170 | 171 | foreach ($version in $PHP_VERSIONS) { 172 | if ($version -like "$PHP_VERSION_BASE.*") { 173 | $PHP_VER=$version 174 | break 175 | } 176 | } 177 | if ($PHP_VER -eq "") { 178 | pm-echo-error "Unsupported PHP base version $PHP_VERSION_BASE" 179 | pm-echo-error "Example inputs: 8.2, 8.3" 180 | exit 1 181 | } 182 | 183 | #don't really need these except for dev versions 184 | $PHP_GIT_REV="php-$PHP_VER" 185 | $PHP_DISPLAY_VER="$PHP_VER" 186 | 187 | $CMAKE_TARGET="Visual Studio 17 2022" 188 | 189 | $VC_VER="" 190 | $SDL_TOOLSET_FLAG="" 191 | $CMAKE_TOOLSET_FLAG="" 192 | 193 | $PHP_VERSION_ID = php-version-id $PHP_VER 194 | if ($PHP_VERSION_ID -ge 80400) { 195 | $VC_VER="vs17" 196 | $SDK_TOOLSET_FLAG="" 197 | $CMAKE_TOOLSET_FLAG="" 198 | } else { 199 | #technically it's fine to build <8.4 with vs17, but this would make the binaries ABI-incompatible with community prebuilt extensions 200 | $VC_VER="vs16" 201 | $SDK_TOOLSET_FLAG="-s=14.29" 202 | $CMAKE_TOOLSET_FLAG="-T v142" 203 | } 204 | 205 | pm-echo "Selected PHP $PHP_VER ($PHP_VERSION_ID), SDK target $VC_VER ($SDK_TOOLSET_FLAG), CMake target $CMAKE_TARGET ($CMAKE_TOOLSET_FLAG)" 206 | 207 | if ($PHP_VERSION_ID -ge 80500) { 208 | $PHP_PMMPTHREAD_VER=$PHP_PMMPTHREAD_VER_PHP85 209 | $PHP_IGBINARY_VER=$PHP_IGBINARY_VER_PHP85 210 | $PHP_XDEBUG_VER=$PHP_XDEBUG_VER_PHP85 211 | } 212 | $PHP_JIT_ENABLE_ARG="no" 213 | if ($PHP_VERSION_ID -ge 80400 -or $env:PHP_JIT_SUPPORT -eq 1) { 214 | $PHP_JIT_ENABLE_ARG="yes" 215 | } 216 | 217 | if ($PHP_JIT_ENABLE_ARG -eq "yes") { 218 | if ($PHP_VERSION_ID -lt 80400) { 219 | pm-echo "[WARNING] JIT in versions below PHP 8.4 is highly unstable and not recommended" 220 | } else { 221 | pm-echo "[WARNING] JIT in PHP 8.4 has not been tested, use it with caution" 222 | } 223 | } else { 224 | pm-echo "JIT support in OPcache won't be compiled" 225 | } 226 | 227 | if ($env:SOURCES_PATH -ne $null) { 228 | $BASE_PATH=$env:SOURCES_PATH 229 | } else { 230 | $BASE_PATH="C:\pocketmine-php" 231 | } 232 | $PHP_SDK_PATH="$BASE_PATH\php-sdk-binary-tools-$PHP_SDK_VER" 233 | $SOURCES_PATH="$BASE_PATH\php-$PHP_DISPLAY_VER-$($OUT_PATH_REL.ToLower())" 234 | 235 | pm-echo "Using path $SOURCES_PATH for PHP build sources" 236 | if (-not (Test-Path "$BASE_PATH")) { 237 | mkdir "$BASE_PATH" >> $log_file 2>&1 238 | } 239 | 240 | if (Test-Path "$pwd\bin") { 241 | pm-echo "Deleting old binary folder..." 242 | Remove-Item -Recurse -Force "$pwd\bin" 2>&1 243 | } 244 | if (Test-Path $SOURCES_PATH) { 245 | pm-echo "Deleting old PHP build workspace $SOURCES_PATH..." 246 | Remove-Item -Recurse -Force $SOURCES_PATH 2>&1 247 | } 248 | $LIB_BUILD_DIR="$BASE_PATH\deps-build-php-$PHP_VERSION_BASE-$($OUT_PATH_REL.ToLower())" 249 | 250 | if (Test-Path "$LIB_BUILD_DIR") { 251 | pm-echo "Deleting old deps build workspace $LIB_BUILD_DIR..." 252 | Remove-Item -Recurse -Force "$LIB_BUILD_DIR" >> $log_file 2>&1 253 | } 254 | 255 | $download_cache="$pwd\download_cache" 256 | function download-file { 257 | param ([string] $url, [string] $prefix) 258 | 259 | $cached_filename="$prefix-$($url.Substring($url.LastIndexOf("/") + 1))" 260 | $cached_path="$download_cache\$cached_filename" 261 | 262 | if (!(Test-Path $download_cache)) { 263 | mkdir $download_cache >> $log_file 2>&1 264 | } 265 | 266 | if (Test-Path $cached_path) { 267 | echo "Cache hit for URL: $url" >> $log_file 268 | } else { 269 | echo "Downloading file from $url to $cached_path" >> $log_file 270 | #download to a tmpfile first, so that we don't leave borked cache entries for later runs 271 | Invoke-WebRequest -Uri $url -OutFile "$download_cache/.temp" >> $log_file 2>&1 272 | Move-Item "$download_cache/.temp" $cached_path >> $log_file 2>&1 273 | } 274 | if (!(Test-Path $cached_path)) { 275 | pm-fatal-error "Failed to download file from $url" 276 | } 277 | 278 | return $cached_path 279 | } 280 | 281 | function unzip-file { 282 | param ([string] $file, [string] $destination) 283 | 284 | #expand-archive doesn't respect script-local ProgressPreference 285 | #https://github.com/PowerShell/Microsoft.PowerShell.Archive/issues/77 286 | $oldProgressPref = $global:ProgressPreference 287 | $global:ProgressPreference = "SilentlyContinue" 288 | Expand-Archive -Path $file -DestinationPath $destination >> $log_file 2>&1 289 | $global:ProgressPreference = $oldProgressPref 290 | } 291 | 292 | 293 | function append-file-utf8 { 294 | param ([string] $line, [string] $file) 295 | 296 | Out-File -Append -FilePath $file -Encoding utf8 -InputObject $line 297 | } 298 | 299 | function download-sdk { 300 | write-library "PHP SDK" $PHP_SDK_VER 301 | 302 | if (Test-Path "$PHP_SDK_PATH") { 303 | write-cached 304 | } else { 305 | write-download 306 | $file = download-file "https://github.com/php/php-sdk-binary-tools/archive/refs/tags/php-sdk-$PHP_SDK_VER.zip" "php-sdk" 307 | write-extracting 308 | unzip-file $file $pwd 309 | Move-Item "php-sdk-binary-tools-php-sdk-$PHP_SDK_VER" $PHP_SDK_PATH 310 | } 311 | write-done 312 | } 313 | 314 | function sdk-command { 315 | param ([string] $command, [string] $errorMessage = "") 316 | 317 | New-Item task.bat -Value $command >> $log_file 2>&1 318 | echo "Running SDK command: $command" >> $log_file 319 | $wrap = "`"$PHP_SDK_PATH\phpsdk-starter.bat`" -c $VC_VER -a $ARCH $SDK_TOOLSET_FLAG -t task.bat 2>&1" 320 | echo "SDK wrapper command: $wrap" >> $log_file 321 | (& cmd.exe /c $wrap) >> $log_file 322 | $result=$LASTEXITCODE 323 | if ($result -ne 0) { 324 | if ($errorMessage -eq "") { 325 | pm-fatal-error "Error code $result running SDK build command" 326 | } else { 327 | pm-fatal-error $errorMessage 328 | } 329 | } 330 | Remove-Item task.bat 331 | } 332 | 333 | function download-php-deps { 334 | write-library "PHP prebuilt deps" "$PHP_VERSION_BASE/$VC_VER" 335 | write-download 336 | sdk-command "phpsdk_deps -u -t $VC_VER -b $PHP_VERSION_BASE -a $ARCH -d $DEPS_DIR || exit 1" 337 | write-done 338 | } 339 | 340 | function build-yaml { 341 | write-library "yaml" $LIBYAML_VER 342 | write-download 343 | $file = download-file "https://github.com/yaml/libyaml/archive/$LIBYAML_VER.zip" "yaml" 344 | write-extracting 345 | unzip-file $file $pwd 346 | Move-Item "libyaml-$LIBYAML_VER" libyaml >> $log_file 2>&1 347 | Push-Location libyaml 348 | 349 | write-configure 350 | sdk-command "cmake -G `"$CMAKE_TARGET`" $CMAKE_TOOLSET_FLAG^` 351 | -DCMAKE_PREFIX_PATH=`"$DEPS_DIR`"^` 352 | -DCMAKE_INSTALL_PREFIX=`"$DEPS_DIR`"^` 353 | -DBUILD_SHARED_LIBS=ON^` 354 | `"$pwd`" || exit 1" 355 | write-compile 356 | sdk-command "msbuild ALL_BUILD.vcxproj /p:Configuration=$MSBUILD_CONFIGURATION /m || exit 1" 357 | write-install 358 | sdk-command "msbuild INSTALL.vcxproj /p:Configuration=$MSBUILD_CONFIGURATION /m || exit 1" 359 | Copy-Item "$MSBUILD_CONFIGURATION\yaml.pdb" "$DEPS_DIR\bin" >> $log_file 2>&1 360 | write-done 361 | Pop-Location 362 | } 363 | 364 | function build-pthreads4w { 365 | write-library "pthreads4w" $PTHREAD_W32_VER 366 | write-download 367 | $file = download-file "https://github.com/pmmp/DependencyMirror/releases/download/mirror/pthreads4w-code-v$PTHREAD_W32_VER.zip" "pthreads4w" 368 | write-extracting 369 | unzip-file $file $pwd 370 | Move-Item "pthreads4w-code-*" pthreads4w >> $log_file 2>&1 371 | Push-Location pthreads4w 372 | 373 | write-compile 374 | sdk-command "nmake VC || exit 1" 375 | 376 | write-install 377 | Copy-Item "pthread.h" "$DEPS_DIR\include" >> $log_file 2>&1 378 | Copy-Item "sched.h" "$DEPS_DIR\include" >> $log_file 2>&1 379 | Copy-Item "semaphore.h" "$DEPS_DIR\include" >> $log_file 2>&1 380 | Copy-Item "_ptw32.h" "$DEPS_DIR\include" >> $log_file 2>&1 381 | Copy-Item "pthreadVC3.lib" "$DEPS_DIR\lib" >> $log_file 2>&1 382 | Copy-Item "pthreadVC3.dll" "$DEPS_DIR\bin" >> $log_file 2>&1 383 | Copy-Item "pthreadVC3.pdb" "$DEPS_DIR\bin" >> $log_file 2>&1 384 | write-done 385 | Pop-Location 386 | } 387 | 388 | function build-leveldb { 389 | write-library "leveldb" $LEVELDB_MCPE_VER 390 | write-download 391 | $file = download-file "https://github.com/pmmp/leveldb/archive/$LEVELDB_MCPE_VER.zip" "leveldb" 392 | write-extracting 393 | unzip-file $file $pwd 394 | Move-Item leveldb-* leveldb >> $log_file 2>&1 395 | Push-Location leveldb 396 | 397 | write-configure 398 | sdk-command "cmake -G `"$CMAKE_TARGET`" $CMAKE_TOOLSET_FLAG^` 399 | -DCMAKE_PREFIX_PATH=`"$DEPS_DIR`"^` 400 | -DCMAKE_INSTALL_PREFIX=`"$DEPS_DIR`"^` 401 | -DBUILD_SHARED_LIBS=ON^` 402 | -DLEVELDB_BUILD_BENCHMARKS=OFF^` 403 | -DLEVELDB_BUILD_TESTS=OFF^` 404 | -DZLIB_LIBRARY=`"$DEPS_DIR\lib\zlib_a.lib`"^` 405 | `"$pwd`" || exit 1" 406 | 407 | write-compile 408 | sdk-command "msbuild ALL_BUILD.vcxproj /p:Configuration=$MSBUILD_CONFIGURATION /m || exit 1" 409 | write-install 410 | sdk-command "msbuild INSTALL.vcxproj /p:Configuration=$MSBUILD_CONFIGURATION /m || exit 1" 411 | Copy-Item "$MSBUILD_CONFIGURATION\leveldb.pdb" "$DEPS_DIR\bin" >> $log_file 2>&1 412 | write-done 413 | Pop-Location 414 | } 415 | 416 | function build-libdeflate { 417 | write-library "libdeflate" $LIBDEFLATE_VER 418 | write-download 419 | $file = download-file "https://github.com/ebiggers/libdeflate/archive/$LIBDEFLATE_VER.zip" "libdeflate" 420 | write-extracting 421 | unzip-file $file $pwd 422 | Move-Item libdeflate-* libdeflate >> $log_file 2>&1 423 | Push-Location libdeflate 424 | 425 | write-configure 426 | #TODO: not sure why we have arch here but not on other cmake targets 427 | sdk-command "cmake -G `"$CMAKE_TARGET`" -A `"$ARCH`" $CMAKE_TOOLSET_FLAG^` 428 | -DCMAKE_PREFIX_PATH=`"$DEPS_DIR`"^` 429 | -DCMAKE_INSTALL_PREFIX=`"$DEPS_DIR`"^` 430 | -DLIBDEFLATE_BUILD_GZIP=OFF^` 431 | -DLIBDEFLATE_BUILD_SHARED_LIB=ON^` 432 | -DLIBDEFLATE_BUILD_STATIC_LIB=OFF^` 433 | `"$pwd`" || exit 1" 434 | write-compile 435 | sdk-command "msbuild ALL_BUILD.vcxproj /p:Configuration=$MSBUILD_CONFIGURATION /m || exit 1" 436 | write-install 437 | sdk-command "msbuild INSTALL.vcxproj /p:Configuration=$MSBUILD_CONFIGURATION /m || exit 1" 438 | Copy-Item "$MSBUILD_CONFIGURATION\deflate.pdb" "$DEPS_DIR\bin" >> $log_file 2>&1 439 | write-done 440 | Pop-Location 441 | } 442 | 443 | function download-php { 444 | write-library "PHP" $PHP_VER 445 | write-download 446 | 447 | $file = download-file "https://github.com/php/php-src/archive/$PHP_GIT_REV.zip" "php" 448 | write-extracting 449 | unzip-file $file $pwd 450 | Move-Item "php-src-$PHP_GIT_REV" $SOURCES_PATH >> $log_file 2>&1 451 | write-done 452 | } 453 | 454 | function get-extension-zip { 455 | param ([string] $name, [string] $version, [string] $url, [string] $extractedName) 456 | 457 | write-library "php-ext $name" $version 458 | write-download 459 | $file = download-file $url "php-ext-$name" 460 | write-extracting 461 | unzip-file $file $pwd 462 | write-done 463 | } 464 | 465 | function get-github-extension { 466 | param ([string] $name, [string] $version, [string] $user, [string] $repo, [string] $versionPrefix) 467 | get-extension-zip $name $version "https://github.com/$user/$repo/archive/$versionPrefix$version.zip" "$repo-$version" 468 | } 469 | 470 | function download-php-extensions { 471 | Push-Location "$SOURCES_PATH\ext" >> $log_file 2>&1 472 | get-github-extension "pmmpthread" $PHP_PMMPTHREAD_VER "pmmp" "ext-pmmpthread" 473 | get-github-extension "yaml" $PHP_YAML_VER "php" "pecl-file_formats-yaml" 474 | get-github-extension "chunkutils2" $PHP_CHUNKUTILS2_VER "pmmp" "ext-chunkutils2" 475 | get-github-extension "igbinary" $PHP_IGBINARY_VER "igbinary" "igbinary" 476 | get-github-extension "leveldb" $PHP_LEVELDB_VER "pmmp" "php-leveldb" 477 | get-github-extension "recursionguard" $PHP_RECURSIONGUARD_VER "pmmp" "ext-recursionguard" 478 | get-github-extension "morton" $PHP_MORTON_VER "pmmp" "ext-morton" 479 | get-github-extension "libdeflate" $PHP_LIBDEFLATE_VER "pmmp" "ext-libdeflate" 480 | get-github-extension "xxhash" $PHP_XXHASH_VER "pmmp" "ext-xxhash" 481 | get-github-extension "xdebug" $PHP_XDEBUG_VER "xdebug" "xdebug" 482 | get-github-extension "arraydebug" $PHP_ARRAYDEBUG_VER "pmmp" "ext-arraydebug" 483 | get-github-extension "encoding" $PHP_ENCODING_VER "pmmp" "ext-encoding" 484 | 485 | write-library "php-ext crypto" $PHP_CRYPTO_VER 486 | write-download 487 | (& cmd.exe /c "git clone https://github.com/bukka/php-crypto.git crypto 2>&1") >> $log_file 488 | Push-Location crypto 489 | write-status "preparing" 490 | (& cmd.exe /c "git checkout $PHP_CRYPTO_VER 2>&1") >> $log_file 491 | (& cmd.exe /c "git submodule update --init --recursive 2>&1") >> $log_file 492 | write-done 493 | Pop-Location 494 | 495 | Pop-Location 496 | } 497 | 498 | download-sdk 499 | 500 | pm-echo "Checking that SDK can find Visual Studio" 501 | #using CMAKE_TARGET for this is a bit meh but it's human readable at least 502 | sdk-command "exit /b 0" "Please install $CMAKE_TARGET" 503 | 504 | $DEPS_DIR="$BASE_PATH\deps-php-$PHP_VERSION_BASE-$($OUT_PATH_REL.ToLower())" 505 | #custom libs depend on some standard libs, so prepare these first 506 | #a bit annoying because this part of the build is slow and makes it take longer to find problems 507 | download-php-deps 508 | 509 | mkdir $LIB_BUILD_DIR >> $log_file 2>&1 510 | cd $LIB_BUILD_DIR >> $log_file 2>&1 511 | 512 | build-pthreads4w 513 | build-yaml 514 | #these two both need zlib from the standard deps 515 | build-leveldb 516 | build-libdeflate 517 | 518 | cd $BASE_PATH >> $log_file 2>&1 519 | 520 | download-php 521 | download-php-extensions 522 | 523 | cd "$SOURCES_PATH" 524 | write-library "PHP" $PHP_VER 525 | write-configure 526 | 527 | sdk-command "buildconf.bat" 528 | sdk-command "configure^` 529 | --with-mp=auto^` 530 | --with-prefix=pocketmine-php-bin^` 531 | --with-php-build=`"$DEPS_DIR`"^` 532 | --$PHP_HAVE_DEBUG^` 533 | --disable-all^` 534 | --disable-cgi^` 535 | --enable-cli^` 536 | --enable-zts^` 537 | --enable-pdo^` 538 | --enable-arraydebug=shared^` 539 | --enable-bcmath^` 540 | --enable-calendar^` 541 | --enable-chunkutils2=shared^` 542 | --enable-com-dotnet^` 543 | --enable-ctype^` 544 | --enable-encoding=shared^` 545 | --enable-fileinfo=shared^` 546 | --enable-filter^` 547 | --enable-hash^` 548 | --enable-igbinary=shared^` 549 | --enable-json^` 550 | --enable-mbstring^` 551 | --enable-morton^` 552 | --enable-opcache^` 553 | --enable-opcache-jit=$PHP_JIT_ENABLE_ARG^` 554 | --enable-phar^` 555 | --enable-recursionguard=shared^` 556 | --enable-sockets^` 557 | --enable-tokenizer^` 558 | --enable-xmlreader^` 559 | --enable-xmlwriter^` 560 | --enable-xxhash^` 561 | --enable-zip^` 562 | --enable-zlib^` 563 | --with-bz2=shared^` 564 | --with-crypto=shared^` 565 | --with-curl^` 566 | --with-dom^` 567 | --with-gd=shared^` 568 | --with-gmp^` 569 | --with-iconv^` 570 | --with-leveldb=shared^` 571 | --with-libdeflate=shared^` 572 | --with-libxml^` 573 | --with-mysqli=shared^` 574 | --with-mysqlnd^` 575 | --with-openssl^` 576 | --with-pcre-jit^` 577 | --with-pmmpthread=shared^` 578 | --with-pmmpthread-sockets^` 579 | --with-simplexml^` 580 | --with-sodium^` 581 | --with-sqlite3=shared^` 582 | --with-xdebug=shared^` 583 | --with-xdebug-compression^` 584 | --with-xml^` 585 | --with-yaml^` 586 | --with-pdo-mysql^` 587 | --with-pdo-sqlite^` 588 | --without-readline" 589 | 590 | write-compile 591 | sdk-command "nmake" 592 | 593 | write-install 594 | sdk-command "nmake snap" 595 | 596 | #remove ICU DLLs copied unnecessarily by nmake snap - this needs to be removed if we ever have ext/intl as a dependency 597 | Remove-Item "$SOURCES_PATH\$ARCH\$($OUT_PATH_REL)_TS\php-$PHP_DISPLAY_VER\icu*.dll" >> $log_file 2>&1 598 | #remove enchant dependencies which are unnecessarily copied - this needs to be removed if we ever have ext/enchant as a dependency 599 | Remove-Item "$SOURCES_PATH\$ARCH\$($OUT_PATH_REL)_TS\php-$PHP_DISPLAY_VER\glib-*.dll" >> $log_file 2>&1 600 | Remove-Item "$SOURCES_PATH\$ARCH\$($OUT_PATH_REL)_TS\php-$PHP_DISPLAY_VER\gmodule-*.dll" >> $log_file 2>&1 601 | Remove-Item -Recurse "$SOURCES_PATH\$ARCH\$($OUT_PATH_REL)_TS\php-$PHP_DISPLAY_VER\lib\enchant\" >> $log_file 2>&1 602 | 603 | cd $outpath >> $log_file 2>&1 604 | Move-Item -Force "$SOURCES_PATH\$ARCH\$($OUT_PATH_REL)_TS\php-debug-pack-*.zip" $outpath 605 | Remove-Item -Recurse bin -ErrorAction Continue >> $log_file 2>&1 606 | mkdir bin >> $log_file 2>&1 607 | Move-Item "$SOURCES_PATH\$ARCH\$($OUT_PATH_REL)_TS\php-$PHP_DISPLAY_VER" bin\php 608 | 609 | $php_exe = "$outpath\bin\php\php.exe" 610 | 611 | if (!(Test-Path $php_exe)) { 612 | pm-fatal-error "Something has gone wrong. php.exe not found" 613 | } 614 | write-status "generating php.ini" 615 | 616 | $php_ini="$outpath\bin\php\php.ini" 617 | 618 | #all this work to make PS output utf-8/ascii instead of utf-16 :( 619 | Out-File -FilePath $php_ini -Encoding ascii -InputObject ";Custom PocketMine-MP php.ini file" 620 | append-file-utf8 "memory_limit=1024M" $php_ini 621 | append-file-utf8 "display_errors=1" $php_ini 622 | append-file-utf8 "display_startup_errors=1" $php_ini 623 | append-file-utf8 "error_reporting=-1" $php_ini 624 | append-file-utf8 "zend.assertions=-1" $php_ini 625 | append-file-utf8 "extension_dir=ext" $php_ini 626 | append-file-utf8 "extension=php_pmmpthread.dll" $php_ini 627 | append-file-utf8 "extension=php_openssl.dll" $php_ini 628 | append-file-utf8 "extension=php_chunkutils2.dll" $php_ini 629 | append-file-utf8 "extension=php_igbinary.dll" $php_ini 630 | append-file-utf8 "extension=php_leveldb.dll" $php_ini 631 | append-file-utf8 "extension=php_crypto.dll" $php_ini 632 | append-file-utf8 "extension=php_libdeflate.dll" $php_ini 633 | append-file-utf8 "extension=php_encoding.dll" $php_ini 634 | append-file-utf8 "igbinary.compact_strings=0" $php_ini 635 | if ($PHP_VERSION_ID -lt 80500) { 636 | append-file-utf8 "zend_extension=php_opcache.dll" $php_ini 637 | } 638 | append-file-utf8 "opcache.enable=1" $php_ini 639 | append-file-utf8 "opcache.enable_cli=1" $php_ini 640 | append-file-utf8 "opcache.save_comments=1" $php_ini 641 | append-file-utf8 "opcache.validate_timestamps=1" $php_ini 642 | append-file-utf8 "opcache.revalidate_freq=0" $php_ini 643 | append-file-utf8 "opcache.file_update_protection=0" $php_ini 644 | append-file-utf8 "opcache.optimization_level=0x7FFEBFFF" $php_ini 645 | append-file-utf8 "opcache.cache_id=PHP_BINARY ;prevent sharing SHM between different binaries - they won't work because of ASLR" $php_ini 646 | append-file-utf8 ";Optional extensions, supplied for plugin use" $php_ini 647 | append-file-utf8 "extension=php_fileinfo.dll" $php_ini 648 | append-file-utf8 "extension=php_gd.dll" $php_ini 649 | append-file-utf8 "extension=php_mysqli.dll" $php_ini 650 | append-file-utf8 "extension=php_sqlite3.dll" $php_ini 651 | append-file-utf8 ";Optional extensions, supplied for debugging" $php_ini 652 | append-file-utf8 "extension=php_recursionguard.dll" $php_ini 653 | append-file-utf8 "recursionguard.enabled=0 ;disabled due to minor performance impact, only enable this if you need it for debugging" $php_ini 654 | append-file-utf8 ";extension=php_arraydebug.dll" $php_ini 655 | append-file-utf8 "" $php_ini 656 | if ($PHP_JIT_ENABLE_ARG -eq "yes") { 657 | append-file-utf8 "; ---- ! WARNING ! ----" $php_ini 658 | append-file-utf8 "; JIT can provide big performance improvements, but it may make your server crash or behave in weird ways. Use it at your own risk." $php_ini 659 | append-file-utf8 "; See https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.jit for possible options." $php_ini 660 | append-file-utf8 "opcache.jit=off" $php_ini 661 | append-file-utf8 "opcache.jit_buffer_size=128M" $php_ini 662 | append-file-utf8 "" $php_ini 663 | } 664 | append-file-utf8 ";WARNING: When loaded, xdebug 3.2.0 will cause segfaults whenever an uncaught error is thrown, even if xdebug.mode=off. Load it at your own risk." $php_ini 665 | append-file-utf8 ";zend_extension=php_xdebug.dll" $php_ini 666 | append-file-utf8 ";https://xdebug.org/docs/all_settings#mode" $php_ini 667 | append-file-utf8 "xdebug.mode=off" $php_ini 668 | append-file-utf8 "xdebug.start_with_request=yes" $php_ini 669 | append-file-utf8 ";The following overrides allow profiler, gc stats and traces to work correctly in ZTS" $php_ini 670 | append-file-utf8 "xdebug.profiler_output_name=cachegrind.%s.%p.%r" $php_ini 671 | append-file-utf8 "xdebug.gc_stats_output_name=gcstats.%s.%p.%r" $php_ini 672 | append-file-utf8 "xdebug.trace_output_name=trace.%s.%p.%r" $php_ini 673 | write-done 674 | pm-echo "Xdebug is included, but disabled by default. To enable it, change 'xdebug.mode' in your php.ini file." 675 | 676 | pm-echo "NOTE: You may need to install VC++ Redistributable for the binaries to work. Download it here: https://aka.ms/vs/16/release/vc_redist.x64.exe" 677 | pm-echo "PHP binary files installed in $outpath\bin" 678 | pm-echo "If the binary doesn't work, please report an issue at https://github.com/pmmp/PHP-Binaries and attach the `"compile.log`" file" 679 | -------------------------------------------------------------------------------- /compile.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PHP_VERSIONS=("8.1.33" "8.2.29" "8.3.27" "8.4.14" "8.5.0RC3") 3 | 4 | #### NOTE: Tags with "v" prefixes behave weirdly in the GitHub API. They'll be stripped in some places but not others. 5 | #### Use commit hashes to avoid this. 6 | 7 | 8 | ZLIB_VERSION="1.3.1" 9 | GMP_VERSION="6.3.0" 10 | 11 | ### Think twice before updating the minor/major versions of curl. 12 | ### curl is by far the worst offender when it comes to random 13 | ### build breakages on updates. 14 | CURL_VERSION="curl-8_13_0" 15 | 16 | YAML_VERSION="0.2.5" 17 | LEVELDB_VERSION="1c7564468b41610da4f498430e795ca4de0931ff" #release not tagged 18 | LIBXML_VERSION="2.15.1" 19 | LIBPNG_VERSION="1.6.50" 20 | LIBJPEG_VERSION="9f" 21 | OPENSSL_VERSION="3.6.0" 22 | LIBZIP_VERSION="1.11.4" 23 | SQLITE3_VERSION="3500400" #3.50.4 24 | LIBDEFLATE_VERSION="96836d7d9d10e3e0d53e6edb54eb908514e336c4" #1.24 - see above note about "v" prefixes 25 | 26 | EXT_PMMPTHREAD_VERSION="6.3.0" 27 | EXT_YAML_VERSION="2.2.5" 28 | EXT_LEVELDB_VERSION="88071eb1b1eae96af043229104b9d813f7cbe40c" #release not tagged 29 | EXT_CHUNKUTILS2_VERSION="0.3.5" 30 | EXT_XDEBUG_VERSION="3.4.7" 31 | EXT_IGBINARY_VERSION="3.2.16" 32 | EXT_CRYPTO_VERSION="999b3c7edbc7f8ca4fdeb0bb4bbae488ad0daf07" #release not tagged 33 | EXT_RECURSIONGUARD_VERSION="0.1.0" 34 | EXT_LIBDEFLATE_VERSION="0.2.1" 35 | EXT_MORTON_VERSION="0.1.2" 36 | EXT_XXHASH_VERSION="0.2.0" 37 | EXT_ARRAYDEBUG_VERSION="0.2.1" 38 | EXT_ENCODING_VERSION="1.0.0" 39 | 40 | EXT_XDEBUG_VERSION_PHP85="3.5.0alpha2" 41 | EXT_IGBINARY_VERSION_PHP85="8f8b7175c7859f1845bcdee6f7d0baeea7d07cb8" 42 | 43 | function write_out { 44 | echo "[$1] $2" 45 | } 46 | 47 | function write_error { 48 | write_out ERROR "$1" >&2 49 | } 50 | 51 | function write_status { 52 | echo -n " $1..." 53 | } 54 | 55 | function write_library { 56 | echo -n "[$1 $2]" 57 | } 58 | 59 | function write_caching { 60 | write_status "using cache" 61 | } 62 | 63 | function write_download { 64 | write_status "downloading" 65 | } 66 | function write_configure { 67 | write_status "configuring" 68 | } 69 | function write_compile { 70 | write_status "compiling" 71 | } 72 | function write_install { 73 | write_status "installing" 74 | } 75 | function write_done { 76 | echo " done!" 77 | } 78 | function cant_use_cache { 79 | if [ -f "$1/.compile.sh.cache" ]; then 80 | return 1 81 | else 82 | return 0 83 | fi 84 | } 85 | function mark_cache { 86 | touch "./.compile.sh.cache" 87 | } 88 | 89 | write_out "PocketMine" "PHP compiler for Linux, MacOS and Android" 90 | DIR="$(pwd)" 91 | BASE_BUILD_DIR="$DIR/install_data" 92 | #libtool and autoconf have a "feature" where it looks for install.sh/install-sh in ./ ../ and ../../ 93 | #this extra subdir makes sure that it doesn't find anything it's not supposed to be looking for. 94 | BUILD_DIR="$BASE_BUILD_DIR/subdir" 95 | LIB_BUILD_DIR="$BUILD_DIR/lib" 96 | INSTALL_DIR="$DIR/bin/php7" 97 | SYMBOLS_DIR="$DIR/bin-debug/php7" 98 | 99 | date > "$DIR/install.log" 2>&1 100 | 101 | uname -a >> "$DIR/install.log" 2>&1 102 | write_out "INFO" "Checking dependencies" 103 | 104 | COMPILE_SH_DEPENDENCIES=( make autoconf automake m4 getconf gzip bzip2 bison g++ git cmake pkg-config re2c) 105 | ERRORS=0 106 | for(( i=0; i<${#COMPILE_SH_DEPENDENCIES[@]}; i++ )) 107 | do 108 | type "${COMPILE_SH_DEPENDENCIES[$i]}" >> "$DIR/install.log" 2>&1 || { write_error "Please install \"${COMPILE_SH_DEPENDENCIES[$i]}\""; ((ERRORS++)); } 109 | done 110 | 111 | type wget >> "$DIR/install.log" 2>&1 || type curl >> "$DIR/install.log" || { write_error "Please install \"wget\" or \"curl\""; ((ERRORS++)); } 112 | 113 | if [ "$(uname -s)" == "Darwin" ]; then 114 | type glibtool >> "$DIR/install.log" 2>&1 || { write_error "Please install GNU libtool"; ((ERRORS++)); } 115 | export LIBTOOL=glibtool 116 | export LIBTOOLIZE=glibtoolize 117 | export PATH="/opt/homebrew/opt/bison/bin:$PATH" 118 | [[ $(bison --version) == "bison (GNU Bison) 3."* ]] || { write_error "MacOS bundled bison is too old. Install bison using Homebrew and update your PATH variable according to its instructions before running this script."; ((ERRORS++)); } 119 | else 120 | type libtool >> "$DIR/install.log" 2>&1 || { write_error "Please install \"libtool\" or \"libtool-bin\""; ((ERRORS++)); } 121 | export LIBTOOL=libtool 122 | export LIBTOOLIZE=libtoolize 123 | fi 124 | 125 | if [ $ERRORS -ne 0 ]; then 126 | exit 1 127 | fi 128 | 129 | #if type llvm-gcc >/dev/null 2>&1; then 130 | # export CC="llvm-gcc" 131 | # export CXX="llvm-g++" 132 | # export AR="llvm-ar" 133 | # export AS="llvm-as" 134 | # export RANLIB=llvm-ranlib 135 | #else 136 | export CC="gcc" 137 | export CXX="g++" 138 | #export AR="gcc-ar" 139 | export RANLIB=ranlib 140 | export STRIP="strip" 141 | #fi 142 | 143 | COMPILE_FOR_ANDROID=no 144 | HAVE_MYSQLI="--enable-mysqlnd --with-mysqli=mysqlnd" 145 | COMPILE_TARGET="" 146 | IS_CROSSCOMPILE="no" 147 | IS_WINDOWS="no" 148 | DO_OPTIMIZE="yes" 149 | DO_STATIC="no" 150 | DO_CLEANUP="yes" 151 | COMPILE_DEBUG="no" 152 | HAVE_VALGRIND="--without-valgrind" 153 | HAVE_OPCACHE="yes" 154 | HAVE_XDEBUG="yes" 155 | FSANITIZE_OPTIONS="" 156 | FLAGS_LTO="" 157 | HAVE_OPCACHE_JIT="no" 158 | 159 | COMPILE_GD="no" 160 | 161 | PM_VERSION_MAJOR="" 162 | 163 | DOWNLOAD_INSECURE="no" 164 | DOWNLOAD_CACHE="$DIR/download_cache" 165 | SEPARATE_SYMBOLS="no" 166 | 167 | PHP_VERSION_BASE="auto" 168 | 169 | while getopts "::t:j:sdDxfgnva:P:c:l:Jiz:" OPTION; do 170 | 171 | case $OPTION in 172 | l) 173 | mkdir "$OPTARG" 2> /dev/null 174 | LIB_BUILD_DIR="$(cd $OPTARG; pwd)" 175 | write_out opt "Reusing previously built libraries in $LIB_BUILD_DIR if found" 176 | write_out WARNING "Reusing previously built libraries may break if different args were used!" 177 | ;; 178 | c) 179 | mkdir "$OPTARG" 2> /dev/null 180 | DOWNLOAD_CACHE="$(cd $OPTARG; pwd)" 181 | write_out opt "Caching downloaded files in $DOWNLOAD_CACHE and reusing if available" 182 | ;; 183 | t) 184 | write_out "opt" "Set target to $OPTARG" 185 | COMPILE_TARGET="$OPTARG" 186 | ;; 187 | j) 188 | write_out "opt" "Set make threads to $OPTARG" 189 | THREADS="$OPTARG" 190 | ;; 191 | d) 192 | write_out "opt" "Will compile everything with debugging symbols, will not remove sources" 193 | COMPILE_DEBUG="yes" 194 | DO_CLEANUP="no" 195 | DO_OPTIMIZE="no" 196 | CFLAGS="$CFLAGS -g" 197 | CXXFLAGS="$CXXFLAGS -g" 198 | ;; 199 | D) 200 | write_out "opt" "Compiling with separated debugging symbols, but leaving optimizations enabled" 201 | SEPARATE_SYMBOLS="yes" 202 | CFLAGS="$CFLAGS -g" 203 | CXXFLAGS="$CXXFLAGS -g" 204 | ;; 205 | x) 206 | write_out "opt" "Doing cross-compile" 207 | IS_CROSSCOMPILE="yes" 208 | ;; 209 | s) 210 | write_out "opt" "Will compile everything statically" 211 | DO_STATIC="yes" 212 | CFLAGS="$CFLAGS -static" 213 | ;; 214 | f) 215 | write_out "deprecated" "The -f flag is deprecated, as optimizations are now enabled by default unless -d (debug mode) is specified" 216 | ;; 217 | g) 218 | write_out "opt" "Will enable GD2" 219 | COMPILE_GD="yes" 220 | ;; 221 | n) 222 | write_out "opt" "Will not remove sources after completing compilation" 223 | DO_CLEANUP="no" 224 | ;; 225 | v) 226 | write_out "opt" "Will enable valgrind support in PHP" 227 | HAVE_VALGRIND="--with-valgrind" 228 | ;; 229 | a) 230 | write_out "opt" "Will pass -fsanitize=$OPTARG to compilers and linkers" 231 | FSANITIZE_OPTIONS="$OPTARG" 232 | ;; 233 | P) 234 | PM_VERSION_MAJOR="$OPTARG" 235 | ;; 236 | J) 237 | write_out "opt" "Compiling JIT support in OPcache" 238 | HAVE_OPCACHE_JIT="yes" 239 | ;; 240 | i) 241 | write_out "opt" "Disabling SSL certificate verification for downloads" 242 | write_out "WARNING" "This is a security risk, please only use this if you know what you are doing!" 243 | DOWNLOAD_INSECURE="yes" 244 | ;; 245 | z) 246 | PHP_VERSION_BASE="$OPTARG" 247 | ;; 248 | \?) 249 | write_error "Invalid option: -$OPTARG" 250 | exit 1 251 | ;; 252 | esac 253 | done 254 | 255 | function php_version_id { 256 | local PHP_VERSION="$1" 257 | local PHP_VERSION_MAJOR=$(echo "$PHP_VERSION" | cut -d. -f1) 258 | local PHP_VERSION_MINOR=$(echo "$PHP_VERSION" | cut -d. -f2) 259 | #TODO: patch is a pain because of suffixes and we don't really need it anyway 260 | 261 | # Use this for switching PHP version specific logic 262 | local PHP_VERSION_ID=$(((PHP_VERSION_MAJOR * 10000) + (PHP_VERSION_MINOR * 100))) 263 | echo "$PHP_VERSION_ID" 264 | } 265 | 266 | PREFERRED_PHP_VERSION_BASE="" 267 | case $PM_VERSION_MAJOR in 268 | 5) 269 | PREFERRED_PHP_VERSION_BASE="8.2" 270 | ;; 271 | "") 272 | write_error "Please specify PocketMine-MP major version target with -P (e.g. -P5)" 273 | exit 1 274 | ;; 275 | \?) 276 | write_error "PocketMine-MP $PM_VERSION_MAJOR is not supported by this version of the build script" 277 | exit 1 278 | ;; 279 | esac 280 | 281 | write_out "opt" "Compiling with configuration for PocketMine-MP $PM_VERSION_MAJOR" 282 | 283 | if [ "$PHP_VERSION_BASE" == "auto" ]; then 284 | PHP_VERSION_BASE="$PREFERRED_PHP_VERSION_BASE" 285 | elif [ "$PHP_VERSION_BASE" != "$PREFERRED_PHP_VERSION_BASE" ]; then 286 | #TODO: validate that this PHP version is able to be used 287 | write_out "WARNING" "$PHP_VERSION_BASE is not the default for PocketMine-MP $PM_VERSION_MAJOR" 288 | write_out "WARNING" "The build may fail, or you may not be able to use the resulting PHP binary" 289 | fi 290 | 291 | for version in "${PHP_VERSIONS[@]}"; do 292 | if [[ "$version" == "$PHP_VERSION_BASE."* ]]; then 293 | PHP_VERSION="$version" 294 | break 295 | fi 296 | done 297 | 298 | if [ "$PHP_VERSION" == "" ]; then 299 | write_error "Unsupported PHP base version $PHP_VERSION_BASE" 300 | write_error "Example inputs: 8.2, 8.3" 301 | exit 1 302 | fi 303 | 304 | PHP_VERSION_ID=$(php_version_id "$PHP_VERSION") 305 | write_out "opt" "Selected PHP $PHP_VERSION ($PHP_VERSION_ID)" 306 | 307 | if [ $PHP_VERSION_ID -ge 80500 ]; then 308 | EXT_XDEBUG_VERSION="$EXT_XDEBUG_VERSION_PHP85" 309 | EXT_IGBINARY_VERSION="$EXT_IGBINARY_VERSION_PHP85" 310 | fi 311 | if [ $PHP_VERSION_ID -ge 80400 ]; then 312 | HAVE_OPCACHE_JIT="yes" 313 | fi 314 | if [ "$HAVE_OPCACHE_JIT" == "yes" ]; then 315 | if [ $PHP_VERSION_ID -lt 80400 ]; then 316 | write_out "WARNING" "JIT in versions below PHP 8.4 is highly unstable and not recommended" 317 | else 318 | write_out "WARNING" "JIT in PHP 8.4 has not been tested, use it with caution" 319 | fi 320 | else 321 | write_out "INFO" "JIT support in OPcache won't be compiled" 322 | fi 323 | 324 | #Needed to use aliases 325 | shopt -s expand_aliases 326 | type wget >> "$DIR/install.log" 2>&1 327 | if [ $? -eq 0 ]; then 328 | wget_flags="" 329 | if [ "$DOWNLOAD_INSECURE" == "yes" ]; then 330 | wget_flags="--no-check-certificate" 331 | fi 332 | alias _download_file="wget $wget_flags -nv -O -" 333 | else 334 | type curl >> "$DIR/install.log" 2>&1 335 | if [ $? -eq 0 ]; then 336 | curl_flags="" 337 | if [ "$DOWNLOAD_INSECURE" == "yes" ]; then 338 | curl_flags="--insecure" 339 | fi 340 | alias _download_file="curl $curl_flags --silent --show-error --location --globoff" 341 | else 342 | write_error "Neither curl nor wget found. Please install one and try again." 343 | exit 1 344 | fi 345 | fi 346 | 347 | function download_file { 348 | local url="$1" 349 | local prefix="$2" 350 | local cached_filename="$prefix-${url##*/}" 351 | 352 | if [[ "$DOWNLOAD_CACHE" != "" ]]; then 353 | if [[ ! -d "$DOWNLOAD_CACHE" ]]; then 354 | mkdir "$DOWNLOAD_CACHE" >> "$DIR/install.log" 2>&1 355 | fi 356 | if [[ -f "$DOWNLOAD_CACHE/$cached_filename" ]]; then 357 | echo "Cache hit for URL: $url" >> "$DIR/install.log" 358 | else 359 | echo "Downloading file to cache: $url" >> "$DIR/install.log" 360 | #download to a tmpfile first, so that we don't leave borked cache entries for later runs 361 | _download_file "$1" > "$DOWNLOAD_CACHE/.temp" 2>> "$DIR/install.log" 362 | mv "$DOWNLOAD_CACHE/.temp" "$DOWNLOAD_CACHE/$cached_filename" >> "$DIR/install.log" 2>&1 363 | fi 364 | cat "$DOWNLOAD_CACHE/$cached_filename" 2>> "$DIR/install.log" 365 | else 366 | echo "Downloading non-cached file: $url" >> "$DIR/install.log" 367 | _download_file "$1" 2>> "$DIR/install.log" 368 | fi 369 | } 370 | 371 | function download_from_mirror { 372 | download_file "https://github.com/pmmp/DependencyMirror/releases/download/mirror/$1" "$2" 373 | } 374 | 375 | #1: github repo 376 | #2: tag or commit 377 | #3: cache prefix 378 | function download_github_src { 379 | download_file "https://github.com/$1/archive/$2.tar.gz" "$3" 380 | } 381 | 382 | GMP_ABI="" 383 | TOOLCHAIN_PREFIX="" 384 | OPENSSL_TARGET="" 385 | CMAKE_GLOBAL_EXTRA_FLAGS="" 386 | 387 | if [ "$IS_CROSSCOMPILE" == "yes" ]; then 388 | export CROSS_COMPILER="$PATH" 389 | if [ "$COMPILE_TARGET" == "android-aarch64" ]; then 390 | COMPILE_FOR_ANDROID=yes 391 | [ -z "$march" ] && march="armv8-a"; 392 | [ -z "$mtune" ] && mtune=generic; 393 | TOOLCHAIN_PREFIX="aarch64-linux-musl" 394 | CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX" 395 | CFLAGS="-static $CFLAGS" 396 | CXXFLAGS="-static $CXXFLAGS" 397 | LDFLAGS="-static -static-libgcc -Wl,-static" 398 | DO_STATIC="yes" 399 | OPENSSL_TARGET="linux-aarch64" 400 | export ac_cv_func_fnmatch_works=yes #musl should be OK 401 | 402 | write_out "INFO" "Cross-compiling for Android ARMv8 (aarch64)" 403 | #TODO: add cross-compile for aarch64 platforms (ios, rpi) 404 | else 405 | write_error "Please supply a proper platform [android-aarch64] to cross-compile" 406 | exit 1 407 | fi 408 | else 409 | if [[ "$COMPILE_TARGET" == "" ]] && [[ "$(uname -s)" == "Darwin" ]]; then 410 | if [ "$(uname -m)" == "arm64" ]; then 411 | COMPILE_TARGET="mac-arm64" 412 | else 413 | COMPILE_TARGET="mac-x86-64" 414 | fi 415 | fi 416 | if [[ "$COMPILE_TARGET" == "linux" ]] || [[ "$COMPILE_TARGET" == "linux64" ]]; then 417 | [ -z "$march" ] && march=x86-64; 418 | [ -z "$mtune" ] && mtune=skylake; 419 | CFLAGS="$CFLAGS -m64" 420 | GMP_ABI="64" 421 | OPENSSL_TARGET="linux-x86_64" 422 | write_out "INFO" "Compiling for Linux x86_64" 423 | elif [[ "$COMPILE_TARGET" == "mac-x86-64" ]]; then 424 | [ -z "$march" ] && march=core2; 425 | [ -z "$mtune" ] && mtune=generic; 426 | [ -z "$MACOSX_DEPLOYMENT_TARGET" ] && export MACOSX_DEPLOYMENT_TARGET=10.9; 427 | CFLAGS="$CFLAGS -m64 -arch x86_64 -fomit-frame-pointer -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET" 428 | LDFLAGS="$LDFLAGS -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET" 429 | if [ "$DO_STATIC" == "no" ]; then 430 | LDFLAGS="$LDFLAGS -Wl,-rpath,@loader_path/../lib"; 431 | export DYLD_LIBRARY_PATH="@loader_path/../lib" 432 | fi 433 | CFLAGS="$CFLAGS -Qunused-arguments" 434 | GMP_ABI="64" 435 | OPENSSL_TARGET="darwin64-x86_64-cc" 436 | CMAKE_GLOBAL_EXTRA_FLAGS="-DCMAKE_OSX_ARCHITECTURES=x86_64" 437 | write_out "INFO" "Compiling for MacOS x86_64" 438 | #TODO: add aarch64 platforms (ios, android, rpi) 439 | elif [[ "$COMPILE_TARGET" == "mac-arm64" ]]; then 440 | [ -z "$MACOSX_DEPLOYMENT_TARGET" ] && export MACOSX_DEPLOYMENT_TARGET=11.0; 441 | CFLAGS="$CFLAGS -arch arm64 -fomit-frame-pointer -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET" 442 | LDFLAGS="$LDFLAGS -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET" 443 | if [ "$DO_STATIC" == "no" ]; then 444 | LDFLAGS="$LDFLAGS -Wl,-rpath,@loader_path/../lib"; 445 | export DYLD_LIBRARY_PATH="@loader_path/../lib" 446 | fi 447 | CFLAGS="$CFLAGS -Qunused-arguments" 448 | GMP_ABI="64" 449 | OPENSSL_TARGET="darwin64-arm64-cc" 450 | CMAKE_GLOBAL_EXTRA_FLAGS="-DCMAKE_OSX_ARCHITECTURES=arm64" 451 | write_out "INFO" "Compiling for MacOS M1" 452 | elif [[ "$COMPILE_TARGET" != "" ]]; then 453 | write_error "Please supply a proper platform [mac-arm64 mac-x86-64 linux linux64] to compile for" 454 | exit 1 455 | elif [ -z "$CFLAGS" ]; then 456 | if [ `getconf LONG_BIT` == "64" ]; then 457 | write_out "INFO" "Compiling for current machine using 64-bit" 458 | if [ "$(uname -m)" != "aarch64" ]; then 459 | CFLAGS="-m64 $CFLAGS" 460 | fi 461 | GMP_ABI="64" 462 | else 463 | write_out "ERROR" "PocketMine-MP is no longer supported on 32-bit systems" 464 | exit 1 465 | fi 466 | fi 467 | fi 468 | 469 | if [ "$DO_STATIC" == "yes" ]; then 470 | HAVE_OPCACHE="no" #doesn't work on static builds 471 | HAVE_OPCACHE_JIT="no" 472 | write_out "warning" "OPcache cannot be used on static builds; this may have a negative effect on performance" 473 | if [ "$FSANITIZE_OPTIONS" != "" ]; then 474 | write_out "warning" "Sanitizers cannot be used on static builds" 475 | fi 476 | if [ "$HAVE_XDEBUG" == "yes" ]; then 477 | write_out "warning" "Xdebug cannot be built in static mode" 478 | HAVE_XDEBUG="no" 479 | fi 480 | fi 481 | 482 | if [ "$TOOLCHAIN_PREFIX" != "" ]; then 483 | export CC="$TOOLCHAIN_PREFIX-gcc" 484 | export CXX="$TOOLCHAIN_PREFIX-g++" 485 | export AR="$TOOLCHAIN_PREFIX-ar" 486 | export RANLIB="$TOOLCHAIN_PREFIX-ranlib" 487 | export CPP="$TOOLCHAIN_PREFIX-cpp" 488 | export LD="$TOOLCHAIN_PREFIX-ld" 489 | export STRIP="$TOOLCHAIN_PREFIX-strip" 490 | fi 491 | 492 | echo "#include " > test.c 493 | echo "int main(void){" >> test.c 494 | echo "printf(\"Hello world\n\");" >> test.c 495 | echo "return 0;" >> test.c 496 | echo "}" >> test.c 497 | 498 | 499 | type $CC >> "$DIR/install.log" 2>&1 || { write_error "Please install \"$CC\""; exit 1; } 500 | 501 | if [ -z "$THREADS" ]; then 502 | write_out "WARNING" "Only 1 thread is used by default. Increase thread count using -j (e.g. -j 4) to compile faster." 503 | THREADS=1; 504 | fi 505 | [ -z "$march" ] && march=native; 506 | [ -z "$mtune" ] && mtune=native; 507 | [ -z "$CFLAGS" ] && CFLAGS=""; 508 | 509 | if [ "$DO_STATIC" == "no" ]; then 510 | [ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath='\$\$ORIGIN/../lib' -Wl,-rpath-link='\$\$ORIGIN/../lib'"; 511 | fi 512 | 513 | [ -z "$CONFIGURE_FLAGS" ] && CONFIGURE_FLAGS=""; 514 | 515 | if [ "$mtune" != "none" ]; then 516 | $CC -march=$march -mtune=$mtune $CFLAGS -o test test.c >> "$DIR/install.log" 2>&1 517 | if [ $? -eq 0 ]; then 518 | CFLAGS="-march=$march -mtune=$mtune $CFLAGS" 519 | fi 520 | else 521 | $CC -march=$march $CFLAGS -o test test.c >> "$DIR/install.log" 2>&1 522 | if [ $? -eq 0 ]; then 523 | CFLAGS="-march=$march $CFLAGS" 524 | fi 525 | fi 526 | 527 | if [ "$DO_OPTIMIZE" != "no" ]; then 528 | #FLAGS_LTO="-fvisibility=hidden -flto" 529 | CFLAGS="$CFLAGS -O2" 530 | GENERIC_CFLAGS="$CFLAGS -ftree-vectorize -fomit-frame-pointer" 531 | $CC $CFLAGS $GENERIC_CFLAGS -o test test.c >> "$DIR/install.log" 2>&1 532 | if [ $? -eq 0 ]; then 533 | CFLAGS="$CFLAGS $GENERIC_CFLAGS" 534 | fi 535 | #clang does not understand the following and will fail 536 | GCC_CFLAGS="$CFLAGS -funsafe-loop-optimizations -fpredictive-commoning -ftracer -ftree-loop-im -frename-registers -fcx-limited-range -funswitch-loops -fivopts -fno-gcse" 537 | $CC $CFLAGS $GCC_CFLAGS -o test test.c >> "$DIR/install.log" 2>&1 538 | if [ $? -eq 0 ]; then 539 | CFLAGS="$CFLAGS $GCC_CFLAGS" 540 | fi 541 | #TODO: -ftree-parallelize-loops requires OpenMP - not sure if it will provide meaningful improvements yet 542 | fi 543 | 544 | if [ "$FSANITIZE_OPTIONS" != "" ]; then 545 | CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" LDFLAGS="$LDFLAGS" $CC -fsanitize=$FSANITIZE_OPTIONS -o asan-test test.c >> "$DIR/install.log" 2>&1 && \ 546 | chmod +x asan-test >> "$DIR/install.log" 2>&1 && \ 547 | ./asan-test >> "$DIR/install.log" 2>&1 && \ 548 | rm asan-test >> "$DIR/install.log" 2>&1 549 | if [ $? -ne 0 ]; then 550 | write_out "ERROR" "One or more sanitizers are not working. Check install.log for details." 551 | exit 1 552 | else 553 | write_out "INFO" "All selected sanitizers are working" 554 | fi 555 | fi 556 | 557 | rm test.* >> "$DIR/install.log" 2>&1 558 | rm test >> "$DIR/install.log" 2>&1 559 | 560 | export CC="$CC" 561 | export CXX="$CXX" 562 | export CFLAGS="-O2 -fPIC $CFLAGS" 563 | export CXXFLAGS="$CFLAGS $CXXFLAGS" 564 | export LDFLAGS="$LDFLAGS" 565 | export CPPFLAGS="$CPPFLAGS" 566 | export LIBRARY_PATH="$INSTALL_DIR/lib:$LIBRARY_PATH" 567 | export PKG_CONFIG_PATH="$INSTALL_DIR/lib/pkgconfig" 568 | 569 | #some stuff (like curl) makes assumptions about library paths that break due to different behaviour in pkgconf vs pkg-config 570 | export PKG_CONFIG_ALLOW_SYSTEM_LIBS="yes" 571 | export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS="yes" 572 | 573 | rm -r -f "$BASE_BUILD_DIR" >> "$DIR/install.log" 2>&1 574 | rm -r -f bin/ >> "$DIR/install.log" 2>&1 575 | mkdir -m 0755 "$BASE_BUILD_DIR" >> "$DIR/install.log" 2>&1 576 | mkdir -m 0755 "$BUILD_DIR" >> "$DIR/install.log" 2>&1 577 | mkdir -m 0755 -p $INSTALL_DIR >> "$DIR/install.log" 2>&1 578 | mkdir -m 0755 -p "$LIB_BUILD_DIR" >> "$DIR/install.log" 2>&1 579 | cd "$BUILD_DIR" 580 | set -e 581 | 582 | #PHP 583 | write_library "PHP" "$PHP_VERSION" 584 | write_download 585 | 586 | download_github_src "php/php-src" "php-$PHP_VERSION" "php" | tar -zx >> "$DIR/install.log" 2>&1 587 | mv php-src-php-$PHP_VERSION php 588 | write_done 589 | 590 | function build_zlib { 591 | if [ "$DO_STATIC" == "yes" ]; then 592 | local EXTRA_FLAGS="--static" 593 | else 594 | local EXTRA_FLAGS="--shared" 595 | fi 596 | 597 | write_library zlib "$ZLIB_VERSION" 598 | local zlib_dir="./zlib-$ZLIB_VERSION" 599 | 600 | if cant_use_cache "$zlib_dir"; then 601 | rm -rf "$zlib_dir" 602 | write_download 603 | download_github_src "madler/zlib" "v$ZLIB_VERSION" "zlib" | tar -zx >> "$DIR/install.log" 2>&1 604 | write_configure 605 | cd "$zlib_dir" 606 | RANLIB=$RANLIB ./configure --prefix="$INSTALL_DIR" \ 607 | $EXTRA_FLAGS >> "$DIR/install.log" 2>&1 608 | write_compile 609 | make -j $THREADS >> "$DIR/install.log" 2>&1 && mark_cache 610 | else 611 | write_caching 612 | cd "$zlib_dir" 613 | fi 614 | write_install 615 | make install >> "$DIR/install.log" 2>&1 616 | cd .. 617 | if [ "$DO_STATIC" != "yes" ]; then 618 | rm -f "$INSTALL_DIR/lib/libz.a" 619 | fi 620 | write_done 621 | } 622 | 623 | function build_gmp { 624 | export jm_cv_func_working_malloc=yes 625 | export ac_cv_func_malloc_0_nonnull=yes 626 | export jm_cv_func_working_realloc=yes 627 | export ac_cv_func_realloc_0_nonnull=yes 628 | 629 | if [ "$IS_CROSSCOMPILE" == "yes" ]; then 630 | local EXTRA_FLAGS="" 631 | else 632 | local EXTRA_FLAGS="--disable-assembly" 633 | fi 634 | 635 | write_library gmp "$GMP_VERSION" 636 | local gmp_dir="./gmp-$GMP_VERSION" 637 | 638 | if cant_use_cache "$gmp_dir"; then 639 | rm -rf "$gmp_dir" 640 | write_download 641 | download_from_mirror "gmp-$GMP_VERSION.tar.xz" "gmp" | tar -Jx >> "$DIR/install.log" 2>&1 642 | write_configure 643 | cd "$gmp_dir" 644 | CFLAGS="-std=gnu17 $CFLAGS" RANLIB=$RANLIB ./configure --prefix="$INSTALL_DIR" \ 645 | $EXTRA_FLAGS \ 646 | --disable-posix-threads \ 647 | --enable-static \ 648 | --disable-shared \ 649 | $CONFIGURE_FLAGS ABI="$GMP_ABI" >> "$DIR/install.log" 2>&1 650 | write_compile 651 | make -j $THREADS >> "$DIR/install.log" 2>&1 && mark_cache 652 | else 653 | write_caching 654 | cd "$gmp_dir" 655 | fi 656 | write_install 657 | make install >> "$DIR/install.log" 2>&1 658 | cd .. 659 | write_done 660 | } 661 | 662 | function build_openssl { 663 | #OpenSSL 664 | OPENSSL_CMD="./config" 665 | if [ "$OPENSSL_TARGET" != "" ]; then 666 | local OPENSSL_CMD="./Configure $OPENSSL_TARGET" 667 | fi 668 | if [ "$DO_STATIC" == "yes" ]; then 669 | local EXTRA_FLAGS="no-shared -static" 670 | else 671 | local EXTRA_FLAGS="shared" 672 | fi 673 | 674 | write_library openssl "$OPENSSL_VERSION" 675 | local openssl_dir="./openssl-openssl-$OPENSSL_VERSION" 676 | 677 | if cant_use_cache "$openssl_dir"; then 678 | rm -rf "$openssl_dir" 679 | write_download 680 | download_github_src "openssl/openssl" "openssl-$OPENSSL_VERSION" "openssl" | tar -zx >> "$DIR/install.log" 2>&1 681 | 682 | write_configure 683 | cd "$openssl_dir" 684 | RANLIB=$RANLIB $OPENSSL_CMD \ 685 | --prefix="$INSTALL_DIR" \ 686 | --openssldir="$INSTALL_DIR" \ 687 | --libdir="$INSTALL_DIR/lib" \ 688 | no-asm \ 689 | no-hw \ 690 | no-engine \ 691 | $EXTRA_FLAGS >> "$DIR/install.log" 2>&1 692 | 693 | write_compile 694 | make -j $THREADS >> "$DIR/install.log" 2>&1 && mark_cache 695 | else 696 | write_caching 697 | cd "$openssl_dir" 698 | fi 699 | write_install 700 | make install_sw >> "$DIR/install.log" 2>&1 701 | cd .. 702 | write_done 703 | } 704 | 705 | function build_curl { 706 | if [ "$DO_STATIC" == "yes" ]; then 707 | local EXTRA_FLAGS="--enable-static --disable-shared" 708 | else 709 | local EXTRA_FLAGS="--disable-static --enable-shared" 710 | fi 711 | 712 | write_library curl "$CURL_VERSION" 713 | local curl_dir="./curl-$CURL_VERSION" 714 | if cant_use_cache "$curl_dir"; then 715 | rm -rf "$curl_dir" 716 | write_download 717 | download_github_src "curl/curl" "$CURL_VERSION" "curl" | tar -zx >> "$DIR/install.log" 2>&1 718 | write_configure 719 | cd "$curl_dir" 720 | if [[ "$(uname -s)" == "Darwin" ]]; then 721 | sed -i'.bak' 's/^CURL_CONVERT_INCLUDE_TO_ISYSTEM//' ./configure.ac 722 | fi 723 | ./buildconf --force >> "$DIR/install.log" 2>&1 724 | RANLIB=$RANLIB ./configure --disable-dependency-tracking \ 725 | --enable-ipv6 \ 726 | --enable-optimize \ 727 | --enable-http \ 728 | --enable-ftp \ 729 | --disable-dict \ 730 | --enable-file \ 731 | --without-librtmp \ 732 | --disable-gopher \ 733 | --disable-imap \ 734 | --disable-pop3 \ 735 | --disable-rtsp \ 736 | --disable-smtp \ 737 | --disable-telnet \ 738 | --disable-tftp \ 739 | --disable-ldap \ 740 | --disable-ldaps \ 741 | --without-libidn \ 742 | --without-libidn2 \ 743 | --without-brotli \ 744 | --without-nghttp2 \ 745 | --without-zstd \ 746 | --without-libpsl \ 747 | --with-zlib="$INSTALL_DIR" \ 748 | --with-ssl="$INSTALL_DIR" \ 749 | --enable-threaded-resolver \ 750 | --prefix="$INSTALL_DIR" \ 751 | $EXTRA_FLAGS \ 752 | $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 753 | write_compile 754 | make -j $THREADS >> "$DIR/install.log" 2>&1 && mark_cache 755 | else 756 | write_caching 757 | cd "$curl_dir" 758 | fi 759 | 760 | write_install 761 | make install >> "$DIR/install.log" 2>&1 762 | cd .. 763 | write_done 764 | } 765 | 766 | function build_yaml { 767 | if [ "$DO_STATIC" == "yes" ]; then 768 | local EXTRA_FLAGS="--disable-shared --enable-static" 769 | else 770 | local EXTRA_FLAGS="--enable-shared --disable-static" 771 | fi 772 | 773 | write_library yaml "$YAML_VERSION" 774 | local yaml_dir="./libyaml-$YAML_VERSION" 775 | if cant_use_cache "$yaml_dir"; then 776 | rm -rf "$yaml_dir" 777 | write_download 778 | download_github_src "yaml/libyaml" "$YAML_VERSION" "yaml" | tar -zx >> "$DIR/install.log" 2>&1 779 | cd "$yaml_dir" 780 | ./bootstrap >> "$DIR/install.log" 2>&1 781 | 782 | write_configure 783 | 784 | RANLIB=$RANLIB ./configure \ 785 | --prefix="$INSTALL_DIR" \ 786 | $EXTRA_FLAGS \ 787 | $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 788 | sed -i=".backup" 's/ tests win32/ win32/g' Makefile 789 | 790 | write_compile 791 | make -j $THREADS all >> "$DIR/install.log" 2>&1 && mark_cache 792 | else 793 | write_caching 794 | cd "$yaml_dir" 795 | fi 796 | write_install 797 | make install >> "$DIR/install.log" 2>&1 798 | cd .. 799 | write_done 800 | } 801 | 802 | function build_leveldb { 803 | write_library leveldb "$LEVELDB_VERSION" 804 | local leveldb_dir="./leveldb-$LEVELDB_VERSION" 805 | if cant_use_cache "$leveldb_dir"; then 806 | rm -rf "$leveldb_dir" 807 | write_download 808 | download_github_src "pmmp/leveldb" "$LEVELDB_VERSION" "leveldb" | tar -zx >> "$DIR/install.log" 2>&1 809 | #download_file "https://github.com/Mojang/leveldb-mcpe/archive/$LEVELDB_VERSION.tar.gz" | tar -zx >> "$DIR/install.log" 2>&1 810 | 811 | write_configure 812 | cd "$leveldb_dir" 813 | if [ "$DO_STATIC" != "yes" ]; then 814 | local EXTRA_FLAGS="-DBUILD_SHARED_LIBS=ON" 815 | else 816 | local EXTRA_FLAGS="" 817 | fi 818 | cmake . \ 819 | -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \ 820 | -DCMAKE_PREFIX_PATH="$INSTALL_DIR" \ 821 | -DCMAKE_INSTALL_LIBDIR=lib \ 822 | -DLEVELDB_BUILD_TESTS=OFF \ 823 | -DLEVELDB_BUILD_BENCHMARKS=OFF \ 824 | -DLEVELDB_SNAPPY=OFF \ 825 | -DLEVELDB_ZSTD=OFF \ 826 | -DLEVELDB_TCMALLOC=OFF \ 827 | -DCMAKE_BUILD_TYPE=Release \ 828 | $CMAKE_GLOBAL_EXTRA_FLAGS \ 829 | $EXTRA_FLAGS \ 830 | >> "$DIR/install.log" 2>&1 831 | 832 | write_compile 833 | make -j $THREADS >> "$DIR/install.log" 2>&1 && mark_cache 834 | else 835 | write_caching 836 | cd "$leveldb_dir" 837 | fi 838 | 839 | write_install 840 | make install >> "$DIR/install.log" 2>&1 841 | cd .. 842 | write_done 843 | } 844 | 845 | function build_libpng { 846 | if [ "$DO_STATIC" == "yes" ]; then 847 | local EXTRA_FLAGS="--enable-shared=no --enable-static=yes" 848 | else 849 | local EXTRA_FLAGS="--enable-shared=yes --enable-static=no" 850 | fi 851 | 852 | write_library libpng "$LIBPNG_VERSION" 853 | local libpng_dir="./libpng-$LIBPNG_VERSION" 854 | if cant_use_cache "$libpng_dir"; then 855 | rm -rf "$libpng_dir" 856 | write_download 857 | download_from_mirror "libpng-$LIBPNG_VERSION.tar.gz" "libpng" | tar -zx >> "$DIR/install.log" 2>&1 858 | 859 | write_configure 860 | cd "$libpng_dir" 861 | LDFLAGS="$LDFLAGS -L${INSTALL_DIR}/lib" CPPFLAGS="$CPPFLAGS -I${INSTALL_DIR}/include" RANLIB=$RANLIB ./configure \ 862 | --prefix="$INSTALL_DIR" \ 863 | $EXTRA_FLAGS \ 864 | $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 865 | 866 | write_compile 867 | make -j $THREADS >> "$DIR/install.log" 2>&1 && mark_cache 868 | else 869 | write_caching 870 | cd "$libpng_dir" 871 | fi 872 | 873 | write_install 874 | make install >> "$DIR/install.log" 2>&1 875 | cd .. 876 | write_done 877 | } 878 | 879 | function build_libjpeg { 880 | if [ "$DO_STATIC" == "yes" ]; then 881 | local EXTRA_FLAGS="--enable-shared=no --enable-static=yes" 882 | else 883 | local EXTRA_FLAGS="--enable-shared=yes --enable-static=no" 884 | fi 885 | 886 | write_library libjpeg "$LIBJPEG_VERSION" 887 | local libjpeg_dir="./libjpeg-$LIBJPEG_VERSION" 888 | if cant_use_cache "$libjpeg_dir"; then 889 | rm -rf "$libjpeg_dir" 890 | write_download 891 | download_from_mirror "jpegsrc.v$LIBJPEG_VERSION.tar.gz" "libjpeg" | tar -zx >> "$DIR/install.log" 2>&1 892 | mv jpeg-$LIBJPEG_VERSION "$libjpeg_dir" 893 | 894 | write_configure 895 | cd "$libjpeg_dir" 896 | LDFLAGS="$LDFLAGS -L${INSTALL_DIR}/lib" CPPFLAGS="$CPPFLAGS -I${INSTALL_DIR}/include" RANLIB=$RANLIB ./configure \ 897 | --prefix="$INSTALL_DIR" \ 898 | $EXTRA_FLAGS \ 899 | $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 900 | 901 | write_compile 902 | make -j $THREADS >> "$DIR/install.log" 2>&1 && mark_cache 903 | else 904 | write_caching 905 | cd "$libjpeg_dir" 906 | fi 907 | write_install 908 | make install >> "$DIR/install.log" 2>&1 909 | cd .. 910 | write_done 911 | } 912 | 913 | 914 | function build_libxml2 { 915 | write_library libxml2 "$LIBXML_VERSION" 916 | local libxml2_dir="./libxml2-$LIBXML_VERSION" 917 | 918 | if cant_use_cache "$libxml2_dir"; then 919 | rm -rf "$libxml2_dir" 920 | write_download 921 | download_from_mirror "libxml2-v$LIBXML_VERSION.tar.gz" "libxml2" | tar -xz >> "$DIR/install.log" 2>&1 922 | mv libxml2-v$LIBXML_VERSION "$libxml2_dir" 923 | 924 | write_configure 925 | cd "$libxml2_dir" 926 | if [ "$DO_STATIC" == "yes" ]; then 927 | local EXTRA_FLAGS="--enable-shared=no --enable-static=yes" 928 | else 929 | local EXTRA_FLAGS="--enable-shared=yes --enable-static=no" 930 | fi 931 | sed -i.bak 's{libtoolize --version{"$LIBTOOLIZE" --version{' autogen.sh #needed for glibtool on macos 932 | ./autogen.sh --prefix="$INSTALL_DIR" \ 933 | --without-iconv \ 934 | --without-python \ 935 | --without-lzma \ 936 | --with-zlib="$INSTALL_DIR" \ 937 | --config-cache \ 938 | $EXTRA_FLAGS \ 939 | $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 940 | 941 | write_compile 942 | make -j $THREADS >> "$DIR/install.log" 2>&1 && mark_cache 943 | else 944 | write_caching 945 | cd "$libxml2_dir" 946 | fi 947 | write_install 948 | make install >> "$DIR/install.log" 2>&1 949 | cd .. 950 | write_done 951 | } 952 | 953 | function build_libzip { 954 | #libzip 955 | if [ "$DO_STATIC" == "yes" ]; then 956 | local CMAKE_LIBZIP_EXTRA_FLAGS="-DBUILD_SHARED_LIBS=OFF" 957 | fi 958 | 959 | write_library libzip "$LIBZIP_VERSION" 960 | local libzip_dir="./libzip-$LIBZIP_VERSION" 961 | if cant_use_cache "$libzip_dir"; then 962 | rm -rf "$libzip_dir" 963 | write_download 964 | download_github_src "nih-at/libzip" "v$LIBZIP_VERSION" "libzip" | tar -zx >> "$DIR/install.log" 2>&1 965 | write_configure 966 | cd "$libzip_dir" 967 | 968 | #we're using OpenSSL for crypto 969 | cmake . \ 970 | -DCMAKE_PREFIX_PATH="$INSTALL_DIR" \ 971 | -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \ 972 | -DCMAKE_INSTALL_LIBDIR=lib \ 973 | $CMAKE_LIBZIP_EXTRA_FLAGS \ 974 | $CMAKE_GLOBAL_EXTRA_FLAGS \ 975 | -DBUILD_TOOLS=OFF \ 976 | -DBUILD_REGRESS=OFF \ 977 | -DBUILD_EXAMPLES=OFF \ 978 | -DBUILD_DOC=OFF \ 979 | -DENABLE_BZIP2=OFF \ 980 | -DENABLE_COMMONCRYPTO=OFF \ 981 | -DENABLE_GNUTLS=OFF \ 982 | -DENABLE_MBEDTLS=OFF \ 983 | -DENABLE_LZMA=OFF \ 984 | -DBUILD_OSSFUZZ=OFF \ 985 | -DENABLE_ZSTD=OFF >> "$DIR/install.log" 2>&1 986 | write_compile 987 | make -j $THREADS >> "$DIR/install.log" 2>&1 && mark_cache 988 | else 989 | write_caching 990 | cd "$libzip_dir" 991 | fi 992 | write_install 993 | make install >> "$DIR/install.log" 2>&1 994 | cd .. 995 | write_done 996 | } 997 | 998 | function build_sqlite3 { 999 | if [ "$DO_STATIC" == "yes" ]; then 1000 | local EXTRA_FLAGS="--disable-shared" 1001 | else 1002 | local EXTRA_FLAGS="--disable-static" 1003 | fi 1004 | 1005 | write_library sqlite3 "$SQLITE3_VERSION" 1006 | local sqlite3_dir="./sqlite3-$SQLITE3_VERSION" 1007 | 1008 | if cant_use_cache "$sqlite3_dir"; then 1009 | rm -rf "$sqlite3_dir" 1010 | write_download 1011 | download_from_mirror "sqlite-autoconf-$SQLITE3_VERSION.tar.gz" "sqlite3" | tar -zx >> "$DIR/install.log" 2>&1 1012 | mv sqlite-autoconf-$SQLITE3_VERSION "$sqlite3_dir" >> "$DIR/install.log" 2>&1 1013 | write_configure 1014 | cd "$sqlite3_dir" 1015 | LDFLAGS="$LDFLAGS -L${INSTALL_DIR}/lib" CPPFLAGS="$CPPFLAGS -I${INSTALL_DIR}/include" RANLIB=$RANLIB ./configure \ 1016 | --prefix="$INSTALL_DIR" \ 1017 | --disable-dependency-tracking \ 1018 | $EXTRA_FLAGS \ 1019 | $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 1020 | write_compile 1021 | make -j $THREADS >> "$DIR/install.log" 2>&1 && mark_cache 1022 | else 1023 | write_caching 1024 | cd "$sqlite3_dir" 1025 | fi 1026 | write_install 1027 | make install >> "$DIR/install.log" 2>&1 1028 | cd .. 1029 | write_done 1030 | } 1031 | 1032 | function build_libdeflate { 1033 | write_library libdeflate "$LIBDEFLATE_VERSION" 1034 | local libdeflate_dir="./libdeflate-$LIBDEFLATE_VERSION" 1035 | 1036 | if [ "$DO_STATIC" == "yes" ]; then 1037 | local CMAKE_LIBDEFLATE_EXTRA_FLAGS="-DLIBDEFLATE_BUILD_STATIC_LIB=ON -DLIBDEFLATE_BUILD_SHARED_LIB=OFF" 1038 | else 1039 | local CMAKE_LIBDEFLATE_EXTRA_FLAGS="-DLIBDEFLATE_BUILD_STATIC_LIB=OFF -DLIBDEFLATE_BUILD_SHARED_LIB=ON" 1040 | fi 1041 | 1042 | if cant_use_cache "$libdeflate_dir"; then 1043 | rm -rf "$libdeflate_dir" 1044 | write_download 1045 | download_github_src "ebiggers/libdeflate" "$LIBDEFLATE_VERSION" "libdeflate" | tar -zx >> "$DIR/install.log" 2>&1 1046 | cd "$libdeflate_dir" 1047 | write_configure 1048 | cmake . \ 1049 | -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \ 1050 | -DCMAKE_PREFIX_PATH="$INSTALL_DIR" \ 1051 | -DCMAKE_INSTALL_LIBDIR=lib \ 1052 | $CMAKE_GLOBAL_EXTRA_FLAGS \ 1053 | -DLIBDEFLATE_BUILD_GZIP=OFF \ 1054 | $CMAKE_LIBDEFLATE_EXTRA_FLAGS >> "$DIR/install.log" 2>&1 1055 | write_compile 1056 | make -j $THREADS >> "$DIR/install.log" 2>&1 && mark_cache 1057 | else 1058 | write_caching 1059 | cd "$libdeflate_dir" 1060 | fi 1061 | write_install 1062 | make install >> "$DIR/install.log" 2>&1 1063 | cd .. 1064 | write_done 1065 | } 1066 | 1067 | cd "$LIB_BUILD_DIR" 1068 | 1069 | build_zlib 1070 | build_gmp 1071 | build_openssl 1072 | build_curl 1073 | build_yaml 1074 | build_leveldb 1075 | if [ "$COMPILE_GD" == "yes" ]; then 1076 | build_libpng 1077 | build_libjpeg 1078 | HAS_GD="--enable-gd" 1079 | HAS_LIBJPEG="--with-jpeg" 1080 | else 1081 | HAS_GD="" 1082 | HAS_LIBJPEG="" 1083 | fi 1084 | 1085 | build_libxml2 1086 | build_libzip 1087 | build_sqlite3 1088 | build_libdeflate 1089 | 1090 | # PECL libraries 1091 | 1092 | # 1: extension name 1093 | # 2: extension version 1094 | # 3: URL to get .tar.gz from 1095 | # 4: Name of extracted directory to move 1096 | function get_extension_tar_gz { 1097 | echo -n " $1: downloading $2..." 1098 | download_file "$3" "php-ext-$1" | tar -zx >> "$DIR/install.log" 2>&1 1099 | mv "$4" "$BUILD_DIR/php/ext/$1" 1100 | write_done 1101 | } 1102 | 1103 | # 1: extension name 1104 | # 2: extension version 1105 | # 3: github user name 1106 | # 4: github repo name 1107 | # 5: version prefix (optional) 1108 | function get_github_extension { 1109 | get_extension_tar_gz "$1" "$2" "https://github.com/$3/$4/archive/$5$2.tar.gz" "$4-$2" 1110 | } 1111 | 1112 | # 1: extension name 1113 | # 2: extension version 1114 | function get_pecl_extension { 1115 | get_extension_tar_gz "$1" "$2" "https://pecl.php.net/get/$1-$2.tgz" "$1-$2" 1116 | } 1117 | 1118 | cd "$BUILD_DIR/php" 1119 | write_out "PHP" "Downloading additional extensions..." 1120 | 1121 | get_github_extension "pmmpthread" "$EXT_PMMPTHREAD_VERSION" "pmmp" "ext-pmmpthread" 1122 | 1123 | 1124 | get_github_extension "yaml" "$EXT_YAML_VERSION" "php" "pecl-file_formats-yaml" 1125 | #get_pecl_extension "yaml" "$EXT_YAML_VERSION" 1126 | 1127 | get_github_extension "igbinary" "$EXT_IGBINARY_VERSION" "igbinary" "igbinary" 1128 | 1129 | get_github_extension "recursionguard" "$EXT_RECURSIONGUARD_VERSION" "pmmp" "ext-recursionguard" 1130 | 1131 | echo -n " crypto: downloading $EXT_CRYPTO_VERSION..." 1132 | git clone https://github.com/bukka/php-crypto.git "$BUILD_DIR/php/ext/crypto" >> "$DIR/install.log" 2>&1 1133 | cd "$BUILD_DIR/php/ext/crypto" 1134 | git checkout "$EXT_CRYPTO_VERSION" >> "$DIR/install.log" 2>&1 1135 | git submodule update --init --recursive >> "$DIR/install.log" 2>&1 1136 | cd "$BUILD_DIR" 1137 | write_done 1138 | 1139 | get_github_extension "leveldb" "$EXT_LEVELDB_VERSION" "pmmp" "php-leveldb" 1140 | 1141 | get_github_extension "chunkutils2" "$EXT_CHUNKUTILS2_VERSION" "pmmp" "ext-chunkutils2" 1142 | 1143 | get_github_extension "libdeflate" "$EXT_LIBDEFLATE_VERSION" "pmmp" "ext-libdeflate" 1144 | 1145 | get_github_extension "morton" "$EXT_MORTON_VERSION" "pmmp" "ext-morton" 1146 | 1147 | get_github_extension "xxhash" "$EXT_XXHASH_VERSION" "pmmp" "ext-xxhash" 1148 | 1149 | get_github_extension "arraydebug" "$EXT_ARRAYDEBUG_VERSION" "pmmp" "ext-arraydebug" 1150 | 1151 | get_github_extension "encoding" "$EXT_ENCODING_VERSION" "pmmp" "ext-encoding" 1152 | 1153 | write_library "PHP" "$PHP_VERSION" 1154 | 1155 | write_configure 1156 | cd php 1157 | rm -f ./aclocal.m4 >> "$DIR/install.log" 2>&1 1158 | rm -rf ./autom4te.cache/ >> "$DIR/install.log" 2>&1 1159 | rm -f ./configure >> "$DIR/install.log" 2>&1 1160 | 1161 | ./buildconf --force >> "$DIR/install.log" 2>&1 1162 | 1163 | #hack for curl with pkg-config (ext/curl doesn't give --static to pkg-config on static builds) 1164 | if [ "$DO_STATIC" == "yes" ]; then 1165 | if [ -z "$PKG_CONFIG" ]; then 1166 | PKG_CONFIG="$(which pkg-config)" || true 1167 | fi 1168 | if [ ! -z "$PKG_CONFIG" ]; then 1169 | #only export this if pkg-config exists, otherwise leave it (it'll fall back to curl-config) 1170 | 1171 | echo '#!/bin/sh' > "$BUILD_DIR/pkg-config-wrapper" 1172 | echo 'exec '$PKG_CONFIG' "$@" --static' >> "$BUILD_DIR/pkg-config-wrapper" 1173 | chmod +x "$BUILD_DIR/pkg-config-wrapper" 1174 | export PKG_CONFIG="$BUILD_DIR/pkg-config-wrapper" 1175 | fi 1176 | fi 1177 | 1178 | 1179 | if [ "$IS_CROSSCOMPILE" == "yes" ]; then 1180 | sed -i=".backup" 's/pthreads_working=no/pthreads_working=yes/' ./configure 1181 | if [ "$IS_WINDOWS" != "yes" ]; then 1182 | if [ "$COMPILE_FOR_ANDROID" == "no" ]; then 1183 | export LIBS="$LIBS -lpthread -ldl -lresolv" 1184 | else 1185 | #workarounds for musl 1.2.5 1186 | if [ "$PHP_VERSION_ID" -lt 80400 ]; then 1187 | sed -i=".backup" 's/cookie_io_functions_use_off64_t=yes/cookie_io_functions_use_off64_t=no/' ./configure 1188 | export ac_cv_pread=yes 1189 | export ac_cv_pwrite=yes 1190 | else 1191 | export php_cv_type_cookie_off64_t=no 1192 | export php_cv_func_pread=yes 1193 | export php_cv_func_pwrite=yes 1194 | fi 1195 | export LIBS="$LIBS -lpthread -lresolv" 1196 | fi 1197 | else 1198 | export LIBS="$LIBS -lpthread" 1199 | fi 1200 | 1201 | mv ext/mysqlnd/config9.m4 ext/mysqlnd/config.m4 1202 | sed -i=".backup" "s{ext/mysqlnd/php_mysqlnd_config.h{config.h{" ext/mysqlnd/mysqlnd_portability.h 1203 | elif [ "$DO_STATIC" == "yes" ]; then 1204 | export LIBS="$LIBS -ldl" 1205 | fi 1206 | 1207 | if [ "$IS_WINDOWS" != "yes" ]; then 1208 | HAVE_PCNTL="--enable-pcntl" 1209 | else 1210 | HAVE_PCNTL="--disable-pcntl" 1211 | cp -f ./win32/build/config.* ./main >> "$DIR/install.log" 2>&1 1212 | sed 's:@PREFIX@:$DIR/bin/php7:' ./main/config.w32.h.in > ./wmain/config.w32.h 2>> "$DIR/install.log" 1213 | fi 1214 | 1215 | if [[ "$(uname -s)" == "Darwin" ]] && [[ "$IS_CROSSCOMPILE" != "yes" ]]; then 1216 | sed -i=".backup" 's/flock_type=unknown/flock_type=bsd/' ./configure 1217 | export EXTRA_CFLAGS=-lresolv 1218 | fi 1219 | 1220 | if [[ "$COMPILE_DEBUG" == "yes" ]]; then 1221 | HAS_DEBUG="--enable-debug" 1222 | else 1223 | HAS_DEBUG="--disable-debug" 1224 | fi 1225 | 1226 | if [ "$FSANITIZE_OPTIONS" != "" ]; then 1227 | CFLAGS="$CFLAGS -fsanitize=$FSANITIZE_OPTIONS -fno-omit-frame-pointer" 1228 | CXXFLAGS="$CXXFLAGS -fsanitize=$FSANITIZE_OPTIONS -fno-omit-frame-pointer" 1229 | LDFLAGS="-fsanitize=$FSANITIZE_OPTIONS $LDFLAGS" 1230 | fi 1231 | 1232 | RANLIB=$RANLIB CFLAGS="$CFLAGS $FLAGS_LTO" CXXFLAGS="$CXXFLAGS $FLAGS_LTO" LDFLAGS="$LDFLAGS $FLAGS_LTO" ./configure $PHP_OPTIMIZATION --prefix="$INSTALL_DIR" \ 1233 | --exec-prefix="$INSTALL_DIR" \ 1234 | --with-curl \ 1235 | --with-zlib \ 1236 | --with-zlib \ 1237 | --with-gmp \ 1238 | --with-yaml \ 1239 | --with-openssl \ 1240 | --with-zip \ 1241 | --with-libdeflate \ 1242 | $HAS_LIBJPEG \ 1243 | $HAS_GD \ 1244 | --with-leveldb="$INSTALL_DIR" \ 1245 | --without-readline \ 1246 | $HAS_DEBUG \ 1247 | --enable-chunkutils2 \ 1248 | --enable-morton \ 1249 | --enable-mbstring \ 1250 | --disable-mbregex \ 1251 | --enable-calendar \ 1252 | --enable-pmmpthread \ 1253 | --enable-fileinfo \ 1254 | --with-libxml \ 1255 | --enable-xml \ 1256 | --enable-dom \ 1257 | --enable-simplexml \ 1258 | --enable-xmlreader \ 1259 | --enable-xmlwriter \ 1260 | --disable-cgi \ 1261 | --disable-phpdbg \ 1262 | --disable-session \ 1263 | --without-pear \ 1264 | --without-iconv \ 1265 | --with-pdo-sqlite \ 1266 | --with-pdo-mysql \ 1267 | --with-pic \ 1268 | --enable-phar \ 1269 | --enable-ctype \ 1270 | --enable-sockets \ 1271 | --enable-shared=no \ 1272 | --enable-static=yes \ 1273 | --enable-shmop \ 1274 | --enable-zts \ 1275 | --disable-short-tags \ 1276 | $HAVE_PCNTL \ 1277 | $HAVE_MYSQLI \ 1278 | --enable-bcmath \ 1279 | --enable-cli \ 1280 | --enable-ftp \ 1281 | --enable-opcache=$HAVE_OPCACHE \ 1282 | --enable-opcache-jit=$HAVE_OPCACHE_JIT \ 1283 | --enable-igbinary \ 1284 | --with-crypto \ 1285 | --enable-recursionguard \ 1286 | --enable-xxhash \ 1287 | --enable-arraydebug \ 1288 | --enable-encoding \ 1289 | $HAVE_VALGRIND \ 1290 | $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 1291 | write_compile 1292 | if [ "$COMPILE_FOR_ANDROID" == "yes" ]; then 1293 | sed -i=".backup" 's/-export-dynamic/-all-static/g' Makefile 1294 | fi 1295 | sed -i=".backup" 's/PHP_BINARIES. pharcmd$/PHP_BINARIES)/g' Makefile 1296 | sed -i=".backup" 's/install-programs install-pharcmd$/install-programs/g' Makefile 1297 | 1298 | if [[ "$DO_STATIC" == "yes" ]]; then 1299 | sed -i=".backup" 's/--mode=link $(CC)/--mode=link $(CXX)/g' Makefile 1300 | fi 1301 | 1302 | make -j $THREADS >> "$DIR/install.log" 2>&1 1303 | write_install 1304 | make install >> "$DIR/install.log" 2>&1 1305 | 1306 | function relativize_macos_library_paths { 1307 | IFS=$'\n' OTOOL_OUTPUT=($(otool -L "$1")) 1308 | 1309 | for (( i=0; i<${#OTOOL_OUTPUT[@]}; i++ )) 1310 | do 1311 | CURRENT_DYLIB_NAME=$(echo ${OTOOL_OUTPUT[$i]} | sed 's# (compatibility version .*##' | xargs) 1312 | if [[ "$CURRENT_DYLIB_NAME" == "$INSTALL_DIR/"* ]]; then 1313 | NEW_DYLIB_NAME=$(echo "$CURRENT_DYLIB_NAME" | sed "s{$INSTALL_DIR{@loader_path/..{" | xargs) 1314 | install_name_tool -change "$CURRENT_DYLIB_NAME" "$NEW_DYLIB_NAME" "$1" >> "$DIR/install.log" 2>&1 1315 | elif [[ "$CURRENT_DYLIB_NAME" != "/usr/lib/"* ]] && [[ "$CURRENT_DYLIB_NAME" != "/System/"* ]] && [[ "$CURRENT_DYLIB_NAME" != "@loader_path"* ]] && [[ "$CURRENT_DYLIB_NAME" != "@rpath"* ]]; then 1316 | write_out "ERROR" "Detected linkage to non-local non-system library $CURRENT_DYLIB_NAME by $1" 1317 | exit 1 1318 | fi 1319 | done 1320 | } 1321 | 1322 | function relativize_macos_all_libraries_paths { 1323 | set +e 1324 | for _library in $(find "$INSTALL_DIR" -name "*.dylib" -o -name "*.so"); do 1325 | relativize_macos_library_paths "$_library" 1326 | done 1327 | set -e 1328 | } 1329 | 1330 | if [[ "$(uname -s)" == "Darwin" ]] && [[ "$IS_CROSSCOMPILE" != "yes" ]]; then 1331 | set +e 1332 | install_name_tool -delete_rpath "$INSTALL_DIR/lib" "$INSTALL_DIR/bin/php" >> "$DIR/install.log" 2>&1 1333 | 1334 | relativize_macos_library_paths "$INSTALL_DIR/bin/php" 1335 | 1336 | relativize_macos_all_libraries_paths 1337 | set -e 1338 | fi 1339 | 1340 | write_status "generating php.ini" 1341 | trap - DEBUG 1342 | TIMEZONE=$(date +%Z) 1343 | echo "memory_limit=1024M" >> "$INSTALL_DIR/bin/php.ini" 1344 | echo "date.timezone=$TIMEZONE" >> "$INSTALL_DIR/bin/php.ini" 1345 | echo "short_open_tag=0" >> "$INSTALL_DIR/bin/php.ini" 1346 | echo "asp_tags=0" >> "$INSTALL_DIR/bin/php.ini" 1347 | echo "phar.require_hash=1" >> "$INSTALL_DIR/bin/php.ini" 1348 | echo "igbinary.compact_strings=0" >> "$INSTALL_DIR/bin/php.ini" 1349 | if [[ "$COMPILE_DEBUG" == "yes" ]]; then 1350 | echo "zend.assertions=1" >> "$INSTALL_DIR/bin/php.ini" 1351 | else 1352 | echo "zend.assertions=-1" >> "$INSTALL_DIR/bin/php.ini" 1353 | fi 1354 | echo "error_reporting=-1" >> "$INSTALL_DIR/bin/php.ini" 1355 | echo "display_errors=1" >> "$INSTALL_DIR/bin/php.ini" 1356 | echo "display_startup_errors=1" >> "$INSTALL_DIR/bin/php.ini" 1357 | echo "recursionguard.enabled=0 ;disabled due to minor performance impact, only enable this if you need it for debugging" >> "$INSTALL_DIR/bin/php.ini" 1358 | 1359 | if [ "$HAVE_OPCACHE" == "yes" ]; then 1360 | if [ "$PHP_VERSION_ID" -lt 80500 ]; then 1361 | echo "zend_extension=opcache.so" >> "$INSTALL_DIR/bin/php.ini" 1362 | fi 1363 | echo "opcache.enable=1" >> "$INSTALL_DIR/bin/php.ini" 1364 | echo "opcache.enable_cli=1" >> "$INSTALL_DIR/bin/php.ini" 1365 | echo "opcache.save_comments=1" >> "$INSTALL_DIR/bin/php.ini" 1366 | echo "opcache.validate_timestamps=1" >> "$INSTALL_DIR/bin/php.ini" 1367 | echo "opcache.revalidate_freq=0" >> "$INSTALL_DIR/bin/php.ini" 1368 | echo "opcache.file_update_protection=0" >> "$INSTALL_DIR/bin/php.ini" 1369 | echo "opcache.optimization_level=0x7FFEBFFF ;https://github.com/php/php-src/blob/53c1b485741f31a17b24f4db2b39afeb9f4c8aba/ext/opcache/Optimizer/zend_optimizer.h" >> "$INSTALL_DIR/bin/php.ini" 1370 | if [ "$HAVE_OPCACHE_JIT" == "yes" ]; then 1371 | echo "" >> "$INSTALL_DIR/bin/php.ini" 1372 | echo "; ---- ! WARNING ! ----" >> "$INSTALL_DIR/bin/php.ini" 1373 | echo "; JIT can provide big performance improvements, but it may make your server crash or behave in weird ways. Use it at your own risk." >> "$INSTALL_DIR/bin/php.ini" 1374 | echo "; See https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.jit for possible options." >> "$INSTALL_DIR/bin/php.ini" 1375 | echo "opcache.jit=off" >> "$INSTALL_DIR/bin/php.ini" 1376 | echo "opcache.jit_buffer_size=128M" >> "$INSTALL_DIR/bin/php.ini" 1377 | fi 1378 | fi 1379 | if [[ "$COMPILE_TARGET" == "mac-"* ]]; then 1380 | #we don't have permission to allocate executable memory on macOS due to not being codesigned 1381 | #workaround this for now by disabling PCRE JIT 1382 | echo "" >> "$INSTALL_DIR/bin/php.ini" 1383 | echo "pcre.jit=off" >> "$INSTALL_DIR/bin/php.ini" 1384 | fi 1385 | 1386 | write_done 1387 | 1388 | if [[ "$HAVE_XDEBUG" == "yes" ]]; then 1389 | get_github_extension "xdebug" "$EXT_XDEBUG_VERSION" "xdebug" "xdebug" 1390 | write_library "xdebug" "$EXT_XDEBUG_VERSION" 1391 | cd "$BUILD_DIR/php/ext/xdebug" 1392 | write_configure 1393 | "$INSTALL_DIR/bin/phpize" >> "$DIR/install.log" 2>&1 1394 | ./configure --with-php-config="$INSTALL_DIR/bin/php-config" >> "$DIR/install.log" 2>&1 1395 | write_compile 1396 | make -j4 >> "$DIR/install.log" 2>&1 1397 | write_install 1398 | make install >> "$DIR/install.log" 2>&1 1399 | echo "" >> "$INSTALL_DIR/bin/php.ini" 2>&1 1400 | echo ";WARNING: When loaded, xdebug 3.2.0 will cause segfaults whenever an uncaught error is thrown, even if xdebug.mode=off. Load it at your own risk." >> "$INSTALL_DIR/bin/php.ini" 2>&1 1401 | echo ";zend_extension=xdebug.so" >> "$INSTALL_DIR/bin/php.ini" 2>&1 1402 | echo ";https://xdebug.org/docs/all_settings#mode" >> "$INSTALL_DIR/bin/php.ini" 2>&1 1403 | echo "xdebug.mode=off" >> "$INSTALL_DIR/bin/php.ini" 2>&1 1404 | echo "xdebug.start_with_request=yes" >> "$INSTALL_DIR/bin/php.ini" 2>&1 1405 | echo ";The following overrides allow profiler, gc stats and traces to work correctly in ZTS" >> "$INSTALL_DIR/bin/php.ini" 2>&1 1406 | echo "xdebug.profiler_output_name=cachegrind.%s.%p.%r" >> "$INSTALL_DIR/bin/php.ini" 2>&1 1407 | echo "xdebug.gc_stats_output_name=gcstats.%s.%p.%r" >> "$INSTALL_DIR/bin/php.ini" 2>&1 1408 | echo "xdebug.trace_output_name=trace.%s.%p.%r" >> "$INSTALL_DIR/bin/php.ini" 2>&1 1409 | write_done 1410 | write_out INFO "Xdebug is included, but disabled by default. To enable it, change 'xdebug.mode' in your php.ini file." 1411 | fi 1412 | 1413 | 1414 | cd "$DIR" 1415 | if [ "$DO_CLEANUP" == "yes" ]; then 1416 | write_out "INFO" "Cleaning up" 1417 | rm -r -f "$BUILD_DIR" >> "$DIR/install.log" 2>&1 1418 | rm -f "$INSTALL_DIR/bin/curl"* >> "$DIR/install.log" 2>&1 1419 | rm -f "$INSTALL_DIR/bin/curl-config"* >> "$DIR/install.log" 2>&1 1420 | rm -f "$INSTALL_DIR/bin/c_rehash"* >> "$DIR/install.log" 2>&1 1421 | rm -f "$INSTALL_DIR/bin/openssl"* >> "$DIR/install.log" 2>&1 1422 | rm -r -f "$INSTALL_DIR/man" >> "$DIR/install.log" 2>&1 1423 | rm -r -f "$INSTALL_DIR/share/man" >> "$DIR/install.log" 2>&1 1424 | rm -r -f "$INSTALL_DIR/php" >> "$DIR/install.log" 2>&1 1425 | rm -r -f "$INSTALL_DIR/misc" >> "$DIR/install.log" 2>&1 1426 | rm -r -f "$INSTALL_DIR/lib/"*.a >> "$DIR/install.log" 2>&1 1427 | rm -r -f "$INSTALL_DIR/lib/"*.la >> "$DIR/install.log" 2>&1 1428 | rm -r -f "$INSTALL_DIR/include" >> "$DIR/install.log" 2>&1 1429 | fi 1430 | 1431 | if [ "$SEPARATE_SYMBOLS" != "no" ]; then 1432 | echo -n "[INFO] Separating debugging symbols into $SYMBOLS_DIR..." 1433 | rm -rf "$SYMBOLS_DIR" || true 2>&1 1434 | mkdir -p "$SYMBOLS_DIR" || true 2>&1 1435 | cp -r "$INSTALL_DIR"/* "$SYMBOLS_DIR" 1436 | cd "$INSTALL_DIR" 1437 | find "lib" \( -name '*.so' -o -name '*.so.*' -o -name '*.dylib' -o -name '*.dylib.*' \) -print0 | while IFS= read -r -d '' file; do 1438 | "$STRIP" -S "$file" >> "$DIR/install.log" 2>&1 || true #if this fails, this probably isn't an executable binary 1439 | done 1440 | for file in "bin/"*; do 1441 | "$STRIP" -S "$file" >> "$DIR/install.log" 2>&1 || true #if this fails, this probably isn't an executable binary 1442 | done 1443 | cd "$DIR" 1444 | write_done 1445 | fi 1446 | 1447 | date >> "$DIR/install.log" 2>&1 1448 | write_out "PocketMine" "You should start the server now using \"./start.sh\"." 1449 | write_out "PocketMine" "If it doesn't work, please send the \"install.log\" file to the Bug Tracker." 1450 | --------------------------------------------------------------------------------