1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
-- __________________
-- < Here be dragons! >
-- ------------------
-- \ ^ /^
-- \ / \ // \
-- \ |\___/| / \// .\
-- \ /O O \__ / // | \ \ *----*
-- / / \/_/ // | \ \ \ |
-- @___@` \/_ // | \ \ \/\ \
-- 0/0/| \/_ // | \ \ \ \
-- 0/0/0/0/| \/// | \ \ | |
-- 0/0/0/0/0/_|_ / ( // | \ _\ | /
-- 0/0/0/0/0/0/`/,_ _ _/ ) ; -. | _ _\.-~ / /
-- ,-} _ *-.|.-~-. .~ ~
-- \ \__/ `/\ / ~-. _ .-~ /
-- \____(@@) *. } { /
-- ( (--) .----~-.\ \-` .~
-- //__\\ \__ Ack! ///.----..< \ _ -~
-- // \\ ///-._ _ _ _ _ _ _{^ - - - - ~
--
local server = require "nvim-lsp-installer.server"
local path = require "nvim-lsp-installer.path"
local installers = require "nvim-lsp-installer.installers"
local Data = require "nvim-lsp-installer.data"
local std = require "nvim-lsp-installer.installers.std"
local platform = require "nvim-lsp-installer.platform"
local context = require "nvim-lsp-installer.installers.context"
local process = require "nvim-lsp-installer.process"
local fs = require "nvim-lsp-installer.fs"
local coalesce, when, list_not_nil = Data.coalesce, Data.when, Data.list_not_nil
return function(name, root_dir)
local llvm_installer
do
---@param version string
---@param os_distribution table<string, string>|nil
---@return string|nil
local function get_archive_name(version, os_distribution)
local name_template = coalesce(when(
platform.is_linux,
coalesce(
when(
platform.arch == "x64",
coalesce(
when(
os_distribution.id == "ubuntu" and os_distribution.version.major >= 20,
"clang+llvm-%s-x86_64-linux-gnu-ubuntu-20.04"
),
when(
os_distribution.id == "ubuntu" and os_distribution.version.major >= 16,
"clang+llvm-%s-x86_64-linux-gnu-ubuntu-16.04"
),
-- the Ubuntu dist is allegedly the most suitable cross-platform one, so we default to it
"clang+llvm-%s-x86_64-linux-gnu-ubuntu-16.04"
)
),
when(platform.arch == "arm64", "clang+llvm-%s-aarch64-linux-gnu"),
when(platform.arch == "armv7", "clang+llvm-%s-armv7a-linux-gnueabihf"),
when(platform.arch == "x86", "clang+llvm-%s-i386-unknown-freebsd13")
)
))
return name_template and name_template:format(version)
end
---@param version string
local function normalize_version(version)
local s = version:gsub("^llvmorg%-", "")
return s
end
llvm_installer = installers.branch_context {
context.use_os_distribution(),
context.set(function(ctx)
-- We unset the requested version for llvm because it's not the primary target - the user's requested version should only apply to ccls.
ctx.requested_server_version = nil
end),
context.capture(function(ctx)
return context.use_github_release_file("llvm/llvm-project", function(version)
-- Strip the "llvmorg-" prefix from tags (llvm releases tags like llvmorg-13.0.0)
local archive_name = get_archive_name(normalize_version(version), ctx.os_distribution)
return archive_name and ("%s.tar.xz"):format(archive_name)
end)
end),
context.capture(function(ctx)
return installers.pipe {
std.untarxz_remote(ctx.github_release_file),
std.rename(
get_archive_name(normalize_version(ctx.requested_server_version), ctx.os_distribution),
"llvm"
),
-- We move the clang headers out, because they need to be persisted
std.rename(
path.concat { "llvm", "lib", "clang", normalize_version(ctx.requested_server_version) },
"clang-resource"
),
}
end),
}
end
local ccls_installer = installers.pipe {
std.git_clone("https://github.com/MaskRay/ccls", {
directory = "ccls-git",
recursive = true,
}),
function(server, callback, ctx)
local c = process.chain {
cwd = path.concat { ctx.install_dir, "ccls-git" },
stdio_sink = ctx.stdio_sink,
}
local clang_resource_dir = path.concat { server.root_dir, "clang-resource" }
c.run(
"cmake",
list_not_nil(
"-DCMAKE_BUILD_TYPE=Release",
"-DUSE_SYSTEM_RAPIDJSON=OFF",
"-DCMAKE_FIND_FRAMEWORK=LAST",
"-Wno-dev",
("-DCMAKE_INSTALL_PREFIX=%s"):format(ctx.install_dir),
("-DCMAKE_PREFIX_PATH=%s"):format(ctx.llvm_dir),
when(platform.is_mac, "-DCMAKE_OSX_SYSROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"),
when(platform.is_linux, ("-DCLANG_RESOURCE_DIR=%s"):format(clang_resource_dir))
)
)
c.run("make", { "install" })
c.spawn(callback)
end,
std.rmrf "ccls-git",
}
local linux_ccls_installer = installers.pipe {
llvm_installer,
context.set(function(ctx)
ctx.llvm_dir = path.concat { ctx.install_dir, "llvm" }
end),
ccls_installer,
std.rmrf "llvm",
}
local mac_ccls_installer = installers.pipe {
context.use_homebrew_prefix(),
context.set(function(ctx)
ctx.llvm_dir = path.concat { ctx.homebrew_prefix, "opt", "llvm" }
end),
function(_, callback, ctx)
if not fs.dir_exists(ctx.llvm_dir) then
ctx.stdio_sink.stderr(
(
"LLVM does not seem to be installed on this system (looked in %q). Please install LLVM via Homebrew:\n $ brew install llvm\n"
):format(ctx.llvm_dir)
)
callback(false)
return
end
callback(true)
end,
ccls_installer,
}
return server.Server:new {
name = name,
root_dir = root_dir,
homepage = "https://github.com/MaskRay/ccls",
languages = { "c", "c++", "objective-c" },
installer = installers.when {
mac = mac_ccls_installer,
linux = linux_ccls_installer,
},
default_options = {
cmd_env = {
PATH = process.extend_path { path.concat { root_dir, "bin" } },
},
},
}
end
|