Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upCargo: produce deterministic filenames for `build --test` and `test --no-run` #1924
Comments
bruno-medeiros
referenced this issue
Aug 20, 2015
Closed
Cargo: produce deterministic filenames for `build --test` and `test --no-run` #27923
This comment has been minimized.
This comment has been minimized.
|
The problem Cargo has to deal with here is that you can test many targets which are all named the same. For example you could have a binary called I do agree though it's annoying to have to basically do a diff of the output directory before and after a test run to see what binaries were generated. |
This comment has been minimized.
This comment has been minimized.
|
Why not just put the test binaries in their own directory then, like |
This comment has been minimized.
This comment has been minimized.
|
The problem is that you can have multiple binaries called |
This comment has been minimized.
This comment has been minimized.
Which is a perfectly fine solution, no? |
This comment has been minimized.
This comment has been minimized.
|
Yet another solution would be to have the Cargo build targets all share the same namespace. Seems like a fine solution if Cargo was just starting out, but at this point it would be a breaking change - so not ideal, I reckon... |
This comment has been minimized.
This comment has been minimized.
|
There may be a more ergonomic possibility than |
This comment has been minimized.
This comment has been minimized.
Then how about just |
This comment has been minimized.
This comment has been minimized.
|
Hm actually now that I think about it we probably want to continue the pattern of |
This comment has been minimized.
This comment has been minimized.
Well, Rust may be 1.0, but Cargo is only version 0.2, so it can be argued that a minor breaking change would be acceptable. But I don't know how strict your policy aims to be with regards to breaking changes in Cargo. |
This comment has been minimized.
This comment has been minimized.
|
Despite Cargo's version it actually needs to be quite stable today, so I'd prefer to keep at least roughly the same pattern that we have today. |
This comment has been minimized.
This comment has been minimized.
FlorentBecker
commented
Nov 29, 2015
|
How about (additionnally?) making cargo run --no-test output the name of the executables it builds on stdout? This way, |
This comment has been minimized.
This comment has been minimized.
|
@FlorentBecker my preference here would be to just have deterministic filenames for now, but that's a possible alternative if it doesn't work out! |
This comment has been minimized.
This comment has been minimized.
adrianheine
commented
Jan 4, 2016
|
I'd have to say that I would prefer to have a way to get the file name from cargo instead of being able to guess it myself. |
This comment has been minimized.
This comment has been minimized.
posborne
commented
Feb 24, 2016
|
I have to agree with @adrianheine and @FlorentBecker. It would be very nice to have cargo give the output of test discovery. To make the output parseable in scripts and the like, I would propose that something like a Currently, I am working on adding infrastructure to nix based on libc. Unlike libc, nix does not currently have most of its tests built separately in a single executable. Right now, after cross compiling the executables there is no great way to get the paths to the test executables and pass execute them in qemu. I can glob but even then it involves a repetition of the individual tests that are in the root Cargo.toml. |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton If compatibility with existing build scripts is important (implying the continuing of the pattern of @posborne 's additional suggestion of enabling Cargo to output the filenames is good as well. It enables tools to figure out the executables without having to be able to parse Cargo.toml and figure out the Cargo targets beforehand. But this suggestion should be an addition, not the main solution, there should still be a way to generate static/deterministic filenames. |
This comment has been minimized.
This comment has been minimized.
|
Yeah at this point I think that we should probably just invent some scheme that has predictable names but lacks hashes. Along those lines I'd be fine with basically anything that kept the convention of |
This comment has been minimized.
This comment has been minimized.
|
Hum, so like |
This comment has been minimized.
This comment has been minimized.
|
That sounds pretty reasonable to me, yeah! |
This comment has been minimized.
This comment has been minimized.
jan-hudec
commented
Mar 17, 2016
I would perhaps avoid the |
This comment has been minimized.
This comment has been minimized.
|
Unfortunately using |
This comment has been minimized.
This comment has been minimized.
jan-hudec
commented
Mar 17, 2016
|
Then The confusion under Windows I feared was that Windows by default hide the extension in various places and don't do it in a particularly consistent way. And because If you want to have |
This comment has been minimized.
This comment has been minimized.
|
Hm this actually gives me an idea! So I'd like to keep the same names we have today in case any scripts are relying on them, but we could perhaps do something like:
That way we could slowly phase out the old locations and we could continue to use the new ones today! |
This comment has been minimized.
This comment has been minimized.
If that's confusing, Windows users should disable the Windows Explorer option that hides file extensions. I suspect most Windows developers and power users do that already anyways (I certainly do). And IDEs certainly don't hide extensions. |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton Yeeeesh, hard links... you sure that's a good idea? Sounds like a really heavy handed solution. Do all the OSes that Rust targets have filesystems that support hard links? What if one wants to use a filesystem that doesn't support hard links? Imagine for example someone has a Rust project on a portable FAT32 USB stick or something like that. Or a network share? It's a really odd and rare scenario, but I think it might realistically happen. |
This comment has been minimized.
This comment has been minimized.
|
Re library to use, |
This comment has been minimized.
This comment has been minimized.
|
@kamalmarhubi Oh cool, didn't know about that. |
This comment has been minimized.
This comment has been minimized.
I haven't thought about if hardlinks are the right approach, but this is a real concern. I think between FS support and confusing Explorer defaults, I'd prefer the confusion over reduced FS support. |
This comment has been minimized.
This comment has been minimized.
DemiMarie
commented
Mar 29, 2016
|
One approach is for Cargo to output all of the filenames that it generates in a JSON file. |
bruno-medeiros
referenced this issue
May 12, 2016
Open
TRACKER for important Rust and Cargo toolchain issues #112
cbiffle
referenced this issue
Sep 16, 2016
Closed
`cargo build` of root crate staticlib fails if FS doesn't support hardlinks #3098
matklad
referenced this issue
Sep 24, 2016
Closed
"cargo metadata" should contain metadata and extra_filename #3109
This comment has been minimized.
This comment has been minimized.
cbiffle
added a commit
to cbiffle/cargo
that referenced
this issue
Sep 25, 2016
This comment has been minimized.
This comment has been minimized.
jan-hudec
commented
Sep 27, 2016
|
@jsgf, this is a bit different. At least shared libraries must contain the metadata part for versioning. But the examples and tests don't and it would be much more useful if they didn't, which is what this issue is asking for. The use-case I have in mind is testing examples. A test would be written that would execute the example and check its output. For which it can use |
matklad
referenced this issue
Feb 8, 2017
Open
Make it possible to run binaries produced by cargo directly. #3670
This comment has been minimized.
This comment has been minimized.
|
I also ran into this when trying to collect test binaries for coverage testing. I used this command to find the binaries after
The thing is, this returns multiple binaries, since i have a crate that provides both a lib.rs and a main.rs. In addition to that, I have integration tests that also produce a binary. My workaround currently is to do the following:
Better support for this would be welcome. |
This comment has been minimized.
This comment has been minimized.
ssokolow
commented
Mar 28, 2017
|
Mine runs |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ssokolow
commented
Mar 28, 2017
|
Hmm. I'll have to think about that. I don't mind using a Python shebang in my justfile for my own projects, but, for the authoritative copy of the boilerplate, the only external scripting language it currently uses for tasks is bash and I'm reluctant to add to the list of dependencies just to parse JSON. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Yeah, Cargo currently has some awesome support for dumping all sorts of interesting info as JSON (http://doc.crates.io/external-tools.html), but it's not very convenient to use from bash. Of course it's relatively easy to create and install custom subcommands to deal with JSON, if you are OK with adding dependencies. By the way, @bruno-medeiros, the original problem of "I need a way to run cargo run / cargo test" from the IDE is going to be solved by #3670 via #3866 soon. |
This comment has been minimized.
This comment has been minimized.
|
We (Fuchsia) really want a solution to this, so we can generate cross-compiled test binaries using a GN build and, and then use other (non-cargo) mechanism to copy the binaries over to a device and run them there. My sense, having explored a bunch of options, is that the best way to do this is to add a flag to |
alexcrichton
referenced this issue
Apr 24, 2017
Closed
Cargo should use Node.js to launch targets built for asmjs #3626
This comment has been minimized.
This comment has been minimized.
jan-hudec
commented
Apr 25, 2017
|
@raphlinus, just keep in mind that there can be targets of different kinds, but same name, so the suffixes have to be type-specific. |
carols10cents
added
C-feature-request
Command-test
labels
Sep 10, 2017
koute
referenced this issue
Dec 18, 2017
Closed
Running `cargo web test` multiple times without modifying code leads to a panic #21
azriel91
referenced this issue
Jan 2, 2018
Closed
Modified binary directory and test executable discovery for coverage #55
aturon
added
the
Feature accepted
label
Jan 22, 2018
This comment has been minimized.
This comment has been minimized.
|
The Cargo team discussed this issue briefly in our meeting today, and we'd be happy to take a PR for it! |
This comment has been minimized.
This comment has been minimized.
ArtemGr
commented
Oct 29, 2018
|
Just a note that JSON isn't a solution for VSCode launch.json / "program", AFAIK. We'd really need a fixed binary path there. |
bruno-medeiros commentedAug 20, 2015
I'm doing IDE integration, and I want my IDE to be able to debug the test binaries - for which the IDE has to launch those programs itself, it shouldn't use
cargo test. However (unlike--binfor example) neitherbuild --testnortest --no-runproduce a deterministic filename, but something random liketest1-748b2ca97d589628.exe.