You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/3502-cargo-script.md
+16-3Lines changed: 16 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -370,9 +370,12 @@ fn main() {
370
370
println!("Hello world");
371
371
}
372
372
```
373
-
- Like with `cargo install`, `.cargo/config.toml` will be read based on the
374
-
scripts location rather than the current-dir.
375
-
- And like [`cargo install`](https://github.com/rust-lang/cargo/issues/7312), the current-dir `rust-toolchain.toml` is respected
373
+
- In contrast to `cargo run --manifest-path <file>.rs`, `.cargo/config.toml` will not be loaded from the current-dir will instead be loaded from `CARGO_HOME`.
374
+
- This is inspired by `cargo install` though its logic is different:
375
+
-`cargo install --path <path>` will load config from `<path>`
376
+
- All other `cargo install`s will load config from `CARGO_HOME`
377
+
- Unlike `cargo install`, we expect people to run single-file packages in unsafe locations, like temp directories or download directories, and don't want to pick up less trustworthy configs
378
+
- Like all cargo commands, including `cargo install`, the current-dir `rust-toolchain.toml` is respected ([cargo#7312](https://github.com/rust-lang/cargo/issues/7312))
376
379
-`--release` is not passed in because the primary use case is for exploratory
377
380
programming, so the emphasis will be on build-time performance and debugging,
378
381
rather than runtime performance
@@ -1064,6 +1067,16 @@ This could serve as an alternative to
1064
1067
[`cargo xtask`](https://github.com/matklad/cargo-xtask) with scripts sharing
1065
1068
the lockfile and `target/` directory.
1066
1069
1070
+
## Script-relative config
1071
+
1072
+
As `.cargo/config.toml` is loaded from `CARGO_HOME`, there isn't a way to ensure that we load the config for a script in a repo (e.g. an xtask).
1073
+
This could become more of prevalent of an issue when workspaces are supported.
1074
+
1075
+
Options
1076
+
- A way to opt-in saying that the parent directories are assumed to be safe directories (see also [RFC #3279](https://github.com/rust-lang/rfcs/pull/3279)).
1077
+
- Key off of workspace membership (as then it won't likely be a temp file)
1078
+
- This has a chicken-and-egg problem as we need to load config before we load manifests
1079
+
1067
1080
## Scaling up
1068
1081
1069
1082
We provide a workflow for turning a single-file package into a multi-file
0 commit comments