-
Notifications
You must be signed in to change notification settings - Fork 478
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
Support compiling on wasm targets #1068
Conversation
Wait... These configs are for the host machine - why are you compiling Anyhow, I'd rather suggest that you fix the dependencies of |
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.
(Deleted)
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.
(Sorry I'm bit sleepy today.)
Is cc-rs used in the build-script?
If so then it would be build for your host OS instead of wasm.
Yeah that's a great suggestion, and it is fixed in the latest version of solana-sdk as you noticed. The problem was originally caused by that dependency not being cfg-guarded in older versions. Unfortunately, those older versions are often still in use and will always need a patch. It's very easy for library authors to not cfg-guard their deps with wasm exclusions (or even realize they should) or to include a dependency that fails to do so. So if another dependency of a dependency makes the same mistake (not cfg-guarding cc) even after such a fix, we'll wind up with the same problem in the future, and once again need to fork/patch. So that's my train of thought here. I'd also suggest that perhaps the compile error being thrown may not be particularly useful for the wasm platform target in practice. |
@jozanza cc is used as a build-dep right? If it is a build-dep, then I can't imagine it causing your wasm build to fail, because your host OS is still unix/windows. Is cc used as a normal dependency in your crate? |
You're right @NobodyXu. The issue is it's not my crate that directly uses cc. If it was, using build-deps or cfg-guarding would work just fine. In my situation, cc is deep in the dependency tree, so I can't control these things by any other means than patching. |
Could you do a I wonder what is their use case for this, if it's a valid use case (not a mistake) I'm willing to merge this PR. Usually nobody uses cc on wasm, because wasm does not support spawning any process, which means you can't really use cc to compile anything on wasm. |
cc @jozanza sorry for the delay, I now think it makes sense to accept this PR, just a minor question. |
Oh great to hear @NobodyXu! What's the question? |
There's a comment on the command_helper, just a minor one |
Can you also update CI to run Thanks |
Thanks, I've opened #1160 which runs the wasm in CI |
* Don't throw compiler error for wasm targets * Don't throw compiler error for wasm targets * Fix attr syntax error * Add unimplemented path for pipe error match for wasm target * Replace `unimplemented!` with `panic!` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add CI check for wasm Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix CI Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix clippy warning on wasm Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> --------- Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> Co-authored-by: Josiah Savary <hello@jsavary.com>
Awesome! Thanks @NobodyXu |
In this PR, I added
target_family = "wasm"
to thecompile_error!
exceptions list in a few modules.For more context, in a wasm game engine SDK I maintain (
turbo
), I'm pulling in a crate (solana-sdk
). However,cc-rs
is deeply buried in dependencies of dependencies of that crate. This wouldn't be a terrible problem sincecc-rs
(especially the parallel feature stuff) is far from any code path that runs in wasm and optimization can get rid of a unused code, however, thecompile_error!
macro preventscc-rs
prevents builds from ever completing in the first place.So the only option in my case (where
cc-rs
is buried deep in the dependency tree and I'm targeting wasm) currently is to fork and patch. This gets brittle fairly quickly since other dependencies can have version conflicts and force me to create more branches with version bumps and other minor tweaks over time.I'm hoping we can land this patch and carve out exceptions for wasm with
compile_error!
moving forward 🙏🏽