@@ -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
+ > ** Note:** The old invocation prefix ` cargo: ` (one colon only) is deprecated
81
+ > and won't get any new features. To migrate, use two-colons prefix ` cargo:: ` ,
82
+ > which was added in Rust 1.77. If you were using ` cargo:KEY=VALUE ` for
83
+ > arbitrary links manifest key-value pairs, it is encouraged to switch to
84
+ > ` cargo::metadata=KEY=VALUE ` . Stick to ` cargo: ` only if the support of Rust
85
+ > version older than 1.77 is required.
86
+
87
+ > 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,40 +106,39 @@ 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
-
135
- ### ` cargo:rustc-link-arg=FLAG ` {#rustc-link-arg}
141
+ ### ` cargo::rustc-link-arg=FLAG ` {#rustc-link-arg}
136
142
137
143
The ` rustc-link-arg ` instruction tells Cargo to pass the [ ` -C link-arg=FLAG `
138
144
option] [ link-arg ] to the compiler, but only when building supported targets
@@ -142,23 +148,21 @@ linker script.
142
148
143
149
[ link-arg ] : ../../rustc/codegen-options/index.md#link-arg
144
150
145
- ### ` cargo:rustc-link-arg-bin=BIN=FLAG ` {#rustc-link-arg-bin}
151
+ ### ` cargo:: rustc-link-arg-bin=BIN=FLAG ` {#rustc-link-arg-bin}
146
152
147
153
The ` rustc-link-arg-bin ` instruction tells Cargo to pass the [ `-C
148
154
link-arg=FLAG` option] [ link-arg ] to the compiler, but only when building
149
155
the binary target with name ` BIN ` . Its usage is highly platform specific. It is useful
150
156
to set a linker script or other linker options.
151
157
152
-
153
- ### ` cargo:rustc-link-arg-bins=FLAG ` {#rustc-link-arg-bins}
158
+ ### ` cargo::rustc-link-arg-bins=FLAG ` {#rustc-link-arg-bins}
154
159
155
160
The ` rustc-link-arg-bins ` instruction tells Cargo to pass the [ `-C
156
161
link-arg=FLAG` option] [ link-arg ] to the compiler, but only when building a
157
162
binary target. Its usage is highly platform specific. It is useful
158
163
to set a linker script or other linker options.
159
164
160
-
161
- ### ` cargo:rustc-link-lib=LIB ` {#rustc-link-lib}
165
+ ### ` cargo::rustc-link-lib=LIB ` {#rustc-link-lib}
162
166
163
167
The ` rustc-link-lib ` instruction tells Cargo to link the given library using
164
168
the compiler's [ ` -l ` flag] [ option-link ] . This is typically used to link a
@@ -182,27 +186,25 @@ The optional `KIND` may be one of `dylib`, `static`, or `framework`. See the
182
186
[ option-link ] : ../../rustc/command-line-arguments.md#option-l-link-lib
183
187
[ FFI ] : ../../nomicon/ffi.md
184
188
185
-
186
- ### ` cargo:rustc-link-arg-tests=FLAG ` {#rustc-link-arg-tests}
189
+ ### ` cargo::rustc-link-arg-tests=FLAG ` {#rustc-link-arg-tests}
187
190
188
191
The ` rustc-link-arg-tests ` instruction tells Cargo to pass the [ `-C
189
192
link-arg=FLAG` option] [ link-arg ] to the compiler, but only when building a
190
193
tests target.
191
194
192
-
193
- ### ` cargo:rustc-link-arg-examples=FLAG ` {#rustc-link-arg-examples}
195
+ ### ` cargo::rustc-link-arg-examples=FLAG ` {#rustc-link-arg-examples}
194
196
195
197
The ` rustc-link-arg-examples ` instruction tells Cargo to pass the [ `-C
196
198
link-arg=FLAG` option] [ link-arg ] to the compiler, but only when building an examples
197
199
target.
198
200
199
- ### ` cargo:rustc-link-arg-benches=FLAG ` {#rustc-link-arg-benches}
201
+ ### ` cargo:: rustc-link-arg-benches=FLAG ` {#rustc-link-arg-benches}
200
202
201
203
The ` rustc-link-arg-benches ` instruction tells Cargo to pass the [ `-C
202
204
link-arg=FLAG` option] [ link-arg ] to the compiler, but only when building a benchmark
203
205
target.
204
206
205
- ### ` cargo:rustc-link-search=[KIND=]PATH ` {#rustc-link-search}
207
+ ### ` cargo:: rustc-link-search=[KIND=]PATH ` {#rustc-link-search}
206
208
207
209
The ` rustc-link-search ` instruction tells Cargo to pass the [ ` -L `
208
210
flag] [ option-search ] to the compiler to add a directory to the library search
@@ -220,14 +222,14 @@ is fine).
220
222
221
223
[ option-search ] : ../../rustc/command-line-arguments.md#option-l-search-path
222
224
223
- ### ` cargo:rustc-flags=FLAGS ` {#rustc-flags}
225
+ ### ` cargo:: rustc-flags=FLAGS ` {#rustc-flags}
224
226
225
227
The ` rustc-flags ` instruction tells Cargo to pass the given space-separated
226
228
flags to the compiler. This only allows the ` -l ` and ` -L ` flags, and is
227
229
equivalent to using [ ` rustc-link-lib ` ] ( #rustc-link-lib ) and
228
230
[ ` rustc-link-search ` ] ( #rustc-link-search ) .
229
231
230
- ### ` cargo:rustc-cfg=KEY[="VALUE"] ` {#rustc-cfg}
232
+ ### ` cargo:: rustc-cfg=KEY[="VALUE"] ` {#rustc-cfg}
231
233
232
234
The ` rustc-cfg ` instruction tells Cargo to pass the given value to the
233
235
[ ` --cfg ` flag] [ option-cfg ] to the compiler. This may be used for compile-time
@@ -239,16 +241,16 @@ used to enable an optional dependency, or enable other Cargo features.
239
241
Be aware that [ Cargo features] use the form ` feature="foo" ` . ` cfg ` values
240
242
passed with this flag are not restricted to that form, and may provide just a
241
243
single identifier, or any arbitrary key/value pair. For example, emitting
242
- ` cargo:rustc-cfg=abc ` will then allow code to use ` #[cfg(abc)] ` (note the lack
244
+ ` cargo:: rustc-cfg=abc ` will then allow code to use ` #[cfg(abc)] ` (note the lack
243
245
of ` feature= ` ). Or an arbitrary key/value pair may be used with an ` = ` symbol
244
- like ` cargo:rustc-cfg=my_component="foo" ` . The key should be a Rust
246
+ like ` cargo:: rustc-cfg=my_component="foo" ` . The key should be a Rust
245
247
identifier, the value should be a string.
246
248
247
249
[ cargo features ] : features.md
248
250
[ conditional compilation ] : ../../reference/conditional-compilation.md
249
251
[ option-cfg ] : ../../rustc/command-line-arguments.md#option-cfg
250
252
251
- ### ` cargo:rustc-env=VAR=VALUE ` {#rustc-env}
253
+ ### ` cargo:: rustc-env=VAR=VALUE ` {#rustc-env}
252
254
253
255
The ` rustc-env ` instruction tells Cargo to set the given environment variable
254
256
when compiling the package. The value can be then retrieved by the [ ` env! `
@@ -268,15 +270,14 @@ Cargo][env-cargo].
268
270
[ env-macro ] : ../../std/macro.env.html
269
271
[ env-cargo ] : environment-variables.md#environment-variables-cargo-sets-for-crates
270
272
271
- ### ` cargo:rustc-cdylib-link-arg=FLAG ` {#rustc-cdylib-link-arg}
273
+ ### ` cargo:: rustc-cdylib-link-arg=FLAG ` {#rustc-cdylib-link-arg}
272
274
273
275
The ` rustc-cdylib-link-arg ` instruction tells Cargo to pass the [ `-C
274
276
link-arg=FLAG` option] [ link-arg ] to the compiler, but only when building a
275
277
` cdylib ` library target. Its usage is highly platform specific. It is useful
276
278
to set the shared library version or the runtime-path.
277
279
278
-
279
- ### ` cargo:warning=MESSAGE ` {#cargo-warning}
280
+ ### ` cargo::warning=MESSAGE ` {#cargo-warning}
280
281
281
282
The ` warning ` instruction tells Cargo to display a warning after the build
282
283
script has finished running. Warnings are only shown for ` path ` dependencies
@@ -321,7 +322,7 @@ FAQ](../faq.md#why-is-cargo-rebuilding-my-code).
321
322
322
323
[ `exclude` and `include` fields ] : manifest.md#the-exclude-and-include-fields
323
324
324
- ### ` cargo:rerun-if-changed=PATH ` {#rerun-if-changed}
325
+ ### ` cargo:: rerun-if-changed=PATH ` {#rerun-if-changed}
325
326
326
327
The ` rerun-if-changed ` instruction tells Cargo to re-run the build script if
327
328
the file at the given path has changed. Currently, Cargo only uses the
@@ -333,14 +334,14 @@ If the path points to a directory, it will scan the entire directory for
333
334
any modifications.
334
335
335
336
If the build script inherently does not need to re-run under any circumstance,
336
- then emitting ` cargo:rerun-if-changed=build.rs ` is a simple way to prevent it
337
+ then emitting ` cargo:: rerun-if-changed=build.rs ` is a simple way to prevent it
337
338
from being re-run (otherwise, the default if no ` rerun-if ` instructions are
338
339
emitted is to scan the entire package directory for changes). Cargo
339
340
automatically handles whether or not the script itself needs to be recompiled,
340
341
and of course the script will be re-run after it has been recompiled.
341
342
Otherwise, specifying ` build.rs ` is redundant and unnecessary.
342
343
343
- ### ` cargo:rerun-if-env-changed=NAME ` {#rerun-if-env-changed}
344
+ ### ` cargo:: rerun-if-env-changed=NAME ` {#rerun-if-env-changed}
344
345
345
346
The ` rerun-if-env-changed ` instruction tells Cargo to re-run the build script
346
347
if the value of an environment variable of the given name has changed.
@@ -351,7 +352,6 @@ variables like `TARGET` that [Cargo sets for build scripts][build-env]. The
351
352
environment variables in use are those received by ` cargo ` invocations, not
352
353
those received by the executable of the build script.
353
354
354
-
355
355
## The ` links ` Manifest Key
356
356
357
357
The ` package.links ` key may be set in the ` Cargo.toml ` manifest to declare
0 commit comments