Skip to content

Commit e4ced43

Browse files
Add Rust tool layer
1 parent b4c507e commit e4ced43

File tree

6 files changed

+118
-1
lines changed

6 files changed

+118
-1
lines changed

layers/+tools/fzf/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ choco install ag
2727
choco install ripgrep
2828
```
2929

30+
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.
31+
3032
## Install
3133

3234
To use this configuration layer, add it to your `~/.spacevim`. *It has been enabled as one of the default layers*.

layers/+tools/rustc/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Rust tool layer
2+
3+
## Table of Contents
4+
5+
<!-- TOC GFM -->
6+
7+
* [Description](#description)
8+
* [Install](#install)
9+
* [Building](#building)
10+
* [Prerequisite](#prerequisite)
11+
* [MS Windows](#ms-windows)
12+
13+
<!-- /TOC -->
14+
15+
## Description
16+
17+
Folowing the zero-install philosophy, this layer adds the Rust compiler, standard library, documentation, and default extensions including Cargo. All built from source.
18+
19+
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.
20+
21+
Cargo will be added to $PATH for use by Vim plugins and for a LSP plugin/engine to install language servers.
22+
23+
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.
24+
25+
## Install
26+
27+
To use this layer, add it to your `~/.spacevim`.
28+
29+
### Building
30+
31+
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.
32+
33+
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.
34+
35+
#### Prerequisite
36+
37+
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.
38+
39+
#### MS Windows
40+
41+
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.
42+
43+
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.

layers/+tools/rustc/config.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
execute 'source '.fnamemodify(expand('<sfile>'), ':h').'/native-dependency.vim'
2+
3+
if spacevim#vim#plug#LocateDependency('rust')[0] ==# 'none'
4+
call spacevim#util#warn('rustc layer failure, try ":call dein#get('.
5+
\ '"rust").hook_post_update()" to build as plugin, or set $RUSTC/'.
6+
\ '$PATH to existing build, or install system-wide with version >= '.
7+
\ join(g:spacevim#vim#plug#native_dependency['rust'].v_req, '.').'.')
8+
else
9+
" Add cargo installed binaries to PATH, e.g. deno, tree-sitter
10+
if exists('$CARGO_INSTALL_ROOT')
11+
call spacevim#util#PostfixPATH(expand('$CARGO_INSTALL_ROOT/bin'))
12+
elseif exists('$CARGO_HOME')
13+
call spacevim#util#PostfixPATH(expand('$CARGO_HOME/bin'))
14+
else
15+
call spacevim#util#PostfixPATH(expand('$HOME/.cargo/bin'))
16+
endif
17+
endif
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
function! Build(native) abort
2+
let python = (g:spacevim.os.windows ? 'python ' : './')
3+
call system(python.a:native.plugpath.'/src/bootstrap/configure.py '.
4+
\ '--prefix='.a:native.plugpath.'/install --bindir=bin --libdir=lib'.
5+
\ ' --sysconfdir=. --disable-docs')
6+
7+
if filereadable('config.toml')
8+
" profile=user setting unsupported through configure.py interface
9+
execute ':tabnew +%s/\\V\#profile\ \=\ \<none\>/profile\ \=\ \"user\"/e|up config.toml'
10+
call spacevim#util#info('Edit config.toml rustc configuration if desired...')
11+
endif
12+
13+
call execute('AsyncRun -cwd='.a:native.plugpath.'/build -mode=term '.
14+
\ '-pos=tab -post='.
15+
\ 'call\ spacevim\#vim\#plug\#PostBuild(code,\ ''rust'') @ '.
16+
\ python.'x.py build && '.python.'x.py install')
17+
endfunction
18+
19+
function! PostBuild(native) abort
20+
"TODO: Comment?
21+
"call delete('library', 'rf')
22+
"call delete('Makefile')
23+
"call delete('src', 'rf')
24+
" Install rg and fd tools if not on system
25+
if executable('rg') != 1
26+
call spacevim#vim#plug#post_update('', 'cargo install --locked ripgrep')
27+
endif
28+
if executable('fd') != 1
29+
call spacevim#vim#plug#post_update('', 'cargo install --locked fd-find')
30+
endif
31+
if executable('delta') != 1
32+
call spacevim#vim#plug#post_update('', 'cargo install --locked git-delta')
33+
endif
34+
if executable('bat') != 1
35+
call spacevim#vim#plug#post_update('', 'cargo install --locked bat')
36+
endif
37+
endfunction
38+
39+
let g:spacevim#vim#plug#native_dependency = get(g:, 'spacevim#vim#plug#native_dependency', {})
40+
let g:spacevim#vim#plug#native_dependency['rust'] = {
41+
\ 'bin': 'rustc',
42+
\ 'override': '$RUSTC',
43+
\ 'repo': 'rust-lang/rust',
44+
\ 'vregex': '\Vrustc \(\[0-9]\+\).\(\[0-9]\+\).\(\[0-9]\+\)',
45+
\ 'v_req': [1, 56, 0],
46+
\ 'Build': function('Build'),
47+
\ 'PostBuild': function('PostBuild'),
48+
\ }

layers/+tools/rustc/packages.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
execute 'source '.fnamemodify(expand('<sfile>'), ':h').'/native-dependency.vim'
2+
3+
if spacevim#vim#plug#LocateDependency('rust')[0] ==# 'none'
4+
MP 'rust-lang/rust', { 'merged': v:false, 'rtp': '',
5+
\ 'hook_post_update': function('spacevim#vim#plug#Build', ['rust']) }
6+
endif

layers/LAYERS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Layer Manifest
22
==============
33

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

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

@@ -52,6 +52,7 @@ Topic | Layer | Plugins
5252
+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>
5353
+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>
5454
+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>
55+
+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>
5556
+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>
5657
+tools | [vimspector](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/vimspector) | <ul><li>[puremourning/vimspector](https://github.com/puremourning/vimspector)</li></ul>
5758
+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>

0 commit comments

Comments
 (0)