Skip to content

Commit

Permalink
Add Rust tool layer
Browse files Browse the repository at this point in the history
  • Loading branch information
rene-descartes2021 committed Dec 8, 2022
1 parent b4c507e commit e4ced43
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 1 deletion.
2 changes: 2 additions & 0 deletions layers/+tools/fzf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ choco install ag
choco install ripgrep
```

Alternatively ripgrep, fd, git-delta, bat will be built from source if using the 'rustc' layer. fzf and ag are not rust and can't be built with the 'rustc' layer.

## Install

To use this configuration layer, add it to your `~/.spacevim`. *It has been enabled as one of the default layers*.
Expand Down
43 changes: 43 additions & 0 deletions layers/+tools/rustc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Rust tool layer

## Table of Contents

<!-- TOC GFM -->

* [Description](#description)
* [Install](#install)
* [Building](#building)
* [Prerequisite](#prerequisite)
* [MS Windows](#ms-windows)

<!-- /TOC -->

## Description

Folowing the zero-install philosophy, this layer adds the Rust compiler, standard library, documentation, and default extensions including Cargo. All built from source.

If `rustc` is found on $PATH, or $RUSTC points to `rustc`, and either is of sufficient version, that will be used instead of building from source.

Cargo will be added to $PATH for use by Vim plugins and for a LSP plugin/engine to install language servers.

A convenience feature of this layer is that the binaries installed by cargo will be added to $PATH, e.g. deno, tree-sitter, and language servers.

## Install

To use this layer, add it to your `~/.spacevim`.

### Building

On building from source, around 600MiB is іnstalled into the prefix `./install` relative to the plugin directory. The building process requires around 17GiB, which will be deleted on completion.

If the automated building doesn't work, you may navigate to the plugin directory and build manually, into the prefix `./install`; installing system-wide isn't required. Or install prebuilt binaries and set $PATH or $RUSTC accordingly.

#### Prerequisite

See [Unix](https://github.com/rust-lang/rust#building-on-a-unix-like-system) or [Windows](https://github.com/rust-lang/rust#building-on-windows) prerequisites.

#### MS Windows

At present rust supports building under two ABIs: GNU and MSVC (comes with Visual Studio Tools). Your choice depends on the C/C++ libraries you want to interoperate with.

Automated building from source isn't tested. However it should work in Cygwin or with the environmental variables as defined by `msys2_shell.cmd` or `vcvars64.bat` per the desired ABI.
17 changes: 17 additions & 0 deletions layers/+tools/rustc/config.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
execute 'source '.fnamemodify(expand('<sfile>'), ':h').'/native-dependency.vim'

if spacevim#vim#plug#LocateDependency('rust')[0] ==# 'none'
call spacevim#util#warn('rustc layer failure, try ":call dein#get('.
\ '"rust").hook_post_update()" to build as plugin, or set $RUSTC/'.
\ '$PATH to existing build, or install system-wide with version >= '.
\ join(g:spacevim#vim#plug#native_dependency['rust'].v_req, '.').'.')
else
" Add cargo installed binaries to PATH, e.g. deno, tree-sitter
if exists('$CARGO_INSTALL_ROOT')
call spacevim#util#PostfixPATH(expand('$CARGO_INSTALL_ROOT/bin'))
elseif exists('$CARGO_HOME')
call spacevim#util#PostfixPATH(expand('$CARGO_HOME/bin'))
else
call spacevim#util#PostfixPATH(expand('$HOME/.cargo/bin'))
endif
endif
48 changes: 48 additions & 0 deletions layers/+tools/rustc/native-dependency.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
function! Build(native) abort
let python = (g:spacevim.os.windows ? 'python ' : './')
call system(python.a:native.plugpath.'/src/bootstrap/configure.py '.
\ '--prefix='.a:native.plugpath.'/install --bindir=bin --libdir=lib'.
\ ' --sysconfdir=. --disable-docs')

if filereadable('config.toml')
" profile=user setting unsupported through configure.py interface
execute ':tabnew +%s/\\V\#profile\ \=\ \<none\>/profile\ \=\ \"user\"/e|up config.toml'
call spacevim#util#info('Edit config.toml rustc configuration if desired...')
endif

call execute('AsyncRun -cwd='.a:native.plugpath.'/build -mode=term '.
\ '-pos=tab -post='.
\ 'call\ spacevim\#vim\#plug\#PostBuild(code,\ ''rust'') @ '.
\ python.'x.py build && '.python.'x.py install')
endfunction

function! PostBuild(native) abort
"TODO: Comment?
"call delete('library', 'rf')
"call delete('Makefile')
"call delete('src', 'rf')
" Install rg and fd tools if not on system
if executable('rg') != 1
call spacevim#vim#plug#post_update('', 'cargo install --locked ripgrep')
endif
if executable('fd') != 1
call spacevim#vim#plug#post_update('', 'cargo install --locked fd-find')
endif
if executable('delta') != 1
call spacevim#vim#plug#post_update('', 'cargo install --locked git-delta')
endif
if executable('bat') != 1
call spacevim#vim#plug#post_update('', 'cargo install --locked bat')
endif
endfunction

let g:spacevim#vim#plug#native_dependency = get(g:, 'spacevim#vim#plug#native_dependency', {})
let g:spacevim#vim#plug#native_dependency['rust'] = {
\ 'bin': 'rustc',
\ 'override': '$RUSTC',
\ 'repo': 'rust-lang/rust',
\ 'vregex': '\Vrustc \(\[0-9]\+\).\(\[0-9]\+\).\(\[0-9]\+\)',
\ 'v_req': [1, 56, 0],
\ 'Build': function('Build'),
\ 'PostBuild': function('PostBuild'),
\ }
6 changes: 6 additions & 0 deletions layers/+tools/rustc/packages.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
execute 'source '.fnamemodify(expand('<sfile>'), ':h').'/native-dependency.vim'

if spacevim#vim#plug#LocateDependency('rust')[0] ==# 'none'
MP 'rust-lang/rust', { 'merged': v:false, 'rtp': '',
\ 'hook_post_update': function('spacevim#vim#plug#Build', ['rust']) }
endif
3 changes: 2 additions & 1 deletion layers/LAYERS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Layer Manifest
==============

Last updated: 2022-09-29 12:39:45
Last updated: 2022-09-29 16:25:03

Default layers: `fzf`, `better-defaults` and `which-key`.

Expand Down Expand Up @@ -52,6 +52,7 @@ Topic | Layer | Plugins
+tools | [file-manager](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/file-manager) | <ul><li>[Xuyuanp/nerdtree-git-plugin](https://github.com/Xuyuanp/nerdtree-git-plugin)</li><li>[danro/rename.vim](https://github.com/danro/rename.vim)</li><li>[liuchengxu/nerdtree-dash](https://github.com/liuchengxu/nerdtree-dash)</li><li>[ryanoasis/vim-devicons](https://github.com/ryanoasis/vim-devicons)</li><li>[scrooloose/nerdtree](https://github.com/scrooloose/nerdtree)</li><li>[tiagofumo/vim-nerdtree-syntax-highlight](https://github.com/tiagofumo/vim-nerdtree-syntax-highlight)</li></ul>
+tools | [fzf](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/fzf) | <ul><li>[Yggdroot/LeaderF](https://github.com/Yggdroot/LeaderF)</li><li>[junegunn/fzf](https://github.com/junegunn/fzf)</li><li>[junegunn/fzf.vim](https://github.com/junegunn/fzf.vim)</li><li>[liuchengxu/vim-clap](https://github.com/liuchengxu/vim-clap)</li><li>[vn-ki/coc-clap](https://github.com/vn-ki/coc-clap)</li></ul>
+tools | [lsp](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/lsp) | <ul><li>[autozimu/LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim)</li><li>[mattn/vim-lsp-settings](https://github.com/mattn/vim-lsp-settings)</li><li>[neoclide/coc-neco](https://github.com/neoclide/coc-neco)</li><li>[neoclide/coc.nvim](https://github.com/neoclide/coc.nvim)</li><li>[prabirshrestha/async.vim](https://github.com/prabirshrestha/async.vim)</li><li>[prabirshrestha/vim-lsp](https://github.com/prabirshrestha/vim-lsp)</li><li>[rhysd/vim-lsp-ale](https://github.com/rhysd/vim-lsp-ale)</li></ul>
+tools | [rustc](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/rustc) | <ul><li>[rust-lang/rust](https://github.com/rust-lang/rust)</li></ul>
+tools | [tmux](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/tmux) | <ul><li>[christoomey/vim-tmux-navigator](https://github.com/christoomey/vim-tmux-navigator)</li><li>[jebaum/vim-tmuxify](https://github.com/jebaum/vim-tmuxify)</li><li>[lucidstack/ctrlp-tmux.vim](https://github.com/lucidstack/ctrlp-tmux.vim)</li></ul>
+tools | [vimspector](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/vimspector) | <ul><li>[puremourning/vimspector](https://github.com/puremourning/vimspector)</li></ul>
+tools | [ycmd](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/ycmd) | <ul><li>[rdnetto/YCM-Generator](https://github.com/rdnetto/YCM-Generator)</li><li>[ycm-core/YouCompleteMe](https://github.com/ycm-core/YouCompleteMe)</li></ul>
Expand Down

0 comments on commit e4ced43

Please sign in to comment.