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

v0.3.0: Support for nested crates with binary targets #20

Merged
merged 14 commits into from
Mar 13, 2023
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: [rnag]
custom: ["https://www.buymeacoffee.com/ritviknag"]
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ Possible header types:
- `other_method()`
-->

## v0.3.0 (2023-03-13)

### Features
- Add support for [Cargo crates with binaries] within the `examples/` folder,
each containing their own `Cargo.toml` file. 🎉
- This calls `cargo run --manifest-path <file>` internally, passing `--bin` in the case of multiple [binary targets].

[Cargo crates with binaries]: https://github.com/rnag/cargo-rx/issues/19
[binary targets]: https://doc.rust-lang.org/cargo/reference/cargo-targets.html#binaries

## v0.2.0 (2022-04-25)

### Breaking Changes
Expand Down
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
[<img alt="github" src="https://img.shields.io/badge/github-source-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/rnag/cargo-rx)
[<img alt="crates.io" src="https://img.shields.io/crates/v/cargo-rx.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/cargo-rx)
[<img alt="docs.rs" src="https://img.shields.io/docsrs/cargo-rx/latest?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K" height="20">](https://docs.rs/cargo-rx)
[<img alt="build status" src="https://img.shields.io/github/workflow/status/rnag/cargo-rx/build/main?style=for-the-badge" height="20">](https://github.com/rnag/cargo-rx/actions?query=branch%3Amain)
[<img alt="build status" src="https://img.shields.io/github/actions/workflow/status/rnag/cargo-rx/build.yml?branch=main&style=for-the-badge" height="20">](https://github.com/rnag/cargo-rx/actions/workflows/build.yml?query=branch%3Amain)

**`cargo-rx` is a simple fuzzy finder and *R*unner for *Ex*amples in a [Cargo] project.**

[![rx demo](https://asciinema.org/a/483363.svg)](https://asciinema.org/a/483363)
<a href="https://asciinema.org/a/483363">
<img src="https://asciinema.org/a/483363.svg" alt="rx demo" height="50%" width="72%" />
</a>

[Cargo]: http://doc.crates.io/

This crate provides a single executable: `rx`.
Basically anywhere you would use `cargo run --example` in a
Rust project, try `rx` instead.

**If this project has helped you, please consider making a [donation](https://www.buymeacoffee.com/ritviknag).**

<!-- TODO
## Getting started
-->
Expand All @@ -27,6 +31,7 @@ Rust project, try `rx` instead.
* [Windows](#windows)
* [Features](#features)
* [Contributing](#contributing)
* [Buy me a coffee](#buy-me-a-coffee)
* [License](#license)
* [Authors](#authors)

Expand Down Expand Up @@ -75,11 +80,13 @@ thus, the `fzf` tool serves as a stand-in alternative for now.
* Fuzzy finder, which leverages [skim] to sort and search for *examples* in a Cargo project -- when called with just `rx`.
* Pass arguments after `--` to the selected example.
* Automatically [enables required-features] when running an example.
* Support for nested [crates with binary targets].
* Play back of most recently run example via the `--replay` option.
* Automatically enables `+nightly` toolchain when passed in *unstable options* to `cargo run`, such as `--unit-graph`.

[skim]: https://github.com/lotabout/skim
[enables required-features]: https://github.com/rust-lang/cargo/issues/4663
[crates with binary targets]: https://github.com/rnag/cargo-rx/issues/19

## Contributing

Expand All @@ -91,6 +98,12 @@ Check out the [Contributing][] section in the docs for more info.
[Contributing]: CONTRIBUTING.md
[open an issue]: https://github.com/rnag/cargo-rx/issues

## Buy me a coffee

Liked some of my work? Buy me a coffee (or more likely a beer)

<a href="https://www.buymeacoffee.com/ritviknag" target="_blank"><img src="https://bmc-cdn.nyc3.digitaloceanspaces.com/BMC-button-images/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;"></a>

## License

This project is proudly licensed under the MIT license ([LICENSE](LICENSE)
Expand Down
11 changes: 11 additions & 0 deletions examples/hello-world-axum/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "hello-world-axum"
version = "0.1.0"
edition = "2021"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
axum = { version = "0.6.10" }
tokio = { version = "1.0", features = ["full"] }
17 changes: 17 additions & 0 deletions examples/hello-world-axum/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! This example is a custom use-case where we have Cargo
//! (binary) crates within the `examples/` folder.
//!
//! # Note
//!
//! This is a use case that not even `cargo run --example`
//! currently supports -- in fact, this is not even
//! detected as an example otherwise!
//!
//! # Sample Projects With This Setup
//!
//! * [axum](https://github.com/tokio-rs/axum)
//! * [tract](https://github.com/sonos/tract)
//!
fn main() {
println!("Hello, world!");
}
18 changes: 18 additions & 0 deletions examples/hello-world-multi-bin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "hello-world-multi-bin"
version = "0.1.0"
edition = "2021"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = { version = "1.0", features = ["full"] }

[[bin]]
name = "hello-world-bin1"
path = "src/main.rs"

[[bin]]
name = "hello-world-bin2"
path = "src/alt.rs"
19 changes: 19 additions & 0 deletions examples/hello-world-multi-bin/src/alt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! # Binary Target #2
//!
//! This example is a custom use-case where we have multiple
//! Cargo (binary) crates within the `examples/` folder.
//!
//! # Note
//!
//! This is a use case that not even `cargo run --example`
//! currently supports -- in fact, this is not even
//! detected as an example otherwise!
//!
//! # Sample Projects With This Setup
//!
//! * [axum](https://github.com/tokio-rs/axum)
//! * [tract](https://github.com/sonos/tract)
//!
fn main() {
println!("Hello, from crate `hello-world-multi-bin` -> Bin #2!");
}
19 changes: 19 additions & 0 deletions examples/hello-world-multi-bin/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! # Binary Target #1
//!
//! This example is a custom use-case where we have multiple
//! Cargo (binary) crates within the `examples/` folder.
//!
//! # Note
//!
//! This is a use case that not even `cargo run --example`
//! currently supports -- in fact, this is not even
//! detected as an example otherwise!
//!
//! # Sample Projects With This Setup
//!
//! * [axum](https://github.com/tokio-rs/axum)
//! * [tract](https://github.com/sonos/tract)
//!
fn main() {
println!("Hello, from crate `hello-world-multi-bin` -> Bin #1!");
}
2 changes: 2 additions & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub const RUST_FILE_EXT: &str = "rs";

/// Name of the `Cargo.toml` file in Cargo projects
pub const CARGO_TOML: &str = "Cargo.toml";
/// Name of the `main.rs` file in Cargo projects
pub const MAIN_RS: &str = "main.rs";
/// Name of the `settings.toml` file for local project cache
pub const SETTINGS_TOML: &str = "settings.toml";

Expand Down
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ mod constants;
mod models;
// noinspection SpellCheckingInspection
mod osstringext;
mod pathbufext;
mod run_ext;
mod run_impl;
mod types;
Expand All @@ -96,6 +97,7 @@ use cache::*;
pub use constants::*;
pub use models::*;
pub use osstringext::*;
pub use pathbufext::*;
pub use run_ext::*;
pub(crate) use run_impl::*;
pub use types::*;
Expand All @@ -109,10 +111,9 @@ pub fn process_input(args: Args) -> Result<()> {

let p = Paths::resolve()?;

let name_to_required_features = p.example_to_required_features()?;
let files = p.example_file_paths()?;
let files = p.example_files()?;

process_input_inner(files, p, args, name_to_required_features)
process_input_inner(files, &p, args)
}

/// This is a **patch** so that the `colored` output works as expected
Expand Down
Loading