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 · 24 comments
Closed

Add rustc --run #9826

SiegeLord opened this issue Oct 12, 2013 · 24 comments
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@SiegeLord
Copy link
Contributor

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

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

@mletterle
Copy link
Contributor

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

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

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 commented Apr 30, 2014

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

@japaric
Copy link
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
Copy link

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

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

cargo run serves this purpose.

@SiegeLord
Copy link
Contributor Author

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 commented Sep 4, 2014

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

@japaric
Copy link
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
Copy link
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 steveklabnik added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Feb 14, 2015
@steveklabnik
Copy link
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.

@aalexgabi
Copy link

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

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 commented Mar 24, 2017

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

@aalexgabi
Copy link

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

@frewsxcv
Copy link
Member

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

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

@igor-petruk
Copy link

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

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?

@abc-mikey
Copy link

abc-mikey commented Mar 20, 2021

wow! 8 years, that is some powerful user unfriendliness.

@agajdosi
Copy link

It's annoying. A handy fix can be found in here: http://blog.joncairns.com/2015/10/a-single-command-to-compile-and-run-rust-programs/.

Create a bash script named rust, place in directory in PATH and make it executable:

#!/bin/bash
name=$(basename $1 .rs)
rustc $@ && ./$name && rm $name

flip1995 pushed a commit to flip1995/rust that referenced this issue Dec 17, 2022
Add semicolon-outside/inside-block lints

changelog: Add `semicolon_outside_block` and `semicolon_inside_block` lints

Fixes rust-lang/rust-clippy#7322

An earlier attempt at this can be found here rust-lang/rust-clippy#7564. This PR still implements two separate lints but I am open to merging them into a single one that's configurable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests