如何在带有货运的建造脚本中使用外部箱子

问题描述 投票:0回答:1

我有此文件结构

Test
│   .gitignore
│   build.rs
│   Cargo.toml
│
├───.vscode
│       tasks.json
│
├───src
│       main.rs

我有这个Cargo.toml

[package]
name = "test"
version = "0.1.0"
authors = ["xtricman"]
edition = "2018"

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

[dependencies]
regex = "*"

还有这个build.rs

fn main() {
    let mt = regex::Regex::new(r"_[1-9][0-9]+.rs|_0.rs\z").unwrap().find("gdf_980.rs");
    let mts = if mt.is_some() {
        println!("{}", mt.unwrap().as_str());
    } else {
        println!("None");
    };
}

我想在构建脚本中使用正则表达式板条箱,但只是出现编译错误

error[E0433]: failed to resolve: use of undeclared type or module `regex`
 --> build.rs:2:14
  |
2 |     let mt = regex::Regex::new(r"_[1-9][0-9]+.rs|_0.rs\z").unwrap().find("gdf_980.rs");
  |              ^^^^^ use of undeclared type or module `regex`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0433`.
error: could not compile `test`.
warning: build failed, waiting for other jobs to finish...
error: build failed

问题如何在构建脚本中使用外部包装箱?货物仅支持build.rs中的std吗?

rust rust-cargo
1个回答
0
投票

改为将其添加到您的[build-dependencies]键:

[build-dependencies]
regex = "*"
© www.soinside.com 2019 - 2024. All rights reserved.