如何在同一个仓库中组织多个构建
How to organise multiple builds in the same repo
我是 Rust 的新手,正在尝试使用 Web Assembly。
我使用 yew 创建了一个简单的应用程序,它使用 t运行k 构建,这按预期工作。
然后我使用 actix 创建了一个简单的 html 服务器,这也被确认按预期工作。
我遇到的问题是,如果 actix 包包含在货物依赖项中,wasm 构建将失败(这似乎是合理的 - 当然在浏览器构建上下文中)。
我不想将它分成多个板条箱 - 至少在我制作原型时是这样,所以我希望有一种方法可以设置 2 个构建管道或使依赖条件成为条件 - 寻求有关如何最好地做到这一点的建议.
项目设置如下:
Cargo.toml
dist/
src/
frontend.rs # call to frontend code from non-main function
main.rs # fn main() here - can be empty function for the frontend
frontend/
mod.rs
app.rs # no actix dependency
shared/
mod.rs
shared.rs # no actix dependency
server/
mod.rs
server.rs # this has the actix dependency
目前我遇到的情况是以下 cargo.toml 和 main 将 运行 前端:
main.rs:
fn main() {}
Cargo.toml:
[dependencies]
seed = "0.8.0"
external_shared_stuff = "0.2.0"
以下将 运行 服务器:
main.rs:
mod server;
fn main() -> std::io::Result<()> {
server::server::serve()
}
Cargo.toml:
[dependencies]
seed = "0.8.0" //not required but no issue - would prefer it wasnt included
external_shared_stuff = "0.2.0"
actix-web = "3"
我目前使用 t运行k 到 build/serve 作为前端,cargo 运行 作为服务器。配置它的最佳方法是什么,以便两个构建都可以工作,我可以在不复制共享依赖项的情况下做到这一点吗?是否可以在构建目标上建立依赖条件?
在此先感谢您的帮助
I'm hoping there is a way to ... make a dependency conditional
有关在 Cargo.toml
中配置条件依赖项的信息,请参阅 Specifying Dependencies in the Cargo Book。在你的情况下你会想要这样的东西:
[dependencies]
seed = "0.8.0"
external_shared_stuff = "0.2.0"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
actix-web = "3"
我是 Rust 的新手,正在尝试使用 Web Assembly。
我使用 yew 创建了一个简单的应用程序,它使用 t运行k 构建,这按预期工作。 然后我使用 actix 创建了一个简单的 html 服务器,这也被确认按预期工作。
我遇到的问题是,如果 actix 包包含在货物依赖项中,wasm 构建将失败(这似乎是合理的 - 当然在浏览器构建上下文中)。
我不想将它分成多个板条箱 - 至少在我制作原型时是这样,所以我希望有一种方法可以设置 2 个构建管道或使依赖条件成为条件 - 寻求有关如何最好地做到这一点的建议.
项目设置如下:
Cargo.toml
dist/
src/
frontend.rs # call to frontend code from non-main function
main.rs # fn main() here - can be empty function for the frontend
frontend/
mod.rs
app.rs # no actix dependency
shared/
mod.rs
shared.rs # no actix dependency
server/
mod.rs
server.rs # this has the actix dependency
目前我遇到的情况是以下 cargo.toml 和 main 将 运行 前端:
main.rs:
fn main() {}
Cargo.toml:
[dependencies]
seed = "0.8.0"
external_shared_stuff = "0.2.0"
以下将 运行 服务器:
main.rs:
mod server;
fn main() -> std::io::Result<()> {
server::server::serve()
}
Cargo.toml:
[dependencies]
seed = "0.8.0" //not required but no issue - would prefer it wasnt included
external_shared_stuff = "0.2.0"
actix-web = "3"
我目前使用 t运行k 到 build/serve 作为前端,cargo 运行 作为服务器。配置它的最佳方法是什么,以便两个构建都可以工作,我可以在不复制共享依赖项的情况下做到这一点吗?是否可以在构建目标上建立依赖条件?
在此先感谢您的帮助
I'm hoping there is a way to ... make a dependency conditional
有关在 Cargo.toml
中配置条件依赖项的信息,请参阅 Specifying Dependencies in the Cargo Book。在你的情况下你会想要这样的东西:
[dependencies]
seed = "0.8.0"
external_shared_stuff = "0.2.0"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
actix-web = "3"