windows - WASM/Yew - 无法解析 : could not find `unix` in `os`

标签 windows rust webassembly yew

在 Windows 上构建 Yew 应用

我正在 Windows 上构建紫杉应用程序和 rocket 后端 this tutorial (虽然教程是针对 Linux 环境的)。我正在尝试构建红 bean 杉应用程序 使用 wasm-pack。不过,我没有使用 Linux 子系统来构建应用程序 我确实安装了它。

代码/配置

The repository .

我已经安装了 wasm 工具链和 cargo make:

rustup target add wasm32-unknown-unknown

以下是我的工具链列表:

stable-x86_64-pc-windows-gnu
stable-x86_64-pc-windows-msvc
nightly-x86_64-pc-windows-msvc (default)
1.30.0-x86_64-pc-windows-msvc

这是我的文件夹结构:

Project root
├───backend           <-- rocket backend
|   ├───Cargo.toml
│   └───src
│       ├───bin
│       └───db
├───frontend          <-- yew frontend
│   ├───pkg
│   ├───src
|   ├───Cargo.toml
|   └───Makefile.toml
├───src
├───Cargo.toml
└───Makefile.toml

这是rootdir\Cargo.toml:

[package]
name = "sentinel"
version = "0.1.0"
authors = ["zachdelano <email>"]
edition = "2018"

[workspace]
members = ["backend", "frontend"]

这是rootdir\Makefile.toml:

[env]
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = "true"

[tasks.default]
clear = true
dependencies = ["build"]

这是rootdir\frontend\Cargo.toml:

[dependencies]
sentinel = { path = ".." }
yew = "0.17.3"
wasm-pack = "0.9.1"
wasm-bindgen = "0.2.68"
web-sys = "0.3.45"

[lib]
crate-type = ["cdylib", "rlib"]

这是rootdir\frontend\Makefile.toml:

[tasks.default]
dependencies = ["create_wasm"]

[tasks.create_wasm]
command = "wasm-pack"
args = ["build", "--target", "web", "--out-name", "package", "--dev"] 
dependencies = ["build"]

预期结果

我希望应用程序在我运行时无错误地完成构建 cargo 制作Yew tutorial 似乎表明不需要其他任何东西。

实际输出

我在运行 cargo make(从根目录)时遇到了很多错误,如下所示:

error[E0433]: failed to resolve: could not find `unix` in `os`
  --> C:\Users\Zach\.cargo\registry\src\github.com-1ecc6299db9ec823\dirs-1.0.5\src\lin.rs:41:18
   |
41 |     use std::os::unix::ffi::OsStringExt;
   |                  ^^^^ could not find `unix` in `os`

参见 the entire list of errors

这是一种工具链之类的东西吗?我该如何解决这个问题?

运行rustup 更新

我明白了 从运行 rustup update

现在当我从根目录运行 cargo make 时,我得到不同的错误:

error[E0432]: unresolved import `crate::sys`                                                                                                                                                                                     
  --> C:\Users\Zach\.cargo\registry\src\github.com-1ecc6299db9ec823\socket2-0.3.15\src\socket.rs:23:5
   |
23 | use crate::sys;
   |     ^^^^^^^^^^ no `sys` in the root

参见 the following output 。 一些代码改变了 full list of errors

最佳答案

问题最终是我试图安装 wasm-packweb-sys。我不知道为什么这是个问题,但当我将它们注释掉并运行 cargo make 时,一切都很好。我还删除了 target 并重新运行 cargo make 以确保安全。

[package]
name = "frontend"
version = "0.1.0"
authors = ["zachdelano <email>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
sentinel = { path = ".." }
yew = "0.17.3"
wasm-bindgen = "0.2.68"
# wasm-pack = "0.9.1"
# web-sys = "0.3.45"

[lib]
crate-type = ["cdylib", "rlib"]

关于windows - WASM/Yew - 无法解析 : could not find `unix` in `os` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64164717/

相关文章:

windows - 在 Windows 服务器上运行的 apache 上的 htaccess 文件是否不同

c++ - 如何在 ListView 控件中制作复选框三态?

windows - 在 Windows 中,有什么方法可以将 errno 转换为 HRESULT?

blazor - 当我创建 Blazor WASM 项目时

go - 如何从 tinygo webassembly 目标返回对象

c# - <string, image> 字典,WP8

rust - 使用泛型时, `From` 的实现如何冲突?

types - 以特定结构作为参数的特征实现

rust - 如何在不使用大量 RAM 的情况下创建压缩的 tar 文件?

swift - 将 Swift 编译为 WebAssembly