PMunch/futhark

getting clang resource dir automagically

weskerfoot opened this issue · 2 comments

Not sure if this is the best method but I did this in order to avoid specifying it manually every time

in yourlib.nim

const clangResourceDir {.strdefine.}: string = "nothing" # defined by config.nims
importc:
  sysPath fmt"{clangResourceDir}/include"
  path: "/usr/include/libxml2/libxml"
  path: "/usr/include/libxml2"
  "parser.h"

in config.nims

import system, strformat, strutils

const clangResourceDir = staticExec("clang -print-resource-dir").strip

switch("passL", "/usr/lib/libxml2.so")
switch("d", fmt"clangResourceDir={clangResourceDir}")

Hopefully someone else will find this useful

With 7dc441b and #51 this is much easier to do. But I will keep this open until I've added a file which can be imported into config.nims so that we could have re-use of this clang finding logic.

Found a better solution, assuming you have clang in your path callable as clang you should now be able to simply not have a sysPath argument.