PMunch / futhark

Automatic wrapping of C headers in Nim
MIT License
394 stars 22 forks source link

Trouble building and testing on Mac OS 14 #127

Open dctucker opened 1 month ago

dctucker commented 1 month ago

Nim v1.6.20

I'm unable to use futhark with Nim v1.6.x:

/Users/dctucker/.nimble/pkgs/futhark-0.13.6/futhark.nim(245, 28) Error: expression 'kind["value"].str' is of type 'string' and has to be used (or discarded)

I have a workaround for this using Nim v2.x to run futhark for generating wrapper code, but I have a preference for 1.6.x since another library I'm using (uing) behaves more predictably at runtime when compiled with older Nim. It'd be nice if I could avoid running choosenim for this step.

Nim v2.x

Using Nim v2.2.0 yields better results, but unless I explicitly specify sysPath, it fails to find stdio.h:

$ nimble futhark
  Verifying dependencies for nimvlc@0.1.0
  Executing task futhark in /Users/dctucker/Development/nimvlc/nimvlc.nimble
Hint: used config file '/Users/dctucker/.choosenim/toolchains/nim-2.2.0/config/nim.cfg' [Conf]
Hint: used config file '/Users/dctucker/.choosenim/toolchains/nim-2.2.0/config/config.nims' [Conf]
...............................................................................................................................................
/Users/dctucker/.nimble/pkgs/futhark-0.13.6/futhark.nim(829, 7) Hint: Running: opir -I/usr/include -I/Applications/VLC.app/Contents/MacOS/include /Users/dctucker/.cache/nim/gen_d/futhark-includes.h [User]
stack trace: (most recent call last)
/Users/dctucker/.nimble/pkgs/futhark-0.13.6/futhark.nim(838, 9) importcImpl
/Users/dctucker/Development/nimvlc/src/gen.nim(15, 5) template/generic instantiation of `importc` from here
/Users/dctucker/.nimble/pkgs/futhark-0.13.6/futhark.nim(708, 14) template/generic instantiation of `importcImpl` from here
/Users/dctucker/.nimble/pkgs/futhark-0.13.6/futhark.nim(838, 9) Error: Opir exited with non-zero exit code 255.
Opir output:
Fatal: 'stdio.h' file not found /Applications/VLC.app/Contents/MacOS/include/vlc/libvlc.h:56:10 2077
Tried to parse: /Users/dctucker/.cache/nim/gen_d/futhark-includes.h
With arguments: -I/usr/include -I/Applications/VLC.app/Contents/MacOS/include
Unable to parse translation unit succesfully. Quitting
stack trace: (most recent call last)
/private/var/folders/1j/7j51cr512hj69tzdsj6153340000gn/T/nimblecache-3013547234098513788/nimscriptapi_2432715556752558808.nim(212, 16)
/Users/dctucker/Development/nimvlc/nimvlc.nimble(26, 5) futharkTask
/Users/dctucker/.choosenim/toolchains/nim-2.2.0/lib/system/nimscript.nim(264, 7) exec
/Users/dctucker/.choosenim/toolchains/nim-2.2.0/lib/system/nimscript.nim(264, 7) Error: unhandled exception: FAILED: nim c -c -d:useFuthark -d:futharkRebuild -d:nodeclguards src/gen.nim [OSError]
       Tip: 1 messages have been suppressed, use --verbose to show them.
nimscriptwrapper.nim(161) execScript

    Error:  Exception raised during nimble script execution

Again, there's a workaround for this, but this does seem like unexpected behavior to me, and maybe it's possible for futhark to auto-detect a proper sysPath within a when(macosx) block.

Test

When I build on Linux things more-or-less work without additional effort. On Mac, I'm unable to run a test binary despite adding the following to the top of my library:

{.passL: "-L/Applications/VLC.app/Contents/MacOS/lib".}
{.passL: "-rpath /Applications/VLC.app/Contents/MacOS/lib".}

SIGSEGV

(redacted) This one gets resolved at runtime by adding VLC_PLUGIN_PATH to the environment. No more SIGSEGV, just a known libvlc on Mac quirk.

Sorry for opening such a long-bodied issue, I just figured having this all in one place would be more useful than opening several related issues.

dctucker commented 1 month ago

Another related issue with building on Mac that I neglected to mention in the initial description is relative paths are ineffective when supplied to the path directive. If I supply a full system path it works normally, but when supplying a path relative to my source tree (as I am able to do on Linux) it indicates file not found:

$ nimble futhark
  Verifying dependencies for nimvlc@0.1.0
  Executing task futhark in /Users/dctucker/Development/nimvlc/nimvlc.nimble
Hint: used config file '/Users/dctucker/.choosenim/toolchains/nim-2.2.0/config/nim.cfg' [Conf]
Hint: used config file '/Users/dctucker/.choosenim/toolchains/nim-2.2.0/config/config.nims' [Conf]
...............................................................................................................................................
/Users/dctucker/.nimble/pkgs/futhark-0.13.6/futhark.nim(829, 7) Hint: Running: opir -I/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include /Users/dctucker/.cache/nim/gen_d/futhark-includes.h [User]
stack trace: (most recent call last)
/Users/dctucker/.nimble/pkgs/futhark-0.13.6/futhark.nim(838, 9) importcImpl
/Users/dctucker/Development/nimvlc/src/gen.nim(19, 5) template/generic instantiation of `importc` from here
/Users/dctucker/.nimble/pkgs/futhark-0.13.6/futhark.nim(708, 14) template/generic instantiation of `importcImpl` from here
/Users/dctucker/.nimble/pkgs/futhark-0.13.6/futhark.nim(838, 9) Error: Opir exited with non-zero exit code 255.
Opir output:
Fatal: 'vlc/libvlc.h' file not found /Users/dctucker/.cache/nim/gen_d/futhark-includes.h:1:10 9
Tried to parse: /Users/dctucker/.cache/nim/gen_d/futhark-includes.h
With arguments: -I/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include
Unable to parse translation unit succesfully. Quitting
stack trace: (most recent call last)
/private/var/folders/1j/7j51cr512hj69tzdsj6153340000gn/T/nimblecache-3013547234098513788/nimscriptapi_2432715556752558808.nim(212, 16)
/Users/dctucker/Development/nimvlc/nimvlc.nimble(26, 5) futharkTask
/Users/dctucker/.choosenim/toolchains/nim-2.2.0/lib/system/nimscript.nim(264, 7) exec
/Users/dctucker/.choosenim/toolchains/nim-2.2.0/lib/system/nimscript.nim(264, 7) Error: unhandled exception: FAILED: nim c -c -d:useFuthark -d:futharkRebuild -d:nodeclguards src/gen.nim [OSError]
       Tip: 1 messages have been suppressed, use --verbose to show them.
nimscriptwrapper.nim(161) execScript

    Error:  Exception raised during nimble script execution

Looking in the folder it mentions (~/.cache/nim/gen_d) I can see the futhark.includes.h attempts to include all of the header files from the importc directive as expected, but since either the include path is ignored AND the header files are absent from the gen_d directory, the above error is shown.

I think this is fixable but I'm low on implementation details at the moment and can't yet propose a fix. My current workaround is specifying the absolute path to my source tree.