I am trying to follow the Rust and WebAssembly tutorial, but I am stuck at "Build the Project".
I am completely new to both rust and WebAssembly, so here is literally everything I have done, in order.
git clone [email protected]:rust-lang/rust.git.git clone [email protected]:rust-lang/cargo.git.cargo binary from step 2).cp target/release/cargo ~/.local/bin/cargo.install.root as _~/.local_.cargo install cargo-generate.cargo generate --git https://github.com/rustwasm/wasm-pack-template.cargo install wasm-pack - and yes, I really did this after generating my project. The documentation is lacking here.It is at this point I am now stuck.
wasm-pack build is complaining that I don't have rustup installed. Which is true, but I don't really understand why that's a problem.
cargo build --target=wasm32-unknown-unknown is throwing the following error.
error: failed to run `rustc` to learn about target-specific information
Caused by:
process didn't exit successfully: `sccache rustc - --crate-name ___ --print=file-names --target wasm32-unknown-unknown --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro` (exit code: 1)
--- stderr
error: Could not create LLVM TargetMachine for triple: wasm32-unknown-unknown: No available targets are compatible with triple "wasm32-unknown-unknown"
curl https://sh.rustup.rs -sSf | sh is complaining that I have an existing install of rust.
info: downloading installer
error: it looks like you have an existing installation of Rust at:
error: /home/code_m/.local/bin
error: rustup cannot be installed alongside Rust. Please uninstall first
error: if this is what you want, restart the installation with `-y'
error: cannot install while Rust is installed
This error also doesn't make any sense to me since it appears that rustup does more than _just install rustc_.
I would really rather not completely start over just to install the rustup tool. Please help me by telling me where else I should be reporting some of these errors.
since it appears that rustup does more than _just install rustc_.
Indeed, rustup is the official all-in-one Rust tool for:
Installing and managing multiple Rust versions (including having both Stable and Nightly installed at the same time, which is very useful)
Installing and managing multiple build targets (including wasm32-unknown-unknown)
Easily updating Rust to the latest version
Is there a particular reason you chose to manually compile Rust rather than use rustup?
What OS are you using? It looks like some flavor of Linux.
Which is true, but I don't really understand why that's a problem.
wasm-pack installs itself into the rustup directory, to avoid polluting your system with things spread all over the place.
It also uses rustup to check whether you have the wasm32-unknown-unknown target installed, and if not it then installs it.
Since rustup is the standard way to use Rust, and since it is supported across all platforms, it's easier for wasm-pack to use it instead of creating custom ad-hoc solutions.
But maybe there's a way we can support using wasm-pack without rustup?
The documentation is lacking here.
Is there anything we can do to improve that?
I took a look at the tutorial and it makes it clear that you need rustup, and it also says to install wasm-pack first, and then create the project.
Are you following a different tutorial somewhere else?
Is there anything we can do to improve that?
I took a look at the tutorial and it makes it clear that you need rustup, and it also says to install wasm-pack first, and then create the project.
I think the simplest thing would be to give an example usage when defining the tool for the first time.
The reason I didn't install it right away is that is was clear to me that wasm-pack was a collection of multiple tools. There was a possibility in my mind that the configuration from wasm-pack-template would allow cargo to take over the building portion.
Giving an example usage of wasm-pack would help indicate the tutorial will be using the tool directly for building later.
What OS are you using? It looks like some flavor of Linux.
I am running Ubuntu 18.04.2 in a Virtual Box environment.
I think it is worth supporting non-rustup workflows if possible, or at least if the w32-u-u target is installed, we shouldn't need rustup and if the target is not installed and rustup is not available, we should have a meaningful/helpful error message.
I think the simplest thing would be to give an example usage when defining the tool for the first time.
FWIW, it says right above there that you need rustup:
You will need the standard Rust toolchain, including
rustup,rustc, andcargo.
@fitzgen or at least if the w32-u-u target is installed
Currently it uses rustup to detect whether wasm32-unknown-unknown is installed, so how would we do that without rustup?
@fitzgen That's precisely the issue I had. The words
the standard Rust toolchain
meant absolutely nothing to me. I had never used the rust toolchain before, so there was still no indication (for me) that the rustup tool did more than install rustc.
That said, in the text you quoted I was referring to wasm-pack. Again, I had never seen the tool before. So without an example output I felt lost. To be completely fair, the cli gif in the README is pretty good. If that same gif appeared in rustwasm & wasm-pack books, it could be helpful for folk who understand by example.
Currently it uses
rustupto detect whetherwasm32-unknown-unknownis installed, so how would we do that withoutrustup?
We could try compiling a hello world (add a and b) crate to wasm and see if it works or not. This is essentially what configure does when checking whether there is a working C/C++ compiler.
there's a somewhat stale PR that was attempting to do this- i am going to work on a release today for tomorrow and i'll see if we can get it in
this should be solved with #552 which landed as #577 - it will be released in 0.7.0 tonight! please try it out and let us know how it works for you! if you have any trouble please file a new issue :)
Most helpful comment
We could try compiling a hello world (add a and b) crate to wasm and see if it works or not. This is essentially what configure does when checking whether there is a working C/C++ compiler.