安装cargo-generate各种坑【mac + wasm + rust 环境搭建】

安装cargo-generate各种坑【mac + wasm + rust 环境搭建】,第1张

cargo install cargo-generate 如果报openssl错误千万别再去装了,各种坑,这个cargo-generate可以手动下载安装的。

先贴上我的报错信息:

run pkg_config fail: "`\"pkg-config\" \"--libs\" \"--cflags\" \"openssl\"` did not exit successfully: exit status: 1\nerror: could not find system library 'openssl' required by the 'openssl-sys' crate\n\n--- stderr\nPackage openssl was not found in the pkg-config search path.\nPerhaps you should add the directory containing `openssl.pc'\nto the PKG_CONFIG_PATH environment variable\nNo package 'openssl' found\n"

  --- stderr
  thread 'main' panicked at '

  Could not find directory of OpenSSL installation, and this `-sys` crate cannot
  proceed without this knowledge. If OpenSSL is installed and this crate had
  trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the
  compilation process.

  Make sure you also have the development packages of openssl installed.
  For example, `libssl-dev` on Ubuntu or `openssl-devel` on Fedora.

  If you're in a situation where you think the directory *should* be found
  automatically, please open a bug at https://github.com/sfackler/rust-openssl
  and include information about your system as well as this message.

  $HOST = x86_64-apple-darwin
  $TARGET = x86_64-apple-darwin
  openssl-sys = 0.9.72



  openssl-sys crate build failed: no supported version of OpenSSL found.

  Ways to fix it:
  - Use the `vendored` feature of openssl-sys crate to build OpenSSL from source.
  - Use Homebrew to install the `openssl` package.

  ', xxx/.cargo/registry/src/mirrors.sjtug.sjtu.edu.cn-7a04d2510079875b/openssl-sys-0.9.72/build/find_normal.rs:180:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: failed to compile `cargo-generate v0.13.1`, intermediate artifacts can be found at `/var/folders/h9/w8_2_02x7j96mcdfd5l70rk80000gn/T/cargo-install1rzgJF`

Caused by:
  build failed
错误尝试

which openssl
openssl version
发现我的是 xx/anaconda3/bin/openssl 的
然后新开终端是 /usr/bin/openssl 的
两者安装都报错
homebrew太慢了,终止。。。
下载安装openssl,似乎也没安装成。。。

正确的方式-手动安装
  1. 上面各种折腾实在没辙,就找了个安装包: https://github.com/cargo-generate/cargo-generate/releases, mac电脑直接下载darwin
  2. 解压后的 cargo-generate 放入 ~/.cargo/bin/ 中
  3. 运行 cargo generate --git https://github.com/rustwasm/wasm-pack-template
    3.1: 这一步如果报权限问题,系统阻止打开generate,那么就和mac打开其他非官方的程序一样到安全那里点仍然打开就允许打开了,然后再重新执行上面命令。
  4. source ~/.bash_profile
  5. sudo wasm-pack build
  6. 之后控制台最后面显示这个就表示编译成功了:
    Finished release [optimized] target(s) in 21.66s
    剩下的就是自己再看参考中后续的教程把webpack项目建好即可:参考 mac + wasm + rust 环境搭建

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/737867.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-28
下一篇 2022-04-28

发表评论

登录后才能评论

评论列表(0条)

保存