kkharji / sqlite.lua

SQLite LuaJIT binding with a very simple api.
MIT License
487 stars 26 forks source link

libsqlite3.so fails to load on nix/guix (workaround) #28

Closed mjlbach closed 3 years ago

mjlbach commented 3 years ago

This probably isn't pertinent to most people, but I'm posting this in case others run into this issue. libz will fail to load before libsqlite3.so is loaded, so you get an error message about libsqlite3 when it's really the fault of libz.

I'm going to try to figure out how to deal with this on the nix packaging side. The following is for neovim installed on a linux system (not nixos), but it should work with the store path's substituted for the appropriate libraries.

diff --git a/lua/sql/defs.lua b/lua/sql/defs.lua
index edc260a..31de4ef 100644
--- a/lua/sql/defs.lua
+++ b/lua/sql/defs.lua
@@ -3,13 +3,8 @@ local bit = require'bit'

 local M = {}

-local clib_path = vim.g.sql_clib_path or (function()
-  if vim.loop.os_uname().sysname == 'Darwin' then
-    return '/usr/local/opt/sqlite3/lib/libsqlite3.dylib'
-  end
-  return 'libsqlite3'
-end)()
-local clib = ffi.load(clib_path)
+ffi.load('/usr/lib64/libz.so')
+local clib = ffi.load('/usr/lib64/libsqlite3.so')

 -- Constants
 M.flags = {
kkharji commented 3 years ago

Hey @mjlbach , what are the cases in which /usr/lib64/libz.so need to be loaded first?

mjlbach commented 3 years ago

It's more that we need to wrap our nix generated neovim with an LD_LIBRARY_PATH which includes both libz.so and libsqlite3.so. I think it would be too hard to ask individual plugin authors to account for this when using the cffi by allowing us to manually set the path to each library/load them sequentially, so I think I'm going to try to solve this more generally from the neovim packaging side in nix.

For reference, this is how you can use frecency (which depends on sql.nvim) with nix. https://github.com/mjlbach/luaffi_nix

rbhanot4739 commented 6 days ago

@mjlbach I am using devbox and having the exact same issue. However since devbox wraps around nix not sure how do I fix this.