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

[WIP] Use --message-format=json to fix #333 #340

Closed
wants to merge 1 commit into from

Conversation

konstin
Copy link
Contributor

@konstin konstin commented Sep 23, 2018

Parse the --message-format=json output with cargo_metadata to get the location of the wasm file from cargo.

This PR is marked WIP because it depends on oli-obk/cargo_metadata#53. 7484faf is because I otherwise had test failures about wrong versions (same as for @alexcrichton in #336 (comment)). With that commit it_can_run_browser_tests is still failing though. I guess this will be fixed before merging and I can rebase the commit away.

Adding wasm_file to Build is a bit of an ugly solution, but I couldn't come up with something better without rewriting the whole steps code. Currently I'm also ignoring the diagnostics messages and instead return the captured stderr in case of an error. (Not capturing stderr and setting -q would fix #288 and with the other messages we could easily do #287. We'd only need to make sure how this interacts with indicatif)

Make sure these boxes are checked! 📦✅

  • You have the latest version of rustfmt installed and have your
    cloned directory set to nightly (well, 2018-09-16)
  • You ran rustfmt on the code base before submitting
  • You reference which issue is being closed in the PR text

Closes #333
Fixes #305
Relevant for #339

✨✨ 😄 Thanks so much for contributing to wasm-pack! 😄 ✨✨

@ashleygwilliams ashleygwilliams added the work in progress do not merge! label Sep 23, 2018
src/build.rs Outdated
.arg("--lib")
.arg("--target=wasm32-unknown-unknown")
.arg("--message-format=json")
.stderr(Stdio::piped())
Copy link
Contributor

Choose a reason for hiding this comment

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

For this I believe it will need to pessimistically spawn a new thread to read stderr. Othrewise the blocking reads on stdout could cause wasm-pack to deadlock when it's waiting for info on stdout but the child is waiting to write info to stderr.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Afaik we're spawning a new process here and stderr is new pipe from the os, so the child can write to stderr no matter what the parent process does (except broken pipe errors and the like). Not an expert though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Pipes have a fixed capacity, however, and won't infinitely buffer. If Cargo dumps a lot of information on stderr it'll eventually block, and then it won't make progress until the pipe is read, which wasm-pack doesn't do until the process has otherwise finished.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah thanks, I didn't think about that! I've replaced the pipe with a tempfile.

@konstin konstin force-pushed the master branch 2 times, most recently from 0bd1dc7 to cc38989 Compare September 27, 2018 10:01
@konstin
Copy link
Contributor Author

konstin commented Sep 27, 2018

I've rebased onto master. I've realized that rustc and therefore cargo can't do both human and json messages at the same time, so we need to get the human messages out of the json.

Because both PBAR and Logger errors aren't shown to the user, I simply eprintln'd the compiler messages. This also means the user is now shown the warning even if the compilation succeeds.

  [1/9] Checking `rustc` version...
  [2/9] Checking crate configuration...
  [3/9] Adding WASM target...
| [4/9] Compiling to WASM...
error[E0425]: cannot find function `fail` in this scope
 --> src/lib.rs:6:5
  |
6 |     fail();
  |     ^^^^ not found in this scope


warning: unused import: `std::ptr`
 --> src/lib.rs:1:5
  |
1 | use std::ptr;
  |     ^^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

\ [4/9] Compiling to WASM...
warning: unused import: `std::mem::replace`
 --> src/lib.rs:2:5
  |
2 | use std::mem::replace;
  |     ^^^^^^^^^^^^^^^^^


error: aborting due to previous error


For more information about this error, try `rustc --explain E0425`.

Compilation of your program failed. stderr:

   Compiling a v0.1.0 (/home/konsti/wasm-pack/a)
error: Could not compile `a`.

To learn more, run the command again with --verbose.

@konstin
Copy link
Contributor Author

konstin commented Oct 10, 2018

This was made impossible by #392.

@konstin konstin closed this Oct 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
work in progress do not merge!
Projects
None yet
3 participants