Skip to content
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

Use bin target name instead of package name as default #157

Merged
merged 1 commit into from
Sep 11, 2023

Conversation

rhysd
Copy link
Contributor

@rhysd rhysd commented Aug 15, 2023

Fixes #156

if let Some(target) = package
.targets
.iter()
.find(|target| target.kind.iter().any(|k| k == "bin"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this just be target.kind.contains("bin")?

Copy link
Contributor Author

@rhysd rhysd Aug 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. It causes a compile error because the iterated item is &String (target.kind is Vec<String>). target.kind.contains(&"bin".to_string()) works, but it causes redundant heap allocation.

error[E0308]: mismatched types
    --> src/bundle/settings.rs:155:57
     |
155  |                     .find(|target| target.kind.contains("bin"))
     |                                                -------- ^^^^^ expected `&String`, found `&str`
     |                                                |
     |                                                arguments to this method are incorrect
     |
     = note: expected reference `&std::string::String`
                found reference `&'static str`
note: method defined here
    --> /Users/rhysd/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/slice/mod.rs:2509:12
     |
2509 |     pub fn contains(&self, x: &T) -> bool
     |            ^^^^^^^^

For more information about this error, try `rustc --explain E0308`.
error: could not compile `cargo-bundle` (bin "cargo-bundle") due to previous error

* `name`: The name of the built application. If this is not present, then it will use the `name` value from
your `Cargo.toml` file.
* `name`: The name of the built application. If this is not present, then it will use the `name` value from `bin`
target in your `Cargo.toml` file.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which bin does it choose if there is more than one?

Copy link
Contributor Author

@rhysd rhysd Aug 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First one is chosen. My understanding is that multiple bin targets are not supported. Shall I explicitly note it here?

@mdsteele mdsteele merged commit 4f1499f into burtonageo:master Sep 11, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo-bundle should use bin target name instead of package name
2 participants