geotre / wren

A nim wrapper for Wren, an embedded scripting language
MIT License
11 stars 1 forks source link

Can't compile programs that use the wrapper #7

Open liquidev opened 5 years ago

liquidev commented 5 years ago

I just tried installing the Nimble package, and I tried to run the following source code:

import wren

var vm = defaultConfig().newVM()
echo vm.interpret("main", """System.print("Hello, World!")""")

However, this error popped up during compilation:

Error: execution of an external compiler program 'gcc -c  -w -I"/home/daknus/.nimble/pkgs/wren-0.2.0/wren/git/src/include" -I"/home/daknus/.nimble/pkgs/wren-0.2.0/wren/git/src/vm" -I"/home/daknus/.nimble/pkgs/wren-0.2.0/wren/git/src/optional"  -I'/home/daknus/.choosenim/toolchains/nim-#devel/lib' -I/home/daknus/Coding/Nim/wrentest -o /home/daknus/.cache/nim/wrentest_d/wren_libwren.c.o /home/daknus/.cache/nim/wrentest_d/wren_libwren.c' failed with exit code: 1

/home/daknus/.cache/nim/wrentest_d/wren_libwren.c: In function ‘wren_libwrenDatInit000’:
/home/daknus/.cache/nim/wrentest_d/wren_libwren.c:98:43: error: invalid application of ‘sizeof’ to incomplete type ‘struct WrenConfiguration’
 NTI_jkZaaPp7ATeGOEOHyTyOdg_.size = sizeof(struct WrenConfiguration);
                                           ^~~~~~
geotre commented 5 years ago

Can you paste the output of nim -v and gcc -v? I have tested on Fedora 29 and the code above works as expected. What command are you using to compile?

liquidev commented 5 years ago

I installed the latest development build of Nim yesterday (0.19.9). Not sure about the gcc version, I'll check back later when I get back home. Also using Fedora 29. I'm using the following command to compile my code:

$ nim c -r wrentest.nim

I'll try updating gcc and report back on the issue.

geotre commented 5 years ago

On a fresh install of fedora 29:

> yum install git gcc
> curl https://nim-lang.org/choosenim/init.sh -sSf | sh  # install choosenim
> choosenim devel
> nimble install wren
> vim test.nim  # pasted your code above
> nim c -r test.nim
[echo]  "Hello, World!"
WREN_RESULT_SUCCESS

Also tested on stable:

> choosenim stable
Switched to Nim 0.19.2
> nim c -r test.nim
[echo]  "Hello, World!"
WREN_RESULT_SUCCESS

Your nim compiler seems to be generating different code, in your paste above you have NTI_jkZaaPp7ATeGOEOHyTyOdg_.size = sizeof(struct WrenConfiguration);, but in the same file after compiling I have NTI_jkZaaPp7ATeGOEOHyTyOdg_.size = sizeof(WrenConfiguration); (after compiling on devel and stable). Maybe you have an old version of the nim compiler being used accidentally?

liquidev commented 5 years ago

The version is not old, for sure, this is the output of nim -v:

Nim Compiler Version 0.19.9 [Linux: amd64]
Compiled at 2019-01-22
Copyright (c) 2006-2018 by Andreas Rumpf

active boot switches: -d:release

gcc -v:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 8.2.1 20181215 (Red Hat 8.2.1-6) (GCC)

I recompiled Nim today using choosenim update devel.

geotre commented 5 years ago

Can't reproduce this

zacharycarter commented 5 years ago

I was able to reproduce this on WIndows 10 - it seems to be that nimgen is generating

WrenConfiguration* {.importc: "struct WrenConfiguration", header: headerlibwren,
                      bycopy.} = object

and

WrenForeignClassMethods* {.importc: "struct WrenForeignClassMethods",
                            header: headerlibwren, bycopy.} = object

I'm guessing something is up in the cfg file - I will look into fixing this.

genotrance commented 5 years ago

This might be due to https://github.com/nim-lang/c2nim/issues/150.

You might want to try updating to the latest c2nim.

geotre commented 5 years ago

That's interesting, will reopen this issue now and try to reproduce.

@genotrance is there a nice way of asserting a minimum version of c2nim in nimgen?

zacharycarter commented 5 years ago

Can confirm, that after installing the latest c2nim, this problem no longer presents itself. Thanks for the tip @genotrance .