Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support installation with additional components and targets #2026

Merged
33 changes: 22 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ affecting any existing installation. Remember to keep those two environment vari
set when running your compiled `rustup-init` or the toolchains it installs, but _unset_
when rebuilding `rustup` itself.

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

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

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

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

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

## Making a release

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

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

## Developer tips and tricks

Expand All @@ -125,6 +125,17 @@ run.
$ RUSTUP_FORCE_ARG0=rustup cargo run -- uninstall nightly
```

### `RUSTUP_BACKTRACK_LIMIT`

If it's necessary to alter the backtracking limit from the default of half
a release cycle for some reason, you can set the `RUSTUP_BACKTRACK_LIMIT`
environment variable. If this is unparseable as an `i32` or if it's absent
then the default of 21 days (half a cycle) is used. If it parses and is less
than 1, it is clamped to 1 at minimum.

This is not meant for use by users, but can be suggested in diagnosing an issue
should one arise with the backtrack limits.

### `RUSTUP_BACKTRACE`

By default while running tests, we unset some environment variables that will
Expand Down
2 changes: 2 additions & 0 deletions rustup-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ OPTIONS:
--default-toolchain <default-toolchain> Choose a default toolchain to install
--default-toolchain none Do not install any toolchains
--profile [minimal|default|complete] Choose a profile
-c, --component <components>... Component name to also install
-t, --target <targets>... Target name to also install
EOF
}

Expand Down
26 changes: 25 additions & 1 deletion src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,22 @@ pub fn cli() -> App<'static, 'static> {
.help("Don't perform self update when running the `rustup toolchain install` command")
.long("no-self-update")
.takes_value(false)
)
.arg(
Arg::with_name("components")
.help("Add specific components on installation")
.long("component")
.short("c")
.takes_value(true)
.multiple(true)
)
.arg(
Arg::with_name("targets")
.help("Add specific targets on installation")
.long("target")
.short("t")
.takes_value(true)
.multiple(true)
),
)
.subcommand(
Expand Down Expand Up @@ -741,7 +757,15 @@ fn update(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
let toolchain = cfg.get_toolchain(name, false)?;

let status = if !toolchain.is_custom() {
Some(toolchain.install_from_dist(m.is_present("force"))?)
let components: Vec<_> = m
.values_of("components")
.map(|v| v.collect())
.unwrap_or_else(Vec::new);
let targets: Vec<_> = m
.values_of("targets")
.map(|v| v.collect())
.unwrap_or_else(Vec::new);
Some(toolchain.install_from_dist(m.is_present("force"), &components, &targets)?)
} else if !toolchain.exists() {
return Err(ErrorKind::InvalidToolchainName(toolchain.name().to_string()).into());
} else {
Expand Down
10 changes: 8 additions & 2 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ use std::fs;
use std::path::{Component, Path, PathBuf};
use std::process::{self, Command};

pub struct InstallOpts {
pub struct InstallOpts<'a> {
pub default_host_triple: String,
pub default_toolchain: String,
pub profile: String,
pub no_modify_path: bool,
pub components: &'a [&'a str],
pub targets: &'a [&'a str],
}

#[cfg(feature = "no-self-update")]
Expand Down Expand Up @@ -283,6 +285,8 @@ pub fn install(no_prompt: bool, verbose: bool, quiet: bool, mut opts: InstallOpt
&opts.default_toolchain,
&opts.profile,
&opts.default_host_triple,
opts.components,
opts.targets,
verbose,
quiet,
)?;
Expand Down Expand Up @@ -737,6 +741,8 @@ fn maybe_install_rust(
toolchain_str: &str,
profile_str: &str,
default_host_triple: &str,
components: &[&str],
targets: &[&str],
verbose: bool,
quiet: bool,
) -> Result<()> {
Expand All @@ -754,7 +760,7 @@ fn maybe_install_rust(
// Set host triple first as it will affect resolution of toolchain_str
cfg.set_default_host_triple(default_host_triple)?;
let toolchain = cfg.get_toolchain(toolchain_str, false)?;
let status = toolchain.install_from_dist(false)?;
let status = toolchain.install_from_dist(false, components, targets)?;
cfg.set_default(toolchain_str)?;
println!();
common::show_channel_update(&cfg, toolchain_str, Ok(status))?;
Expand Down
28 changes: 28 additions & 0 deletions src/cli/setup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ pub fn main() -> Result<()> {
.possible_values(Profile::names())
.default_value(Profile::default_name()),
)
.arg(
Arg::with_name("components")
.help("Component name to also install")
.long("component")
.short("c")
.takes_value(true)
.multiple(true),
)
.arg(
Arg::with_name("targets")
.help("Target name to also install")
.long("target")
.short("target")
.takes_value(true)
.multiple(true),
)
.arg(
Arg::with_name("no-modify-path")
.long("no-modify-path")
Expand All @@ -81,11 +97,23 @@ pub fn main() -> Result<()> {
.expect("Unreachable: Clap should supply a default");
let no_modify_path = matches.is_present("no-modify-path");

let components: Vec<_> = matches
.values_of("components")
.map(|v| v.collect())
.unwrap_or_else(Vec::new);

let targets: Vec<_> = matches
.values_of("targets")
.map(|v| v.collect())
.unwrap_or_else(Vec::new);

let opts = InstallOpts {
default_host_triple: default_host,
default_toolchain: default_toolchain.to_owned(),
profile: profile.to_owned(),
no_modify_path,
components: &components,
targets: &targets,
};

self_update::install(no_prompt, verbose, quiet, opts)?;
Expand Down
6 changes: 3 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl Cfg {
ErrorKind::OverrideToolchainNotInstalled(name.to_string())
})
} else {
toolchain.install_from_dist(false)?;
toolchain.install_from_dist(false, &[], &[])?;
Ok(Some((toolchain, reason)))
}
}
Expand Down Expand Up @@ -413,7 +413,7 @@ impl Cfg {
// Update toolchains and collect the results
let channels = channels.map(|(n, t)| {
let t = t.and_then(|t| {
let t = t.install_from_dist(force_update);
let t = t.install_from_dist(force_update, &[], &[]);
if let Err(ref e) = t {
(self.notify_handler)(Notification::NonFatalError(e));
}
Expand Down Expand Up @@ -465,7 +465,7 @@ impl Cfg {
) -> Result<Command> {
let toolchain = self.get_toolchain(toolchain, false)?;
if install_if_missing && !toolchain.exists() {
toolchain.install_from_dist(false)?;
toolchain.install_from_dist(false, &[], &[])?;
}

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