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

Work with crates? #19

Closed
Yevgnen opened this issue Apr 27, 2022 · 3 comments · Fixed by #20
Closed

Work with crates? #19

Yevgnen opened this issue Apr 27, 2022 · 3 comments · Fixed by #20
Labels
acknowledged enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Yevgnen
Copy link

Yevgnen commented Apr 27, 2022

Is your feature request related to a problem? Please describe.

Some libraries like tract and axum use workspaces to indicate examples, but current cargo-rx does not seem to able to identify them.

Describe the solution you'd like

Identify workspaces for examples based on directory names?

Additional context

No.

@Yevgnen Yevgnen added the enhancement New feature or request label Apr 27, 2022
@rnag
Copy link
Owner

rnag commented May 3, 2022

@Yevgnen Thanks for opening this issue!

From an initial look, it looks like axum for example suggests running the workspace examples using cargo run instead of cargo run --example.

I agree that this is a great use case for this project, since cargo doesn't identify such examples currently, but it would be nice to fuzzy find and select a workspace example to run. The one caveat is that we'll need to leverage cargo run instead of cargo run --example to test out such examples.

In terms of changes required in this project, I think the simplest way would be to keep a separate list (or hashset) of workspace-specific examples -- note that we could probably determine such examples based on the presence of a Cargo.toml file in an examples/ subfolder. Then, based on the example that the user selects, we can then check if the selected example name is present in the hashset, and proceed to load the Cargo.toml of the example (in order to retrieve the package name, though I think cd and just cargo run could also work); and finally, we can run the workspace example without passing the --example argument to cargo run.

Again, a PR to achieve this would be very welcome. I will also look into this once I have some free time, since it seems like this should be a relatively straightforward change, that should hopefully be pretty simple to implement at least.

@rnag rnag added help wanted Extra attention is needed good first issue Good for newcomers acknowledged labels May 3, 2022
@rnag rnag changed the title Work with workspaces? Work with Cargo crates? Mar 13, 2023
@rnag rnag changed the title Work with Cargo crates? Work with crates? Mar 13, 2023
@rnag
Copy link
Owner

rnag commented Mar 13, 2023

Hi @Yevgnen, I've been looking into this recently, and just a note that the terminology workspaces might not be the exact use case here -- I believe that the actual scenario would be to support Cargo crates with binary targets.

A very simplified project or folder structure could be as follows:

├── Cargo.lock
├── Cargo.toml
├── README.md
├── examples
│   ├── hello-world-crate
│   │   ├── Cargo.lock
│   │   ├── Cargo.toml
│   │   └── src
│   │       └── main.rs
├── ...

A few additional notes for clarification:

  • By itself, cargo run --example does not currently detect such crates as valid examples
  • The Cargo crates would be nested (as sub-folders) within the examples/ folder
  • Each crate would contain its own Cargo.toml file
  • The crate would normally be run with cargo run, and the default binary target would then be src/main.rs
  • For multiple binaries, we could define separate entries for [[bin]] in a crate's Cargo.toml file, and then cargo-rx should display each binary target as a separate example to run

Hope this helps. I'm underway with the new release to support this feature request, and it should be rolling out shortly.

@rnag rnag closed this as completed in #20 Mar 13, 2023
@rnag
Copy link
Owner

rnag commented Mar 13, 2023

@Yevgnen This feature request has been accepted and should be available as part of v0.3.0. Here are the release notes.

I have tested so far with the axum project after cloning it locally, and the good news is that binary targets for all crates within the examples/ folder are now correctly detected by the rx tool as expected.

With projects such as tract, some binaries and examples (mainly indirect examples, such as those within workspace members) are detected by cargo but not by rx as of yet. I have noted this issue as a separate feature request, as part of #21 which I have opened.

Cheers, and have a great Monday! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acknowledged enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants