PMunch/futhark

How to multiple paths with header dependency

nixfreak opened this issue · 5 comments

Hello,

I am trying to create wrappers for efl libaries starting with Elementary https://git.enlightenment.org/enlightenment/efl/src/branch/master/src/lib/elementary

The only problem I am having is that when I want to wrap Elementary.h there is multiple dependencies in other directories

Here is my code:
`import futhark
importc:
sysPath "/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.1/include"
path "/usr/include/elementary-1/Elementary.h"
path "/usr/include/eina-1/Efl_Config.h"

static:
writeFile("enim.c", """
#define ELEMENTARY_IMPLEMENTATION
#include "/usr/include/elementary-1/Elementary.h"
#include "/usr/include/eina-1/Efl_Config.h"
""")

{.compile: "enim.c".}
`

Here is my error:

nim c -d:Debug --passL: "$(pkg-config --cflags --libs elementary)" enim.nim
Hint: used config file '/home/nixfreak/.choosenim/toolchains/nim-#devel/config/nim.cfg' [Conf]
Hint: used config file '/home/nixfreak/.choosenim/toolchains/nim-#devel/config/config.nims' [Conf]
................................................................................................................
/home/nixfreak/.nimble/pkgs/futhark-0.6.1/futhark.nim(521, 12) Hint: Running: opir -I/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.1/include -I/usr/include/elementary-1/Elementary.h -I/usr/include/eina-1/Efl_Config.h /home/nixfreak/.cache/nim/enim_d/futhark-includes.h [User]
/home/nixfreak/.nimble/pkgs/futhark-0.6.1/futhark.nim(528, 8) Hint: Parsing Opir output [User]
/home/nixfreak/.nimble/pkgs/futhark-0.6.1/futhark.nim(539, 10) Hint: Caching Opir output in /home/nixfreak/.cache/nim/enim_d/opir_CF17E89EA8CA239C.json [User]
/home/nixfreak/.nimble/pkgs/futhark-0.6.1/futhark.nim(542, 8) Hint: Generating Futhark output [User]
/home/nixfreak/.nimble/pkgs/futhark-0.6.1/futhark.nim(689, 8) Hint: Caching Futhark output in /home/nixfreak/.cache/nim/enim_d/futhark_F54D6D299808F288.nim [User]
/home/nixfreak/.nimble/pkgs/futhark-0.6.1/futhark.nim(647, 10) Warning: imported and not used: 'macros' [UnusedImport]
CC: enim
In file included from /home/nixfreak/build/enim.c:2:
/usr/include/elementary-1/Elementary.h:59:10: fatal error: Efl_Config.h: No such file or directory
59 | #include "Efl_Config.h"
| ^~~~~~~~~~~~~~
compilation terminated.
Error: execution of an external compiler program 'gcc -c -w -fmax-errors=3 -pthread -I'/home/nixfreak/.choosenim/toolchains/nim-#devel/lib' -I/home/nixfreak/build -o /home/nixfreak/.cache/nim/enim_d/enim.c.o /home/nixfreak/build/enim.c' failed with exit code: 1

The example in the README is for libraries that have to be compiled into your project. You appear to link existing objects to your binary so the entire static section can be removed. Also if you pass path to folders instead of files it will load any required files from that folder. Try something like this instead:

import futhark
importc:
  sysPath "/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.1/include"
  path "/usr/include/elementary-1/"
  path "/usr/include/eina-1/"
  "Elementary.h"
  "Efl_Config.h"

With a build command like the one you used.

Ok after adding all the dependencies are received this error now:

nim c -d:release --passL: "$(pkg-config --cflags --libs elementary)" enim.nim
Hint: used config file '/home/nixfreak/.choosenim/toolchains/nim-#devel/config/nim.cfg' [Conf]
Hint: used config file '/home/nixfreak/.choosenim/toolchains/nim-#devel/config/config.nims' [Conf]
................................................................................................................
/home/nixfreak/.nimble/pkgs/futhark-0.6.1/futhark.nim(521, 12) Hint: Running: opir -I/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.1/include/ -I/usr/include/elementary-1/ -I/usr/include/eina-1/ -I/usr/include/eina-1/eina/ -I/usr/include/eet-1/ -I/usr/include/evas-1/ -I/usr/include/ecore-1/ -I/usr/include/ecore-file-1/ -I/usr/include/ecore-input-1/ -I/usr/include/ecore-imf-1/ -I/usr/include/ecore-con-1/ -I/usr/include/ecore-evas-1/ -I/usr/include/edje-1/ -I/usr/include/eldbus-1/ -I/usr/include/efreet-1/ -I/usr/include/ethumb-1/ -I/usr/include/ethumb-client-1/ -I/usr/include/emile-1/ -I/usr/include/eo-1/ -I/usr/include/efl-1/ -I/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.1/include-fixed/ /home/nixfreak/.cache/nim/enim_r/futhark-includes.h [User]
stack trace: (most recent call last)
futhark.nim(522, 39) importcImpl
strutils.nim(852, 12) splitLines
iterators_1.nim(90, 18) substr
/home/nixfreak/build/enim.nim(2, 1) template/generic instantiation of importc from here
/home/nixfreak/.nimble/pkgs/futhark-0.6.1/futhark.nim(476, 14) template/generic instantiation of importcImpl from here
/home/nixfreak/.choosenim/toolchains/nim-#devel/lib/system/iterators_1.nim(90, 18) Error: interpretation requires too many iterations; if you are sure this is not a bug in your code, compile with --maxLoopIterationsVM:number (current value: 10000000)

Is this a memory issue?

Here is my code:

import futhark
importc:
sysPath "/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.1/include/"
path "/usr/include/elementary-1/"
path "/usr/include/eina-1/"
path "/usr/include/eina-1/eina/"
path "/usr/include/eet-1/"
path "/usr/include/evas-1/"
path "/usr/include/ecore-1/"
path "/usr/include/ecore-file-1/"
path "/usr/include/ecore-input-1/"
path "/usr/include/ecore-imf-1/"
path "/usr/include/ecore-con-1/"
path "/usr/include/ecore-evas-1/"
path "/usr/include/edje-1/"
path "/usr/include/eldbus-1/"
path "/usr/include/efreet-1/"
path "/usr/include/ethumb-1/"
path "/usr/include/ethumb-client-1/"
path "/usr/include/emile-1/"
path "/usr/include/eo-1/"
path "/usr/include/efl-1/"
path "/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.1/include-fixed/"
"limits.h"
"Elementary.h"
"Elementary_Options.h"
"Efl_Config.h"
"limits.h"
"eina_types.h"
"Eet.h"
"Evas.h"
"Ecore.h"
"Evas_GL.h"
"Ecore_Evas.h"
"Ecore_File.h"
"Ecore_Input.h"
"Ecore_IMF.h"
"Ecore_Con.h"
"Edje.h"
"Eldbus.h"
"Efreet.h"
"Efreet_Mime.h"
"Efreet_Trash.h"
"Emile.h"
"Eo.h"
"Efl.h"
"Ethumb_Client.h"

Nah, it's just the Nim compiler not allowing the parser to parse such a large JSON object, it believes it has reached an infinite loop. Just increase the max iteration loop count with --maxLoopIterationsVM:

Ok that worked I now have a 123K executable file. Thank you now on to calling those functions and see if I can do something with them.

Ok so I should be able to call this binary from nim , do you have documentation for that ? Also is there a way to actually see the functions ? Right now I'm running Futhark again and tee out a log.

Call which binary from Nim? You import functions that you should then just call like normal Nim functions. You can see the functions in the generated Futhark cache file, or by nim doc on your module.