Change:
use std::env; use std::ffi::OsString; use std::fmt; <del> use std::fs::{self, File}; use std::io::{self, Write, BufWriter}; </del> <ins> use std::fs; use std::io; </ins> use std::path::{Path, PathBuf}; use std::process::{Output, Stdio}; use std::str;

Discussion:
Hello. I have been trying to compile a rather big project for wasm32-unknown-emscripten using cargo on Windows. Unfortunately, the linking process fails when trying to run because the command line invoked is too long for Windows' limitations (about 8k characters). After manually counting, the command indeed is too big with in my case about 11k characters, as it includes the absolute path of every single .o and .rlib files. My project, while including piston as a dependency, does not have an incredibly large amount of them, which makes me believe this could be an important issue in the long run (this does not apply to Linux however as the maximum character limit usually is much higher). After a little bit of digging, emscripten seems to provide a workaround for this problem by accepting parameters from files. However it has to be handled by the user. Thanks in advance for your help.
why not use a folder like c:a so that it works?
Well yes, that would work in my specific case. But do you really want that in a final product?
Maybe is related.
can you provide the full error message? It looks like this may be a bug in emscripten, not in rustc.
I uploaded the project I tried to compile to this repo contains the entire output edit: i'm adding the verbose output too edit: done
Ah ok thanks for the extra info So for a bit of background, rustc does indeed have for reinvoking the linker if necessary when the command line is deemed too large. What's happening here, though, is that the error is happening at the wrong time. The current detection relies on the spawning of the process itself to fail (aka the OS tells us about the failure) but it looks like at least is succeeding. Some spawned process actually prints out but it's not clear to me whether that's or .
Is there any additional test you'd want me to run to try to figure this out?
If you'd like to debug further that'd be great. We'd first need to understand what's actually failing here ( or something in emscripten). Once that's known we could figure out if it's reasonable for us to catch the error and do something about it.
So I edited to print a dummy message when it gets called.

As the message did not show up, I came to the conclusion that cmd itself refuses to run the command. I tried to run it with a shorter command and the message showed up. This is surprising because that means rust would have failed to survive cmd's refusal. I'm not an OS expert so I'm not sure what rawoserror actually returns, but here cmd's return code is 1.
Ok so sounds like we successfully spawn a process and then fails to spawn its own subprocess. That's going to be much trickier to handle an catch, but it at least sounds like what's happening here at least.
A dirty way to catch it would be to simply check the error description. At least it is self explanatory so there won't be any false positive.
Another way I just thought of would be to try to summon without cmd, maybe trying to run it using something similar to C's . Maybe this would allow better handling.
Assuming and em++ are working in a similar matter, seems to provide a solution. We can simply write all the command parameters to an .rsp file, and then pass that file to the
Honestly, I believe doing this approach by default would be the best solution. The performance overhead is negligible when it's only about linking, and this would cover all future problems. It's simply a matter of deleting . I can not try it right now but if anyone is interested to remove it and see if it works.
Writing the arguments to file looks like a good solution here, yeah.
I'm running into this issue as well when trying to use the cargo-web crate. Any ETA on this being fixed in nightly?
If nobody does it before I do, I'll make file parameters default behavior, check if nothing breaks and make a pull request by Sunday.
I've posted a PR for this at