官术网_书友最值得收藏!

The compile and run commands

As the main build tool, cargo does compile and run by way of creating and then executing the output binary (usually found in target/<profile>/<target-triple>/).

What if a library written in a different language is required to precede the Rust build? This is where build scripts come in. As mentioned in the Project configuration section, the manifest provides a field called build which takes a path or name to a build script.

The script itself can be a regular Rust binary that generates output in a designated folder, and can even have dependencies specified in Cargo.toml ([build-dependencies], but nothing else). Any required information (target architecture, output, and so on) is passed into the program using environment variables, and any output for cargo is required to have the cargo:key=value format. Those are picked up by cargo to configure further steps. While the most popular is building native dependencies, it's entirely possible to generate code (such as bindings, data access classes, and so on) as well. Read more in the cargo reference: https://doc.rust-lang.org/cargo/reference/build-scripts.html.

Larger projects will require a more complex structure than a simple src/ folder to contain all the source code, which is why cargo provides the option to split projects into subprojects, called a workspace. This comes in handy for architectural patterns such as microservices (each service could be a project), or loosely coupling components (clean architecture). To set this up, place each subproject in a subdirectory and create a Cargo.toml in the workspace that declares its members:

[workspace] 
members = [ "core", "web", "data"]

This applies any commands run at the top level to every crate in the workspace. Invoking cargo test will run all types of tests and that can take a long time.

主站蜘蛛池模板: 开阳县| 攀枝花市| 遂平县| 湘阴县| 龙游县| 苏尼特左旗| 拉萨市| 平远县| 五原县| 洛南县| 湛江市| 农安县| 泾阳县| 收藏| 南阳市| 山西省| 瑞丽市| 永新县| 乌鲁木齐市| 积石山| 犍为县| 曲沃县| 萨嘎县| 扶余县| 雷州市| 乐安县| 开封县| 金堂县| 阜平县| 阜南县| 濮阳市| 基隆市| 定陶县| 蕉岭县| 肃南| 宜州市| 滦平县| 介休市| 海宁市| 大余县| 东乌珠穆沁旗|