Download the PHP package masakielastic/hello-zig without Composer
On this page you can find all versions of the php package masakielastic/hello-zig. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download masakielastic/hello-zig
More information about masakielastic/hello-zig
Files in masakielastic/hello-zig
Download masakielastic/hello-zig
More information about masakielastic/hello-zig
Files in masakielastic/hello-zig
Vendor masakielastic
Package hello-zig
Short Description PHP extension that returns Hello World from a Zig FFI library
License MIT
Package hello-zig
Short Description PHP extension that returns Hello World from a Zig FFI library
License MIT
Please rate this library. Is it a good library?
Informations about the package hello-zig
hello-zig
Learning-focused sample of a PHP extension that calls Zig through a C ABI (FFI boundary).
Learning goals
- Understand how PHP extension C code calls a Zig function.
- Understand how Zig builds a static library consumed by PHP extension build.
- Understand how PIE metadata points to the extension build directory.
Project layout
composer.json: PIE metadata (type: php-ext, build path, extension name)ext/config.m4: phpize/autoconf build integration and Zig library linkingext/hello_zig.c: PHP function registration and call into Zig ABIext/zig/build.zig: Zig static library build definitionext/zig/src/hellozig.zig: exported Zig function (hellozig_message)ext/zig/src/hellozig.h: C header consumed fromhello_zig.cext/tests/001_hello_zig_hello.phpt: runtime behavior test
How the call flow works
- PHP userland calls
hello_zig_hello(). - PHP extension C code (
ext/hello_zig.c) invokeshellozig_message(). hellozig_message()is implemented in Zig and exported with C ABI.- Returned C string is sent back to PHP as a string result.
Install with PIE (from Packagist)
This package is intended to be installable from Packagist:
https://packagist.org/packages/masakielastic/hello-zig
Example:
Expected output:
Build and run (from clean state)
Prerequisites:
phpizeand PHP development headers- Zig compiler (on
PATH, or provided viaZIG=/path/to/zig)
Expected output:
Run tests
What to edit while learning
- Change return text:
ext/zig/src/hellozig.zig - Add new PHP function:
ext/hello_zig.c(function entry table + implementation) - Add new Zig export and header declaration:
ext/zig/src/hellozig.zigandext/zig/src/hellozig.h - Add regression test:
ext/tests/*.phpt
Troubleshooting
zig command not found:- Pass explicit path:
ZIG=/absolute/path/to/zig ./configure --enable-hello-zig
- Pass explicit path:
- Build errors after file moves:
- Re-run from clean build dir:
phpizethen./configurethenmake
- Re-run from clean build dir:
- Extension not loading:
- Confirm
.soexists atext/modules/hello_zig.so - Use absolute path in
-dextension=...
- Confirm
All versions of hello-zig with dependencies
PHP Build Version
Package Version
Requires
php Version
>=8.1
The package masakielastic/hello-zig contains the following files
Loading the files please wait ...