-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add cargo build --examples to build all examples #3112
Comments
Sounds reasonable to me, we could even extend to:
(etc) |
I'd like to see this implemented. My workaround: move them to |
@BenWiederhake would you be up for implementing a PR to do this? I wouldn't mind helping out with a PR if you'd like |
At first glance, it looks like this would either need to (I) enumerate things on its own during Am I even on the right track? I guess you prefer the (II) way? I'm MikeMountain on irc.mozilla.org, in case a chat is more productive. |
Ah yeah I think this change will boil down to:
and that should be it! |
A new variant to // Current
pub enum CompileFilter<'a> {
Everything,
Only {
lib: bool,
bins: &'a [String],
examples: &'a [String],
tests: &'a [String],
benches: &'a [String],
}
}
// Proposed
pub enum FilterRule<'a> {
Everything,
Only (&'a [String]),
}
pub enum CompileFilter<'a> {
lib: bool,
bins: FilterRule<'a>,
examples: FilterRule<'a>,
tests: FilterRule<'a>,
benches: FilterRule<'a>,
} With this I want to express that:
Where these aren't sure yet:
I'll go ahead and try to implement it like this. Or do you prefer a different way? EDIT: Oh Github Hotkeys, I love you. Sorry for the spurious initial version. |
@BenWiederhake yeah that sounds great to me! I've often wanted to add something like |
The current behavior goes like this: If the user specifies With the new representation, it is much easier to write EDIT: Ah, no, obviously Looks I need to read more first :) |
Ah yeah so to clarify the intention was that we'd support crazy invocations like:
or basically any mixture of all these flags, so I don't think we'd want any of them to be mutually exclusive. |
Yup, I'm aware of this. I think I found a nice interpretation for the flags that stays backwards compatible. How should we handle combinations like
I'll go and try to implement 1, as it is slightly easier. Or do you think that anyone needs "2"? |
Oh I'd consider flags on the command line to always be "unioned" together in the sense that they're always composable. That way |
So now there's at least three potential interpretations. Do you really think it's a good idea to specify the behavior of something for which there are multiple reasonable interpretations? |
I went with this interpretations since I didn't want to introduce a new |
So I implemented it, but running How should I proceed? I don't want to open a PR yet, I haven't checked the style guidelines yet. |
It looks like those test failures may be related to |
Argh, my fault, I didn't see that this is why the tests are failing. Yes, it's a flag in a local |
Ah ok! That's covered by #3863 |
Looks like it's going well. I guess I should also provide tests which actually make use of |
Yeah I think we'll definitely want tests for a number of the various cases here, and yeah |
This'll take longer than expected, apparently I broke a lot of implicit assumptions. |
Fascinating. Apparently it wasn't me, it's just that the implicit assumption is just … wrong.
Now invoke This is a reminder to myself that I want to add a test case for this, after fixing it. (The logic that determines how many binaries there are needs to be adapted heavily anyway.) EDIT: Just to make sure: I'm fully aware what the bug is and where it lives, I just wanted to point out that this bug becomes more obvious due to the new |
Oh dear sounds bad! If you end up fixing that in a drive-by commit it'd be more than welcome :) |
Uhh, so I can only come up with these ways to handle the additional issue:
I'll go ahead and implement the latter, leaving #3867 for later. |
So I hunted down some bugs in my code, and there seems to be one where I don't know how to go about debugging it. This particular test:
Fails in a strange way. One can easily reproduce it by manually invoking it:
It appears to just fail to parse the arguments, but why? Did I forget to change something in the I'm aware that |
Ah yeah leaving #3867 is fine for now, thanks for opening an issue! Oh for that it's a docopt thing whether |
You mean the But there's still something I don't understand: Why is it not needed for so many other things then? As far as I can see, Also, I don't quite understand the failure of |
Oh I forget the precise intricacies of how docopt works unfortunately, you may have to consult that documentation. Also hm that sounds quite odd coming into |
Fix `cargo run` panic when required-features not satisfied This PR fixes #3867 which is made up of two parts. The first part involves `cargo run` triggering an assertion after compiling. This is triggered by the single binary selected for compilation being filtered out when required-features is specified and said features are not enabled. The cleanest approach to me involves just sticking a flag into `CompileFilter::Everything`. The flag then triggers the already existing error message when required-features is not satisfied. I think this works best because it localizes what is really a `cargo run` quirk without requiring any boilerplate or duplicate code. The second part shows `cargo run` bailing when two binaries exist, both with required-features, but only one is resolved to be compiled due to default features. I feel like the current approach is correct because it's consistent with what normally happens when there are multiple binaries. I'm open to changing this, but for now, I've added a test to enforce this behavior. cc @BenWiederhake: I took a quick peek at your branch to fix #3112 and I noticed that it probably won't merge cleanly with this PR. Just an FYI in case it makes sense to have this merged.
I give up for now, since I have no idea why this change breaks EDIT: I should mention that |
Erroneously closed, please re-open |
@BenWiederhake want to gist some of the logs you've been seeing? If you want to make a WIP PR I can also try to help out there |
Here is a diff between the outputs. The command
As you can see, the debug messages don't indicate any difference (except in timing) until "suddenly" the second run of the As the list of enumerated targets is printed (and proven to be of length 1, so cargo_compile definitely doesn't do duplicate work), I can only guess that I broke an assumption somewhere in the "runner", or wherever the loop that says |
Maybe some target is being added twice to the final list by accident or something like that? It may help to debug where the relevant arrays are constructed to see why they contain too many elements. |
Turns out that the bug is somewhere else entirely: - filter = ops::CompileFilter::new(true, &empty, &empty, &empty, &empty);
+ filter = ops::CompileFilter::Everything; Back when I did that change, I assumed that All existing tests are now passing. I'm working on adding additional tests and rebasing it on top of current master (including #3879), then I can think about creating a PR. |
Oh awesome, thanks for tracking that down! |
Implementation and CLI-support for `--all-$KIND` flags This implements #3112. This means all of the following commands are now possible and meaningful: ``` cargo build --all-bins cargo build --all-tests cargo test --all-tests cargo test --all-bins cargo check --all-bins --all-examples --all-tests --all-benches ``` The commits try to represent the incremental "propagation" of the new feature: - core functionality (`cargo check --lib` passes) - CLI suport (`cargo build` passes) - additional tests (`cargo test` covers new functionality) Note that `--all` is already reserved to mean "all packages of the workspace", so it can't be used to mean `--all-bins --all-examples --all-tests --all-benches`. I intend to follow this up by some other PRs, so please do tell me where I could improve.
Since I haven't seen it being discussed, is there already a shortcut for If not, maybe we can add one, like And then maybe IMHO, |
Very nice feature! 😸 |
Or maybe it could be called
--all_examples
for consistency with--all_features
.It would be convenient to build all examples and then run them with
target/debug/examples/NAME
instead of needing to list the examples directory and find specific names to pass tocargo run --example
.#2548 would definitely help here, but I think both features would be nice to have.
Edit: Apologies if this has been discussed and rejected - I couldn't find an explicit "we don't want this" anywhere.
The text was updated successfully, but these errors were encountered: