I’m wondering if there’s a way to retrieve the version of a Nimble dependency at compile time, when the package itself doesn’t expose a version constant.
I’m aware that Nimble installs packages under a pkgs/ directory (e.g. ~/.nimble/pkgs/packagename-version/), so the version is technically encoded in the path.
However, that directory is not straightforward to locate reliably: it can vary depending on the OS, the Nimble configuration, or whether the project uses a local nimbledeps/ folder.
Out of curiosity why do you want/need the version of a dep at compile time? Perhaps there's a better (more stable) approach using "feature" blocks?
In general it wouldn't be easy to do. Perhaps with nimble deps --format=json (something like that) which will tell you the dep versions and such.
Thanks for the suggestions! To clarify the use case: I want to conditionally call procs that only exist in certain versions of a dependency — so the goal is really API compatibility, not the version number itself.
I actually figured out a solution in the meantime
when declared(...) it checks at compile time whether a symbol exists, without needing to know the actual version number.
And for limiting the supported versions, a simple constraint in the .nimble file does the job.
What I don’t know how to do, however, is restrict a package to a range between a minimum and maximum version ? something like that :
requires "packagename >= 2.0.0 < 2.2.0" https://nim-lang.github.io/nimble/create-packages.html#dependenciesNo prob!
Probably the best path to use when. Actually I didn't know or forgot about when declared and have been abusing when compiles.
Do this I think:
requires "packagename < 2.2.0 & >= 2.0.0"requires "packagename < 2.2.0 & >= 2.0.0"
Oh, thanks, I didn't know we could write that way.
Many thanks.