Commit f0a4ee0
committed
Auto merge of #11705 - t-rapp:env-cargo-bin-name, r=epage
Set CARGO_BIN_NAME environment variable also for binary examples
### What does this PR try to resolve?
The existing CARGO_BIN_NAME environment variable is useful when building command-line programs. It lets the command know its binary name, e.g. for printing out simple usage instructions. This PR extends the CARGO_BIN_NAME environment variable to be set when building binary example targets, additional to "normal" binary targets.
Fixes #11689.
### How should we test and review this PR?
Create a new binary project with `cargo new hello-env`. Add a new file "examples/foo-bar.rs" with the following lines:
```
fn main() {
let program = env!("CARGO_BIN_NAME");
println!("{program}");
}
```
Building and running the example with `cargo run --example foo-bar` should print a line with the string "foo-bar".
Note that this PR extends the existing testcase for the CARGO_BIN_NAME environment variable with an example target.File tree
3 files changed
+26
-2
lines changed- src
- cargo/core/compiler
- doc/src/reference
- tests/testsuite
3 files changed
+26
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
375 | | - | |
| 375 | + | |
376 | 376 | | |
377 | 377 | | |
378 | 378 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
235 | | - | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
236 | 238 | | |
237 | 239 | | |
238 | 240 | | |
| |||
256 | 258 | | |
257 | 259 | | |
258 | 260 | | |
| 261 | + | |
| 262 | + | |
259 | 263 | | |
260 | 264 | | |
261 | 265 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1466 | 1466 | | |
1467 | 1467 | | |
1468 | 1468 | | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
1469 | 1486 | | |
1470 | 1487 | | |
1471 | 1488 | | |
| |||
1503 | 1520 | | |
1504 | 1521 | | |
1505 | 1522 | | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
1506 | 1526 | | |
1507 | 1527 | | |
1508 | 1528 | | |
| |||
0 commit comments