Setup: pass include paths and CUDA macros to c2hs#87
Open
mgajda wants to merge 1 commit into
Open
Conversation
On distributions where CUDA headers are not in c2hs's default search path
(e.g. Ubuntu 24.04 installs to /usr/include rather than /usr/local/cuda/include),
or where the working directory at c2hs invocation does not match the package
root, two separate failures occur:
1. cbits/stubs.h not found during preprocessing:
fatal error: cbits/stubs.h: No such file or directory
The .chs files use `#include "cbits/stubs.h"` which requires the package
root to be on the c2hs include path.
2. CUDA_INSTALL_PATH undefined in Foreign.CUDA.Path:
Cannot find a definition for `CUDA_INSTALL_PATH' in the header file.
Foreign.CUDA.Path uses `{#const CUDA_INSTALL_PATH#}`, but the macro is
only passed to GHC via `-optc-D`, not forwarded to c2hs `--cppopts`.
Fix: extend the `x-extra-c2hs-options` emitted by `libraryBuildInfo` to
include:
* `--cppopts=-I.` and `--cppopts=-Icbits` for the package root and cbits/
* `--cppopts=-I\<cuda_include_dir\>` from the detected CUDA installation
* `--cppopts=-DCUDA_INSTALL_PATH=...` and `--cppopts=-DCUDA_LIBRARY_PATH=...`
Tested: c2hs 0.28.8, GHC 9.4.7, CUDA 12.0 and 13.0, Ubuntu 24.04.
Collaborator
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Branch:
fix/setup-c2hs-includesCommit:
Setup: pass include paths and CUDA macros to c2hsOn Ubuntu 24.04 (and other distributions where the CUDA toolkit installs to a non-standard layout), two separate build failures occur during the c2hs preprocessing stage.
Failure 1 —
cbits/stubs.hnot found:The .chs files use
#include "cbits/stubs.h", which requires the package root to be on the c2hs include path. The currentSetup.hsdoes not add it.Failure 2 —
CUDA_INSTALL_PATHundefined inForeign.CUDA.Path:Foreign.CUDA.Pathuses{#const CUDA_INSTALL_PATH#}. The macro is passed to GHC via-optc-Dbut not forwarded to c2hs via--cppopts, so c2hs cannot resolve it.The fix extends the
x-extra-c2hs-optionsgenerated bylibraryBuildInfoto include:--cppopts=-I.and--cppopts=-Icbitsso relative includes from .chs files resolve--cppopts=-I<cuda_include_dir>from the detected CUDA installation--cppopts=-DCUDA_INSTALL_PATH=...and--cppopts=-DCUDA_LIBRARY_PATH=...Tested: c2hs 0.28.8, GHC 9.4.7, CUDA 12.0 and 13.0, Ubuntu 24.04.