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

Compilation failure under rust nightly webassembly target #1132

Closed
smarter opened this issue Dec 20, 2017 · 9 comments
Closed

Compilation failure under rust nightly webassembly target #1132

smarter opened this issue Dec 20, 2017 · 9 comments
Labels
C-enhancement Category: Raise on the bar on expectations E-easy Call for participation: Experience needed to fix: Easy / not much E-medium Call for participation: Experience needed to fix: Medium / intermediate

Comments

@smarter
Copy link

smarter commented Dec 20, 2017

Rust Version

  • rustc 1.24.0-nightly (dc39c3169 2017-12-17)

Affected Version of clap

  • 2.29.0

Rust now has a webassembly target, trying to use it in a project that depends on clap results in a build failure:

     Running `rustc --crate-name clap /home/smarter/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-2.29.0/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="ansi_term"' --cfg 'feature="atty"' --cfg 'feature="color"' --cfg 'feature="default"' --cfg 'feature="strsim"' --cfg 'feature="suggestions"' --cfg 'feature="vec_map"' -C metadata=65f4e6c3f5bc989d -C extra-filename=-65f4e6c3f5bc989d --out-dir /home/smarter/opt/rav1e/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -L dependency=/home/smarter/opt/rav1e/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/smarter/opt/rav1e/target/debug/deps --extern unicode_width=/home/smarter/opt/rav1e/target/wasm32-unknown-unknown/debug/deps/libunicode_width-d8e4ab5b3b6e196a.rlib --extern bitflags=/home/smarter/opt/rav1e/target/wasm32-unknown-unknown/debug/deps/libbitflags-6b084702002cf111.rlib --extern ansi_term=/home/smarter/opt/rav1e/target/wasm32-unknown-unknown/debug/deps/libansi_term-ac6664a6dc50e79a.rlib --extern vec_map=/home/smarter/opt/rav1e/target/wasm32-unknown-unknown/debug/deps/libvec_map-c395abf84ff3b365.rlib --extern textwrap=/home/smarter/opt/rav1e/target/wasm32-unknown-unknown/debug/deps/libtextwrap-216ed0ff2756cb7b.rlib --extern atty=/home/smarter/opt/rav1e/target/wasm32-unknown-unknown/debug/deps/libatty-ee3084e679e50df7.rlib --extern strsim=/home/smarter/opt/rav1e/target/wasm32-unknown-unknown/debug/deps/libstrsim-64624fb788d914f4.rlib --cap-lints allow`
error[E0433]: failed to resolve. Could not find `unix` in `os`
   --> /home/smarter/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-2.29.0/src/app/parser.rs:662:26
    |
662 |             use std::os::unix::ffi::OsStrExt;
    |                          ^^^^ Could not find `unix` in `os`

error[E0433]: failed to resolve. Could not find `unix` in `os`
 --> /home/smarter/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-2.29.0/src/args/arg.rs:8:14
  |
8 | use std::os::unix::ffi::OsStrExt;
  |              ^^^^ Could not find `unix` in `os`

...

It might be impossible to actually use clap for anything with the wasm backend right now, but it would be nice if it still managed to build.

@kbknapp
Copy link
Member

kbknapp commented Jan 9, 2018

I agree. I haven't really put any thought into wasm because I can't imagine parsing arguments in the browser, but you're right it'd be nice if it still builds.

This would probably be an easy fix, and if anyone wants to add a non-default cargo feature wasm and do the fixes I'd be happy to mentor it.

@kbknapp kbknapp added C-enhancement Category: Raise on the bar on expectations P4: nice to have E-medium Call for participation: Experience needed to fix: Medium / intermediate E-easy Call for participation: Experience needed to fix: Easy / not much labels Jan 9, 2018
@rtsao
Copy link

rtsao commented Jan 10, 2018

I think the clap use case for the wasm target would be consuming it from Node.js. I guess in theory you could build a CLI entirely in Rust then ship it to npm.

@stevepentland
Copy link

@kbknapp I'm interested in taking this one on if no one else has started

@kbknapp
Copy link
Member

kbknapp commented Feb 11, 2018

That would be great! Thanks @stevepentland

@stevepentland
Copy link

@kbknapp I need to ask about what you meant with a non-default wasm cargo feature? I've been looking through the code at how to reconcile the changes and could use a little insight from you.

@kbknapp
Copy link
Member

kbknapp commented Feb 11, 2018

By non-default I just meant a cargo feature that it's not included in the default features array (and thus opt-in instead of opt-out). However, I now think there are better ways to solve this.

A better solution would be to add some additional OsStrExt traits inside src/osstringext.rs following the OsStrExt3 example for Windows, since Windows is essentially the same problem as wasm.

Actually...now that I think about it, maybe just reusing the OsStrExt3 that Windows uses would work too? That just require changing the cfg statements...hmm I'd try that out first.

So in order of things I'd try:

  • Reusing the OsStrExt3 for Windows and wasn't
  • Adding a new trait just like OsStrExt3 but for was specifically

@stevepentland
Copy link

Alright sounds good, I’ll start there and see how it goes. Thanks!

This was referenced Feb 19, 2018
@kbknapp
Copy link
Member

kbknapp commented Feb 23, 2018

Closed with #1190 thanks to @stevepentland 🎉

@kbknapp kbknapp closed this as completed Feb 23, 2018
@jamesray1
Copy link

jamesray1 commented May 5, 2018

Getting this error with Drops-of-Diamond/diamond_drops#59 with Clap 2.31.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Raise on the bar on expectations E-easy Call for participation: Experience needed to fix: Easy / not much E-medium Call for participation: Experience needed to fix: Medium / intermediate
Projects
None yet
Development

No branches or pull requests

5 participants