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

Updating dependencies breaks generated TypeScript #161

Open
andybalaam opened this issue Oct 30, 2024 · 6 comments
Open

Updating dependencies breaks generated TypeScript #161

andybalaam opened this issue Oct 30, 2024 · 6 comments

Comments

@andybalaam
Copy link
Member

andybalaam commented Oct 30, 2024

If I am using Rust 1.82.0 and run a cargo update then I get this error:

$ yarn build
...
[INFO]: ⬇️  Installing wasm-bindgen...
[INFO]: Optimizing wasm binaries with `wasm-opt`...
[wasm-validator error in function olmmachine_receiveSyncChanges\20externref\20shim] unexpected false: table.fill requires bulk-memory [--enable-bulk-memory], on 
(table.fill $1
 (local.get $7)
 (ref.null noextern)
 (i32.const 1)
)
...
Error: failed to execute `wasm-opt`: exited with exit status: 1
  full command: "/home/andy/.cache/.wasm-pack/wasm-opt-1ceaaea8b7b5f7e0/bin/wasm-opt" "/home/andy/code/public/matrix-rust/matrix-rust-sdk-crypto-wasm/pkg/matrix_sdk_crypto_wasm_bg.wasm" "-o" "/home/andy/code/public/matrix-rust/matrix-rust-sdk-crypto-wasm/pkg/matrix_sdk_crypto_wasm_bg.wasm-opt.wasm" "-Oz" "-g"
To disable `wasm-opt`, add `wasm-opt = false` to your package metadata in your `Cargo.toml`.
Caused by: failed to execute `wasm-opt`: exited with exit status: 1

Reading around this, it looks like some change in the dependencies causes this version of rustc¹ to use bulk memory operations in the generated wasm.

¹ Before I upgraded to rustc 1.82.0 it all actually built fine with no errors, but staying on an old rustc version doesn't seem viable.

If I enable bulk memory operations in wasm-opt by doing:

diff --git a/Cargo.toml b/Cargo.toml
index a5a87bd..df4b95e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -37,7 +37,7 @@ dwarf-debug-info = true
 #  * `-Oz`: optimise for size
 #  * `-g`: include the "name" section (which holds the printable names for
 #    symbols) in the output.
-wasm-opt = ['-Oz', '-g']
+wasm-opt = ['-Oz', '-g', '--enable-bulk-memory']

Then the build works OK but linting the generated TypeScript fails:

$ yarn lint
...
> tsc --noEmit
pkg/matrix_sdk_crypto_wasm_bg.wasm.d.ts:5:59 - error TS2314: Generic type 'Array<T>' requires 1 type argument(s).
5 export function attachment_encrypt(a: number, b: number): Array;
                                                            ~~~~~
...

It looks like this lint is correctly identifying invalid/incomplete TypeScript being emitted (by wasm-bindgen?).

So we are unable to update our dependencies until we can fix this problem.

@richvdh
Copy link
Member

richvdh commented Oct 30, 2024

possibly we can work around this by post-processing the generated typescript, but that is clearly an unsatisfactory solution :/

@andybalaam
Copy link
Member Author

I strongly suspect that the dependency update causing the change is the wasm-bindgen dependency itself. This looks like a similar issue: rustwasm/wasm-bindgen#4234

@andybalaam
Copy link
Member Author

Ah, it looks like this is caused by rustwasm/wasm-bindgen#4207 or at least very closely related.

@andybalaam
Copy link
Member Author

So we should stay on wasm-bindgen v0.2.93 until rustwasm/wasm-bindgen#4207 is fixed.

@richvdh
Copy link
Member

richvdh commented Dec 17, 2024

I wonder if we can now update wasm-bindgen.

@andybalaam
Copy link
Member Author

The linked bug was apparently fixed in October this year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants