Hi,
Currently porting Nim to NuttX.
If I clone Nim source from git and build it, will find nimbase.h in .. /lib/ from the PATH of the "nim" command. install With "choosenim #devel --latest", I am having difficulty finding "nimbase.h" automatically with commands and such. (Required for automatic specification in the Makefile)
Is there a better way?
I've previously had success with `choosenim show path`/lib/nimbase.h
Or in a Makefile that would be $(shell choosenim show path)/lib/nimbase.h
I have been working with git sources, and was looking for a way to get information from the "nim" command outputs. Once I can install with choosenim, the method you suggested sounds good!
Thank you very much.
Another solution could be $(shell dirname $(shell dirname $(shell which nim)))/lib which I was using some years ago, but I think that only works if you have added Nim to your PATH manually. Maybe you can use it as a fallback somehow.
Alternatively, you can still install a local Nim git repo with choosenim like so:
$ cd path/to/Nim
$ choosenim .
I didn't know there was such a way to use choosenim, that's the first time I've heard of it. I will use that method in the future when I develop with source from git.
Thank you again!
This is how I implemented it in picostdlib:
https://github.com/EmbeddedNim/picostdlib/blob/master/src/piconim.nim#L102
Works for me on linux and windows using choosenim. It should find the "lib" directory (containing the nimbase.h file) that is associated with the "nim" binary currently on the path.
But PMunch's comment actually makes me realize it might not work with OS package managers. I'll have to try that. I wonder if we could add a getCurrentCompilerLibPath proc to Nim, that works like getCurrentCompilerExe(). Or extract the include paths from the compiler command lines produced by Nim. Are those in the json file produced in nimcache? Hm.
I'd say to not use choosenim, as not every nim install uses it. However, theres an equivalent Nim. Had to dig this up:
NIMLIB := $(shell nim dump file.json 2>&1 | grep lib | sort | head -n1 )
I think thats correct. You might want to check the raw nim dump output.
So the nim command has information about the PATH of libraries, etc.
If so, I would like the ability to have the nim command display the PATH with an option like --showLibPath. I think that people who use Windows cannot use the same method with grep and so on.
That, or it could be implemented as a library proc in system or std/os like getCurrentCompilerExe. If you want to shell out with make you can then do something like
nim --verbosity:0 --eval:"import std/os; echo getCurrentLibPath()" (runs as nimscript)
I could probably put in a PR for this, I've dug around in the C compiler invocation code lately, should be able to find out where the compiler pulls the lib path and put that in an accessible library proc.
To describe in the Makefile, I think it would be better to have it implemented as an option of the command so that it is not noisy enough.
However, I am still too new to judge which method is appropriate for the Nim language, so I hope it will be implemented in a better way.
I implemented elcritch's nim dump method (thanks) in picostdlib, in case it can be useful to someone else:
https://github.com/EmbeddedNim/picostdlib/pull/61
(with some extra checks rather than sort and pick the first path)