Hi, these are the setup instructions for the rust workshop. This is the (hopefully) bullet-proof way to get everything you need for Thursday (and still have it working on Thursday). If you run into issues, check the FAQ section.
Note: If you don't like to use Docker, see below for an alternative method.
- Mac installer
- Windows installer
- On Ubuntu/linux:
sudo apt install docker.io
sudo service docker restart
sudo addgroup $USER docker
newgrp docker
(This is the slow thing; it includes a couple GB of Ubuntu.)
docker pull gzel/rust-workshop:latest
Note: If you're pulling from the VMware network, you will likely see the following error message:
Error response from daemon: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit
The simplest workaround for this is to disconnect the corporate VPN if you're working from home. If you have to use the corporate network, go to the docker hub website and sign up for an account there (if you haven't already). Then, login on the command line with docker login
and enter your docker hub username and password in the prompt before repeating the docker pull
command from above.
Note: copy-paste the commands line-by-line, otherwise it'll likely not paste the 2nd and 3rd command after starting a new shell
docker container run -t -i gzel/rust-workshop:latest /bin/bash
Now, in the new shell prompt (of the container) execute the following commands:
rustc --version
exit
If everything is working, you should see:
rustc 1.60.0 (7737e0b5c 2022-04-04)
Run the image connected to your file-system so you can edit files in your OS, and then run rustlings from inside the docker container:
mkdir work
cd work
docker container run -t -i --mount src="`pwd`",target=/home/rust/work,type=bind --workdir /home/rust/work gzel/rust-workshop:latest /bin/bash
If you're on Windows: The
pwd
command insrc=...
might not work under Windows, if this is the case you should substitutepwd
with the absolute path to thework
directory here and in the following command invocations todocker run ...
You should now be in the shell inside the docker container, here execute the following commands:
git clone -b workshop2 https://github.com/gz/rustlings.git
chmod a+rw -R rustlings/
cd rustlings
cargo install --path .
Now you can edit files using your preferred native OS editor under the work/ directory, and verify them with a rust compiler/rustlings from the terminal that's running the docker image.
If you're preparing for the workshop, stop here! The first set of exercises begins after the first lecture session.
(You can exit the docker container by typing exit
in the console)
If you exited your container, you'll have to enter it again to do the rustlings exercises, use the follwoing commands:
cd work
docker container run -t -i --mount src="`pwd`",target=/home/rust/work,type=bind --workdir /home/rust/work gzel/rust-workshop:latest /bin/bash
Then in the container execute:
cd rustlings
cargo install --path .
Now you're ready to work on the exercises.
The rustlings
directories contains a set of exercises for you to work through.
The binary called rustlings
, installed in your container, will guide you through the exercises.
Start it by typing rustlings watch
in the rustlings folder now.
-
exercises/$module/*.rs
: work through these files in order. Instructions appear by executingrustlings watch
in your docker container. -
hint
: If you get stuck on an exercise, you can get a hint from rustlings by typinghint
in the terminal. -
exercises/$module/README.md
: Some modules contain a readme with helpful links to more documenation & resources for material they cover. -
exercises/quiz*.rs
: These are quizzes that rustlings will give you in order to test you every time you completed a few of the modules. Quizzes don't have hints. -
If you want to skip some exercises to work on a specific exercise use
rustlings run if1
(where if1 is the filename of the exercise).
-
On Linux,
rustlings watch
terminates immediately with exit status 0? Try increasing the amount of inotify user watches in your system (e.g.,echo 32000 | sudo tee /proc/sys/fs/inotify/max_user_watches
). -
docker pull gzel/rust-workshop:latest
gives me an error? One cause for this can be that your corporate network might block access to docker. The fix then is to make sure you're not connected to a company VPN/network. -
I'm getting "bash: rustlings: command not found" after I exited the container and started it again? You may have to reinstall rustlings if you restart the container, execute like this:
cd work
docker container run -t -i --mount src="`pwd`",target=/home/rust/work,type=bind --workdir /home/rust/work gzel/rust-workshop:latest /bin/bash
cd rustlings
cargo install --path .
- I'm getting this error when doing
docker container ...
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create": dial unix /var/run/docker.sock: connect: permission denied.`
This happens because you're supposed to logout/login again after adding yourself to the docker group on Linux (I suppose).
So login/logout should fix this (you might want to just reboot if the problem persists - sorry).
Another (simpler but slightly scarier) fix: If you just want to use docker for this tutorial and you'll uninstall it afterwards, just do sudo chmod 666 /var/run/docker.sock
.
cargo install --path .
fails with:
error: linker `cc` not found
|
= note: No such file or directory (os error 2)
This shouldn't happen with the docker image. You'll have to install a C compiler (e.g., try sudo apt install build-essentials
on Ubuntu).
Me neither! You can install rust on your computer following the instructions here and then clone and install this repo we're going to use:
mkdir work
cd work
git clone -b workshop2 https://github.com/gz/rustlings.git
cd rustlings
cargo install --path .
And if you don't like to install git, you can also download a ZIP file of the repo.