Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Refine the helper function fo building Rust dep #202

Merged
merged 7 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,7 @@ Vim-clap is a modern generic interactive finder and dispatcher, based on the new

#### `Rust`

If you have installed Rust on your system, specifically, `cargo` executable exists, you can build the extra tools for a performant and nicer vim-clap using one single command `:call clap#helper#build_all()`.

Notes: [Python dynamic module](https://github.com/liuchengxu/vim-clap#python-dynamic-module) needs to be compiled using Rust nightly, ensure you have installed it:

```bash
$ rustup toolchain install nightly
```
If you have installed Rust on your system, specifically, `cargo` executable exists, you can build the extra tools for a performant and nicer vim-clap using this single command `:call clap#helper#build_all()`.

##### `maple` binary

Expand All @@ -107,6 +101,8 @@ $ rustup toolchain install nightly
To install `maple` you can use the helper function and run `:call clap#helper#build_maple()`, or install it manually:

```bash
cd path/to/vim-clap

# Compile the release build
cargo build --release

Expand All @@ -116,7 +112,15 @@ To install `maple` you can use the helper function and run `:call clap#helper#bu

##### Python dynamic module

Use `:call clap#helper#build_rust_ext()` to install the Python dynamic module written in Rust for 10x faster fuzzy filter than the Python one. Refer to the post [Make Vim Python plugin 10x faster using Rust](http://liuchengxu.org/posts/speed-up-vim-python-plugin-using-rust/) for the whole story.
If you don't have `+python`, you can safely skip this section, it's totally fine, vim-clap can still work very well with only `maple` binary installed. This Python dynamic module is mainly for saving the async job when the data set is small.

[Python dynamic module](https://github.com/liuchengxu/vim-clap#python-dynamic-module) needs to be compiled using Rust nightly, ensure you have installed it if you want to run the helper function successfully:

```bash
$ rustup toolchain install nightly
```

Then use `:call clap#helper#build_python_dynamic_module()` to install the Python dynamic module written in Rust for 10x faster fuzzy filter than the Python one. Refer to the post [Make Vim Python plugin 10x faster using Rust](http://liuchengxu.org/posts/speed-up-vim-python-plugin-using-rust/) for the whole story.

## Installation

Expand Down
48 changes: 37 additions & 11 deletions autoload/clap/helper.vim
Original file line number Diff line number Diff line change
Expand Up @@ -102,35 +102,61 @@ else
let s:rust_ext_cwd = fnamemodify(g:clap#autoload_dir, ':h').'/pythonx/clap'
endif

function! clap#helper#build_rust_ext() abort
function! s:has_rust_nightly(show_warning) abort
call system('cargo +nightly --help')
if v:shell_error
if a:show_warning
call clap#helper#echo_warn('Rust nightly is required, try running `rustup toolchain install nightly` in the command line and then rerun this function.')
else
call clap#helper#echo_info('Rust nightly is required, skip building the Python dynamic module.')
endif
return v:false
endif
return v:true
endfunction

function! clap#helper#build_python_dynamic_module() abort
if !has('python3')
call clap#helper#echo_info('+python3 is required, skip building the Python dynamic module.')
return
endif

if executable('cargo')
call s:run_term(s:rust_ext_cmd, s:rust_ext_cwd, 'build Rust extension successfully')
if !s:has_rust_nightly(v:true)
return
endif
call s:run_term(s:rust_ext_cmd, s:rust_ext_cwd, 'build Python dynamic module successfully')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

built*

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will fix that later.

else
call clap#helper#echo_error('Can not build Rust extension in that cargo is not found.')
call clap#helper#echo_error('Can not build Python dynamic module in that cargo is not found.')
endif
endfunction

function! clap#helper#build_maple() abort
if executable('cargo')
let cmd = 'cargo build --release'
let cwd = fnamemodify(g:clap#autoload_dir, ':h')
call s:run_term(cmd, cwd, 'build maple successfully')
call s:run_term(cmd, cwd, 'build maple binary successfully')
else
call clap#helper#echo_error('Can not build maple in that cargo is not found.')
call clap#helper#echo_error('Can not build maple binary in that cargo is not found.')
endif
endfunction

function! clap#helper#build_all(...) abort
if executable('cargo')
let cwd = fnamemodify(g:clap#autoload_dir, ':h')
if has('win32')
let cmd = printf('cargo build --release && cd /d %s && %s', s:rust_ext_cwd, s:rust_ext_cmd)
" If Rust nightly and +python3 is unavailable, build the maple only.
if has('python3') && s:has_rust_nightly(v:false)
let cwd = fnamemodify(g:clap#autoload_dir, ':h')
if has('win32')
let cmd = printf('cargo build --release && cd /d %s && %s', s:rust_ext_cwd, s:rust_ext_cmd)
else
let cmd = 'make'
endif
call s:run_term(cmd, cwd, 'build maple binary and Python dynamic module successfully')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

built*

else
let cmd = 'make'
call clap#helper#build_maple()
endif
call s:run_term(cmd, cwd, 'build maple and Rust extension successfully')
else
call clap#helper#echo_warn('cargo not found, skipped building maple and the Rust extension.')
call clap#helper#echo_warn('cargo not found, skipped building maple binary and Python dynamic module.')
endif
endfunction

Expand Down