You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm running into the following error when I try running pdfium.wasm with wasmtime. I'm running on MacOS M3. Any ideas what could be wrong?
raise WasmtimeError._from_ptr(error)
wasmtime._error.WasmtimeError: incompatible import type for `wasi_snapshot_preview1::fd_seek`
Caused by:
types incompatible: expected type `(func (param i32 i32 i32 i32 i32) (result i32))`, found type `(func (param i32 i64 i32 i32) (result i32))`
Steps to Reproduce
Install Deps
pip install wasmtime
Download and install pdfium-wasm
curl -L -O https://github.com/bblanchon/pdfium-binaries/releases/latest/download/pdfium-wasm.tgz
tar -xzvf pdfium-wasm.tgz
Run python test_wasm.py in the same directory
# test_wasm.pyfromwasmtimeimportEngine, Store, Module, Linker, WasiConfig, FuncType, ValTypeimportctypesimportosimportlogging# Set up logginglogging.basicConfig(level=logging.INFO)
logger=logging.getLogger(__name__)
defdefine_unknown_imports_as_default_values(linker: Linker, module: Module) ->None:
forimpinmodule.imports:
ifimp.module!="env":
continueifisinstance(imp.type, FuncType):
func_ty=imp.typeresult_tys=func_ty.resultsdefdefault_func(*args):
# XXX: For some reason _emscripten_throw_longjmp is called with different numbers of# arguments, and sometimes expects a return value and sometimes not. This feels like# a bug, but I don't know if it's in emscripten or wasmtime.ifimp.name=="_emscripten_throw_longjmp":
iflen(args) in (3, 5):
return0returnNoneresults= []
fortyinresult_tys:
matchty:
caseValType.i32():
results.append(0)
caseValType.i64():
results.append(0)
caseValType.f32():
results.append(0.0)
caseValType.f64():
results.append(0.0)
returnresultslinker.define_func(imp.module, imp.name, func_ty, default_func)
defmain():
# Path to your PDFium WASM filewasm_file="lib/pdfium.wasm"importsys# Check if files existifnotos.path.exists(wasm_file):
logger.error(f"WASM file not found: {wasm_file}")
return# Create a store and engineengine=Engine()
module=Module.from_file(engine, wasm_file)
store=Store(engine)
linker=Linker(engine)
linker.define_wasi()
wasi_config=WasiConfig()
wasi_config.inherit_stdout()
store.set_wasi(wasi_config)
# Compile and instantiate the WASM modulelogger.info("Loading WASM module...")
define_unknown_imports_as_default_values(linker, module)
instance=linker.instantiate(store, module)
if__name__=="__main__":
main()
The text was updated successfully, but these errors were encountered:
mrboxtobox
changed the title
Function signature mismatch with pdfium.wasm on M3
Function signature mismatch with pdfium.wasm i32 vs. i64
Sep 13, 2024
Hi,
I'm running into the following error when I try running
pdfium.wasm
withwasmtime
. I'm running on MacOS M3. Any ideas what could be wrong?Steps to Reproduce
test_wasm.py
in the same directoryThe text was updated successfully, but these errors were encountered: