Skip to content

Commit ef1fcb9

Browse files
feat(ansible)!: install rust through rustup instead of apt (#6825)
Signed-off-by: Arjun Jagdish Ram <arjun.ram@tier4.jp> Co-authored-by: Mete Fatih Cırıt <mfc@autoware.org>
1 parent 965da1f commit ef1fcb9

File tree

2 files changed

+51
-16
lines changed

2 files changed

+51
-16
lines changed

ansible/roles/rust/README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# rust
22

3-
This role installs the Rust toolchain (rustc and cargo) via apt for building Autoware components that depend on Rust (e.g. acados and tera_renderer). Rustup is not installed; the system compiler and cargo from the distribution are used.
3+
This role installs the Rust toolchain (rustc and cargo) via [rustup](https://rustup.rs/) for building Autoware components that depend on Rust (e.g. acados and tera_renderer).
44

55
## Tools
66

7-
- rustc (apt)
8-
- cargo (apt)
7+
- rustc
8+
- cargo
99

1010
## Inputs
1111

@@ -15,17 +15,29 @@ This role installs the Rust toolchain (rustc and cargo) via apt for building Aut
1515

1616
## Manual Installation
1717

18+
Reference: [Rust installation documentation](https://www.rust-lang.org/tools/install).
19+
20+
```bash
21+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o /tmp/rustup-init.sh
22+
chmod +x /tmp/rustup-init.sh
23+
24+
/tmp/rustup-init.sh -y
25+
```
26+
27+
Add the following line to your `~/.bashrc`.
28+
1829
```bash
19-
sudo apt-get update
20-
sudo apt-get install -y rustc cargo build-essential
30+
. "$HOME/.cargo/env"
31+
```
32+
33+
And source the file. (`source ~/.bashrc` or just call `bash` in the terminal).
2134

35+
```bash
2236
# Verify
2337
cargo --version
2438
rustc --version
2539
```
2640

27-
For a user-managed toolchain (multiple Rust versions, rustup), see [Rust installation documentation](https://www.rust-lang.org/tools/install).
28-
2941
## Ansible Installation
3042

3143
Install ansible following the instructions in the [ansible installation guide](../../README.md#ansible-installation).

ansible/roles/rust/tasks/main.yaml

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
1-
- name: Install Rust toolchain (rustc and cargo) and build dependencies via apt
2-
become: true
3-
ansible.builtin.apt:
4-
name:
5-
- rustc
6-
- cargo
1+
- name: Download rustup-init script
2+
become: false
3+
ansible.builtin.get_url:
4+
url: https://sh.rustup.rs
5+
dest: /tmp/rustup-init.sh
6+
mode: "0755"
7+
8+
- name: Install rustup using rustup-init script
9+
become: false
10+
ansible.builtin.command: /tmp/rustup-init.sh -y
11+
args:
12+
creates: "{{ ansible_env.HOME }}/.cargo/bin/rustc"
13+
14+
- name: Ensure ~/.cargo/bin is in PATH via .bashrc
15+
become: false
16+
ansible.builtin.lineinfile:
17+
path: "{{ ansible_env.HOME }}/.bashrc"
18+
line: . "$HOME/.cargo/env"
19+
insertafter: EOF
720
state: present
8-
update_cache: true
9-
cache_valid_time: 3600
1021

1122
- name: Check cargo version
12-
ansible.builtin.command: cargo --version
23+
become: false
24+
ansible.builtin.shell: |
25+
{{ ansible_env.HOME }}/.cargo/bin/cargo --version
1326
register: rust_cargo_version
1427
changed_when: false
1528

1629
- name: Show cargo version
1730
ansible.builtin.debug:
1831
msg: "Cargo version: {{ rust_cargo_version.stdout }}"
32+
33+
- name: Check rust version
34+
become: false
35+
ansible.builtin.command: "{{ ansible_env.HOME }}/.cargo/bin/rustc --version"
36+
register: rust_rustc_version
37+
changed_when: false
38+
39+
- name: Show rust version
40+
ansible.builtin.debug:
41+
msg: "Rust version: {{ rust_rustc_version.stdout }}"

0 commit comments

Comments
 (0)