nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.58k stars 1.47k forks source link

Variable $nim returns different values depending on where used. #21666

Closed thindil closed 1 year ago

thindil commented 1 year ago

Description

The value of $nim variable is different when used in a configuration file and in a Nim code. It is a problem, when someone uses Nim provided as a system package, as they usually put binaries and libraries in different places. It isn't a problem when using Nim version from choosenim or downloaded from the page, as both have everything bundled and $nim points into the same place.

For example, when nim binary is installed in /usr/local/bin and Nim library installed in /usr/local/lib/nim:

  1. When creating file config.nims with just one line: switch("path", "$nim") it returns the path to where Nim library is located. In example: /usr/local/lib/nim.
  2. When using the variable in a Nim code, again one line is enough: import "$nim"/compiler/ast it returns the parent's path of the binary file. In example: /usr/local. Which causes the code not compile, can't find package.

Nim Version

Nim Compiler Version 1.6.12 [FreeBSD: amd64] Compiled at 2023-03-18 Copyright (c) 2006-2023 by Andreas Rumpf

active boot switches: -d:release

Current Output

No response

Expected Output

No response

Possible Solution

No response

Additional Information

No response

Araq commented 1 year ago

When using the variable in a Nim code, again one line is enough: import "$nim"/compiler/ast it returns the parent's path of the binary file. In example: /usr/local. Which causes the code not compile, can't find package.

But why would /usr/local/lib/ contain the compiler's source code? It might not be packaged at all so your premise is wrong.

thindil commented 1 year ago

I'm mainly surprised that the same variable returns different values depending on where it is used. My guess, one of these values, is wrong. The question is, which one? :)

Compiler package was used here mostly as an example, but I got recently hit by that problem in one of Nim's packages.

ringabout commented 1 year ago

Hi @thindil probably fixed by https://github.com/nim-lang/Nim/pull/21328 ?

thindil commented 1 year ago

Hello, @ringabout, thank you for checking. I will look on it. At the moment, it seems like Nim 2.0 doesn't want to build on FreeBSD. 🙄 I will need a bit more time to check and update needed patches to be able to check devel branch.

thindil commented 1 year ago

Tested against the devel branch with the commit d2d849d. In both situations, $nim returns the same value, to the place where Nim library is. Thus, I think, the issue is resolved. Thank you very much for pointing me there. 😄