diff --git a/.github/actions/godot-cpp/action.yml b/.github/actions/godot-cpp/action.yml index 1a10355..03c15c3 100644 --- a/.github/actions/godot-cpp/action.yml +++ b/.github/actions/godot-cpp/action.yml @@ -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 }} diff --git a/SConstruct b/SConstruct index d0f3394..840a17f 100644 --- a/SConstruct +++ b/SConstruct @@ -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( diff --git a/SCsub b/SCsub index a9d688f..ea4b21b 100644 --- a/SCsub +++ b/SCsub @@ -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( diff --git a/utils.py b/utils.py index eb9c75d..35cf0ea 100644 --- a/utils.py +++ b/utils.py @@ -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: @@ -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): @@ -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): diff --git a/wasm-windows.patch b/wasm-windows.patch deleted file mode 100644 index f47f02c..0000000 --- a/wasm-windows.patch +++ /dev/null @@ -1,26 +0,0 @@ -diff --git a/wasmer/include/wasm.h b/wasmer/include/wasm.h -index 0873193..723cfd9 100644 ---- a/wasmer/include/wasm.h -+++ b/wasmer/include/wasm.h -@@ -11,7 +11,7 @@ - - #ifndef WASM_API_EXTERN - #ifdef _WIN32 --#define WASM_API_EXTERN __declspec(dllimport) -+#define WASM_API_EXTERN - #else - #define WASM_API_EXTERN - #endif -diff --git a/wasmer/include/wasm.hh b/wasmer/include/wasm.hh -index f0b3ee2..b2904ec 100644 ---- a/wasmer/include/wasm.hh -+++ b/wasmer/include/wasm.hh -@@ -13,7 +13,7 @@ - - #ifndef WASM_API_EXTERN - #ifdef _WIN32 --#define WASM_API_EXTERN __declspec(dllimport) -+#define WASM_API_EXTERN - #else - #define WASM_API_EXTERN - #endif