Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 1 addition & 50 deletions blacksmith/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
mod channel;

use std::{
collections::BTreeMap,
fmt::Write,
io::{BufRead, BufReader},
time::SystemTime,
};
use std::{collections::BTreeMap, fmt::Write, time::SystemTime};

use mdbook::{
book::{Book, BookItem},
Expand All @@ -16,8 +11,6 @@ use mdbook::{
const CHANNELS: &[&str] = &["stable", "beta", "nightly"];
const CHANNEL_URL_PREFIX: &str = "https://static.rust-lang.org/dist/channel-rust-";
const MANIFESTS_URL: &str = "https://static.rust-lang.org/manifests.txt";
const RUSTUP_URLS: &str =
"https://raw.githubusercontent.com/rust-lang/rustup.rs/stable/ci/cloudfront-invalidation.txt";

/// A representation of a rust target platform. `stable`, `beta`, and `nightly`
/// represent whether the platform is available on that channel. `stable` also
Expand All @@ -43,7 +36,6 @@ impl Default for Platform {
#[derive(Default, serde::Serialize, serde::Deserialize)]
pub struct Blacksmith {
last_update: Option<u64>,
rustup: Vec<String>,
stable_version: Option<String>,
platforms: BTreeMap<String, Platform>,
#[serde(default)]
Expand All @@ -70,17 +62,6 @@ impl Blacksmith {
pub fn init() -> Result<Self, Box<dyn std::error::Error>> {
let mut blacksmith = Self::new();

let rustup_url_regex =
regex::Regex::new(r"^rustup/dist/([^/]+)/rustup-init(?:\.exe)?$").unwrap();
for line in BufReader::new(reqwest::blocking::get(RUSTUP_URLS)?).lines() {
if let Some(m) = rustup_url_regex.captures(&(line?)) {
blacksmith
.rustup
.push(m.get(1).unwrap().as_str().to_string());
}
}
log::info!("Found {} targets for rustup", blacksmith.rustup.len());

for &channel_name in CHANNELS {
let channel_url = format!("{}{}.toml", CHANNEL_URL_PREFIX, channel_name);
let content = reqwest::blocking::get(&channel_url)?.text()?;
Expand Down Expand Up @@ -264,34 +245,6 @@ impl Blacksmith {
Ok(blacksmith)
}

/// Creates a list of hyperlinks to `rustup-init` based on what targets
/// rustup provided using the following URL schema. Where `target` is the
/// platforms target tuple (`x86_64-apple-darwin`) and `suffix` is a target
/// specific file extension.
/// ```url
/// https://static.rust-lang.org/rustup/dist/{target}/rustup-init{suffix}
/// ```
fn generate_rustup_init_list(&self) -> String {
let mut buffer = String::new();

for target in &self.rustup {
let suffix = if target.contains("windows") {
".exe"
} else {
""
};

writeln!(
buffer,
"- [{target}](https://static.rust-lang.org/rustup/dist/{target}/rustup-init{suffix})",
target = target,
suffix = suffix,
).unwrap();
}

buffer
}

/// Generates a table of links to the standalone installer packages for
/// each platform.
fn generate_standalone_installers_table(&self) -> String {
Expand Down Expand Up @@ -469,7 +422,6 @@ impl Preprocessor for Blacksmith {
}
}

let rustup_init_list = self.generate_rustup_init_list();
let standalone_installers_table = self.generate_standalone_installers_table();
let previous_stable_standalone_installers_tables =
self.generate_previous_stable_standalone_installers_tables();
Expand All @@ -481,7 +433,6 @@ impl Preprocessor for Blacksmith {
// However if the processing time begins to become a bottleneck this
// should change.
for item in &mut book.sections {
recursive_replace(item, "{{#rustup_init_list}}", &rustup_init_list);
recursive_replace(item, "{{#installer_table}}", &standalone_installers_table);
recursive_replace(
item,
Expand Down
33 changes: 8 additions & 25 deletions src/infra/other-installation-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,8 @@ itself. Such targets can be installed with the `rustup target add` command.

<span id="rustup"></span>

The way to install `rustup` differs by platform:

- On Unix, run `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh` in your shell. This
downloads and runs [`rustup-init.sh`], which in turn downloads and runs the
correct version of the `rustup-init` executable for your platform.
- On Windows, download and run [`rustup-init.exe`].

`rustup-init` can be configured interactively, and all options can additionally
be controlled by command-line arguments, which can be passed through the shell
script. Pass `--help` to `rustup-init` as follows to display the arguments
`rustup-init` accepts:

```
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --help
```

If you prefer not to use the shell script, you may directly download
`rustup-init` for the platform of your choice:

<!-- `{{#rustup_init_list}}`, `{{#installer_table}}`, and `{{#source_code_table}}`
are generated at build time. Please refer to the `blacksmith` preprocessor for
what they each specifically generate.
-->

{{#rustup_init_list}}
Please refer to `rustup`'s [Other installation
methods](https://rust-lang.github.io/rustup/installation/other.html).

## Standalone installers

Expand All @@ -83,6 +60,12 @@ what they each specifically generate.

Past releases can be found in [the archive].

<!--
`{{#installer_table}}` and `{{#source_code_table}}`
are generated at build time. Please refer to the `blacksmith` preprocessor for
what they each specifically generate.
-->

{{#installer_table}}

## Source code
Expand Down