@@ -15,7 +15,7 @@ that script and execute it just before building the package.
15
15
// Example custom build script.
16
16
fn main() {
17
17
// Tell Cargo that if the given file changes, to rerun this build script.
18
- println!("cargo:rerun-if-changed=src/hello.c");
18
+ println!("cargo:: rerun-if-changed=src/hello.c");
19
19
// Use the `cc` crate to build a C file and statically link it.
20
20
cc::Build::new()
21
21
.file("src/hello.c")
@@ -42,7 +42,7 @@ scripts.
42
42
Just before a package is built, Cargo will compile a build script into an
43
43
executable (if it has not already been built). It will then run the script,
44
44
which may perform any number of tasks. The script may communicate with Cargo
45
- by printing specially formatted commands prefixed with ` cargo: ` to stdout.
45
+ by printing specially formatted commands prefixed with ` cargo:: ` to stdout.
46
46
47
47
The build script will be rebuilt if any of its source files or dependencies
48
48
change.
@@ -74,16 +74,23 @@ directory specified in the [`OUT_DIR` environment variable][build-env]. Scripts
74
74
should not modify any files outside of that directory.
75
75
76
76
Build scripts communicate with Cargo by printing to stdout. Cargo will
77
- interpret each line that starts with ` cargo: ` as an instruction that will
77
+ interpret each line that starts with ` cargo:: ` as an instruction that will
78
78
influence compilation of the package. All other lines are ignored.
79
79
80
- > Note: The order of ` cargo: ` instructions printed by the build script * may*
80
+ After the merge of [ #12201 ] , various instruction formats are now available, including:
81
+
82
+ * ` cargo::KEY=VALUE ` or ` cargo:KEY=VALUE ` for setting Cargo recognized keys.
83
+ * ` cargo::metadata=KEY=VALUE ` or ` cargo:KEY=VALUE ` for setting unrecognized metadata keys.
84
+
85
+ [ #12201 ] : https://github.com/rust-lang/cargo/pull/12201
86
+
87
+ > Note: The order of ` cargo:: ` instructions printed by the build script * may*
81
88
> affect the order of arguments that ` cargo ` passes to ` rustc ` . In turn, the
82
89
> order of arguments passed to ` rustc ` may affect the order of arguments passed
83
90
> to the linker. Therefore, you will want to pay attention to the order of the
84
91
> build script's instructions. For example, if object ` foo ` needs to link against
85
92
> library ` bar ` , you may want to make sure that library ` bar ` 's
86
- > [ ` cargo:rustc-link-lib ` ] ( #rustc-link-lib ) instruction appears * after*
93
+ > [ ` cargo:: rustc-link-lib ` ] ( #rustc-link-lib ) instruction appears * after*
87
94
> instructions to link object ` foo ` .
88
95
89
96
The output of the script is hidden from the terminal during normal
@@ -99,41 +106,41 @@ configuration). The stderr output is also saved in that same directory.
99
106
The following is a summary of the instructions that Cargo recognizes, with each
100
107
one detailed below.
101
108
102
- * [ ` cargo:rerun-if-changed=PATH ` ] ( #rerun-if-changed ) --- Tells Cargo when to
109
+ * [ ` cargo:: rerun-if-changed=PATH ` ] ( #rerun-if-changed ) --- Tells Cargo when to
103
110
re-run the script.
104
- * [ ` cargo:rerun-if-env-changed=VAR ` ] ( #rerun-if-env-changed ) --- Tells Cargo when
111
+ * [ ` cargo:: rerun-if-env-changed=VAR ` ] ( #rerun-if-env-changed ) --- Tells Cargo when
105
112
to re-run the script.
106
- * [ ` cargo:rustc-link-arg=FLAG ` ] ( #rustc-link-arg ) --- Passes custom flags to a
113
+ * [ ` cargo:: rustc-link-arg=FLAG ` ] ( #rustc-link-arg ) --- Passes custom flags to a
107
114
linker for benchmarks, binaries, ` cdylib ` crates, examples, and tests.
108
- * [ ` cargo:rustc-link-arg-bin=BIN=FLAG ` ] ( #rustc-link-arg-bin ) --- Passes custom
115
+ * [ ` cargo:: rustc-link-arg-bin=BIN=FLAG ` ] ( #rustc-link-arg-bin ) --- Passes custom
109
116
flags to a linker for the binary ` BIN ` .
110
- * [ ` cargo:rustc-link-arg-bins=FLAG ` ] ( #rustc-link-arg-bins ) --- Passes custom
117
+ * [ ` cargo:: rustc-link-arg-bins=FLAG ` ] ( #rustc-link-arg-bins ) --- Passes custom
111
118
flags to a linker for binaries.
112
- * [ ` cargo:rustc-link-arg-tests=FLAG ` ] ( #rustc-link-arg-tests ) --- Passes custom
119
+ * [ ` cargo:: rustc-link-arg-tests=FLAG ` ] ( #rustc-link-arg-tests ) --- Passes custom
113
120
flags to a linker for tests.
114
- * [ ` cargo:rustc-link-arg-examples=FLAG ` ] ( #rustc-link-arg-examples ) --- Passes custom
121
+ * [ ` cargo:: rustc-link-arg-examples=FLAG ` ] ( #rustc-link-arg-examples ) --- Passes custom
115
122
flags to a linker for examples.
116
- * [ ` cargo:rustc-link-arg-benches=FLAG ` ] ( #rustc-link-arg-benches ) --- Passes custom
123
+ * [ ` cargo:: rustc-link-arg-benches=FLAG ` ] ( #rustc-link-arg-benches ) --- Passes custom
117
124
flags to a linker for benchmarks.
118
- * [ ` cargo:rustc-link-lib=LIB ` ] ( #rustc-link-lib ) --- Adds a library to
125
+ * [ ` cargo:: rustc-link-lib=LIB ` ] ( #rustc-link-lib ) --- Adds a library to
119
126
link.
120
- * [ ` cargo:rustc-link-search=[KIND=]PATH ` ] ( #rustc-link-search ) --- Adds to the
127
+ * [ ` cargo:: rustc-link-search=[KIND=]PATH ` ] ( #rustc-link-search ) --- Adds to the
121
128
library search path.
122
- * [ ` cargo:rustc-flags=FLAGS ` ] ( #rustc-flags ) --- Passes certain flags to the
129
+ * [ ` cargo:: rustc-flags=FLAGS ` ] ( #rustc-flags ) --- Passes certain flags to the
123
130
compiler.
124
- * [ ` cargo:rustc-cfg=KEY[="VALUE"] ` ] ( #rustc-cfg ) --- Enables compile-time ` cfg `
131
+ * [ ` cargo:: rustc-cfg=KEY[="VALUE"] ` ] ( #rustc-cfg ) --- Enables compile-time ` cfg `
125
132
settings.
126
- * [ ` cargo:rustc-env=VAR=VALUE ` ] ( #rustc-env ) --- Sets an environment variable.
127
- * [ ` cargo:rustc-cdylib-link-arg=FLAG ` ] ( #rustc-cdylib-link-arg ) --- Passes custom
133
+ * [ ` cargo:: rustc-env=VAR=VALUE ` ] ( #rustc-env ) --- Sets an environment variable.
134
+ * [ ` cargo:: rustc-cdylib-link-arg=FLAG ` ] ( #rustc-cdylib-link-arg ) --- Passes custom
128
135
flags to a linker for cdylib crates.
129
- * [ ` cargo:warning=MESSAGE ` ] ( #cargo-warning ) --- Displays a warning on the
136
+ * [ ` cargo:: warning=MESSAGE ` ] ( #cargo-warning ) --- Displays a warning on the
130
137
terminal.
131
- * [ ` cargo:KEY=VALUE ` ] ( #the-links-manifest-key ) --- Metadata, used by ` links `
138
+ * [ ` cargo::metadata= KEY=VALUE ` ] ( #the-links-manifest-key ) --- Metadata, used by ` links `
132
139
scripts.
133
140
134
141
135
142
<a id =" rustc-link-arg " ></a >
136
- #### ` cargo:rustc-link-arg=FLAG `
143
+ #### ` cargo:: rustc-link-arg=FLAG `
137
144
138
145
The ` rustc-link-arg ` instruction tells Cargo to pass the [ ` -C link-arg=FLAG `
139
146
option] [ link-arg ] to the compiler, but only when building supported targets
@@ -144,7 +151,7 @@ linker script.
144
151
[ link-arg ] : ../../rustc/codegen-options/index.md#link-arg
145
152
146
153
<a id =" rustc-link-arg-bin " ></a >
147
- #### ` cargo:rustc-link-arg-bin=BIN=FLAG `
154
+ #### ` cargo:: rustc-link-arg-bin=BIN=FLAG `
148
155
149
156
The ` rustc-link-arg-bin ` instruction tells Cargo to pass the [ `-C
150
157
link-arg=FLAG` option] [ link-arg ] to the compiler, but only when building
@@ -153,7 +160,7 @@ to set a linker script or other linker options.
153
160
154
161
155
162
<a id =" rustc-link-arg-bins " ></a >
156
- #### ` cargo:rustc-link-arg-bins=FLAG `
163
+ #### ` cargo:: rustc-link-arg-bins=FLAG `
157
164
158
165
The ` rustc-link-arg-bins ` instruction tells Cargo to pass the [ `-C
159
166
link-arg=FLAG` option] [ link-arg ] to the compiler, but only when building a
@@ -162,7 +169,7 @@ to set a linker script or other linker options.
162
169
163
170
164
171
<a id =" rustc-link-lib " ></a >
165
- #### ` cargo:rustc-link-lib=LIB `
172
+ #### ` cargo:: rustc-link-lib=LIB `
166
173
167
174
The ` rustc-link-lib ` instruction tells Cargo to link the given library using
168
175
the compiler's [ ` -l ` flag] [ option-link ] . This is typically used to link a
@@ -188,29 +195,29 @@ The optional `KIND` may be one of `dylib`, `static`, or `framework`. See the
188
195
189
196
190
197
<a id =" rustc-link-arg-tests " ></a >
191
- #### ` cargo:rustc-link-arg-tests=FLAG `
198
+ #### ` cargo:: rustc-link-arg-tests=FLAG `
192
199
193
200
The ` rustc-link-arg-tests ` instruction tells Cargo to pass the [ `-C
194
201
link-arg=FLAG` option] [ link-arg ] to the compiler, but only when building a
195
202
tests target.
196
203
197
204
198
205
<a id =" rustc-link-arg-examples " ></a >
199
- #### ` cargo:rustc-link-arg-examples=FLAG `
206
+ #### ` cargo:: rustc-link-arg-examples=FLAG `
200
207
201
208
The ` rustc-link-arg-examples ` instruction tells Cargo to pass the [ `-C
202
209
link-arg=FLAG` option] [ link-arg ] to the compiler, but only when building an examples
203
210
target.
204
211
205
212
<a id =" rustc-link-arg-benches " ></a >
206
- #### ` cargo:rustc-link-arg-benches=FLAG `
213
+ #### ` cargo:: rustc-link-arg-benches=FLAG `
207
214
208
215
The ` rustc-link-arg-benches ` instruction tells Cargo to pass the [ `-C
209
216
link-arg=FLAG` option] [ link-arg ] to the compiler, but only when building a benchmark
210
217
target.
211
218
212
219
<a id =" rustc-link-search " ></a >
213
- #### ` cargo:rustc-link-search=[KIND=]PATH `
220
+ #### ` cargo:: rustc-link-search=[KIND=]PATH `
214
221
215
222
The ` rustc-link-search ` instruction tells Cargo to pass the [ ` -L `
216
223
flag] [ option-search ] to the compiler to add a directory to the library search
@@ -229,15 +236,15 @@ is fine).
229
236
[ option-search ] : ../../rustc/command-line-arguments.md#option-l-search-path
230
237
231
238
<a id =" rustc-flags " ></a >
232
- #### ` cargo:rustc-flags=FLAGS `
239
+ #### ` cargo:: rustc-flags=FLAGS `
233
240
234
241
The ` rustc-flags ` instruction tells Cargo to pass the given space-separated
235
242
flags to the compiler. This only allows the ` -l ` and ` -L ` flags, and is
236
243
equivalent to using [ ` rustc-link-lib ` ] ( #rustc-link-lib ) and
237
244
[ ` rustc-link-search ` ] ( #rustc-link-search ) .
238
245
239
246
<a id =" rustc-cfg " ></a >
240
- #### ` cargo:rustc-cfg=KEY[="VALUE"] `
247
+ #### ` cargo:: rustc-cfg=KEY[="VALUE"] `
241
248
242
249
The ` rustc-cfg ` instruction tells Cargo to pass the given value to the
243
250
[ ` --cfg ` flag] [ option-cfg ] to the compiler. This may be used for compile-time
@@ -249,17 +256,17 @@ used to enable an optional dependency, or enable other Cargo features.
249
256
Be aware that [ Cargo features] use the form ` feature="foo" ` . ` cfg ` values
250
257
passed with this flag are not restricted to that form, and may provide just a
251
258
single identifier, or any arbitrary key/value pair. For example, emitting
252
- ` cargo:rustc-cfg=abc ` will then allow code to use ` #[cfg(abc)] ` (note the lack
259
+ ` cargo:: rustc-cfg=abc ` will then allow code to use ` #[cfg(abc)] ` (note the lack
253
260
of ` feature= ` ). Or an arbitrary key/value pair may be used with an ` = ` symbol
254
- like ` cargo:rustc-cfg=my_component="foo" ` . The key should be a Rust
261
+ like ` cargo:: rustc-cfg=my_component="foo" ` . The key should be a Rust
255
262
identifier, the value should be a string.
256
263
257
264
[ cargo features ] : features.md
258
265
[ conditional compilation ] : ../../reference/conditional-compilation.md
259
266
[ option-cfg ] : ../../rustc/command-line-arguments.md#option-cfg
260
267
261
268
<a id =" rustc-env " ></a >
262
- #### ` cargo:rustc-env=VAR=VALUE `
269
+ #### ` cargo:: rustc-env=VAR=VALUE `
263
270
264
271
The ` rustc-env ` instruction tells Cargo to set the given environment variable
265
272
when compiling the package. The value can be then retrieved by the [ ` env! `
@@ -280,7 +287,7 @@ Cargo][env-cargo].
280
287
[ env-cargo ] : environment-variables.md#environment-variables-cargo-sets-for-crates
281
288
282
289
<a id =" rustc-cdylib-link-arg " ></a >
283
- #### ` cargo:rustc-cdylib-link-arg=FLAG `
290
+ #### ` cargo:: rustc-cdylib-link-arg=FLAG `
284
291
285
292
The ` rustc-cdylib-link-arg ` instruction tells Cargo to pass the [ `-C
286
293
link-arg=FLAG` option] [ link-arg ] to the compiler, but only when building a
@@ -289,7 +296,7 @@ to set the shared library version or the runtime-path.
289
296
290
297
291
298
<a id =" cargo-warning " ></a >
292
- #### ` cargo:warning=MESSAGE `
299
+ #### ` cargo:: warning=MESSAGE `
293
300
294
301
The ` warning ` instruction tells Cargo to display a warning after the build
295
302
script has finished running. Warnings are only shown for ` path ` dependencies
@@ -335,7 +342,7 @@ FAQ](../faq.md#why-is-cargo-rebuilding-my-code).
335
342
[ `exclude` and `include` fields ] : manifest.md#the-exclude-and-include-fields
336
343
337
344
<a id =" rerun-if-changed " ></a >
338
- #### ` cargo:rerun-if-changed=PATH `
345
+ #### ` cargo:: rerun-if-changed=PATH `
339
346
340
347
The ` rerun-if-changed ` instruction tells Cargo to re-run the build script if
341
348
the file at the given path has changed. Currently, Cargo only uses the
@@ -347,15 +354,15 @@ If the path points to a directory, it will scan the entire directory for
347
354
any modifications.
348
355
349
356
If the build script inherently does not need to re-run under any circumstance,
350
- then emitting ` cargo:rerun-if-changed=build.rs ` is a simple way to prevent it
357
+ then emitting ` cargo:: rerun-if-changed=build.rs ` is a simple way to prevent it
351
358
from being re-run (otherwise, the default if no ` rerun-if ` instructions are
352
359
emitted is to scan the entire package directory for changes). Cargo
353
360
automatically handles whether or not the script itself needs to be recompiled,
354
361
and of course the script will be re-run after it has been recompiled.
355
362
Otherwise, specifying ` build.rs ` is redundant and unnecessary.
356
363
357
364
<a id =" rerun-if-env-changed " ></a >
358
- #### ` cargo:rerun-if-env-changed=NAME `
365
+ #### ` cargo:: rerun-if-env-changed=NAME `
359
366
360
367
The ` rerun-if-env-changed ` instruction tells Cargo to re-run the build script
361
368
if the value of an environment variable of the given name has changed.
0 commit comments