PMunch / futhark

Automatic wrapping of C headers in Nim
MIT License
382 stars 21 forks source link

Why `from os import parentDir`? #126

Open 29th-Day opened 6 days ago

29th-Day commented 6 days ago

I'm trying to create a wrapper for a library on an embedded device and I use the --os:any flag when compiling my code. Therefore, the os module is not available but from is import parentDir is present in every wrapper file but never used. Why is this present and is there an automatic way of avoiding it?

My nim file for creating the wrapper looks like this

import os, futhark

importc:
  outputPath currentSourcePath.parentDir / "lib"
  path "/path/to/lib/include/"
  "header.h"
PMunch commented 5 days ago

The problem is actually not the wrapper, but Futharks code itself. There's a bug in Nim where the target is the only thing deciding whether or not the os module is available. So even if you're compiling from a host with the os module available, as long as the target doesn't have it then it's not available even for macros. The way to solve it is to use a two step process. Have one program run and create the wrapper, making sure to pass all the right flags to the C compiler (Futhark doesn't inherit the passC and passL's of the program, you need to set these in the importc block). Then a second program which uses the wrapper from the first and compiles with --os:any. This is what I do for my FreeRTOS wrapper.