janet-lang / janet

A dynamic language and bytecode vm
https://janet-lang.org
MIT License
3.43k stars 221 forks source link

Windows build issue via cmake generated files for TIC-80 #1293

Closed sogaiu closed 11 months ago

sogaiu commented 11 months ago

We're trying to update the version of Janet used in TIC-80 and are encountering issues for Windows builds in CI.

When trying to build via TIC-80's cmake generated files, the following sort of output is observed:

state.obj : error LNK2019: unresolved external symbol _InterlockedIncrement referenced in function _janet_interpreter_interrupt [D:\a\TIC-80\TIC-80\build\janet.vcxproj]
state.obj : error LNK2019: unresolved external symbol _InterlockedDecrement referenced in function _janet_interpreter_interrupt_handled [D:\a\TIC-80\TIC-80\build\janet.vcxproj]
build\janet_boot.exe : fatal error LNK1120: 2 unresolved externals [D:\a\TIC-80\TIC-80\build\janet.vcxproj]

via: https://github.com/nesbox/TIC-80/actions/runs/6223953191/job/16891060122?pr=2306#step:4:1692

I noticed that some other source files under Janet's src/core have includes for the Windows case, so I tried the following patch to src/core/state.c:

diff --git a/src/core/state.c b/src/core/state.c
index 4c976da..b17fb9d 100644
--- a/src/core/state.c
+++ b/src/core/state.c
@@ -53,6 +53,10 @@ void janet_vm_load(JanetVM *from) {
     janet_vm = *from;
 }

+#ifdef JANET_WINDOWS
+#include "windows.h"
+#endif
+
 /* Trigger suspension of the Janet vm by trying to
  * exit the interpeter loop when convenient. You can optionally
  * use NULL to interrupt the current VM when convenient */

This made the build work for TIC-80 on Windows (at least in a local setup meant to mimick relevant aspects of GitHub's CI).

Is the above sort of change superfluous [1]?

cc: @AlecTroemel


[1] I don't understand why Janet itself (outside of the TIC-80 context) builds fine without it (via an appropriate Native command prompt -- I verified this) and the build fails for TIC-80. Both invoke build_win.bat...so I guess something may be different about TIC-80's setup but I have not succeeded in determining what that is.

pepe commented 11 months ago

Probably not related at all, but I had problems to compile spork on Windows not that long ago because of the versions of VS tooling. 2016 vs 2019.

sogaiu commented 11 months ago

Thanks for sharing your thoughts.

In this case, locally I was using VisualStudio 2022, so as you suggested, perhaps the version is not the issue here.

AlecTroemel commented 11 months ago

looks like bakpakin made sogaiu's suggestions here -> https://github.com/janet-lang/janet/commit/169bd812c9183865b2399a8eaeab6aad238856c5