-
Notifications
You must be signed in to change notification settings - Fork 386
[ php-wasm ] Add intl dynamic extension to @php-wasm/node JSPI
#2501
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
[ php-wasm ] Add intl dynamic extension to @php-wasm/node JSPI
#2501
Conversation
|
Running the following script crashes : const response = await php.runStream({
code: `<?php
$data = array(
'ET' => 'Éthiopie',
'ES' => 'Espagne',
'AF' => 'Afghanistan',
'AX' => 'Åland Islands',
);
$collator = new Collator( 'en_US' );
$collator->asort( $data, Collator::SORT_STRING );`
});With stack trace : I have no idea why but that could be related to the fact that the main module PHP.wasm and side module Intl.so need to coordinate their JSPI-wrapped functions. The file I/O operations need to be consistently wrapped across both modules. |
|
I finally found out why I had the Removing that line made the extension compile. This means the file descriptor will remain open until process teardown. If this is not what we expected we can look for an improvement later. Intl dynamic extension for every PHP version Node JSPI are now available next to Xdebug! 🎉 And all checks passed! |
packages/php-wasm/node/src/lib/extensions/intl/get-intl-extension-module.ts
Outdated
Show resolved
Hide resolved
| /** | ||
| * intl support | ||
| */ | ||
| describe('intl extension support', { skip: options.withXdebug }, () => { |
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.
We should keep testing the asyncify version
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.
done.
|
Almost there @mho22, I've left a few logistic notes to make sure the rest of the project continues to work once this PR is merged. |
adamziel
left a comment
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.
See the previous comment
|
@adamziel I reverted the code needed for PHP.wasm Node Asyncify and PHP.wasm Web, made some changes and all tests passed. A new pull request is already on the works for Intl dynamic extension on PHP.wasm Node Asyncify. |
|
Lovely! So this PR now loads ICU as a dynamic extension in Node + JSPI and as a static extension otherwise, correct? It looks pretty good now! Let's just hold on with merging this one until we merge #2558 and release new packages with just that change. |
|
@adamziel Yes! In the current state of this pull request, only PHP.wasm Node JSPI has the I already drafted the "intl dynamic extension for PHP.wasm Node ASYNCIFY" pull request here. |
|
Yay, this is amazing! Thank you @mho22 ❤️ |
…2501 (#2557) ## Motivation for the change, related issues This is a pull request to dynamically load Intl in @php-wasm Node ASYNCIFY. ## Related issues and pull requests Issues - #2466 - #2299 - #1295 Pull requests - #2501 - #2247 - #2187 ## Implementation details ### Intl Dynamic Extension Compilation ASYNCIFY - Improvement to the specific Intl dynamic extension Dockerfile file based on PHP versions and ASYNCIFY - Modification of the dedicated `project.json` file which will store the list of compilation commands related to each dynamic extension for asyncify. - Compilation of every version of Intl Dynamic Extension For Asyncify ### PHP.wasm Node WithIntl option - Add Intl extension file import for Asyncify - Test the correct use of the extension in the `php-dynamic-loading.spec.ts` file. - Keep the Intl static extension compilation process for PHP.wasm Web. ## Testing Instructions (or ideally a Blueprint) `test.js` ```javascript import { PHP } from '@php-wasm/universal'; import { loadNodeRuntime } from '@php-wasm/node'; const script = `<?php $formatter = numfmt_create('en-US', NumberFormatter::CURRENCY); echo numfmt_format($formatter, 100.00); $formatter = numfmt_create('fr-FR', NumberFormatter::CURRENCY); echo numfmt_format($formatter, 100.00); ?>`; const php = new PHP( await loadNodeRuntime( '8.3', { withIntl : true } ) ); const result = await php.runStream( { code : script } ); console.log( await result.stdoutText ); ``` ``` > node scripts/example.js //withIntl : true $100.00100,00 € //withIntl : false <br /> <b>Fatal error</b>: Uncaught Error: Call to undefined function numfmt_create() in /internal/eval.php:3 Stack trace: #0 {main} thrown in <b>/internal/eval.php</b> on line <b>3</b><br /> ``` ## Next steps - [x] Experimental PHP Node JSPI 8.3 - [x] PHP.wasm Node JSPI - [x] PHP.wasm Node Asyncify - [ ] PHP.wasm Web - [ ] Remove artifacts in PHP.wasm - [ ] Remove artifacts in Playground - [ ] Move Xdebug in shared directory alongside Intl
## Motivation for the change, related issues This is a pull request to dynamically load Intl in PHP.wasm Web. ## Related issues and pull requests Issues - #2466 - #2299 - #1295 Pull requests - #2557 - #2501 - #2247 - #2187 ## Implementation details - Removal of static Intl options in PHP compilation - Set up of PHP as a `MAIN_MODULE` in node and web - Correction of #2318 by adding`worker` to the [`web`] environment - Improvement of build file for shared libraries - Implementation of Intl dynamic extension lazy loading logic in PHP.wasm web - Creation of a `ignore-lib-imports` Vite plugin - Playwright E2E tests implementation for PHP.wasm web by duplicating existing ones from PHP.wasm Node - Creation of a virtual alias for `wasm-feature-detect` to simulate JSPI mode enabled based on Playwright ENV - CI jobs implementation to test PHP.wasm web in JSPI and Asyncify mode ## Testing Instructions (or ideally a Blueprint) CI 🧪 test-e2e-php-wasm-web-jspi 🧪 test-e2e-php-wasm-web-asyncify ## Next steps - [x] Experimental PHP.wasm Node JSPI 8.3 - [x] PHP.wasm Node JSPI - [x] PHP.wasm Node Asyncify - [x] Experimental PHP.wasm Web JSPI 8.3 - [x] Experimental PHP.wasm Web Asyncify 8.3 - [x] PHP.wasm Web JSPI - [x] PHP.wasm Web Asyncify - [ ] Implement Intl in Blueprints - [ ] Remove remaining Intl artifacts in PHP.wasm - [ ] Remove remaining Intl artifacts in Playground --------- Co-authored-by: Adam Zieliński <adam@adamziel.com>
Motivation for the change, related issues
This is a pull request to dynamically load Intl in @php-wasm Node JSPI.
Roadmap
Related issues and pull requests
Issues
Pull requests
intlextension #2187Implementation details
Intl Dynamic Extension Compilation JSPI
shareddirectory inphp-wasm/compilewhich will store the dynamic extensions build processes and files.build.jsscript with options related to the dynamic extensions.sofile based on PHP versions and JSPIproject.jsonfile which will store the list of compilation commands related to each dynamic extension for JSPIPHP.wasm Node WithIntl option
withIntl[ same logic as Xdebug ]. This loads dynamically the needed version of the dynamic extension. Stores it in the filesystem. Prepare the related php ini file and load the related ICU data file.php-dynamic-loading.spec.tsfile.Testing Instructions (or ideally a Blueprint)
test.jsNext steps