Skip to content

Instantly share code, notes, and snippets.

@gz
Last active May 4, 2022 04:35
Show Gist options
  • Save gz/fae0e0b91af7f2af3b34ad8799b0cd12 to your computer and use it in GitHub Desktop.
Save gz/fae0e0b91af7f2af3b34ad8799b0cd12 to your computer and use it in GitHub Desktop.

Rust Workshop set-up instructions

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.

Install Docker itself if you don't have it already

sudo apt install docker.io
sudo service docker restart
sudo addgroup $USER docker
newgrp docker

Pull the image

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

Test that the image works

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

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 in src=... might not work under Windows, if this is the case you should substitute pwd with the absolute path to the work directory here and in the following command invocations to docker 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.

STOP HERE

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)

Welcome back

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.

Working 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 executing rustlings watch in your docker container.

  • hint: If you get stuck on an exercise, you can get a hint from rustlings by typing hint 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).

FAQ & Common issues

  • 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).

I don't want to use docker or read all this stuff

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.

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