Skip to content

Commit 96b0352

Browse files
authored
Merge pull request #53 from jyn514/rustdoc-binary
Allow running arbitrary binaries through rustup
2 parents 283aa76 + e8c974d commit 96b0352

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55

66
## Unreleased
77

8+
### Added
9+
10+
- New method `Toolchain::rustup_binary` to allow running arbitrary binaries managed by rustup. Before, only `rustc` and `cargo` could be run.
11+
812
## [0.12.0] - 2021-01-28
913

1014
### Added
1115

1216
- New variant `PrepareError::MissingDependencies`, returned during the prepare
1317
step when a dependency does not exist.
14-
1518
### Changed
1619

1720
- Path dependencies are no longer removed from `Cargo.toml` during the prepare

src/toolchain.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,7 @@ impl Toolchain {
400400
/// # }
401401
/// ```
402402
pub fn cargo(&self) -> impl Runnable + '_ {
403-
RustupProxy {
404-
toolchain: self,
405-
name: "cargo",
406-
}
403+
self.rustup_binary("cargo")
407404
}
408405

409406
/// Return a runnable object configured to run `rustc` with this toolchain. This method is
@@ -424,9 +421,29 @@ impl Toolchain {
424421
/// # }
425422
/// ```
426423
pub fn rustc(&self) -> impl Runnable + '_ {
424+
self.rustup_binary("rustc")
425+
}
426+
427+
/// Return a runnable object configured to run `name` with this toolchain. This method is
428+
/// intended to be used with [`rustwide::cmd::Command`](cmd/struct.Command.html).
429+
///
430+
/// # Example
431+
///
432+
/// ```no_run
433+
/// # use rustwide::{WorkspaceBuilder, Toolchain, cmd::Command};
434+
/// # use std::error::Error;
435+
/// # fn main() -> Result<(), Box<dyn Error>> {
436+
/// # let workspace = WorkspaceBuilder::new("".as_ref(), "").init()?;
437+
/// let toolchain = Toolchain::dist("beta");
438+
/// Command::new(&workspace, toolchain.rustup_binary("rustdoc"))
439+
/// .args(&["hello.rs"])
440+
/// .run()?;
441+
/// # Ok(())
442+
/// # }
443+
pub fn rustup_binary(&self, name: &'static str) -> impl Runnable + '_ {
427444
RustupProxy {
428445
toolchain: self,
429-
name: "rustc",
446+
name,
430447
}
431448
}
432449

0 commit comments

Comments
 (0)