Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
ialex32x committed Sep 14, 2024
2 parents 7541bf5 + f1174e1 commit eb896d8
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 43 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ git clone https://github.com/ialex32x/GodotJS.git

```sh
# download the archive of prebuilt v8
curl https://github.com/ialex32x/GodotJS-Dependencies/releases/download/v8_r6/v8_r6.zip --output your/download/path/v8.zip
curl https://github.com/ialex32x/GodotJS-Dependencies/releases/download/v8_r11/v8_r11.zip --output your/download/path/v8.zip

# extract the zip file into your `GodotJS` directory,
# NOTE: no white space after the switch `-o`
Expand All @@ -56,7 +56,8 @@ The module directroy structure looks like this:
┃ ┣━ include
┃ ┣━ linux.x86_64.release
┃ ┣━ macos.arm64.release
┃ ┗━ windows.x86_64.release
┃ ┣━ windows_x86_64_release
┃ ┗━ ...
┣━ gridmap
┣━ ...
```
Expand All @@ -66,7 +67,7 @@ The currently used version of `v8` is `12.4.254.20`.
**STEP 3:** Compile and launch `Godot Editor`. Then, [install TypeScript/JavaScript presets](./docs/install_ts_presets.md) into a Godot project.

> [!NOTE]
> Since the prebuilt `v8` library is built with the `windows-latest` github runner which uses VS2022, encountering `Unresolved external symbol` errors during linkage with `v8_monolith.lib` or `libucrt.lib` may be addressed by updating to the latest version of the `MSVC v143` toolchain, `Windows Universal CRT SDK` and `Visual Studio 2022` itself.
> Since the prebuilt `v8` library is built with the `windows-latest` github runner which uses VS2022, encountering `Unresolved external symbol` errors during linkage with `v8_monolith.lib` or `libucrt.lib` may be addressed by updating to the latest version of the `MSVC v143` toolchain, `Windows Universal CRT SDK` and `Visual Studio 2022` itself. See [GodotJS-Dependencies README](https://github.com/ialex32x/GodotJS-Dependencies) for the version of MSVC C++ Compiler used in different prebuilt library packages.
A prebuilt version of `Godot Editor` can be downloaded from [GodotJS-Build](https://github.com/ialex32x/GodotJS-Build/releases).
**Because the GodotJS-Build workflow is currently run manually, it may not be built from the latest commit of `GodotJS`.**
Expand Down Expand Up @@ -108,9 +109,9 @@ For more information on how to use `GodotJS` in a project, check out [GodotJSExa
- [x] Windows: x86_64
- [ ] Windows: arm64, UWP
- [x] MacOS: arm64
- [ ] MacOS: x86_64
- [x] MacOS: x86_64 (not tested)
- [x] Linux: x86_64
- [ ] Linux: arm64
- [ ] Android
- [ ] iOS
- [x] Android: arm32, arm64, x86_64 (`ndk_platform=android-24`)
- [x] iOS: arm64, x86_64 (not tested)
- [ ] WebAssembly (quickjs only)
74 changes: 47 additions & 27 deletions SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@ def check(condition, text):
print("Error: " + text)
Exit(2)

jsb_platform = "linux" if env["platform"] == "linuxbsd" else env["platform"]
jsb_arch = env["arch"]
prebuilt_deps_url = "https://github.com/ialex32x/GodotJS-Dependencies/releases/download/v8_r11/v8_r11.zip"
module_path = os.path.dirname(os.path.abspath("jsb.h"))
module_name = os.path.basename(module_path)
javascript_engine = "v8" if env["platform"] != "web" else "quickjs"
websocket_lib = "lws" if env["platform"] != "web" else "none"
javascript_engine = "v8" if jsb_platform in ["windows", "linux", "macos", "android", "ios"] else "quickjs"
websocket_lib = "lws" if jsb_platform in ["windows", "linux", "macos"] else "none"

print("compiling:", module_name)
print("javascript engine:", javascript_engine)
print("websocket lib:", websocket_lib)
print("platform:", jsb_platform)
print("arch:", jsb_arch)

if jsb_platform == "android":
print("ndk_platform:", env["ndk_platform"])
print("ANDROID_NDK_ROOT:", env["ANDROID_NDK_ROOT"])

class CompileDefines:
def __init__(self, name, value, help = None):
Expand Down Expand Up @@ -214,24 +223,33 @@ if javascript_engine == "v8":
# it seems v8_monolith must be compiled with `use_rtti=true` explicitly, or the linker will fail on `v8::ArrayBuffer::Allocator`

# check existence of v8 (since it's setup manually)
v8_missing_msg = "The v8 engine is not found in GodotJS, please build it initially or download the prebuilt v8 library from https://github.com/ialex32x/GodotJS-Dependencies/releases/download/v8_r6/v8_r6.zip"
v8_missing_msg = f"The v8 engine is not found in GodotJS, please build it initially or download the prebuilt v8 library from {prebuilt_deps_url}"
v8_basename = f"{jsb_platform}.{jsb_arch}.release"
check(os.path.exists("v8/include/v8.h"), v8_missing_msg)

if env["platform"] == "macos":
check(os.path.exists("v8/macos.arm64.release/libv8_monolith.a"), v8_missing_msg)
env.Append(LIBPATH=[f'#modules/{module_name}/v8/macos.arm64.release'])
if jsb_platform == "macos":
check(os.path.exists(f"v8/{v8_basename}/libv8_monolith.a"), v8_missing_msg)
env.Append(LIBPATH=[f'#modules/{module_name}/v8/{v8_basename}'])
env.Append(LINKFLAGS=["-lv8_monolith"])
elif env["platform"] == "linuxbsd":
check(os.path.exists("v8/linux.x86_64.release/libv8_monolith.a"), v8_missing_msg)
env.Append(LIBS=[File('v8/linux.x86_64.release/libv8_monolith.a')])
else:
v8_lib_path = update_path_for_4_3("v8/windows.x86_64.release")
elif jsb_platform == "linux":
check(os.path.exists(f"v8/{v8_basename}/libv8_monolith.a"), v8_missing_msg)
env.Append(LIBS=[File(f"v8/{v8_basename}/libv8_monolith.a")])
elif jsb_platform == "windows":
v8_lib_path = update_path_for_4_3(f"v8/{v8_basename}")
check(os.path.exists(v8_lib_path+"/v8_monolith.lib"), v8_missing_msg)
env.Append(LIBS=[File(v8_lib_path+"/v8_monolith.lib")])
env.Append(LINKFLAGS=["winmm.lib", "Dbghelp.lib"])
elif jsb_platform == "android":
check(os.path.exists(f"v8/{v8_basename}/libv8_monolith.a"), v8_missing_msg)
env.Append(LIBS=[File(f"v8/{v8_basename}/libv8_monolith.a")])
elif jsb_platform == "ios":
check(os.path.exists(f"v8/{v8_basename}/libv8_monolith.a"), v8_missing_msg)
env.Append(LIBS=[File(f"v8/{v8_basename}/libv8_monolith.a")])
else:
check(False, f'v8 is not supported on {env["platform"]}')

# platform-specific defines
if env["platform"] != "ios":
if jsb_platform not in ["ios", "android"]:
env_jsb.AppendUnique(CPPDEFINES=["V8_COMPRESS_POINTERS"])
pass

Expand All @@ -253,23 +271,25 @@ env_jsb.add_source_files(module_obj, "bridge-v8/*.cpp")
# lws
if websocket_lib == "lws":
lws_missing_msg = "The prebuilt lws lib is missing? Please build it at first."
if env["platform"] == "macos":
check(os.path.exists("lws/macos_arm64_release/libwebsockets.a"), lws_missing_msg)
env_jsb.Append(CPPPATH=["lws/macos_arm64_release/include"])
env.Append(LIBPATH=[f'#modules/{module_name}/lws/macos_arm64_release'])
lws_basename = f"{jsb_platform}_{jsb_arch}_release"

if jsb_platform == "macos":
check(os.path.exists(f"lws/{lws_basename}/libwebsockets.a"), lws_missing_msg)
env_jsb.Append(CPPPATH=[f"lws/{lws_basename}/include"])
env.Append(LIBPATH=[f'#modules/{module_name}/lws/{lws_basename}'])
env.Append(LINKFLAGS=["-lwebsockets"])
elif env["platform"] == "linuxbsd":
check(os.path.exists("lws/linux_x86_64_release/libwebsockets.a"), lws_missing_msg)
env_jsb.Append(CPPPATH=["lws/linux_x86_64_release/include"])
env.Append(LIBS=[File('lws/linux_x86_64_release/libwebsockets.a')])
elif env["platform"] == "windows":
check(os.path.exists("lws/windows_x86_64_release/websockets.lib"), lws_missing_msg)
elif jsb_platform == "linux":
check(os.path.exists(f"lws/{lws_basename}/libwebsockets.a"), lws_missing_msg)
env_jsb.Append(CPPPATH=[f"lws/{lws_basename}/include"])
env.Append(LIBS=[File(f"lws/{lws_basename}/libwebsockets.a")])
elif jsb_platform == "windows":
check(os.path.exists(f"lws/{lws_basename}/websockets.lib"), lws_missing_msg)
if env.msvc and env["vsproj"]:
env.Append(CPPPATH=[f"#modules/{module_name}/lws/windows_x86_64_release/include"])
env_jsb.Append(CPPPATH=["lws/windows_x86_64_release/include"])

env.Append(LIBS=[File("lws/windows_x86_64_release/websockets.lib")])
#TODO lws builds on other platforms
env.Append(CPPPATH=[f"#modules/{module_name}/lws/{lws_basename}/include"])
env_jsb.Append(CPPPATH=[f"lws/{lws_basename}/include"])
env.Append(LIBS=[File(f"lws/{lws_basename}/websockets.lib")])
else:
check(False, f'lws is not supported on {env["platform"]}')

generate_code({
# presets for runtime
Expand Down
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Core:
✔ directly use typescripts in `godot editor`, hide compiled results (.js files) @done(24-07-08)
✔ global scope defined constants (such as PropertyHint) @done
☐ source-map: incorrect Ln:Col on bundle scripts
☐ core: possible to call virtual methods even if not defined by scripts
✔ embed jsb sources in C++ @done(24-08-15 23:16)
✔ exception is swallowed if thrown in GodotJS ScriptInstance::callp method @started(24-04-30 17:52) @done(24-07-05 21:42)
✔ SArray: return a simple wrapper with address guarded scope instead of a barebone reference? (`Env::get_object_class` etc.) @done(24-08-15)
Expand Down
5 changes: 2 additions & 3 deletions bridge-v8/jsb_module_resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ namespace jsb

// update `exports`, because its value may be covered during the execution process of the elevator script.
const v8::Local<v8::Value> updated_exports = module_obj->Get(context, jsb_name(environment, exports)).ToLocalChecked();
#if JSB_DEBUG
if (updated_exports != argv[kIndexExports]) { JSB_LOG(Log, "`exports` is overwritten in module"); }
#endif
jsb_notice(updated_exports != argv[kIndexExports], "`exports` is overwritten in module: %s", filename);

p_module.exports.Reset(isolate, updated_exports);
return true;
}
Expand Down
1 change: 1 addition & 0 deletions bridge-v8/jsb_pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <memory>
#include <cstdint>
#include <unordered_map>

#include "core/core_constants.h"
#include "core/string/string_builder.h"
Expand Down
4 changes: 2 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
def can_build(env, platform):
# temp
# return platform == "windows"
return platform in ["windows", "macos", "linuxbsd"] # currently supported platforms
# return True
# return platform in ["windows", "macos", "linuxbsd", "android", "ios"] # currently supported platforms
return True

def configure(env):
pass
Expand Down
1 change: 1 addition & 0 deletions internal/jsb_internal_pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define GODOTJS_INTERNAL_PCH_H

#include <memory>
#include <vector>

#include "core/object/object.h"
#include "core/variant/variant_utility.h"
Expand Down
2 changes: 1 addition & 1 deletion internal/jsb_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#endif

#if JSB_DEBUG
# define jsb_notice(Condition, Format, ...) if (!!(Condition)) { JSB_LOG_IMPL(jsb, Warning, Format, ##__VA_ARGS__); } (void) 0
# define jsb_notice(Condition, Format, ...) if (!!(Condition)) { JSB_LOG_IMPL(jsb, Log, Format, ##__VA_ARGS__); } (void) 0
#else
# define jsb_notice(Condition, Format, ...) (void) 0
#endif
Expand Down
1 change: 0 additions & 1 deletion internal/jsb_timer_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define GODOTJS_TIMER_MANAGER_H

#include "jsb_internal_pch.h"
#include <vector>

namespace jsb::internal
{
Expand Down
2 changes: 1 addition & 1 deletion jsb.config.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@
#define JSB_TYPESCRIPT_EXT "ts"
#define JSB_JAVASCRIPT_EXT "js"

#define JSB_BUNDLE_VERSION 1
#define JSB_BUNDLE_VERSION 2

#endif
4 changes: 4 additions & 0 deletions jsb_project_preset.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ struct GodotJSProjectPreset
static const char* get_source(const String& p_filename, size_t& r_len)
{
if (const char* res = get_source_rt(p_filename, r_len)) return res;
#ifdef TOOLS_ENABLED
return get_source_ed(p_filename, r_len);
#else
return nullptr;
#endif
}

static const char* get_source_rt(const String& p_filename, size_t& r_len);
Expand Down
2 changes: 1 addition & 1 deletion scripts/presets/tsconfig.json.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

/* Modules */
"module": "__MODULE__", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
"rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
Expand Down

0 comments on commit eb896d8

Please sign in to comment.