acalejos / exgboost

Elixir bindings to the XGBoost C API (https://xgboost.readthedocs.io/en/stable/c.html) using Native Implemented Functions (NIFs)
Apache License 2.0
164 stars 7 forks source link

Does not compile under Nix on X86 or Darwin #42

Closed vegabook closed 4 months ago

vegabook commented 4 months ago

I have tried on both Apple Silicon, and on AMD64 Nixos, using Nix:

nix-shell -p elixir erlang gcc cmake libgcc xgboost

But can't seem to find libgomp.so.1 even though this is (provided by libgcc)[https://search.nixos.org/packages?channel=24.05&from=0&size=50&sort=relevance&type=packages&query=libgomp], and for good measure, I also put xgboost into the environment.

22:47:48.878 [warning] The on_load function for module Elixir.EXGBoost.NIF returned:
{:error,
 {:load_failed,
  ~c"Failed to load NIF library /home/tbrowne/scratch/test/_build/dev/lib/exgboost/priv/libexgboost: 'libgomp.so.1: cannot open shared object file: No such file or directory'"}}

And the full Asciinema: https://asciinema.org/a/4Cq3qL4eiehonuJxNbV1gvfVR

acalejos commented 4 months ago

Try

'brew install libomp'

Then recompile

vegabook commented 4 months ago

Try

'brew install libomp'

Then recompile

Yeah that does work, but on Nix still doesn't. Even though xgboost is there, and the Nix search libgomp is provided by libgcc which I also put into the environment. This may be a Nix issue, but I'm wondering if some assumptions about the location of libgomp are being made or something like that which are not valid under NixOS.

Reason I say that is that the rest of the (fairly complicated) NX stack works fine under NixOS and there's NIFs aplenty there too.

acalejos commented 4 months ago

Hmm I'm not sure then. I've done no testing under Nix. If it does have to do with assumptions with how XGBoost links, then the XGBoost issues or docs might be of more help

vegabook commented 4 months ago

Hmm I'm not sure then. I've done no testing under Nix. If it does have to do with assumptions with how XGBoost links, then the XGBoost issues or docs might be of more help

thing is xgboost is natively provided by Nix, but as I'm unsure of where exactly the problem lies I'm going to close this for now and see if I can get any more useful information.

vegabook commented 4 months ago

@acalejos Just FYI I have gotten it to compile by forcing NixOS to emulate the Linux File System Hierarchy (FHS). Here is another asciinema showing it in action (both before and after success): https://asciinema.org/a/uILBg73uDf2as2SdYJ4U54j4m

BTW the trick is to emulate the Linux "File System Hierarchy" to fool exgboost to think it doesn't need explicit paths to all its libs. Essentially you're assuming you'll always work on a "standard" Linux distro, that adheres to FHS, and where libgomp.so.1 will always be where Ubuntu/Fedora etc put them. This is not going to work on Nix, nor on many embedded systems, nor on any of the BSDs probably. Not sure exactly how libgomp.so.1 is being referenced in the [e]xgboost stack. The rest of the Nx stack does not suffer from this and I know that Explorer for example uses NIFs and that I'm sure those try to hit all sorts of Linux libs, but don't rely on FHS.

Here is the shell.nix that helps:

{ pkgs ? import <nixpkgs> {} }:

(pkgs.buildFHSEnv {
  name = "fhs-env";
  multiPkgs = pkgs: (with pkgs; [
    elixir
    erlang
  ]);
  runScript = "bash";
}).env

Anyway enough waffling now looking forward to using your lib!