WIP: CI: switch Emscripten job to Meson - #24603

Closed
rgommers wants to merge 1 commit into
numpy:mainfrom
rgommers:ci-emscripten
Closed

WIP: CI: switch Emscripten job to Meson#24603
rgommers wants to merge 1 commit into
numpy:mainfrom
rgommers:ci-emscripten

Conversation

@rgommers

Copy link
Copy Markdown
Member

This is one of the last CI jobs to be converted to Meson. Still a work in progress.

Note that we need to cross-compile here. Using pyodide build fails on not having a cross file. The source() function in pyodide_build/cli/build.py needs a --backend-flags parameter so that we can pass config-settings arguments to the backend. In the meantime, we use python -m build ....

One can also try this locally with:

$ python -m build -wnx -Csetup-args=--cross-file=\$PWD/tools/ci/emscripten.meson.cross -Csetup-args=-Dallow-noblas=true

as long as both pyodide-build and the exact version of Emscripten (currently 3.1.32, can be installed with https://emscripten.org/docs/tools_reference/emsdk.html) are available. The configure stage of the build looks fine, the build itself fails halfway through due to:

include/python3.11/pyport.h:601:2: error: "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."

That issue is due to a static assert in pyconfig.h, also discussed at: pyodide/pyodide#2494 (comment)

See also pyodide/pyodide#2238 and the patches to _numpyconfig.h in https://github.com/pyodide/pyodide/tree/main/packages/numpy.

tl;dr this needs some work, and it seems like cross-compilation is hard because Pyodide doesn't ship its own Python interpreter that we can actually target during a direct cross build.

Cc @hoodmane@rth. I hope I can bother you with this. If I got any of the above wrong or if you've got a suggestion to get past the LONG_BIT error, I'd love to hear it. Also, a couple of questions:

  • If I didn't overlook a way to pass --config-settings flags to the backend in the pyodide build CLI, would you accept a PR to Pyodide to add that? It should match backend-flags in meta.yaml recipes I think.
  • Since scikit-image can be cross-compiled, I had expected to be able to make that work for numpy too. But after reading this comment, that may not be true? Is that still the case, and do you see a road to a regular cross-compile working for NumPy? It's actually not clear to me how the distutils-based build works right now, it doesn't seem to be doing the "playback" thing explained in that comment.

@rgommers
rgommers marked this pull request as draft August 31, 2023 15:13
endian = 'little'

[properties]
longdouble_format = 'IEEE_QUAD_LE'

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This is the only addition compared to the upstream emscripten.meson.cross file in Pyodide - necessary for now.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Most of this file can be removed, only this is needed:

[properties]longdouble_format = 'IEEE_QUAD_LE'

@hoodmane

Copy link
Copy Markdown
Contributor

cc @ryanking13@henryiii

@rgommersrgommers added this to the 2.0.0 release milestone Sep 9, 2023
@rgommersrgommers mentioned this pull request Sep 9, 2023
3 tasks
@rgommers

Copy link
Copy Markdown
MemberAuthor

I decided that it's easier to finish this only after upgrading the build of numpy that Pyodide does in-tree to Meson and 1.26.x first. I've made a start on that, but I need to do some more digging. There was also a pip bug that made that a little more difficult. And pyodide/pyodide#4118 is the same LONG_BIT error as I'm seeing in this PR.

Next steps I plan to take (not necessarily in this order):

  • disable this CI job and remove all setup.py files
  • finish unvendoring meson-python from this repo after the next meson-python release
  • upgrade numpy in Pyodide to 1.26.0 + Meson
  • if needed, ensure the out-of-tree Pyodide build can take the same backend-flags as the in-tree build
  • re-enable this CI job on the main branch

@rth

rth commented Sep 11, 2023

Copy link
Copy Markdown
Contributor

Thanks for working on this @rgommers ! I don't have useful suggestions about the errors you are facing but I agree it would probably be easier to do this in the in-tree build first. Also cc @lesteve who worked on the scikit-image meson build.

If I didn't overlook a way to pass --config-settings flags to the backend in the pyodide build CLI, would you accept a PR to Pyodide to add that?

I think overall we could be happy to accept any changes needed to make numpy with meson work. But since pyodide build aims to be a drop-in replacement for python -m build, we need to double check in particular whether this would still be OK with cibuildwheel, or if there is some other recommended way of passing those config settings.

@rgommers

Copy link
Copy Markdown
MemberAuthor

But since pyodide build aims to be a drop-in replacement for python -m build, we need to double check in particular whether this would still be OK with cibuildwheel, or if there is some other recommended way of passing those config settings.

That should be fine for cibuildwheel I think. python -m build -Ckey=value will add key=value to the config_settings dict and then pass that on to the backend. -C/--config-setting is implemented in build, and -C/--config-settings in pip (note the extra s for pip in the long form). I am missing that flag from pyodide build --help.

@ryanking13

Copy link
Copy Markdown
Contributor

That should be fine for cibuildwheel I think. python -m build -Ckey=value will add key=value to the config_settings dict and then pass that on to the backend. -C/--config-setting is implemented in build, and -C/--config-settings in pip (note the extra s for pip in the long form). I am missing that flag from pyodide build --help.

Currently pyodide build passes extra command line arguments to config-settings (backend-flags), so pyodide build key1=val1 is equivalent to python -m build -C key1==val1 (it is not documented sorry). But yes, we should change it to -C/--config-settings to match the behavior of pypabuild and pip.

@rgommers

Copy link
Copy Markdown
MemberAuthor

Thank you @ryanking13, that's exactly what I needed.

lagru added a commit to scikit-image/scikit-image that referenced this pull request Dec 11, 2023
hoodmane referenced this pull request Feb 9, 2024
Moving it to Meson is going to take a bit of time, and in the meantime
we have to disable it, because it's the only job that still needs
the `setup.py` based build and we'd like to remove support for building
with `setup.py`.
@hoodmane

Copy link
Copy Markdown
Contributor

@ryanking13 Do you know what the status of this is? It would be good if we could look into this again. I would look into it myself but so far I don't know much about meson...

@rgommers

Copy link
Copy Markdown
MemberAuthor

I've been meaning to get back to this PR. I believe with @ryanking13's changes for improved Meson/meson-python support in Pyodide, this should be unblocked. Timing wise I realistically won't revisit it before the NumPy 2.0 release settles down though (any week now ...).

@ryanking13

Copy link
Copy Markdown
Contributor

Yes, now that we're building numpy with meson in-tree, I don't think it's going to be hard to make it work in out-of-tree too. We've recently added a patch for python-meson >= 0.15 so I think we need to release pyodide-build (0.25.1).

before the NumPy 2.0 release settles down

Maybe emscripten CI should also wait for numpy 2.0 to be released? I've seen Pyodide builds break in many cases when packages do major releases, so it might be better to wait and see if the numpy 2.0 build works in-tree before applying it.

@rgommers

rgommers commented Feb 11, 2024

Copy link
Copy Markdown
MemberAuthor

Maybe emscripten CI should also wait for numpy 2.0 to be released? I've seen Pyodide builds break in many cases when packages do major releases, so it might be better to wait and see if the numpy 2.0 build works in-tree before applying it.

That seems reasonable to me. EDIT: no real reason not to do it now though, it's just not a priority compared to 2.0-critical tasks.

@rgommersrgommers left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I added some comments to this file about what is still relevant. @agriyakhetarpal is going to have a fresh attempt at a new/updated CI job.


- name: Install pyodide-build
run: pip install "pydantic<2" pyodide-build==$PYODIDE_VERSION
run: pip install "pydantic<2" build pyodide-build==$PYODIDE_VERSION

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

build isn't needed anymore, I think pyodide-build will do fine.

cp pyproject.toml.setuppy pyproject.toml
CFLAGS=-g2 LDFLAGS=-g2 pyodide build
# Note that we need to cross-compile here. Using `pyodide build`
# fails on not having a cross file. The `source() function in

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This is no longer true, the cross file is shipped by pyodide now.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Update: still true actually, the cross file won't get applied as long as we have vendored-meson.

We also need the fix from pyodide/pyodide#4502 to actually pick up vendored-meson. With that, an out of tree build should work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am on it – I shall be adding a patch file to port the above PR into vendored-meson, as discussed on Slack.

# tl;dr this needs some work, and it seems like cross-compilation is
# hard because Pyodide doesn't ship its own Python interpreter that
# we can actually target during a direct cross build.
python -m build --wheel -Csetup-args=--cross-file=$PWD/tools/ci/emscripten.meson.cross -Csetup-args=-Dallow-noblas=true

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The -Dallow-noblas=true is no longer needed, the fallback to internal code when BLAS is missing is automatic.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The -Csetup-args=--cross-file=$PWD/tools/ci/emscripten.meson.cross will still be needed I think, only to add the longdouble format, just in slightly different format. From this comment I think it should be:

pyodide build setup-args="--cross-file=$PWD/tools/ci/emscripten.meson.cross"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pyodide bundles emscripten.meson.cross used in in-tree build, so probably you can try that one too.

PYODIDE_MESON_CROSS_FILE=`pyodide config get meson_cross_file`
pyodide build -C "setup-args=\"${PYODIDE_MESON_CROSS_FILE}\""

source .venv-pyodide/bin/activate
cd ..
python numpy/runtests.py -n -vv
pytest --pyargs numpy -m "not slow"

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This change is still needed.

Comment threadmeson_cpu/meson.build
's390x': S390X_FEATURES,
'arm': ARM_FEATURES,
'aarch64': ARM_FEATURES,
'wasm32': {},

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

the changes in this file will still be needed.

endian = 'little'

[properties]
longdouble_format = 'IEEE_QUAD_LE'

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Most of this file can be removed, only this is needed:

[properties]longdouble_format = 'IEEE_QUAD_LE'

agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 23, 2024
Copied with updates and suggestions received from numpy#24603 on 23/02/2024.
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 23, 2024
Copied with updates and suggestions received from numpy#24603 on 23/02/2024.
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
@rgommersrgommers removed this from the 2.1.0 release milestone Feb 27, 2024
@rgommers

Copy link
Copy Markdown
MemberAuthor

This PR is superseded by gh-25894, things seem to work there. So I'll close this PR. Thanks for the help everyone!

@hoodmane

Copy link
Copy Markdown
Contributor

Thanks for working on this @rgommers and @agriyakhetarpal!

rgommers added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 29, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but
without SSE or SIMD instructions.
2. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target
(cross-builds).
3. Enables run for Emscripten/Pyodide wheels by setting the `if:`
condition to `true`.
4. Uses recursive submodules to ensure that vendored-meson is received.
5. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a
separate Emscripten folder to store relevant files)
6. Adds a patch for vendored-meson detection for Pyodide and applies
this Pyodide-meson patch in the Emscripten CI jobs
7. Builds wasm32 wheels without BLAS and LAPACK support (see
numpy#24750 (comment))
8. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions
received from numpy#24603 on 23/02/2024 and authorship is preserved with this
commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
agriyakhetarpal pushed a commit to agriyakhetarpal/scikit-image that referenced this pull request Mar 18, 2024
lagru added a commit to scikit-image/scikit-image that referenced this pull request Jun 10, 2024
* Test emscripten workflow inspired by NumPy
Adds a CI job to build and test scikit-image in a Pyodide virtual
environment through WASM wheels. Following this, it would be
possible to include JupyterLite notebooks in the
documentation in order to run scikit-image's code snippets
which come with docstring-based examples.
Initial inspiration was taken from
numpy/numpy#24603.
Co-authored-by: Lars Grüter <lagru@mailbox.org>
Co-authored-by: Stefan van der Walt <45071+stefanv@users.noreply.github.com>
Sign up for freeto 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.

5 participants

@rgommers@hoodmane@rth@ryanking13@agriyakhetarpal
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

WIP: CI: switch Emscripten job to Meson - #24603

Closed
rgommers wants to merge 1 commit into
numpy:mainfrom
rgommers:ci-emscripten
Closed

WIP: CI: switch Emscripten job to Meson#24603
rgommers wants to merge 1 commit into
numpy:mainfrom
rgommers:ci-emscripten

Conversation

@rgommers

Copy link
Copy Markdown
Member

This is one of the last CI jobs to be converted to Meson. Still a work in progress.

Note that we need to cross-compile here. Using pyodide build fails on not having a cross file. The source() function in pyodide_build/cli/build.py needs a --backend-flags parameter so that we can pass config-settings arguments to the backend. In the meantime, we use python -m build ....

One can also try this locally with:

$ python -m build -wnx -Csetup-args=--cross-file=\$PWD/tools/ci/emscripten.meson.cross -Csetup-args=-Dallow-noblas=true

as long as both pyodide-build and the exact version of Emscripten (currently 3.1.32, can be installed with https://emscripten.org/docs/tools_reference/emsdk.html) are available. The configure stage of the build looks fine, the build itself fails halfway through due to:

include/python3.11/pyport.h:601:2: error: "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."

That issue is due to a static assert in pyconfig.h, also discussed at: pyodide/pyodide#2494 (comment)

See also pyodide/pyodide#2238 and the patches to _numpyconfig.h in https://github.com/pyodide/pyodide/tree/main/packages/numpy.

tl;dr this needs some work, and it seems like cross-compilation is hard because Pyodide doesn't ship its own Python interpreter that we can actually target during a direct cross build.

Cc @hoodmane@rth. I hope I can bother you with this. If I got any of the above wrong or if you've got a suggestion to get past the LONG_BIT error, I'd love to hear it. Also, a couple of questions:

  • If I didn't overlook a way to pass --config-settings flags to the backend in the pyodide build CLI, would you accept a PR to Pyodide to add that? It should match backend-flags in meta.yaml recipes I think.
  • Since scikit-image can be cross-compiled, I had expected to be able to make that work for numpy too. But after reading this comment, that may not be true? Is that still the case, and do you see a road to a regular cross-compile working for NumPy? It's actually not clear to me how the distutils-based build works right now, it doesn't seem to be doing the "playback" thing explained in that comment.

@rgommers
rgommers marked this pull request as draft August 31, 2023 15:13
endian = 'little'

[properties]
longdouble_format = 'IEEE_QUAD_LE'

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This is the only addition compared to the upstream emscripten.meson.cross file in Pyodide - necessary for now.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Most of this file can be removed, only this is needed:

[properties]longdouble_format = 'IEEE_QUAD_LE'

@hoodmane

Copy link
Copy Markdown
Contributor

cc @ryanking13@henryiii

@rgommersrgommers added this to the 2.0.0 release milestone Sep 9, 2023
@rgommersrgommers mentioned this pull request Sep 9, 2023
3 tasks
@rgommers

Copy link
Copy Markdown
MemberAuthor

I decided that it's easier to finish this only after upgrading the build of numpy that Pyodide does in-tree to Meson and 1.26.x first. I've made a start on that, but I need to do some more digging. There was also a pip bug that made that a little more difficult. And pyodide/pyodide#4118 is the same LONG_BIT error as I'm seeing in this PR.

Next steps I plan to take (not necessarily in this order):

  • disable this CI job and remove all setup.py files
  • finish unvendoring meson-python from this repo after the next meson-python release
  • upgrade numpy in Pyodide to 1.26.0 + Meson
  • if needed, ensure the out-of-tree Pyodide build can take the same backend-flags as the in-tree build
  • re-enable this CI job on the main branch

@rth

rth commented Sep 11, 2023

Copy link
Copy Markdown
Contributor

Thanks for working on this @rgommers ! I don't have useful suggestions about the errors you are facing but I agree it would probably be easier to do this in the in-tree build first. Also cc @lesteve who worked on the scikit-image meson build.

If I didn't overlook a way to pass --config-settings flags to the backend in the pyodide build CLI, would you accept a PR to Pyodide to add that?

I think overall we could be happy to accept any changes needed to make numpy with meson work. But since pyodide build aims to be a drop-in replacement for python -m build, we need to double check in particular whether this would still be OK with cibuildwheel, or if there is some other recommended way of passing those config settings.

@rgommers

Copy link
Copy Markdown
MemberAuthor

But since pyodide build aims to be a drop-in replacement for python -m build, we need to double check in particular whether this would still be OK with cibuildwheel, or if there is some other recommended way of passing those config settings.

That should be fine for cibuildwheel I think. python -m build -Ckey=value will add key=value to the config_settings dict and then pass that on to the backend. -C/--config-setting is implemented in build, and -C/--config-settings in pip (note the extra s for pip in the long form). I am missing that flag from pyodide build --help.

@ryanking13

Copy link
Copy Markdown
Contributor

That should be fine for cibuildwheel I think. python -m build -Ckey=value will add key=value to the config_settings dict and then pass that on to the backend. -C/--config-setting is implemented in build, and -C/--config-settings in pip (note the extra s for pip in the long form). I am missing that flag from pyodide build --help.

Currently pyodide build passes extra command line arguments to config-settings (backend-flags), so pyodide build key1=val1 is equivalent to python -m build -C key1==val1 (it is not documented sorry). But yes, we should change it to -C/--config-settings to match the behavior of pypabuild and pip.

@rgommers

Copy link
Copy Markdown
MemberAuthor

Thank you @ryanking13, that's exactly what I needed.

lagru added a commit to scikit-image/scikit-image that referenced this pull request Dec 11, 2023
hoodmane referenced this pull request Feb 9, 2024
Moving it to Meson is going to take a bit of time, and in the meantime
we have to disable it, because it's the only job that still needs
the `setup.py` based build and we'd like to remove support for building
with `setup.py`.
@hoodmane

Copy link
Copy Markdown
Contributor

@ryanking13 Do you know what the status of this is? It would be good if we could look into this again. I would look into it myself but so far I don't know much about meson...

@rgommers

Copy link
Copy Markdown
MemberAuthor

I've been meaning to get back to this PR. I believe with @ryanking13's changes for improved Meson/meson-python support in Pyodide, this should be unblocked. Timing wise I realistically won't revisit it before the NumPy 2.0 release settles down though (any week now ...).

@ryanking13

Copy link
Copy Markdown
Contributor

Yes, now that we're building numpy with meson in-tree, I don't think it's going to be hard to make it work in out-of-tree too. We've recently added a patch for python-meson >= 0.15 so I think we need to release pyodide-build (0.25.1).

before the NumPy 2.0 release settles down

Maybe emscripten CI should also wait for numpy 2.0 to be released? I've seen Pyodide builds break in many cases when packages do major releases, so it might be better to wait and see if the numpy 2.0 build works in-tree before applying it.

@rgommers

rgommers commented Feb 11, 2024

Copy link
Copy Markdown
MemberAuthor

Maybe emscripten CI should also wait for numpy 2.0 to be released? I've seen Pyodide builds break in many cases when packages do major releases, so it might be better to wait and see if the numpy 2.0 build works in-tree before applying it.

That seems reasonable to me. EDIT: no real reason not to do it now though, it's just not a priority compared to 2.0-critical tasks.

@rgommersrgommers left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I added some comments to this file about what is still relevant. @agriyakhetarpal is going to have a fresh attempt at a new/updated CI job.


- name: Install pyodide-build
run: pip install "pydantic<2" pyodide-build==$PYODIDE_VERSION
run: pip install "pydantic<2" build pyodide-build==$PYODIDE_VERSION

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

build isn't needed anymore, I think pyodide-build will do fine.

cp pyproject.toml.setuppy pyproject.toml
CFLAGS=-g2 LDFLAGS=-g2 pyodide build
# Note that we need to cross-compile here. Using `pyodide build`
# fails on not having a cross file. The `source() function in

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This is no longer true, the cross file is shipped by pyodide now.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Update: still true actually, the cross file won't get applied as long as we have vendored-meson.

We also need the fix from pyodide/pyodide#4502 to actually pick up vendored-meson. With that, an out of tree build should work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am on it – I shall be adding a patch file to port the above PR into vendored-meson, as discussed on Slack.

# tl;dr this needs some work, and it seems like cross-compilation is
# hard because Pyodide doesn't ship its own Python interpreter that
# we can actually target during a direct cross build.
python -m build --wheel -Csetup-args=--cross-file=$PWD/tools/ci/emscripten.meson.cross -Csetup-args=-Dallow-noblas=true

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The -Dallow-noblas=true is no longer needed, the fallback to internal code when BLAS is missing is automatic.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The -Csetup-args=--cross-file=$PWD/tools/ci/emscripten.meson.cross will still be needed I think, only to add the longdouble format, just in slightly different format. From this comment I think it should be:

pyodide build setup-args="--cross-file=$PWD/tools/ci/emscripten.meson.cross"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pyodide bundles emscripten.meson.cross used in in-tree build, so probably you can try that one too.

PYODIDE_MESON_CROSS_FILE=`pyodide config get meson_cross_file`
pyodide build -C "setup-args=\"${PYODIDE_MESON_CROSS_FILE}\""

source .venv-pyodide/bin/activate
cd ..
python numpy/runtests.py -n -vv
pytest --pyargs numpy -m "not slow"

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This change is still needed.

Comment threadmeson_cpu/meson.build
's390x': S390X_FEATURES,
'arm': ARM_FEATURES,
'aarch64': ARM_FEATURES,
'wasm32': {},

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

the changes in this file will still be needed.

endian = 'little'

[properties]
longdouble_format = 'IEEE_QUAD_LE'

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Most of this file can be removed, only this is needed:

[properties]longdouble_format = 'IEEE_QUAD_LE'

agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 23, 2024
Copied with updates and suggestions received from numpy#24603 on 23/02/2024.
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 23, 2024
Copied with updates and suggestions received from numpy#24603 on 23/02/2024.
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
@rgommersrgommers removed this from the 2.1.0 release milestone Feb 27, 2024
@rgommers

Copy link
Copy Markdown
MemberAuthor

This PR is superseded by gh-25894, things seem to work there. So I'll close this PR. Thanks for the help everyone!

@hoodmane

Copy link
Copy Markdown
Contributor

Thanks for working on this @rgommers and @agriyakhetarpal!

rgommers added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 29, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but
without SSE or SIMD instructions.
2. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target
(cross-builds).
3. Enables run for Emscripten/Pyodide wheels by setting the `if:`
condition to `true`.
4. Uses recursive submodules to ensure that vendored-meson is received.
5. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a
separate Emscripten folder to store relevant files)
6. Adds a patch for vendored-meson detection for Pyodide and applies
this Pyodide-meson patch in the Emscripten CI jobs
7. Builds wasm32 wheels without BLAS and LAPACK support (see
numpy#24750 (comment))
8. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions
received from numpy#24603 on 23/02/2024 and authorship is preserved with this
commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
agriyakhetarpal pushed a commit to agriyakhetarpal/scikit-image that referenced this pull request Mar 18, 2024
lagru added a commit to scikit-image/scikit-image that referenced this pull request Jun 10, 2024
* Test emscripten workflow inspired by NumPy
Adds a CI job to build and test scikit-image in a Pyodide virtual
environment through WASM wheels. Following this, it would be
possible to include JupyterLite notebooks in the
documentation in order to run scikit-image's code snippets
which come with docstring-based examples.
Initial inspiration was taken from
numpy/numpy#24603.
Co-authored-by: Lars Grüter <lagru@mailbox.org>
Co-authored-by: Stefan van der Walt <45071+stefanv@users.noreply.github.com>
Sign up for freeto 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.

5 participants

@rgommers@hoodmane@rth@ryanking13@agriyakhetarpal
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

WIP: CI: switch Emscripten job to Meson - #24603

Closed
rgommers wants to merge 1 commit into
numpy:mainfrom
rgommers:ci-emscripten
Closed

WIP: CI: switch Emscripten job to Meson#24603
rgommers wants to merge 1 commit into
numpy:mainfrom
rgommers:ci-emscripten

Conversation

@rgommers

Copy link
Copy Markdown
Member

This is one of the last CI jobs to be converted to Meson. Still a work in progress.

Note that we need to cross-compile here. Using pyodide build fails on not having a cross file. The source() function in pyodide_build/cli/build.py needs a --backend-flags parameter so that we can pass config-settings arguments to the backend. In the meantime, we use python -m build ....

One can also try this locally with:

$ python -m build -wnx -Csetup-args=--cross-file=\$PWD/tools/ci/emscripten.meson.cross -Csetup-args=-Dallow-noblas=true

as long as both pyodide-build and the exact version of Emscripten (currently 3.1.32, can be installed with https://emscripten.org/docs/tools_reference/emsdk.html) are available. The configure stage of the build looks fine, the build itself fails halfway through due to:

include/python3.11/pyport.h:601:2: error: "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."

That issue is due to a static assert in pyconfig.h, also discussed at: pyodide/pyodide#2494 (comment)

See also pyodide/pyodide#2238 and the patches to _numpyconfig.h in https://github.com/pyodide/pyodide/tree/main/packages/numpy.

tl;dr this needs some work, and it seems like cross-compilation is hard because Pyodide doesn't ship its own Python interpreter that we can actually target during a direct cross build.

Cc @hoodmane@rth. I hope I can bother you with this. If I got any of the above wrong or if you've got a suggestion to get past the LONG_BIT error, I'd love to hear it. Also, a couple of questions:

  • If I didn't overlook a way to pass --config-settings flags to the backend in the pyodide build CLI, would you accept a PR to Pyodide to add that? It should match backend-flags in meta.yaml recipes I think.
  • Since scikit-image can be cross-compiled, I had expected to be able to make that work for numpy too. But after reading this comment, that may not be true? Is that still the case, and do you see a road to a regular cross-compile working for NumPy? It's actually not clear to me how the distutils-based build works right now, it doesn't seem to be doing the "playback" thing explained in that comment.

@rgommers
rgommers marked this pull request as draft August 31, 2023 15:13
endian = 'little'

[properties]
longdouble_format = 'IEEE_QUAD_LE'

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This is the only addition compared to the upstream emscripten.meson.cross file in Pyodide - necessary for now.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Most of this file can be removed, only this is needed:

[properties]longdouble_format = 'IEEE_QUAD_LE'

@hoodmane

Copy link
Copy Markdown
Contributor

cc @ryanking13@henryiii

@rgommersrgommers added this to the 2.0.0 release milestone Sep 9, 2023
@rgommersrgommers mentioned this pull request Sep 9, 2023
3 tasks
@rgommers

Copy link
Copy Markdown
MemberAuthor

I decided that it's easier to finish this only after upgrading the build of numpy that Pyodide does in-tree to Meson and 1.26.x first. I've made a start on that, but I need to do some more digging. There was also a pip bug that made that a little more difficult. And pyodide/pyodide#4118 is the same LONG_BIT error as I'm seeing in this PR.

Next steps I plan to take (not necessarily in this order):

  • disable this CI job and remove all setup.py files
  • finish unvendoring meson-python from this repo after the next meson-python release
  • upgrade numpy in Pyodide to 1.26.0 + Meson
  • if needed, ensure the out-of-tree Pyodide build can take the same backend-flags as the in-tree build
  • re-enable this CI job on the main branch

@rth

rth commented Sep 11, 2023

Copy link
Copy Markdown
Contributor

Thanks for working on this @rgommers ! I don't have useful suggestions about the errors you are facing but I agree it would probably be easier to do this in the in-tree build first. Also cc @lesteve who worked on the scikit-image meson build.

If I didn't overlook a way to pass --config-settings flags to the backend in the pyodide build CLI, would you accept a PR to Pyodide to add that?

I think overall we could be happy to accept any changes needed to make numpy with meson work. But since pyodide build aims to be a drop-in replacement for python -m build, we need to double check in particular whether this would still be OK with cibuildwheel, or if there is some other recommended way of passing those config settings.

@rgommers

Copy link
Copy Markdown
MemberAuthor

But since pyodide build aims to be a drop-in replacement for python -m build, we need to double check in particular whether this would still be OK with cibuildwheel, or if there is some other recommended way of passing those config settings.

That should be fine for cibuildwheel I think. python -m build -Ckey=value will add key=value to the config_settings dict and then pass that on to the backend. -C/--config-setting is implemented in build, and -C/--config-settings in pip (note the extra s for pip in the long form). I am missing that flag from pyodide build --help.

@ryanking13

Copy link
Copy Markdown
Contributor

That should be fine for cibuildwheel I think. python -m build -Ckey=value will add key=value to the config_settings dict and then pass that on to the backend. -C/--config-setting is implemented in build, and -C/--config-settings in pip (note the extra s for pip in the long form). I am missing that flag from pyodide build --help.

Currently pyodide build passes extra command line arguments to config-settings (backend-flags), so pyodide build key1=val1 is equivalent to python -m build -C key1==val1 (it is not documented sorry). But yes, we should change it to -C/--config-settings to match the behavior of pypabuild and pip.

@rgommers

Copy link
Copy Markdown
MemberAuthor

Thank you @ryanking13, that's exactly what I needed.

lagru added a commit to scikit-image/scikit-image that referenced this pull request Dec 11, 2023
hoodmane referenced this pull request Feb 9, 2024
Moving it to Meson is going to take a bit of time, and in the meantime
we have to disable it, because it's the only job that still needs
the `setup.py` based build and we'd like to remove support for building
with `setup.py`.
@hoodmane

Copy link
Copy Markdown
Contributor

@ryanking13 Do you know what the status of this is? It would be good if we could look into this again. I would look into it myself but so far I don't know much about meson...

@rgommers

Copy link
Copy Markdown
MemberAuthor

I've been meaning to get back to this PR. I believe with @ryanking13's changes for improved Meson/meson-python support in Pyodide, this should be unblocked. Timing wise I realistically won't revisit it before the NumPy 2.0 release settles down though (any week now ...).

@ryanking13

Copy link
Copy Markdown
Contributor

Yes, now that we're building numpy with meson in-tree, I don't think it's going to be hard to make it work in out-of-tree too. We've recently added a patch for python-meson >= 0.15 so I think we need to release pyodide-build (0.25.1).

before the NumPy 2.0 release settles down

Maybe emscripten CI should also wait for numpy 2.0 to be released? I've seen Pyodide builds break in many cases when packages do major releases, so it might be better to wait and see if the numpy 2.0 build works in-tree before applying it.

@rgommers

rgommers commented Feb 11, 2024

Copy link
Copy Markdown
MemberAuthor

Maybe emscripten CI should also wait for numpy 2.0 to be released? I've seen Pyodide builds break in many cases when packages do major releases, so it might be better to wait and see if the numpy 2.0 build works in-tree before applying it.

That seems reasonable to me. EDIT: no real reason not to do it now though, it's just not a priority compared to 2.0-critical tasks.

@rgommersrgommers left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I added some comments to this file about what is still relevant. @agriyakhetarpal is going to have a fresh attempt at a new/updated CI job.


- name: Install pyodide-build
run: pip install "pydantic<2" pyodide-build==$PYODIDE_VERSION
run: pip install "pydantic<2" build pyodide-build==$PYODIDE_VERSION

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

build isn't needed anymore, I think pyodide-build will do fine.

cp pyproject.toml.setuppy pyproject.toml
CFLAGS=-g2 LDFLAGS=-g2 pyodide build
# Note that we need to cross-compile here. Using `pyodide build`
# fails on not having a cross file. The `source() function in

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This is no longer true, the cross file is shipped by pyodide now.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Update: still true actually, the cross file won't get applied as long as we have vendored-meson.

We also need the fix from pyodide/pyodide#4502 to actually pick up vendored-meson. With that, an out of tree build should work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am on it – I shall be adding a patch file to port the above PR into vendored-meson, as discussed on Slack.

# tl;dr this needs some work, and it seems like cross-compilation is
# hard because Pyodide doesn't ship its own Python interpreter that
# we can actually target during a direct cross build.
python -m build --wheel -Csetup-args=--cross-file=$PWD/tools/ci/emscripten.meson.cross -Csetup-args=-Dallow-noblas=true

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The -Dallow-noblas=true is no longer needed, the fallback to internal code when BLAS is missing is automatic.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The -Csetup-args=--cross-file=$PWD/tools/ci/emscripten.meson.cross will still be needed I think, only to add the longdouble format, just in slightly different format. From this comment I think it should be:

pyodide build setup-args="--cross-file=$PWD/tools/ci/emscripten.meson.cross"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pyodide bundles emscripten.meson.cross used in in-tree build, so probably you can try that one too.

PYODIDE_MESON_CROSS_FILE=`pyodide config get meson_cross_file`
pyodide build -C "setup-args=\"${PYODIDE_MESON_CROSS_FILE}\""

source .venv-pyodide/bin/activate
cd ..
python numpy/runtests.py -n -vv
pytest --pyargs numpy -m "not slow"

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This change is still needed.

Comment threadmeson_cpu/meson.build
's390x': S390X_FEATURES,
'arm': ARM_FEATURES,
'aarch64': ARM_FEATURES,
'wasm32': {},

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

the changes in this file will still be needed.

endian = 'little'

[properties]
longdouble_format = 'IEEE_QUAD_LE'

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Most of this file can be removed, only this is needed:

[properties]longdouble_format = 'IEEE_QUAD_LE'

agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 23, 2024
Copied with updates and suggestions received from numpy#24603 on 23/02/2024.
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 23, 2024
Copied with updates and suggestions received from numpy#24603 on 23/02/2024.
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
@rgommersrgommers removed this from the 2.1.0 release milestone Feb 27, 2024
@rgommers

Copy link
Copy Markdown
MemberAuthor

This PR is superseded by gh-25894, things seem to work there. So I'll close this PR. Thanks for the help everyone!

@hoodmane

Copy link
Copy Markdown
Contributor

Thanks for working on this @rgommers and @agriyakhetarpal!

rgommers added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 29, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but
without SSE or SIMD instructions.
2. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target
(cross-builds).
3. Enables run for Emscripten/Pyodide wheels by setting the `if:`
condition to `true`.
4. Uses recursive submodules to ensure that vendored-meson is received.
5. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a
separate Emscripten folder to store relevant files)
6. Adds a patch for vendored-meson detection for Pyodide and applies
this Pyodide-meson patch in the Emscripten CI jobs
7. Builds wasm32 wheels without BLAS and LAPACK support (see
numpy#24750 (comment))
8. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions
received from numpy#24603 on 23/02/2024 and authorship is preserved with this
commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
agriyakhetarpal pushed a commit to agriyakhetarpal/scikit-image that referenced this pull request Mar 18, 2024
lagru added a commit to scikit-image/scikit-image that referenced this pull request Jun 10, 2024
* Test emscripten workflow inspired by NumPy
Adds a CI job to build and test scikit-image in a Pyodide virtual
environment through WASM wheels. Following this, it would be
possible to include JupyterLite notebooks in the
documentation in order to run scikit-image's code snippets
which come with docstring-based examples.
Initial inspiration was taken from
numpy/numpy#24603.
Co-authored-by: Lars Grüter <lagru@mailbox.org>
Co-authored-by: Stefan van der Walt <45071+stefanv@users.noreply.github.com>
Sign up for freeto 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.

5 participants

@rgommers@hoodmane@rth@ryanking13@agriyakhetarpal
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

WIP: CI: switch Emscripten job to Meson - #24603

Closed
rgommers wants to merge 1 commit into
numpy:mainfrom
rgommers:ci-emscripten
Closed

WIP: CI: switch Emscripten job to Meson#24603
rgommers wants to merge 1 commit into
numpy:mainfrom
rgommers:ci-emscripten

Conversation

@rgommers

Copy link
Copy Markdown
Member

This is one of the last CI jobs to be converted to Meson. Still a work in progress.

Note that we need to cross-compile here. Using pyodide build fails on not having a cross file. The source() function in pyodide_build/cli/build.py needs a --backend-flags parameter so that we can pass config-settings arguments to the backend. In the meantime, we use python -m build ....

One can also try this locally with:

$ python -m build -wnx -Csetup-args=--cross-file=\$PWD/tools/ci/emscripten.meson.cross -Csetup-args=-Dallow-noblas=true

as long as both pyodide-build and the exact version of Emscripten (currently 3.1.32, can be installed with https://emscripten.org/docs/tools_reference/emsdk.html) are available. The configure stage of the build looks fine, the build itself fails halfway through due to:

include/python3.11/pyport.h:601:2: error: "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."

That issue is due to a static assert in pyconfig.h, also discussed at: pyodide/pyodide#2494 (comment)

See also pyodide/pyodide#2238 and the patches to _numpyconfig.h in https://github.com/pyodide/pyodide/tree/main/packages/numpy.

tl;dr this needs some work, and it seems like cross-compilation is hard because Pyodide doesn't ship its own Python interpreter that we can actually target during a direct cross build.

Cc @hoodmane@rth. I hope I can bother you with this. If I got any of the above wrong or if you've got a suggestion to get past the LONG_BIT error, I'd love to hear it. Also, a couple of questions:

  • If I didn't overlook a way to pass --config-settings flags to the backend in the pyodide build CLI, would you accept a PR to Pyodide to add that? It should match backend-flags in meta.yaml recipes I think.
  • Since scikit-image can be cross-compiled, I had expected to be able to make that work for numpy too. But after reading this comment, that may not be true? Is that still the case, and do you see a road to a regular cross-compile working for NumPy? It's actually not clear to me how the distutils-based build works right now, it doesn't seem to be doing the "playback" thing explained in that comment.

@rgommers
rgommers marked this pull request as draft August 31, 2023 15:13
endian = 'little'

[properties]
longdouble_format = 'IEEE_QUAD_LE'

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This is the only addition compared to the upstream emscripten.meson.cross file in Pyodide - necessary for now.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Most of this file can be removed, only this is needed:

[properties]longdouble_format = 'IEEE_QUAD_LE'

@hoodmane

Copy link
Copy Markdown
Contributor

cc @ryanking13@henryiii

@rgommersrgommers added this to the 2.0.0 release milestone Sep 9, 2023
@rgommersrgommers mentioned this pull request Sep 9, 2023
3 tasks
@rgommers

Copy link
Copy Markdown
MemberAuthor

I decided that it's easier to finish this only after upgrading the build of numpy that Pyodide does in-tree to Meson and 1.26.x first. I've made a start on that, but I need to do some more digging. There was also a pip bug that made that a little more difficult. And pyodide/pyodide#4118 is the same LONG_BIT error as I'm seeing in this PR.

Next steps I plan to take (not necessarily in this order):

  • disable this CI job and remove all setup.py files
  • finish unvendoring meson-python from this repo after the next meson-python release
  • upgrade numpy in Pyodide to 1.26.0 + Meson
  • if needed, ensure the out-of-tree Pyodide build can take the same backend-flags as the in-tree build
  • re-enable this CI job on the main branch

@rth

rth commented Sep 11, 2023

Copy link
Copy Markdown
Contributor

Thanks for working on this @rgommers ! I don't have useful suggestions about the errors you are facing but I agree it would probably be easier to do this in the in-tree build first. Also cc @lesteve who worked on the scikit-image meson build.

If I didn't overlook a way to pass --config-settings flags to the backend in the pyodide build CLI, would you accept a PR to Pyodide to add that?

I think overall we could be happy to accept any changes needed to make numpy with meson work. But since pyodide build aims to be a drop-in replacement for python -m build, we need to double check in particular whether this would still be OK with cibuildwheel, or if there is some other recommended way of passing those config settings.

@rgommers

Copy link
Copy Markdown
MemberAuthor

But since pyodide build aims to be a drop-in replacement for python -m build, we need to double check in particular whether this would still be OK with cibuildwheel, or if there is some other recommended way of passing those config settings.

That should be fine for cibuildwheel I think. python -m build -Ckey=value will add key=value to the config_settings dict and then pass that on to the backend. -C/--config-setting is implemented in build, and -C/--config-settings in pip (note the extra s for pip in the long form). I am missing that flag from pyodide build --help.

@ryanking13

Copy link
Copy Markdown
Contributor

That should be fine for cibuildwheel I think. python -m build -Ckey=value will add key=value to the config_settings dict and then pass that on to the backend. -C/--config-setting is implemented in build, and -C/--config-settings in pip (note the extra s for pip in the long form). I am missing that flag from pyodide build --help.

Currently pyodide build passes extra command line arguments to config-settings (backend-flags), so pyodide build key1=val1 is equivalent to python -m build -C key1==val1 (it is not documented sorry). But yes, we should change it to -C/--config-settings to match the behavior of pypabuild and pip.

@rgommers

Copy link
Copy Markdown
MemberAuthor

Thank you @ryanking13, that's exactly what I needed.

lagru added a commit to scikit-image/scikit-image that referenced this pull request Dec 11, 2023
hoodmane referenced this pull request Feb 9, 2024
Moving it to Meson is going to take a bit of time, and in the meantime
we have to disable it, because it's the only job that still needs
the `setup.py` based build and we'd like to remove support for building
with `setup.py`.
@hoodmane

Copy link
Copy Markdown
Contributor

@ryanking13 Do you know what the status of this is? It would be good if we could look into this again. I would look into it myself but so far I don't know much about meson...

@rgommers

Copy link
Copy Markdown
MemberAuthor

I've been meaning to get back to this PR. I believe with @ryanking13's changes for improved Meson/meson-python support in Pyodide, this should be unblocked. Timing wise I realistically won't revisit it before the NumPy 2.0 release settles down though (any week now ...).

@ryanking13

Copy link
Copy Markdown
Contributor

Yes, now that we're building numpy with meson in-tree, I don't think it's going to be hard to make it work in out-of-tree too. We've recently added a patch for python-meson >= 0.15 so I think we need to release pyodide-build (0.25.1).

before the NumPy 2.0 release settles down

Maybe emscripten CI should also wait for numpy 2.0 to be released? I've seen Pyodide builds break in many cases when packages do major releases, so it might be better to wait and see if the numpy 2.0 build works in-tree before applying it.

@rgommers

rgommers commented Feb 11, 2024

Copy link
Copy Markdown
MemberAuthor

Maybe emscripten CI should also wait for numpy 2.0 to be released? I've seen Pyodide builds break in many cases when packages do major releases, so it might be better to wait and see if the numpy 2.0 build works in-tree before applying it.

That seems reasonable to me. EDIT: no real reason not to do it now though, it's just not a priority compared to 2.0-critical tasks.

@rgommersrgommers left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I added some comments to this file about what is still relevant. @agriyakhetarpal is going to have a fresh attempt at a new/updated CI job.


- name: Install pyodide-build
run: pip install "pydantic<2" pyodide-build==$PYODIDE_VERSION
run: pip install "pydantic<2" build pyodide-build==$PYODIDE_VERSION

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

build isn't needed anymore, I think pyodide-build will do fine.

cp pyproject.toml.setuppy pyproject.toml
CFLAGS=-g2 LDFLAGS=-g2 pyodide build
# Note that we need to cross-compile here. Using `pyodide build`
# fails on not having a cross file. The `source() function in

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This is no longer true, the cross file is shipped by pyodide now.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Update: still true actually, the cross file won't get applied as long as we have vendored-meson.

We also need the fix from pyodide/pyodide#4502 to actually pick up vendored-meson. With that, an out of tree build should work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am on it – I shall be adding a patch file to port the above PR into vendored-meson, as discussed on Slack.

# tl;dr this needs some work, and it seems like cross-compilation is
# hard because Pyodide doesn't ship its own Python interpreter that
# we can actually target during a direct cross build.
python -m build --wheel -Csetup-args=--cross-file=$PWD/tools/ci/emscripten.meson.cross -Csetup-args=-Dallow-noblas=true

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The -Dallow-noblas=true is no longer needed, the fallback to internal code when BLAS is missing is automatic.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The -Csetup-args=--cross-file=$PWD/tools/ci/emscripten.meson.cross will still be needed I think, only to add the longdouble format, just in slightly different format. From this comment I think it should be:

pyodide build setup-args="--cross-file=$PWD/tools/ci/emscripten.meson.cross"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pyodide bundles emscripten.meson.cross used in in-tree build, so probably you can try that one too.

PYODIDE_MESON_CROSS_FILE=`pyodide config get meson_cross_file`
pyodide build -C "setup-args=\"${PYODIDE_MESON_CROSS_FILE}\""

source .venv-pyodide/bin/activate
cd ..
python numpy/runtests.py -n -vv
pytest --pyargs numpy -m "not slow"

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This change is still needed.

Comment threadmeson_cpu/meson.build
's390x': S390X_FEATURES,
'arm': ARM_FEATURES,
'aarch64': ARM_FEATURES,
'wasm32': {},

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

the changes in this file will still be needed.

endian = 'little'

[properties]
longdouble_format = 'IEEE_QUAD_LE'

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Most of this file can be removed, only this is needed:

[properties]longdouble_format = 'IEEE_QUAD_LE'

agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 23, 2024
Copied with updates and suggestions received from numpy#24603 on 23/02/2024.
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 23, 2024
Copied with updates and suggestions received from numpy#24603 on 23/02/2024.
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
@rgommersrgommers removed this from the 2.1.0 release milestone Feb 27, 2024
@rgommers

Copy link
Copy Markdown
MemberAuthor

This PR is superseded by gh-25894, things seem to work there. So I'll close this PR. Thanks for the help everyone!

@hoodmane

Copy link
Copy Markdown
Contributor

Thanks for working on this @rgommers and @agriyakhetarpal!

rgommers added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 29, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but
without SSE or SIMD instructions.
2. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target
(cross-builds).
3. Enables run for Emscripten/Pyodide wheels by setting the `if:`
condition to `true`.
4. Uses recursive submodules to ensure that vendored-meson is received.
5. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a
separate Emscripten folder to store relevant files)
6. Adds a patch for vendored-meson detection for Pyodide and applies
this Pyodide-meson patch in the Emscripten CI jobs
7. Builds wasm32 wheels without BLAS and LAPACK support (see
numpy#24750 (comment))
8. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions
received from numpy#24603 on 23/02/2024 and authorship is preserved with this
commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
agriyakhetarpal pushed a commit to agriyakhetarpal/scikit-image that referenced this pull request Mar 18, 2024
lagru added a commit to scikit-image/scikit-image that referenced this pull request Jun 10, 2024
* Test emscripten workflow inspired by NumPy
Adds a CI job to build and test scikit-image in a Pyodide virtual
environment through WASM wheels. Following this, it would be
possible to include JupyterLite notebooks in the
documentation in order to run scikit-image's code snippets
which come with docstring-based examples.
Initial inspiration was taken from
numpy/numpy#24603.
Co-authored-by: Lars Grüter <lagru@mailbox.org>
Co-authored-by: Stefan van der Walt <45071+stefanv@users.noreply.github.com>
Sign up for freeto 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.

5 participants

@rgommers@hoodmane@rth@ryanking13@agriyakhetarpal
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

WIP: CI: switch Emscripten job to Meson - #24603

Closed
rgommers wants to merge 1 commit into
numpy:mainfrom
rgommers:ci-emscripten
Closed

WIP: CI: switch Emscripten job to Meson#24603
rgommers wants to merge 1 commit into
numpy:mainfrom
rgommers:ci-emscripten

Conversation

@rgommers

Copy link
Copy Markdown
Member

This is one of the last CI jobs to be converted to Meson. Still a work in progress.

Note that we need to cross-compile here. Using pyodide build fails on not having a cross file. The source() function in pyodide_build/cli/build.py needs a --backend-flags parameter so that we can pass config-settings arguments to the backend. In the meantime, we use python -m build ....

One can also try this locally with:

$ python -m build -wnx -Csetup-args=--cross-file=\$PWD/tools/ci/emscripten.meson.cross -Csetup-args=-Dallow-noblas=true

as long as both pyodide-build and the exact version of Emscripten (currently 3.1.32, can be installed with https://emscripten.org/docs/tools_reference/emsdk.html) are available. The configure stage of the build looks fine, the build itself fails halfway through due to:

include/python3.11/pyport.h:601:2: error: "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."

That issue is due to a static assert in pyconfig.h, also discussed at: pyodide/pyodide#2494 (comment)

See also pyodide/pyodide#2238 and the patches to _numpyconfig.h in https://github.com/pyodide/pyodide/tree/main/packages/numpy.

tl;dr this needs some work, and it seems like cross-compilation is hard because Pyodide doesn't ship its own Python interpreter that we can actually target during a direct cross build.

Cc @hoodmane@rth. I hope I can bother you with this. If I got any of the above wrong or if you've got a suggestion to get past the LONG_BIT error, I'd love to hear it. Also, a couple of questions:

  • If I didn't overlook a way to pass --config-settings flags to the backend in the pyodide build CLI, would you accept a PR to Pyodide to add that? It should match backend-flags in meta.yaml recipes I think.
  • Since scikit-image can be cross-compiled, I had expected to be able to make that work for numpy too. But after reading this comment, that may not be true? Is that still the case, and do you see a road to a regular cross-compile working for NumPy? It's actually not clear to me how the distutils-based build works right now, it doesn't seem to be doing the "playback" thing explained in that comment.

@rgommers
rgommers marked this pull request as draft August 31, 2023 15:13
endian = 'little'

[properties]
longdouble_format = 'IEEE_QUAD_LE'

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This is the only addition compared to the upstream emscripten.meson.cross file in Pyodide - necessary for now.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Most of this file can be removed, only this is needed:

[properties]longdouble_format = 'IEEE_QUAD_LE'

@hoodmane

Copy link
Copy Markdown
Contributor

cc @ryanking13@henryiii

@rgommersrgommers added this to the 2.0.0 release milestone Sep 9, 2023
@rgommersrgommers mentioned this pull request Sep 9, 2023
3 tasks
@rgommers

Copy link
Copy Markdown
MemberAuthor

I decided that it's easier to finish this only after upgrading the build of numpy that Pyodide does in-tree to Meson and 1.26.x first. I've made a start on that, but I need to do some more digging. There was also a pip bug that made that a little more difficult. And pyodide/pyodide#4118 is the same LONG_BIT error as I'm seeing in this PR.

Next steps I plan to take (not necessarily in this order):

  • disable this CI job and remove all setup.py files
  • finish unvendoring meson-python from this repo after the next meson-python release
  • upgrade numpy in Pyodide to 1.26.0 + Meson
  • if needed, ensure the out-of-tree Pyodide build can take the same backend-flags as the in-tree build
  • re-enable this CI job on the main branch

@rth

rth commented Sep 11, 2023

Copy link
Copy Markdown
Contributor

Thanks for working on this @rgommers ! I don't have useful suggestions about the errors you are facing but I agree it would probably be easier to do this in the in-tree build first. Also cc @lesteve who worked on the scikit-image meson build.

If I didn't overlook a way to pass --config-settings flags to the backend in the pyodide build CLI, would you accept a PR to Pyodide to add that?

I think overall we could be happy to accept any changes needed to make numpy with meson work. But since pyodide build aims to be a drop-in replacement for python -m build, we need to double check in particular whether this would still be OK with cibuildwheel, or if there is some other recommended way of passing those config settings.

@rgommers

Copy link
Copy Markdown
MemberAuthor

But since pyodide build aims to be a drop-in replacement for python -m build, we need to double check in particular whether this would still be OK with cibuildwheel, or if there is some other recommended way of passing those config settings.

That should be fine for cibuildwheel I think. python -m build -Ckey=value will add key=value to the config_settings dict and then pass that on to the backend. -C/--config-setting is implemented in build, and -C/--config-settings in pip (note the extra s for pip in the long form). I am missing that flag from pyodide build --help.

@ryanking13

Copy link
Copy Markdown
Contributor

That should be fine for cibuildwheel I think. python -m build -Ckey=value will add key=value to the config_settings dict and then pass that on to the backend. -C/--config-setting is implemented in build, and -C/--config-settings in pip (note the extra s for pip in the long form). I am missing that flag from pyodide build --help.

Currently pyodide build passes extra command line arguments to config-settings (backend-flags), so pyodide build key1=val1 is equivalent to python -m build -C key1==val1 (it is not documented sorry). But yes, we should change it to -C/--config-settings to match the behavior of pypabuild and pip.

@rgommers

Copy link
Copy Markdown
MemberAuthor

Thank you @ryanking13, that's exactly what I needed.

lagru added a commit to scikit-image/scikit-image that referenced this pull request Dec 11, 2023
hoodmane referenced this pull request Feb 9, 2024
Moving it to Meson is going to take a bit of time, and in the meantime
we have to disable it, because it's the only job that still needs
the `setup.py` based build and we'd like to remove support for building
with `setup.py`.
@hoodmane

Copy link
Copy Markdown
Contributor

@ryanking13 Do you know what the status of this is? It would be good if we could look into this again. I would look into it myself but so far I don't know much about meson...

@rgommers

Copy link
Copy Markdown
MemberAuthor

I've been meaning to get back to this PR. I believe with @ryanking13's changes for improved Meson/meson-python support in Pyodide, this should be unblocked. Timing wise I realistically won't revisit it before the NumPy 2.0 release settles down though (any week now ...).

@ryanking13

Copy link
Copy Markdown
Contributor

Yes, now that we're building numpy with meson in-tree, I don't think it's going to be hard to make it work in out-of-tree too. We've recently added a patch for python-meson >= 0.15 so I think we need to release pyodide-build (0.25.1).

before the NumPy 2.0 release settles down

Maybe emscripten CI should also wait for numpy 2.0 to be released? I've seen Pyodide builds break in many cases when packages do major releases, so it might be better to wait and see if the numpy 2.0 build works in-tree before applying it.

@rgommers

rgommers commented Feb 11, 2024

Copy link
Copy Markdown
MemberAuthor

Maybe emscripten CI should also wait for numpy 2.0 to be released? I've seen Pyodide builds break in many cases when packages do major releases, so it might be better to wait and see if the numpy 2.0 build works in-tree before applying it.

That seems reasonable to me. EDIT: no real reason not to do it now though, it's just not a priority compared to 2.0-critical tasks.

@rgommersrgommers left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I added some comments to this file about what is still relevant. @agriyakhetarpal is going to have a fresh attempt at a new/updated CI job.


- name: Install pyodide-build
run: pip install "pydantic<2" pyodide-build==$PYODIDE_VERSION
run: pip install "pydantic<2" build pyodide-build==$PYODIDE_VERSION

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

build isn't needed anymore, I think pyodide-build will do fine.

cp pyproject.toml.setuppy pyproject.toml
CFLAGS=-g2 LDFLAGS=-g2 pyodide build
# Note that we need to cross-compile here. Using `pyodide build`
# fails on not having a cross file. The `source() function in

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This is no longer true, the cross file is shipped by pyodide now.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Update: still true actually, the cross file won't get applied as long as we have vendored-meson.

We also need the fix from pyodide/pyodide#4502 to actually pick up vendored-meson. With that, an out of tree build should work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am on it – I shall be adding a patch file to port the above PR into vendored-meson, as discussed on Slack.

# tl;dr this needs some work, and it seems like cross-compilation is
# hard because Pyodide doesn't ship its own Python interpreter that
# we can actually target during a direct cross build.
python -m build --wheel -Csetup-args=--cross-file=$PWD/tools/ci/emscripten.meson.cross -Csetup-args=-Dallow-noblas=true

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The -Dallow-noblas=true is no longer needed, the fallback to internal code when BLAS is missing is automatic.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The -Csetup-args=--cross-file=$PWD/tools/ci/emscripten.meson.cross will still be needed I think, only to add the longdouble format, just in slightly different format. From this comment I think it should be:

pyodide build setup-args="--cross-file=$PWD/tools/ci/emscripten.meson.cross"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pyodide bundles emscripten.meson.cross used in in-tree build, so probably you can try that one too.

PYODIDE_MESON_CROSS_FILE=`pyodide config get meson_cross_file`
pyodide build -C "setup-args=\"${PYODIDE_MESON_CROSS_FILE}\""

source .venv-pyodide/bin/activate
cd ..
python numpy/runtests.py -n -vv
pytest --pyargs numpy -m "not slow"

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This change is still needed.

Comment threadmeson_cpu/meson.build
's390x': S390X_FEATURES,
'arm': ARM_FEATURES,
'aarch64': ARM_FEATURES,
'wasm32': {},

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

the changes in this file will still be needed.

endian = 'little'

[properties]
longdouble_format = 'IEEE_QUAD_LE'

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Most of this file can be removed, only this is needed:

[properties]longdouble_format = 'IEEE_QUAD_LE'

agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 23, 2024
Copied with updates and suggestions received from numpy#24603 on 23/02/2024.
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 23, 2024
Copied with updates and suggestions received from numpy#24603 on 23/02/2024.
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
@rgommersrgommers removed this from the 2.1.0 release milestone Feb 27, 2024
@rgommers

Copy link
Copy Markdown
MemberAuthor

This PR is superseded by gh-25894, things seem to work there. So I'll close this PR. Thanks for the help everyone!

@hoodmane

Copy link
Copy Markdown
Contributor

Thanks for working on this @rgommers and @agriyakhetarpal!

rgommers added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 29, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but
without SSE or SIMD instructions.
2. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target
(cross-builds).
3. Enables run for Emscripten/Pyodide wheels by setting the `if:`
condition to `true`.
4. Uses recursive submodules to ensure that vendored-meson is received.
5. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a
separate Emscripten folder to store relevant files)
6. Adds a patch for vendored-meson detection for Pyodide and applies
this Pyodide-meson patch in the Emscripten CI jobs
7. Builds wasm32 wheels without BLAS and LAPACK support (see
numpy#24750 (comment))
8. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions
received from numpy#24603 on 23/02/2024 and authorship is preserved with this
commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
agriyakhetarpal pushed a commit to agriyakhetarpal/scikit-image that referenced this pull request Mar 18, 2024
lagru added a commit to scikit-image/scikit-image that referenced this pull request Jun 10, 2024
* Test emscripten workflow inspired by NumPy
Adds a CI job to build and test scikit-image in a Pyodide virtual
environment through WASM wheels. Following this, it would be
possible to include JupyterLite notebooks in the
documentation in order to run scikit-image's code snippets
which come with docstring-based examples.
Initial inspiration was taken from
numpy/numpy#24603.
Co-authored-by: Lars Grüter <lagru@mailbox.org>
Co-authored-by: Stefan van der Walt <45071+stefanv@users.noreply.github.com>
Sign up for freeto 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.

5 participants

@rgommers@hoodmane@rth@ryanking13@agriyakhetarpal
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

WIP: CI: switch Emscripten job to Meson - #24603

Closed
rgommers wants to merge 1 commit into
numpy:mainfrom
rgommers:ci-emscripten
Closed

WIP: CI: switch Emscripten job to Meson#24603
rgommers wants to merge 1 commit into
numpy:mainfrom
rgommers:ci-emscripten

Conversation

@rgommers

Copy link
Copy Markdown
Member

This is one of the last CI jobs to be converted to Meson. Still a work in progress.

Note that we need to cross-compile here. Using pyodide build fails on not having a cross file. The source() function in pyodide_build/cli/build.py needs a --backend-flags parameter so that we can pass config-settings arguments to the backend. In the meantime, we use python -m build ....

One can also try this locally with:

$ python -m build -wnx -Csetup-args=--cross-file=\$PWD/tools/ci/emscripten.meson.cross -Csetup-args=-Dallow-noblas=true

as long as both pyodide-build and the exact version of Emscripten (currently 3.1.32, can be installed with https://emscripten.org/docs/tools_reference/emsdk.html) are available. The configure stage of the build looks fine, the build itself fails halfway through due to:

include/python3.11/pyport.h:601:2: error: "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."

That issue is due to a static assert in pyconfig.h, also discussed at: pyodide/pyodide#2494 (comment)

See also pyodide/pyodide#2238 and the patches to _numpyconfig.h in https://github.com/pyodide/pyodide/tree/main/packages/numpy.

tl;dr this needs some work, and it seems like cross-compilation is hard because Pyodide doesn't ship its own Python interpreter that we can actually target during a direct cross build.

Cc @hoodmane@rth. I hope I can bother you with this. If I got any of the above wrong or if you've got a suggestion to get past the LONG_BIT error, I'd love to hear it. Also, a couple of questions:

  • If I didn't overlook a way to pass --config-settings flags to the backend in the pyodide build CLI, would you accept a PR to Pyodide to add that? It should match backend-flags in meta.yaml recipes I think.
  • Since scikit-image can be cross-compiled, I had expected to be able to make that work for numpy too. But after reading this comment, that may not be true? Is that still the case, and do you see a road to a regular cross-compile working for NumPy? It's actually not clear to me how the distutils-based build works right now, it doesn't seem to be doing the "playback" thing explained in that comment.

@rgommers
rgommers marked this pull request as draft August 31, 2023 15:13
endian = 'little'

[properties]
longdouble_format = 'IEEE_QUAD_LE'

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This is the only addition compared to the upstream emscripten.meson.cross file in Pyodide - necessary for now.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Most of this file can be removed, only this is needed:

[properties]longdouble_format = 'IEEE_QUAD_LE'

@hoodmane

Copy link
Copy Markdown
Contributor

cc @ryanking13@henryiii

@rgommersrgommers added this to the 2.0.0 release milestone Sep 9, 2023
@rgommersrgommers mentioned this pull request Sep 9, 2023
3 tasks
@rgommers

Copy link
Copy Markdown
MemberAuthor

I decided that it's easier to finish this only after upgrading the build of numpy that Pyodide does in-tree to Meson and 1.26.x first. I've made a start on that, but I need to do some more digging. There was also a pip bug that made that a little more difficult. And pyodide/pyodide#4118 is the same LONG_BIT error as I'm seeing in this PR.

Next steps I plan to take (not necessarily in this order):

  • disable this CI job and remove all setup.py files
  • finish unvendoring meson-python from this repo after the next meson-python release
  • upgrade numpy in Pyodide to 1.26.0 + Meson
  • if needed, ensure the out-of-tree Pyodide build can take the same backend-flags as the in-tree build
  • re-enable this CI job on the main branch

@rth

rth commented Sep 11, 2023

Copy link
Copy Markdown
Contributor

Thanks for working on this @rgommers ! I don't have useful suggestions about the errors you are facing but I agree it would probably be easier to do this in the in-tree build first. Also cc @lesteve who worked on the scikit-image meson build.

If I didn't overlook a way to pass --config-settings flags to the backend in the pyodide build CLI, would you accept a PR to Pyodide to add that?

I think overall we could be happy to accept any changes needed to make numpy with meson work. But since pyodide build aims to be a drop-in replacement for python -m build, we need to double check in particular whether this would still be OK with cibuildwheel, or if there is some other recommended way of passing those config settings.

@rgommers

Copy link
Copy Markdown
MemberAuthor

But since pyodide build aims to be a drop-in replacement for python -m build, we need to double check in particular whether this would still be OK with cibuildwheel, or if there is some other recommended way of passing those config settings.

That should be fine for cibuildwheel I think. python -m build -Ckey=value will add key=value to the config_settings dict and then pass that on to the backend. -C/--config-setting is implemented in build, and -C/--config-settings in pip (note the extra s for pip in the long form). I am missing that flag from pyodide build --help.

@ryanking13

Copy link
Copy Markdown
Contributor

That should be fine for cibuildwheel I think. python -m build -Ckey=value will add key=value to the config_settings dict and then pass that on to the backend. -C/--config-setting is implemented in build, and -C/--config-settings in pip (note the extra s for pip in the long form). I am missing that flag from pyodide build --help.

Currently pyodide build passes extra command line arguments to config-settings (backend-flags), so pyodide build key1=val1 is equivalent to python -m build -C key1==val1 (it is not documented sorry). But yes, we should change it to -C/--config-settings to match the behavior of pypabuild and pip.

@rgommers

Copy link
Copy Markdown
MemberAuthor

Thank you @ryanking13, that's exactly what I needed.

lagru added a commit to scikit-image/scikit-image that referenced this pull request Dec 11, 2023
hoodmane referenced this pull request Feb 9, 2024
Moving it to Meson is going to take a bit of time, and in the meantime
we have to disable it, because it's the only job that still needs
the `setup.py` based build and we'd like to remove support for building
with `setup.py`.
@hoodmane

Copy link
Copy Markdown
Contributor

@ryanking13 Do you know what the status of this is? It would be good if we could look into this again. I would look into it myself but so far I don't know much about meson...

@rgommers

Copy link
Copy Markdown
MemberAuthor

I've been meaning to get back to this PR. I believe with @ryanking13's changes for improved Meson/meson-python support in Pyodide, this should be unblocked. Timing wise I realistically won't revisit it before the NumPy 2.0 release settles down though (any week now ...).

@ryanking13

Copy link
Copy Markdown
Contributor

Yes, now that we're building numpy with meson in-tree, I don't think it's going to be hard to make it work in out-of-tree too. We've recently added a patch for python-meson >= 0.15 so I think we need to release pyodide-build (0.25.1).

before the NumPy 2.0 release settles down

Maybe emscripten CI should also wait for numpy 2.0 to be released? I've seen Pyodide builds break in many cases when packages do major releases, so it might be better to wait and see if the numpy 2.0 build works in-tree before applying it.

@rgommers

rgommers commented Feb 11, 2024

Copy link
Copy Markdown
MemberAuthor

Maybe emscripten CI should also wait for numpy 2.0 to be released? I've seen Pyodide builds break in many cases when packages do major releases, so it might be better to wait and see if the numpy 2.0 build works in-tree before applying it.

That seems reasonable to me. EDIT: no real reason not to do it now though, it's just not a priority compared to 2.0-critical tasks.

@rgommersrgommers left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I added some comments to this file about what is still relevant. @agriyakhetarpal is going to have a fresh attempt at a new/updated CI job.


- name: Install pyodide-build
run: pip install "pydantic<2" pyodide-build==$PYODIDE_VERSION
run: pip install "pydantic<2" build pyodide-build==$PYODIDE_VERSION

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

build isn't needed anymore, I think pyodide-build will do fine.

cp pyproject.toml.setuppy pyproject.toml
CFLAGS=-g2 LDFLAGS=-g2 pyodide build
# Note that we need to cross-compile here. Using `pyodide build`
# fails on not having a cross file. The `source() function in

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This is no longer true, the cross file is shipped by pyodide now.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Update: still true actually, the cross file won't get applied as long as we have vendored-meson.

We also need the fix from pyodide/pyodide#4502 to actually pick up vendored-meson. With that, an out of tree build should work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am on it – I shall be adding a patch file to port the above PR into vendored-meson, as discussed on Slack.

# tl;dr this needs some work, and it seems like cross-compilation is
# hard because Pyodide doesn't ship its own Python interpreter that
# we can actually target during a direct cross build.
python -m build --wheel -Csetup-args=--cross-file=$PWD/tools/ci/emscripten.meson.cross -Csetup-args=-Dallow-noblas=true

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The -Dallow-noblas=true is no longer needed, the fallback to internal code when BLAS is missing is automatic.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The -Csetup-args=--cross-file=$PWD/tools/ci/emscripten.meson.cross will still be needed I think, only to add the longdouble format, just in slightly different format. From this comment I think it should be:

pyodide build setup-args="--cross-file=$PWD/tools/ci/emscripten.meson.cross"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pyodide bundles emscripten.meson.cross used in in-tree build, so probably you can try that one too.

PYODIDE_MESON_CROSS_FILE=`pyodide config get meson_cross_file`
pyodide build -C "setup-args=\"${PYODIDE_MESON_CROSS_FILE}\""

source .venv-pyodide/bin/activate
cd ..
python numpy/runtests.py -n -vv
pytest --pyargs numpy -m "not slow"

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This change is still needed.

Comment threadmeson_cpu/meson.build
's390x': S390X_FEATURES,
'arm': ARM_FEATURES,
'aarch64': ARM_FEATURES,
'wasm32': {},

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

the changes in this file will still be needed.

endian = 'little'

[properties]
longdouble_format = 'IEEE_QUAD_LE'

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Most of this file can be removed, only this is needed:

[properties]longdouble_format = 'IEEE_QUAD_LE'

agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 23, 2024
Copied with updates and suggestions received from numpy#24603 on 23/02/2024.
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 23, 2024
Copied with updates and suggestions received from numpy#24603 on 23/02/2024.
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
@rgommersrgommers removed this from the 2.1.0 release milestone Feb 27, 2024
@rgommers

Copy link
Copy Markdown
MemberAuthor

This PR is superseded by gh-25894, things seem to work there. So I'll close this PR. Thanks for the help everyone!

@hoodmane

Copy link
Copy Markdown
Contributor

Thanks for working on this @rgommers and @agriyakhetarpal!

rgommers added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 29, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but
without SSE or SIMD instructions.
2. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target
(cross-builds).
3. Enables run for Emscripten/Pyodide wheels by setting the `if:`
condition to `true`.
4. Uses recursive submodules to ensure that vendored-meson is received.
5. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a
separate Emscripten folder to store relevant files)
6. Adds a patch for vendored-meson detection for Pyodide and applies
this Pyodide-meson patch in the Emscripten CI jobs
7. Builds wasm32 wheels without BLAS and LAPACK support (see
numpy#24750 (comment))
8. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions
received from numpy#24603 on 23/02/2024 and authorship is preserved with this
commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
agriyakhetarpal pushed a commit to agriyakhetarpal/scikit-image that referenced this pull request Mar 18, 2024
lagru added a commit to scikit-image/scikit-image that referenced this pull request Jun 10, 2024
* Test emscripten workflow inspired by NumPy
Adds a CI job to build and test scikit-image in a Pyodide virtual
environment through WASM wheels. Following this, it would be
possible to include JupyterLite notebooks in the
documentation in order to run scikit-image's code snippets
which come with docstring-based examples.
Initial inspiration was taken from
numpy/numpy#24603.
Co-authored-by: Lars Grüter <lagru@mailbox.org>
Co-authored-by: Stefan van der Walt <45071+stefanv@users.noreply.github.com>
Sign up for freeto 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.

5 participants

@rgommers@hoodmane@rth@ryanking13@agriyakhetarpal
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

WIP: CI: switch Emscripten job to Meson - #24603

Closed
rgommers wants to merge 1 commit into
numpy:mainfrom
rgommers:ci-emscripten
Closed

WIP: CI: switch Emscripten job to Meson#24603
rgommers wants to merge 1 commit into
numpy:mainfrom
rgommers:ci-emscripten

Conversation

@rgommers

Copy link
Copy Markdown
Member

This is one of the last CI jobs to be converted to Meson. Still a work in progress.

Note that we need to cross-compile here. Using pyodide build fails on not having a cross file. The source() function in pyodide_build/cli/build.py needs a --backend-flags parameter so that we can pass config-settings arguments to the backend. In the meantime, we use python -m build ....

One can also try this locally with:

$ python -m build -wnx -Csetup-args=--cross-file=\$PWD/tools/ci/emscripten.meson.cross -Csetup-args=-Dallow-noblas=true

as long as both pyodide-build and the exact version of Emscripten (currently 3.1.32, can be installed with https://emscripten.org/docs/tools_reference/emsdk.html) are available. The configure stage of the build looks fine, the build itself fails halfway through due to:

include/python3.11/pyport.h:601:2: error: "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."

That issue is due to a static assert in pyconfig.h, also discussed at: pyodide/pyodide#2494 (comment)

See also pyodide/pyodide#2238 and the patches to _numpyconfig.h in https://github.com/pyodide/pyodide/tree/main/packages/numpy.

tl;dr this needs some work, and it seems like cross-compilation is hard because Pyodide doesn't ship its own Python interpreter that we can actually target during a direct cross build.

Cc @hoodmane@rth. I hope I can bother you with this. If I got any of the above wrong or if you've got a suggestion to get past the LONG_BIT error, I'd love to hear it. Also, a couple of questions:

  • If I didn't overlook a way to pass --config-settings flags to the backend in the pyodide build CLI, would you accept a PR to Pyodide to add that? It should match backend-flags in meta.yaml recipes I think.
  • Since scikit-image can be cross-compiled, I had expected to be able to make that work for numpy too. But after reading this comment, that may not be true? Is that still the case, and do you see a road to a regular cross-compile working for NumPy? It's actually not clear to me how the distutils-based build works right now, it doesn't seem to be doing the "playback" thing explained in that comment.

@rgommers
rgommers marked this pull request as draft August 31, 2023 15:13
endian = 'little'

[properties]
longdouble_format = 'IEEE_QUAD_LE'

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This is the only addition compared to the upstream emscripten.meson.cross file in Pyodide - necessary for now.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Most of this file can be removed, only this is needed:

[properties]longdouble_format = 'IEEE_QUAD_LE'

@hoodmane

Copy link
Copy Markdown
Contributor

cc @ryanking13@henryiii

@rgommersrgommers added this to the 2.0.0 release milestone Sep 9, 2023
@rgommersrgommers mentioned this pull request Sep 9, 2023
3 tasks
@rgommers

Copy link
Copy Markdown
MemberAuthor

I decided that it's easier to finish this only after upgrading the build of numpy that Pyodide does in-tree to Meson and 1.26.x first. I've made a start on that, but I need to do some more digging. There was also a pip bug that made that a little more difficult. And pyodide/pyodide#4118 is the same LONG_BIT error as I'm seeing in this PR.

Next steps I plan to take (not necessarily in this order):

  • disable this CI job and remove all setup.py files
  • finish unvendoring meson-python from this repo after the next meson-python release
  • upgrade numpy in Pyodide to 1.26.0 + Meson
  • if needed, ensure the out-of-tree Pyodide build can take the same backend-flags as the in-tree build
  • re-enable this CI job on the main branch

@rth

rth commented Sep 11, 2023

Copy link
Copy Markdown
Contributor

Thanks for working on this @rgommers ! I don't have useful suggestions about the errors you are facing but I agree it would probably be easier to do this in the in-tree build first. Also cc @lesteve who worked on the scikit-image meson build.

If I didn't overlook a way to pass --config-settings flags to the backend in the pyodide build CLI, would you accept a PR to Pyodide to add that?

I think overall we could be happy to accept any changes needed to make numpy with meson work. But since pyodide build aims to be a drop-in replacement for python -m build, we need to double check in particular whether this would still be OK with cibuildwheel, or if there is some other recommended way of passing those config settings.

@rgommers

Copy link
Copy Markdown
MemberAuthor

But since pyodide build aims to be a drop-in replacement for python -m build, we need to double check in particular whether this would still be OK with cibuildwheel, or if there is some other recommended way of passing those config settings.

That should be fine for cibuildwheel I think. python -m build -Ckey=value will add key=value to the config_settings dict and then pass that on to the backend. -C/--config-setting is implemented in build, and -C/--config-settings in pip (note the extra s for pip in the long form). I am missing that flag from pyodide build --help.

@ryanking13

Copy link
Copy Markdown
Contributor

That should be fine for cibuildwheel I think. python -m build -Ckey=value will add key=value to the config_settings dict and then pass that on to the backend. -C/--config-setting is implemented in build, and -C/--config-settings in pip (note the extra s for pip in the long form). I am missing that flag from pyodide build --help.

Currently pyodide build passes extra command line arguments to config-settings (backend-flags), so pyodide build key1=val1 is equivalent to python -m build -C key1==val1 (it is not documented sorry). But yes, we should change it to -C/--config-settings to match the behavior of pypabuild and pip.

@rgommers

Copy link
Copy Markdown
MemberAuthor

Thank you @ryanking13, that's exactly what I needed.

lagru added a commit to scikit-image/scikit-image that referenced this pull request Dec 11, 2023
hoodmane referenced this pull request Feb 9, 2024
Moving it to Meson is going to take a bit of time, and in the meantime
we have to disable it, because it's the only job that still needs
the `setup.py` based build and we'd like to remove support for building
with `setup.py`.
@hoodmane

Copy link
Copy Markdown
Contributor

@ryanking13 Do you know what the status of this is? It would be good if we could look into this again. I would look into it myself but so far I don't know much about meson...

@rgommers

Copy link
Copy Markdown
MemberAuthor

I've been meaning to get back to this PR. I believe with @ryanking13's changes for improved Meson/meson-python support in Pyodide, this should be unblocked. Timing wise I realistically won't revisit it before the NumPy 2.0 release settles down though (any week now ...).

@ryanking13

Copy link
Copy Markdown
Contributor

Yes, now that we're building numpy with meson in-tree, I don't think it's going to be hard to make it work in out-of-tree too. We've recently added a patch for python-meson >= 0.15 so I think we need to release pyodide-build (0.25.1).

before the NumPy 2.0 release settles down

Maybe emscripten CI should also wait for numpy 2.0 to be released? I've seen Pyodide builds break in many cases when packages do major releases, so it might be better to wait and see if the numpy 2.0 build works in-tree before applying it.

@rgommers

rgommers commented Feb 11, 2024

Copy link
Copy Markdown
MemberAuthor

Maybe emscripten CI should also wait for numpy 2.0 to be released? I've seen Pyodide builds break in many cases when packages do major releases, so it might be better to wait and see if the numpy 2.0 build works in-tree before applying it.

That seems reasonable to me. EDIT: no real reason not to do it now though, it's just not a priority compared to 2.0-critical tasks.

@rgommersrgommers left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I added some comments to this file about what is still relevant. @agriyakhetarpal is going to have a fresh attempt at a new/updated CI job.


- name: Install pyodide-build
run: pip install "pydantic<2" pyodide-build==$PYODIDE_VERSION
run: pip install "pydantic<2" build pyodide-build==$PYODIDE_VERSION

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

build isn't needed anymore, I think pyodide-build will do fine.

cp pyproject.toml.setuppy pyproject.toml
CFLAGS=-g2 LDFLAGS=-g2 pyodide build
# Note that we need to cross-compile here. Using `pyodide build`
# fails on not having a cross file. The `source() function in

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This is no longer true, the cross file is shipped by pyodide now.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Update: still true actually, the cross file won't get applied as long as we have vendored-meson.

We also need the fix from pyodide/pyodide#4502 to actually pick up vendored-meson. With that, an out of tree build should work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am on it – I shall be adding a patch file to port the above PR into vendored-meson, as discussed on Slack.

# tl;dr this needs some work, and it seems like cross-compilation is
# hard because Pyodide doesn't ship its own Python interpreter that
# we can actually target during a direct cross build.
python -m build --wheel -Csetup-args=--cross-file=$PWD/tools/ci/emscripten.meson.cross -Csetup-args=-Dallow-noblas=true

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The -Dallow-noblas=true is no longer needed, the fallback to internal code when BLAS is missing is automatic.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The -Csetup-args=--cross-file=$PWD/tools/ci/emscripten.meson.cross will still be needed I think, only to add the longdouble format, just in slightly different format. From this comment I think it should be:

pyodide build setup-args="--cross-file=$PWD/tools/ci/emscripten.meson.cross"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pyodide bundles emscripten.meson.cross used in in-tree build, so probably you can try that one too.

PYODIDE_MESON_CROSS_FILE=`pyodide config get meson_cross_file`
pyodide build -C "setup-args=\"${PYODIDE_MESON_CROSS_FILE}\""

source .venv-pyodide/bin/activate
cd ..
python numpy/runtests.py -n -vv
pytest --pyargs numpy -m "not slow"

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This change is still needed.

Comment threadmeson_cpu/meson.build
's390x': S390X_FEATURES,
'arm': ARM_FEATURES,
'aarch64': ARM_FEATURES,
'wasm32': {},

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

the changes in this file will still be needed.

endian = 'little'

[properties]
longdouble_format = 'IEEE_QUAD_LE'

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Most of this file can be removed, only this is needed:

[properties]longdouble_format = 'IEEE_QUAD_LE'

agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 23, 2024
Copied with updates and suggestions received from numpy#24603 on 23/02/2024.
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 23, 2024
Copied with updates and suggestions received from numpy#24603 on 23/02/2024.
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
@rgommersrgommers removed this from the 2.1.0 release milestone Feb 27, 2024
@rgommers

Copy link
Copy Markdown
MemberAuthor

This PR is superseded by gh-25894, things seem to work there. So I'll close this PR. Thanks for the help everyone!

@hoodmane

Copy link
Copy Markdown
Contributor

Thanks for working on this @rgommers and @agriyakhetarpal!

rgommers added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 29, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but
without SSE or SIMD instructions.
2. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target
(cross-builds).
3. Enables run for Emscripten/Pyodide wheels by setting the `if:`
condition to `true`.
4. Uses recursive submodules to ensure that vendored-meson is received.
5. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a
separate Emscripten folder to store relevant files)
6. Adds a patch for vendored-meson detection for Pyodide and applies
this Pyodide-meson patch in the Emscripten CI jobs
7. Builds wasm32 wheels without BLAS and LAPACK support (see
numpy#24750 (comment))
8. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions
received from numpy#24603 on 23/02/2024 and authorship is preserved with this
commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
agriyakhetarpal pushed a commit to agriyakhetarpal/scikit-image that referenced this pull request Mar 18, 2024
lagru added a commit to scikit-image/scikit-image that referenced this pull request Jun 10, 2024
* Test emscripten workflow inspired by NumPy
Adds a CI job to build and test scikit-image in a Pyodide virtual
environment through WASM wheels. Following this, it would be
possible to include JupyterLite notebooks in the
documentation in order to run scikit-image's code snippets
which come with docstring-based examples.
Initial inspiration was taken from
numpy/numpy#24603.
Co-authored-by: Lars Grüter <lagru@mailbox.org>
Co-authored-by: Stefan van der Walt <45071+stefanv@users.noreply.github.com>
Sign up for freeto 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.

5 participants

@rgommers@hoodmane@rth@ryanking13@agriyakhetarpal
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

WIP: CI: switch Emscripten job to Meson - #24603

Closed
rgommers wants to merge 1 commit into
numpy:mainfrom
rgommers:ci-emscripten
Closed

WIP: CI: switch Emscripten job to Meson#24603
rgommers wants to merge 1 commit into
numpy:mainfrom
rgommers:ci-emscripten

Conversation

@rgommers

Copy link
Copy Markdown
Member

This is one of the last CI jobs to be converted to Meson. Still a work in progress.

Note that we need to cross-compile here. Using pyodide build fails on not having a cross file. The source() function in pyodide_build/cli/build.py needs a --backend-flags parameter so that we can pass config-settings arguments to the backend. In the meantime, we use python -m build ....

One can also try this locally with:

$ python -m build -wnx -Csetup-args=--cross-file=\$PWD/tools/ci/emscripten.meson.cross -Csetup-args=-Dallow-noblas=true

as long as both pyodide-build and the exact version of Emscripten (currently 3.1.32, can be installed with https://emscripten.org/docs/tools_reference/emsdk.html) are available. The configure stage of the build looks fine, the build itself fails halfway through due to:

include/python3.11/pyport.h:601:2: error: "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."

That issue is due to a static assert in pyconfig.h, also discussed at: pyodide/pyodide#2494 (comment)

See also pyodide/pyodide#2238 and the patches to _numpyconfig.h in https://github.com/pyodide/pyodide/tree/main/packages/numpy.

tl;dr this needs some work, and it seems like cross-compilation is hard because Pyodide doesn't ship its own Python interpreter that we can actually target during a direct cross build.

Cc @hoodmane@rth. I hope I can bother you with this. If I got any of the above wrong or if you've got a suggestion to get past the LONG_BIT error, I'd love to hear it. Also, a couple of questions:

  • If I didn't overlook a way to pass --config-settings flags to the backend in the pyodide build CLI, would you accept a PR to Pyodide to add that? It should match backend-flags in meta.yaml recipes I think.
  • Since scikit-image can be cross-compiled, I had expected to be able to make that work for numpy too. But after reading this comment, that may not be true? Is that still the case, and do you see a road to a regular cross-compile working for NumPy? It's actually not clear to me how the distutils-based build works right now, it doesn't seem to be doing the "playback" thing explained in that comment.

@rgommers
rgommers marked this pull request as draft August 31, 2023 15:13
endian = 'little'

[properties]
longdouble_format = 'IEEE_QUAD_LE'

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This is the only addition compared to the upstream emscripten.meson.cross file in Pyodide - necessary for now.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Most of this file can be removed, only this is needed:

[properties]longdouble_format = 'IEEE_QUAD_LE'

@hoodmane

Copy link
Copy Markdown
Contributor

cc @ryanking13@henryiii

@rgommersrgommers added this to the 2.0.0 release milestone Sep 9, 2023
@rgommersrgommers mentioned this pull request Sep 9, 2023
3 tasks
@rgommers

Copy link
Copy Markdown
MemberAuthor

I decided that it's easier to finish this only after upgrading the build of numpy that Pyodide does in-tree to Meson and 1.26.x first. I've made a start on that, but I need to do some more digging. There was also a pip bug that made that a little more difficult. And pyodide/pyodide#4118 is the same LONG_BIT error as I'm seeing in this PR.

Next steps I plan to take (not necessarily in this order):

  • disable this CI job and remove all setup.py files
  • finish unvendoring meson-python from this repo after the next meson-python release
  • upgrade numpy in Pyodide to 1.26.0 + Meson
  • if needed, ensure the out-of-tree Pyodide build can take the same backend-flags as the in-tree build
  • re-enable this CI job on the main branch

@rth

rth commented Sep 11, 2023

Copy link
Copy Markdown
Contributor

Thanks for working on this @rgommers ! I don't have useful suggestions about the errors you are facing but I agree it would probably be easier to do this in the in-tree build first. Also cc @lesteve who worked on the scikit-image meson build.

If I didn't overlook a way to pass --config-settings flags to the backend in the pyodide build CLI, would you accept a PR to Pyodide to add that?

I think overall we could be happy to accept any changes needed to make numpy with meson work. But since pyodide build aims to be a drop-in replacement for python -m build, we need to double check in particular whether this would still be OK with cibuildwheel, or if there is some other recommended way of passing those config settings.

@rgommers

Copy link
Copy Markdown
MemberAuthor

But since pyodide build aims to be a drop-in replacement for python -m build, we need to double check in particular whether this would still be OK with cibuildwheel, or if there is some other recommended way of passing those config settings.

That should be fine for cibuildwheel I think. python -m build -Ckey=value will add key=value to the config_settings dict and then pass that on to the backend. -C/--config-setting is implemented in build, and -C/--config-settings in pip (note the extra s for pip in the long form). I am missing that flag from pyodide build --help.

@ryanking13

Copy link
Copy Markdown
Contributor

That should be fine for cibuildwheel I think. python -m build -Ckey=value will add key=value to the config_settings dict and then pass that on to the backend. -C/--config-setting is implemented in build, and -C/--config-settings in pip (note the extra s for pip in the long form). I am missing that flag from pyodide build --help.

Currently pyodide build passes extra command line arguments to config-settings (backend-flags), so pyodide build key1=val1 is equivalent to python -m build -C key1==val1 (it is not documented sorry). But yes, we should change it to -C/--config-settings to match the behavior of pypabuild and pip.

@rgommers

Copy link
Copy Markdown
MemberAuthor

Thank you @ryanking13, that's exactly what I needed.

lagru added a commit to scikit-image/scikit-image that referenced this pull request Dec 11, 2023
hoodmane referenced this pull request Feb 9, 2024
Moving it to Meson is going to take a bit of time, and in the meantime
we have to disable it, because it's the only job that still needs
the `setup.py` based build and we'd like to remove support for building
with `setup.py`.
@hoodmane

Copy link
Copy Markdown
Contributor

@ryanking13 Do you know what the status of this is? It would be good if we could look into this again. I would look into it myself but so far I don't know much about meson...

@rgommers

Copy link
Copy Markdown
MemberAuthor

I've been meaning to get back to this PR. I believe with @ryanking13's changes for improved Meson/meson-python support in Pyodide, this should be unblocked. Timing wise I realistically won't revisit it before the NumPy 2.0 release settles down though (any week now ...).

@ryanking13

Copy link
Copy Markdown
Contributor

Yes, now that we're building numpy with meson in-tree, I don't think it's going to be hard to make it work in out-of-tree too. We've recently added a patch for python-meson >= 0.15 so I think we need to release pyodide-build (0.25.1).

before the NumPy 2.0 release settles down

Maybe emscripten CI should also wait for numpy 2.0 to be released? I've seen Pyodide builds break in many cases when packages do major releases, so it might be better to wait and see if the numpy 2.0 build works in-tree before applying it.

@rgommers

rgommers commented Feb 11, 2024

Copy link
Copy Markdown
MemberAuthor

Maybe emscripten CI should also wait for numpy 2.0 to be released? I've seen Pyodide builds break in many cases when packages do major releases, so it might be better to wait and see if the numpy 2.0 build works in-tree before applying it.

That seems reasonable to me. EDIT: no real reason not to do it now though, it's just not a priority compared to 2.0-critical tasks.

@rgommersrgommers left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I added some comments to this file about what is still relevant. @agriyakhetarpal is going to have a fresh attempt at a new/updated CI job.


- name: Install pyodide-build
run: pip install "pydantic<2" pyodide-build==$PYODIDE_VERSION
run: pip install "pydantic<2" build pyodide-build==$PYODIDE_VERSION

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

build isn't needed anymore, I think pyodide-build will do fine.

cp pyproject.toml.setuppy pyproject.toml
CFLAGS=-g2 LDFLAGS=-g2 pyodide build
# Note that we need to cross-compile here. Using `pyodide build`
# fails on not having a cross file. The `source() function in

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This is no longer true, the cross file is shipped by pyodide now.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Update: still true actually, the cross file won't get applied as long as we have vendored-meson.

We also need the fix from pyodide/pyodide#4502 to actually pick up vendored-meson. With that, an out of tree build should work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am on it – I shall be adding a patch file to port the above PR into vendored-meson, as discussed on Slack.

# tl;dr this needs some work, and it seems like cross-compilation is
# hard because Pyodide doesn't ship its own Python interpreter that
# we can actually target during a direct cross build.
python -m build --wheel -Csetup-args=--cross-file=$PWD/tools/ci/emscripten.meson.cross -Csetup-args=-Dallow-noblas=true

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The -Dallow-noblas=true is no longer needed, the fallback to internal code when BLAS is missing is automatic.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The -Csetup-args=--cross-file=$PWD/tools/ci/emscripten.meson.cross will still be needed I think, only to add the longdouble format, just in slightly different format. From this comment I think it should be:

pyodide build setup-args="--cross-file=$PWD/tools/ci/emscripten.meson.cross"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pyodide bundles emscripten.meson.cross used in in-tree build, so probably you can try that one too.

PYODIDE_MESON_CROSS_FILE=`pyodide config get meson_cross_file`
pyodide build -C "setup-args=\"${PYODIDE_MESON_CROSS_FILE}\""

source .venv-pyodide/bin/activate
cd ..
python numpy/runtests.py -n -vv
pytest --pyargs numpy -m "not slow"

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This change is still needed.

Comment threadmeson_cpu/meson.build
's390x': S390X_FEATURES,
'arm': ARM_FEATURES,
'aarch64': ARM_FEATURES,
'wasm32': {},

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

the changes in this file will still be needed.

endian = 'little'

[properties]
longdouble_format = 'IEEE_QUAD_LE'

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Most of this file can be removed, only this is needed:

[properties]longdouble_format = 'IEEE_QUAD_LE'

agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 23, 2024
Copied with updates and suggestions received from numpy#24603 on 23/02/2024.
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 23, 2024
Copied with updates and suggestions received from numpy#24603 on 23/02/2024.
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
agriyakhetarpal added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 27, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but without SSE or SIMD instructions.
2. Removes CPU feature detection message for an unsupported architecture.
3. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target (cross-builds).
4. Enables run for Emscripten/Pyodide wheels by setting the `if:` condition to `true`.
5. Uses recursive submodules to ensure that vendored-meson is received.
6. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a separate Emscripten folder to store relevant files)
7. Adds a patch for vendored-meson detection for Pyodide and applies this Pyodide-meson patch in the Emscripten CI jobs
8. Builds wasm32 wheels without BLAS and LAPACK support (see numpy#24750 (comment))
9. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions received from numpy#24603 on 23/02/2024 and authorship is preserved with this commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
@rgommersrgommers removed this from the 2.1.0 release milestone Feb 27, 2024
@rgommers

Copy link
Copy Markdown
MemberAuthor

This PR is superseded by gh-25894, things seem to work there. So I'll close this PR. Thanks for the help everyone!

@hoodmane

Copy link
Copy Markdown
Contributor

Thanks for working on this @rgommers and @agriyakhetarpal!

rgommers added a commit to agriyakhetarpal/numpy that referenced this pull request Feb 29, 2024
This commit performs the following actions:
1. Adds WASM builds to the CPU family for Meson configurations, but
without SSE or SIMD instructions.
2. Enables `IEEE_QUAD_LE` longdouble format for the wasm32 target
(cross-builds).
3. Enables run for Emscripten/Pyodide wheels by setting the `if:`
condition to `true`.
4. Uses recursive submodules to ensure that vendored-meson is received.
5. Moves the Meson cross file to `tools/ci/emscripten/` (i.e., creates a
separate Emscripten folder to store relevant files)
6. Adds a patch for vendored-meson detection for Pyodide and applies
this Pyodide-meson patch in the Emscripten CI jobs
7. Builds wasm32 wheels without BLAS and LAPACK support (see
numpy#24750 (comment))
8. Forces coloured and prettified outputs for test runs
Some of these changes have been copied with updates and suggestions
received from numpy#24603 on 23/02/2024 and authorship is preserved with this
commit.
[skip cirrus] [skip circle] [skip azp]
Co-Authored-By: Ralf Gommers <ralf.gommers@gmail.com>
Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
agriyakhetarpal pushed a commit to agriyakhetarpal/scikit-image that referenced this pull request Mar 18, 2024
lagru added a commit to scikit-image/scikit-image that referenced this pull request Jun 10, 2024
* Test emscripten workflow inspired by NumPy
Adds a CI job to build and test scikit-image in a Pyodide virtual
environment through WASM wheels. Following this, it would be
possible to include JupyterLite notebooks in the
documentation in order to run scikit-image's code snippets
which come with docstring-based examples.
Initial inspiration was taken from
numpy/numpy#24603.
Co-authored-by: Lars Grüter <lagru@mailbox.org>
Co-authored-by: Stefan van der Walt <45071+stefanv@users.noreply.github.com>
Sign up for freeto 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.

5 participants

@rgommers@hoodmane@rth@ryanking13@agriyakhetarpal