-
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
Make it possible to run binaries produced by cargo directly. #3670
Comments
Thanks for summarizing the lay of the land here @matklad! I agree with your analysis and I'd be totally down with extending json messages and such. To take that route it sounds like:
|
Thanks for the summary! Your proposal sounds good to me... In my usecase (ie. |
Yes please! I recently wrote a Cargo subcommand that needs to know the name of the binaries which are produced after a build, and this was absolutely the biggest pain point I had. Right now I have this really ugly hack where I basically just list all of the files in the target directory that could match whatever the kind of a build I want to run could generate, then I try to build it, and then I see what changed. I would love to have something like
In my use case I really don't want to use |
How the proposed approaches works for doc tests (they are ephemeral)? The |
I think neither approach would work out of the box, because it's rustdoc who manages the execution of doctests. That is, any solution we implement in cargo, we need to also implement in rustdoc and then make Cargo to forward command line arguments to rustdoc. But I think that executing doctests directly is an extremely niche use case, and perhaps we can just not do this? |
I think I want In IDEA UI the rule in general is "everything you can run, you can debug". So the user may launch command line like So I want to be able to get the command line for debugging from the command for running. One way to do this is to add Another way would be to parse the command line, find out the equivalent |
Oh so the user is typing in |
Side note: Just seeing the literal |
A similar issue is that we have |
Yeah I wouldn't expect a user to type |
Ok, let me try to summarize:
Correct me if I'm wrong in any of those points... |
My use case for executing doctests directly is to collect code coverage. Although some says that doctest should not be used in code coverage, some functions have doctests that are good enough and not running them would decrease the coverage. |
@vojtechkral did you see @matklad's description above? It sounds like users are typing And currently |
@alexcrichton I must have missed that post or misunderstood it earlier. Sorry. I'm not convinced that's a good reasoning, though. I don't think it's a good idea to make cargo's interface tailored to IntelliJ. Picture a few months/years down the road a newbie comes along:
Could we instead perhaps separate "no running" and "printing"? Or maybe even better make "printing" imply "not running", where applicable? Ie.
I guess my problem with the I hope I'm making sense. Anyway, obvisouly, that's just my $.02, if you guys come to the conclusion |
@vojtechkral totally agree with you that I think the core problem is that there are actually two issues we are trying to solve Issue 1"I need to find out where the artifacts are" This issues should be covered by #3319 and #3752. This info is currently available in JSON only, but I think we could expose it in the human readable format if Issue 2"What is the command line invocation (that is, binary path, command line arguments, environment variables) that cargo would use for my binary? I would love to intercept it exactly" This is a rather more specific use case. We need it for IntelliJ Rust, but I imagine other usecases. For example, one can implement a command User runs One way to do it is to add a special argument, |
Sounds good to me! |
@matklad yeah that sounds pretty reasonable, something like |
Ok, I think I'll try that, but only after some time. First, I need to do a week-long vacation in Paris :) Then, I'd love to experiment with existing artifact json messages and IntelliJ's debugger: it should be possible to do a lot only with I'll edit the issue description to point to |
Awesome, thanks @matklad and have fun! |
Aside: I wrote a small library that should make it easy* to write cargo wrappers for *) example usage: extern crate cargo_wrap;
fn main() {
cargo_wrap::cargo_wrap(|target, mut args| {
args.push(target);
(String::from("gdb"), args)
});
} |
cc #3866, a proposed solution |
-"OUT_DIR" is now restricted to build scripts, as a temporary workaround until resolution of rust-lang/cargo#3670 we'll use LD_LIBRARY_PATH, though there are other options needed to be looked into -call AtPath and make use SceneSettings in context of fixtures dir being optional.
Making a note that exposing a binary name would also be helpful for containerization tools that build the copy binaries into a container |
I just noticed that I never pinged this issue, but I wrote a cargo plugin a while ago which may be interesting to some people until this issue is resolved upstream: cargo-with It essentially builds on @matklad initial idea of a |
How about Having a way to get this information without having to dig through JSON would be great, as I don't know how else to locate a binary in a deployment where users may or may not have set a default binary or |
Any updates? |
For integration test purposes, I couldn't be happier about the new |
What is the current recommendation to get the final output name? In my use case, the build consists of two phases:
Both steps are more or less independent; IDEs or external scripts might have their own idea about the Hence, step 2 needs to determine the path to the binary somehow and atm it works only by guessing and relying on the usual behavior (--> |
Another workaround with
|
I think, using
There should be at least some passive command like
|
It seems that cargo --config "target.'cfg(unix)'.runner = 'ls'" run In contrast to |
EDIT: 90% of this is solved by
--message-format=json
flag.Hi! This is a followup of #1924 and #1726.
Problem
Sometimes one needs to run an executable produced by Cargo (be it example, binary or doc/unit/integration test) directly.
The most common use case is debugger integration in the IDE, but other examples include
strace
,perfrecord
and similar tools.Peculiarities
cargo test
can produce more than one binary. We need to handle this somehow.Both
cargo run
andcargo test
have different flavors for specifying profiles, features, targets and arguments for the binary. Ideally, it should be easy to learn the name of output file by the cargo command.Cargo can setup
LD_LIBRARY_PATH
when running a binary, it would be good to be able replicate this as well.Solutions
--with
wrapperAdd a
--with
option to the run family of commands to allow to specify a custom wrapper. There's a stale pull request implementation in #1763.This would probably be the most useful option on the command line. However, it is not flexible enough: there's still an intermediate Cargo process around, and this won't be enough for IntellJ Rust: we launch debugger process first and then send it a command to launch the debugee.
Also, this can be implemented as an external subcommand on top of other options, so that you can run
cargo with-wrapper strace run --release --bin foo
.--output-file
optionWe can implement #1706, than clients could specify the name they want. This is a nice option, but it's not perfect: the binary may assume certain location and use something like
../../foo/bar
to get resources at run time or something like that. While arguably you should not do this, ideally we should be able able to run binaries exactly as Cargo does. Also with explicit output file the client has to manage temporary directories, which is some extra work.Stable file names
We can make the names of binaries predictable. This is perhaps the simplest option, but I don't like it for various reasons:
We already have
debug
andrelease
profiles, which affect the output path. This means that clients should implement some logic to get the current profile, which may be brittle.This requires stabilizing target directory layout and may make future features harder. What if one day we would like to add custom profiles and an ability to configure the custom profile via environment variables/config files?
This does not allow to easily derive the binary name given the cargo command, which again means some logic on the client's side.
Add file names to
cargo metadata
This is very similar to the previous option, and does not solve the profiles problem at all.
Print the resulting file name with
--no-run
This is my favorite option :)
It is naturally forward compatible.
It's naturally extendable to print more information about the environment which is used to run the process (
LD_LIBRARY_PATH
, command line flags).We almost do this already: with
--message-format=json
we print the path to binary if it is not fresh. I suggest that we always output this info, even we don't actually rebuild the binary. Perhaps we should use a new, separate message, to make it easier to extend it to support additional and to make it easier for the clients to separate dependencies from the actual end binaries.It would be trivial to match cargo commands with binary names: just add
--no-run
option (I'd like to add this flag tocargo run
as well).I like that on the client side, you have to actually build the binary before trying to use it. This solves debugging stale binaries problem by construction.
I'll be glad to implement any of these options :)
cc @bruno-medeiros @vojtechkral.
The text was updated successfully, but these errors were encountered: