idris-lang / Idris2

A purely functional programming language with first class types
https://idris-lang.org/
Other
2.49k stars 373 forks source link

Idris REPL does not appropriately configure LD_LIBRARY_PATH #514

Open bigs opened 4 years ago

bigs commented 4 years ago

In attempting to create libgit2 bindings for Idris 2, I've run into some usability issues with the Idris REPL that make it difficult to work with external shared objects. I've copied my .ipkg and Makefile from the Idris2 sample FFI-readline. The FFI-readline project is in a pretty poor state (I'll make another issue for that). My small motivating example can be found in this repo.

Steps to Reproduce

  1. Clone my repository
  2. Install the package with idris2 --install libgit.ipkg
  3. Open a repl with idris2
  4. Import the module :module Libgit
  5. Attempt a call to my function
    Main> :exec logSomething "sup"    
    Exception: (while loading libgit_idris_wrapper.so) libgit_idris_wrapper.so: cannot open shared object

I can fix this by setting the LD_LIBRARY_PATH manually e.g.

$ LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$(idris2 --libdir)/libgit/lib" 
Main> :module Libgit
Imported module Libgit
Main> :exec logSomething "sup"
logging: sup

Expected Behavior

idris2 adds the lib/ folder in installed package paths to LD_LIBRARY_PATH e.g. $(idris2 --libdir)/libgit/lib

Observed Behavior

LD_LIBRARY_PATH is not updated to include the package-specific library paths, resulting in an error opening the shared object.

bigs commented 4 years ago

As a side note, I've made some progress (setting LD_LIBRARY_PATH on my own), so I'd be happy to contribute some fixes to get FFI-readline in ship shape!

bigs commented 4 years ago

@gallais Do you have any ideas as to how shared libraries should be handled by Idris 2 packages? Should they simply be installed somewhere on a user's LD_LIBRARY_PATH? Installing into the idris2 package directories would be suitable for the REPL, where we could modify the environment some, but I worry that it wouldn't be suitable for compiled binaries. I'm happy to take the lead of implementation if we have a solid idea, even if it's just documenting some best practices.

gallais commented 4 years ago

I don't know much about the FFI and even less about interop with other languages / libraries, sorry.

bigs commented 4 years ago

No problem and thanks for the speedy reply! I'll do some noodling and see if I can come up with something reasonable.

gallais commented 3 years ago

Open a repl with idris2

Surely you should open it with idris2 -p libgit?