Skip to content

Commit

Permalink
Static Wasm C API flag, simpler DLL patch
Browse files Browse the repository at this point in the history
Black format utils.py
  • Loading branch information
ashtonmeuser committed Sep 10, 2023
1 parent 2833445 commit 4d961df
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/actions/godot-cpp/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ runs:
shell: bash
run: |
cd godot-cpp
scons platform=${{ inputs.platform }} target=${{ inputs.target }} generate_bindings=yes ${{ inputs.scons-flags }}
scons platform=${{ inputs.platform }} target=${{ inputs.target }} ${{ inputs.scons-flags }}
4 changes: 2 additions & 2 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ if env["platform"] == "windows":
else: # MSVC
env["LIBRUNTIMESUFFIX"] = ".lib"
# Force Windows SDK library suffix (see https://github.com/godotengine/godot/issues/23687)
env.Append(LINKFLAGS=["bcrypt.lib", "userenv.lib", "ws2_32.lib", "advapi32.lib"])
env.Append(LINKFLAGS=["bcrypt.lib", "userenv.lib", "ws2_32.lib", "advapi32.lib", "ntdll.lib"])

# Defines for GDExtension specific API
env.Append(CPPDEFINES=["GDEXTENSION"])
env.Append(CPPDEFINES=["GDEXTENSION", "LIBWASM_STATIC"])

# Explicit static libraries
runtime_lib = env.File(
Expand Down
2 changes: 1 addition & 1 deletion SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ env.Append(LIBS=[runtime_lib])
module_env.Append(CPPPATH=[env.Dir("{}/include".format(module_env["wasm_runtime"])).abspath])

# Defines for module agnosticism
module_env.Append(CPPDEFINES=["GODOT_MODULE"])
module_env.Append(CPPDEFINES=["GODOT_MODULE", "LIBWASM_STATIC"])

# Module sources
module_env.add_source_files(
Expand Down
29 changes: 17 additions & 12 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ def _validate_version(v):
def _strip_tar_members(f, s=""):
"""Optionally strip tarfile top level directory"""
for member in f.getmembers():
if re.fullmatch(s, member.path): continue # Top level dir
elif re.match(s + r"\/", member.path): # Nested file
member.path = member.path.split('/', 1)[1]
if re.fullmatch(s, member.path):
continue # Top level dir
elif re.match(s + r"\/", member.path): # Nested file
member.path = member.path.split("/", 1)[1]
yield member


def _download_tarfile(url, dest, rename={}):
"""Download and extract tarfile removing redundant top level dir"""
strip = r"^{}[\w\-.]*".format(dest) # Dir of same name as destination
filename = "tmp.tar.gz" # Temporary tarfile name
strip = r"^{}[\w\-.]*".format(dest) # Dir of same name as destination
filename = "tmp.tar.gz" # Temporary tarfile name
os.makedirs(dest, exist_ok=True)
request.urlretrieve(url, filename)
with tarfile.open(filename) as file:
Expand All @@ -38,12 +39,16 @@ def _download_tarfile(url, dest, rename={}):
os.remove(filename)


def _safe_apply_patch(patch):
"""Apply diff patch with shell tool or git"""
if shutil.which("patch") is not None:
os.system("patch -p1 < {}".format(patch))
else:
os.system("git apply {}".format(patch))
def _patch_dll_import():
"""Patch old Wasm C API header (see https://github.com/WebAssembly/wasm-c-api/pull/183)"""
for path in ["wasmer/include/wasm.h", "wasmtime/include/wasm.h"]:
if not os.path.isfile(path):
continue
with open(path, "r") as file:
content = file.read()
content = content.replace("__declspec(dllimport)", "")
with open(path, "w") as file:
file.write(content)


def download_wasmer(env, force=False, version=WASMER_VER_DEFAULT):
Expand Down Expand Up @@ -75,7 +80,7 @@ def download_wasmer(env, force=False, version=WASMER_VER_DEFAULT):
# Temporary workaround for Wasm C API and Wasmer issue
# See https://github.com/ashtonmeuser/godot-wasm/issues/26
# See https://github.com/ashtonmeuser/godot-wasm/issues/29
_safe_apply_patch("wasm-windows.patch")
_patch_dll_import()


def download_wasmtime(env, force=False, version=WASMTIME_VER_DEFAULT):
Expand Down
26 changes: 0 additions & 26 deletions wasm-windows.patch

This file was deleted.

0 comments on commit 4d961df

Please sign in to comment.