Skip to content

Commit

Permalink
Each pavexc version will manage its own Rust toolchain, via rustup. P…
Browse files Browse the repository at this point in the history
…avex will delegate that part of the setup to pavexc, rather than doing it directly
  • Loading branch information
LukeMathWalker committed Aug 14, 2024
1 parent 2452eef commit 6f814db
Show file tree
Hide file tree
Showing 21 changed files with 525 additions and 251 deletions.
178 changes: 98 additions & 80 deletions libs/Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion libs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace]
members = [
"./pavex*",
"generate_from_path",
"generate_from_path", "pavex_cli_deps",
"persist_if_changed",
"px_workspace_hack",
]
Expand Down
1 change: 1 addition & 0 deletions libs/pavex_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ vergen = { workspace = true }

[dependencies]
pavexc_cli_client = { path = "../pavexc_cli_client", version = "0.1.46" }
pavex_cli_deps = { path = "../pavex_cli_deps", version = "0.1.46" }
clap = { workspace = true, features = ["derive", "env"] }
pavex_miette = { path = "../pavex_miette", version = "0.1.46" }
miette = { workspace = true }
Expand Down
126 changes: 0 additions & 126 deletions libs/pavex_cli/src/dependencies/installers.rs

This file was deleted.

2 changes: 0 additions & 2 deletions libs/pavex_cli/src/dependencies/mod.rs

This file was deleted.

1 change: 0 additions & 1 deletion libs/pavex_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pub mod activation;
pub mod cargo_install;
pub mod cli_kind;
pub mod command;
pub mod dependencies;
pub mod env;
pub mod locator;
pub mod package_graph;
Expand Down
20 changes: 14 additions & 6 deletions libs/pavex_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ use pavex_cli::activation::{
use pavex_cli::cargo_install::{cargo_install, GitSourceRevision, Source};
use pavex_cli::cli_kind::CliKind;
use pavex_cli::command::{Cli, Color, Command, SelfCommands};
use pavex_cli::dependencies::installers;
use pavex_cli::dependencies::installers::{CargoPx, NightlyToolchain, RustdocJson, Rustup};
use pavex_cli::locator::PavexLocator;
use pavex_cli::package_graph::compute_package_graph;
use pavex_cli::pavexc::{get_or_install_from_graph, get_or_install_from_version};
Expand All @@ -24,6 +22,9 @@ use pavex_cli::state::State;
use pavex_cli::user_input::{confirm, mandatory_question};
use pavex_cli::utils;
use pavex_cli::version::latest_released_version;
use pavex_cli_deps::{
verify_installation, CargoPx, IfAutoinstallable, RustdocJson, Rustup, RustupToolchain,
};
use pavexc_cli_client::commands::generate::{BlueprintArgument, GenerateError};
use pavexc_cli_client::commands::new::NewError;
use pavexc_cli_client::commands::new::TemplateName;
Expand Down Expand Up @@ -278,10 +279,17 @@ fn setup(
locator: &PavexLocator,
key_set: &JwkSet,
) -> Result<(), anyhow::Error> {
installers::verify_installation::<Rustup>(shell)?;
installers::verify_installation::<NightlyToolchain>(shell)?;
installers::verify_installation::<RustdocJson>(shell)?;
installers::verify_installation::<CargoPx>(shell)?;
let options = IfAutoinstallable::PromptForConfirmation;
verify_installation(shell, Rustup, options)?;
let rustup_toolchain = RustupToolchain {
name: "nightly".into(),
};
verify_installation(shell, rustup_toolchain, options)?;
let rust_docs_json = RustdocJson {
toolchain: "nightly".into(),
};
verify_installation(shell, rust_docs_json, options)?;
verify_installation(shell, CargoPx, options)?;

let _ = shell.status("Checking", "if Pavex has been activated");
let must_activate = match get_activation_key(locator, shell) {
Expand Down
3 changes: 3 additions & 0 deletions libs/pavex_cli/src/pavexc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::path::{Path, PathBuf};

mod install;
mod location;
mod setup;
mod version;

static PAVEX_GITHUB_URL: &str = "https://github.com/LukeMathWalker/pavex";
Expand Down Expand Up @@ -116,6 +117,8 @@ fn _install(
install::install(shell, pavexc_cli_path, version, install_source)?;
#[cfg(unix)]
executable::make_executable(pavexc_cli_path)?;
setup::pavexc_setup(pavexc_cli_path)
.context("Failed to install the nightly Rust toolchain required by `pavexc`")?;
Ok(())
}

Expand Down
19 changes: 19 additions & 0 deletions libs/pavex_cli/src/pavexc/setup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::{path::Path, process::Stdio};

use anyhow::Context;

/// Ensure that the required dependencies are installed for this version of `pavexc`.
pub(super) fn pavexc_setup(cli_path: &Path) -> Result<(), anyhow::Error> {
let mut cmd = std::process::Command::new(cli_path);
cmd.arg("self").arg("setup");
let cmd_debug = format!("{:?}", &cmd);
let output = cmd
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.with_context(|| format!("`{cmd_debug}` failed"))?;
if !output.status.success() {
anyhow::bail!("`{cmd_debug}` failed");
}
Ok(())
}
11 changes: 11 additions & 0 deletions libs/pavex_cli_deps/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "pavex_cli_deps"
edition.workspace = true
repository.workspace = true
homepage.workspace = true
license.workspace = true
version.workspace = true

[dependencies]
anyhow = { workspace = true }
cargo-like-utils = { workspace = true }
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use anyhow::Context;
use std::process::Stdio;

use crate::RustupToolchain;

/// Check if `rustup` is installed and available in the system's $PATH.
pub fn is_rustup_installed() -> Result<(), anyhow::Error> {
let mut cmd = std::process::Command::new("rustup");
Expand All @@ -15,12 +17,12 @@ pub fn is_rustup_installed() -> Result<(), anyhow::Error> {
Ok(())
}

/// Check if the nightly toolchain is installed via `rustup`.
pub fn is_nightly_installed() -> Result<(), anyhow::Error> {
/// Check if a Rust toolchain is installed via `rustup`.
pub fn is_rustup_toolchain_installed(toolchain: &RustupToolchain) -> Result<(), anyhow::Error> {
let mut cmd = std::process::Command::new("rustup");
cmd.arg("which")
.arg("--toolchain")
.arg("nightly")
.arg(&toolchain.name)
.arg("cargo");
let cmd_debug = format!("{:?}", &cmd);
let output = cmd
Expand All @@ -32,10 +34,10 @@ pub fn is_nightly_installed() -> Result<(), anyhow::Error> {
Ok(())
}

/// Install the nightly toolchain via `rustup`.
pub fn install_nightly() -> Result<(), anyhow::Error> {
/// Install a Rust toolchain via `rustup`.
pub fn install_rustup_toolchain(toolchain: &RustupToolchain) -> Result<(), anyhow::Error> {
let mut cmd = std::process::Command::new("rustup");
cmd.arg("toolchain").arg("install").arg("nightly");
cmd.arg("toolchain").arg("install").arg(&toolchain.name);
let cmd_debug = format!("{:?}", &cmd);
let output = cmd
.stdout(Stdio::inherit())
Expand All @@ -48,14 +50,14 @@ pub fn install_nightly() -> Result<(), anyhow::Error> {
Ok(())
}

/// Check if the nightly toolchain is installed via `rustup`.
pub fn is_rustdoc_json_installed() -> Result<(), anyhow::Error> {
/// Check if the `rust-docs-json` component is installed for a certain Rust toolchain.
pub fn is_rustdoc_json_installed(toolchain_name: &str) -> Result<(), anyhow::Error> {
let mut cmd = std::process::Command::new("rustup");
cmd.arg("component")
.arg("list")
.arg("--installed")
.arg("--toolchain")
.arg("nightly");
.arg(toolchain_name);
let cmd_debug = format!("{:?}", &cmd);
let output = cmd
.output()
Expand All @@ -72,19 +74,20 @@ pub fn is_rustdoc_json_installed() -> Result<(), anyhow::Error> {
Ok(())
} else {
Err(anyhow::anyhow!(
"`rust-docs-json` component is not installed for the nightly toolchain"
"`rust-docs-json` component is not installed for the `{}` toolchain",
toolchain_name
))
}
}

/// Install the `rust-docs-json` component for the nightly toolchain via `rustup`.
pub fn install_rustdoc_json() -> Result<(), anyhow::Error> {
/// Install the `rust-docs-json` component for a Rust toolchain via `rustup`.
pub fn install_rustdoc_json(toolchain_name: &str) -> Result<(), anyhow::Error> {
let mut cmd = std::process::Command::new("rustup");
cmd.arg("component")
.arg("add")
.arg("rust-docs-json")
.arg("--toolchain")
.arg("nightly");
.arg(toolchain_name);
let cmd_debug = format!("{:?}", &cmd);
let output = cmd
.stdout(Stdio::inherit())
Expand Down
Loading

0 comments on commit 6f814db

Please sign in to comment.