Pebaz / nimporter

Compile Nim Extensions for Python On Import!
MIT License
824 stars 33 forks source link

pragmas ignored, not in nimporter.build_nim_extensions() #28

Closed phdye closed 3 years ago

phdye commented 4 years ago

The extension objects in nimporter.build_nim_extensions() do not contain the values specified by:

.passC
.passL
.compile
.link

Of note, the pragma values do carry through to nim-extensions/nim-extensions/src./.json. No effect on the execution of setup.py though.

To workaround, one may add the necessary values after calling nimporter.build_nim_extensions():

modules = nimporter.build_nim_extensions()
modules[0].sources.append("src/capture_c.c")
modules[0].extra_compile_args.append("-w")
setup (
    name = "capture",
    ext_modules = modules
)
Pebaz commented 4 years ago

Hello @phdye !

I'm sorry, I'm a little confused. Can you explain a little bit more about this issue?

As far as I am aware, no extra C-compiler and C-linker arguments are needed.

phdye commented 4 years ago

I have a package which utilizes an external C file. Within a .nim file, one may specify pragmas to add other files to compile (.compile), merely link (.link), other compile (.passC), or linking (.passL) arguments.

I can upload a few tiny projects to github with examples if that would help.

Pebaz commented 4 years ago

Hello @phdye !

Thank you for clarifying this!

I am unsure of whether or not this can be supported by Nimporter.

I have a question: can .passC be supported in a *.nim.cfg file instead?

If not, the only other option is to support these pragmas within the switches.py file since the whole point of nimporter.build_nim_extensions() is to allow Python users a simple way to use Nim code in their project.

I'd be happy to look into a patch for this, contingent on my above question.

Pebaz commented 3 years ago

If special flags need to be passed to Nim during Nimporter's execution, you can use a switches.py script.

If you need additional assistance don't hesitate to reopen! :)