-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4c507e
commit e4ced43
Showing
6 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
\ } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters