Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Support MSVC #161

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,24 @@ if JS_ENGINE == "quickjs":
quickjs_env.Append(CPPDEFINES=["CONFIG_BIGNUM"])
if "release" not in (quickjs_env["target"] or ""):
quickjs_env.Append(CPPDEFINES={"DUMP_LEAKS": 1})
quickjs_env.Append(CPPDEFINES={"QUICKJS_WITH_DEBUGGER": 1})
if not env.msvc:
env_module.Append(CPPDEFINES={"QUICKJS_WITH_DEBUGGER": 1})
quickjs_env.Append(CPPPATH=["thirdparty/quickjs/quickjs"])
quickjs_env.Append(CPPPATH=["thirdparty/quickjs"])
quickjs_env.disable_warnings()
if TOOLS:
quickjs_env.add_source_files(env.modules_sources, "tools/editor_tools.cpp")
quickjs_env.add_source_files(env.modules_sources, "thirdparty/quickjs/quickjs_builtin_binder.gen.cpp")
quickjs_env.add_source_files(env.modules_sources, "thirdparty/quickjs/*.cpp")
quickjs_env.add_source_files(env.modules_sources, "thirdparty/quickjs/quickjs/*.c")

env_thirdparty = quickjs_env.Clone()
if env.msvc:
env_thirdparty.AppendUnique(CCFLAGS=["/TC"])

# TODO: find a better way to remove /std:c++17
del env_thirdparty["CCFLAGS"][0]
env_thirdparty.Prepend(CCFLAGS=["/std:c11"])
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/quickjs/quickjs/*.c")

# Binding script to run at engine initializing
with open("misc/godot.binding_script.gen.cpp", "w") as f:
Expand Down
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def can_build(env, platform):
return (platform == "windows" and env["use_mingw"]) or platform == "linux" or platform == "macos"
return True #(platform == "windows" and env["use_mingw"]) or platform == "linux" or platform == "macos"


def configure(env):
Expand Down
2 changes: 1 addition & 1 deletion register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class EditorExportJavaScript : public EditorExportPlugin {
return;
}
}
virtual String get_name() const override { return "JavaScript"; }
virtual String _get_name() const override { return "JavaScript"; }
};

#endif
Expand Down
47 changes: 47 additions & 0 deletions thirdparty/quickjs/quickjs/cutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,53 @@ static inline int64_t min_int64(int64_t a, int64_t b)
return b;
}



#ifdef _MSC_VER
#include <intrin.h>

static inline int __builtin_ctz(unsigned x)
{
return (int)_tzcnt_u32(x);
}

static inline int __builtin_ctzll(unsigned long long x)
{
#ifdef _WIN64
return (int)_tzcnt_u64(x);
#else
return !!unsigned(x) ? __builtin_ctz((unsigned)x) : 32 + __builtin_ctz((unsigned)(x >> 32));
#endif
}

static inline int __builtin_ctzl(unsigned long x)
{
return sizeof(x) == 8 ? __builtin_ctzll(x) : __builtin_ctz((unsigned)x);
}

static inline int __builtin_clz(unsigned x)
{
return (int)_lzcnt_u32(x);
}

static inline int __builtin_clzll(unsigned long long x)
{
#ifdef _WIN64
return (int)_lzcnt_u64(x);
#else
return !!unsigned(x >> 32) ? __builtin_clz((unsigned)(x >> 32)) : 32 + __builtin_clz((unsigned)x);
#endif
}

static inline int __builtin_clzl(unsigned long x)
{
return sizeof(x) == 8 ? __builtin_clzll(x) : __builtin_clz((unsigned)x);
}
#endif




/* WARNING: undefined if a = 0 */
static inline int clz32(unsigned int a)
{
Expand Down
6 changes: 4 additions & 2 deletions thirdparty/quickjs/quickjs/quickjs-debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ static int js_transport_write_fully(JSDebuggerInfo *info, const char *buffer, si
return 1;
}

#define JS_TRANSPORT_WRITE_MESSAGE_NEWLINE_MESSAGE_LENGTH 10

static int js_transport_write_message_newline(JSDebuggerInfo *info, const char* value, size_t len) {
// length prefix is 8 hex followed by newline = 012345678\n
// not efficient, but protocol is then human readable.
char message_length[10];
char message_length[JS_TRANSPORT_WRITE_MESSAGE_NEWLINE_MESSAGE_LENGTH];
message_length[9] = '\0';
sprintf(message_length, "%08x\n", (int)len + 1);
sprintf_s(message_length, JS_TRANSPORT_WRITE_MESSAGE_NEWLINE_MESSAGE_LENGTH, "%08x\n", (int)len + 1);
if (!js_transport_write_fully(info, message_length, 9))
return 0;
int ret = js_transport_write_fully(info, value, len);
Expand Down
Loading
Loading