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

Bug: Rust Wrappers cannot be invoked (WasmtimeError: failed to parse WebAssembly module) #39

Closed
1 of 2 tasks
rihp opened this issue Nov 2, 2022 · 2 comments · Fixed by polywrap/wrap-cli#1396
Closed
1 of 2 tasks
Assignees
Labels
bug Something isn't working

Comments

@rihp
Copy link
Contributor

rihp commented Nov 2, 2022

We still have the error with WasmTime and Interface Types which doesn't allow us to execute the SHA3 wrapper for example, so we're skipping those tests now

Some background on the issue:

Most recent suggested solution on this issue thread proposes the following alternatives *(posted back in january, and few updates since)

Native support for Interface Types will be re-added to Wasmtime together with support for WebAssembly Components in the not-too-distant future. For now, wit-bindgen https://github.com/bytecodealliance/wit-bindgen (formerly known as wai-bindgen / witx-bindgen) is the right way to use Interface Types, though note that the details of the IDL and the bindings are still changing in breaking ways.

@radu-matei recently published an excellent blog post https://radu-matei.com/blog/intro-wasm-components/ describing how Components work and how to use wit-bindgen and other tools to work with them.

However these Wasm Component standards which would substitute the Interface Types are being developed still on the wasmtime repo from bytecode alliance (bytecodealliance/wasmtime#4185) and although "There's no esimate at this time", about 80% of the todos listed on such an issue have been closed

Another suggested approach:

@rihp rihp added the bug Something isn't working label Nov 2, 2022
@rihp
Copy link
Contributor Author

rihp commented Nov 2, 2022

The error we are getting with SHA3 is also arising with the wasm-rs bigint type wrapper (link)

In the case of the BigInt Type Rust wrapper, i've created this PR #40 which returns the following output on the cli:


========================================================================== FAILURES ==========================================================================
_________________________________________________________ test_invoke_bigint_rs_with_1arg_and_1prop __________________________________________________________

    async def test_invoke_bigint_rs_with_1arg_and_1prop():
        client = PolywrapClient()
        uri = Uri(f'fs/{Path(__file__).parent.joinpath("cases", "bigint-type-rs").absolute()}')
        args = { "arg1": "123", # The base number
            "obj": {
                "prop1": "1000", # multiply the base number by this factor
            }
        }
        options = InvokerOptions(uri=uri, method="method", args=args, encode_result=False)
>       result = await client.invoke(options)

tests/test_bigint_type.py:19: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
polywrap_client/client.py:146: in invoke
    result = await wrapper.invoke(options, invoker=self)
../polywrap-wasm/polywrap_wasm/wasm_wrapper.py:87: in invoke
    instance = self.create_wasm_instance(store, state, invoker)
../polywrap-wasm/polywrap_wasm/wasm_wrapper.py:49: in create_wasm_instance
    module = Module(store.engine, self.wasm_module)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <wasmtime._module.Module object at 0x10523df90>, engine = <wasmtime._engine.Engine object at 0x10523de10>
wasm = b'\x00asm\x01\x00\x00\x00\x01\x86\x01\x14`\x02\x7f\x7f\x01\x7f`\x03\x7f\x7f\x7f\x01\x7f`\x02\x7f\x7f\x00`\x03\x7f\x7f\...2022-04-04)\x06walrus\x060.12.0\x0cwasm-bindgen\x060.2.83\twasm-snip\x050.4.0\x00\x1b\x14wasm-interface-types\x050.1.0'

    def __init__(self, engine: Engine, wasm: typing.Union[str, bytes]):
        if not isinstance(engine, Engine):
            raise TypeError("expected an Engine")
    
        # If this looks like a string, parse it as the text format. Note that
        # in python 2 strings and bytes are basically the same, so we skip this
        # if the first byte in the string is 0, meaning this is actually a wasm
        # module.
        if isinstance(wasm, str) and len(wasm) > 0 and ord(wasm[0]) != 0:
            wasm = wat2wasm(wasm)
        if isinstance(wasm, bytes) and len(wasm) > 0 and wasm[0] != 0:
            wasm = wat2wasm(wasm)
    
        if not isinstance(wasm, (bytes, bytearray)):
            raise TypeError("expected wasm bytes")
    
        # TODO: can the copy be avoided here? I can't for the life of me
        # figure this out.
        binary = (c_uint8 * len(wasm)).from_buffer_copy(wasm)
        ptr = POINTER(ffi.wasmtime_module_t)()
        error = ffi.wasmtime_module_new(engine._ptr, binary, len(wasm), byref(ptr))
        if error:
>           raise WasmtimeError._from_ptr(error)
E           wasmtime._error.WasmtimeError: failed to parse WebAssembly module
E           
E           Caused by:
E               Unsupported feature: Support for interface types has temporarily been removed from `wasmtime`.
E               
E               For more information about this temoprary you can read on the issue online:
E               
E                   https://github.com/bytecodealliance/wasmtime/issues/1271
E               
E               and for re-adding support for interface types you can see this issue:
E               
E                   https://github.com/bytecodealliance/wasmtime/issues/677

../../../../../Library/Caches/pypoetry/virtualenvs/polywrap-client-hp5JTaRk-py3.10/lib/python3.10/site-packages/wasmtime/_module.py:42: WasmtimeError
================================================================== short test summary info ===================================================================
FAILED tests/test_bigint_type.py::test_invoke_bigint_rs_with_1arg_and_1prop - wasmtime._error.WasmtimeError: failed to parse WebAssembly module

@rihp
Copy link
Contributor Author

rihp commented Nov 3, 2022

The error trace is also visible in the CICD job run: link

@rihp rihp changed the title Bug: SHA3 cannot be invoked (WasmtimeError: failed to parse WebAssembly module) Bug: Rust Wrappers cannot be invoked (WasmtimeError: failed to parse WebAssembly module) Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants