Skip to content

Commit 45b0537

Browse files
Add Rust tool layer
1 parent 02d4c74 commit 45b0537

File tree

5 files changed

+116
-0
lines changed

5 files changed

+116
-0
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

0 commit comments

Comments
 (0)