Skip to content

CI, BLD: Use cibuildwheel to build WASM NumPy wheels#26570

Merged
rgommers merged 1 commit intonumpy:mainfrom
agriyakhetarpal:cibuildwheel-pyodide
Aug 15, 2024
Merged

CI, BLD: Use cibuildwheel to build WASM NumPy wheels#26570
rgommers merged 1 commit intonumpy:mainfrom
agriyakhetarpal:cibuildwheel-pyodide

Conversation

@agriyakhetarpal
Copy link
Contributor

@agriyakhetarpal agriyakhetarpal commented May 29, 2024

Description

This PR intends to invoke pypa/cibuildwheel#1456 for building and testing the Pyodide builds for NumPy. cc @rgommers who recommended testing out on a fork of NumPy first, which I did, and I got it to pass.

Update: cibuildwheel version 2.19.1 is out with the required support for Pyodide.

Additional context

  1. Pyodide builds in the cibuildwheel documentation: https://cibuildwheel.pypa.io/en/latest/setup/#pyodide-webassembly-builds-experimental

@rgommers
Copy link
Member

Do we want an extra CI job for this, or only change the existing one?

@agriyakhetarpal
Copy link
Contributor Author

Do we want an extra CI job for this, or only change the existing one?

Ah, I should have mentioned it in the PR description. I plan to change the existing one to use cibuildwheel after we have a stable release for it – in the meantime, I plan to try this for a few other repositories.

P.S. This could have been incorporated into wheels.yml as well to reduce the number of workflows uploading artifacts or accessing secrets, but considering the instability of the platform, running only on [wheel build] commit messages on PRs and not every time is probably not the best approach.

@rgommers
Copy link
Member

Sounds good to me, thanks. And yes, I'd prefer to keep it separate from wheels.yml, at least for now.

# To enable this workflow on a fork, comment out:
if: github.repository == 'numpy/numpy'
env:
PYODIDE_VERSION: 0.26.0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel that it would be better not to pin the Pyodide version for this workflow. Two reasons:

  1. The pyodide-build version is coupled with the Pyodide version, which in-turn is set by cibuildwheel. In my earlier commits, I used pip to install pyodide-build, which can fall out of date
  2. NumPy is one of the fundamental packages and is extensively built and tested with Pyodide when the Emscripten toolchain version is bumped (i.e., when the ABI breaks). It's quite unlikely that building it would be broken for a released version of Pyodide, and owing to the experimental nature of the build system and this feature in general, cibuildwheel will not plan to provide WebAssembly builds for a tip-of-tree or unlisted Pyodide build – which would require its own CDN or distribution channel, anyway.

Do you have any thoughts about this, @rgommers?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think it's fine to remove this and always build/test with the latest releases. We have lots of unpinned test setups like this, and by now our Pyodide support has stabilized.

Comment on lines +61 to +56
- name: Upload wheel artifact(s)
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
Copy link
Contributor Author

@agriyakhetarpal agriyakhetarpal Jun 10, 2024

Choose a reason for hiding this comment

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

I see that other workflows upload artifacts on failure() events, while some upload them without conditions. I have added this for the sake of completeness/convenience, but it's not needed if we don't plan to share it across jobs, at least for now (the documentation builds can be adjusted to need them later). Happy to keep this or remove this based on further directions.

@agriyakhetarpal agriyakhetarpal changed the title [WIP]: CI, BLD: Use cibuildwheel to build WASM NumPy wheels CI, BLD: Use cibuildwheel to build WASM NumPy wheels Jun 10, 2024
@agriyakhetarpal agriyakhetarpal marked this pull request as ready for review June 10, 2024 19:26

[tool.cibuildwheel.pyodide]
config-settings = "build-dir=build setup-args=--cross-file=$PWD/tools/ci/emscripten/emscripten.meson.cross setup-args=-Dblas=none setup-args=-Dlapack=none"

Copy link
Member

Choose a reason for hiding this comment

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

This will use lapack-lite. Is there a better BLAS implementation available?

Copy link
Member

Choose a reason for hiding this comment

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

It's supposed to use lapack-lite here (for now at least), that's what is happening in Pyodide in-tree as well. It's possible that will switch to openblas in the future, but it doesn't really matter here (performance isn't a high prio for things like interactive docs).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to make it try to use OpenBLAS or any alternative BLAS vendor in the future (not for now, though – indeed not a priority)

@mattip
Copy link
Member

mattip commented Jul 3, 2024

@rgommers is this ready for merging?

@agriyakhetarpal
Copy link
Contributor Author

I just noticed that there were conflicts here. I've merged the latest changes from main and fixed them, so this PR remains ready to merge.

This commit performs the following changes:

1. cibuildwheel version 2.20.0 is added for building
and testing the Pyodide wheels for NumPy in its workflow
for out-of-tree builds.
2. The workflow sets the CIBW_PLATFORM environment
variable in order to point to Pyodide as the build target.
3. The version of Pyodide used is bumped to the recent
version 0.26.1.
4. The TOML tables are updated to use cibuildwheel's
provided overrides for the test command, the wheels'
repair command, and the setup arguments needed at the
time of building the wheel.

[skip azp] [skip circle] [skip cirrus]
@rgommers rgommers force-pushed the cibuildwheel-pyodide branch from 51a90fc to ad58c55 Compare August 15, 2024 07:55
Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

I reviewed this, rebased it and made one more tweak (updating to cibuildwheel 2.20.0), and everything LGTM. Time to merge this. Thanks @agriyakhetarpal, and thanks for the review @mattip.

# To enable this workflow on a fork, comment out:
if: github.repository == 'numpy/numpy'
env:
PYODIDE_VERSION: 0.26.0
Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think it's fine to remove this and always build/test with the latest releases. We have lots of unpinned test setups like this, and by now our Pyodide support has stabilized.

config-settings = "setup-args=--vsenv setup-args=-Dallow-noblas=true build-dir=build"
repair-wheel-command = ""

[[tool.cibuildwheel.overrides]]
Copy link
Member

Choose a reason for hiding this comment

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

It indeed seems correct to have multiple sections with this exact name (see https://cibuildwheel.pypa.io/en/stable/options/#overrides). That design seems a bit questionable to me, but if it works it works.

@rgommers rgommers merged commit 89b6820 into numpy:main Aug 15, 2024
@rgommers rgommers added this to the 2.2.0 release milestone Aug 15, 2024
@agriyakhetarpal agriyakhetarpal deleted the cibuildwheel-pyodide branch August 15, 2024 20:44
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.

3 participants