Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape backslashes used in -D flags on Windows. #50

Merged
merged 1 commit into from
Oct 24, 2017

Conversation

TravisWhitaker
Copy link
Contributor

Setup.hs as it is on master yields this cuda.buildinfo.generated on my Windows 10 machine (GHC 8.2.1, Stack 1.5.1):

buildable: True
cc-options: -DCUDA_INSTALL_PATH="C:\cuda\8\dev"
            -DCUDA_LIBRARY_PATH="C:\cuda\8\dev\lib/x64" -IC:\cuda\8\dev\include
ld-options: -LC:\cuda\8\dev\lib/x64
extra-libraries:
    cudart
    cuda
extra-ghci-libraries: cudart64_80
                      nvcuda
extra-lib-dirs: C:\cuda\8\dev\lib/x64
x-extra-c2hs-options: --cppopts=-E --cppopts=-m64 --cppopts=-DUSE_EMPTY_CASE

With this, stack build --stack-yaml=stack-8.2.yaml yields this:

c2hs.exe: C header contains errors:

.stack-work\\dist\\e53504d9\\build\\Foreign\\CUDA\\Path.chs.h:2: (column 24) [ERROR]  >>> Lexical error !
  The character '"' does not fit here.

This seems related to @yuhangwang's issue #48. Escaping the backslashes in the -D flags let's the build proceed, like so:

buildable: True
cc-options: -DCUDA_INSTALL_PATH="C:\\cuda\\8\\dev"
            -DCUDA_LIBRARY_PATH="C:\\cuda\\8\\dev\\lib/x64" -IC:\cuda\8\dev\include
ld-options: -LC:\cuda\8\dev\lib/x64
extra-libraries:
    cudart
    cuda
extra-ghci-libraries: cudart64_80
                      nvcuda
extra-lib-dirs: C:\cuda\8\dev\lib/x64
x-extra-c2hs-options: --cppopts=-E --cppopts=-m64 --cppopts=-DUSE_EMPTY_CASE

Strangely this only must be done with the -D flags; there's something strange among Windows, MinGW, and/or c2hs going on. This patch has Setup.hs escape the backslashes when on Windows. I believe it is always safe to do this, but there may be some Windows-specific edge case I'm missing. I'll also note that I get this error when building, although the build succeeds and the library seems to work:

In file included from .\cbits\stubs.h:9:0: error:
    0,
                     from cbits\init.c:1:
C:\cuda\8\dev\include/host_defines.h:84:0: warning: "__cdecl" redefined
 #define __cdecl

<built-in>: note: this is the location of the previous definition

In file included from .\cbits\stubs.h:9:0: error:
    0,
                     from cbits\stubs.c:5:
C:\cuda\8\dev\include/host_defines.h:84:0: warning: "__cdecl" redefined
 #define __cdecl

If all is well it'd be nice to get a point release with this fix, since I don't think there's a way to build this package on Windows otherwise (disregarding any Cygwin trickery).

@tmcdonell tmcdonell merged commit f486338 into tmcdonell:master Oct 24, 2017
@tmcdonell
Copy link
Owner

Awesome work, thanks!

Uploaded as cuda-0.8.0.1.

@TravisWhitaker TravisWhitaker deleted the windows-escape branch October 24, 2017 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants