Skip to content

Commit 54e5518

Browse files
authored
Example for linking a custom extension to PHP (#919)
## Summary Shows how to use flakes to add a custom extension (.so file) to PHP. I think this is dynamically linking the extension instead of compiling it into PHP -- not sure how to compile it statically ## How was it tested? Follow the instructions in the Readme
1 parent ba7d6e9 commit 54e5518

File tree

5 files changed

+106
-0
lines changed

5 files changed

+106
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Adding a custom PHP Extension
2+
3+
This example shows how to add a custom PHP extension to a PHP package using Flakes. This uses an extension built from the [PHP Skeleton Extension](https://github.com/improved-php-library/skeleton-php-ext) from [Improved PHP Library](https://github.com/improved-php-library)
4+
5+
To test this example:
6+
7+
1. Run `devbox shell` to start your shell
8+
2. Start PHP in interactive mode with `php -a`
9+
3. Run `echo skeleton_nop("Hello World");` to test the extension. This should print `Hello World` to the screen
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"packages": [
3+
"path:my-php-flake#php"
4+
],
5+
"shell": {
6+
"init_hook": null
7+
},
8+
"nixpkgs": {
9+
"commit": "f80ac848e3d6f0c12c52758c0f25c10c97ca3b62"
10+
}
11+
}

examples/flakes/php-extension/my-php-flake/flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
description =
3+
"A flake that outputs PHP with a custom extension (skeleton.so) linked.";
4+
5+
inputs = {
6+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
7+
flake-utils.url = "github:numtide/flake-utils";
8+
};
9+
10+
outputs = { self, nixpkgs, flake-utils }:
11+
flake-utils.lib.eachDefaultSystem (system:
12+
let pkgs = nixpkgs.legacyPackages.${system};
13+
in {
14+
packages = {
15+
# Customize and export the PHP package with some extra config
16+
php = pkgs.php.buildEnv {
17+
# extraConfig will add the line below to our php.ini
18+
# ${self} is a variable representing the current flake
19+
extraConfig = ''
20+
extension=${self}/skeleton.so
21+
'';
22+
};
23+
};
24+
});
25+
}
50.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)