-
-
Notifications
You must be signed in to change notification settings - Fork 133
Add V8Js extension layer #663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mchristie
wants to merge
1
commit into
brefphp:master
Choose a base branch
from
mchristie:add-v8js-layer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+112
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "php": [ | ||
| "82", | ||
| "83", | ||
| "84" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 to 3 hours build per PHP version will be problematic on our CI here 😥
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(actually looking at the build it took 4h 😿)