summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--posts/install-rust-analyzer-on-openbsd-current.md53
1 files changed, 53 insertions, 0 deletions
diff --git a/posts/install-rust-analyzer-on-openbsd-current.md b/posts/install-rust-analyzer-on-openbsd-current.md
new file mode 100644
index 0000000..a97f711
--- /dev/null
+++ b/posts/install-rust-analyzer-on-openbsd-current.md
@@ -0,0 +1,53 @@
+---
+title: "Install rust-analyzer on OpenBSD -current"
+description: "How to install the language server for Rust from source without rustup."
+published: 2022-01-04
+---
+
+The Rust Programming Language is anything but small.
+One thing that helped me find my way through the language and its libraries is the language server [rust-analyzer](https://rust-analyzer.github.io/).
+The [manual](https://rust-analyzer.github.io/manual.html) lists numerous compatible editor integrations.
+For example, I'm happy with using Vim with [vim-lsp](https://github.com/prabirshrestha/vim-lsp) and [asyncomplete.vim](https://github.com/prabirshrestha/asyncomplete.vim).
+
+The project provides [pre-compiled binaries](https://github.com/rust-analyzer/rust-analyzer/releases) for Linux, macOS, and Windows.
+However, installation from source was slightly trickier than expected.
+So here's how I installed rust-analyzer from source on OpenBSD -current.
+The process should work on other platforms alike, especially without `rustup`.
+
+First, install `rustc` and `cargo` from the `lang/rust` port.
+You might also want to install `rust-clippy` and `rust-rustfmt` while you're at it.
+
+ $ doas pkg_add rust rust-clippy rust-rustfmt
+
+Second, compile and install the rust-analyzer binary from source.
+
+ $ cargo install \
+ --git https://github.com/rust-analyzer/rust-analyzer.git \
+ --branch release \
+ --force \
+ --bin rust-analyzer \
+ --target-dir "$HOME/.cache/rust-analyzer" \
+ --locked \
+ rust-analyzer
+
+This will install the latest release of rust-analyzer to `~/.cargo/bin/`.
+Remember to add this location to your `PATH`.
+
+ $ export PATH="$HOME/.cargo/bin:$PATH"
+
+Finally, rust-analyzer needs a local copy of Rust's source code.
+The following commands fetch the source code matching the version of the currently installed Rust compiler.
+
+ $ [ -d "$HOME/.cache/rust-src" ] ||
+ git clone https://github.com/rust-lang/rust.git "$HOME/.cache/rust-src"
+ $ cd "$HOME/.cache/rust-src" &&
+ git fetch --tags &&
+ git checkout "$( rustc --version | sed 's/^rustc[[:space:]]*//' )"
+
+Lastly, tell rust-analyzer where to find the source code.
+
+ $ export RUST_SRC_PATH="$HOME/.cache/rust-src/library"
+
+With this, your favorite editor should be able to talk to rust-analyzer and help you find your way.
+Of course, you better add the above exports to your `~/.profile`.
+I've also added the above commands to my local update script to keep rustc, rust-analyzer, and the sources in sync.
Generated by cgit. See skreutz.com for my tech blog and contact information.