File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 87
87
- [ Dependencies] ( cargo/deps.md )
88
88
- [ Conventions] ( cargo/conventions.md )
89
89
- [ Tests] ( cargo/test.md )
90
+ - [ Build Scripts] ( cargo/build_scripts.md )
90
91
91
92
- [ Attributes] ( attribute.md )
92
93
- [ ` dead_code ` ] ( attribute/unused.md )
Original file line number Diff line number Diff line change
1
+ # Build Scripts
2
+
3
+ Sometimes a normal build from cargo is not enough. Perhaps your crate needs some
4
+ pre-requisites before cargo will successfully compile, things like code
5
+ generation, or some native code that needs to be compiled. To solve this problem
6
+ we have build scripts that Cargo can run.
7
+
8
+ To add a build script to your package it can either be specified in the
9
+ ` Cargo.toml ` as follows:
10
+
11
+ ``` toml
12
+ [package ]
13
+ ...
14
+ build = " build.rs"
15
+ ```
16
+
17
+ Otherwise Cargo will look for a ` build.rs ` file in the project directory by
18
+ default.
19
+
20
+ ## How to use a build script
21
+
22
+ The build script is simply another Rust file that will be compiled and invoked
23
+ prior to compiling anything else in the package. Hence it can be used to fulfil
24
+ pre-requisites of your crate.
25
+
26
+ Cargo provides the script with inputs via environment variables [ specified
27
+ here] that can be used.
28
+
29
+ The script provides output via stdout. All lines printed are written to
30
+ ` target/debug/build/<pkg>/output ` . Further, lines prefixed with ` cargo: ` will be
31
+ interpreted by Cargo directly and hence can be used to define parameters for the
32
+ packages compilation.
33
+
34
+ For further specification and examples have a read of the [ cargo specification] .
35
+
36
+ [ specified here ] : https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts
37
+
38
+ [ cargo specification ] : https://doc.rust-lang.org/cargo/reference/build-scripts.html
You can’t perform that action at this time.
0 commit comments