Skip to content

Commit 8d86711

Browse files
firejaune
andcommitted
Support MSVC builds without error in Github Actions.
Co-Authored-By: jaune <[email protected]>
1 parent 71c6704 commit 8d86711

File tree

9 files changed

+161
-47
lines changed

9 files changed

+161
-47
lines changed

SCsub

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,24 @@ if JS_ENGINE == "quickjs":
4646
quickjs_env.Append(CPPDEFINES=["CONFIG_BIGNUM"])
4747
if "release" not in (quickjs_env["target"] or ""):
4848
quickjs_env.Append(CPPDEFINES={"DUMP_LEAKS": 1})
49-
quickjs_env.Append(CPPDEFINES={"QUICKJS_WITH_DEBUGGER": 1})
49+
if not env.msvc:
50+
env_module.Append(CPPDEFINES={"QUICKJS_WITH_DEBUGGER": 1})
5051
quickjs_env.Append(CPPPATH=["thirdparty/quickjs/quickjs"])
5152
quickjs_env.Append(CPPPATH=["thirdparty/quickjs"])
5253
quickjs_env.disable_warnings()
5354
if TOOLS:
5455
quickjs_env.add_source_files(env.modules_sources, "tools/editor_tools.cpp")
5556
quickjs_env.add_source_files(env.modules_sources, "thirdparty/quickjs/quickjs_builtin_binder.gen.cpp")
5657
quickjs_env.add_source_files(env.modules_sources, "thirdparty/quickjs/*.cpp")
57-
quickjs_env.add_source_files(env.modules_sources, "thirdparty/quickjs/quickjs/*.c")
5858

59+
env_thirdparty = quickjs_env.Clone()
60+
if env.msvc:
61+
env_thirdparty.AppendUnique(CCFLAGS=["/TC"])
62+
63+
# TODO: find a better way to remove /std:c++17
64+
del env_thirdparty["CCFLAGS"][0]
65+
env_thirdparty.Prepend(CCFLAGS=["/std:c11"])
66+
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/quickjs/quickjs/*.c")
5967

6068
# Binding script to run at engine initializing
6169
with open("misc/godot.binding_script.gen.cpp", "w") as f:

config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
def can_build(env, platform):
2-
return not (platform == "windows" and not env["use_mingw"])
3-
2+
return True
3+
44

55
def configure(env):
66
pass

register_types.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class EditorExportJavaScript : public EditorExportPlugin {
5252
return;
5353
}
5454
}
55-
virtual String get_name() const override { return "JavaScript"; }
55+
virtual String _get_name() const override { return "JavaScript"; }
5656
};
5757

5858
#endif

thirdparty/quickjs/quickjs/cutils.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,53 @@ static inline int64_t min_int64(int64_t a, int64_t b)
119119
return b;
120120
}
121121

122+
123+
124+
#ifdef _MSC_VER
125+
#include <intrin.h>
126+
127+
static inline int __builtin_ctz(unsigned x)
128+
{
129+
return (int)_tzcnt_u32(x);
130+
}
131+
132+
static inline int __builtin_ctzll(unsigned long long x)
133+
{
134+
#ifdef _WIN64
135+
return (int)_tzcnt_u64(x);
136+
#else
137+
return !!unsigned(x) ? __builtin_ctz((unsigned)x) : 32 + __builtin_ctz((unsigned)(x >> 32));
138+
#endif
139+
}
140+
141+
static inline int __builtin_ctzl(unsigned long x)
142+
{
143+
return sizeof(x) == 8 ? __builtin_ctzll(x) : __builtin_ctz((unsigned)x);
144+
}
145+
146+
static inline int __builtin_clz(unsigned x)
147+
{
148+
return (int)_lzcnt_u32(x);
149+
}
150+
151+
static inline int __builtin_clzll(unsigned long long x)
152+
{
153+
#ifdef _WIN64
154+
return (int)_lzcnt_u64(x);
155+
#else
156+
return !!unsigned(x >> 32) ? __builtin_clz((unsigned)(x >> 32)) : 32 + __builtin_clz((unsigned)x);
157+
#endif
158+
}
159+
160+
static inline int __builtin_clzl(unsigned long x)
161+
{
162+
return sizeof(x) == 8 ? __builtin_clzll(x) : __builtin_clz((unsigned)x);
163+
}
164+
#endif
165+
166+
167+
168+
122169
/* WARNING: undefined if a = 0 */
123170
static inline int clz32(unsigned int a)
124171
{

thirdparty/quickjs/quickjs/quickjs-debugger.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ static int js_transport_write_fully(JSDebuggerInfo *info, const char *buffer, si
3636
return 1;
3737
}
3838

39+
#define JS_TRANSPORT_WRITE_MESSAGE_NEWLINE_MESSAGE_LENGTH 10
40+
3941
static int js_transport_write_message_newline(JSDebuggerInfo *info, const char* value, size_t len) {
4042
// length prefix is 8 hex followed by newline = 012345678\n
4143
// not efficient, but protocol is then human readable.
42-
char message_length[10];
44+
char message_length[JS_TRANSPORT_WRITE_MESSAGE_NEWLINE_MESSAGE_LENGTH];
4345
message_length[9] = '\0';
44-
sprintf(message_length, "%08x\n", (int)len + 1);
46+
sprintf_s(message_length, JS_TRANSPORT_WRITE_MESSAGE_NEWLINE_MESSAGE_LENGTH, "%08x\n", (int)len + 1);
4547
if (!js_transport_write_fully(info, message_length, 9))
4648
return 0;
4749
int ret = js_transport_write_fully(info, value, len);

0 commit comments

Comments
 (0)