rustlings icon indicating copy to clipboard operation
rustlings copied to clipboard

Cargo configuration for easy local running

Open voddan opened this issue 10 years ago • 4 comments

Currently there is no Cargo.toml for the project, which blocks a possibility to open it locally in an IDE.

Besides that would be very nice to have Cargo to run separate examples independently from each other.

I achieved that with placing all examples to $root/examples. That way Cargo auto-generates running targets like cargo run --example ex1. The problem with that approach was that I wasn't able to tell Cargo to look inside subfolders like $root/examples/variables/

voddan avatar Feb 23 '16 16:02 voddan

Interesting! What IDE do you use? I'm not super familiar with IDEs... there isn't a way to just open a directory?

I'll investigate how to use cargo to run each example, but I have to admit I haven't thought about it since I've been focused on running the examples in the playground :)

carols10cents avatar Feb 24 '16 23:02 carols10cents

I use the plugin for Intelij Idea, but it does not work just yet.

Regardless for an IDE, a convenient way to run the examples locally is a must-have. Having Cargo doing it automatically is very useful.

voddan avatar Feb 25 '16 05:02 voddan

In general I'm pro cargo in any case, but in this case it might be useful to let new users try to use the rust compiler and get used to the flags that are needed. E.g. for tests.

jan-schreib avatar Jan 03 '17 23:01 jan-schreib

Here is a quick and dirty script to get it running locally

# create Cargo.toml and symlinks
echo -e '[package]\nname = "rustlings"\nversion = "0.1.0"' > Cargo.toml
echo -e "target/\nexamples/" >>.gitignore
mkdir -p examples; ls ex*.rs */*.rs | grep -v "^examples/" | while read F; do ln -sf "../$F" examples/$(echo "$F" | sed -re 's:^(.*)/\1:\1:;s:/:_:'); done

# then run examples with 
cargo run --example ex1
# or use this
select EX in $(ls examples | sed 's/\.rs$//'); do [ -n "$EX" ] && while true;do cargo run --example "$EX"; read; done; done

ssendev avatar Jun 05 '17 10:06 ssendev