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