Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Cannot run cargo run --example simple_host #71

Closed
Walther opened this issue Oct 10, 2018 · 1 comment
Closed

Cannot run cargo run --example simple_host #71

Walther opened this issue Oct 10, 2018 · 1 comment

Comments

@Walther
Copy link
Contributor

Walther commented Oct 10, 2018

(Moved from here into its own issue)

AFAIU, this should work: cargo run --example simple_host, as the example is a) under subdirectory examples/ and b) explicitly defined under an [[example]] declaration in Cargo.toml. This should make Cargo find the named example and run it (and give us the helpful suggestion "usage: simple_host path/to/vst", and hint the end user towards running the command with a path to a VST as a parameter).

However, what actually happens is this:

cargo run --example simple_host
error: example target `simple_host` is a library and cannot be executed

The behavior for detecting things as libraries or binaries has been implemented in this PR.


Another curiosity: if you remove this part from Cargo.toml:

[[example]]
name = "simple_host"
crate-type = ["bin"]

and run cargo run --example simple_host, you get:

warning: An explicit [[example]] section is specified in Cargo.toml which currently
disables Cargo from automatically inferring other example targets.
This inference behavior will change in the Rust 2018 edition and the following
files will be included as a example target:

* /Users/walther/git/rust-vst/examples/simple_host.rs

This is likely to break cargo build or cargo test as these files may not be
ready to be compiled as a example target today. You can future-proof yourself
and disable this warning by adding `autoexamples = false` to your [package]
section. You may also move the files to a location where Cargo would not
automatically infer them to be a target, such as in subfolders.

For more information on this warning you can consult
https://github.com/rust-lang/cargo/issues/5330
error: no example target named `simple_host`

Additionally, if you remove all of the example declarations from the Cargo.toml, cargo run --example simple_host starts working! However, then the library-vs-binary distinction/detection apparently turns completely off, because now you can run cargo run --example sine_synth and get error[E0601]: `main` function not found in crate `sine_synth from the compiler, not triggering the "is a library" -error.


Could this be a bug in the library / binary detection algorithm in Cargo? Maybe crate-type = ["bin"] is not detected correctly if some of the examples are declared as crate-type = ["cdylib"]? Or maybe the entire project is labelled as a binary because the project itself has no main.rs, only lib.rs, even if some of the examples would have a fn main() and be declared as a bin? If so, I can go and file a bug report in Cargo repo.


EDIT: reported to upstream, see below

@Walther
Copy link
Contributor Author

Walther commented Mar 3, 2019

Fixed by rust-lang/cargo#6159

@Walther Walther closed this as completed Mar 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant