-
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
Ability to specify the output name for a bin target different from the crate name #9627
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,6 +194,8 @@ pub struct Target { | |
struct TargetInner { | ||
kind: TargetKind, | ||
name: String, | ||
// Note that `bin_name` is used for the cargo-feature `different_binary_name` | ||
bin_name: Option<String>, | ||
// Note that the `src_path` here is excluded from the `Hash` implementation | ||
// as it's absolute currently and is otherwise a little too brittle for | ||
// causing rebuilds. Instead the hash for the path that we send to the | ||
|
@@ -350,6 +352,7 @@ compact_debug! { | |
[debug_the_fields( | ||
kind | ||
name | ||
bin_name | ||
src_path | ||
required_features | ||
tested | ||
|
@@ -627,6 +630,7 @@ impl Target { | |
inner: Arc::new(TargetInner { | ||
kind: TargetKind::Bin, | ||
name: String::new(), | ||
bin_name: None, | ||
src_path, | ||
required_features: None, | ||
doc: false, | ||
|
@@ -662,6 +666,7 @@ impl Target { | |
|
||
pub fn bin_target( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is something that we'll want to handle for at least the cdylib output as well, perhaps the staticlib output too. Overall I think that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to re-use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think what Alex is referring to here is that it could be generalized for all the target types, and that could be handled in some place like |
||
name: &str, | ||
bin_name: Option<String>, | ||
src_path: PathBuf, | ||
required_features: Option<Vec<String>>, | ||
edition: Edition, | ||
|
@@ -670,6 +675,7 @@ impl Target { | |
target | ||
.set_kind(TargetKind::Bin) | ||
.set_name(name) | ||
.set_binary_name(bin_name) | ||
.set_required_features(required_features) | ||
.set_doc(true); | ||
target | ||
|
@@ -911,11 +917,17 @@ impl Target { | |
Arc::make_mut(&mut self.inner).name = name.to_string(); | ||
self | ||
} | ||
pub fn set_binary_name(&mut self, bin_name: Option<String>) -> &mut Target { | ||
Arc::make_mut(&mut self.inner).bin_name = bin_name; | ||
self | ||
} | ||
pub fn set_required_features(&mut self, required_features: Option<Vec<String>>) -> &mut Target { | ||
Arc::make_mut(&mut self.inner).required_features = required_features; | ||
self | ||
} | ||
|
||
pub fn binary_filename(&self) -> Option<String> { | ||
self.inner.bin_name.clone() | ||
} | ||
pub fn description_named(&self) -> String { | ||
match self.kind() { | ||
TargetKind::Lib(..) => "lib".to_string(), | ||
|
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.
This looks like it's automatically appending a prefix/suffix such as
lib
,.a
, and.exe
I think. If that's the case I'm not sure thatfilename
is the right name for the key in the manifest since it's only influencing part of the filename, not the whole filename.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.
what about something like
binary_name
instead offilename
? would that be more suitable?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.
We discussed some ideas for the name, but none seemed particularly good.
file_stem
is a strong option, but it may not work well with libraries. Another option is to allowname
to support arbitrary values, but if it is a non-identifier, require a second field ofcrate-name
.We didn't feel strongly about any of the options we thought of, so I think leaving this as
filename
for now is fine, and we can maybe consider other options later.