Skip to content

Commit c593835

Browse files
committed
feat: glibc 2.17 and musl prebuilt binaries
closes #160
1 parent 1baf475 commit c593835

File tree

5 files changed

+124
-58
lines changed

5 files changed

+124
-58
lines changed

.github/workflows/release.yaml

+37-9
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,42 @@ jobs:
1414
strategy:
1515
matrix:
1616
include:
17-
# Linux builds (statically linked for compatibility, have to use glibc for FFI)
18-
# TODO: check if we still need glibc on mlua
17+
## Linux builds
18+
# Glibc 2.31
1919
- os: ubuntu-latest
2020
target: x86_64-unknown-linux-gnu
2121
artifact_name: target/x86_64-unknown-linux-gnu/release/libblink_cmp_fuzzy.so
2222
- os: ubuntu-latest
2323
target: aarch64-unknown-linux-gnu
2424
artifact_name: target/aarch64-unknown-linux-gnu/release/libblink_cmp_fuzzy.so
25+
# Glibc 2.17
26+
- os: ubuntu-latest
27+
target: x86_64-unknown-linux-gnu
28+
target_name: x86_64-unknown-linux-gnu-legacy
29+
legacy: true
30+
artifact_name: target/x86_64-unknown-linux-gnu/release/libblink_cmp_fuzzy.so
31+
- os: ubuntu-latest
32+
target: aarch64-unknown-linux-gnu
33+
target_name: aarch64-unknown-linux-gnu-legacy
34+
legacy: true
35+
artifact_name: target/aarch64-unknown-linux-gnu/release/libblink_cmp_fuzzy.so
36+
# Musl 1.2.3
37+
- os: ubuntu-latest
38+
target: x86_64-unknown-linux-musl
39+
artifact_name: target/x86_64-unknown-linux-musl/release/libblink_cmp_fuzzy.so
40+
- os: ubuntu-latest
41+
target: aarch64-unknown-linux-musl
42+
artifact_name: target/aarch64-unknown-linux-musl/release/libblink_cmp_fuzzy.so
2543

26-
# macOS builds
44+
## macOS builds
2745
- os: macos-latest
2846
target: x86_64-apple-darwin
2947
artifact_name: target/x86_64-apple-darwin/release/libblink_cmp_fuzzy.dylib
3048
- os: macos-latest
3149
target: aarch64-apple-darwin
3250
artifact_name: target/aarch64-apple-darwin/release/libblink_cmp_fuzzy.dylib
3351

34-
# Windows builds
52+
## Windows builds
3553
- os: windows-latest
3654
target: x86_64-pc-windows-msvc
3755
artifact_name: target/x86_64-pc-windows-msvc/release/blink_cmp_fuzzy.dll
@@ -46,16 +64,26 @@ jobs:
4664
rustup target add ${{ matrix.target }}
4765
4866
- name: Build for Linux
49-
if: contains(matrix.os, 'ubuntu')
67+
if: contains(matrix.os, 'ubuntu') && !matrix.legacy
5068
run: |
5169
cargo install cross --git https://github.com/cross-rs/cross
52-
RUSTFLAGS="-C target-feature=-crt-static" cross build --release --target ${{ matrix.target }}
70+
cross build --release --target ${{ matrix.target }}
5371
mv "${{ matrix.artifact_name }}" "${{ matrix.target }}.so"
5472
73+
- name: Build for Linux (legacy)
74+
if: contains(matrix.os, 'ubuntu') && matrix.legacy
75+
run: |
76+
echo "[target.aarch64-unknown-linux-gnu]" >> Cross.toml
77+
echo "image = \"ghcr.io/cross-rs/${{ matrix.target }}:main-centos\"" >> Cross.toml
78+
79+
cargo install cross --git https://github.com/cross-rs/cross
80+
cross build --release --target ${{ matrix.target }}
81+
mv "${{ matrix.artifact_name }}" "${{ matrix.target_name || matrix.target }}.so"
82+
5583
- name: Build for macOS
5684
if: contains(matrix.os, 'macos')
5785
run: |
58-
# Ventura
86+
# Ventura (https://en.wikipedia.org/wiki/MacOS_version_history#Releases)
5987
MACOSX_DEPLOYMENT_TARGET="13" cargo build --release --target ${{ matrix.target }}
6088
mv "${{ matrix.artifact_name }}" "${{ matrix.target }}.dylib"
6189
@@ -68,8 +96,8 @@ jobs:
6896
- name: Upload artifacts
6997
uses: actions/upload-artifact@v4
7098
with:
71-
name: ${{ matrix.target }}
72-
path: ${{ matrix.target }}.*
99+
name: ${{ matrix.target_name || matrix.target }}
100+
path: ${{ matrix.target_name || matrix.target }}.*
73101

74102
release:
75103
name: Release

README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,20 @@ MiniDeps.add({
258258
-- controls which sorts to use and in which order, these three are currently the only allowed options
259259
sorts = { 'label', 'kind', 'score' },
260260

261-
prebuiltBinaries = {
261+
prebuilt_binaries = {
262262
-- Whether or not to automatically download a prebuilt binary from github. If this is set to `false`
263263
-- you will need to manually build the fuzzy binary dependencies by running `cargo build --release`
264264
download = true,
265-
-- When downloading a prebuilt binary force the downloader to resolve this version. If this is uset
265+
-- When downloading a prebuilt binary, force the downloader to resolve this version. If this is unset
266266
-- then the downloader will attempt to infer the version from the checked out git tag (if any).
267267
--
268268
-- Beware that if the FFI ABI changes while tracking main then this may result in blink breaking.
269-
forceVersion = nil,
269+
force_version = nil,
270+
-- When downloading a prebuilt binary, force the downloader to use this system triple. If this is unset
271+
-- then the downloader will attempt to infer the system triple from `jit.os` and `jit.arch`.
272+
--
273+
-- Beware that if the FFI ABI changes while tracking main then this may result in blink breaking.
274+
force_system_triple = nil,
270275
},
271276
},
272277

lua/blink/cmp/config.lua

+10-4
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,16 @@
8686

8787
--- @class blink.cmp.PrebuiltBinariesConfig
8888
--- @field download? boolean
89-
--- @field forceVersion? string | nil
89+
--- @field force_version? string | nil
90+
--- @field force_system_triple? string | nil
9091

9192
--- @class blink.cmp.FuzzyConfig
9293
--- @field use_typo_resistance? boolean
9394
--- @field use_frecency? boolean
9495
--- @field use_proximity? boolean
9596
--- @field max_items? number
9697
--- @field sorts? ("label" | "kind" | "score")[]
97-
--- @field prebuiltBinaries? blink.cmp.PrebuiltBinariesConfig
98+
--- @field prebuilt_binaries? blink.cmp.PrebuiltBinariesConfig
9899

99100
--- @class blink.cmp.WindowConfig
100101
--- @field autocomplete? blink.cmp.AutocompleteConfig
@@ -285,15 +286,20 @@ local config = {
285286
-- controls which sorts to use and in which order, these three are currently the only allowed options
286287
sorts = { 'label', 'kind', 'score' },
287288

288-
prebuiltBinaries = {
289+
prebuilt_binaries = {
289290
-- Whether or not to automatically download a prebuilt binary from github. If this is set to `false`
290291
-- you will need to manually build the fuzzy binary dependencies by running `cargo build --release`
291292
download = true,
292293
-- When downloading a prebuilt binary force the downloader to resolve this version. If this is uset
293294
-- then the downloader will attempt to infer the version from the checked out git tag (if any).
294295
--
295296
-- Beware that if the FFI ABI changes while tracking main then this may result in blink breaking.
296-
forceVersion = nil,
297+
force_version = nil,
298+
-- When downloading a prebuilt binary, force the downloader to use this system triple. If this is unset
299+
-- then the downloader will attempt to infer the system triple from `jit.os` and `jit.arch`.
300+
--
301+
-- Beware that if the FFI ABI changes while tracking main then this may result in blink breaking.
302+
force_system_triple = nil,
297303
},
298304
},
299305

lua/blink/cmp/fuzzy/download.lua

+65-38
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local download_config = require('blink.cmp.config').fuzzy.prebuiltBinaries
1+
local download_config = require('blink.cmp.config').fuzzy.prebuilt_binaries
22

33
local download = {}
44

@@ -15,40 +15,40 @@ local version_path = root_dir .. '../../../../target/release/version.txt'
1515

1616
--- @param callback fun(err: string | nil)
1717
function download.ensure_downloaded(callback)
18-
local function cb(err)
19-
vim.schedule(function() callback(err) end)
20-
end
18+
callback = vim.schedule_wrap(callback)
2119

22-
if not download_config.download then return cb() end
20+
if not download_config.download then return callback() end
2321

2422
download.get_git_tag(function(git_version_err, git_version)
25-
if git_version_err then return cb(git_version_err) end
23+
if git_version_err then return callback(git_version_err) end
2624

2725
download.get_downloaded_version(function(version_err, version)
2826
download.is_downloaded(function(downloaded)
29-
local target_version = download_config.forceVersion or git_version
27+
local target_version = download_config.force_version or git_version
3028

3129
-- not built locally, not a git tag, error
3230
if not downloaded and not target_version then
33-
return cb(
34-
"Can't download from github due to not being on a git tag and no fuzzy.prebuiltBinaries.forceVersion set, but found no built version of the library. "
35-
.. 'Either run `cargo build --release` via your package manager, switch to a git tag, or set `fuzzy.prebuiltBinaries.forceVersion` in config. '
31+
return callback(
32+
"Can't download from github due to not being on a git tag and no fuzzy.prebuilt_binaries.force_version set, but found no built version of the library. "
33+
.. 'Either run `cargo build --release` via your package manager, switch to a git tag, or set `fuzzy.prebuilt_binaries.force_version` in config. '
3634
.. 'See the README for more info.'
3735
)
3836
end
3937
-- built locally, ignore
40-
if downloaded and (version_err or version == nil) then return cb() end
38+
if downloaded and (version_err or version == nil) then return callback() end
4139
-- already downloaded and the correct version
42-
if version == target_version and downloaded then return cb() end
40+
if version == target_version and downloaded then return callback() end
4341
-- unknown state
44-
if not target_version then return cb('Unknown error while getting pre-built binary. Consider re-installing') end
42+
if not target_version then
43+
return callback('Unknown error while getting pre-built binary. Consider re-installing')
44+
end
4545

4646
-- download from github and set version
4747
download.from_github(target_version, function(download_err)
48-
if download_err then return cb(download_err) end
48+
if download_err then return callback(download_err) end
4949
download.set_downloaded_version(target_version, function(set_err)
50-
if set_err then return cb(set_err) end
51-
cb()
50+
if set_err then return callback(set_err) end
51+
callback()
5252
end)
5353
end)
5454
end)
@@ -85,22 +85,23 @@ end
8585
--- @param tag string
8686
--- @param cb fun(err: string | nil)
8787
function download.from_github(tag, cb)
88-
local system_triple = download.get_system_triple()
89-
if not system_triple then
90-
return cb(
91-
'Your system is not supported by pre-built binaries. You must run cargo build --release via your package manager with rust nightly. See the README for more info.'
92-
)
93-
end
88+
download.get_system_triple(function(system_triple)
89+
if not system_triple then
90+
return cb(
91+
'Your system is not supported by pre-built binaries. You must run cargo build --release via your package manager with rust nightly. See the README for more info.'
92+
)
93+
end
9494

95-
local url = 'https://github.com/saghen/blink.cmp/releases/download/'
96-
.. tag
97-
.. '/'
98-
.. system_triple
99-
.. download.get_lib_extension()
95+
local url = 'https://github.com/saghen/blink.cmp/releases/download/'
96+
.. tag
97+
.. '/'
98+
.. system_triple
99+
.. download.get_lib_extension()
100100

101-
vim.system({ 'curl', '--create-dirs', '-fLo', download.lib_path, url }, {}, function(out)
102-
if out.code ~= 0 then cb('Failed to download pre-build binaries: ' .. out.stderr) end
103-
cb()
101+
vim.system({ 'curl', '--create-dirs', '-fLo', download.lib_path, url }, {}, function(out)
102+
if out.code ~= 0 then cb('Failed to download pre-build binaries: ' .. out.stderr) end
103+
cb()
104+
end)
104105
end)
105106
end
106107

@@ -129,18 +130,44 @@ function download.set_downloaded_version(version, cb)
129130
end)
130131
end
131132

132-
--- @return string | nil
133-
function download.get_system_triple()
133+
--- @param cb fun(triple: string | nil)
134+
function download.get_system_triple(cb)
135+
if download_config.force_system_triple then return cb(download_config.force_system_triple) end
136+
137+
if jit.os:lower() == 'mac' or jit.os:lower() == 'osx' then
138+
if jit.arch:lower():match('arm') then return cb('aarch64-apple-darwin') end
139+
if jit.arch:lower():match('x64') then return cb('x86_64-apple-darwin') end
140+
elseif jit.os:lower() == 'windows' then
141+
if jit.arch:lower():match('x64') then return cb('x86_64-pc-windows-msvc') end
142+
elseif jit.os:lower() == 'linux' then
143+
vim.system({ 'uname', '-a' }, {}, function(out)
144+
local libc = 'gnu'
145+
if out.stdout:lower():match('alpine') then libc = 'musl' end
146+
147+
if jit.arch:lower():match('arm') then return cb('aarch64-unknown-linux-' .. libc) end
148+
if jit.arch:lower():match('x64') then return cb('x86_64-unknown-linux-' .. libc) end
149+
return cb(nil)
150+
end)
151+
else
152+
return cb(nil)
153+
end
154+
end
155+
156+
function download.get_system_triple_sync()
157+
if download_config.force_system_triple then return download_config.force_system_triple end
158+
134159
if jit.os:lower() == 'mac' or jit.os:lower() == 'osx' then
135160
if jit.arch:lower():match('arm') then return 'aarch64-apple-darwin' end
136161
if jit.arch:lower():match('x64') then return 'x86_64-apple-darwin' end
137-
end
138-
if jit.os:lower() == 'windows' then
162+
elseif jit.os:lower() == 'windows' then
139163
if jit.arch:lower():match('x64') then return 'x86_64-pc-windows-msvc' end
140-
end
141-
if jit.os:lower() ~= 'windows' then
142-
if jit.arch:lower():match('arm') then return 'aarch64-unknown-linux-gnu' end
143-
if jit.arch:lower():match('x64') then return 'x86_64-unknown-linux-gnu' end
164+
elseif jit.os:lower() == 'linux' then
165+
local libc = 'gnu'
166+
local out = vim.system({ 'uname', '-a' }, {}):wait()
167+
if out.stdout:lower():match('alpine') then libc = 'musl' end
168+
169+
if jit.arch:lower():match('arm') then return 'aarch64-unknown-linux-' .. libc end
170+
if jit.arch:lower():match('x64') then return 'x86_64-unknown-linux-' .. libc end
144171
end
145172
end
146173

lua/blink/cmp/health.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
local M = {}
1+
local health = {}
22
local download = require('blink.cmp.fuzzy.download')
33

4-
M.check = function()
4+
health.check = function()
55
vim.health.start('blink.cmp healthcheck')
66

77
local required_executables = { 'curl', 'git' }
@@ -14,7 +14,7 @@ M.check = function()
1414
end
1515

1616
-- check if os is supported
17-
local system_triple = download.get_system_triple()
17+
local system_triple = download.get_system_triple_sync()
1818
if system_triple then
1919
vim.health.ok('Your system is supported by pre-built binaries (' .. system_triple .. ')')
2020
else
@@ -32,4 +32,4 @@ M.check = function()
3232
vim.health.warn('blink_cmp_fuzzy lib is not downloaded/built')
3333
end
3434
end
35-
return M
35+
return health

0 commit comments

Comments
 (0)