【问题标题】:WASM/Yew - failed to resolve: could not find `unix` in `os`WASM/Yew - 无法解决:在 `os` 中找不到 `unix`
【发布时间】:2021-01-17 17:27:45
【问题描述】:

在 Windows 上构建 Yew 应用

我正在 Windows 上与火箭后端一起构建一个 yew 应用程序 this tutorial (尽管本教程适用于 Linux 环境)。我正在尝试构建 yew 应用程序 使用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 makeYew 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 update

我得到the following output 从运行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

请参阅full list of errors。 部分代码更改in the repository

【问题讨论】:

    标签: windows rust webassembly yew


    【解决方案1】:

    问题最终是我试图安装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"]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-22
      • 1970-01-01
      • 2017-11-06
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 2020-10-08
      • 1970-01-01
      相关资源
      最近更新 更多