From ad7fca700d3917d2a047c934dcec2aa2c8a09498 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 1 May 2023 20:04:59 -0400 Subject: [PATCH] Build rust-analyzer on FreeBSD. The official FreeBSD package rust-analyzer crashes. I suspect this is because its built for rust stable which conflicts with the rust-nightly I have installed. --- ansible/roles/emacs/files/lang-rust.el | 18 ++++++++++++++++++ ansible/roles/rust/tasks/freebsd.yaml | 25 ++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/ansible/roles/emacs/files/lang-rust.el b/ansible/roles/emacs/files/lang-rust.el index fa2923c..4b6ce88 100644 --- a/ansible/roles/emacs/files/lang-rust.el +++ b/ansible/roles/emacs/files/lang-rust.el @@ -2,10 +2,28 @@ (require 'util-tree-sitter) (defun locate-rust-analyzer () + "Find rust-analyzer." + (let ((rust-analyzer-paths (list (locate-rust-analyzer-rustup) (locate-rust-analyzer-ansible-built)))) + (let ((first-non-nill-path (seq-find (lambda (elt) elt) rust-analyzer-paths))) + first-non-nill-path + ) + ) + ) + +(defun locate-rust-analyzer-rustup () "Find rust-analyzer through rustup." (run-command-in-directory nil "rustup" "which" "rust-analyzer") ) +(defun locate-rust-analyzer-ansible-built () + "Find rust-analyzer where the ansible playbook built it." + (let ((rust-analyzer-path "/opt/rust-analyzer/target/release/rust-analyzer")) + (when (file-exists-p rust-analyzer-path) + rust-analyzer-path + ) + ) + ) + (use-package rust-mode :mode "\\.rs\\'" :hook ( diff --git a/ansible/roles/rust/tasks/freebsd.yaml b/ansible/roles/rust/tasks/freebsd.yaml index f4d95e4..813c2ec 100644 --- a/ansible/roles/rust/tasks/freebsd.yaml +++ b/ansible/roles/rust/tasks/freebsd.yaml @@ -2,5 +2,28 @@ package: name: - rust-nightly - - rust-analyzer state: present + +- name: Create directories + file: + name: "{{ item }}" + state: directory + mode: 0755 + owner: root + group: wheel + loop: + - "/opt/rust-analyzer" + +- name: Clone rust-analyzer Source + git: + repo: "https://github.com/rust-lang/rust-analyzer.git" + dest: /opt/rust-analyzer + version: "2023-05-01" + force: true + diff: false + +- name: Build rust-analyzer + command: "cargo build --release" + args: + creates: "/opt/rust-analyzer/target/release/rust-analyzer" + chdir: /opt/rust-analyzer