Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't assume vcc availability on Windows #37

Closed
richboss opened this issue Oct 28, 2020 · 2 comments
Closed

Don't assume vcc availability on Windows #37

richboss opened this issue Oct 28, 2020 · 2 comments

Comments

@richboss
Copy link

OS: Windows 10 Version 2004 (Build 19041.572)
Python: Python 3.8.4 (tags/v3.8.4:dfa645a, Jul 13 2020, 16:46:45) [MSC v.1924 64 bit (AMD64)]
Nim: 1.4.0
C Compiler: gcc version 8.1.0 (i686-posix-dwarf-rev0, Built by MinGW-W64 project)

On Windows, nimporter doesn't work if the Visual Studio C Compiler is not installed. See the following stacktrace:

c:\Temp>python test.py
Traceback (most recent call last):
  File "C:\Temp\test.py", line 2, in <module>
    import nimporter, nim_math
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 914, in _find_spec
  File "O:\app\python3\lib\site-packages\nimporter.py", line 1123, in find_spec
    return Nimporter.import_nim_code(fullname, path, library=False)
  File "O:\app\python3\lib\site-packages\nimporter.py", line 806, in import_nim_code
    NimCompiler.compile_nim_code(
  File "O:\app\python3\lib\site-packages\nimporter.py", line 566, in compile_nim_code
    raise NimCompileException(errors[0])
  File "O:\app\python3\lib\site-packages\nimporter.py", line 48, in __init__
    nim_module = nim_module.splitlines()[-1]
IndexError: list index out of range

Alas, this stacktrace is not very meaningful. But the root cause is quite simple. The class NimCompiler in the file nimporter.py defines a standard set of Nim cli args. On Windows (if sys.platform == 'win32') another option is added: --cc:vcc. This is where the problem arises. IMO it is wrong to unconditionally assume the availability of vcc on Windows boxes. Nim could well be using gcc or tcc instead.

Maybe you could check if vcc is at all installed before adding this cli argument?

@Pebaz
Copy link
Owner

Pebaz commented Oct 28, 2020

Thank you for the bug report!

I will look into this soon and see if enumerating installed compilers is even possible on Windows. Any thoughts on how to do this would be appreciated!

@Pebaz Pebaz closed this as completed in adbd240 Feb 14, 2021
@retsyo
Copy link
Contributor

retsyo commented Jan 30, 2022

this is not a fix to fit every case. in case somebody use mingw, you can change line 133-146 in nimporter.py
from

    NIM_CLI_ARGS = [
                       '--opt:speed',
                       '--parallelBuild:0',
                       '--gc:refc',
                       '--threads:on',
                       '--app:lib',
                       '-d:release',
                       '-d:strip',
                       '-d:ssl',

                       # https://github.com/Pebaz/nimporter/issues/41
                       '--warning[ProveInit]:off',

                   ] + (['--cc:vcc'] if 'MSC' in sys.version else [])

to

    NIM_CLI_ARGS = [
                       '--opt:speed',
                       '--parallelBuild:0',
                       '--gc:refc',
                       '--threads:on',
                       '--app:lib',
                       '-d:release',
                       '-d:strip',
                       '-d:ssl',
                       '--passL:-static',        # else, you need libgcc_s_seh-1.dll

                       # https://github.com/Pebaz/nimporter/issues/41
                       '--warning[ProveInit]:off',

                   ] 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants