Skip to content

Improvements to Emscripten build script #145219

Description

@hoodmane

@freakboy3742's desired improvements to the Emscripten build script:

  1. clean should be a little more selective. It currently destroys all of cross-build; it should only be purging the parts of cross-build that are emscripten specific (so that Emscripten, iOS and Android builds can co-exist). This is admittedly a "me" problem... but it's a problem I have :-)
  2. The cross-build directory name should be configurable. Again, this is somewhat a "me" problem... but I currently need to have cross builds for 3.10-3.15, and they can't currently co-exist.
  3. We shouldn't be building dependencies (libFFI and mpdec) on every build. A similar caching strategy to the one described for EMSDK should be possible - look to this directory; if the cache has a build for the right emscripten version, use it rather than rebuilding.
  4. Add install-emscripten subcommand

Linked PRs

Activity

  1. hoodmane commented on Feb 25, 2026

    @hoodmane
    ContributorAuthor

    @freakboy3742 I can make these changes but I want to wait until #145177 is merged to avoid conflicts.

  2. hoodmane commented on Feb 25, 2026

    @hoodmane
    ContributorAuthor
  3. added 3 commits that reference this issue on Mar 6, 2026
  4. hoodmane commented on Mar 6, 2026

    @hoodmane
    ContributorAuthor

    @freakboy3742 for caching libraries, I'm thinking maybe we do the following:

    1. Move emsdk from <emsdk-cache>/<version>/emsdk_env.sh to <emsdk-cache>/<version>/emsdk/emsdk_env.sh
    2. If --emsdk-cache is provided, put the prefix at <emsdk-cache>/<version>/prefix.

    Sound reasonable to you?

  5. freakboy3742 commented on Mar 7, 2026

    @freakboy3742
    Contributor

    Yes, I think that makes sense.

    An additional suggestion: For consistency with other builds, we should simplify the <cross-build>/wasm32-emscripten/python directory to just be the Python build (i.e., build Python in <cross-build>/wasm32-emscripten), use <emsdk-cache>/<version>/mpdecimal-x.y.z as the location for a build for mpdecimal if a cache is provided, or <cross-build>/dependencies/wasm32-emscripten/mpdecimal-x.y.z if it isn't, and shortcut dependency builds if that directory already exists.

    That would allow build artefacts for mpdecimal and libffi to persist between builds, increases consistency between Android, iOS and Emscripten build structures, and in particular makes the cleaning strategy consistent.

    (I guess strictly we should be looking for one of the the installed products in <prefix> rather than the build directory as the shortcut trigger; I'm not sure if it will make that much difference in practice)

  6. added a commit that references this issue on Mar 9, 2026
  7. added a commit that references this issue on Mar 9, 2026
  8. added a commit that references this issue on Mar 9, 2026
  9. added a commit that references this issue on Mar 9, 2026
  10. hoodmane commented on Mar 9, 2026

    @hoodmane
    ContributorAuthor

    For consistency with other builds, we should simplify the <cross-build>/wasm32-emscripten/python directory to just be the Python build
    <cross-build>/dependencies/wasm32-emscripten/mpdecimal-x.y.z

    I'm confused about this: it looks to me like both android and iOS have their prefix under <cross-build>/<host>/prefix and don't make a dependencies directory at all? I do see that they build Python directly at <cross-build>/<host> but that seems weird given that prefix is underneath it and has nothing directly to do with the Python build.

    in particular makes the cleaning strategy consistent.

    Seems to me that cleaning is simplest if everything about wasm32-emscripten stays under cross-build/wasm32-emscripten?

  11. hoodmane commented on Mar 9, 2026

    @hoodmane
    ContributorAuthor

    Anyways, I'm okay with whatever file structure but I don't understand what you intend here. If you want you can directly commit whatever changes you want to the structure to #145664 or do it as a followup PR?

  12. freakboy3742 commented on Mar 9, 2026

    @freakboy3742
    Contributor

    For consistency with other builds, we should simplify the <cross-build>/wasm32-emscripten/python directory to just be the Python build
    <cross-build>/dependencies/wasm32-emscripten/mpdecimal-x.y.z

    I'm confused about this: it looks to me like both android and iOS have their prefix under <cross-build>/<host>/prefix and don't make a dependencies directory at all? I do see that they build Python directly at <cross-build>/<host> but that seems weird given that prefix is underneath it and has nothing directly to do with the Python build.

    The difference is that Android and iOS don't have to build their dependencies as part of the CPython build. The build of mpdecimal-1.0.0 can be shared across all builds of all versions of CPython; there's no analog of the EMSDK version dependency. As a result, they both use downloads; the prefix is just the unpacked version of the downloads; and the downloads can be cached outside the build tree.

    What I'm trying to optimize here is needing to do a full rebuilt of mpdecimal, libffi et al on every rebuild of wasm32-emscripten.

    in particular makes the cleaning strategy consistent.

    Seems to me that cleaning is simplest if everything about wasm32-emscripten stays under cross-build/wasm32-emscripten?

    As long as what we clean up doesn't mean re-building the same version of mpdecimal with the same verision of EMSDK.

    I guess we could do the build for mpdecimal somewhere into the emsdk directory, install it into a standalone prefix, then zip up that artefact and cache it in the downloads folder; then, for the actual build, you look for the download, unpack it into the "live" prefix, and proceed as normal.

  13. hoodmane commented on Mar 10, 2026

    @hoodmane
    ContributorAuthor

    What do you think of the approach in #145664 then?

  14. freakboy3742 commented on Mar 10, 2026

    @freakboy3742
    Contributor

    Just reviewed the PR - that approach looks good to me. I've flagged one more cleanup that I'd like to make, but it requires a parallel build in the buildbot, so I suspect that will be easier to make when we get to the "move to Platforms" PR.

  15. added a commit that references this issue on Mar 11, 2026
  16. added a commit that references this issue on Mar 11, 2026
  17. added a commit that references this issue on Mar 11, 2026
  18. added 2 commits that reference this issue on Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-emscriptenbuildThe build process and cross-buildtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions