From f6ca185e63f5fd61c4702f81459c130ded3a4a0b Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 20 Mar 2017 15:55:58 -0400 Subject: [PATCH] lang/rust: add bootstrap --- modules/lang/rust/config.el | 6 +++--- modules/lang/rust/packages.el | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/modules/lang/rust/config.el b/modules/lang/rust/config.el index e2f6b057b..cc3607dc4 100644 --- a/modules/lang/rust/config.el +++ b/modules/lang/rust/config.el @@ -1,6 +1,6 @@ ;;; module-rust.el -(defvar +rust-cache-dir (concat doom-cache-dir "+rust/") +(defvar +rust-ext-dir (concat doom-etc-dir "rust/") "TODO") (def-package! rust-mode @@ -18,8 +18,8 @@ :init (add-hook! rust-mode '(racer-mode eldoc-mode flycheck-rust-setup)) :config - (setq racer-cmd (expand-file-name "racer/target/release/racer" +rust-cache-dir) - racer-rust-src-path (expand-file-name "rust/src/" +rust-cache-dir)) + (setq racer-cmd (expand-file-name "racer/target/release/racer" +rust-ext-dir) + racer-rust-src-path (expand-file-name "rust/src/" +rust-ext-dir)) ;; TODO Unit test keybinds (map! :map rust-mode-map :m "gd" 'racer-find-definition)) diff --git a/modules/lang/rust/packages.el b/modules/lang/rust/packages.el index 511c4a8e5..7805fc351 100644 --- a/modules/lang/rust/packages.el +++ b/modules/lang/rust/packages.el @@ -9,3 +9,33 @@ (when (featurep! :completion company) (package! company-racer)) + +;; +(def-bootstrap! rust + (pcase (doom-system-os) + ('arch + (let (pkgs) + (unless (executable-find "rustc") (push "rust" pkgs)) + (unless (executable-find "cargo") (push "cargo" pkgs)) + (when pkgs + (sudo "pacman --noconfirm -S %s" (string-join pkgs " "))))) + ('debian) ;; TODO + ('macos + (unless (executable-find "rustc") + (sh "brew install rust")))) + + (dolist (bin '("rustc" "cargo")) + (unless (executable-find bin) + (error "Failed to install %s" bin))) + + (require! :lang rust t) + (require 'racer) + (and (unless (file-directory-p racer-rust-src-path) + (fetch :github "rust-lang/rust" (expand-file-name "rust" +rust-ext-dir)) + t) + (unless (file-executable-p racer-cmd) + (let ((racer-dir (expand-file-name "racer" +rust-ext-dir))) + (fetch :github "phildawes/racer" racer-dir) + (let ((default-directory racer-dir)) + (sh "cargo build --release")) + t))))