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

Javascript Web WASM Fix #1247

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
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,18 @@ jobs:
run-tests: false
cache-name: ios-arm64

- name: 🌐 Web (wasm32)
os: ubuntu-20.04
platform: javascript
artifact-name: godot-cpp-javascript-wasm32-release
artifact-path: bin/libgodot-cpp.javascript.template_release.wasm32.a
run-tests: false
cache-name: javascript-wasm32

env:
SCONS_CACHE: ${{ github.workspace }}/.scons-cache/
EM_VERSION: 3.1.45
EM_CACHE_FOLDER: "emsdk-cache"

steps:
- name: Checkout
Expand All @@ -104,6 +114,13 @@ jobs:
sudo apt-get update -qq
sudo apt-get install -qqq build-essential pkg-config

- name: Web dependencies
if: ${{ matrix.platform == 'javascript' }}
uses: mymindstorm/setup-emsdk@v12
with:
version: ${{env.EM_VERSION}}
actions-cache-folder: ${{env.EM_CACHE_FOLDER}}

- name: Install scons
run: |
python -m pip install scons==4.0.0
Expand Down
2 changes: 2 additions & 0 deletions test/project/example.gdextension
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ android.debug.x86_64 = "res://bin/libgdexample.android.template_debug.x86_64.so"
android.release.x86_64 = "res://bin/libgdexample.android.template_release.x86_64.so"
android.debug.arm64 = "res://bin/libgdexample.android.template_debug.arm64.so"
android.release.arm64 = "res://bin/libgdexample.android.template_release.arm64.so"
web.debug.wasm32 = "res://bin/libgdexample.javascript.template_debug.wasm32.wasm"
web.release.wasm32 = "res://bin/libgdexample.javascript.template_release.wasm32.wasm"
15 changes: 6 additions & 9 deletions tools/javascript.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
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.")
env.Exit(1)

if "EM_CONFIG" in os.environ:
env["ENV"] = os.environ

env["CC"] = "emcc"
env["CXX"] = "em++"
env["AR"] = "emar"
Expand All @@ -26,6 +24,10 @@ 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(CCFLAGS=["-s", "USE_PTHREADS=1"])
env.Append(LINKFLAGS=["-s", "USE_PTHREADS=1"])

# All intermediate files are just LLVM bitcode.
env["OBJPREFIX"] = ""
env["OBJSUFFIX"] = ".bc"
Expand All @@ -39,9 +41,4 @@ def generate(env):
env.Replace(SHLINKFLAGS="$LINKFLAGS")
env.Replace(SHLINKFLAGS="$LINKFLAGS")

if env["target"] == "debug":
env.Append(CCFLAGS=["-O0", "-g"])
elif env["target"] == "release":
env.Append(CCFLAGS=["-O3"])

env.Append(CPPDEFINES=["WEB_ENABLED", "UNIX_ENABLED"])