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

nimporter ignores nim.cfg #43

Closed
mhechthz opened this issue Mar 1, 2021 · 6 comments
Closed

nimporter ignores nim.cfg #43

mhechthz opened this issue Mar 1, 2021 · 6 comments

Comments

@mhechthz
Copy link

mhechthz commented Mar 1, 2021

Hi,

I'm totally new to Nim and nimporter and tried to build a little test application. I changed Nim to use clang, which is compatible with CPython on Windows 10. Nim file:

import nimpy
import math, random
import times

let time = cpuTime()

proc mcpi(nthrows: float): float {.exportpy.} =
  randomize()
  var inside = 0.0
  for i in 1..int64(nthrows):
    if hypot(rand(1.0), rand(1.0)) < 1:
      inside += 1
  result = 4 * inside / nthrows
 
echo mcpi(250000000)

echo cpuTIme()-time  

Python file:

import nimporter, mcpi
import time

time0 = time.time()
print("pi:",mcpi.mcpi(250000000))
print("tm:",time.time()-time0)

Running the nim-file using Nim works perfectly. Compiling to library (nimpy only) and importing to Python also works perfectly.

Running the Python program "hangs" the execution and while trying to start Visual C++. Both files are in the same directory, i.e. there is no directory structure.

What is wrong here?

@Pebaz
Copy link
Owner

Pebaz commented Mar 1, 2021

@mhechthz can you post the nim.cfg?

@mhechthz
Copy link
Author

mhechthz commented Mar 1, 2021

It's the default nim.cfg, with the only change

# cc = gcc
cc = clang

How can I be sure, that this config file from Nim installation directory is really used? I set the PATH to NimInstallDir\bin.

EDIT: It seems that LLVM is using MSVC++ during linking. That's probably the reason why I see this running. Nevertheless, it doesn't work

@Pebaz
Copy link
Owner

Pebaz commented Mar 3, 2021

Hello @mhechthz I was able to get both of the code snippets to work on my Windows 10 machine using MSVC.

Nimporter can't change Nim's behavior for supporting nim.cfg files so if the nim.cfg is in the proper directory as specified by the docs it will work with Nimporter.

However, you mentioned that "Visual Studio" (the graphical application) starts up when you run the Python example above?

@Pebaz
Copy link
Owner

Pebaz commented Mar 3, 2021

Also, Nimporter will tell Nim to use MSVC only if Python was compiled with MSVC. You can tell if Python is compiled with MSVC by running this in a Python shell:

>>> import sys; sys.version
'3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]'

The "MSC" in the square brackets is for MSVC. If "MSC" is not in sys.version, Nimporter does not suggest a compiler, which means that the cc = clang should be honored by Nim itself (since Nimporter will not have asked Nim to use MSVC manually).

@Pebaz
Copy link
Owner

Pebaz commented Mar 3, 2021

If you need to explicitly control 100% of all flags Nimporter passes to Nim, you can use a switches.py script.

@Pebaz
Copy link
Owner

Pebaz commented May 19, 2021

Closing for now

@Pebaz Pebaz closed this as completed May 19, 2021
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

2 participants