Skip to content

Commit d45969a

Browse files
committed
Auto merge of #12201 - hi-rustin:rustin-patch-build-script, r=epage
Extend the build directive syntax with `cargo::`
2 parents 74ef21b + dec9e8c commit d45969a

20 files changed

+577
-291
lines changed

src/cargo/core/compiler/custom_build.rs

+167-48
Large diffs are not rendered by default.

src/cargo/core/compiler/fingerprint/dirty_reason.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl DirtyReason {
168168
DirtyReason::LocalLengthsChanged => {
169169
s.dirty_because(unit, "the local lengths changed")?;
170170
s.note(
171-
"This could happen because of added/removed `cargo:rerun-if` instructions in the build script",
171+
"This could happen because of added/removed `cargo::rerun-if` instructions in the build script",
172172
)?;
173173

174174
Ok(())

src/doc/src/faq.md

+22-22
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ Cargo has no way right now of after-the-fact debugging "why was that rebuilt?"
242242

243243
Some issues we've seen historically which can cause crates to get rebuilt are:
244244

245-
* A build script prints `cargo:rerun-if-changed=foo` where `foo` is a file that
245+
* A build script prints `cargo::rerun-if-changed=foo` where `foo` is a file that
246246
doesn't exist and nothing generates it. In this case Cargo will keep running
247247
the build script thinking it will generate the file but nothing ever does. The
248248
fix is to avoid printing `rerun-if-changed` in this scenario.
@@ -280,38 +280,38 @@ issue](https://github.com/rust-lang/cargo/issues/new)!
280280
281281
Have you seen the error message above?
282282

283-
This is one of the most annoying error message for Cargo users. There are several
284-
situations may lead us to a version conflict. Below we'll walk through possible
283+
This is one of the most annoying error message for Cargo users. There are several
284+
situations may lead us to a version conflict. Below we'll walk through possible
285285
causes and provide diagnostic techniques to help you out there:
286286

287-
- The project and its dependencies use [links] to repeatedly link the local
288-
library. Cargo forbids linking two packages with the same native library, so
289-
even with multiple layers of dependencies it is not allowed. In this case, the
290-
error message will prompt: `Only one package in the dependency graph may specify
291-
the same links value`, you may need to manually check and delete duplicate link
287+
- The project and its dependencies use [links] to repeatedly link the local
288+
library. Cargo forbids linking two packages with the same native library, so
289+
even with multiple layers of dependencies it is not allowed. In this case, the
290+
error message will prompt: `Only one package in the dependency graph may specify
291+
the same links value`, you may need to manually check and delete duplicate link
292292
values. The community also have [conventions in place] to alleviate this.
293293

294-
- When depending on different crates in the project, if these crates use the same
295-
dependent library, but the version used is restricted, making it impossible to
296-
determine the correct version, it will also cause conflicts. The error message
297-
will prompt: `all possible versions conflict with previously selected packages`.
294+
- When depending on different crates in the project, if these crates use the same
295+
dependent library, but the version used is restricted, making it impossible to
296+
determine the correct version, it will also cause conflicts. The error message
297+
will prompt: `all possible versions conflict with previously selected packages`.
298298
You may need to modify the version requirements to make them consistent.
299299

300-
- If there are multiple versions of dependencies in the project, when using
301-
[`direct-minimal-versions`], the minimum version requirements cannot be met,
300+
- If there are multiple versions of dependencies in the project, when using
301+
[`direct-minimal-versions`], the minimum version requirements cannot be met,
302302
which will cause conflicts. You may need to modify version requirements of your
303303
direct dependencies to meet the minimum SemVer version accordingly.
304304

305-
- If the dependent crate does not have the features you choose, it will also
306-
cause conflicts. At this time, you need to check the dependent version and its
305+
- If the dependent crate does not have the features you choose, it will also
306+
cause conflicts. At this time, you need to check the dependent version and its
307307
features.
308308

309-
- Conflicts may occur when merging branches or PRs, if there are non-trivial
310-
conflicts, you can reset all "yours" changes, fix all other conflicts in the
311-
branch, and then run some cargo command (like `cargo tree` or `cargo check`),
312-
which should re-update the lockfile with your own local changes. If you previously
313-
ran some `cargo update` commands in your branch, you can re-run them that this
314-
time. The community has been looking to resolve merge conflicts with `Cargo.lock`
309+
- Conflicts may occur when merging branches or PRs, if there are non-trivial
310+
conflicts, you can reset all "yours" changes, fix all other conflicts in the
311+
branch, and then run some cargo command (like `cargo tree` or `cargo check`),
312+
which should re-update the lockfile with your own local changes. If you previously
313+
ran some `cargo update` commands in your branch, you can re-run them that this
314+
time. The community has been looking to resolve merge conflicts with `Cargo.lock`
315315
and `Cargo.toml` using a [custom merge tool].
316316

317317

src/doc/src/reference/build-script-examples.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn main() {
7171
}
7272
"
7373
).unwrap();
74-
println!("cargo:rerun-if-changed=build.rs");
74+
println!("cargo::rerun-if-changed=build.rs");
7575
}
7676
```
7777

@@ -173,9 +173,9 @@ fn main() {
173173
.current_dir(&Path::new(&out_dir))
174174
.status().unwrap();
175175
176-
println!("cargo:rustc-link-search=native={}", out_dir);
177-
println!("cargo:rustc-link-lib=static=hello");
178-
println!("cargo:rerun-if-changed=src/hello.c");
176+
println!("cargo::rustc-link-search=native={}", out_dir);
177+
println!("cargo::rustc-link-lib=static=hello");
178+
println!("cargo::rerun-if-changed=src/hello.c");
179179
}
180180
```
181181

@@ -214,7 +214,7 @@ fn main() {
214214
cc::Build::new()
215215
.file("src/hello.c")
216216
.compile("hello");
217-
println!("cargo:rerun-if-changed=src/hello.c");
217+
println!("cargo::rerun-if-changed=src/hello.c");
218218
}
219219
```
220220

@@ -316,7 +316,7 @@ The build script is fairly simple:
316316
317317
fn main() {
318318
pkg_config::Config::new().probe("zlib").unwrap();
319-
println!("cargo:rerun-if-changed=build.rs");
319+
println!("cargo::rerun-if-changed=build.rs");
320320
}
321321
```
322322

@@ -344,9 +344,9 @@ Run `cargo build -vv` to see the output from the build script. On a system
344344
with `libz` already installed, it may look something like this:
345345

346346
```text
347-
[libz-sys 0.1.0] cargo:rustc-link-search=native=/usr/lib
348-
[libz-sys 0.1.0] cargo:rustc-link-lib=z
349-
[libz-sys 0.1.0] cargo:rerun-if-changed=build.rs
347+
[libz-sys 0.1.0] cargo::rustc-link-search=native=/usr/lib
348+
[libz-sys 0.1.0] cargo::rustc-link-lib=z
349+
[libz-sys 0.1.0] cargo::rerun-if-changed=build.rs
350350
```
351351

352352
Nice! `pkg-config` did all the work of finding the library and telling Cargo
@@ -408,7 +408,7 @@ fn main() {
408408
cfg.include(include);
409409
}
410410
cfg.compile("zuser");
411-
println!("cargo:rerun-if-changed=src/zuser.c");
411+
println!("cargo::rerun-if-changed=src/zuser.c");
412412
}
413413
```
414414

@@ -440,7 +440,7 @@ script looks something [like
440440
this](https://github.com/sfackler/rust-openssl/blob/dc72a8e2c429e46c275e528b61a733a66e7877fc/openssl-sys/build/main.rs#L216):
441441

442442
```rust,ignore
443-
println!("cargo:version_number={:x}", openssl_version);
443+
println!("cargo::version_number={:x}", openssl_version);
444444
```
445445

446446
This instruction causes the `DEP_OPENSSL_VERSION_NUMBER` environment variable
@@ -460,19 +460,19 @@ if let Ok(version) = env::var("DEP_OPENSSL_VERSION_NUMBER") {
460460
let version = u64::from_str_radix(&version, 16).unwrap();
461461
462462
if version >= 0x1_00_01_00_0 {
463-
println!("cargo:rustc-cfg=ossl101");
463+
println!("cargo::rustc-cfg=ossl101");
464464
}
465465
if version >= 0x1_00_02_00_0 {
466-
println!("cargo:rustc-cfg=ossl102");
466+
println!("cargo::rustc-cfg=ossl102");
467467
}
468468
if version >= 0x1_01_00_00_0 {
469-
println!("cargo:rustc-cfg=ossl110");
469+
println!("cargo::rustc-cfg=ossl110");
470470
}
471471
if version >= 0x1_01_00_07_0 {
472-
println!("cargo:rustc-cfg=ossl110g");
472+
println!("cargo::rustc-cfg=ossl110g");
473473
}
474474
if version >= 0x1_01_01_00_0 {
475-
println!("cargo:rustc-cfg=ossl111");
475+
println!("cargo::rustc-cfg=ossl111");
476476
}
477477
}
478478
```

0 commit comments

Comments
 (0)