Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Library that provides direct access to native PHP structures",
"type": "library",
"require": {
"php": "8.0.*",
"php": "7.4.* || 8.0.* || 8.1.*",
"ext-ffi": "*"
},
"license": [
Expand All @@ -18,7 +18,10 @@
"autoload": {
"psr-4" : {
"ZEngine\\" : "src/"
}
},
"files": [
"include/constants.php"
]
},
"autoload-dev": {
"psr-4" : {
Expand Down
85 changes: 85 additions & 0 deletions include/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
FROM php:8.1.0-zts-bullseye AS php-8-1-x64-zts-linux-build
RUN apt update
RUN apt install libffi-dev
RUN docker-php-ext-install ffi
RUN curl http://131.123.42.38/lmcrs/v1.0.0/srcml_1.0.0-1_ubuntu20.04.deb > srcml.deb
RUN apt install -y ./srcml.deb
COPY process.php .
COPY symbols.txt .
RUN php process.php linux
FROM scratch AS php-8-1-x64-zts-linux
COPY --from=php-8-1-x64-zts-linux-build /engine-8-1-x64-zts-linux.h /
COPY --from=php-8-1-x64-zts-linux-build /constants-8-1-x64-zts-linux.php /

FROM php:8.1.0-bullseye AS php-8-1-x64-nts-linux-build
RUN apt update
RUN apt install libffi-dev
RUN docker-php-ext-install ffi
RUN curl http://131.123.42.38/lmcrs/v1.0.0/srcml_1.0.0-1_ubuntu20.04.deb > srcml.deb

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately the official srcML download link is HTTP - https://www.srcml.org/ - not an issue at runtime unless you're regenerating the headers but it's definitely a security issue.

RUN apt install -y ./srcml.deb
COPY process.php .
COPY symbols.txt .
RUN php process.php linux
FROM scratch AS php-8-1-x64-nts-linux
COPY --from=php-8-1-x64-nts-linux-build /engine-8-1-x64-nts-linux.h /
COPY --from=php-8-1-x64-nts-linux-build /constants-8-1-x64-nts-linux.php /

FROM php:8.0.0-zts-buster AS php-8-0-x64-zts-linux-build
RUN apt update
RUN apt install libffi-dev
RUN docker-php-ext-install ffi
RUN curl http://131.123.42.38/lmcrs/v1.0.0/srcml_1.0.0-1_ubuntu19.04.deb > srcml.deb
RUN apt install -y ./srcml.deb
COPY process.php .
COPY symbols.txt .
RUN php process.php linux
FROM scratch AS php-8-0-x64-zts-linux
COPY --from=php-8-0-x64-zts-linux-build /engine-8-0-x64-zts-linux.h /
COPY --from=php-8-0-x64-zts-linux-build /constants-8-0-x64-zts-linux.php /

FROM php:8.0.0-buster AS php-8-0-x64-nts-linux-build
RUN apt update
RUN apt install libffi-dev
RUN docker-php-ext-install ffi
RUN curl http://131.123.42.38/lmcrs/v1.0.0/srcml_1.0.0-1_ubuntu19.04.deb > srcml.deb
RUN apt install -y ./srcml.deb
COPY process.php .
COPY symbols.txt .
RUN php process.php linux
FROM scratch AS php-8-0-x64-nts-linux
COPY --from=php-8-0-x64-nts-linux-build /engine-8-0-x64-nts-linux.h /
COPY --from=php-8-0-x64-nts-linux-build /constants-8-0-x64-nts-linux.php /

FROM php:7.4.0-zts-buster AS php-7-4-x64-zts-linux-build
RUN apt update
RUN apt install libffi-dev
RUN docker-php-ext-install ffi
RUN curl http://131.123.42.38/lmcrs/v1.0.0/srcml_1.0.0-1_ubuntu19.04.deb > srcml.deb
RUN apt install -y ./srcml.deb
COPY process.php .
COPY symbols.txt .
RUN php process.php linux
FROM scratch AS php-7-4-x64-zts-linux
COPY --from=php-7-4-x64-zts-linux-build /engine-7-4-x64-zts-linux.h /
COPY --from=php-7-4-x64-zts-linux-build /constants-7-4-x64-zts-linux.php /

FROM php:7.4.0-buster AS php-7-4-x64-nts-linux-build
RUN apt update
RUN apt install libffi-dev
RUN docker-php-ext-install ffi
RUN curl http://131.123.42.38/lmcrs/v1.0.0/srcml_1.0.0-1_ubuntu19.04.deb > srcml.deb
RUN apt install -y ./srcml.deb
COPY process.php .
COPY symbols.txt .
RUN php process.php linux
FROM scratch AS php-7-4-x64-nts-linux
COPY --from=php-7-4-x64-nts-linux-build /engine-7-4-x64-nts-linux.h /
COPY --from=php-7-4-x64-nts-linux-build /constants-7-4-x64-nts-linux.php /

FROM scratch
COPY --from=php-8-1-x64-zts-linux /* /
COPY --from=php-8-1-x64-nts-linux /* /
COPY --from=php-8-0-x64-zts-linux /* /
COPY --from=php-8-0-x64-nts-linux /* /
COPY --from=php-7-4-x64-zts-linux /* /
COPY --from=php-7-4-x64-nts-linux /* /
27 changes: 27 additions & 0 deletions include/Dockerfile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
$top = "";
$bottom = "FROM scratch\n";
foreach([[8, 1, "bullseye", "srcml_1.0.0-1_ubuntu20.04.deb"], [8, 0, "buster", "srcml_1.0.0-1_ubuntu19.04.deb"], [7, 4, "buster", "srcml_1.0.0-1_ubuntu19.04.deb"]] as [$major, $minor, $distro, $srcmlDeb])
foreach(["x64"] as $arch)
foreach([["zts", "-zts"], ["nts", ""]] as [$threadSafety, $ts])
foreach(["linux"] as $os) {
$top .= <<<DOCKERFILE
FROM php:$major.$minor.0$ts-$distro AS php-$major-$minor-$arch-$threadSafety-$os-build
RUN apt update
RUN apt install libffi-dev
RUN docker-php-ext-install ffi
RUN curl http://131.123.42.38/lmcrs/v1.0.0/$srcmlDeb > srcml.deb
RUN apt install -y ./srcml.deb
COPY process.php .
COPY symbols.txt .
RUN php process.php $os
FROM scratch AS php-$major-$minor-$arch-$threadSafety-$os
COPY --from=php-$major-$minor-$arch-$threadSafety-$os-build /engine-$major-$minor-$arch-$threadSafety-$os.h /
COPY --from=php-$major-$minor-$arch-$threadSafety-$os-build /constants-$major-$minor-$arch-$threadSafety-$os.php /


DOCKERFILE;
$bottom .= "COPY --from=php-$major-$minor-$arch-$threadSafety-$os /* /\n";
}

echo "$top$bottom";
25 changes: 25 additions & 0 deletions include/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
To regenerate the dockerfile, run `php Dockerfile.php > Dockerfile`
To regenerate headers, run: `docker buildx build . -o .`
To generate headers without checking (useful for getting a copy of the header file to identify any errors), comment out the last line of process.php

Symbols syntax:
- `x`: export symbol x
- `#x`: export definition x
- `//...`: Comment

Modifiers (after a symbol):
- `zts` / `nts`: Only import symbol on thread-safe/non-thread-safe
- `<x.y` / `>x.y` / `<=x.y` / `>=x.y` / `=x.y` / `!=x.y`: Only import symbol on a given PHP version

To add a new symbol:
- Check what PHP versions it's defined in and if it's in an `#ifdef` (specifically `ZTS`) and add modifiers as appropriate
- Add to bottom of symbols.txt *unless* required by another symbol (in which case list it above)
- Regenerate headers and ensure all builds pass
- Commit updated headers

To add a new PHP version:
- Add to Dockerfile.php
- Regenerate dockerfile
- Regenerate headers
- Add modifier for any removed symbols to exclude them
- Add modifier for any newly required symbols (ex. members of common classes)
Loading