mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-16 10:20:11 -04:00
Support TSInstall on Winddows with Clang
This commit is contained in:
parent
930591b689
commit
4f1a464027
1 changed files with 106 additions and 42 deletions
|
|
@ -62,14 +62,82 @@ local function select_executable(executables)
|
||||||
return vim.tbl_filter(function(c) return fn.executable(c) == 1 end, executables)[1]
|
return vim.tbl_filter(function(c) return fn.executable(c) == 1 end, executables)[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function select_args(repo)
|
||||||
|
if fn.has('win32') then
|
||||||
|
return {
|
||||||
|
'-o',
|
||||||
|
'parser.so',
|
||||||
|
'-I./src',
|
||||||
|
repo.files,
|
||||||
|
'-shared',
|
||||||
|
'-Os',
|
||||||
|
'-lstdc++',
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return {
|
||||||
|
'-o',
|
||||||
|
'parser.so',
|
||||||
|
'-I./src',
|
||||||
|
repo.files,
|
||||||
|
'-shared',
|
||||||
|
'-Os',
|
||||||
|
'-lstdc++',
|
||||||
|
'-fPIC'
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function select_install_rm_cmd(cache_folder, project_name)
|
||||||
|
if fn.has('win32') then
|
||||||
|
dir = cache_folder ..'\\'.. project_name
|
||||||
|
return {
|
||||||
|
cmd = 'cmd',
|
||||||
|
opts = {
|
||||||
|
args = { '/C', 'if', 'exist', dir, 'rmdir', '/s', '/q', dir },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return {
|
||||||
|
cmd = 'rm',
|
||||||
|
opts = {
|
||||||
|
args = { 'rf', cache_folder..'/'..project_name },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function select_mv_cmd(compile_location, parser_lib_name)
|
||||||
|
if fn.has('win32') then
|
||||||
|
return {
|
||||||
|
cmd = 'cmd',
|
||||||
|
opts = {
|
||||||
|
args = { '/C', 'move', compile_location..'\\parser.so', parser_lib_name },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return {
|
||||||
|
cmd = 'mv',
|
||||||
|
opts = {
|
||||||
|
args = { compile_location..'/parser.so', parser_lib_name }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
local function run_install(cache_folder, package_path, lang, repo, with_sync)
|
local function run_install(cache_folder, package_path, lang, repo, with_sync)
|
||||||
parsers.reset_cache()
|
parsers.reset_cache()
|
||||||
|
|
||||||
|
local path_sep = '/'
|
||||||
|
if fn.has('win32') then
|
||||||
|
path_sep = '\\'
|
||||||
|
end
|
||||||
|
|
||||||
local project_name = 'tree-sitter-'..lang
|
local project_name = 'tree-sitter-'..lang
|
||||||
local project_repo = cache_folder..'/'..project_name
|
local project_repo = cache_folder..path_sep..project_name
|
||||||
-- compile_location only needed for typescript installs.
|
-- compile_location only needed for typescript installs.
|
||||||
local compile_location = cache_folder..'/'..(repo.location or project_name)
|
local compile_location = cache_folder..path_sep..(repo.location or project_name)
|
||||||
local parser_lib_name = package_path.."/parser/"..lang..".so"
|
local parser_lib_name = package_path..path_sep.."parser"..path_sep..lang..".so"
|
||||||
|
|
||||||
local compilers = { "cc", "gcc", "clang" }
|
local compilers = { "cc", "gcc", "clang" }
|
||||||
local cc = select_executable(compilers)
|
local cc = select_executable(compilers)
|
||||||
|
|
@ -79,12 +147,7 @@ local function run_install(cache_folder, package_path, lang, repo, with_sync)
|
||||||
end
|
end
|
||||||
|
|
||||||
local command_list = {
|
local command_list = {
|
||||||
{
|
select_install_rm_cmd(cache_folder, project_name),
|
||||||
cmd = 'rm',
|
|
||||||
opts = {
|
|
||||||
args = { '-rf', project_repo },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
cmd = 'git',
|
cmd = 'git',
|
||||||
info = 'Downloading...',
|
info = 'Downloading...',
|
||||||
|
|
@ -99,31 +162,12 @@ local function run_install(cache_folder, package_path, lang, repo, with_sync)
|
||||||
info = 'Compiling...',
|
info = 'Compiling...',
|
||||||
err = 'Error during compilation',
|
err = 'Error during compilation',
|
||||||
opts = {
|
opts = {
|
||||||
args = vim.tbl_flatten({
|
args = vim.tbl_flatten(select_args(repo)),
|
||||||
'-o',
|
|
||||||
'parser.so',
|
|
||||||
'-I./src',
|
|
||||||
repo.files,
|
|
||||||
'-shared',
|
|
||||||
'-Os',
|
|
||||||
'-lstdc++',
|
|
||||||
'-fPIC',
|
|
||||||
}),
|
|
||||||
cwd = compile_location
|
cwd = compile_location
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
select_mv_cmd(compile_location, parser_lib_name),
|
||||||
cmd = 'mv',
|
select_install_rm_cmd(cache_folder, project_name)
|
||||||
opts = {
|
|
||||||
args = { compile_location..'/parser.so', parser_lib_name }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
cmd = 'rm',
|
|
||||||
opts = {
|
|
||||||
args = { '-rf', project_repo }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if with_sync then
|
if with_sync then
|
||||||
|
|
@ -200,7 +244,34 @@ function M.update(lang)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function select_uninstall_rm_cmd(lang, parser_lib)
|
||||||
|
if fn.has('win32') then
|
||||||
|
return {
|
||||||
|
cmd = 'cmd',
|
||||||
|
opts = {
|
||||||
|
args = { '/C', 'if', 'exist', parser_lib, 'del', parser_lib },
|
||||||
|
},
|
||||||
|
info = "Uninstalling parser for "..lang,
|
||||||
|
err = "Could not delete "..parser_lib,
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return {
|
||||||
|
cmd = 'rm',
|
||||||
|
opts = {
|
||||||
|
args = { parser_lib },
|
||||||
|
},
|
||||||
|
info = "Uninstalling parser for "..lang,
|
||||||
|
err = "Could not delete "..parser_lib,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function M.uninstall(lang)
|
function M.uninstall(lang)
|
||||||
|
local path_sep = '/'
|
||||||
|
if fn.has('win32') then
|
||||||
|
path_sep = '\\'
|
||||||
|
end
|
||||||
|
|
||||||
if lang == 'all' then
|
if lang == 'all' then
|
||||||
local installed = info.installed_parsers()
|
local installed = info.installed_parsers()
|
||||||
for _, lang in pairs(installed) do
|
for _, lang in pairs(installed) do
|
||||||
|
|
@ -212,19 +283,12 @@ function M.uninstall(lang)
|
||||||
print(err)
|
print(err)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local parser_lib = package_path.."/parser/"..lang..".so"
|
local parser_lib = package_path..path_sep.."parser"..path_sep..lang..".so"
|
||||||
|
|
||||||
local command_list = {
|
local command_list = {
|
||||||
{
|
select_uninstall_rm_cmd(lang, parser_lib)
|
||||||
cmd = 'rm',
|
}
|
||||||
opts = {
|
M.iter_cmd(command_list, 1, lang, 'Treesitter parser for '..lang..' has been uninstalled')
|
||||||
args = { parser_lib },
|
|
||||||
},
|
|
||||||
info = "Uninstalling parser for "..lang,
|
|
||||||
err = "Could not delete "..parser_lib,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
M.iter_cmd(command_list, 1, lang, 'Treesitter parser for '..lang..' has been uninstalled')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue