供应本地依赖性以构建而无需访问该依赖关系

发布于 2025-01-25 16:28:39 字数 2387 浏览 2 评论 0原文

生锈& 我拥有的货物版本

$ rustc --version
rustc 1.60.0 (7737e0b5c 2022-04-04)
$ cargo version
cargo 1.60.0 (d1fd9fe 2022-03-01)

上下文

  • 库板条板 enger 在我的磁盘上定义的某个地方定义(/path/to/crate/ettrate/ettry
  • 二进制板条箱hello ,使用此ettry库板条箱,并在其他地方定义(/an/other/path/to/crate/crate/hello

库板条

箱库板条箱(entry)导出一个功能; /path/to/crate/greet/src/lib.rs.rs看起来像:

pub fn say_hello() {
    println!("Hello!");
}

二进制板条箱hello

我的二进制板条箱(hello> Hello)使用<代码>问候库板条箱; /an/other/path/to/crate/hello/cargo.toml看起来像:

[package]
name = "hello"
version = "0.1.0"
edition = "2021"

[dependencies]
greet = { path = "/path/to/crate/greet" }

hello/src/main.rs看起来像:

fn main() {
    greet::say_hello();
}

所有工作完美,货物运行Hello文件夹打印hello!

问题

我的用例是在码头容器中构建二进制板条箱 hello ,而无需访问/安装/path/to/crate/ettrate/ettrate/etche卷:

docker run --rm -it -v /an/other/path/to/crate/hello:/app -w /app \
    rust:1.60.0-slim cargo build

如果我运行上一个命令,我显然有一个错误:

error: failed to get `greet` as a dependency of package `hello v0.1.0 (/app)`

Caused by:
  failed to load source for dependency `greet`

Caused by:
  Unable to update /path/to/crate/greet

Caused by:
  failed to read `/path/to/crate/greet/Cargo.toml`

Caused by:
  No such file or directory (os error 2)

我想我的问题与供应我的库板条箱有关。但是,当我从我的二进制板条箱 Hello 中运行货物供应商时,我收到了一条消息:

这个项目中供应商没有依赖性。

我如何供应商此库板条板 hello文件夹,以便我一次捕获entry> engry板条箱的内容,因此看起来看起来很像像这样:

.
└── hello
    ├── Cargo.toml
    ├── src
    │   └── main.rs
    └── vendor
         └── greet
              └── ...

因此,我能够使用docker 访问/path/to/crate/ettrate 代码>?

Rust & cargo versions

$ rustc --version
rustc 1.60.0 (7737e0b5c 2022-04-04)
$ cargo version
cargo 1.60.0 (d1fd9fe 2022-03-01)

Context

I have:

  • a library crate greet defined somewhere on my disk (/path/to/crate/greet)
  • a binary crate hello, using this greet library crate, and defined somewhere else (/an/other/path/to/crate/hello)

Library crate greet

My library crate (greet) exports one function; /path/to/crate/greet/src/lib.rs looks like:

pub fn say_hello() {
    println!("Hello!");
}

Binary crate hello

My binary crate (hello) uses the greet library crate; /an/other/path/to/crate/hello/Cargo.toml looks like:

[package]
name = "hello"
version = "0.1.0"
edition = "2021"

[dependencies]
greet = { path = "/path/to/crate/greet" }

And hello/src/main.rs looks like:

fn main() {
    greet::say_hello();
}

All works perfectly, cargo run from hello folder prints Hello!.

Question

My use case is to build the binary crate hello in a Docker container, without having access to/mounting the /path/to/crate/greet volume:

docker run --rm -it -v /an/other/path/to/crate/hello:/app -w /app \
    rust:1.60.0-slim cargo build

If I run the previous command, I obviously got an error:

error: failed to get `greet` as a dependency of package `hello v0.1.0 (/app)`

Caused by:
  failed to load source for dependency `greet`

Caused by:
  Unable to update /path/to/crate/greet

Caused by:
  failed to read `/path/to/crate/greet/Cargo.toml`

Caused by:
  No such file or directory (os error 2)

I suppose that my question relates to vendoring my library crate. But when I run cargo vendor from my binary crate hello, I got a message:

There is no dependency to vendor in this project.

How can I vendor this library crate in hello folder, so that I can capture the contents of greet crate at one time, and so it looks like this:

.
└── hello
    ├── Cargo.toml
    ├── src
    │   └── main.rs
    └── vendor
         └── greet
              └── ...

And so I am able to build hello with docker without access to /path/to/crate/greet?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文