aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2023-07-04 22:42:25 +0100
committerChristian Clason <c.clason@uni-graz.at>2025-05-12 18:43:40 +0200
commit26302f412f6fe1ff968802888a8b8419accd6462 (patch)
tree8558769b41aa5517f080184310d0960af9b3a6d2
parentfix: remove upstreamed directives (diff)
downloadnvim-treesitter-26302f412f6fe1ff968802888a8b8419accd6462.tar
nvim-treesitter-26302f412f6fe1ff968802888a8b8419accd6462.tar.gz
nvim-treesitter-26302f412f6fe1ff968802888a8b8419accd6462.tar.bz2
nvim-treesitter-26302f412f6fe1ff968802888a8b8419accd6462.tar.lz
nvim-treesitter-26302f412f6fe1ff968802888a8b8419accd6462.tar.xz
nvim-treesitter-26302f412f6fe1ff968802888a8b8419accd6462.tar.zst
nvim-treesitter-26302f412f6fe1ff968802888a8b8419accd6462.zip
fix: add stricter cc options (#5063)
-rw-r--r--lua/nvim-treesitter/install.lua32
1 files changed, 30 insertions, 2 deletions
diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua
index ff5cff036..f4112d880 100644
--- a/lua/nvim-treesitter/install.lua
+++ b/lua/nvim-treesitter/install.lua
@@ -307,6 +307,21 @@ local function do_download_git(logger, repo, project_name, cache_dir, revision,
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[]
---@return string?
function M.select_executable(executables)
@@ -359,6 +374,13 @@ local function select_compiler_args(repo, compiler)
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
#vim.iter.filter(
--- @param file string
@@ -370,11 +392,17 @@ local function select_compiler_args(repo, compiler)
repo.files
) > 0
then
- table.insert(args, '-lstdc++')
+ add_cc_arg('-lstdc++')
end
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
return args