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

cIncludeDir doesn't seem to be working #48

Closed
kaushalmodi opened this issue Jan 20, 2019 · 7 comments
Closed

cIncludeDir doesn't seem to be working #48

kaushalmodi opened this issue Jan 20, 2019 · 7 comments

Comments

@kaushalmodi
Copy link

Hello,

I am using nimterop built from master and nim built from devel.

I am using nimterop this way:

import nimterop/cimport

cDebug()

# Below doesn't work
cIncludeDir("/cad/adi/apps/cadence/xlm/linux/current/tools/include")
# Below doesn't work
# cIncludeDir(/cad/adi/apps/cadence/xlm/linux/current/tools/include)
# Below doesn't work
# {.passC: "-I/cad/adi/apps/cadence/xlm/linux/current/tools/include".}

# Below manual definition of s_vpi_vecval is a workaround for
# https://github.com/genotrance/nimterop/issues/47.
type
  s_vpi_vecval* {.importc: "s_vpi_vecval".} = object
    aval: uint32
    bval: uint32

cImport("svdpi.h")

The svdpi.h and the other header file needed are in that directory path that I have in the above example, but still they cannot be found. I get this error:

{.passC: "-I\"/cad/adi/apps/cadence/xlm/linux/current/tools/include\"".}
stack trace: (most recent call last)
../../../../.nimble/pkgs/nimterop-0.1.0/nimterop/cimport.nim(232, 24) cImport
../../../../.nimble/pkgs/nimterop-0.1.0/nimterop/cimport.nim(21, 11) findPath
../../../../stow/pkgs/nim/devel/lib/system.nim(3989, 20) failedAssertImpl
../../../../stow/pkgs/nim/devel/lib/system.nim(3982, 11) raiseAssert
../../../../stow/pkgs/nim/devel/lib/system.nim(3016, 7) sysFatal
svdpi.nim(16, 8) template/generic instantiation of `cImport` from here
../../../../stow/pkgs/nim/devel/lib/system.nim(3016, 7) Error: unhandled exception: /home/kmodi/.nimble/pkgs/nimterop-0.1.0/nimterop/cimport.nim(21, 5) `(not fail)` File or directory not found: svdpi.h

The only way I can get the compilation to work is if I copy the .h files and put them in the directory containing the above .nim file.

Am I missing something in the cIncludeDir syntax?

@kaushalmodi
Copy link
Author

Also adding --passC:-I/cad/adi/apps/cadence/xlm/linux/current/tools/include directly to the nim c .. command doesn't make any difference. But the needed .h files are definitely in that directory, albeit as symlinks.

@zedeus
Copy link

zedeus commented Jan 20, 2019

Try setting the search path to the include path using cAddSearchDir, then use cImport(cSearchPath("svdpi.h")) to import

@genotrance
Copy link
Collaborator

cIncludeDir() only forwards to gcc, it isn't used by nimterop itself.

See #7 for some details.

Please confirm that @zestyr's solution works.

@kaushalmodi
Copy link
Author

kaushalmodi commented Jan 21, 2019

@zestyr thank you!

This worked:

import nimterop/cimport
import os

# cDebug()

# Below manual definition of s_vpi_vecval is a workaround for
# https://github.com/genotrance/nimterop/issues/47.
type
  s_vpi_vecval* {.importc: "s_vpi_vecval".} = object
    aval: uint32
    bval: uint32

const
  xlmIncludePath = getEnv("XCELIUM_ROOT") / ".." / "include"
static:
  doAssert fileExists(xlmIncludePath / "svdpi.h")
  doAssert fileExists(xlmIncludePath / "svdpi_compatibility.h")

# Below works  
cAddSearchDir(xlmIncludePath)
cImport(cSearchPath("svdpi.h"))

# https://github.com/genotrance/nimterop/issues/48
# Below doesn't work
# cIncludeDir(xlmIncludePath)
# cImport("svdpi.h")

Any idea why cIncludeDir wouldn't work? i.e. why wouldn't gcc find the svdpi.h at that path even though those doAsserts pass?

@kaushalmodi
Copy link
Author

kaushalmodi commented Jan 21, 2019

I think that the issue is probably that the assert in the findPath in cimport causes the fail because the gcc command runs:

proc findPath(path: string, fail = true): string =
  # Relative to project path
  result = joinPathIfRel(getProjectPath(), path).replace("\\", "/")
  echo "debug = " & result                     # I added this debug
  if not fileExists(result) and not dirExists(result):
    doAssert (not fail), "File or directory not found: " & path
    result = ""

Above debug statement prints:

debug = /home/kmodi/sandbox/systemverilog/dpi_c/nim_svdpi_import_export/svdpi.h

The svdpi.h of course is not in the current directory .. it's in the directory I set using cIncludePath.

From cDebug(), I get:

{.passC: "-I"/cad/adi/apps/cadence/xlm/linux/18.03-s06/tools/include"".}

.. and svdpi.h does exist in that path.

So looks like the assertion is kicking too soon? .. not sure ..

@genotrance
Copy link
Collaborator

Again - cIncludeDir() is only used to send -Ixyz directives to gcc. It is not used by nimterop to find files. Even gcc only uses -I to search for files included in the file being processed but expects a full path to the file.

You need to use cAddSearchDir() and cSearchPath() lik you have to do this. This was explicitly requested by @timotheecour where originally cIncludeDir() was shared.

We can think about it again but it was separated out so that you don't confuse nimterop paths with gcc.

@kaushalmodi
Copy link
Author

You need to use cAddSearchDir() and cSearchPath() lik you have to do this. This was explicitly requested by @timotheecour where originally cIncludeDir() was shared.

Thanks! Closing this issue then.

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