Skip to content

Commit 1c73f78

Browse files
committed
fix: modernize rust guide
1 parent f0070c1 commit 1c73f78

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

doc/guides/rust_tutorials/create_project.mdx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import Contact from '@components/contact.astro';
1515
Now that we have added RIOT as a submodule to our project, we can start writing our hello world program.
1616
You can use any text editor to create this file. We will use Visual Studio Code in this example. To open Visual Studio Code in the directory, you can use the following command:
1717

18-
```bash
18+
```bash title="Open Visual Studio Code"
1919
code .
2020
```
2121

2222
## Step 2: Initialize Rust
2323

2424
Now that Visual Studio Code is open, we need to tell Rust what kind of project we want to create. We do this by running the following command in the terminal:
2525

26-
```bash
26+
```bash title="Create a new Rust project"
2727
cargo new hello_world --lib
2828
```
2929

@@ -45,7 +45,7 @@ You should now have 3 new files within your project directory:
4545

4646
Now that we have created our hello world program, we need to create a Makefile to build our program. The Makefile is a build automation tool that allows us to define how our program should be built. We create a new file called `Makefile` in the root directory of our project and add the following code:
4747

48-
```makefile
48+
```makefile title="Makefile"
4949
# name of your application
5050
APPLICATION = hello-world
5151

@@ -66,17 +66,16 @@ DEVELHELP ?= 1
6666
# Change this to 0 show compiler invocation lines by default:
6767
QUIET ?= 1
6868

69-
# Tell the build system to use the Rust crate here
70-
FEATURES_REQUIRED += rust_target
7169
# Make sure this matches the name of the Rust crate
7270
APPLICATION_RUST_MODULE = hello_world
73-
BASELIBS += $(APPLICATION_RUST_MODULE).module
7471

7572
include $(RIOTBASE)/Makefile.include
7673
```
7774

7875
:::note
79-
The `BUILD_IN_DOCKER=1` flag tells the build system to use the docker image provided by RIOT to build our program. This ensures that we have all the necessary dependencies to build our program. If you have already built RIOT on your system, you can omit this flag and the build system will use the toolchain installed on your system.
76+
The `BUILD_IN_DOCKER=1` flag tells the build system to use the docker image provided by RIOT to build our program.
77+
This ensures that we have all the necessary dependencies to build our program.
78+
If you have already built RIOT on your system, you can omit this flag and the build system will use the toolchain installed on your system.
8079
:::
8180

8281
Now RIOT knows that you want to build a Rust application and will use the `hello_world` crate as the main module.
@@ -87,7 +86,7 @@ Now RIOT knows that you want to build a Rust application and will use the `hello
8786

8887
Next, we need to adjust the `Cargo.toml` file to tell Cargo that we want to build for RIOT. Open the `Cargo.toml` file and replace its contents with the following:
8988

90-
```toml
89+
```toml title="Cargo.toml"
9190
[package]
9291
name = "hello-world"
9392
version = "0.1.0"
@@ -125,7 +124,7 @@ make info-rust
125124

126125
The output will look something like this:
127126

128-
```bash
127+
```bash title="Output of make info-rust"
129128
[ann@ann-laptop13 rust01-hello-world]$ make info-rust
130129
cargo version
131130
cargo 1.81.0 (2dbb1af80 2024-08-20)
@@ -144,7 +143,7 @@ Beware that the way command line arguments are passed in is not consistent acros
144143
In VSCode you can now go to the workspace settings `.vscode/settings.json`
145144
and add the following settings:
146145

147-
```json
146+
```json title=".vscode/settings.json"
148147
{
149148
"rust-analyzer.cargo.extraArgs": [
150149
"--profile",
@@ -162,7 +161,7 @@ You can also use the `make cargo-command` command to run cargo commands with the
162161
We are nearly done with setting up our project. The last thing we need to do i
163162
s to write the actual hello world program. Open the `src/lib.rs` file and replace its contents with the following code:
164163

165-
```rust
164+
```rust title="src/lib.rs"
166165
#![no_std]
167166

168167
use riot_wrappers::riot_main;
@@ -181,7 +180,7 @@ this replaces the `println!` macro from the standard library, since, as mentione
181180

182181
Now we need to actually write the `main` function. Add the following code to the `src/lib.rs` file:
183182

184-
```rust
183+
```rust title="src/lib.rs"
185184
riot_main!(main);
186185

187186
fn main() {
@@ -202,19 +201,19 @@ Congratulations! You have now created your first Rust program for RIOT. 🎉
202201

203202
To build our program, we use the following command:
204203

205-
```bash
204+
```bash title="Build the program"
206205
make
207206
```
208207

209208
After building the program, we can run it using the following command to start the RIOT shell:
210209

211-
```bash
210+
```bash title="Connect to the RIOT shell"
212211
make term
213212
```
214213

215214
You should see the following output:
216215

217-
```
216+
```txt title="Output in the terminal"
218217
You are running RIOT using Rust on a(n) native board.
219218
```
220219

46.8 KB
Loading

0 commit comments

Comments
 (0)