diff --git a/.github/actions/compile_gdextension/action.yml b/.github/actions/compile_gdextension/action.yml index 096bcebe..9e9b5aa5 100644 --- a/.github/actions/compile_gdextension/action.yml +++ b/.github/actions/compile_gdextension/action.yml @@ -80,7 +80,7 @@ runs: echo "::endgroup::" - name: Prepare artifact Unix - if: runner.os != 'Windows' && inputs.platform != 'android' + if: runner.os != 'Windows' && inputs.platform != 'android' && inputs.platform != 'javascript' shell: bash run: | if [ "$RUNNER_OS" == "macOS" ]; then diff --git a/.github/workflows/gdextension_build.yml b/.github/workflows/gdextension_build.yml index 01dbe46d..2146c799 100644 --- a/.github/workflows/gdextension_build.yml +++ b/.github/workflows/gdextension_build.yml @@ -143,6 +143,48 @@ jobs: # ============================================ + web-gdextension: + name: 🕸 Web + runs-on: "ubuntu-latest" + + strategy: + fail-fast: false + matrix: + arch: [wasm32] + target: [template_debug, template_release] + + env: + EM_VERSION: 3.1.46 + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + lfs: true + submodules: recursive + + - uses: mymindstorm/setup-emsdk@v11 + with: + version: ${{env.EM_VERSION}} + + - shell: bash + run: | + cd godot-cpp + git apply --ignore-space-change --ignore-whitespace ../patches/fixed_javascript_build.patch + cd .. + + - name: Compile GDExtension + uses: ./.github/actions/compile_gdextension + with: + platform: javascript + target: ${{matrix.target}} + arch: ${{matrix.arch}} + output_libs_path: ${{env.OUTPUT_LIBS_PATH}} + artifact: javascript + additional: lto=yes + + # ============================================ + collect-gdextension: needs: [ @@ -150,6 +192,7 @@ jobs: linux-gdextension, macos-gdextension, android-gdextension, + web-gdextension, ] name: 📦 Collect GDExtension binaries runs-on: ubuntu-latest diff --git a/addons/debug_draw_3d/debug_draw_3d.gdextension b/addons/debug_draw_3d/debug_draw_3d.gdextension index c914b155..2ec73f63 100644 --- a/addons/debug_draw_3d/debug_draw_3d.gdextension +++ b/addons/debug_draw_3d/debug_draw_3d.gdextension @@ -11,6 +11,8 @@ macos = { } windows.x86_64 = { } linux.x86_64 = { } +web.wasm32 = {} + android.arm32 = { } android.arm64 = { } android.x86_32 = { } @@ -20,17 +22,32 @@ macos.template_release = { } windows.template_release.x86_64 = { } linux.template_release.x86_64 = { } +web.template_release.wasm32 = {} + android.template_release.arm32 = { } android.template_release.arm64 = { } android.template_release.x86_32 = { } android.template_release.x86_64 = { } +macos.template_release.forced_dd3d = { } +windows.template_release.x86_64.forced_dd3d = { } +linux.template_release.x86_64.forced_dd3d = { } + +web.template_release.wasm32.forced_dd3d = {} + +android.template_release.arm32.forced_dd3d = { } +android.template_release.arm64.forced_dd3d = { } +android.template_release.x86_32.forced_dd3d = { } +android.template_release.x86_64.forced_dd3d = { } + [libraries] macos = "libs/libdd3d.macos.editor.universal.dylib" windows.x86_64 = "libs/libdd3d.windows.editor.x86_64.dll" linux.x86_64 = "libs/libdd3d.linux.editor.x86_64.so" +web.wasm32 = "libs/libdd3d.javascript.template_debug.wasm32.wasm" + android.arm32 = "libs/libdd3d.android.template_debug.arm32.so" android.arm64 = "libs/libdd3d.android.template_debug.arm64.so" android.x86_32 = "libs/libdd3d.android.template_debug.x86_32.so" @@ -40,6 +57,8 @@ macos.template_release = "libs/libdd3d.macos.template_release.universal.dylib" windows.template_release.x86_64 = "libs/libdd3d.windows.template_release.x86_64.dll" linux.template_release.x86_64 = "libs/libdd3d.linux.template_release.x86_64.so" +web.template_release.wasm32 = "libs/libdd3d.javascript.template_release.wasm32.wasm" + android.template_release.arm32 = "libs/libdd3d.android.template_release.arm32.so" android.template_release.arm64 = "libs/libdd3d.android.template_release.arm64.so" android.template_release.x86_32 = "libs/libdd3d.android.template_release.x86_32.so" @@ -49,6 +68,8 @@ macos.template_release.forced_dd3d = "libs/libdd3d.macos.template_release.univer windows.template_release.x86_64.forced_dd3d = "libs/libdd3d.windows.template_release.x86_64.enabled.dll" linux.template_release.x86_64.forced_dd3d = "libs/libdd3d.linux.template_release.x86_64.enabled.so" +web.template_release.wasm32.forced_dd3d = "libs/libdd3d.javascript.template_release.wasm32.enabled.wasm" + android.template_release.arm32.forced_dd3d = "libs/libdd3d.android.template_release.arm32.enabled.so" android.template_release.arm64.forced_dd3d = "libs/libdd3d.android.template_release.arm64.enabled.so" android.template_release.x86_32.forced_dd3d = "libs/libdd3d.android.template_release.x86_32.enabled.so" diff --git a/addons/debug_draw_3d/libs/libdd3d.javascript.template_debug.wasm32.wasm b/addons/debug_draw_3d/libs/libdd3d.javascript.template_debug.wasm32.wasm new file mode 100644 index 00000000..40f32b81 Binary files /dev/null and b/addons/debug_draw_3d/libs/libdd3d.javascript.template_debug.wasm32.wasm differ diff --git a/addons/debug_draw_3d/libs/libdd3d.javascript.template_release.wasm32.enabled.wasm b/addons/debug_draw_3d/libs/libdd3d.javascript.template_release.wasm32.enabled.wasm new file mode 100644 index 00000000..80ec417c Binary files /dev/null and b/addons/debug_draw_3d/libs/libdd3d.javascript.template_release.wasm32.enabled.wasm differ diff --git a/addons/debug_draw_3d/libs/libdd3d.javascript.template_release.wasm32.wasm b/addons/debug_draw_3d/libs/libdd3d.javascript.template_release.wasm32.wasm new file mode 100644 index 00000000..bdae0bc0 Binary files /dev/null and b/addons/debug_draw_3d/libs/libdd3d.javascript.template_release.wasm32.wasm differ diff --git a/patches/fixed_javascript_build.patch b/patches/fixed_javascript_build.patch new file mode 100644 index 00000000..4287d729 --- /dev/null +++ b/patches/fixed_javascript_build.patch @@ -0,0 +1,51 @@ +diff --git a/tools/javascript.py b/tools/javascript.py +index 42c601d..8fcb921 100644 +--- a/tools/javascript.py ++++ b/tools/javascript.py +@@ -1,18 +1,14 @@ + import os +- ++from SCons.Util import WhereIs + + def exists(env): +- return "EM_CONFIG" in os.environ +- ++ return WhereIs("emcc") is not None + + def generate(env): + if env["arch"] not in ("wasm32"): + print("Only wasm32 supported on web. Exiting.") + Exit() + +- if "EM_CONFIG" in os.environ: +- env["ENV"] = os.environ +- + env["CC"] = "emcc" + env["CXX"] = "em++" + env["AR"] = "emar" +@@ -26,6 +22,13 @@ def generate(env): + env["ARCOM_POSIX"] = env["ARCOM"].replace("$TARGET", "$TARGET.posix").replace("$SOURCES", "$SOURCES.posix") + env["ARCOM"] = "${TEMPFILE(ARCOM_POSIX)}" + ++ # Thread support (via SharedArrayBuffer). ++ env.Append(CPPDEFINES=["PTHREAD_NO_RENAME"]) ++ env.Append(CCFLAGS=["-s", "USE_PTHREADS=1"]) ++ env.Append(LINKFLAGS=["-s", "USE_PTHREADS=1"]) ++ env.Append(LINKFLAGS=["-s", "PTHREAD_POOL_SIZE=8"]) ++ env.Append(LINKFLAGS=["-s", "WASM_MEM_MAX=2048MB"]) ++ + # All intermediate files are just LLVM bitcode. + env["OBJPREFIX"] = "" + env["OBJSUFFIX"] = ".bc" +@@ -39,9 +42,9 @@ def generate(env): + env.Replace(SHLINKFLAGS="$LINKFLAGS") + env.Replace(SHLINKFLAGS="$LINKFLAGS") + +- if env["target"] == "debug": ++ if env["target"] in ["editor", "template_debug"]: + env.Append(CCFLAGS=["-O0", "-g"]) +- elif env["target"] == "release": ++ elif env["target"] == "template_release": + env.Append(CCFLAGS=["-O3"]) + + env.Append(CPPDEFINES=["WEB_ENABLED", "UNIX_ENABLED"])