dom96 / choosenim

Tool for easily installing and managing multiple versions of the Nim programming language.
BSD 3-Clause "New" or "Revised" License
679 stars 67 forks source link

choosenim should update mingw as well #130

Open rayman22201 opened 4 years ago

rayman22201 commented 4 years ago

On Windows, different versions of Nim apparently require different versions of Mingw, but choosenim does not have any way to independently update Mingw (or change the Mingw version).

Choosenim should provide a way to update and choose the version of Mingw that is used, not just the version that is installed with choosenim by default, or the system Mingw.

Perhaps a warning about the system Mingw being too old would also be useful, if a system Mingw is detected.

This is related to #129 and #128

peheje commented 4 years ago

On Windows 10 I just updated to Nim 1.2, but this fails when I try to compile to C and run seems to fail:

C:\Users\PHJ\nimcache\app_d\stdlib_io.nim.c.o:stdlib_io.nim.c:(.text+0x686): undefined reference to `__builtin_sadd_overflow'
C:\Users\PHJ\nimcache\app_d\stdlib_io.nim.c.o:stdlib_io.nim.c:(.text+0x72d): undefined reference to `__builtin_sadd_overflow'
C:\Users\PHJ\nimcache\app_d\stdlib_io.nim.c.o:stdlib_io.nim.c:(.text+0x857): undefined reference to `__builtin_sadd_overflow'
C:/Users/PHJ/.choosenim/toolchains/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.9.1/../../../../i686-w64-mingw32/bin/ld.exe: C:\Users\PHJ\nimcache\app_d\stdlib_io.nim.c.o: bad reloc address 0x20 in section `.eh_frame'
C:/Users/PHJ/.choosenim/toolchains/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.9.1/../../../../i686-w64-mingw32/bin/ld.exe: final link failed: Invalid operation
Error: execution of an external program failed: 'gcc.exe   -o c:\Users\PHJ\Desktop\dev\app.exe  C:\Users\PHJ\nimcache\app_d\stdlib_io.nim.c.o C:\Users\PHJ\nimcache\app_d\stdlib_system.nim.c.o C:\Users\PHJ\nimcache\app_d\@mapp.nim.c.o    '

I'm guessing because MinGW needs update, compiling c++ gives slightly more info it seems

C:\Users\PHJ\nimcache\app_d\stdlib_io.nim.cpp: In function 'void writeWindows__JO9bn8JE1R6MjKZqdvhBrWg(FILE*, NimStringDesc*, bool)':
C:\Users\PHJ\.choosenim\toolchains\nim-1.2.0\lib/nimbase.h:562:67: error: '__builtin_sadd_overflow' was not declared in this scope
     #define nimAddInt(a, b, res) __builtin_sadd_overflow(a, b, res)
                                                                   ^
C:\Users\PHJ\nimcache\app_d\stdlib_io.nim.cpp:427:9: note: in expansion of macro 'nimAddInt'
     if (nimAddInt(i, ((NI) 1), &TM__MnCJ0VAmeZ9aTATUB39cx60Q_11)) { raiseOverflow(); };
         ^
C:\Users\PHJ\.choosenim\toolchains\nim-1.2.0\lib/nimbase.h:562:67: error: '__builtin_sadd_overflow' was not declared in this scope
     #define nimAddInt(a, b, res) __builtin_sadd_overflow(a, b, res)
                                                                   ^
C:\Users\PHJ\nimcache\app_d\stdlib_io.nim.cpp:447:9: note: in expansion of macro 'nimAddInt'
     if (nimAddInt(i, ((NI) (w_2)), &TM__MnCJ0VAmeZ9aTATUB39cx60Q_12)) { raiseOverflow(); };
         ^
C:\Users\PHJ\nimcache\app_d\stdlib_io.nim.cpp: In function 'void echoBinSafe(NimStringDesc**, NI)':
C:\Users\PHJ\.choosenim\toolchains\nim-1.2.0\lib/nimbase.h:562:67: error: '__builtin_sadd_overflow' was not declared in this scope
     #define nimAddInt(a, b, res) __builtin_sadd_overflow(a, b, res)
                                                                   ^
C:\Users\PHJ\nimcache\app_d\stdlib_io.nim.cpp:475:9: note: in expansion of macro 'nimAddInt'
     if (nimAddInt(i, ((NI) 1), &TM__MnCJ0VAmeZ9aTATUB39cx60Q_13)) { raiseOverflow(); };
         ^
Error: execution of an external compiler program 'g++.exe -c  -w -mno-ms-bitfields -w -fpermissive -mno-ms-bitfields  -std=gnu++14 -funsigned-char  -IC:\Users\PHJ\.choosenim\toolchains\nim-1.2.0\lib -Ic:\Users\PHJ\Desktop\dev -o C:\Users\PHJ\nimcache\app_d\stdlib_io.nim.cpp.o C:\Users\PHJ\nimcache\app_d\stdlib_io.nim.cpp' failed with exit code: 1

PS C:\Users\PHJ\Desktop\dev> In file included from C:\Users\PHJ\nimcache\app_d\stdlib_system.nim.cpp:9:0:
C:\Users\PHJ\nimcache\app_d\stdlib_system.nim.cpp: In function 'void* newSeq(TNimType*, NI)':
C:\Users\PHJ\.choosenim\toolchains\nim-1.2.0\lib/nimbase.h:564:67: error: '__builtin_smul_overflow' was not declared in this scope
     #define nimMulInt(a, b, res) __builtin_smul_overflow(a, b, res)
                                                                   ^
C:\Users\PHJ\nimcache\app_d\stdlib_system.nim.cpp:5170:6: note: in expansion of macro 'nimMulInt'
  if (nimMulInt(len, (*(*typ).base).size, &TM__Q5wkpxktOdTGvlSRo9bzt9aw_12)) { raiseOverflow(); };
      ^
C:\Users\PHJ\.choosenim\toolchains\nim-1.2.0\lib/nimbase.h:562:67: error: '__builtin_sadd_overflow' was not declared in this scope
     #define nimAddInt(a, b, res) __builtin_sadd_overflow(a, b, res)
                                                                   ^
C:\Users\PHJ\nimcache\app_d\stdlib_system.nim.cpp:5171:6: note: in expansion of macro 'nimAddInt'
  if (nimAddInt((NI)(TM__Q5wkpxktOdTGvlSRo9bzt9aw_12), ((NI) 8), &TM__Q5wkpxktOdTGvlSRo9bzt9aw_13)) { raiseOverflow(); };
      ^
C:\Users\PHJ\nimcache\app_d\stdlib_system.nim.cpp: In function 'NI atomicInc__v6qORsZ9azlHHhOL1JYACRAsystem(NI&, NI)':
C:\Users\PHJ\.choosenim\toolchains\nim-1.2.0\lib/nimbase.h:562:67: error: '__builtin_sadd_overflow' was not declared in this scope
     #define nimAddInt(a, b, res) __builtin_sadd_overflow(a, b, res)
                                                                   ^
C:\Users\PHJ\nimcache\app_d\stdlib_system.nim.cpp:5449:6: note: in expansion of macro 'nimAddInt'
  if (nimAddInt(memLoc, x, &TM__Q5wkpxktOdTGvlSRo9bzt9aw_9)) { raiseOverflow(); };
dom96 commented 4 years ago

Looks like it, you might have luck deleting C:/Users/PHJ/.choosenim/toolchains/mingw32 and re-running choosenim. If all else fails you can always download your own mingw and put it in your PATH, choosenim will use it automatically.

rayman22201 commented 4 years ago

Yeah.

This is the same issue as the old GCC version bug reported here: https://forum.nim-lang.org/t/6175#38128

You either need to upgrade your Mingw or enable the -d:nimEmulateOverflowChecks flag.

(I think @Araq underestimated how many people still have older C compilers that don't support the overflow check feature... There might need to be some automatic compiler feature detection that needs to be implemented in various parts of the the install process... idk)

peheje commented 4 years ago

Thanks both of you for this helping hand.

I tried to nuke the .choosenim and start it from scratch but it failed.

Sorry my evening has been hectic so didn't take images. I eventually got it working through other means through which MinGW was updated.

Have a good night 😊