安装时可能无法安装“wasm32-wasi”目标

Vic*_*lyk 1 rust rust-cargo rustup rust-wasm

为什么在安装时cargo build --target wasm32-wasi会抛出错误并提示没有安装。\n重现的步骤wasm32-wasi

\n
    \n
  1. 货运新列车
  2. \n
  3. rustup 目标添加 wasm32-wasi
  4. \n
  5. 货物构建--目标 wasm32-wasi
  6. \n
\n

接下来是控制台的输出

\n
\xe2\x9e\x9c  train git:(master) \xe2\x9c\x97 cargo build --target wasm32-wasi\n   Compiling train v0.1.0 (/user/playground/rustLang/train)\nerror[E0463]: can't find crate for `std`\n  |\n  = note: the `wasm32-wasi` target may not be installed\n  = help: consider downloading the target with `rustup target add wasm32-wasi`\n\nerror: cannot find macro `println` in this scope\n --> src/main.rs:2:5\n  |\n2 |     println!("hello");\n  |     ^^^^^^^\n\nerror: requires `sized` lang_item\n\nFor more information about this error, try `rustc --explain E0463`.\nerror: could not compile `train` due to 3 previous errors\n\xe2\x9e\x9c  train git:(master) \xe2\x9c\x97 rustup target add wasm32-wasi\ninfo: component 'rust-std' for target 'wasm32-wasi' is up to date\n\xe2\x9e\x9c  train git:(master) \xe2\x9c\x97 \n
Run Code Online (Sandbox Code Playgroud)\n

小智 8

我有同样的问题。我在 MacOS 上:

\n
\xe2\x9d\xae cargo wasi build --release                                                                                                         \nerror: failed to find the `wasm32-wasi` target installed, and rustup is also not detected, you\'ll need to be sure to install the `wasm32-wasi` target before using this command\n
Run Code Online (Sandbox Code Playgroud)\n

事实证明,我使用的是 Rust 的自制安装:

\n
\xe2\x9d\xaf which cargo                                                                                                                          \n/opt/homebrew/bin/cargo\n
Run Code Online (Sandbox Code Playgroud)\n

解决方案是卸载 rust 的自制版本,然后按照 rust-lang.org 上的说明安装该版本(实际代码可能有所不同。只需访问https://www.rust-lang.org/tools/install并按照说明)

\n
\xe2\x9d\xaf brew uninstall rust                                                                                                                  \nUninstalling /opt/homebrew/Cellar/rust/1.67.1... (36,648 files, 891.6MB)\n\n\xe2\x9d\xaf curl --proto \'=https\' --tlsv1.2 -sSf https://sh.rustup.rs | sh\n
Run Code Online (Sandbox Code Playgroud)\n