Skip to content

Commit f01316f

Browse files
docs: add cross-complilation guidelines for raspberry pi
1 parent a0bda28 commit f01316f

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Introduction
2+
3+
This document will explain how to build and deploy Rust application for a RasperryPi (ARM architecture)
4+
5+
<br/>
6+
7+
# Steps
8+
## 1. Creating a Rust app (we laready hae one so we skip this step)
9+
## 2. Craeting a deployment script
10+
## 3. Cross-compiling the application
11+
12+
<br/>
13+
14+
# Creating a Rust Application
15+
Since we already have one so we're skipping this step
16+
17+
<br/>
18+
19+
# Creating a deployment script
20+
Since, it's a multistep process, and we'll be iterating over our application and each iteration involves at a minimum compiling on the development machine and running on the target board. So, it is useful to create an script with necessary commands to avoid typing multiple commands each time.
21+
22+
We'll create a text file in the root of our project and name it after it's purpose `deploy` (without any extension).
23+
24+
```bash
25+
#!/bin/bash
26+
27+
set -o errexit
28+
set -o nounset
29+
set -o xtrace
30+
31+
cargo build --release
32+
```
33+
34+
After that we can just run to execute file:
35+
```
36+
$ ./deploy
37+
```
38+
39+
If you encounter with some execution related permissions error then make the script file executable with:
40+
41+
```
42+
$ chmod +x ./deploy
43+
```
44+
Now you can run the script successfully.
45+
<br/>
46+
<br/>
47+
At this point we have compiled our app in release mode. We can inspect this compiled binary with the following command:
48+
```
49+
$ file ./target/release/actix_mongo_app
50+
```
51+
- `actix_mongo_app`: is the application name
52+
53+
which prints out something like
54+
```
55+
target/release/actix_mongo_app: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=7d6ea5fc91dcf91b45d4cc5b2a5f180206487961, for GNU/Linux 3.2.0, with debug_info, not stripped
56+
```
57+
58+
If you read this carefully, you'll find out that it is a 64-bit binary for x86_64 architecture. Let's try running this on Pi and see what happens
59+
60+
```bash
61+
#!/bin/bash
62+
63+
set -o errexit
64+
set -o nounset
65+
set -o xtrace
66+
67+
68+
readonly TARGET_PATH=/home/pi/actix_mongo_app
69+
readonly SOURCE_PATH=./target/release/actix_mongo_app
70+
71+
cargo build --release
72+
rsync ${SOURCE_PATH} ${TARGET_HOST}:${TARGET_PATH}
73+
ssh -t ${TARGET_HOST} ${TARGET_PATH}
74+
```
75+
76+
Let me describe the elements of the above scripts before moving further
77+
- `pi`: Username on raspberry pi
78+
- `raspberrypi.local`: Hostname of raspberry pi
79+
- `actix_mongo_app`: Our application name
80+

0 commit comments

Comments
 (0)