diff --git a/.cargo/config.toml b/.cargo/config.toml index ed561c71..88bd7e3a 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -15,3 +15,13 @@ rustflags = ["-C", "target-feature=-crt-static"] [target.aarch64-unknown-linux-musl] rustflags = ["-C", "target-feature=-crt-static"] + +[target.aarch64-linux-android] +rustflags = [ + "-C", + "linker=aarch64-linux-android-clang", + "-C", + "link-args=-rdynamic", + "-C", + "default-linker-libraries", +] diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 8b90d00d..77086b33 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -43,6 +43,11 @@ jobs: target: x86_64-pc-windows-msvc artifact_name: target/x86_64-pc-windows-msvc/release/blink_cmp_fuzzy.dll + # Android builds + - os: ubuntu-latest + target: aarch64-linux-android + artifact_name: target/aarch64-linux-android/release/libblink_cmp_fuzzy.so + steps: - uses: actions/checkout@v4 diff --git a/lua/blink/cmp/fuzzy/download.lua b/lua/blink/cmp/fuzzy/download.lua index da999ce8..fe2fda24 100644 --- a/lua/blink/cmp/fuzzy/download.lua +++ b/lua/blink/cmp/fuzzy/download.lua @@ -2,6 +2,21 @@ local download_config = require('blink.cmp.config').fuzzy.prebuilt_binaries local download = {} +download.system_triples = { + mac = { + arm = 'aarch64-apple-darwin', + x64 = 'x86_64-apple-darwin', + }, + windows = { + x64 = 'x86_64-pc-windows-msvc', + }, + linux = { + android = 'aarch64-linux-android', + arm = function(libc) return 'aarch64-unknown-linux-' .. libc end, + x64 = function(libc) return 'x86_64-unknown-linux-' .. libc end, + }, +} + --- @return string function download.get_lib_extension() 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) end) end ---- @param cb fun(triple: string | nil) +--- @return string, string +function download.get_system_info() + local os = jit.os:lower() + if os == 'osx' then os = 'mac' end + local arch = jit.arch:lower():match('arm') and 'arm' or jit.arch:lower():match('x64') and 'x64' or nil + return os, arch +end + +--- @param cb fun(triple: string | function | nil) function download.get_system_triple(cb) if download_config.force_system_triple then return cb(download_config.force_system_triple) end - if jit.os:lower() == 'mac' or jit.os:lower() == 'osx' then - if jit.arch:lower():match('arm') then return cb('aarch64-apple-darwin') end - if jit.arch:lower():match('x64') then return cb('x86_64-apple-darwin') end - elseif jit.os:lower() == 'windows' then - if jit.arch:lower():match('x64') then return cb('x86_64-pc-windows-msvc') end - elseif jit.os:lower() == 'linux' then + local os, arch = download.get_system_info() + local triples = download.system_triples[os] + + if os == 'linux' then + if vim.fn.has('android') == 1 then return cb(triples.android) end + vim.uv.fs_stat('/etc/alpine-release', function(err, is_alpine) local libc = (not err and is_alpine) and 'musl' or 'gnu' - if jit.arch:lower():match('arm') then return cb('aarch64-unknown-linux-' .. libc) end - if jit.arch:lower():match('x64') then return cb('x86_64-unknown-linux-' .. libc) end - return cb(nil) + local triple = triples[arch] + return cb(triple and type(triple) == 'function' and triple(libc) or triple) end) else - return cb(nil) + return cb(triples[arch]) end end function download.get_system_triple_sync() if download_config.force_system_triple then return download_config.force_system_triple end - if jit.os:lower() == 'mac' or jit.os:lower() == 'osx' then - if jit.arch:lower():match('arm') then return 'aarch64-apple-darwin' end - if jit.arch:lower():match('x64') then return 'x86_64-apple-darwin' end - elseif jit.os:lower() == 'windows' then - if jit.arch:lower():match('x64') then return 'x86_64-pc-windows-msvc' end - elseif jit.os:lower() == 'linux' then + local os, arch = download.get_system_info() + local triples = download.system_triples[os] + + if os == 'linux' then + if vim.fn.has('android') == 1 then return triples.android end + local success, is_alpine = pcall(vim.uv.fs_stat, '/etc/alpine-release') local libc = (success and is_alpine) and 'musl' or 'gnu' - - if jit.arch:lower():match('arm') then return 'aarch64-unknown-linux-' .. libc end - if jit.arch:lower():match('x64') then return 'x86_64-unknown-linux-' .. libc end + local triple = triples[arch] + return triple and type(triple) == 'function' and triple(libc) or triple + else + return triples[arch] end end