Skip to content

Commit c3f8b2f

Browse files
committed
Update build script docs
Signed-off-by: hi-rustin <[email protected]>
1 parent 0e51014 commit c3f8b2f

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

src/doc/src/reference/build-scripts.md

+39-39
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ that script and execute it just before building the package.
1515
// Example custom build script.
1616
fn main() {
1717
// 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::metadata=rerun-if-changed=src/hello.c");
1919
// Use the `cc` crate to build a C file and statically link it.
2020
cc::Build::new()
2121
.file("src/hello.c")
@@ -42,7 +42,7 @@ scripts.
4242
Just before a package is built, Cargo will compile a build script into an
4343
executable (if it has not already been built). It will then run the script,
4444
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::metadata=` to stdout.
4646

4747
The build script will be rebuilt if any of its source files or dependencies
4848
change.
@@ -74,16 +74,16 @@ directory specified in the [`OUT_DIR` environment variable][build-env]. Scripts
7474
should not modify any files outside of that directory.
7575

7676
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::metadata=` as an instruction that will
7878
influence compilation of the package. All other lines are ignored.
7979

80-
> Note: The order of `cargo:` instructions printed by the build script *may*
80+
> Note: The order of `cargo::metadata=` instructions printed by the build script *may*
8181
> affect the order of arguments that `cargo` passes to `rustc`. In turn, the
8282
> order of arguments passed to `rustc` may affect the order of arguments passed
8383
> to the linker. Therefore, you will want to pay attention to the order of the
8484
> build script's instructions. For example, if object `foo` needs to link against
8585
> library `bar`, you may want to make sure that library `bar`'s
86-
> [`cargo:rustc-link-lib`](#rustc-link-lib) instruction appears *after*
86+
> [`cargo::metadata=rustc-link-lib`](#rustc-link-lib) instruction appears *after*
8787
> instructions to link object `foo`.
8888
8989
The output of the script is hidden from the terminal during normal
@@ -99,41 +99,41 @@ configuration). The stderr output is also saved in that same directory.
9999
The following is a summary of the instructions that Cargo recognizes, with each
100100
one detailed below.
101101

102-
* [`cargo:rerun-if-changed=PATH`](#rerun-if-changed) --- Tells Cargo when to
102+
* [`cargo::metadata=rerun-if-changed=PATH`](#rerun-if-changed) --- Tells Cargo when to
103103
re-run the script.
104-
* [`cargo:rerun-if-env-changed=VAR`](#rerun-if-env-changed) --- Tells Cargo when
104+
* [`cargo::metadata=rerun-if-env-changed=VAR`](#rerun-if-env-changed) --- Tells Cargo when
105105
to re-run the script.
106-
* [`cargo:rustc-link-arg=FLAG`](#rustc-link-arg) --- Passes custom flags to a
106+
* [`cargo::metadata=rustc-link-arg=FLAG`](#rustc-link-arg) --- Passes custom flags to a
107107
linker for benchmarks, binaries, `cdylib` crates, examples, and tests.
108-
* [`cargo:rustc-link-arg-bin=BIN=FLAG`](#rustc-link-arg-bin) --- Passes custom
108+
* [`cargo::metadata=rustc-link-arg-bin=BIN=FLAG`](#rustc-link-arg-bin) --- Passes custom
109109
flags to a linker for the binary `BIN`.
110-
* [`cargo:rustc-link-arg-bins=FLAG`](#rustc-link-arg-bins) --- Passes custom
110+
* [`cargo::metadata=rustc-link-arg-bins=FLAG`](#rustc-link-arg-bins) --- Passes custom
111111
flags to a linker for binaries.
112-
* [`cargo:rustc-link-arg-tests=FLAG`](#rustc-link-arg-tests) --- Passes custom
112+
* [`cargo::metadata=rustc-link-arg-tests=FLAG`](#rustc-link-arg-tests) --- Passes custom
113113
flags to a linker for tests.
114-
* [`cargo:rustc-link-arg-examples=FLAG`](#rustc-link-arg-examples) --- Passes custom
114+
* [`cargo::metadata=rustc-link-arg-examples=FLAG`](#rustc-link-arg-examples) --- Passes custom
115115
flags to a linker for examples.
116-
* [`cargo:rustc-link-arg-benches=FLAG`](#rustc-link-arg-benches) --- Passes custom
116+
* [`cargo::metadata=rustc-link-arg-benches=FLAG`](#rustc-link-arg-benches) --- Passes custom
117117
flags to a linker for benchmarks.
118-
* [`cargo:rustc-link-lib=LIB`](#rustc-link-lib) --- Adds a library to
118+
* [`cargo::metadata=rustc-link-lib=LIB`](#rustc-link-lib) --- Adds a library to
119119
link.
120-
* [`cargo:rustc-link-search=[KIND=]PATH`](#rustc-link-search) --- Adds to the
120+
* [`cargo::metadata=rustc-link-search=[KIND=]PATH`](#rustc-link-search) --- Adds to the
121121
library search path.
122-
* [`cargo:rustc-flags=FLAGS`](#rustc-flags) --- Passes certain flags to the
122+
* [`cargo::metadata=rustc-flags=FLAGS`](#rustc-flags) --- Passes certain flags to the
123123
compiler.
124-
* [`cargo:rustc-cfg=KEY[="VALUE"]`](#rustc-cfg) --- Enables compile-time `cfg`
124+
* [`cargo::metadata=rustc-cfg=KEY[="VALUE"]`](#rustc-cfg) --- Enables compile-time `cfg`
125125
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
126+
* [`cargo::metadata=rustc-env=VAR=VALUE`](#rustc-env) --- Sets an environment variable.
127+
* [`cargo::metadata=rustc-cdylib-link-arg=FLAG`](#rustc-cdylib-link-arg) --- Passes custom
128128
flags to a linker for cdylib crates.
129-
* [`cargo:warning=MESSAGE`](#cargo-warning) --- Displays a warning on the
129+
* [`cargo::metadata=warning=MESSAGE`](#cargo-warning) --- Displays a warning on the
130130
terminal.
131-
* [`cargo:KEY=VALUE`](#the-links-manifest-key) --- Metadata, used by `links`
131+
* [`cargo::metadata=KEY=VALUE`](#the-links-manifest-key) --- Metadata, used by `links`
132132
scripts.
133133

134134

135135
<a id="rustc-link-arg"></a>
136-
#### `cargo:rustc-link-arg=FLAG`
136+
#### `cargo::metadata=rustc-link-arg=FLAG`
137137

138138
The `rustc-link-arg` instruction tells Cargo to pass the [`-C link-arg=FLAG`
139139
option][link-arg] to the compiler, but only when building supported targets
@@ -144,7 +144,7 @@ linker script.
144144
[link-arg]: ../../rustc/codegen-options/index.md#link-arg
145145

146146
<a id="rustc-link-arg-bin"></a>
147-
#### `cargo:rustc-link-arg-bin=BIN=FLAG`
147+
#### `cargo::metadata=rustc-link-arg-bin=BIN=FLAG`
148148

149149
The `rustc-link-arg-bin` instruction tells Cargo to pass the [`-C
150150
link-arg=FLAG` option][link-arg] to the compiler, but only when building
@@ -153,7 +153,7 @@ to set a linker script or other linker options.
153153

154154

155155
<a id="rustc-link-arg-bins"></a>
156-
#### `cargo:rustc-link-arg-bins=FLAG`
156+
#### `cargo::metadata=rustc-link-arg-bins=FLAG`
157157

158158
The `rustc-link-arg-bins` instruction tells Cargo to pass the [`-C
159159
link-arg=FLAG` option][link-arg] to the compiler, but only when building a
@@ -162,7 +162,7 @@ to set a linker script or other linker options.
162162

163163

164164
<a id="rustc-link-lib"></a>
165-
#### `cargo:rustc-link-lib=LIB`
165+
#### `cargo::metadata=rustc-link-lib=LIB`
166166

167167
The `rustc-link-lib` instruction tells Cargo to link the given library using
168168
the compiler's [`-l` flag][option-link]. This is typically used to link a
@@ -188,29 +188,29 @@ The optional `KIND` may be one of `dylib`, `static`, or `framework`. See the
188188

189189

190190
<a id="rustc-link-arg-tests"></a>
191-
#### `cargo:rustc-link-arg-tests=FLAG`
191+
#### `cargo::metadata=rustc-link-arg-tests=FLAG`
192192

193193
The `rustc-link-arg-tests` instruction tells Cargo to pass the [`-C
194194
link-arg=FLAG` option][link-arg] to the compiler, but only when building a
195195
tests target.
196196

197197

198198
<a id="rustc-link-arg-examples"></a>
199-
#### `cargo:rustc-link-arg-examples=FLAG`
199+
#### `cargo::metadata=rustc-link-arg-examples=FLAG`
200200

201201
The `rustc-link-arg-examples` instruction tells Cargo to pass the [`-C
202202
link-arg=FLAG` option][link-arg] to the compiler, but only when building an examples
203203
target.
204204

205205
<a id="rustc-link-arg-benches"></a>
206-
#### `cargo:rustc-link-arg-benches=FLAG`
206+
#### `cargo::metadata=rustc-link-arg-benches=FLAG`
207207

208208
The `rustc-link-arg-benches` instruction tells Cargo to pass the [`-C
209209
link-arg=FLAG` option][link-arg] to the compiler, but only when building a benchmark
210210
target.
211211

212212
<a id="rustc-link-search"></a>
213-
#### `cargo:rustc-link-search=[KIND=]PATH`
213+
#### `cargo::metadata=rustc-link-search=[KIND=]PATH`
214214

215215
The `rustc-link-search` instruction tells Cargo to pass the [`-L`
216216
flag][option-search] to the compiler to add a directory to the library search
@@ -229,15 +229,15 @@ is fine).
229229
[option-search]: ../../rustc/command-line-arguments.md#option-l-search-path
230230

231231
<a id="rustc-flags"></a>
232-
#### `cargo:rustc-flags=FLAGS`
232+
#### `cargo::metadata=rustc-flags=FLAGS`
233233

234234
The `rustc-flags` instruction tells Cargo to pass the given space-separated
235235
flags to the compiler. This only allows the `-l` and `-L` flags, and is
236236
equivalent to using [`rustc-link-lib`](#rustc-link-lib) and
237237
[`rustc-link-search`](#rustc-link-search).
238238

239239
<a id="rustc-cfg"></a>
240-
#### `cargo:rustc-cfg=KEY[="VALUE"]`
240+
#### `cargo::metadata=rustc-cfg=KEY[="VALUE"]`
241241

242242
The `rustc-cfg` instruction tells Cargo to pass the given value to the
243243
[`--cfg` flag][option-cfg] to the compiler. This may be used for compile-time
@@ -249,17 +249,17 @@ used to enable an optional dependency, or enable other Cargo features.
249249
Be aware that [Cargo features] use the form `feature="foo"`. `cfg` values
250250
passed with this flag are not restricted to that form, and may provide just a
251251
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
252+
`cargo::metadata=rustc-cfg=abc` will then allow code to use `#[cfg(abc)]` (note the lack
253253
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
254+
like `cargo::metadata=rustc-cfg=my_component="foo"`. The key should be a Rust
255255
identifier, the value should be a string.
256256

257257
[cargo features]: features.md
258258
[conditional compilation]: ../../reference/conditional-compilation.md
259259
[option-cfg]: ../../rustc/command-line-arguments.md#option-cfg
260260

261261
<a id="rustc-env"></a>
262-
#### `cargo:rustc-env=VAR=VALUE`
262+
#### `cargo::metadata=rustc-env=VAR=VALUE`
263263

264264
The `rustc-env` instruction tells Cargo to set the given environment variable
265265
when compiling the package. The value can be then retrieved by the [`env!`
@@ -280,7 +280,7 @@ Cargo][env-cargo].
280280
[env-cargo]: environment-variables.md#environment-variables-cargo-sets-for-crates
281281

282282
<a id="rustc-cdylib-link-arg"></a>
283-
#### `cargo:rustc-cdylib-link-arg=FLAG`
283+
#### `cargo::metadata=rustc-cdylib-link-arg=FLAG`
284284

285285
The `rustc-cdylib-link-arg` instruction tells Cargo to pass the [`-C
286286
link-arg=FLAG` option][link-arg] to the compiler, but only when building a
@@ -289,7 +289,7 @@ to set the shared library version or the runtime-path.
289289

290290

291291
<a id="cargo-warning"></a>
292-
#### `cargo:warning=MESSAGE`
292+
#### `cargo::metadata=warning=MESSAGE`
293293

294294
The `warning` instruction tells Cargo to display a warning after the build
295295
script has finished running. Warnings are only shown for `path` dependencies
@@ -335,7 +335,7 @@ FAQ](../faq.md#why-is-cargo-rebuilding-my-code).
335335
[`exclude` and `include` fields]: manifest.md#the-exclude-and-include-fields
336336

337337
<a id="rerun-if-changed"></a>
338-
#### `cargo:rerun-if-changed=PATH`
338+
#### `cargo::metadata=rerun-if-changed=PATH`
339339

340340
The `rerun-if-changed` instruction tells Cargo to re-run the build script if
341341
the file at the given path has changed. Currently, Cargo only uses the
@@ -347,15 +347,15 @@ If the path points to a directory, it will scan the entire directory for
347347
any modifications.
348348

349349
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
350+
then emitting `cargo::metadata=rerun-if-changed=build.rs` is a simple way to prevent it
351351
from being re-run (otherwise, the default if no `rerun-if` instructions are
352352
emitted is to scan the entire package directory for changes). Cargo
353353
automatically handles whether or not the script itself needs to be recompiled,
354354
and of course the script will be re-run after it has been recompiled.
355355
Otherwise, specifying `build.rs` is redundant and unnecessary.
356356

357357
<a id="rerun-if-env-changed"></a>
358-
#### `cargo:rerun-if-env-changed=NAME`
358+
#### `cargo::metadata=rerun-if-env-changed=NAME`
359359

360360
The `rerun-if-env-changed` instruction tells Cargo to re-run the build script
361361
if the value of an environment variable of the given name has changed.

0 commit comments

Comments
 (0)