-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
fix(rust): fix build for wasm #9502
Conversation
@ritchie46 would you review this change? Build failures are unrelated (probably just need to rebase) |
polars/polars-io/src/utils.rs
Outdated
pub fn resolve_homedir(path: &Path) -> PathBuf { | ||
// replace "~" with home directory | ||
if path.starts_with("~") { | ||
if let Some(homedir) = home_dir() { | ||
// home crate does not compile on wasm https://github.com/rust-lang/cargo/issues/12297 | ||
#[cfg(not(target_arch = "wasm32"))] | ||
if let Some(homedir) = home::home_dir() { | ||
return homedir.join(path.strip_prefix("~").unwrap()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is probably fine if we are just concerned with compiling, but since WASM doesn't have a filesystem, i'm wondering if resolve_homedir
should be feature flagged instead? Likely anything that calls resolve_homedir
will panic on wasm32
anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With WASI it could make sense for wasm to have a file system, and even a home dir. And generally this function can be used with paths that don't need homedir at all.
Seeing as it's likely the upstream will make this compile and return None on wasm rust-lang/cargo#12297, my proposed change will match that behavior and be safe to remove without consequences on behavior. This is also a reason not to add a feature flag. Ultimately that means we will fix the regression without changing behavior.
@ritchie46 — would you please review this? I'm stuck on 0.28 because the build has been broken for wasm. |
.github/workflows/test-rust.yml
Outdated
- name: Wasm | ||
target: wasm32-unknown-unknown | ||
features: > | ||
-F abs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that familiar with this. What does -F mean in this context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is used further down on line 226 — it specifies a feature:
cargo build --target ${{ matrix.target }} -p polars --no-default-features ${{ matrix.features }}
polars/polars-utils/src/wasm.rs
Outdated
@@ -5,6 +5,14 @@ impl Pool { | |||
rayon::current_num_threads() | |||
} | |||
|
|||
pub fn current_thread_index(&self) -> Option<usize> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this was necessary to build on wasm.
For context, crate::POOL
is configured to a custom struct when building on wasm rather than the corresponding lazily-built rayon::ThreadPool
.
In particular, this method is used in polars-core/src/frame/groupby/hashing.rs
and polars-core/src/series/implementations/struct_.rs
.
Just rebased, no manual changes were necessary. @ritchie46 please take another look! Would like to fix the regression from 0.28. |
rebased to deal with conflict from #10279 in |
Fixes issue #8783, where v0.29 broke the build for wasm. In addition to fixing the build, this adds a CI test to prevent regressions like this in the future. Relatedly there's an issue for the `home` crate rust-lang/cargo#12297 to make it compile for wasm. The previously used crate there, `dirs`, _does_ support wasm (just returning None for the home dir).
Rebased again — @orlp perhaps you can review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems reasonable to me.
only suggestion I have is maybe moving the ci stuff to the Makefile so it is easier to build outside of CI as well.
Thanks! It appears the Makefile is only used for working in py-polars, but the relevant libraries are part of the rust crates. I'm happy to put the ci stuff in a more appropriate place — I think the next best place to list out the features would be in |
There is another Makefile in the On another note, is there no other solution than to manually specify an entire list of feature flags? That's rather brittle and needs maintaining forever. |
There are a few other ways that come to mind:
I haven't looked into the difficulty of the first choice. The second choice risks regressions when other features lose support, and is hence tied to a judgement call I'd rather not make. I don't know of solutions for the third choice, though it seems technically solvable with the limited scope of cargo features across targets. And just pushed the change for the Makefile. |
Actually, another option is to have a list of excludes — features that are not supported on wasm. That list would be smaller and more precisely capture where the problems exist. I'll try making that change now. |
Nice, it looks much better. In case you're curious, most of the build failures are coming from |
I can submit a small PR after this which will fix many of the |
@ritchie46 looks like this is ready to go — could you merge? |
That's a lot of excludes, but the solution to that isn't part of this pull request. Would love pull requests to reduce the amount of WASM-incompatible features. |
@lorepozo I am reverting this because it broke our CI. You can view the error log here: https://github.com/pola-rs/polars/actions/runs/5880942481/job/15948348046?pr=10388. Could you make a new pull request, and test it first in CI on a fork? |
It was tested correctly in CI via this PR, looks like a merge race because of #10492 breaking the |
Fixes issue #8783, where v0.29 broke the build for wasm. In addition to fixing the build, this adds a CI test to prevent regressions like this in the future. I've gone ahead and added every feature that works with wasm (not all features work out of the box and adding support for those can be done in the future as needed).
Relatedly there's an issue for the
home
crate rust-lang/cargo#12297 to make it compile for wasm.