Skip to content

Commit 9864b0b

Browse files
authored
Merge pull request #2026 from kinnison/kinnison/add-components-and-targets
Support installation with additional components and targets
2 parents 70f8357 + 75c0491 commit 9864b0b

14 files changed

+311
-79
lines changed

CONTRIBUTING.md

+22-11
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ affecting any existing installation. Remember to keep those two environment vari
2020
set when running your compiled `rustup-init` or the toolchains it installs, but _unset_
2121
when rebuilding `rustup` itself.
2222

23-
We use `rustfmt` to keep our codebase consistently formatted. Please ensure that
23+
We use `rustfmt` to keep our codebase consistently formatted. Please ensure that
2424
you have correctly formatted your code (most editors will do this automatically
2525
when saving) or it may not pass the CI tests.
2626

@@ -46,11 +46,11 @@ The first part is always the binary name as per `clap`'s normal operation. The
4646
version number is a combination of the most recent tag in the git repo, and the
4747
number of commits since that tag. The parenthesised information is, naturally,
4848
the SHA of the most recent commit and the date of that commit. If the indication
49-
of a dirty tree is present, the number of changes is indicated. This combines
49+
of a dirty tree is present, the number of changes is indicated. This combines
5050
adds, deletes, modifies, and unknown entries.
5151

5252
You can request further information of a `rustup` binary with the
53-
`rustup dump-testament` hidden command. It produces output of the form:
53+
`rustup dump-testament` hidden command. It produces output of the form:
5454

5555
```shell
5656
$ rustup dump-testament
@@ -64,25 +64,25 @@ Modified: CONTRIBUTING.md
6464
This can be handy when you are testing development versions on your PC
6565
and cannot remember exactly which version you had installed, or if you have given
6666
a development copy (or instruction to build such) to a user, and wish to have them
67-
confirm *exactly* what they are using.
67+
confirm _exactly_ what they are using.
6868

6969
Finally, we tell `git-testament` that we trust the `stable` branch to carry
70-
releases. If the build is being performed when not on the `stable` branch, and
70+
releases. If the build is being performed when not on the `stable` branch, and
7171
the tag and `CARGO_PKG_VERSION` differ, then the short version string will include
7272
both, in the form `rustup-init 1.18.3 :: 1.18.2+99 (a54051502 2019-05-26)` which
7373
indicates the crate version before the rest of the commit.
7474
On the other hand, if the build was on the `stable` branch then regardless
7575
of the tag information, providing the commit was clean, the version is
76-
always replaced by the crate version. The `dump-testament` hidden command can
76+
always replaced by the crate version. The `dump-testament` hidden command can
7777
reveal the truth however.
7878

7979
## Making a release
8080

8181
Before making a release, ensure that `rustup-init.sh` is behaving correctly,
8282
and that you're satisfied that nothing in the ecosystem is breaking because
83-
of the update. A useful set of things to check includes verifying that
83+
of the update. A useful set of things to check includes verifying that
8484
real-world toolchains install okay, and that `rls-vscode` isn't broken by
85-
the release. While it's not our responsibility if they depend on non-stable
85+
the release. While it's not our responsibility if they depend on non-stable
8686
APIs, we should behave well if we can.
8787

8888
Producing the final release artifacts is a bit involved because of the way
@@ -107,10 +107,10 @@ Rustup is distributed. The steps for a release are:
107107
anything egregious in which case abort the change and roll back.
108108
8. Once the official release has happened, prepare and push a tag
109109
of that commit, and also push the content to master
110-
* `git tag -as $VER_NUM -m $VER_NUM` (optionally without -s if not GPG
110+
- `git tag -as $VER_NUM -m $VER_NUM` (optionally without -s if not GPG
111111
signing the tag)
112-
* `git push origin HEAD:master`
113-
* `git push origin $VER_NUM`
112+
- `git push origin HEAD:master`
113+
- `git push origin $VER_NUM`
114114

115115
## Developer tips and tricks
116116

@@ -125,6 +125,17 @@ run.
125125
$ RUSTUP_FORCE_ARG0=rustup cargo run -- uninstall nightly
126126
```
127127

128+
### `RUSTUP_BACKTRACK_LIMIT`
129+
130+
If it's necessary to alter the backtracking limit from the default of half
131+
a release cycle for some reason, you can set the `RUSTUP_BACKTRACK_LIMIT`
132+
environment variable. If this is unparseable as an `i32` or if it's absent
133+
then the default of 21 days (half a cycle) is used. If it parses and is less
134+
than 1, it is clamped to 1 at minimum.
135+
136+
This is not meant for use by users, but can be suggested in diagnosing an issue
137+
should one arise with the backtrack limits.
138+
128139
### `RUSTUP_BACKTRACE`
129140

130141
By default while running tests, we unset some environment variables that will

rustup-init.sh

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ OPTIONS:
3131
--default-toolchain <default-toolchain> Choose a default toolchain to install
3232
--default-toolchain none Do not install any toolchains
3333
--profile [minimal|default|complete] Choose a profile
34+
-c, --component <components>... Component name to also install
35+
-t, --target <targets>... Target name to also install
3436
EOF
3537
}
3638

src/cli/rustup_mode.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,22 @@ pub fn cli() -> App<'static, 'static> {
256256
.help("Don't perform self update when running the `rustup toolchain install` command")
257257
.long("no-self-update")
258258
.takes_value(false)
259+
)
260+
.arg(
261+
Arg::with_name("components")
262+
.help("Add specific components on installation")
263+
.long("component")
264+
.short("c")
265+
.takes_value(true)
266+
.multiple(true)
267+
)
268+
.arg(
269+
Arg::with_name("targets")
270+
.help("Add specific targets on installation")
271+
.long("target")
272+
.short("t")
273+
.takes_value(true)
274+
.multiple(true)
259275
),
260276
)
261277
.subcommand(
@@ -741,7 +757,15 @@ fn update(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
741757
let toolchain = cfg.get_toolchain(name, false)?;
742758

743759
let status = if !toolchain.is_custom() {
744-
Some(toolchain.install_from_dist(m.is_present("force"))?)
760+
let components: Vec<_> = m
761+
.values_of("components")
762+
.map(|v| v.collect())
763+
.unwrap_or_else(Vec::new);
764+
let targets: Vec<_> = m
765+
.values_of("targets")
766+
.map(|v| v.collect())
767+
.unwrap_or_else(Vec::new);
768+
Some(toolchain.install_from_dist(m.is_present("force"), &components, &targets)?)
745769
} else if !toolchain.exists() {
746770
return Err(ErrorKind::InvalidToolchainName(toolchain.name().to_string()).into());
747771
} else {

src/cli/self_update.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ use std::fs;
4545
use std::path::{Component, Path, PathBuf};
4646
use std::process::{self, Command};
4747

48-
pub struct InstallOpts {
48+
pub struct InstallOpts<'a> {
4949
pub default_host_triple: String,
5050
pub default_toolchain: String,
5151
pub profile: String,
5252
pub no_modify_path: bool,
53+
pub components: &'a [&'a str],
54+
pub targets: &'a [&'a str],
5355
}
5456

5557
#[cfg(feature = "no-self-update")]
@@ -283,6 +285,8 @@ pub fn install(no_prompt: bool, verbose: bool, quiet: bool, mut opts: InstallOpt
283285
&opts.default_toolchain,
284286
&opts.profile,
285287
&opts.default_host_triple,
288+
opts.components,
289+
opts.targets,
286290
verbose,
287291
quiet,
288292
)?;
@@ -737,6 +741,8 @@ fn maybe_install_rust(
737741
toolchain_str: &str,
738742
profile_str: &str,
739743
default_host_triple: &str,
744+
components: &[&str],
745+
targets: &[&str],
740746
verbose: bool,
741747
quiet: bool,
742748
) -> Result<()> {
@@ -754,7 +760,7 @@ fn maybe_install_rust(
754760
// Set host triple first as it will affect resolution of toolchain_str
755761
cfg.set_default_host_triple(default_host_triple)?;
756762
let toolchain = cfg.get_toolchain(toolchain_str, false)?;
757-
let status = toolchain.install_from_dist(false)?;
763+
let status = toolchain.install_from_dist(false, components, targets)?;
758764
cfg.set_default(toolchain_str)?;
759765
println!();
760766
common::show_channel_update(&cfg, toolchain_str, Ok(status))?;

src/cli/setup_mode.rs

+28
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ pub fn main() -> Result<()> {
6161
.possible_values(Profile::names())
6262
.default_value(Profile::default_name()),
6363
)
64+
.arg(
65+
Arg::with_name("components")
66+
.help("Component name to also install")
67+
.long("component")
68+
.short("c")
69+
.takes_value(true)
70+
.multiple(true),
71+
)
72+
.arg(
73+
Arg::with_name("targets")
74+
.help("Target name to also install")
75+
.long("target")
76+
.short("target")
77+
.takes_value(true)
78+
.multiple(true),
79+
)
6480
.arg(
6581
Arg::with_name("no-modify-path")
6682
.long("no-modify-path")
@@ -81,11 +97,23 @@ pub fn main() -> Result<()> {
8197
.expect("Unreachable: Clap should supply a default");
8298
let no_modify_path = matches.is_present("no-modify-path");
8399

100+
let components: Vec<_> = matches
101+
.values_of("components")
102+
.map(|v| v.collect())
103+
.unwrap_or_else(Vec::new);
104+
105+
let targets: Vec<_> = matches
106+
.values_of("targets")
107+
.map(|v| v.collect())
108+
.unwrap_or_else(Vec::new);
109+
84110
let opts = InstallOpts {
85111
default_host_triple: default_host,
86112
default_toolchain: default_toolchain.to_owned(),
87113
profile: profile.to_owned(),
88114
no_modify_path,
115+
components: &components,
116+
targets: &targets,
89117
};
90118

91119
self_update::install(no_prompt, verbose, quiet, opts)?;

src/config.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl Cfg {
304304
ErrorKind::OverrideToolchainNotInstalled(name.to_string())
305305
})
306306
} else {
307-
toolchain.install_from_dist(false)?;
307+
toolchain.install_from_dist(false, &[], &[])?;
308308
Ok(Some((toolchain, reason)))
309309
}
310310
}
@@ -413,7 +413,7 @@ impl Cfg {
413413
// Update toolchains and collect the results
414414
let channels = channels.map(|(n, t)| {
415415
let t = t.and_then(|t| {
416-
let t = t.install_from_dist(force_update);
416+
let t = t.install_from_dist(force_update, &[], &[]);
417417
if let Err(ref e) = t {
418418
(self.notify_handler)(Notification::NonFatalError(e));
419419
}
@@ -465,7 +465,7 @@ impl Cfg {
465465
) -> Result<Command> {
466466
let toolchain = self.get_toolchain(toolchain, false)?;
467467
if install_if_missing && !toolchain.exists() {
468-
toolchain.install_from_dist(false)?;
468+
toolchain.install_from_dist(false, &[], &[])?;
469469
}
470470

471471
if let Some(cmd) = self.maybe_do_cargo_fallback(&toolchain, binary)? {

0 commit comments

Comments
 (0)