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.22k stars 1.46k forks source link

On Linux, "nimsuggest" crashes if Nim is installed in /usr/bin and the library in /usr/lib/nim #23695

Closed lscrd closed 3 weeks ago

lscrd commented 3 weeks ago

Description

If Nim is installed in the standard locations of a Linux system, nimsuggest expects the library to be installed in /usr/lib instead of /usr/lib/nim.

The issue has been encountered on a Manjaro system, but should exist on any Linux system and even on any Posix system.

Nim Version

Nim Compiler Version 2.0.4 [Linux: amd64] Compiled at 2024-05-04 Copyright (c) 2006-2023 by Andreas Rumpf

active boot switches: -d:release

Current Output

For instance, for command "nimsuggest somefile.nim":

Error: cannot open '/usr/lib/system.nim'
lineinfos.nim(314)       raiseRecoverableError
Error: unhandled exception: cannot open '/usr/lib/system.nim' [ERecoverableError]

Expected Output

No error.

Possible Solution

No response

Additional Information

Looking at the sources, it appears that nimsuggest doesn’t use the same rule as the compiler to find the location of the library. For Posix system, the compiler adds special rules if "nim" binary is installed in /usr/bin or /usr/local/bin.

jmgomez commented 3 weeks ago

Related: https://github.com/nim-lang/Nim/pull/21328

jmgomez commented 3 weeks ago

https://github.com/nim-lang/Nim/issues/23201 and https://github.com/nim-lang/Nim/issues/22369

jmgomez commented 3 weeks ago

@lscrd Can you give a shot at the PR? You will need to ./build_all.sh and then replace your nimsuggest with the one in the PR.

Thanks

lscrd commented 3 weeks ago

@jmgomez I did the test but nimsuggest still crashes. I noted that the path to the library is also computed in the procedure handleCmdLine which is called when nimsuggest is the main module. So I suppose that a modification should be done here too.

jmgomez commented 3 weeks ago

@lscrd I changed it as well, but the chunk didnt make it into the commit. Apologies. Should be up now.

lscrd commented 3 weeks ago

@jmgomez I applied the modifications and now nimsuggest works. Thanks!