planetis-m / naylib

Yet another raylib Nim wrapper
MIT License
234 stars 10 forks source link

Fix cross-compiling with -d:windows -d:mingw #82

Closed planetis-m closed 6 months ago

planetis-m commented 1 year ago

Dir separator is replaced with backslash. Use https://github.com/demotomohiro/pathX

ahungry commented 1 year ago

I'm having the same issue - if I try using -d:mingw it fails, stating files cannot be found (due to backslash), while they are definitely present, using the proper forward slash.

❯ nim c -d:mingw --mm:orc -o:quarm_patcher.exe quarm_patcher.nim
Hint: used config file '/home/mcarter/.choosenim/toolchains/nim-2.0.0/config/nim.cfg' [Conf]
Hint: used config file '/home/mcarter/.choosenim/toolchains/nim-2.0.0/config/config.nims' [Conf]
.......................................................................................................................
/home/mcarter/.nimble/pkgs2/naylib-4.6.1-b8dba6d8ec2d85d03665077430f315612b508f4c/raylib.nim(97, 16) Error: cannot find: \home\mcarter\.nimble\pkgs2\naylib-4.6.1-b8dba6d8ec2d85d03665077430f315612b508f4c\raylib\src\rglfw.c
❯ ls -l /home/mcarter/.nimble/pkgs2/naylib-4.6.1-b8dba6d8ec2d85d03665077430f315612b508f4c/raylib/src/rglfw.c
-rw-r--r-- 1 mcarter mcarter 5421 Sep  4 15:46 /home/mcarter/.nimble/pkgs2/naylib-4.6.1-b8dba6d8ec2d85d03665077430f315612b508f4c/raylib/src/rglfw.c

Where my file (quarm_patcher.nim) has the contents of https://github.com/planetis-m/raylib-examples/blob/main/shapes/basic_shapes.nim sample and nothing else.

planetis-m commented 8 months ago

Also related, when building from Windows for the web target, currentSourcePath.parentDir returns "."

import os

parentDir(r"C:\Users\me\raylib")
planetis-m commented 6 months ago

After adding these lines in raylib.nim:

when defined(mingw):
  import std/private/globs
  from std/private/ospaths2 import joinPath
  func `/`*(head, tail: Path): Path {.inline.} =
    joinPath(head.string, tail.string).nativeToUnixPath.Path
  {.passC: "-I/usr/x86_64-w64-mingw32/include".}
  {.passC: "-D_GLFW_X11".}

I am getting a ton of errors like:

In file included from /home/antonisg/Code/raydev/naylib/src/raylib/rglfw.c:73:
In file included from /home/antonisg/Code/raydev/naylib/src/raylib/external/glfw/src/init.c:28:
In file included from /home/antonisg/Code/raydev/naylib/src/raylib/external/glfw/src/internal.h:49:
In file included from /home/antonisg/Code/raydev/naylib/src/raylib/external/glfw/src/../include/GLFW/glfw3.h:103:
In file included from /usr/x86_64-w64-mingw32/include/stddef.h:7:
In file included from /usr/x86_64-w64-mingw32/include/crtdefs.h:10:
In file included from /usr/x86_64-w64-mingw32/include/corecrt.h:10:
/usr/x86_64-w64-mingw32/include/_mingw.h:271:2: error: Only Win32 target is supported!
  271 | #error Only Win32 target is supported!
      |  ^
In file included from In file included from /home/antonisg/Code/raydev/naylib/src/raylib/rglfw.c/home/antonisg/Code/raydev/naylib/src/raylib/rtext.c:73:
In file included from /home/antonisg/Code/raydev/naylib/src/raylib/external/glfw/src/init.c:28:
In file included from /home/antonisg/Code/raydev/naylib/src/raylib/external/glfw/src/internal.h:325:
In file included from :/home/antonisg/Code/raydev/naylib/src/raylib/external/glfw/src/platform.h56::
81In file included from :
/home/antonisg/Code/raydev/naylib/src/raylib/raylib.hIn file included from :/home/antonisg/Code/raydev/naylib/src/raylib/external/glfw/src/x11_platform.h82::
28In file included from :
/usr/x86_64-w64-mingw32/include/stdarg.hIn file included from :/usr/x86_64-w64-mingw32/include/unistd.h140::
10:
/usr/x86_64-w64-mingw32/include/_mingw_stdarg.hIn file included from :/usr/x86_64-w64-mingw32/include/io.h11::102:
: /usr/x86_64-w64-mingw32/include/string.h:error: 51:3Only Win32 target is supported!: 
error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes