供应本地依赖性以构建而无需访问该依赖关系
生锈& 我拥有的货物版本
$ 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 thisgreet
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论