mosdepth icon indicating copy to clipboard operation
mosdepth copied to clipboard

How to use --d4?

Open LudvigOlsen opened this issue 10 months ago • 5 comments

Would it be possible to add a bit more information to the readme about how to use --d4? Maybe I'm missing something, but I'm failing to get the argument to show up.

I've tried installing d4tools via conda and nimble install https://github.com/brentp/d4-nim.git and then installing the current master branch. And the --d4 argument is still missing. Do I need to add something to the $PATH or something? I feel like I got it to work a year ago or something, so I'm a bit confused :D

I assume, the when defined(d4): means it only adds the argument when d4 is available. Wouldn't it be better not to hide it?

LudvigOlsen avatar Jan 17 '25 17:01 LudvigOlsen

you need to compile with nim c -d:d4 ... mosdepth.nim

brentp avatar Jan 17 '25 17:01 brentp

Does d4 need to be specified further with a path or something?

CC: mosdepth.nim
/home/user/.cache/nim/mosdepth_d/@[email protected]@[email protected]@sd4.nim.c:8:10: fatal error: d4.h: No such file or directory
    8 | #include <d4.h>
      |          ^~~~~~
compilation terminated.
Error: execution of an external compiler program 'gcc -c  -w -fmax-errors=3   -I/home/user/.choosenim/toolchains/nim-1.6.14/lib -I/home/user/mosdepth -o /home/user/.cache/nim/mosdepth_d/@[email protected]@[email protected]@sd4.nim.c.o /home/user/.cache/nim/mosdepth_d/@[email protected]@[email protected]@sd4.nim.c' failed with exit code: 1
                                

LudvigOlsen avatar Jan 17 '25 17:01 LudvigOlsen

I tried the following:

nim c -d:d4 --passC:"-I$HOME/.nimble/pkgs/d4-0.0.5/include" --passL:"-L$HOME/.nimble/pkgs/d4-0.0.5/lib" mosdepth.nim

But the d4.h file is not located in any of those folders, so it's the same error.

LudvigOlsen avatar Jan 17 '25 18:01 LudvigOlsen

it is dynamically linking d4 so you need to build and install that.

brentp avatar Jan 17 '25 19:01 brentp

Okay, that was a lot of trial and error. Here's what I ended up with (since I don't have sudo permissions):

cd ~/
git clone https://github.com/38/d4-format
cd d4-format
cargo build --release --package d4binding

# Make dirs for the relevant files (could probably skip this and point directly to d4-format/)
mkdir -p ~/local/d4/lib
mkdir -p ~/local/d4/include

cp ~/d4-format/target/release/libd4binding.* ~/local/d4/lib/
cp ~/d4-format/d4binding/include/d4.h       ~/local/d4/include/

cd ../mosdepth/
nim c -d:d4 -d:release --passC:"-I$HOME/d4-format/d4binding/include" --passL:"-L$HOME/d4-format/target/release" mosdepth.nim

I added the following to .bashrc:

# d4tools
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/local/d4/lib/
export LIBRARY_PATH=$LIBRARY_PATH:$HOME/local/d4/lib/
export C_INCLUDE_PATH=$C_INCLUDE_PATH:$HOME/local/d4/include/

Now the --d4 argument is finally there :-)

LudvigOlsen avatar Jan 17 '25 20:01 LudvigOlsen