-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Cargo should use Node.js to launch targets built for asmjs #3626
Comments
Cargo doesn't currently have any knowledge of targets, it just assumes that if you request @brson do you have thoughts about whether Cargo should special case here? |
(I'm tempted to say that this error is expected and we should rely on users to run node manually) |
Just note it should use "nodejs" on debian like systems, to conform with http://lists.debian.org/debian-devel-announce/2012/07/msg00002.html (TLDR: official package for node.js is called |
Actually, now that I think about it I'm more inclined to agree with Alex. The problem space is a little more complex than just simply running Node.js; in fact I've wrote my own Cargo subcommand for this very use case. In the vast majority of cases when someone compiles something to asm.js/webasm he/she does that to run it in a web browser on the client-side (because otherwise why aren't you simply building a native binary?); running that in Node.js is not ideal since Node.js (obviously) doesn't support most Web APIs. What you actually would want to do here is to either start an embedded web server and allow the user to access it with his/her web browser ( So, yes, we probably shouldn't add a special case for running the build results through Node.js, but on the other hand a |
@koute yeah I'd be totally up for improving error messages here in any case. We could detect cross compiles and then detect an error to execute and then print out a message saying that this likely wasn't going to work in the first place (or something along those lines) |
This could be really useful for running tests though, as output names are not very predictable. How about, instead of specializing for Emscripten, provide generic argument like |
@RReverser heh there's actually a surprising number of related proposals currently in flight as well. For example I think #3866 would help with that? Some other references: #3670, #1763, #1924. Right now the sort of "conventional" way to do this (albeit not an easy way) would be to:
|
Sure, but such conventional way can't be exactly called convenient :) Especially when just running commands yourself from console, without involving yet another build wrapper around cargo like Make :) These proposals indeed sound relevant. Is there a plan to merge it yet? Looks like they're all postponed or just in discussion phase, would love to track in some centralized place. |
Yeah there's currently not a huge driving force on these unfortunately. Re-reviewing though some of it's been lack of motivation and/or not the strongest of use cases. Looking back I'm sort of tempted to just add
That would enable use cases like: # debug a test
cargo test --with gdb --test foo
# run all tests on node
cargo test --with node --target asmjs-unknown-emscripten
# run a binary with strace
cargo run --with strace
# Print the arguments/env vars without actually running anything
cargo run --with my-custom-tool @RReverser would you be up for spearheading discussion here and helping to drive this forward? |
Sounds great! Few questions:
|
Oh right yeah this'd be accepted anywhere it made sense. For arguments we could add something like For discussion basically just leading the charge on determining questions like you brough up, working to reach a consensus on what the answer should be, and then (optionally) implementing and/or just making sure it's written down for the next person! |
Yeah, I'm happy to help with this - can't guarantee spending much time, but answering questions and implementing should be pretty straightforward. |
ok, I'll cc some others who may be interested -- @matklad @brson @wycats @carols10cents |
Looks like the end effect would be almost the same as in #3887, but for the resulting binaries instead of compiler. I wonder if these two use cases should share similar interface. For example, with |
That's not something we've needed yet since sccache takes all of its configuration from environment variables currently, but I could see it being useful in the future. I am planning on implementing config file support for sccache, so it might be nice to be able to pass Related to the issue at hand: for Firefox test harnesses we added |
@matklad yeah it's definitely similar, but I'd be wary of creating an abstraction that may not be too useful in the end, do we have a use case for wrapping literally everything Cargo spawns (rustc and binaries alike)? (is that IntelliJ's use case?) |
No definitely not.
Yeah, I'm saying that we should keep the other use case in mind and, for example, use similar named configuration option name. |
Duplicate of #1411. Which asks for |
@est31 If you're referring to the current discussion, this doesn't matter at all, as Cargo won't be searching for Node.js executable, just using what user explicitly configured to run this target with. For some users, Also, when you install emsdk, it provides its own |
@jan-hudec I like that proposal, |
@jan-hudec Made an initial PR in #3954 (the only difference with your proposal is that I chose |
When `target.$triple.runner` is specified, it will be used for any execution commands by cargo including `cargo run`, `cargo test` and `cargo bench`. The original file is passed to the runner executable as a first argument. This allows to run tests when cross-comping Rust projects. This is not a complete solution, and might be extended in future for better ergonomics to support passing extra arguments to the runner itself or overriding runner from command line, but it should already unlock major existing usecases. Fixes rust-lang#1411 Resolves rust-lang#3626
Add support for custom target-specific runners When `target.$triple.runner` is specified, it will be used for any execution commands by cargo including `cargo run`, `cargo test` and `cargo bench`. The original file is passed to the runner executable as a first argument. This allows to run tests when cross-comping Rust projects. This is not a complete solution and might be extended in future for better ergonomics to support passing extra arguments to the runner itself or overriding runner from the command line, but it should already unlock major existing use cases. Fixes #1411 Resolves #3626
Add support for custom target-specific runners When `target.$triple.runner` is specified, it will be used for any execution commands by cargo including `cargo run`, `cargo test` and `cargo bench`. The original file is passed to the runner executable as a first argument. This allows to run tests when cross-comping Rust projects. This is not a complete solution and might be extended in future for better ergonomics to support passing extra arguments to the runner itself or overriding runner from the command line, but it should already unlock major existing use cases. Fixes #1411 Resolves #3626
Currently when doing
cargo run --target=asmjs-unknown-emscripten
orcargo test --target=asmjs-unknown-emscripten
you get the following error:While the asmjs backend is mostly meant to be used on the Web it would be quite useful to have the targets compiled for the asmjs to be launched through Node.js, if nothing else for running tests.
There is, of course, a partial workaround for Linux where you could technically do this:
and the OS would take care of launching the files through Node.js; this, however, doesn't work currently as Cargo doesn't set the executable bits on the
.js
files it produces.The text was updated successfully, but these errors were encountered: