-
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
Allow examples to be library #3556
Allow examples to be library #3556
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Looks good to me, thanks! The line with TODO looks ok to me and the failure on Travis seems relevant (just a style issue). If you take a look at |
@alexcrichton, I will add some tests. |
I allowed an example to be built as a library. EDIT: |
@alexcrichton, fn main() {
panic!("");
}
#[test]
fn f() {
panic!("");
} It does nothing. |
This just checks for lines longer than 100 characters, nothing fancy. |
@alexcrichton, |
Thanks @KalitaAlexey! Could you also add assertions that the relevant files exist (e.g. dylibs and such) and also remove the TODO? |
@alexcrichton, |
@alexcrichton, |
I don't know how to check whether a library exists. |
I have found out that cargo uses rustc to determine the prefix and the suffix of a library. |
@KalitaAlexey you can use the |
@alexcrichton, Am I right about library prefixes and extensions?
|
It should do whatever it does today. If it runs unit tests then it should run unit test. If it just builds the artifact then it should just build the artifact. On OSX the dylib extension is "dylib", but other than that the info you have I believe is correct. |
In the PR Today it doesn't compile because it is treated as a binary. |
What happens if you point it to an example that's a binary? Libraries should match the same behavior. |
@alexcrichton, |
It works. |
TargetKind::Lib(ref kinds) => { | ||
kinds.iter().map(|k| k.crate_type()).collect() | ||
TargetKind::Lib(ref kinds) | | ||
// TODO: I am not sure whether it should be encoded like a library or like an example |
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.
(it's ok to remove this now)
Looks like there's a failure on Travis as well? |
@alexcrichton, |
I hope it won't fail again. |
@bors: r+ Looks good, thanks! I think that rollup PR is for rust-lang/rust, not Cargo, so this can't be included. |
📌 Commit e73e270 has been approved by |
…excrichton Allow examples to be library This PR allows to specify **crate-type** to an example in **Cargo.toml**. After this PR an example's **crate-type** can be: * lib * rlib * dylib * proc-macro Please look at src/cargo/core/manifest.rs:116 because I am not sure whether I done it right. I haven't added any tests. I'd like to add them if someone says me how to do that. Fixes #2358.
☀️ Test successful - status-appveyor, status-travis |
Contrary to what's in OP, |
Follow up issue in #3572 |
@alexcrichton, |
@KalitaAlexey the docs are in |
…es, r=alexcrichton Added information about examples as libraries to the documentation [Allow examples to be library](#3556) has been committed. The PR adds information to the documentation.
I have a minor problem with this change. |
@ehuss yeah want to open a new issue? |
Hi @ehuss, |
@KalitaAlexey since we're seeing some breakage want to send a PR to revert back to the original behavior? We can probably add a new field to the metadata which indicates whether an example is a library or not. |
@alexcrichton, |
This PR allows to specify crate-type to an example in Cargo.toml.
After this PR an example's crate-type can be:
Please look at src/cargo/core/manifest.rs:116 because I am not sure whether I done it right.
I haven't added any tests.
I'd like to add them if someone says me how to do that.
Fixes #2358.