Skip to content
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

Unable to do a custom Builds #70

Open
kambo-1st opened this issue Nov 4, 2024 · 6 comments
Open

Unable to do a custom Builds #70

kambo-1st opened this issue Nov 4, 2024 · 6 comments

Comments

@kambo-1st
Copy link

kambo-1st commented Nov 4, 2024

What I am trying to achieve:
I want to bundle an existing PHP CLI application with a multiple files and run it with php-wasm by building my own php-wasm with included files through the configuration in .php-wasm-rc.

Platform:

  • OS: Linux Ubuntu 22.04 LTS
  • Node Version: v23.1.0

Steps to Reproduce:

  1. Followed the instructions at: https://github.com/seanmorris/php-wasm/tree/master?tab=readme-ov-file#%EF%B8%8F-custom-builds
  2. Run: npm install -g php-wasm-builder
  3. Tried to run:
    • php-wasm-builder image (Command not found)
    • php-wasm-build image (This worked)
  4. Tried to run: php-wasm-build build

Result:

PHP_DIST_DIR=/home/xxx/Public/temp docker-compose --progress auto -p phpwasm run  --rm -e PKG_CONFIG_PATH=/src/lib/lib/pkgconfig -e PRELOAD_ASSETS='lib/share/icu/72.1/icudt72l.dat' -e INITIAL_MEMORY=64MB -e ENVIRONMENT=web -e PHP_BRANCH=php-8.2.11 -e EMCC_CORES=`nproc` emscripten-builder cp -rf /src/third_party/libicu-72-1 /src/third_party/libicu_alt
PHP_DIST_DIR=/home/xxx/Public/temp docker-compose --progress auto -p phpwasm run  --rm -e PKG_CONFIG_PATH=/src/lib/lib/pkgconfig -e PRELOAD_ASSETS='lib/share/icu/72.1/icudt72l.dat' -e INITIAL_MEMORY=64MB -e ENVIRONMENT=web -e PHP_BRANCH=php-8.2.11 -e EMCC_CORES=`nproc` emscripten-builder mv /src/third_party/libicu_alt /src/third_party/libicu-72-1
PHP_DIST_DIR=/home/xxx/Public/temp docker-compose --progress auto -p phpwasm run  --rm -e PKG_CONFIG_PATH=/src/lib/lib/pkgconfig -e PRELOAD_ASSETS='lib/share/icu/72.1/icudt72l.dat' -e INITIAL_MEMORY=64MB -e ENVIRONMENT=web -e PHP_BRANCH=php-8.2.11 -e EMCC_CORES=`nproc` -w /src/third_party/libicu-72-1/icu4c/source emscripten-builder git apply --no-index ../../../../patch/libicu.patch
error: can't open patch 'icu4c/source/../../../../patch/libicu.patch': No such file or directory
make: *** [/home/xxx/.nvm/versions/node/v23.1.0/lib/node_modules/php-wasm-builder/node_modules/php-wasm-libicu/static.mak:56: third_party/libicu-72-1/.gitignore] Error 128

What I tried next:

  • Installed the alpha version: npm install -g php-wasm-builder@alpha
  • Run: php-wasm-builder image (Works)
  • Run: php-wasm-builder build

Result:

npm warn deprecated [email protected]: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
ReferenceError: [BABEL] source/PhpBase.js: Unknown option: /home/xxx/.nvm/versions/node/v23.1.0/lib/node_modules/php-wasm-builder/.babelrc.presets
    at Logger.error (/home/xxx/.npm/_npx/02ef052036b6e199/node_modules/babel-core/lib/transformation/file/logger.js:58:11)
    at OptionManager.mergeOptions (/home/xxx/.npm/_npx/02ef052036b6e199/node_modules/babel-core/lib/transformation/file/options/option-manager.js:126:29)
    at OptionManager.addConfig (/home/xxx/.npm/_npx/02ef052036b6e199/node_modules/babel-core/lib/transformation/file/options/option-manager.js:107:10)
    at OptionManager.findConfigs (/home/xxx/.npm/_npx/02ef052036b6e199/node_modules/babel-core/lib/transformation/file/options/option-manager.js:168:35)
    at OptionManager.init (/home/xxx/.npm/_npx/02ef052036b6e199/node_modules/babel-core/lib/transformation/file/options/option-manager.js:229:12)
    at File.initOptions (/home/xxx/.npm/_npx/02ef052036b6e199/node_modules/babel-core/lib/transformation/file/index.js:147:75)
    at new File (/home/xxx/.npm/_npx/02ef052036b6e199/node_modules/babel-core/lib/transformation/file/index.js:137:22)
    at Pipeline.transform (/home/xxx/.npm/_npx/02ef052036b6e199/node_modules/babel-core/lib/transformation/pipeline.js:164:16)
    at exports.transform (/home/xxx/.npm/_npx/02ef052036b6e199/node_modules/babel/lib/babel/util.js:40:22)
    at exports.compile (/home/xxx/.npm/_npx/02ef052036b6e199/node_modules/babel/lib/babel/util.js:49:20)
make: *** [Makefile:648: /home/xxx/Public/temp/PhpBase.js] Error 1

Expected behavior:
Successful build of a PHP application that can run with php-wasm.

Actual behavior:

  • Build fails due to missing patch file in libicu step.
  • Alpha version build fails with Babel-related errors.

Extra question:
I wonder if building PHP is really necessary. Would it be possible to just bundle a couple of PHP files without this extra step?

@seanmorris
Copy link
Owner

@kambo-1st Usually building a custom PHP version isn't necessary, unless you need to change the list of statically compiled extensions. There are a few different ways you can bring files in, however. What is your use-case?

@kambo-1st
Copy link
Author

@seanmorris Thanks for asking! My goal is to bundle a PHP CLI application (involving multiple files and using composer for autoloading) to run it within a PHP-WASM environment. I'm mainly aiming to get the CLI application running in the browser without requiring server-side PHP.

If building PHP isn’t necessary, I'd love to know more about the alternative ways you mentioned to bring files in, especially if it means avoiding the build process.

@seanmorris
Copy link
Owner

seanmorris commented Nov 10, 2024

@kambo-1st You can load files into the FS via constructor params. You just need to use an array of objects with the following form:

const files = [
    {
        name: 'icudt72l.dat',
        parent: '/preload/',
        url: 'https://unpkg.com/php-wasm-intl/icudt72l.dat'
    }
];

https://php-wasm.seanmorr.is/filesystem/loading-files.html

Those constructor params are also accessible from static HTML:

https://codepen.io/SeanMorris227/pen/KKLeePJ?editors=1000

@kambo-1st
Copy link
Author

@seanmorris Thanks for the heads-up! I know about loading files via constructor params. Honestly, though, I’m not sure if this approach would be ideal for a PHP application that has over 10,325 files (some of them are composer depedencies). Do you think this is the only viable approach in this case?

@seanmorris
Copy link
Owner

@kambo-1st Ah, yea its somewhat annoying that we need to do custom builds to create emscripten preloaded FS, so I try to avoid that. The demo-web application actually uses the php-zip extension and a small script to set up the drupal, laravel, cakephp & lamias demos.

I could probably add some functionality to download and unzip a file right to the FS as well. Let me know if that sounds useful.

@kambo-1st
Copy link
Author

kambo-1st commented Nov 13, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants