diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 750d0587..36f8c08a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 diff --git a/test/project/example.gdextension b/test/project/example.gdextension index 99c1746d..d4234613 100644 --- a/test/project/example.gdextension +++ b/test/project/example.gdextension @@ -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" diff --git a/tools/javascript.py b/tools/javascript.py index 1d8009eb..e8f6af1c 100644 --- a/tools/javascript.py +++ b/tools/javascript.py @@ -1,8 +1,9 @@ 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): @@ -10,9 +11,6 @@ def generate(env): 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" @@ -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" @@ -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"])