Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Find rustup components installed under a different toolchain #5

@dtolnay

Description

@dtolnay

In dtolnay/cargo-expand#39 I need to look for any rustfmt that may be installed on the system.

Currently what happens is that if the user has rustup component add rustfmt --toolchain stable but is running cargo +nightly expand, then somehow Cargo sets up the subcommand environment such that simply running Command::new("rustfmt") will end up running a shim that only tells you there is no rustfmt installed for the nightly toolchain. The thing is, I don't care whether the rustfmt I run is from the same toolchain as the cargo-expand binary. I would happily run the stable toolchain's rustfmt from the nightly toolchain's cargo-expand if I knew the path to the right binary.

pub fn find_installed_component(name: &str) -> Option<PathBuf>;

Intended usage:

use std::process::Command;

let which_rustfmt = find_installed_component("rustfmt");
match which_rustfmt {
    None => {
        /* there is no rustfmt on any toolchain */
    }
    Some(rustfmt) => {
        Command::new(rustfmt).args(...).spawn();
    }
}

This will be relevant to other Cargo subcommands too, so the implementation should go in a crate rather than directly in cargo-expand.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions