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

Add Web/WASM Support #23

Merged
Merged
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
2 changes: 1 addition & 1 deletion .github/actions/compile_gdextension/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/gdextension_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,56 @@ 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:
[
windows-gdextension,
linux-gdextension,
macos-gdextension,
android-gdextension,
web-gdextension,
]
name: 📦 Collect GDExtension binaries
runs-on: ubuntu-latest
Expand Down
21 changes: 21 additions & 0 deletions addons/debug_draw_3d/debug_draw_3d.gdextension
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ macos = { }
windows.x86_64 = { }
linux.x86_64 = { }

web.wasm32 = {}

android.arm32 = { }
android.arm64 = { }
android.x86_32 = { }
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
51 changes: 51 additions & 0 deletions patches/fixed_javascript_build.patch
Original file line number Diff line number Diff line change
@@ -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"])