Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ffi): handle cargo library naming conventions for windows binaries #74

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build-ffi-bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ end
$(cat "$(pwd)/lua/blink/cmp/fuzzy/ffi.lua")
" > "$(pwd)/lua/blink/cmp/fuzzy/ffi.lua"

sed -i "s/ffi\.load.'blink-cmp-fuzzy'./ffi.load(debug.getinfo(1).source:match('@?(.*\/)') .. '..\/..\/..\/..\/target\/release\/libblink_cmp_fuzzy\' .. get_shared_lib_extension())/" "$(pwd)/lua/blink/cmp/fuzzy/ffi.lua"
sed -i "s|local rust = ffi\.load('blink-cmp-fuzzy')|local ok, rust = pcall(function() return ffi.load(debug.getinfo(1).source:match('@?(.*/)') .. '../../../../target/release/libblink_cmp_fuzzy' .. get_shared_lib_extension()) end)\nif not ok then\n rust = ffi.load(debug.getinfo(1).source:match('@?(.*/)') .. '../../../../target/release/blink_cmp_fuzzy' .. get_shared_lib_extension())\nend|" "$(pwd)/lua/blink/cmp/fuzzy/ffi.lua"
9 changes: 8 additions & 1 deletion lua/blink/cmp/fuzzy/download.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ end

--- @param cb fun(downloaded: boolean)
function download.is_downloaded(cb)
return vim.uv.fs_stat(lib_path, function(err) cb(not err) end)
vim.uv.fs_stat(lib_path, function(err)
if not err then
cb(true)
else
-- If not found, check without 'lib' prefix
vim.uv.fs_stat(string.gsub(lib_path, 'libblink_cmp_fuzzy', 'blink_cmp_fuzzy'), function(error) cb(not error) end)
end
end)
end

--- @param cb fun(err: string | nil, tag: string | nil)
Expand Down
129 changes: 66 additions & 63 deletions lua/blink/cmp/fuzzy/ffi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,24 @@ end




typedef struct {
const char * *ptr;
size_t len;
size_t capacity;
} blink_cmp_fuzzy__Vec___string_ptr;
const int32_t *ptr;
} blink_cmp_fuzzy__Option_int32_t;
typedef struct {
const int32_t *ptr;
size_t len;
size_t capacity;
} blink_cmp_fuzzy__Vec_int32_t;

typedef struct {
const int32_t *ptr;
} blink_cmp_fuzzy__Option_int32_t;
typedef struct {
const uint32_t *ptr;
const char * *ptr;
size_t len;
size_t capacity;
} blink_cmp_fuzzy__Vec_uint32_t;



} blink_cmp_fuzzy__Vec___string_ptr;
typedef struct {
const char * *ptr;
} blink_cmp_fuzzy__Option___string_ptr;

typedef struct {
const char * label;
const blink_cmp_fuzzy__Option___string_ptr sort_text;
const blink_cmp_fuzzy__Option___string_ptr filter_text;
const uint32_t kind;
const blink_cmp_fuzzy__Option_int32_t score_offset;
const char * source;
} blink_cmp_fuzzy__LspItem;

typedef struct {
const blink_cmp_fuzzy__Vec___string_ptr *ptr;
} blink_cmp_fuzzy__Option_Vec___string_ptr;
Expand All @@ -65,6 +49,22 @@ typedef struct {
const blink_cmp_fuzzy__Vec___string_ptr sorts;
} blink_cmp_fuzzy__FuzzyOptions;



typedef struct {
const char * label;
const blink_cmp_fuzzy__Option___string_ptr sort_text;
const blink_cmp_fuzzy__Option___string_ptr filter_text;
const uint32_t kind;
const blink_cmp_fuzzy__Option_int32_t score_offset;
const char * source;
} blink_cmp_fuzzy__LspItem;

typedef struct {
const uint32_t *ptr;
size_t len;
size_t capacity;
} blink_cmp_fuzzy__Vec_uint32_t;
int32_t init_db(
const char *,
int8_t*);
Expand Down Expand Up @@ -97,37 +97,33 @@ int32_t __gc_get_words(

]]

local rust = ffi.load(debug.getinfo(1).source:match('@?(.*/)') .. '../../../../target/release/libblink_cmp_fuzzy' .. get_shared_lib_extension())
local ok, rust = pcall(function() return ffi.load(debug.getinfo(1).source:match('@?(.*/)') .. '../../../../target/release/libblink_cmp_fuzzy' .. get_shared_lib_extension()) end)
if not ok then
rust = ffi.load(debug.getinfo(1).source:match('@?(.*/)') .. '../../../../target/release/blink_cmp_fuzzy' .. get_shared_lib_extension())
end

local M = {}



local __const_c_typename_int32_t = ffi.typeof("const int32_t[?]")
local __c_function_argument_int32_t = ffi.typeof("int32_t[?]")
local __c_mut_function_argument_int32_t = ffi.typeof("int32_t[?]")


local __const_c_typename___string_ptr = ffi.typeof("const char *[?]")
local __c_function_argument___string_ptr = ffi.typeof("const char *[?]")
local __c_mut_function_argument___string_ptr = ffi.typeof("char *[?]")
local __const_c_typename_bool = ffi.typeof("const int8_t[?]")
local __c_function_argument_bool = ffi.typeof("int8_t[?]")
local __c_mut_function_argument_bool = ffi.typeof("int8_t[?]")


local __const_c_typename_uint32_t = ffi.typeof("const uint32_t[?]")
local __c_function_argument_uint32_t = ffi.typeof("uint32_t[?]")
local __c_mut_function_argument_uint32_t = ffi.typeof("uint32_t[?]")
local __const_c_typename_size_t = ffi.typeof("const size_t[?]")
local __c_function_argument_size_t = ffi.typeof("size_t[?]")
local __c_mut_function_argument_size_t = ffi.typeof("size_t[?]")


local __typename_Vec___string_ptr = ffi.metatype("blink_cmp_fuzzy__Vec___string_ptr", {})
local __const_c_typename_Vec___string_ptr = ffi.typeof("const blink_cmp_fuzzy__Vec___string_ptr[?]")
local __c_function_argument_Vec___string_ptr = ffi.typeof("const blink_cmp_fuzzy__Vec___string_ptr*[?]")
local __c_mut_function_argument_Vec___string_ptr = ffi.typeof("blink_cmp_fuzzy__Vec___string_ptr*[?]")
local __const_c_typename_uint16_t = ffi.typeof("const uint16_t[?]")
local __c_function_argument_uint16_t = ffi.typeof("uint16_t[?]")
local __c_mut_function_argument_uint16_t = ffi.typeof("uint16_t[?]")


local __typename_Vec_int32_t = ffi.metatype("blink_cmp_fuzzy__Vec_int32_t", {})
local __const_c_typename_Vec_int32_t = ffi.typeof("const blink_cmp_fuzzy__Vec_int32_t[?]")
local __c_function_argument_Vec_int32_t = ffi.typeof("const blink_cmp_fuzzy__Vec_int32_t*[?]")
local __c_mut_function_argument_Vec_int32_t = ffi.typeof("blink_cmp_fuzzy__Vec_int32_t*[?]")
local __const_c_typename_int32_t = ffi.typeof("const int32_t[?]")
local __c_function_argument_int32_t = ffi.typeof("int32_t[?]")
local __c_mut_function_argument_int32_t = ffi.typeof("int32_t[?]")


local __typename_Option_int32_t = ffi.metatype("blink_cmp_fuzzy__Option_int32_t", {})
Expand All @@ -136,25 +132,21 @@ local __c_function_argument_Option_int32_t = ffi.typeof("const blink_cmp_fuzzy__
local __c_mut_function_argument_Option_int32_t = ffi.typeof("blink_cmp_fuzzy__Option_int32_t*[?]")


local __typename_Vec_uint32_t = ffi.metatype("blink_cmp_fuzzy__Vec_uint32_t", {})
local __const_c_typename_Vec_uint32_t = ffi.typeof("const blink_cmp_fuzzy__Vec_uint32_t[?]")
local __c_function_argument_Vec_uint32_t = ffi.typeof("const blink_cmp_fuzzy__Vec_uint32_t*[?]")
local __c_mut_function_argument_Vec_uint32_t = ffi.typeof("blink_cmp_fuzzy__Vec_uint32_t*[?]")


local __const_c_typename_size_t = ffi.typeof("const size_t[?]")
local __c_function_argument_size_t = ffi.typeof("size_t[?]")
local __c_mut_function_argument_size_t = ffi.typeof("size_t[?]")
local __typename_Vec_int32_t = ffi.metatype("blink_cmp_fuzzy__Vec_int32_t", {})
local __const_c_typename_Vec_int32_t = ffi.typeof("const blink_cmp_fuzzy__Vec_int32_t[?]")
local __c_function_argument_Vec_int32_t = ffi.typeof("const blink_cmp_fuzzy__Vec_int32_t*[?]")
local __c_mut_function_argument_Vec_int32_t = ffi.typeof("blink_cmp_fuzzy__Vec_int32_t*[?]")


local __const_c_typename_bool = ffi.typeof("const int8_t[?]")
local __c_function_argument_bool = ffi.typeof("int8_t[?]")
local __c_mut_function_argument_bool = ffi.typeof("int8_t[?]")
local __const_c_typename___string_ptr = ffi.typeof("const char *[?]")
local __c_function_argument___string_ptr = ffi.typeof("const char *[?]")
local __c_mut_function_argument___string_ptr = ffi.typeof("char *[?]")


local __const_c_typename_uint16_t = ffi.typeof("const uint16_t[?]")
local __c_function_argument_uint16_t = ffi.typeof("uint16_t[?]")
local __c_mut_function_argument_uint16_t = ffi.typeof("uint16_t[?]")
local __typename_Vec___string_ptr = ffi.metatype("blink_cmp_fuzzy__Vec___string_ptr", {})
local __const_c_typename_Vec___string_ptr = ffi.typeof("const blink_cmp_fuzzy__Vec___string_ptr[?]")
local __c_function_argument_Vec___string_ptr = ffi.typeof("const blink_cmp_fuzzy__Vec___string_ptr*[?]")
local __c_mut_function_argument_Vec___string_ptr = ffi.typeof("blink_cmp_fuzzy__Vec___string_ptr*[?]")


local __typename_Option___string_ptr = ffi.metatype("blink_cmp_fuzzy__Option___string_ptr", {})
Expand All @@ -163,12 +155,6 @@ local __c_function_argument_Option___string_ptr = ffi.typeof("const blink_cmp_fu
local __c_mut_function_argument_Option___string_ptr = ffi.typeof("blink_cmp_fuzzy__Option___string_ptr*[?]")


local __typename_LspItem = ffi.metatype("blink_cmp_fuzzy__LspItem", {})
local __const_c_typename_LspItem = ffi.typeof("const blink_cmp_fuzzy__LspItem[?]")
local __c_function_argument_LspItem = ffi.typeof("const blink_cmp_fuzzy__LspItem*[?]")
local __c_mut_function_argument_LspItem = ffi.typeof("blink_cmp_fuzzy__LspItem*[?]")


local __typename_Option_Vec___string_ptr = ffi.metatype("blink_cmp_fuzzy__Option_Vec___string_ptr", {})
local __const_c_typename_Option_Vec___string_ptr = ffi.typeof("const blink_cmp_fuzzy__Option_Vec___string_ptr[?]")
local __c_function_argument_Option_Vec___string_ptr = ffi.typeof("const blink_cmp_fuzzy__Option_Vec___string_ptr*[?]")
Expand All @@ -180,6 +166,23 @@ local __const_c_typename_FuzzyOptions = ffi.typeof("const blink_cmp_fuzzy__Fuzzy
local __c_function_argument_FuzzyOptions = ffi.typeof("const blink_cmp_fuzzy__FuzzyOptions*[?]")
local __c_mut_function_argument_FuzzyOptions = ffi.typeof("blink_cmp_fuzzy__FuzzyOptions*[?]")


local __const_c_typename_uint32_t = ffi.typeof("const uint32_t[?]")
local __c_function_argument_uint32_t = ffi.typeof("uint32_t[?]")
local __c_mut_function_argument_uint32_t = ffi.typeof("uint32_t[?]")


local __typename_LspItem = ffi.metatype("blink_cmp_fuzzy__LspItem", {})
local __const_c_typename_LspItem = ffi.typeof("const blink_cmp_fuzzy__LspItem[?]")
local __c_function_argument_LspItem = ffi.typeof("const blink_cmp_fuzzy__LspItem*[?]")
local __c_mut_function_argument_LspItem = ffi.typeof("blink_cmp_fuzzy__LspItem*[?]")


local __typename_Vec_uint32_t = ffi.metatype("blink_cmp_fuzzy__Vec_uint32_t", {})
local __const_c_typename_Vec_uint32_t = ffi.typeof("const blink_cmp_fuzzy__Vec_uint32_t[?]")
local __c_function_argument_Vec_uint32_t = ffi.typeof("const blink_cmp_fuzzy__Vec_uint32_t*[?]")
local __c_mut_function_argument_Vec_uint32_t = ffi.typeof("blink_cmp_fuzzy__Vec_uint32_t*[?]")

function M.init_db(
db_path)
local __typeof = __c_mut_function_argument_bool
Expand Down