janet-lang/janet

Mingw compilation error

Closed this issue ยท 10 comments

The problem is that mingw is using int32_t for JanetAtomicInt instead of long.

src/core/state.c: In function 'janet_interpreter_interrupt_handled':
src/core/state.c:75:26: error: passing argument 1 of '_InterlockedDecrement' from incompatible pointer type [-Wincompatible-pointer-types]
75 | InterlockedDecrement(&vm->auto_suspend);
| ^~~~~~~~~~~~~~~~~
| |
| volatile int32_t * {aka volatile int *}
C:/msys64/mingw64/include/psdk_inc/intrin-impl.h:1692:51: note: expected 'volatile long int *' but argument is of type 'volatile int32_t *' {aka 'volatile int *'}

How are you building Janet? We do have some Mingw tests in our CI so I'm a bit confused on how this is happening.

So I checked the TIC80 source code, I believe you are on version 1.34? The latest janet should have a fix for this - on windows, Janet atomics are exposed as long instead of int32. Please make sure you are using the latest release of Janet.

I'll check with latest. Yep, we are in v1.34 because 1.36 had problems with winxp builds I think.

Weird, with v1.36 I get this error: src/core/capi.c: In function 'janet_atomic_inc':
src/core/capi.c:550:12: error: implicit declaration of function 'InterlockedIncrement' [-Wimplicit-function-declaration]
src/core/capi.c: In function 'janet_atomic_dec':
src/core/capi.c:560:12: error: implicit declaration of function 'InterlockedDecrement' [-Wimplicit-function-declaration]
src/core/capi.c: In function 'janet_atomic_load':
src/core/capi.c:570:12: error: implicit declaration of function 'InterlockedOr' [-Wimplicit-function-declaration]

Took a deeper look at this, and noticed that TIC-80 uses a custom build of Janet that is single threaded. This causes us to, on windows, not include windows.h for you.

With this fix, I'm able to build TIC-80 with Janet on windows-mingw - https://github.com/bakpakin/TIC-80/actions/runs/11284749144/job/31386437246

I'll check with latest. Yep, we are in v1.34 because 1.36 had problems with winxp builds I think.

My guess is that this is related to the inclusion of SRWLock and some networking code for the ev module - since TIC-80 is single threaded, this shouldn't be totally necessary on windows. from (in janet) features.h

/* needed for inet_pton and InitializeSRWLock */
#ifdef __MINGW32__
#define _WIN32_WINNT _WIN32_WINNT_VISTA
#endif

Fix is here: 43a68dc

While we are here though, I would like to make sure that windows XP is working to for Janet since they are probably related.

@Miguel-hrvs let me know if XP is still an issue.

Thanks, mingw and msvc 2019 now build great. Wonder why winxp still fails.
Creating library build\janet_boot.lib and object build\janet_boot.exp
capi.obj : error LNK2019: unresolved external symbol _InterlockedOr referenced in function _janet_atomic_load [D:\a\TIC-80\TIC-80\build\janet.vcxproj]
build\janet_boot.exe : fatal error LNK1120: 1 unresolved externals

Ok, more looking around, there is no reason to use Interlocked* functions at all unless 1. we are on windows and we are using MSVC.

This change use MSVCs compiler intrinsics when needed, and on mingw will use GCCs intrinsics, meaning we don't need to include any thing. d10c1fe

Also tried it out with TIC-80, looks like it builds now on winxp too: https://github.com/bakpakin/TIC-80/actions/runs/11301442227/job/31435854576

@Miguel-hrvs feel free to close if this works for you. These changes will make it into the next release of Janet.

Perfect, now it builds in winxp too. Thank you, I'll close the issue.