Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ functions:
| Tideways | `${bref-extra:tideways-php-81}` |
| Tidy | `${bref-extra:tidy-php-81}` |
| UUID | `${bref-extra:uuid-php-81}` |
| V8Js | `${bref-extra:v8js-php-81}` |
| Xdebug | `${bref-extra:xdebug-php-81}` |
| Xlswriter | `${bref-extra:xlswriter-php-81}` |
| xmlrpc | `${bref-extra:xmlrpc-php-81}` |
Expand Down
66 changes: 66 additions & 0 deletions layers/v8js/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
ARG PHP_VERSION
ARG BREF_VERSION
FROM bref/build-php-$PHP_VERSION:$BREF_VERSION AS ext

ENV V8JS_BUILD_DIR=${BUILD_DIR}/v8js
ENV V8_VERSION=12.0.267.36
ENV V8JS_COMMIT=8a39efa3cf3b275e402ddf3c4f6b611a5f69a499
ENV V8_DIR=${INSTALL_DIR}/v8

RUN mkdir -p ${V8JS_BUILD_DIR}
WORKDIR ${V8JS_BUILD_DIR}

RUN LD_LIBRARY_PATH= dnf -y install \
gcc \
gcc-c++ \
git \
glib2-devel \
make \
ninja-build \
patchelf \
pkgconf-pkg-config \
python3 \
which

RUN git clone --depth 1 https://chromium.googlesource.com/chromium/tools/depot_tools.git ${V8JS_BUILD_DIR}/depot_tools
ENV PATH="${V8JS_BUILD_DIR}/depot_tools:${PATH}"
ENV DEPOT_TOOLS_UPDATE=0

RUN fetch v8
WORKDIR ${V8JS_BUILD_DIR}/v8
RUN git checkout ${V8_VERSION} && gclient sync -D
RUN tools/dev/v8gen.py -vv x64.release -- is_component_build=true use_custom_libcxx=false
RUN ninja -C out.gn/x64.release/

RUN mkdir -p ${V8_DIR}/lib ${V8_DIR}/include && \
cp out.gn/x64.release/lib*.so out.gn/x64.release/*_blob.bin out.gn/x64.release/icudtl.dat ${V8_DIR}/lib/ && \
cp -R include/* ${V8_DIR}/include/ && \
for f in ${V8_DIR}/lib/*.so; do patchelf --set-rpath '$ORIGIN' "$f"; done

WORKDIR ${V8JS_BUILD_DIR}
RUN curl -Ls https://github.com/phpv8/v8js/archive/${V8JS_COMMIT}.tar.gz | tar xz
WORKDIR ${V8JS_BUILD_DIR}/v8js-${V8JS_COMMIT}
RUN phpize && \
./configure \
--with-v8js=${V8_DIR} \
LDFLAGS="-lstdc++ -Wl,-rpath,${V8_DIR}/lib" \
CPPFLAGS="-DV8_COMPRESS_POINTERS -DV8_ENABLE_SANDBOX" && \
make -j "$(nproc)" && \
make install

RUN cp "$(php-config --extension-dir)"/v8js.so /tmp/v8js.so
RUN strip --strip-debug /tmp/v8js.so
RUN echo 'extension=v8js.so' > /tmp/ext.ini

RUN php /bref/lib-copy/copy-dependencies.php /tmp/v8js.so /tmp/extension-libs
RUN cp ${V8_DIR}/lib/libv8*.so ${V8_DIR}/lib/icudtl.dat ${V8_DIR}/lib/*_blob.bin /tmp/extension-libs/
RUN cp -L /lib64/libstdc++.so.6 /lib64/libgcc_s.so.1 /tmp/extension-libs/
RUN patchelf --set-rpath '$ORIGIN/../../lib' /tmp/v8js.so
RUN for f in /tmp/extension-libs/*.so; do patchelf --set-rpath '$ORIGIN' "$f"; done

FROM scratch

COPY --from=ext /tmp/v8js.so /opt/bref/extensions/v8js.so
COPY --from=ext /tmp/ext.ini /opt/bref/etc/php/conf.d/ext-v8js.ini
COPY --from=ext /opt/v8 /opt/v8
COPY --from=ext /tmp/extension-libs /opt/lib
18 changes: 18 additions & 0 deletions layers/v8js/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# V8Js

PHP bindings for the [V8 JavaScript engine](https://v8.dev/), via [phpv8/v8js](https://github.com/phpv8/v8js).

## Build notes

This layer compiles V8 from source during the Docker build. Expect **long CI runtimes** (often 1–3 hours per PHP version) and a **large layer** (V8 shared libraries and ICU data).

Pinned versions:

- V8: `12.0.267.36`
- v8js: commit `8a39efa3cf3b275e402ddf3c4f6b611a5f69a499`

The extension is built with `V8_COMPRESS_POINTERS` and `V8_ENABLE_SANDBOX` to match the V8 build configuration.

## Lambda limits

Check the unzipped layer size against the [Lambda deployment package limit](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html) (250 MB unzipped for direct uploads). This layer is significantly larger than typical PECL extensions.
7 changes: 7 additions & 0 deletions layers/v8js/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"php": [
"82",
"83",
"84"
]
}
20 changes: 20 additions & 0 deletions layers/v8js/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

if (!extension_loaded('v8js')) {
echo 'FAIL: v8js extension is not loaded.'.PHP_EOL;
exit(1);
}

if (!class_exists(V8Js::class)) {
echo 'FAIL: V8Js class does not exist.'.PHP_EOL;
exit(1);
}

$v8js = new V8Js();
$result = $v8js->executeString('1 + 1');
if ($result !== 2) {
echo sprintf('FAIL: Expected 2, got %s.', var_export($result, true)).PHP_EOL;
exit(1);
}

exit(0);
Loading