ayman-albaz / nim-duckdb

DuckDB wrapper in Nim
Apache License 2.0
20 stars 4 forks source link

Not on Nimble (also - fails to compile on Windows) #2

Closed winrid closed 1 year ago

winrid commented 1 year ago

Hello!

Thanks for taking the time to do this and put it on GitHub!

I'm fairly new to Nim, but I was wondering how to use this library. It does not appear in Nimble for me.

As a temporary workaround I've copied the sources into my project, but it fails to compile with:

C:\Users\winrid\nimcache\nimterop\toastCache\nimterop_673525496.nim(292, 36) Error: undeclared identifier: 'dllimport'
candidates (edit distance, scope distance); see '--spellSuggest': 
 (3, 0): 'cimport' [module declared in c:\Users\winrid\Documents\ioteer\lib\duckdb\duckdb\duckdb_wrapper.nim(1, 16)]
 (3, 2): 'c2nImport' [macro declared in C:\Users\winrid\.nimble\pkgs\nimterop-0.6.13\nimterop\cimport.nim(707, 7)]
 (3, 2): 'cImport' [macro declared in C:\Users\winrid\.nimble\pkgs\nimterop-0.6.13\nimterop\cimport.nim(611, 7)]
 (3, 2): 'cImport' [macro declared in C:\Users\winrid\.nimble\pkgs\nimterop-0.6.13\nimterop\cimport.nim(652, 7)]

I haven't found much searching for this Error, yet. :)

winrid commented 1 year ago

Ah, looks like maybe a Windows-specific error w/ nimterop and DuckDB:

# const 'DUCKDB_API' has unsupported value '__declspec(dllimport)'
# const 'DUCKDB_API_LATEST' has unsupported value 'DUCKDB_API_0_3_2'
# const 'DUCKDB_API_VERSION' has unsupported value 'DUCKDB_API_LATEST'
winrid commented 1 year ago

Confirmed compiles fine on Linux.

ayman-albaz commented 1 year ago

Regarding this package not being available on nimble that is fine.

You can use the command nimble install https://github.com/ayman-albaz/nim-duckdb for any packages not yet on nimble.

Windows error should now be gone. Error was due to incorrect dynamic library selection. Windows now added to CICD to insure windows support.

Also note, you may have to delete the nimcache folder from your windows machine in order for the new libraries to download.

If problems persists, please open this issue.

winrid commented 1 year ago

Thanks! That solved it. I now get another issue, which might be a bug in Nim, or maybe something wrong with the toolchain on my machine, but not sure yet. It's:

C:\Users\winrid\nimcache\@m..@s..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem@sansi_c.nim.c: In function 'c_setjmp__systemZansi95c_42':
C:\Users\winrid\nimcache\@m..@s..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem@sansi_c.nim.c:27:11: error: too many arguments to function '_setjmp'
  result = _setjmp(jmpb, NIM_NIL);
           ^~~~~~~
In file included from C:\Users\winrid\nimcache\@m..@s..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem@sansi_c.nim.c:8:0:
c:\mingw\include\setjmp.h:39:37: note: declared here
 _CRTIMP int __cdecl __MINGW_NOTHROW _setjmp (jmp_buf);
                                     ^~~~~~~
CC: ../../../.choosenim/toolchains/nim-1.6.8/lib/system/ansi_c.nim
CC: ../../../.choosenim/toolchains/nim-1.6.8/lib/system.nim
Error: execution of an external compiler program 'gcc.exe -c  -w -fmax-errors=3 -mno-ms-bitfields   -IC:\Users\winrid\.choosenim\toolchains\nim-1.6.8\lib -IC:\Users\winrid\nimcache\nimterop\cPlugins -o C:\Users\winrid\nimcache\@m..@s..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem@sansi_c.nim.c.o C:\Users\winrid\nimcache\@m..@s..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem@sansi_c.nim.c' failed with exit code: 1

C:\Users\winrid\nimcache\@m..@s..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem.nim.c: In function 'showErrorMessage__system_2538':
C:\Users\winrid\nimcache\@m..@s..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem.nim.c:3802:44: error: too many arguments to function '_setjmp'
   TM__Q5wkpxktOdTGvlSRo9bzt9aw_26.status = _setjmp(TM__Q5wkpxktOdTGvlSRo9bzt9aw_26.context, 0);
                                            ^~~~~~~
In file included from C:\Users\winrid\nimcache\@m..@s..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem.nim.c:9:0:
c:\mingw\include\setjmp.h:39:37: note: declared here
 _CRTIMP int __cdecl __MINGW_NOTHROW _setjmp (jmp_buf);
                                     ^~~~~~~

Failed to compile cPlugin()

cmd: C:\Users\winrid\.choosenim\toolchains\nim-1.6.8\bin\nim.exe c --app:lib --gc:markAndSweep  --out:"C:\Users\winrid\nimcache\nimterop\cPlugins\nimterop_1221099484.dll" C:\Users\winrid\nimcache\nimterop\cPlugins\nimterop_1221099484.nim [AssertionDefect]

Looks like Nim is trying to pass NIM_NIL as a second argument to _setjmp, which does only takes one argument: https://linux.die.net/man/3/_setjmp

winrid commented 1 year ago

Note - the above does not appear related to this library. Ripped out library and deleted nimcache etc. But, it was compiling before, and not after installing duckdb. Weird! I've tried setting nimcache to a different directory, not sure what else to try yet. Anyway, thanks for fixing the bug. :)

Update: well, it compiles fine on WSL... screw windows I guess. :)

ayman-albaz commented 1 year ago

Thanks! That solved it. I now get another issue, which might be a bug in Nim, or maybe something wrong with the toolchain on my machine, but not sure yet. It's:

C:\Users\winrid\nimcache\@m..@s..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem@sansi_c.nim.c: In function 'c_setjmp__systemZansi95c_42':
C:\Users\winrid\nimcache\@m..@s..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem@sansi_c.nim.c:27:11: error: too many arguments to function '_setjmp'
  result = _setjmp(jmpb, NIM_NIL);
           ^~~~~~~
In file included from C:\Users\winrid\nimcache\@m..@s..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem@sansi_c.nim.c:8:0:
c:\mingw\include\setjmp.h:39:37: note: declared here
 _CRTIMP int __cdecl __MINGW_NOTHROW _setjmp (jmp_buf);
                                     ^~~~~~~
CC: ../../../.choosenim/toolchains/nim-1.6.8/lib/system/ansi_c.nim
CC: ../../../.choosenim/toolchains/nim-1.6.8/lib/system.nim
Error: execution of an external compiler program 'gcc.exe -c  -w -fmax-errors=3 -mno-ms-bitfields   -IC:\Users\winrid\.choosenim\toolchains\nim-1.6.8\lib -IC:\Users\winrid\nimcache\nimterop\cPlugins -o C:\Users\winrid\nimcache\@m..@s..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem@sansi_c.nim.c.o C:\Users\winrid\nimcache\@m..@s..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem@sansi_c.nim.c' failed with exit code: 1

C:\Users\winrid\nimcache\@m..@s..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem.nim.c: In function 'showErrorMessage__system_2538':
C:\Users\winrid\nimcache\@m..@s..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem.nim.c:3802:44: error: too many arguments to function '_setjmp'
   TM__Q5wkpxktOdTGvlSRo9bzt9aw_26.status = _setjmp(TM__Q5wkpxktOdTGvlSRo9bzt9aw_26.context, 0);
                                            ^~~~~~~
In file included from C:\Users\winrid\nimcache\@m..@s..@s..@s.choosenim@stoolchains@snim-1.6.8@slib@ssystem.nim.c:9:0:
c:\mingw\include\setjmp.h:39:37: note: declared here
 _CRTIMP int __cdecl __MINGW_NOTHROW _setjmp (jmp_buf);
                                     ^~~~~~~

Failed to compile cPlugin()

cmd: C:\Users\winrid\.choosenim\toolchains\nim-1.6.8\bin\nim.exe c --app:lib --gc:markAndSweep  --out:"C:\Users\winrid\nimcache\nimterop\cPlugins\nimterop_1221099484.dll" C:\Users\winrid\nimcache\nimterop\cPlugins\nimterop_1221099484.nim [AssertionDefect]

Looks like Nim is trying to pass NIM_NIL as a second argument to _setjmp, which does only takes one argument: https://linux.die.net/man/3/_setjmp

This appears to be a compiler bug. I have seen something similar to this before for C interop libs and specific GC configs.

Try removing the gc you selected and try the default nim one and if that fails try ORC.

I also recommend submitting this bug to the official nim github repo.

ayman-albaz commented 1 year ago

Note - the above does not appear related to this library. Ripped out library and deleted nimcache etc. But, it was compiling before, and not after installing duckdb. Weird! I've tried setting nimcache to a different directory, not sure what else to try yet. Anyway, thanks for fixing the bug. :)

Update: well, it compiles fine on WSL... screw windows I guess. :)

WSL saves the day for windows yet again !