Add rustc --run #9826

Closed
SiegeLord opened this Issue Oct 12, 2013 · 18 comments

Comments

Projects
None yet
@SiegeLord
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@thestinger

thestinger Oct 26, 2013

Contributor

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

Contributor

thestinger commented Oct 26, 2013

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

@mletterle

This comment has been minimized.

Show comment
Hide comment
@mletterle

mletterle Oct 26, 2013

Contributor

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

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@thestinger

thestinger Oct 26, 2013

Contributor

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.

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@SiegeLord

SiegeLord Oct 26, 2013

Contributor

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
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@RSully

RSully Apr 30, 2014

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

RSully commented Apr 30, 2014

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

@japaric

This comment has been minimized.

Show comment
Hide comment
@japaric

japaric Jun 17, 2014

Member

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.

Member

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

This comment has been minimized.

Show comment
Hide comment
@Ape

Ape 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.

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

This comment has been minimized.

Show comment
Hide comment
@thestinger

thestinger Jun 18, 2014

Contributor

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.

Contributor

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.

@japaric japaric referenced this issue in rust-lang/rust-by-example Jul 3, 2014

Closed

New chapter about `rustc` flags #156

0 of 5 tasks complete
@steveklabnik

This comment has been minimized.

Show comment
Hide comment
@steveklabnik

steveklabnik Aug 23, 2014

Member

cargo run serves this purpose.

Member

steveklabnik commented Aug 23, 2014

cargo run serves this purpose.

@SiegeLord

This comment has been minimized.

Show comment
Hide comment
@SiegeLord

SiegeLord Aug 23, 2014

Contributor

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.

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@Binero

Binero Sep 4, 2014

Contributor

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

Contributor

Binero commented Sep 4, 2014

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

@japaric

This comment has been minimized.

Show comment
Hide comment
@japaric

japaric Oct 14, 2014

Member

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

Member

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

This comment has been minimized.

Show comment
Hide comment
@nrc

nrc Oct 14, 2014

Member

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

Member

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

This comment has been minimized.

Show comment
Hide comment
@steveklabnik

steveklabnik Feb 2, 2016

Member

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.

Member

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

This comment has been minimized.

Show comment
Hide comment
@aalexgabi

aalexgabi 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!

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

This comment has been minimized.

Show comment
Hide comment
@steveklabnik

steveklabnik Mar 23, 2017

Member

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.

Member

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

This comment has been minimized.

Show comment
Hide comment
@bronson

bronson Mar 24, 2017

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

bronson commented Mar 24, 2017

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

@aalexgabi

This comment has been minimized.

Show comment
Hide comment
@aalexgabi

aalexgabi Mar 24, 2017

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment