Как использовать внешние ящики в скрипте сборки Car go? - PullRequest
1 голос
/ 11 февраля 2020

У меня есть эта файловая структура

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

У меня есть этот автомобиль go .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`

Поддерживает ли Car go только std в build.rs?

1 Ответ

2 голосов
/ 11 февраля 2020

Добавьте ящик к вашему ключу [build-dependencies]:

[build-dependencies]
regex = "*"

Вы можете также добавить ящик к ключу [dependencies], если он нужен вашему ящику.

См. Также:

...