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

Add rustc --run #9826

Closed
SiegeLord opened this issue Oct 12, 2013 · 22 comments
Closed

Add rustc --run #9826

SiegeLord opened this issue Oct 12, 2013 · 22 comments
Labels

Comments

@SiegeLord
Copy link
Contributor

@SiegeLord SiegeLord commented Oct 12, 2013

With the removal of the rust tool, there is nothing good to place in the initial hashbang comment in a Rust file (you used to be put rust run in there). rustc --run should be added to fill that gap.

The use case, of course, is some kind support for script-like usage for Rust which will become attractive when the compilation speed improves.

@thestinger
Copy link
Contributor

@thestinger thestinger commented Oct 26, 2013

Also useful would be rustc --test and rustc --bench.

@mletterle
Copy link
Contributor

@mletterle mletterle commented Oct 26, 2013

Is adding all the old rust functionality to rustc really a good idea? Why not have rust resurrected as a separate project?

@thestinger
Copy link
Contributor

@thestinger thestinger commented Oct 26, 2013

I don't think we should have more than one official tool for the same functionality. Either we should commit to moving everything we have now behind a rust command or implement useful functionality for the existing commands.

@SiegeLord
Copy link
Contributor Author

@SiegeLord SiegeLord commented Oct 26, 2013

I was thinking that --run would be composable with other arguments. Since rustc --test already exists, the usage for testing/benchmarking would look like this:

rustc --test --run
rustc --test --run --bench

In the latter case --bench is passed to the test executable (I.e. I'm thinking that all arguments after --run get passed to the executable). Alternatively, --bench could be introduced to rustc and it'd look like this:

rustc --bench --run
@RSully
Copy link

@RSully RSully commented Apr 30, 2014

Has there been any updates for the compile+execute functionality? Similar to go run?

@japaric
Copy link
Member

@japaric japaric commented Jun 17, 2014

I got a minimal working implementation here. Feedback welcome.

N.B. I decided to wrap rustc rather than modify it, because that seemed like the fastest way to get a working prototype.

@Ape
Copy link

@Ape Ape commented Jun 18, 2014

I think we should store the compiled binaries to boost the performance. That way it could easily replace small Python scripts and actually be faster to execute.

When running a rust script (with rustic shebang) called hello.rs, it would check if hello.rsc exists and is modified after hello.rs. If so, it would just execute the binary. Otherwise it would compile, store the binary and then run it.

I would like to see this behaviour merged to the main project.

@thestinger
Copy link
Contributor

@thestinger thestinger commented Jun 18, 2014

It's not that simple. It would need to verify that none of the modules or crates it depends on changed, along with making sure rustc itself wasn't updated.

@steveklabnik
Copy link
Member

@steveklabnik steveklabnik commented Aug 23, 2014

cargo run serves this purpose.

@SiegeLord
Copy link
Contributor Author

@SiegeLord SiegeLord commented Aug 23, 2014

No, it does not (at least not in its current incarnation). The purpose of rustc --run is to be placed in the hashbang comment. cargo run, on the other hand, currently requires a specific directory structure and Cargo.toml that does not appear to work for this purpose.

@Binero
Copy link
Contributor

@Binero Binero commented Sep 4, 2014

I do agree the rust compiler should be able to run rust code.

@japaric
Copy link
Member

@japaric japaric commented Oct 14, 2014

This issue is a feature request, and needs an approved RFC to be implemented. It should be moved to the rust-lang/rfcs repo. (As per the issues policy)

cc @nick29581

@nrc
Copy link
Member

@nrc nrc commented Oct 14, 2014

I don't think compiler features (cf language features) need an RFC unless they are very far reaching. Leaving here for now.

@steveklabnik
Copy link
Member

@steveklabnik steveklabnik commented Feb 2, 2016

Triage: no comments in a long time. https://github.com/DanielKeep/cargo-script can be used in a shebang line, and includes Cargo stuff as well.

@aalexgabi
Copy link

@aalexgabi aalexgabi commented Feb 10, 2017

Tried cargo run 😞 but it seems that you need Cargo.toml file:

[root@arch-anywhere:~]# cargo run main.rs                                                                       (02-10 13:49)
error: could not find `Cargo.toml` in `/root` or any parent directory

I agree there should be some kind of command that abstracts away the compilation part. I'm not sure this has something to do with cargo. Maybe adding a rust command:

$ rust main.rs
Hi man!
$ 

By also adding a shebang:

#!/usr/bin/env rust

fn main() {
  println("Hi man!")
}

We can execute by simply:

$ chmod +x main.rs
$ ./main.rs

This allows distributing via compiled binaries via rustc main.rs and running in one step.

cargo-script is ok but is not installed by default. I'm not sure that the all the verbosity is needed:

[root@arch-anywhere:~][127]# cargo script main.rs                                                               (02-10 13:58)
   Compiling main v0.1.0 (file:///root/.cargo/script-cache/file-main-fa4ca44a3cefa0f6)
    Finished release [optimized] target(s) in 0.24 secs
Hi man!
@steveklabnik
Copy link
Member

@steveklabnik steveklabnik commented Mar 23, 2017

I am going to give this one a close, as cargo script fills in this gap. Including it with cargo by default would be RFC-worthy.

@bronson
Copy link

@bronson bronson commented Mar 24, 2017

Leaves the rustc --test and rustc --bench gaps unfilled though. :)

@aalexgabi
Copy link

@aalexgabi aalexgabi commented Mar 24, 2017

@steveklabnik As pointed earlier cargo script is not installed by default.

@frewsxcv
Copy link
Member

@frewsxcv frewsxcv commented Oct 28, 2018

With the removal of the rust tool

For the sake of posterity and documenting some history, here's where the rust command was added:

and here's where the rust command was removed:

@dangdennis
Copy link

@dangdennis dangdennis commented Mar 9, 2019

For those wondering what Steve refers to as cargo script.
https://github.com/DanielKeep/cargo-script

@igor-petruk
Copy link

@igor-petruk igor-petruk commented Nov 3, 2019

As for now, it is not clear if cargo script is maintained. I have written a language agnostic tool, in case anyone needs it. Works well for Rust too, including building static binaries in Docker and extracting them to host

https://github.com/igor-petruk/scriptisto

@metaspook
Copy link

@metaspook metaspook commented Jun 29, 2020

Tried cargo run 😞 but it seems that you need Cargo.toml file:

[root@arch-anywhere:~]# cargo run main.rs                                                                       (02-10 13:49)
error: could not find `Cargo.toml` in `/root` or any parent directory

I agree there should be some kind of command that abstracts away the compilation part. I'm not sure this has something to do with cargo. Maybe adding a rust command:

$ rust main.rs
Hi man!
$ 

By also adding a shebang:

#!/usr/bin/env rust

fn main() {
  println("Hi man!")
}

We can execute by simply:

$ chmod +x main.rs
$ ./main.rs

This allows distributing via compiled binaries via rustc main.rs and running in one step.

cargo-script is ok but is not installed by default. I'm not sure that the all the verbosity is needed:

[root@arch-anywhere:~][127]# cargo script main.rs                                                               (02-10 13:58)
   Compiling main v0.1.0 (file:///root/.cargo/script-cache/file-main-fa4ca44a3cefa0f6)
    Finished release [optimized] target(s) in 0.24 secs
Hi man!

This is a great idea I love it will they implement it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.