Skip to content

Commit

Permalink
Merge pull request #164 from nmerget/fix-gd4-rebase-2
Browse files Browse the repository at this point in the history
Refactor JavaScript integration and improve code readability.
  • Loading branch information
fire authored Oct 1, 2023
2 parents ca34e79 + 7160c86 commit 7fecf15
Show file tree
Hide file tree
Showing 22 changed files with 104 additions and 356 deletions.
87 changes: 10 additions & 77 deletions .github/workflows/linux_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,46 +33,11 @@ jobs:
proj-conv: true
artifact: true

- name: Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold)
cache-name: linux-editor-double-sanitizers
target: editor
tests: true
# Debug symbols disabled as they're huge on this build and we hit the 14 GB limit for runners.
sconsflags: dev_build=yes debug_symbols=no precision=double use_asan=yes use_ubsan=yes linker=gold
proj-test: true
# Can be turned off for PRs that intentionally break compat with godot-cpp,
# until both the upstream PR and the matching godot-cpp changes are merged.
godot-cpp-test: true
bin: "./bin/godot.linuxbsd.editor.dev.double.x86_64.san"
build-mono: false
# Skip 2GiB artifact speeding up action.
artifact: false

- name: Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)
cache-name: linux-editor-llvm-sanitizers
target: editor
tests: true
sconsflags: dev_build=yes use_asan=yes use_ubsan=yes use_llvm=yes linker=lld
bin: "./bin/godot.linuxbsd.editor.dev.x86_64.llvm.san"
build-mono: false
# Skip 2GiB artifact speeding up action.
artifact: false

- name: Template w/ Mono (target=template_release)
cache-name: linux-template-mono
target: template_release
tests: false
sconsflags: module_mono_enabled=yes
build-mono: false
artifact: true

- name: Minimal template (target=template_release, everything disabled)
cache-name: linux-template-minimal
target: template_release
tests: false
sconsflags: modules_enabled_by_default=no disable_3d=yes disable_advanced_gui=yes deprecated=no minizip=no
artifact: true

- name: Minimal template (target=template_release, everything disabled)
cache-name: linux-template-minimal
target: template_release
tests: false
sconsflags: modules_enabled_by_default=no disable_3d=yes disable_advanced_gui=yes deprecated=no
steps:
- name: Checkout Godot
uses: actions/checkout@v2
Expand Down Expand Up @@ -185,40 +150,8 @@ jobs:
xvfb-run ${{ matrix.bin }} 40 --audio-driver Dummy --path test_project 2>&1 | tee sanitizers_log.txt || true
misc/scripts/check_ci_log.py sanitizers_log.txt
# Checkout godot-cpp
- name: Checkout godot-cpp
if: ${{ matrix.godot-cpp-test }}
uses: actions/checkout@v3
with:
repository: godotengine/godot-cpp
ref: ${{ env.GODOT_BASE_BRANCH }}
submodules: 'recursive'
path: 'godot-cpp'

# Dump GDExtension interface and API
- name: Dump GDExtension interface and API for godot-cpp build
if: ${{ matrix.godot-cpp-test }}
run: |
${{ matrix.bin }} --headless --dump-gdextension-interface --dump-extension-api
cp -f gdextension_interface.h godot-cpp/gdextension/
cp -f extension_api.json godot-cpp/gdextension/
# Build godot-cpp test extension
- name: Build godot-cpp test extension
if: ${{ matrix.godot-cpp-test }}
run: |
cd godot-cpp/test
scons target=template_debug dev_build=yes
cd ../..
- name: Prepare artifact
if: ${{ matrix.artifact }}
run: |
strip bin/godot.*
chmod +x bin/godot.*
- name: Upload artifact
uses: ./.github/actions/upload-artifact
if: ${{ matrix.artifact }}
with:
name: ${{ matrix.cache-name }}
- name: Upload artifact
uses: ./.github/actions/upload-artifact
if: ${{ matrix.artifact }}
with:
name: ${{ matrix.cache-name }}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ You can try demos in the [ECMAScriptDemos](https://github.com/Geequlim/ECMAScrip
## Developer notes

- This package is not compatible with MSVC, you will get build errors in quickjs.
- To update the github actions scripts we have the file `build_github_actions.py`. This script will copy the actions from the godot repo (usually at `../../`) and modify them to fix the requirements of quickjs and this repo.
\*\* If you are updating this repo's compatibility, you should run that script (a brief description is at the top of the script) and it will re-create the actions `.yml` files for you.
- The script also build the `on_tag.yml` script which automates the github release publishing.
\*\* The `on_tag.yml` functionality tries to sleep until all jobs with the same `sha` are completed. It should be fine to run whenever, but depending on how github actions culls long running jobs you might want to make sure that all/(most of) the builds look good before tagging.
- Linux ubsan asan build woes:
- The godot repo has ubsan and asan builds that we can't build from. Currently we skip them (get removed via the `build_github_actions.py` script).
- They should definitely be fixed & enabled at some point, **so please submit a PR if you have any ideas of how to do that!**
47 changes: 18 additions & 29 deletions SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ env_module = env_modules.Clone()
JS_ENGINE = "quickjs"
TOOLS = "editor" == env_module["target"]

if env["platform"] == "windows":
if env["use_mingw"]:
env.Append(LIBS=["pthread"])


def open_file(path, mode):
if platform.python_version() > "3":
Expand Down Expand Up @@ -41,27 +37,20 @@ if JS_ENGINE == "quickjs":

thirdparty.quickjs.builtin_binding_generator.generate_builtin_bindings()
version = open("thirdparty/quickjs/quickjs/VERSION.txt", "r").read().split("\n")[0]
quickjs_env = env_modules.Clone()
quickjs_env.Append(CPPDEFINES={"QUICKJS_CONFIG_VERSION": '"' + version + '"'})
quickjs_env.Append(CPPDEFINES=["CONFIG_BIGNUM"])
if "release" not in (quickjs_env["target"] or ""):
quickjs_env.Append(CPPDEFINES={"DUMP_LEAKS": 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()
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")

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")
env_module.Append(CPPDEFINES={"QUICKJS_CONFIG_VERSION": '"' + version + '"'})
env_module.Append(CPPDEFINES=["CONFIG_BIGNUM"])
if "release" not in (env_module["target"] or ""):
env_module.Append(CPPDEFINES={"DUMP_LEAKS": 1})
env_module.Append(CPPDEFINES={"QUICKJS_WITH_DEBUGGER": 1})
env_module.Append(CPPPATH=["thirdparty/quickjs/quickjs"])
env_module.Append(CPPPATH=["thirdparty/quickjs"])

if TOOLS:
env_module.add_source_files(env.modules_sources, "tools/editor_tools.cpp")
env_module.add_source_files(env.modules_sources, "thirdparty/quickjs/quickjs_builtin_binder.gen.cpp")
env_module.add_source_files(env.modules_sources, "thirdparty/quickjs/*.cpp")
env_module.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 All @@ -81,19 +70,19 @@ if TOOLS:
'/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "editor_tools.h"\nString JavaScriptPlugin::{} = \n{};'
)
tool_fns = {
"editor/godot.d.ts.gen.cpp": (
"tools/godot.d.ts.gen.cpp": (
"BUILTIN_DECLARATION_TEXT",
dump_text_file_to_cpp("misc/godot.d.ts"),
),
"editor/tsconfig.json.gen.cpp": (
"tools/tsconfig.json.gen.cpp": (
"TSCONFIG_CONTENT",
dump_text_file_to_cpp("misc/tsconfig.json"),
),
"editor/decorators.ts.gen.cpp": (
"tools/decorators.ts.gen.cpp": (
"TS_DECORATORS_CONTENT",
dump_text_file_to_cpp("misc/decorators.ts"),
),
"editor/package.json.gen.cpp": (
"tools/package.json.gen.cpp": (
"PACKAGE_JSON_CONTENT",
dump_text_file_to_cpp("misc/package.json"),
),
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 not platform == "android" and not platform == "mono"
return not (platform == "windows" and not env["use_mingw"])


def configure(env):
Expand Down
2 changes: 1 addition & 1 deletion doc_classes/JavaScript.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="JavaScript" inherits="Script" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<class name="JavaScript" inherits="Script" version="4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A JavaScript script resource for creating and managing JavaScript scripts in Godot.
</brief_description>
Expand Down
2 changes: 1 addition & 1 deletion doc_classes/JavaScriptModule.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="JavaScriptModule" inherits="Resource" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<class name="JavaScriptModule" inherits="Resource" version="4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A JavaScript module resource for managing JavaScript source code and bytecode.
</brief_description>
Expand Down
72 changes: 0 additions & 72 deletions editor/editor_tools.h

This file was deleted.

2 changes: 1 addition & 1 deletion javascript_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "core/object/class_db.h"

#include "javascript_binder.h"
#include "thirdparty/quickjs/quickjs_binder.h"
#include "quickjs_binder.h"

JavaScriptLanguage *JavaScriptLanguage::singleton = nullptr;

Expand Down
2 changes: 1 addition & 1 deletion misc/godot.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ declare module globalThis {
*
* Workers run in another global context that is different from the current context.
*
* You can run whatever code you like inside the worker thread. All of the godot API are available inside workers.
* You can run whatever code you like inside the worker thread. All of the godot API are avaliable inside workers.
*
* Data is sent between workers and the main thread via a system of messages — both sides send their messages using the `postMessage()` method, and respond to messages via the `onmessage` event handler (the message is contained within the Message event's data attribute.) The data is copied rather than shared.
*
Expand Down
1 change: 1 addition & 0 deletions quickjs/quickjs_callable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "../../quickjs_binder.h"
#include "../javascript_language.h"
#include "quickjs/quickjs.h"
#include "../../quickjs_binder.h"

bool QuickJSCallable::compare_equal(const CallableCustom *p_a, const CallableCustom *p_b) {
const QuickJSCallable *a = static_cast<const QuickJSCallable *>(p_a);
Expand Down
6 changes: 3 additions & 3 deletions register_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef REGISTER_TYPES_H
#define REGISTER_TYPES_H
#ifndef JAVASCRIPT_REGISTER_TYPES_H
#define JAVASCRIPT_REGISTER_TYPES_H

#include "modules/register_module_types.h"
void initialize_javascript_module(ModuleInitializationLevel p_level);
void uninitialize_javascript_module(ModuleInitializationLevel p_level);

#endif // REGISTER_TYPES_H
#endif // JAVASCRIPT_REGISTER_TYPES_H
16 changes: 8 additions & 8 deletions tests/UnitTest.js.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test('Object.prototype.connect', () => {

let obj = new godot.Object();
obj.connect('script_changed', (...args)=> {
console.log(`signal 'script_changed' emitted with:`, ...args);
console.log(`signal 'script_changed' emited with:`, ...args);
ok = true;
});
obj.emit_signal('script_changed', 123, 'hello');
Expand All @@ -39,28 +39,28 @@ test('Object.prototype.connect', () => {


// --------------------------- Unit Test Implementation ------------------------
function test(description, block, group = 'default') {
function test(description, blcok, group = 'default') {
const entries = TEST_ENTRIES.get(group) || [];
entries.push({ description, block });
entries.push({ description, blcok });
TEST_ENTRIES.set(group, entries);
}
function runEntry(entry) {
return new Promise((resolve, reject) => {
switch (typeof (entry.block)) {
switch (typeof (entry.blcok)) {
case 'boolean':
return resolve(entry.block);
return resolve(entry.blcok);
case 'function': {
try {
resolve(entry.block());
resolve(entry.blcok());
} catch (error) {
console.error(error);
resolve(false);
}
}
break;
case 'object':
if (entry.block instanceof Promise) {
entry.block.then(() => {
if (entry.blcok instanceof Promise) {
entry.blcok.then(() => {
resolve(true);
}).catch(err => {
resolve(false);
Expand Down
Loading

0 comments on commit 7fecf15

Please sign in to comment.