The wasm-bindgen-cli is a command line tool that is used to generate JavaScript bindings for the WebAssembly modules. It was used in a previous tutorial on how to create and run a Wasm Rust module in a browser. I was using Windows when I wrote that article, but a few days ago, I went through the tutorial using Ubuntu 20.04 and encountered few errors when attempting to install wasm-bindgen-cli tool.
To install the wasm-bindgen-cli tool, we use the following command:
curl https://sh.rustup.rs -sSf | sh
into the terminal. More information can be found on this page.Aside from a bit lengthy installation process, I didn't have any other issues when using Windows, but on Ubuntu 20.04, I received two installation errors.
The linker `cc` not found error
The first error that appeared was related to the linker.
error: linker `cc` not found
|
= note: No such file or directory (os error 2)
error: could not compile `libc` due to previous error
warning: build failed, waiting for other jobs to finish...
error: failed to compile `wasm-bindgen-cli v0.2.84`, intermediate artifacts can be found at ...
The solution was to install the build-essential package, which includes basic tools to compile other packages from the source code.
This fixed the linker error, but when I ran the wasm-bindgen-cli installation again, I got another error.
The "failed to run custom build command for openssl-sys" error
The exact error message displayed was as follows:
Caused by:
process didn't exit successfully: `/tmp/cargo-installbcXvkc/release/build/openssl-sys-972f5eb3ddbebfda/build-script-main` (exit status: 101)
--- stdout
cargo:rustc-cfg=const_fn
cargo:rustc-cfg=openssl
...
And the solution here was first to install the libssl-dev package, which is a development library for OpenSSL.
But this wasn't enough. I also needed to install the pkg-config package that is used to manage library dependencies.
If we now attempt the installation again, it should succeed. The last line of the installation process should display something like this:
We can verify that the installation was successful by checking the version of the tool:
Summary
The wasm-bindgen-cli tool is part of the wasm-bindgen project, and we can use it to bind the wasm module with JavaScript. That way, we can run the wasm module from a browser for example. To successfully install the wasm-bindgen-cli tool on Ubuntu 20.04, we must first have Rust installed. We also need to have a few packages installed too. Those are build-essential, libssl-dev, and the pkg-config package.