@@ -2,6 +2,21 @@ local download_config = require('blink.cmp.config').fuzzy.prebuilt_binaries
2
2
3
3
local download = {}
4
4
5
+ download .system_triples = {
6
+ mac = {
7
+ arm = ' aarch64-apple-darwin' ,
8
+ x64 = ' x86_64-apple-darwin' ,
9
+ },
10
+ windows = {
11
+ x64 = ' x86_64-pc-windows-msvc' ,
12
+ },
13
+ linux = {
14
+ android = ' aarch64-linux-android' ,
15
+ arm = function (libc ) return ' aarch64-unknown-linux-' .. libc end ,
16
+ x64 = function (libc ) return ' x86_64-unknown-linux-' .. libc end ,
17
+ },
18
+ }
19
+
5
20
--- @return string
6
21
function download .get_lib_extension ()
7
22
if jit .os :lower () == ' mac' or jit .os :lower () == ' osx' then return ' .dylib' end
@@ -134,41 +149,49 @@ function download.set_downloaded_version(version, cb)
134
149
end )
135
150
end
136
151
137
- --- @param cb fun ( triple : string | nil )
152
+ --- @return string , string
153
+ function download .get_system_info ()
154
+ local os = jit .os :lower ()
155
+ if os == ' osx' then os = ' mac' end
156
+ local arch = jit .arch :lower ():match (' arm' ) and ' arm' or jit .arch :lower ():match (' x64' ) and ' x64' or nil
157
+ return os , arch
158
+ end
159
+
160
+ --- @param cb fun ( triple : string | function | nil )
138
161
function download .get_system_triple (cb )
139
162
if download_config .force_system_triple then return cb (download_config .force_system_triple ) end
140
163
141
- if jit . os : lower () == ' mac ' or jit . os : lower () == ' osx ' then
142
- if jit . arch : lower (): match ( ' arm ' ) then return cb ( ' aarch64-apple-darwin ' ) end
143
- if jit . arch : lower (): match ( ' x64 ' ) then return cb ( ' x86_64-apple-darwin ' ) end
144
- elseif jit . os : lower () == ' windows ' then
145
- if jit . arch : lower (): match ( ' x64 ' ) then return cb (' x86_64-pc-windows-msvc ' ) end
146
- elseif jit . os : lower () == ' linux ' then
164
+ local os , arch = download . get_system_info ()
165
+ local triples = download . system_triples [ os ]
166
+
167
+ if os == ' linux ' then
168
+ if vim . fn . has ( ' android ' ) == 1 then return cb (triples . android ) end
169
+
147
170
vim .uv .fs_stat (' /etc/alpine-release' , function (err , is_alpine )
148
171
local libc = (not err and is_alpine ) and ' musl' or ' gnu'
149
- if jit .arch :lower ():match (' arm' ) then return cb (' aarch64-unknown-linux-' .. libc ) end
150
- if jit .arch :lower ():match (' x64' ) then return cb (' x86_64-unknown-linux-' .. libc ) end
151
- return cb (nil )
172
+ local triple = triples [arch ]
173
+ return cb (triple and type (triple ) == ' function' and triple (libc ) or triple )
152
174
end )
153
175
else
154
- return cb (nil )
176
+ return cb (triples [ arch ] )
155
177
end
156
178
end
157
179
158
180
function download .get_system_triple_sync ()
159
181
if download_config .force_system_triple then return download_config .force_system_triple end
160
182
161
- if jit . os : lower () == ' mac ' or jit . os : lower () == ' osx ' then
162
- if jit . arch : lower (): match ( ' arm ' ) then return ' aarch64-apple-darwin ' end
163
- if jit . arch : lower (): match ( ' x64 ' ) then return ' x86_64-apple-darwin ' end
164
- elseif jit . os : lower () == ' windows ' then
165
- if jit . arch : lower (): match ( ' x64 ' ) then return ' x86_64-pc-windows-msvc ' end
166
- elseif jit . os : lower () == ' linux ' then
183
+ local os , arch = download . get_system_info ()
184
+ local triples = download . system_triples [ os ]
185
+
186
+ if os == ' linux ' then
187
+ if vim . fn . has ( ' android ' ) == 1 then return triples . android end
188
+
167
189
local success , is_alpine = pcall (vim .uv .fs_stat , ' /etc/alpine-release' )
168
190
local libc = (success and is_alpine ) and ' musl' or ' gnu'
169
-
170
- if jit .arch :lower ():match (' arm' ) then return ' aarch64-unknown-linux-' .. libc end
171
- if jit .arch :lower ():match (' x64' ) then return ' x86_64-unknown-linux-' .. libc end
191
+ local triple = triples [arch ]
192
+ return triple and type (triple ) == ' function' and triple (libc ) or triple
193
+ else
194
+ return triples [arch ]
172
195
end
173
196
end
174
197
0 commit comments