-
Notifications
You must be signed in to change notification settings - Fork 111
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
cargo-apk: Reimplement "default" (--
) subcommand trailing args for cargo
#363
Conversation
Fwiw the main reason I dislike this approach is because users may (accidentally) pass (For example |
Realizing the original issue in winit 1 2 won't easily be solvable with this as it currently uses a generic env var to invoke |
The way this question is framed I assume they do something more complicated than just |
@dvc94ch they do, by (ab)using Specifically, since our migration to But then I think we may want to skip that doc step entirely? |
Since migrating `cargo-apk` to `clap` [it is now annoying] to pass unknown arguments to an underlying `cargo` command (like `cargo doc`): fortunately generating docs doesn't need to go through `cargo apk` to set up cross-compiler/linker environment variables at all. [it is now annoying]: rust-mobile/ndk#363
It seems that Now only |
Looks like it's not something xbuild intended to do. To check if the tests compile wouldn't cargo ndk do the job? I could add a cargo command |
@dvc94ch it might be good for I don't want to defer to |
Sorry didn't have time this weekend. Had some family stuff on Friday and Saturday and then had to some work today to compensate for Friday. I can look into it towards the end of next week |
@dvc94ch No worries, we all have exactly that (plus lots of opensource / hobby projects to care about). In any case I applied this change to |
f02d12e
to
5fd1570
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks fine to me, also the winit CI changes!
@msiglreith perfect, thanks! I'll start the release train tomorrow morning 🚂! |
Haven't researched how you actually use cargo dinghy --device=... --any-other-dinghy-commands-here run --release --other-normal-cargo-commands-here (Note that |
@madsmtm looks like This is what I wanted to avoid and/or have implemented in some way in
Fortunately we do not currently support any arguments before the In other words, @madsmtm would you like to see us implementing something along these lines instead of committing to |
I don't have much of an opinion on this, honestly didn't know Would be nice though to my eyes if every |
@madsmtm definitely!
Getting back to this, with a slight modification this logic actually/easily starts working with mixed arguments, which is what I originally wanted to have 🎉 I'll push this after lunch and see if it works without the proposed invasive change in |
5fd1570
to
7b28849
Compare
And it actually works out for Here's a short run-down of what I did and found: First up the code from Then, for what the implementation does here:
|
cargo
with --
separator--
) subcommand trailing args for cargo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic looks sound, nothing to add from me beside some nitpick (:
… with `--` separator `clap` [does not currently support] parsing unknown arguments into a side `Vec`, which is exactly what `cargo apk --` needs to parse a few known `cargo` arguments (such as `--target` and `-p`) but forward the rest verbatim to the underlying `cargo` subcommand. `allow_hyphen_values = true` could partially help us out with this, but it parses all remaining arguments into that `Vec` upon encountering the first unknown flag/arg, resulting in all known flags after that to also be treated as "unknown" instead of filling up our `args: Args` struct. Since [a workaround for this isn't currently functioning], introduce pure trailing args with an additional `--` separator to make it clear which arguments go to `cargo-apk` (and are almost all, except `--device`, forwarded to `cargo`) and which are only passed to `cargo <subcommand>`. [does not currently support]: clap-rs/clap#1404 [a workaround for this isn't currently functioning]: clap-rs/clap#1404 (comment)
With some custom logic, and assuming (validated with an `assert!`) our `Args` struct doesn't have any positionals, we can implement argument separation ourselves: this allows the user to mix and match `cargo <subcommand>` arguments with arguments recognized by `cargo-apk`, and expect `cargo-apk` to set up the environment as expected (as it did previously) by taking these arguments into account while disregarding _only_ unknown arguments.
Mixed `cargo-apk` and `cargo` args will still be split out from `cargo_args`, and they'll be appended to existing values for `args`.
7b28849
to
e2b9db4
Compare
Since migrating `cargo-apk` to `clap` [it is now annoying] to pass unknown arguments to an underlying `cargo` command (like `cargo doc`): fortunately generating docs doesn't need to go through `cargo apk` to set up cross-compiler/linker environment variables at all. [it is now annoying]: rust-mobile/ndk#363
* ci: Don't use `$CMD` for Android doc building Since migrating `cargo-apk` to `clap` [it is now annoying] to pass unknown arguments to an underlying `cargo` command (like `cargo doc`): fortunately generating docs doesn't need to go through `cargo apk` to set up cross-compiler/linker environment variables at all. [it is now annoying]: rust-mobile/ndk#363 * ci: Simplify * ci: Explicitly build just the `winit` package on Android Since rust-mobile/cargo-subcommand#23 `cargo-apk` now strictly searches for workspaces first before committing to finding the right package _within said workspace_, and bails when no package was selected since we don't support selecting (building, packaging, running) >1 target currently. Perhaps it's a bit hash to enforce this on free-form `cargo apk --` invocations, but it is what it is.
@MarijnS95 sorry the current winit ci won't work with xbuild. that's not what xbuild is for. If you want to build a gui application or game then you can build/deploy it with xbuild. To test that something compiles for a specific target while respecting all the cargo flags is a different story. I doubt this is acceptable to you, but you could just set
after picking 1. when building cargo-apk I decided to go with 2. for xbuild. the advantage of 2. is that I'm confident that whatever the combination of cli arguments you provide to xbuild it actually does what it's supposed to. |
the other alternative is to just hack it for the winit build, probably also unacceptable: |
@dvc94ch That is fine then, we can look for alternatives by e.g. setting up However, this also means I'm not yet ready to deprecate Regardless, the fixes have been merged and released, so we can build on this for some time. I'll just have to backport some features to |
one thing we might be able to do is get "-C linker=clang -C link-arg=-fuse-ld=lld -C link-arg=--target=aarch64-linux-android" into the rust target definition. then the only thing that would need to be supplied for winit would be the sorry wasn't trying to diss any tool. but I do think that cargo-apk tries to mimick the behaviour of cargo in it's various flags and we have had a few of bugs where we either oversimplified cargos behaviour or didn't quite get it right. mimicking a complex tool like cargo is always going to be a hard task and there will be edge cases that won't work like what's being emulated. |
just fyi "often behaves unexpectedly" this looks like a quote and I never said those words :) |
You are right that
Maybe you were not directly calling out |
Take it back, I did say those words hahha |
But I think the main point I was trying to make is valid. xbuild is not a cargo replacement and the fact that it uses cargo is an internal implementation detail as far as the user is concerned. Similar like cargo doesn't allow passing arbitrary rustc flags. Yes I know there's RUSTFLAGS and |
clap
does not currently support parsing unknown arguments into a sideVec
, which is exactly whatcargo apk --
needs to parse a few knowncargo
arguments (such as--target
and-p
) but forward the rest verbatim to the underlyingcargo
subcommand.allow_hyphen_values = true
could partially help us out with this, but it parses all remaining arguments into thatVec
upon encountering the first unknown flag/arg, resulting in all known flags after that to also be treated as "unknown" instead of filling up ourargs: Args
struct.Since a workaround for this isn't currently functioning, introduce pure trailing args with an additional
--
separator to make it clear which arguments go tocargo-apk
(and are almost all, except--device
, forwarded tocargo
) and which are only passed tocargo <subcommand>
.CC @epage for seeing if we can do something about this :)
CC @kchibisov as I'd like to release
cargo-apk
with this soon-ish, and will make sure to add the--
separator towinit
beforehand for testing.