mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-18 03:10:04 -04:00
fix: add stricter cc options (#5063)
This commit is contained in:
parent
f13420ccff
commit
26302f412f
1 changed files with 30 additions and 2 deletions
|
|
@ -307,6 +307,21 @@ local function do_download_git(logger, repo, project_name, cache_dir, revision,
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- @type table<string,table<string,boolean>>
|
||||||
|
local cc_args_cache = vim.defaulttable()
|
||||||
|
|
||||||
|
--- @param cc string
|
||||||
|
--- @param arg string
|
||||||
|
--- @return boolean
|
||||||
|
local function test_cc_arg(cc, arg)
|
||||||
|
if cc_args_cache[cc][arg] == nil then
|
||||||
|
cc_args_cache[cc][arg] = system({ cc, '-xc', '-', arg }, {
|
||||||
|
stdin = 'int main(void) { return 0; }',
|
||||||
|
}).code == 0
|
||||||
|
end
|
||||||
|
return cc_args_cache[cc][arg]
|
||||||
|
end
|
||||||
|
|
||||||
---@param executables string[]
|
---@param executables string[]
|
||||||
---@return string?
|
---@return string?
|
||||||
function M.select_executable(executables)
|
function M.select_executable(executables)
|
||||||
|
|
@ -359,6 +374,13 @@ local function select_compiler_args(repo, compiler)
|
||||||
ismac and '-bundle' or '-shared',
|
ismac and '-bundle' or '-shared',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--- @param arg string
|
||||||
|
local function add_cc_arg(arg)
|
||||||
|
if test_cc_arg(compiler, arg) then
|
||||||
|
args[#args + 1] = arg
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if
|
if
|
||||||
#vim.iter.filter(
|
#vim.iter.filter(
|
||||||
--- @param file string
|
--- @param file string
|
||||||
|
|
@ -370,11 +392,17 @@ local function select_compiler_args(repo, compiler)
|
||||||
repo.files
|
repo.files
|
||||||
) > 0
|
) > 0
|
||||||
then
|
then
|
||||||
table.insert(args, '-lstdc++')
|
add_cc_arg('-lstdc++')
|
||||||
end
|
end
|
||||||
|
|
||||||
if not iswin then
|
if not iswin then
|
||||||
table.insert(args, '-fPIC')
|
add_cc_arg('-Wall')
|
||||||
|
add_cc_arg('-Wextra')
|
||||||
|
add_cc_arg('-fPIC')
|
||||||
|
|
||||||
|
-- Make sure we don't compile in any unresolved symbols, otherwise nvim will
|
||||||
|
-- just exit (not even crash)
|
||||||
|
add_cc_arg('-Werror=implicit-function-declaration')
|
||||||
end
|
end
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue