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

Build wasm libraries separately from PHP #838

Merged
merged 14 commits into from
Dec 6, 2023
Merged

Build wasm libraries separately from PHP #838

merged 14 commits into from
Dec 6, 2023

Conversation

adamziel
Copy link
Collaborator

@adamziel adamziel commented Dec 3, 2023

Rationale for this change

Separates the build pipeline of the libraries required by PHP from the build pipeline for PHP itself.

The goal is to accelerate the PHP builds. Right now, rebuilding PHP may involve rebuilding all the related libraries which takes forever and makes iterating on PHP challenging.

With this PR, PHP builds are much faster and perhaps could even be moved to GitHub actions.

Building PHP in GitHub CI

My initial attempt to recompile PHP via GitHub actions failed because the task timed out after 5 hours of rebuilding PHP dependencies. I don't think GitHub actually used Docker cache between builds, but even if it did then building the libraries took extremely long time.

With this PR, npm run recompile:php:web:light:8.0 takes 4 – 5 minutes! This makes GitHub actions a much more viable build environment.

CleanShot 2023-12-03 at 21 30 33@2x

Implementation details

This PR ships a Makefile with a task for each library. The following libraries are covered by the Makefile and shipped with this PR as pre-built binaries:

  • bison2.7
  • libedit
  • libiconv
  • libncurses
  • libopenssl
  • libpng16
  • libsqlite3
  • libxm12
  • libz
  • libzip

To remove the pre-built libraries on your computer, run:

cd packages/php-wasm/compile/
make clean

To rebuild the libraries on your computer, run:

cd packages/php-wasm/compile/
make all

Follow-up work

  • Create a GitHub task to regenerate outdated PHP builds (e.g. when 8.0.9 is shipped, but 8.0.11 is available)
  • Explore moving the pre-built PHP .wasm from tracked git files into GitHub releases or any other GitHub facility that enables shipping files. This will likely require adding some kind of npm run update-php local task that will automatically run when building wasm-wordpress-net and after running npm install.

Testing instructions

  • Confirm the CI tests passed
  • Run the following commands to confirm the build procedure works for all the libraries covered by Makefile:
cd packages/php-wasm/compile/
make clean
make all
  • Rebuild all the PHP versions locally
    • recompile:php:web
    • recompile:php:node
  • Run npm run dev and confirm the local website still works
  • Run npm run test and confirm the unit tests still pass
  • Run npm run e2e and confirm the E2E tests still pass

@adamziel adamziel marked this pull request as ready for review December 3, 2023 20:40
@adamziel adamziel requested a review from a team as a code owner December 3, 2023 20:40
@adamziel adamziel changed the title Ship pre-built PHP dependencies. Build libraries separately from PHP. Build wasm libraries separately from PHP Dec 3, 2023
@adamziel adamziel self-assigned this Dec 4, 2023
# ↑ ↑
# ┌──────────┴─────────────┐ ┌──────────┴─────────────┐
# │ skip those flags when │ │ add these flags when │
# │ calling emcc │ │ calling emcc │
Copy link
Contributor

Choose a reason for hiding this comment

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

@adamziel Nitpick: This ascii art is broken

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh! How is it broken? It seems in tact on my screen:

CleanShot 2023-12-06 at 09 38 06@2x

git apply --no-index /root/bison27.patch && \
./configure --prefix=/usr/local/bison --with-libiconv-prefix=/usr/local/libiconv/ && \
make && \
make install
Copy link
Contributor

Choose a reason for hiding this comment

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

@adamziel nitpick: Files should end in newlines

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! Just updated all Dockerfiles

@seanmorris
Copy link
Contributor

@adamziel This looks awesome! But I notice that there are a lot of contributed files from other software packages being contributed to the repository. Do you think it would be better if we git/CURL them in during the build process?

Let me know your thoughts.

@adamziel
Copy link
Collaborator Author

adamziel commented Dec 6, 2023

This looks awesome! But I notice that there are a lot of contributed files from other software packages being contributed to the repository. Do you think it would be better if we git/CURL them in during the build process?

This PR ships the pre-built WebAssembly output. The source code is downloaded via curl/wget. Some of the pre-built output maps 1:1 to the source code, but I'm hesitant of manually recreating parts of the build step to avoid shipping those files. I'd rather move all the pre-built files into something like GitHub releases later on – see #58.

@adamziel adamziel merged commit 50328e8 into trunk Dec 6, 2023
5 checks passed
@adamziel adamziel deleted the php-makefile branch December 6, 2023 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants