{"id":16827236,"url":"https://github.com/petk/php-build-system","last_synced_at":"2025-04-11T04:12:35.332Z","repository":{"id":182619068,"uuid":"668743884","full_name":"petk/php-build-system","owner":"petk","description":"Carefully crafted, CMake-based PHP build system","archived":false,"fork":false,"pushed_at":"2025-04-07T23:03:51.000Z","size":6810,"stargazers_count":23,"open_issues_count":7,"forks_count":2,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-11T04:12:28.306Z","etag":null,"topics":["autotools","c","cmake","php"],"latest_commit_sha":null,"homepage":"","language":"CMake","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/petk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"docs/CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-20T13:49:21.000Z","updated_at":"2025-04-07T23:03:55.000Z","dependencies_parsed_at":"2023-07-20T17:41:17.648Z","dependency_job_id":"d0d32695-0c31-4583-99d6-9a218ae3655b","html_url":"https://github.com/petk/php-build-system","commit_stats":null,"previous_names":["petk/php-build-system"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petk%2Fphp-build-system","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petk%2Fphp-build-system/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petk%2Fphp-build-system/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petk%2Fphp-build-system/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/petk","download_url":"https://codeload.github.com/petk/php-build-system/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248339225,"owners_count":21087215,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autotools","c","cmake","php"],"created_at":"2024-10-13T11:20:06.228Z","updated_at":"2025-04-11T04:12:35.297Z","avatar_url":"https://github.com/petk.png","language":"CMake","funding_links":[],"categories":["CMake"],"sub_categories":[],"readme":"# PHP build system\n\n[![PHP version](https://img.shields.io/badge/PHP-8.5-777BB4?logo=php\u0026labelColor=17181B)](https://www.php.net/)\n[![CMake version](https://img.shields.io/badge/CMake-3.25-064F8C?logo=cmake\u0026labelColor=17181B)](https://cmake.org)\n[![C11](https://img.shields.io/badge/standard-C11-A8B9CC?logo=C\u0026labelColor=17181B)](https://port70.net/~nsz/c/c11/n1570.html)\n[![GNU](https://img.shields.io/badge/-GNU-A42E2B?logo=gnu\u0026labelColor=17181B)](https://www.gnu.org/)\n[![Ninja](https://img.shields.io/badge/%F0%9F%A5%B7-Ninja%20build-DD6620?labelColor=17181B)](https://ninja-build.org/)\n\nThis repository delves into the core of the PHP build system, elucidating the\nintricacies of how to build PHP with CMake.\n\n![ElePHPant](docs/images/elephpant.jpg)\n\n## Quick usage - TL;DR\n\n### Step 1 - Install prerequisites\n\n```sh\n# Prerequisites for Debian-based distributions:\nsudo apt install cmake gcc g++ bison libsqlite3-dev\n\n# Prerequisites for Fedora-based distributions:\nsudo dnf install cmake gcc gcc-c++ bison sqlite-devel\n```\n\n\u003cdetails\u003e\n  \u003csummary\u003eClick here for more platforms\u003c/summary\u003e\n\n  ```sh\n  # Prerequisites for macOS:\n  xcode-select --install   # XCode command line tools\n  brew install cmake bison # See https://brew.sh how to install Homebrew\n\n  # Prerequisites for Alpine Linux:\n  sudo apk add --no-cache cmake make gcc g++ musl-dev bison sqlite-dev\n\n  # Prerequisites for BSD-based systems:\n  sudo pkg install cmake bison sqlite3\n\n  # Prerequisites for Haiku:\n  pkgman install cmake bison sqlite_devel\n\n  # Prerequisites for Solaris/illumos-based systems:\n  sudo pkg install cmake bison sqlite-3\n  ```\n\u003c/details\u003e\n\n### Step 2 - Clone this repository\n\n```sh\ngit clone https://github.com/petk/php-build-system\n\ncd php-build-system\n```\n\n### Step 3 - Generate build system to a build directory\n\n```sh\ncmake -B php-build\n```\n\n### Step 4 - Build PHP in parallel\n\n```sh\ncmake --build php-build -j\n```\n\nAfter build is complete, a PHP binary should be available to run:\n\n```sh\n./php-build/php/sapi/cli/php -v\n```\n\n## Introduction\n\nPHP developers typically opt for convenient methods to set up PHP on their\nmachines, such as utilizing prebuilt Linux packages available in their Linux\ndistribution repositories, deploying Docker images, or relying on user-friendly\nstacks that bundle PHP, its extensions, web server, and database into a unified\ninstallation package.\n\n```sh\n# Debian-based distributions:\nsudo apt install php...\n\n# Fedora-based distributions:\nsudo dnf install php...\n```\n\nIn contrast, the practice of building PHP from source code is primarily reserved\nfor specific purposes, such as PHP source code development or extensive\ncustomization of PHP configurations on a particular system. This approach is\nless commonly employed by everyday PHP developers due to its intricate and\ntime-consuming nature.\n\nIn the realm of software development, a build system is a collection of tools\nand files that automate the process of compiling, linking, and assembling the\nproject's source code into its final form, ready to be executed. It helps\ndevelopers with repetitive tasks and ensures consistency and correctness in the\nbuild process for various platforms and hardware out there.\n\nA key function of a build system in the context of C/C++ software development is\nto establish a structured framework that guides how code should be written.\nBeyond its primary role of compiling source files into executable programs, the\nbuild system plays a pivotal educational role, imparting best practices and\ncoding standards to developers. By enforcing consistency and adherence to coding\nconventions, it fosters the creation of high-quality code, ultimately enhancing\nsoftware maintainability and reliability.\n\nAdditionally, the build system aims to enable developers to work efficiently by\nabstracting away system-specific details, allowing them to focus on the logic\nand usability of their code. When adding a new source file or making minor\nmodifications, developers shouldn't have to delve into the inner workings of the\nbuild system, sift through extensive build system documentation or extensively\nexplore the complexities of the underlying system.\n\nThere are numerous well-known build systems available, ranging from the veteran\nGNU Autotools and the widely adopted CMake, to the efficient Ninja, versatile\nSCons, adaptable Meson, nimble xmake, cutting-edge Zig build system, and even\nthe simplest manual usage of Make.\n\n## PHP directory structure\n\nTo understand the PHP source code better, it would be beneficial to grasp its\ndirectory structure. PHP is developed at the\n[php-src GitHub repository](https://github.com/php/php-src).\n\nAfter cloning the repository:\n\n```sh\ngit clone https://github.com/php/php-src\ncd php-src\n```\n\nthere is a large monolithic repository consisting of C source code files, PHP\ntests and other associated files:\n\n```sh\n📂 \u003cphp-src\u003e\n├─📂 .git                        # Git configuration and source directory\n├─📂 benchmark                   # Benchmark some common applications in CI\n├─📂 build                       # *nix build system files\n├─📂 docs                        # PHP internals documentation\n└─📂 ext                         # PHP core extensions\n  └─📂 bcmath                    # The bcmath PHP extension\n    ├─📂 libbcmath               # The bcmath library forked and maintained in php-src\n    ├─📂 tests                   # *.phpt test files for extension\n    ├─📄 bcmath.stub.php         # A stub file for the bcmath extension functions\n    └─📄 ...\n  └─📂 curl                      # The curl PHP extension\n    ├─📄 sync-constants.php      # The curl symbols checker\n    └─📄 ...\n  └─📂 date                      # The date/time PHP extension\n    └─📂 lib                     # Bundled datetime library https://github.com/derickr/timelib\n      └─📄 ...\n    └─📄 ...\n  ├─📂 dl_test                   # Extension for testing dl()\n  └─📂 dom\n    ├─📂 lexbor                  # https://github.com/lexbor/lexbor\n    └─📄 ...\n  └─📂 ffi                       # The FFI PHP extension\n    ├─📄 ffi_parser.c            # Generated by https://github.com/dstogov/llk\n    └─📄 ...\n  └─📂 fileinfo                  # The fileinfo PHP extension\n    ├─📂 libmagic                # Modified libmagic https://github.com/file/file\n    ├─📄 data_file.c             # Generated by `ext/fileinfo/create_data_file.php`\n    ├─📄 libmagic.patch          # Modifications patch from upstream libmagic\n    ├─📄 magicdata.patch         # Modifications patch from upstream libmagic\n    └─📄 ...\n  └─📂 gd                        # The GD PHP extension\n    ├─📂 libgd                   # Bundled and modified GD library https://github.com/libgd/libgd\n    └─📄 ...\n  └─📂 mbstring                  # The Multibyte string PHP extension\n    ├─📂 libmbfl                 # Forked and maintained in php-src\n    ├─📄 unicode_data.h          # Generated by `ext/mbstring/ucgendat/ucgendat.php`\n    └─📄 ...\n  └─📂 opcache                   # The OPcache PHP extension\n    └─📂 jit                     # OPcache Jit\n      └─📂 ir                    # Bundled part of IR framework https://github.com/dstogov/ir\n        └─📂 dynasm              # DynASM encoding engine\n          ├─📄 minilua.c         # Customized Lua scripting language to build LuaJIT\n          └─📄 ...\n        ├─📄 gen_ir_fold_hash    # IR folding engine generator created at build\n        ├─📄 ir_emit_\u003carch\u003e.h    # IR folding engine rules generated by minilua\n        ├─📄 minilua             # Executable tool created at build\n        └─📄 ...\n  └─📂 pcre                      # The PCRE PHP extension\n    ├─📂 pcre2lib                # https://www.pcre.org/\n    └─📄 ...\n  ├─📂 skeleton                  # Skeleton for new extensions using `ext/ext_skel.php`\n  └─📂 standard                  # Always enabled core extension\n    └─📂 html_tables\n      ├─📂 mappings              # https://www.unicode.org/Public/MAPPINGS/\n      └─📄 ...\n    ├─📄 credits_ext.h           # Generated by `scripts/dev/credits`\n    ├─📄 credits_sapi.h          # Generated by `scripts/dev/credits`\n    ├─📄 html_tables.h           # Generated by `ext/standard/html_tables/html_table_gen.php`\n    └─📄 ...\n  └─📂 tokenizer                 # The tokenizer PHP extension\n    ├─📄 tokenizer_data.c        # Generated by `ext/tokenizer/tokenizer_data_gen.php`\n    ├─📄 tokenizer_data_stub.php # Generated by `ext/tokenizer/tokenizer_data_gen.php`\n    └─📄 ...\n  └─📂 zend_test                 # For testing internal APIs. Not needed for regular builds\n    └─📄 ...\n  └─📂 zip/                      # Bundled https://github.com/pierrejoye/php_zip\n    └─📄 ...\n  ├─📂 ...\n  └─📄 ext_skel.php              # Helper script that creates a new PHP extension\n└─📂 main                        # Binding that ties extensions, SAPIs, and Zend Engine together\n  ├─📂 streams                   # Streams layer subsystem\n  ├─📄 debug_gdb_scripts.c       # Generated by `scripts/gdb/debug_gdb_scripts_gen.php`\n  └─📄 ...\n├─📂 modules                     # Shared libraries, created when building PHP\n├─📂 pear                        # PEAR installation\n└─📂 sapi                        # PHP SAPI (Server API) modules\n  └─📂 cli                       # Command-line PHP SAPI module\n    ├─📄 mime_type_map.h         # Generated by `sapi/cli/generate_mime_type_map.php`\n    └─📄 ...\n  └─📄 ...\n├─📂 scripts                     # php-config, phpize and internal development scripts\n├─📂 tests                       # Core features tests\n├─📂 TSRM                        # Thread Safe Resource Manager\n└─📂 Zend                        # Zend Engine\n  ├─📂 asm                       # Bundled from src/asm in https://github.com/boostorg/context\n  ├─📂 Optimizer                 # For faster PHP execution through opcode caching and optimization\n  ├─📂 tests                     # PHP tests *.phpt files for Zend Engine\n  ├─📄 zend_vm_execute.h         # Generated by `Zend/zend_vm_gen.php`\n  ├─📄 zend_vm_opcodes.c         # Generated by `Zend/zend_vm_gen.php`\n  ├─📄 zend_vm_opcodes.h         # Generated by `Zend/zend_vm_gen.php`\n  └─📄 ...\n├─📂 win32                       # Windows build files\n└─📄 ...\n```\n\n## Why CMake?\n\nAt the time of writing, CMake is actively developed, and many developers may\nalready be familiar with it, making C code more appealing to new contributors.\nNumerous IDEs offer excellent CMake integration for C/C++ projects.\n\nCMake shares many similarities with Autotools, which simplifies the learning\ncurve for those already accustomed to building C code using existing systems.\n\nNotably, CMake features better out-of-the-box support on Windows systems, where\nAutotools may encounter issues without additional adaptations and adjustments in\nthe build process.\n\nDespite Autotools potentially seeming complex and arcane to new developers,\nunfamiliar with it, it remains a robust and solid build system option for C/C++\nprojects on \\*nix systems. Many large open-source projects use Autotools, and\nsome even incorporate it alongside CMake.\n\n## Documentation\n\n* CMake\n  * [Introduction to CMake](/docs/cmake/introduction.md)\n  * [CMake-based PHP build system](/docs/cmake/cmake.md)\n  * [Configuration](/docs/cmake/configuration.md)\n  * [CMake code style](/docs/cmake/cmake-code-style.md)\n  * [PHP native and CMake-based build system differences](/docs/cmake/differences.md)\n* [Dependencies in C/C++ projects](/docs/dependencies.md)\n* [Autotools-based PHP build system](/docs/autotools.md)\n* [Windows build system for PHP](/docs/windows.md)\n* [PHP installation](/docs/php-installation.md)\n* [Cross-compiling](/docs/cross-compiling.md)\n* [PHP build system evolution](/docs/evolution.md)\n* [Introduction to C](/docs/c.md)\n* [Frequently asked questions](/docs/faq.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpetk%2Fphp-build-system","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpetk%2Fphp-build-system","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpetk%2Fphp-build-system/lists"}