Skip to content

Commit 11a50fe

Browse files
feat: add prebuilt binaries for android (#362)
1 parent 392458e commit 11a50fe

File tree

3 files changed

+57
-20
lines changed

3 files changed

+57
-20
lines changed

.cargo/config.toml

+10
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,13 @@ rustflags = ["-C", "target-feature=-crt-static"]
1515

1616
[target.aarch64-unknown-linux-musl]
1717
rustflags = ["-C", "target-feature=-crt-static"]
18+
19+
[target.aarch64-linux-android]
20+
rustflags = [
21+
"-C",
22+
"linker=aarch64-linux-android-clang",
23+
"-C",
24+
"link-args=-rdynamic",
25+
"-C",
26+
"default-linker-libraries",
27+
]

.github/workflows/release.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ jobs:
2929
- os: ubuntu-latest
3030
target: aarch64-unknown-linux-musl
3131
artifact_name: target/aarch64-unknown-linux-musl/release/libblink_cmp_fuzzy.so
32+
# Android(Termux)
33+
- os: ubuntu-latest
34+
target: aarch64-linux-android
35+
artifact_name: target/aarch64-linux-android/release/libblink_cmp_fuzzy.so
3236

3337
## macOS builds
3438
- os: macos-latest

lua/blink/cmp/fuzzy/download.lua

+43-20
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@ local download_config = require('blink.cmp.config').fuzzy.prebuilt_binaries
22

33
local download = {}
44

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+
520
--- @return string
621
function download.get_lib_extension()
722
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)
134149
end)
135150
end
136151

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)
138161
function download.get_system_triple(cb)
139162
if download_config.force_system_triple then return cb(download_config.force_system_triple) end
140163

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+
147170
vim.uv.fs_stat('/etc/alpine-release', function(err, is_alpine)
148171
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)
152174
end)
153175
else
154-
return cb(nil)
176+
return cb(triples[arch])
155177
end
156178
end
157179

158180
function download.get_system_triple_sync()
159181
if download_config.force_system_triple then return download_config.force_system_triple end
160182

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+
167189
local success, is_alpine = pcall(vim.uv.fs_stat, '/etc/alpine-release')
168190
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]
172195
end
173196
end
174197

0 commit comments

Comments
 (0)