Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI tests for wasm32-emscripten wheels in Pyodide #244

Merged
merged 4 commits into from
Aug 7, 2022

Conversation

hoodmane
Copy link
Contributor

This is another attempt to add emscripten tests. We generate wheels "by hand" and then test them in Pyodide. This approach could benefit from improvements to Pyodide, it's currently a bit ad-hoc. Would still appreciate review.

The tests work for html-py-ever, namespace_package, and rust_with_cffi, but I couldn't get hello-world to build so I am not testing it.

@hoodmane hoodmane marked this pull request as draft June 14, 2022 01:30
@hoodmane
Copy link
Contributor Author

I'm keeping this as a draft because IMO it needs some improvements before it can merge but I would still appreciate feedback if you get around to it. @messense @davidhewitt

noxfile.py Outdated Show resolved Hide resolved
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks for working on this and sorry for the long delay in review. Been busy either side of falling ill.

Looks solid to me, really cool to see this working. There appears to be a rust_with_cffi failure when trying to build cffi, maybe it makes sense to skip that one for now?

CARGO_TARGET_WASM32_UNKNOWN_EMSCRIPTEN_LINKER=str(
emscripten_dir / "emcc_wrapper.py"
),
PYO3_CONFIG_FILE=str(emscripten_dir / "pyo3_config.ini"),
Copy link
Member

Choose a reason for hiding this comment

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

From this should I infer that pyo3_build_config doesn't configure for pyodide correctly? Do you think we would be able to upstream a fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From this should I infer that pyo3_build_config doesn't configure for pyodide correctly?

I am not sure. I think it may just be that I don't know how to use the tool correctly. How would I check this?

Copy link
Member

Choose a reason for hiding this comment

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

So usually in cross-compile situations like for emscripten the pyo3_build_config build scripts will try to look for a sysconfigdata file and configure from that. Alternatively, can set the abi3-py310 feature and then it will do a "standard" cross compile, which might just work.

I view the PYO3_CONFIG_FILE env var as an escape hatch when nothing built-in works, so if either of the above work (or can be made to work) that's probably preferable.

noxfile.py Outdated
emscripten_dir / "emcc_wrapper.py"
),
PYO3_CONFIG_FILE=str(emscripten_dir / "pyo3_config.ini"),
RUSTFLAGS=" ".join(
Copy link
Member

Choose a reason for hiding this comment

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

It might be worth having a .cargo/config.toml with a [target.wasm32-unknown-emscripten] section for these? Or alternatively setuptools-rust could set them automatically internally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well we are working on upstreaming this stuff:
https://github.com/rust-lang/rust/pulls?q=author%3Ahoodmane
I don't know what the best thing to do before the upstream fixes go in. Unfortunately it looks like the merge window for Rust 1.63.0 is closing today. The fixes will probably go into into 1.64.0.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, very nice. I think it's ok for us to keep this as-is for now then; if things will eventually "just work" on a new enough rustc I think that's good enough for now.

setuptools_rust/build.py Outdated Show resolved Hide resolved
emscripten/pyconfig.h Outdated Show resolved Hide resolved
@hoodmane
Copy link
Contributor Author

This can be simplified quite a lot now similar to this PR on maturin:
https://github.com/PyO3/maturin/pull/983/files

@hoodmane hoodmane marked this pull request as ready for review June 25, 2022 00:41
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Looks really tidy! Think I've spotted why the new test failure...

@@ -3,6 +3,7 @@ on:
push:
branches:
- main
- emscripten-ci2
Copy link
Member

Choose a reason for hiding this comment

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

Reminder to remove this when ready to merge.

noxfile.py Outdated
_PYTHON_SYSCONFIGDATA_NAME="_sysconfigdata__emscripten_wasm32-emscripten",
_PYTHON_HOST_PLATFORM="emscripten_3_1_14_wasm32",
CARGO_BUILD_TARGET="wasm32-unknown-emscripten",
CARGO_UNSTABLE_BUILD_STD="true",
Copy link
Member

Choose a reason for hiding this comment

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

Looking at the CI failure and docs for build-std I think this actually might want to be CARGO_UNSTABLE_BUILD_STD="core,alloc,std,proc_macro,test". Or presumably we can drop this soon-ish when your upstream Rust PRs merge.

@davidhewitt
Copy link
Member

Rebased this and removed some of the tweaks which I think are now covered by upstream rustc; let's see if we can get this merged.

@davidhewitt
Copy link
Member

Hmm, emscripten failing with missing symbols. @hoodmane do you know if there's a flag for allowing the undefined symbols through (presumably they are provided by Pyodide at runtime), similar to -undefined dynamic_lookup which we have to use on macOS?

@hoodmane
Copy link
Contributor Author

hoodmane commented Aug 2, 2022

I suspect it didn't see -sSIDE_MODULE=2 for some reason.

@davidhewitt
Copy link
Member

Ah in which case I removed too many RUSTFLAGS - thanks 👍

@hoodmane
Copy link
Contributor Author

hoodmane commented Aug 2, 2022

Yeah I think -sWASM_BIGINT had better stay too.

.github/workflows/ci.yml Outdated Show resolved Hide resolved
@davidhewitt
Copy link
Member

Finally working!

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks for upgrading the version @messense!

Copy link
Member

@messense messense left a comment

Choose a reason for hiding this comment

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

👍

@messense messense merged commit b244fe7 into PyO3:main Aug 7, 2022
@hoodmane
Copy link
Contributor Author

hoodmane commented Aug 7, 2022

Thanks @messense and @davidhewitt!

@davidhewitt
Copy link
Member

Cheers, appreciate you kicking this off for us, I've got a much better idea how we do (pyodide) support now going forward 👍

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

Successfully merging this pull request may close these issues.

3 participants