Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 80 additions & 6 deletions devtools/setup-dev/ansible/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ sh_test(
"all.yml",
"bazel.yml",
"bazel-affected-tests.yml",
"biome.yml",
"buf.yml",
"buildifier.yml",
"buildozer.yml",
"cargo-clippy.yml",
"cargo-install-update.yml",
"clang-format.yml",
"claude.yml",
Expand Down Expand Up @@ -186,7 +186,9 @@ sh_test(
"repo-sync.yml",
"rg.yml",
"ruff.yml",
"rust-analyzer.yml",
"rustc.yml",
"rustfmt.yml",
"sed.yml",
"setup-bazel.yml",
"setup-cargo.yml",
Expand All @@ -206,6 +208,8 @@ sh_test(
"setup-npm.yml",
"setup-nvm.yml",
"setup-perplexity-mcp.yml",
"setup-rust.yml",
"setup-rust-tools.yml",
"setup-shell-profile.yml",
"setup-spacemacs.yml",
"setup-spacemacs-go.yml",
Expand Down Expand Up @@ -350,6 +354,20 @@ sh_test(
],
)

sh_test(
name = "cargo-clippy_syntax_test",
srcs = ["test_ansible_syntax.sh"],
args = ["cargo-clippy.yml"],
data = [
"cargo-clippy.yml",
"setup-rust.yml",
],
tags = [
"ansible",
"local",
],
)

sh_test(
name = "cargo-install-update_syntax_test",
srcs = ["test_ansible_syntax.sh"],
Expand Down Expand Up @@ -1701,6 +1719,20 @@ sh_test(
],
)

sh_test(
name = "rust-analyzer_syntax_test",
srcs = ["test_ansible_syntax.sh"],
args = ["rust-analyzer.yml"],
data = [
"rust-analyzer.yml",
"setup-rust.yml",
],
tags = [
"ansible",
"local",
],
)

sh_test(
name = "rustc_syntax_test",
srcs = ["test_ansible_syntax.sh"],
Expand All @@ -1715,6 +1747,20 @@ sh_test(
],
)

sh_test(
name = "rustfmt_syntax_test",
srcs = ["test_ansible_syntax.sh"],
args = ["rustfmt.yml"],
data = [
"rustfmt.yml",
"setup-rust.yml",
],
tags = [
"ansible",
"local",
],
)

sh_test(
name = "sed_syntax_test",
srcs = ["test_ansible_syntax.sh"],
Expand Down Expand Up @@ -1871,13 +1917,11 @@ sh_test(
srcs = ["test_ansible_syntax.sh"],
args = ["setup-devtools.yml"],
data = [
"biome.yml",
"buf.yml",
"cargo-install-update.yml",
"clang-format.yml",
"cleanup-repo.yml",
"curl.yml",
"eslint.yml",
"fd.yml",
"gh.yml",
"gmi.yml",
Expand All @@ -1890,8 +1934,6 @@ sh_test(
"locate.yml",
"man.yml",
"notmuch.yml",
"npm.yml",
"prettier.yml",
"protoc.yml",
"protoc-gen-go.yml",
"protoc-gen-go-grpc.yml",
Expand All @@ -1903,7 +1945,6 @@ sh_test(
"setup-cargo.yml",
"setup-devtools.yml",
"setup-grpc.yml",
"setup-npm.yml",
"setup-shell-profile.yml",
"setup-user-bin-directory.yml",
"setup-user-go-bin-directory.yml",
Expand Down Expand Up @@ -2225,6 +2266,34 @@ sh_test(
],
)

sh_test(
name = "setup-rust_syntax_test",
srcs = ["test_ansible_syntax.sh"],
args = ["setup-rust.yml"],
data = ["setup-rust.yml"],
tags = [
"ansible",
"local",
],
)

sh_test(
name = "setup-rust-tools_syntax_test",
srcs = ["test_ansible_syntax.sh"],
args = ["setup-rust-tools.yml"],
data = [
"cargo-clippy.yml",
"rust-analyzer.yml",
"rustfmt.yml",
"setup-rust.yml",
"setup-rust-tools.yml",
],
tags = [
"ansible",
"local",
],
)

sh_test(
name = "setup-shell-profile_syntax_test",
srcs = ["test_ansible_syntax.sh"],
Expand Down Expand Up @@ -2838,6 +2907,7 @@ test_suite(
":buildifier_syntax_test",
":buildozer_syntax_test",
":cargo-add_syntax_test",
":cargo-clippy_syntax_test",
":cargo-install-update_syntax_test",
":cargo-outdated_syntax_test",
":check-jsonschema_syntax_test",
Expand Down Expand Up @@ -2933,7 +3003,9 @@ test_suite(
":repo-sync_syntax_test",
":rg_syntax_test",
":ruff_syntax_test",
":rust-analyzer_syntax_test",
":rustc_syntax_test",
":rustfmt_syntax_test",
":sed_syntax_test",
":semgrep_syntax_test",
":setup-bazel_syntax_test",
Expand Down Expand Up @@ -2961,6 +3033,8 @@ test_suite(
":setup-nvm_syntax_test",
":setup-pass_syntax_test",
":setup-perplexity-mcp_syntax_test",
":setup-rust-tools_syntax_test",
":setup-rust_syntax_test",
":setup-shell-profile_syntax_test",
":setup-spacemacs-go_syntax_test",
":setup-spacemacs-python_syntax_test",
Expand Down
13 changes: 11 additions & 2 deletions devtools/setup-dev/ansible/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,15 @@ so it's usually a good idea to use it for Go projects. The generator includes
automatic version checking and upgrade logic for Go packages.

*** macOS
Homebrew is the preferred package manager for macOS, with support for taps and
installation options when needed.
Homebrew is the most preferred installation method on macOS because it provides
system-level packages, which is what this setup-dev/ansible setup generally
aims for. Even when alternative installation methods exist (e.g., =rustup= for
Rust tools, =cargo= for Rust packages), Homebrew is preferred when available
because it integrates with the system package management and ensures consistent
tooling across the development environment.

Homebrew also supports taps and installation options when needed for specialized
packages.

To regenerate the playbooks, simply run:
#+begin_src sh
Expand Down Expand Up @@ -216,6 +223,8 @@ These files are playbooks not generated from =generate_packages.go=:
- setup-nvm.yml
- setup-pass.yml
- setup-perplexity-mcp.yml
- setup-rust.yml
- setup-rust-tools.yml
- setup-shell-profile.yml
- setup-spacemacs.yml
- setup-spacemacs-go.yml
Expand Down
3 changes: 2 additions & 1 deletion devtools/setup-dev/ansible/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
- import_playbook: setup-wrangler.yml
- import_playbook: setup-swift-tools.yml
when: ansible_facts['os_family'] == "Darwin"
- import_playbook: setup-devtools.yml
- import_playbook: setup-rust-tools.yml
- import_playbook: setup-sql-tools.yml
- import_playbook: setup-devtools.yml
56 changes: 56 additions & 0 deletions devtools/setup-dev/ansible/cargo-clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
# THIS FILE IS AUTO-GENERATED by generate_packages.go - DO NOT EDIT MANUALLY
# To make changes, modify generate_packages.go, install_methods.go, packages_data.go, or templates.go
# and then run: make
- import_playbook: setup-rust.yml

- name: Ensure cargo-clippy is present
hosts: all
tasks:
- name: Include guard for cargo-clippy playbook
block:
- name: Stop early if the cargo-clippy playbook is already included
meta: end_play
when: cargo_clippy_playbook_imported is defined
- name: Ensure the cargo-clippy playbook is not included
set_fact:
cargo_clippy_playbook_imported: true
when: cargo_clippy_playbook_imported is not defined

- name: Ensure cargo-clippy is present on MacOS
block:
- name: Check if cargo-clippy is installed
shell: command -v cargo-clippy
changed_when: False
rescue:
- name: Install cargo-clippy on MacOS
community.general.homebrew:
name: clippy
state: present
when: ansible_facts['os_family'] == "Darwin"

- name: Ensure cargo-clippy is present on Termux
block:
- name: Check if cargo-clippy is installed
shell: command -v cargo-clippy
register: cargo_clippy_installed
ignore_errors: yes
changed_when: False

- name: Install clippy component via rustup
command: rustup component add clippy
when: cargo_clippy_installed.rc != 0
when: ansible_facts['env']['TERMUX_VERSION'] is defined

- name: Install cargo-clippy via rustup-component on Debian/Ubuntu
block:
- name: Check if cargo-clippy is installed
shell: command -v cargo-clippy
register: cargo_clippy_installed
ignore_errors: yes
changed_when: False

- name: Install clippy component via rustup
command: rustup component add clippy
when: cargo_clippy_installed.rc != 0
when: ansible_facts['env']['TERMUX_VERSION'] is not defined and ansible_facts['os_family'] != "Darwin"
11 changes: 11 additions & 0 deletions devtools/setup-dev/ansible/ensure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ PKG_CACHE="$CACHE_DIR/termux-pkg-upgrade"
BREW_CACHE="$CACHE_DIR/brew-update"
NALA_CACHE="$CACHE_DIR/nala-upgrade"
PIP_CACHE="$CACHE_DIR/pip"
RUSTUP_CACHE="$CACHE_DIR/rustup-update"
ANSIBLE_GALAXY_CACHE="$CACHE_DIR/ansible-galaxy-collection"

# Detect OS
Expand Down Expand Up @@ -171,6 +172,16 @@ else
fi
fi

# Update rustup if installed (upgrades rust toolchain and all components)
# Only update if not done in the last 24 hours
if command -v rustup >/dev/null 2>&1; then
if [ ! -f "$RUSTUP_CACHE" ] || [ "$(find "$RUSTUP_CACHE" -mtime +1 2>/dev/null | wc -l)" -gt 0 ]; then
echo "Updating Rust toolchain via rustup..."
rustup update
touch "$RUSTUP_CACHE"
fi
fi

# Install community.general collection if not already installed
if [ ! -f "$ANSIBLE_GALAXY_CACHE" ] || [ "$(find "$ANSIBLE_GALAXY_CACHE" -mtime +1 2>/dev/null | wc -l)" -gt 0 ]; then
ansible-galaxy collection install community.general
Expand Down
37 changes: 37 additions & 0 deletions devtools/setup-dev/ansible/install_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,43 @@ func (g GoInstallMethod) RenderBlockInstallTask(command string) string {
return indent(g.RenderInstallTask(command), 4)
}

// RustupComponentMethod handles installation of Rust components via rustup.
// Components like clippy, rustfmt, and rust-analyzer are installed this way.
// Upgrades are handled by `rustup update` in ensure.sh, so this only checks
// if the component is installed.
type RustupComponentMethod struct {
Name string
}

func (r RustupComponentMethod) GetMethodType() string {
return "rustup-component"
}

func (r RustupComponentMethod) GetImports() []Import {
return []Import{{Playbook: "setup-rust"}}
}

func (r RustupComponentMethod) RenderSetupTasks(_ string) string {
return ""
}

func (r RustupComponentMethod) RenderInstallTask(command string) string {
commandID := strings.ReplaceAll(command, "-", "_")
return ` - name: Check if ` + command + ` is installed
shell: command -v ` + command + `
register: ` + commandID + `_installed
ignore_errors: yes
changed_when: False

- name: Install ` + r.Name + ` component via rustup
command: rustup component add ` + r.Name + `
when: ` + commandID + `_installed.rc != 0`
}

func (r RustupComponentMethod) RenderBlockInstallTask(command string) string {
return indent(r.RenderInstallTask(command), 4)
}

// CargoInstallMethod handles installation via Rust cargo command.
// Includes update logic using cargo-install-update.
type CargoInstallMethod struct {
Expand Down
27 changes: 27 additions & 0 deletions devtools/setup-dev/ansible/packages_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ var platformSpecificTools = []PlatformSpecificTool{
},
Imports: nil,
},
{
command: "cargo-clippy",
platforms: map[PlatformName]InstallMethod{
PlatformDarwin: BrewInstallMethod{Name: "clippy"},
PlatformDebianLike: RustupComponentMethod{Name: "clippy"},
PlatformTermux: RustupComponentMethod{Name: "clippy"},
},
Imports: nil,
},
{
command: "cargo-install-update",
platforms: map[PlatformName]InstallMethod{
Expand Down Expand Up @@ -383,6 +392,24 @@ rm -rf $TMPDIR/codex
},
Imports: nil,
},
{
command: "rust-analyzer",
platforms: map[PlatformName]InstallMethod{
PlatformDarwin: BrewInstallMethod{Name: "rust-analyzer"},
PlatformDebianLike: RustupComponentMethod{Name: "rust-analyzer"},
PlatformTermux: RustupComponentMethod{Name: "rust-analyzer"},
},
Imports: nil,
},
{
command: "rustfmt",
platforms: map[PlatformName]InstallMethod{
PlatformDarwin: BrewInstallMethod{Name: "rustfmt"},
PlatformDebianLike: RustupComponentMethod{Name: "rustfmt"},
PlatformTermux: RustupComponentMethod{Name: "rustfmt"},
},
Imports: nil,
},
{
command: "semgrep",
platforms: map[PlatformName]InstallMethod{
Expand Down
Loading
Loading