将非 Rust 存储库声明为 Rust 项目中的依赖项的最佳方法是什么?
What's the best way to declare a non-rust repository as a dependency in a rust project?
我有一个 rust 项目,我想在其中使用存在于另一个非 rust 存储库中的 protobuf 定义。
我打算下载 protobuf 存储库,在我的主存储库中创建一个 src/common_protobuf
模块,使用 cargo build
将每个 protobuf 的所有 rust 实现生成到 common_protobuf
模块,然后使用 pub use
.
选择性地将生成的结构重新导出到它们的预期模块中
我似乎找不到指定依赖关系的最佳方式。使用
[build-dependencies]
pbrepo = { git="https://github.com/username/pbrepo" }
结果
Caused by:
Could not find Cargo.toml in `/Users/username/.cargo/git/checkouts/pbrepo-33abcde7dddd6356/fdefgd9`
我无法将 Cargo.toml
提交到外部存储库。我考虑过使用 git 子模块或使用子模块和 Cargo.toml 创建 sys-crate,但我更喜欢将构建依赖项放在一个地方,而不必在构建期间同步多个 repos。
我可以在构建脚本中手动下载存储库并将提交设置为拉入我的 build.rs
但我还是希望将所有构建依赖项放在一个地方。
是否有实现此目的的机制,或者这是使用远程 protobuf 定义的更好方法?
Cargo 不支持下载非 Rust 依赖项。您唯一可以为您下载 Cargo 的是 Cargo 包(松散的“板条箱”)。
即使您将 Cargo.toml
添加到您的非 Rust 存储库中,这也无济于事,因为无法请求该依赖项的位置以从中读取。 Cargo 的依赖机制让您只依赖 构建的库 ,而不是它的源文件(据我所知;我可能错过了一些东西)。
在 运行 cargo build
.
之前,您将不得不使用一些单独的程序来下载依赖项(自定义脚本,git 子模块……)
我会用 cargo-make
它允许更复杂的依赖关系跟踪和从其他语言构建东西。
由于您 use Cargo directly, you have to resort to a higher-level mechanism, such as Git submodules, which can be 在通过 build.rs
构建之前。这样 cargo build
将在单个命令中获取子模块并构建您的项目。
我有一个 rust 项目,我想在其中使用存在于另一个非 rust 存储库中的 protobuf 定义。
我打算下载 protobuf 存储库,在我的主存储库中创建一个 src/common_protobuf
模块,使用 cargo build
将每个 protobuf 的所有 rust 实现生成到 common_protobuf
模块,然后使用 pub use
.
我似乎找不到指定依赖关系的最佳方式。使用
[build-dependencies]
pbrepo = { git="https://github.com/username/pbrepo" }
结果
Caused by:
Could not find Cargo.toml in `/Users/username/.cargo/git/checkouts/pbrepo-33abcde7dddd6356/fdefgd9`
我无法将 Cargo.toml
提交到外部存储库。我考虑过使用 git 子模块或使用子模块和 Cargo.toml 创建 sys-crate,但我更喜欢将构建依赖项放在一个地方,而不必在构建期间同步多个 repos。
我可以在构建脚本中手动下载存储库并将提交设置为拉入我的 build.rs
但我还是希望将所有构建依赖项放在一个地方。
是否有实现此目的的机制,或者这是使用远程 protobuf 定义的更好方法?
Cargo 不支持下载非 Rust 依赖项。您唯一可以为您下载 Cargo 的是 Cargo 包(松散的“板条箱”)。
即使您将 Cargo.toml
添加到您的非 Rust 存储库中,这也无济于事,因为无法请求该依赖项的位置以从中读取。 Cargo 的依赖机制让您只依赖 构建的库 ,而不是它的源文件(据我所知;我可能错过了一些东西)。
在 运行 cargo build
.
我会用 cargo-make
它允许更复杂的依赖关系跟踪和从其他语言构建东西。
由于您 build.rs
构建之前。这样 cargo build
将在单个命令中获取子模块并构建您的项目。