[PATCH 1/5] install-rust-deps: Add generic Rust toolchain role
Luis Chamberlain <[email protected]> Fri, 17 Oct 2025 19:32:13 -0700
| Newsgroups | dev.linux.lists.kdevops |
|---|---|
| Message-ID | <[email protected]> |
Add reusable install-rust-deps role that provides consistent Rust toolchain installation across all distributions: - Debian/Ubuntu: cargo, rustc, pkg-config - Fedora/RHEL: cargo, rust, pkgconfig - SUSE: cargo, rust, pkg-config This modular role can be included by any workflow or role needing Rust support, following kdevops patterns for dependency management. Adopt Linux kernel's .rustfmt.toml configuration to enforce consistent Rust code formatting across kdevops. This enables 'cargo fmt' to automatically format Rust code according to kernel standards, ensuring code quality and consistency. Generated-by: Claude AI Signed-off-by: Luis Chamberlain <[email protected]> --- .rustfmt.toml | 12 +++ playbooks/roles/install-rust-deps/README.md | 90 +++++++++++++++++++ .../tasks/install-deps/debian/main.yml | 12 +++ .../tasks/install-deps/fedora/main.yml | 11 +++ .../tasks/install-deps/main.yml | 21 +++++ .../tasks/install-deps/redhat/main.yml | 11 +++ .../tasks/install-deps/suse/main.yml | 11 +++ .../roles/install-rust-deps/tasks/main.yml | 15 ++++ 8 files changed, 183 insertions(+) create mode 100644 .rustfmt.toml create mode 100644 playbooks/roles/install-rust-deps/README.md create mode 100644 playbooks/roles/install-rust-deps/tasks/install-deps/debian/main.yml create mode 100644 playbooks/roles/install-rust-deps/tasks/install-deps/fedora/main.yml create mode 100644 playbooks/roles/install-rust-deps/tasks/install-deps/main.yml create mode 100644 playbooks/roles/install-rust-deps/tasks/install-deps/redhat/main.yml create mode 100644 playbooks/roles/install-rust-deps/tasks/install-deps/suse/main.yml create mode 100644 playbooks/roles/install-rust-deps/tasks/main.yml diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 00000000..3de5cc49 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,12 @@ +edition = "2021" +newline_style = "Unix" + +# Unstable options that help catching some mistakes in formatting and that we may want to enable +# when they become stable. +# +# They are kept here since they are useful to run from time to time. +#format_code_in_doc_comments = true +#reorder_impl_items = true +#comment_width = 100 +#wrap_comments = true +#normalize_comments = true diff --git a/playbooks/roles/install-rust-deps/README.md b/playbooks/roles/install-rust-deps/README.md new file mode 100644 index 00000000..f6dd654a --- /dev/null +++ b/playbooks/roles/install-rust-deps/README.md @@ -0,0 +1,90 @@ +# install-rust-deps Role + +Generic Ansible role for installing Rust toolchain dependencies across multiple +Linux distributions. + +## Purpose + +Provides consistent Rust build environment setup for any kdevops workflow or +role that needs Rust support. This modular role can be included via +`ansible.builtin.include_role` to ensure cargo, rustc, and pkg-config are +available. + +## Packages Installed + +### Debian/Ubuntu +- `cargo` - Rust package manager and build tool +- `rustc` - Rust compiler +- `pkg-config` - Helper tool for compiling applications + +### Fedora/RHEL/CentOS +- `cargo` - Rust package manager and build tool +- `rust` - Rust compiler +- `pkgconfig` - Helper tool for compiling applications + +### SUSE/openSUSE +- `cargo` - Rust package manager and build tool +- `rust` - Rust compiler +- `pkg-config` - Helper tool for compiling applications + +## Rust Code Quality Tools + +This role provides the foundation for Rust development in kdevops. After +installation, the following tools are available: + +### cargo fmt +Automatic code formatter using Linux kernel rustfmt standards: +```bash +cd workflows/rcloud # or any Rust project +cargo fmt +``` + +Configuration is provided via `.rustfmt.toml` in the kdevops root directory +(included with this role). + +### cargo clippy +Linter for catching common mistakes and non-idiomatic code: +```bash +cd workflows/rcloud # or any Rust project +cargo clippy --all-targets --all-features -- -D warnings +``` + +**Always run both tools before committing Rust code:** +1. `cargo fmt` - Auto-format according to kernel standards +2. `cargo clippy` - Fix all warnings (treated as errors with `-D warnings`) + +## Usage + +### Include in Your Role + +```yaml +- name: Install Rust build dependencies + ansible.builtin.include_role: + name: install-rust-deps +``` + +### Example Workflows Using This Role + +- **bootlinux**: Kernel builds with Rust support +- **rcloud**: Private cloud infrastructure written in Rust + +## Files Provided + +- `.rustfmt.toml` - Linux kernel Rust formatting configuration + - Edition 2021 + - Unix newlines + - Consistent code style across all kdevops Rust code + +## Design Philosophy + +This role follows kdevops patterns: +- Distribution-agnostic with distro-specific task files +- No conditional installation guards (always ensures packages present) +- Minimal dependencies +- Reusable across workflows + +## See Also + +- `install-go-deps` - Similar role for Go toolchain +- `install-rcloud-deps` - Uses this role for rcloud workflow +- `CLAUDE.md` - Code quality requirements including Rust guidelines diff --git a/playbooks/roles/install-rust-deps/tasks/install-deps/debian/main.yml b/playbooks/roles/install-rust-deps/tasks/install-deps/debian/main.yml new file mode 100644 index 00000000..9526fd55 --- /dev/null +++ b/playbooks/roles/install-rust-deps/tasks/install-deps/debian/main.yml @@ -0,0 +1,12 @@ +--- +- name: Install Rust build dependencies + become: true + become_method: sudo + ansible.builtin.apt: + name: + - cargo + - rustc + - pkg-config + state: present + update_cache: false + tags: ["rust", "deps"] diff --git a/playbooks/roles/install-rust-deps/tasks/install-deps/fedora/main.yml b/playbooks/roles/install-rust-deps/tasks/install-deps/fedora/main.yml new file mode 100644 index 00000000..d87c50f2 --- /dev/null +++ b/playbooks/roles/install-rust-deps/tasks/install-deps/fedora/main.yml @@ -0,0 +1,11 @@ +--- +- name: Install Rust build dependencies + become: true + become_method: sudo + ansible.builtin.dnf: + name: + - cargo + - rust + - pkgconfig + state: present + tags: ["rust", "deps"] diff --git a/playbooks/roles/install-rust-deps/tasks/install-deps/main.yml b/playbooks/roles/install-rust-deps/tasks/install-deps/main.yml new file mode 100644 index 00000000..23cda58e --- /dev/null +++ b/playbooks/roles/install-rust-deps/tasks/install-deps/main.yml @@ -0,0 +1,21 @@ +--- +- name: Import optional distribution specific variables + ansible.builtin.include_vars: "{{ item }}" + ignore_errors: true + with_first_found: + - files: + - "{{ ansible_facts['os_family'] | lower }}.yml" + skip: true + tags: vars + +- name: Distribution specific setup + ansible.builtin.import_tasks: debian/main.yml + when: ansible_facts['os_family']|lower == 'debian' +- ansible.builtin.import_tasks: suse/main.yml + when: ansible_facts['os_family']|lower == 'suse' +- ansible.builtin.import_tasks: redhat/main.yml + when: + - ansible_facts['os_family']|lower == 'redhat' + - ansible_facts['distribution']|lower != "fedora" +- ansible.builtin.import_tasks: fedora/main.yml + when: ansible_facts['distribution']|lower == "fedora" diff --git a/playbooks/roles/install-rust-deps/tasks/install-deps/redhat/main.yml b/playbooks/roles/install-rust-deps/tasks/install-deps/redhat/main.yml new file mode 100644 index 00000000..d87c50f2 --- /dev/null +++ b/playbooks/roles/install-rust-deps/tasks/install-deps/redhat/main.yml @@ -0,0 +1,11 @@ +--- +- name: Install Rust build dependencies + become: true + become_method: sudo + ansible.builtin.dnf: + name: + - cargo + - rust + - pkgconfig + state: present + tags: ["rust", "deps"] diff --git a/playbooks/roles/install-rust-deps/tasks/install-deps/suse/main.yml b/playbooks/roles/install-rust-deps/tasks/install-deps/suse/main.yml new file mode 100644 index 00000000..cc806b14 --- /dev/null +++ b/playbooks/roles/install-rust-deps/tasks/install-deps/suse/main.yml @@ -0,0 +1,11 @@ +--- +- name: Install Rust build dependencies + become: true + become_method: sudo + community.general.zypper: + name: + - cargo + - rust + - pkg-config + state: present + tags: ["rust", "deps"] diff --git a/playbooks/roles/install-rust-deps/tasks/main.yml b/playbooks/roles/install-rust-deps/tasks/main.yml new file mode 100644 index 00000000..946b9c8e --- /dev/null +++ b/playbooks/roles/install-rust-deps/tasks/main.yml @@ -0,0 +1,15 @@ +--- +- name: Import optional extra_args file + ansible.builtin.include_vars: "{{ item }}" + ignore_errors: true + with_first_found: + - files: + - "../extra_vars.yml" + - "../extra_vars.yaml" + - "../extra_vars.json" + skip: true + tags: vars + +# Install Rust build dependencies +- name: Install Rust build dependencies + ansible.builtin.include_tasks: install-deps/main.yml -- 2.51.0