How do you make a WASM library?

Continuing the discussion from Is it possible to compile WASM from Rust using C libraries?:

@kthakore It is preferable to create new topic instead of replying to very old topics. You can use the "Reply as linked topic" button. I created this topic for the new discussion.


I think we need to understand what want to do with the WASM. A WASM library isn't a cdylib.

I can see where the cdylib - wasm library connection comes from. The mdn link doesn't explain cdylib but assures it is needed.

They do link to this: https://doc.rust-lang.org/reference/linkage.html

--crate-type=cdylib, #[crate_type = "cdylib"] - A dynamic system library will be produced. This is used when compiling a dynamic library to be loaded from another language. This output type will create *.so files on Linux, *.dylib files on macOS, and *.dll files on Windows.

That unfortunately doesn't mention wasm, which leads to questions like this that explain in more detail why wasm uses cdylib.

1 Like