-
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
Infer multi-file binaries like src/bin/server/main.rs
by convention
#4086
Comments
Sounds great to me! |
If anyone wants to fix it, the place to look at is this line Line 54 in 263548d
and this function Line 503 in 263548d
The tests should probably go into this file: https://github.com/rust-lang/cargo/blob/master/tests/build.rs |
Is anybody working on this? |
@msehnout not that I know of, feel free to take it! |
Infer multi-file binaries like `src/bin/server/main.rs` by convention This feature is described in issue #4086
#4214 enabled this for src/bin, but how about also enabling this pattern for examples (and maybe integration tests)? |
@crumblingstatue that sounds plausible! Right now I am refactoring the implementation of this stuff in #4259 though, so, if you'd like to send a PR, it's better to wait for a while :) |
Hi @matklad, I think I could try to work on this one. The PR you mentioned is merged already. Is there anything I should be aware of before I start? |
Awesome @rwakulszowa ! I think toml/targets.rs is the only file that should me modified, besides the test. |
Hey, I have a few questions
|
Yeah, the benchmarks could use the same logic
I would probably check that |
Infer targets from subdirectories Fixes #4086 I still have a few questions: - should I add some tests for the old behaviour? It isn't really tested at the moment (no tests failed when I broke the implementation); I could refactor the tests to check for both single file and subdirectory inference - I moved things around, mostly reusing the code from `inferred_bins` - hopefully I didn't break anything, but it won't hurt to double check :) - Do we have something like servo's `tidy` check for coding style? I'm open for suggestions if something isn't formatted correctly - Just a general one - should I rebase + squash commits every time I make subsequent changes to cargo?
Did support for examples with a main.rs file get added as part of this or should that be a separate issue? |
Yes - examples, benches and tests follow the same logic and allow
multi-file directories, as long as they contain a main.rs file.
Did you encounter a problem with that?
19.11.2017 17:01 "Sunjay Varma" <notifications@github.com> napisał(a):
… Did support for examples with a main.rs file get added as part of this or
should that be a separate issue?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4086 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AKQgyOsIslY-urII1LDbBZqRuXkU31cdks5s4F7zgaJpZM4Ni3Ta>
.
|
@rwakulszowa Yes, it didn't work. Here's a minimal example: From the base project created by
Both files contain the simple hello world program. When I try to run them, this is what happens:
The flat file worked, but nesting a file within a directory and having a file called "main.rs" did not work. |
Are you sure you are using a recent cargo build? This change got merged in
September, but I'm not sure which cargo release contains it ( @matklad ?)
I have limited network access at the moment, so I'll check the official
release tomorrow, but I tested the feature locally and it works fine.
Maybe the feature didn't make it to the official release yet, or some other
changes modified the behavior. I'll take a look.
19.11.2017 19:42 "Sunjay Varma" <notifications@github.com> napisał(a):
… @rwakulszowa <https://github.com/rwakulszowa> Yes, it didn't work. Here's
a minimal example:
From the base project created by cargo new --lib <project name>, I added
a file examples/dir/main.rs and a file examples/foo.rs.
.
├── Cargo.lock
├── Cargo.toml
├── examples
│ ├── dir
│ │ └── main.rs
│ └── foo.rs
└── src
└── lib.rs
Both files contain the simple hello world program. When I try to run them,
this is what happens:
$ cargo run --example dir
error: no example target named `dir`
Did you mean `foo`?
$ cargo run --example foo
Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
Running `target/debug/examples/foo`
Hello, world!
The flat file worked, but nesting a file within a directory and having a
file called "main.rs" did not work.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4086 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AKQgyEWAvRZWzF4_6nFTQlDQ5X2CNDGPks5s4ISxgaJpZM4Ni3Ta>
.
|
Yes it seems so. I tried running it with |
Alright!
19.11.2017 20:45 "Sunjay Varma" <notifications@github.com> napisał(a):
… Maybe the feature didn't make it to the official release yet, or some other
changes modified the behavior. I'll take a look.
Yes it seems so. I tried running it with cargo +nightly run --example dir
and it worked. Looks like this will probably be out in Rust 1.22 😄
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4086 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AKQgyGFszm-gsWsYgHdRo9wYHW2a2AVNks5s4JNggaJpZM4Ni3Ta>
.
|
Currently
cargo
infers binaries from files insrc/bin
. This works if you binary fits in one file, but if you need more than one file, you have to write custom[[bin]]
specification in Cargo.toml.Looks like a reasonable convention for multifile binary projects is this:
So let's infer
src/bin/foo/main.rs
as a binary namedfoo
?This should be mostly backwards compatible change. The only failure case is when someone has
src/bin/foo/main.rs
which is not a binary, and no[[bin]]
sections are present, and this seems unlikely.A potential edge case is
This should be an error.
The text was updated successfully, but these errors were encountered: